From 1a1919fb8e476cc3c138a75a841c5702a4cae304 Mon Sep 17 00:00:00 2001 From: Pascal Serrarens Date: Tue, 21 Apr 2026 14:16:12 +0200 Subject: [PATCH] Fix expansion of clsuter arrays --- Editor/ClusterViewer.cs | 108 +++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 57 deletions(-) diff --git a/Editor/ClusterViewer.cs b/Editor/ClusterViewer.cs index 925cfb0..1ae3662 100644 --- a/Editor/ClusterViewer.cs +++ b/Editor/ClusterViewer.cs @@ -313,64 +313,54 @@ namespace NanoBrain { // Draw selected Nucleus if (expandArray) { - // if (this.currentNucleus is IReceptor receptor1) { - // float maxValue = 0; - // foreach (Nucleus nucleus in receptor1.nucleiArray) { - // if (nucleus is Neuron neuron) { - // float value = neuron.outputMagnitude; - // if (value > maxValue) - // maxValue = value; - // } - // } - - // float spacing = 400f / receptor1.nucleiArray.Count(); - // float margin = 10 + spacing / 2; - // float xMin = 150 - size; - // float xMax = 150 + size; - // float yMin = 10 + margin - size / 2; - // float yMax = 400 - margin + size; - // Vector3[] verts = new Vector3[4] { - // new(xMin, yMin, 0), - // new(xMax, yMin, 0), - // new(xMax, yMax, 0), - // new(xMin, yMax, 0) - // }; - // Handles.color = Color.black; - // Handles.DrawAAConvexPolygon(verts); - // int row = 0; - // foreach (Nucleus nucleus in receptor1.nucleiArray) { - // Vector3 pos = new(150, margin + row * spacing, 0.0f); - // Handles.color = Color.white; - // // The selected nucleus highlight ring - // Handles.DrawSolidDisc(pos, Vector3.forward, size + 2); - // DrawNucleus(nucleus, pos, maxValue, size); - // row++; - // } - // GUIStyle style = new(EditorStyles.label) { - // alignment = TextAnchor.UpperCenter, - // normal = { textColor = Color.white }, - // fontStyle = FontStyle.Bold, - // }; - // Vector3 labelPos = new(150, yMax + size + 5, 0); - // string receptorName = receptor1.GetName(); - // int colonPos = receptorName.IndexOf(":"); - // if (colonPos > 0) { - // string baseName = receptorName[..colonPos]; - // Handles.Label(labelPos, baseName, style); - // } - // else - // Handles.Label(labelPos, receptorName, style); - // } - // else { float maxValue = 1; - if (this.currentNucleus is Neuron neuron) - maxValue = neuron.outputMagnitude; - else if (this.currentNucleus is Cluster cluster) - maxValue = cluster.defaultOutput.outputMagnitude; - DrawNucleus(this.currentNucleus, position, maxValue, 20); + if (this.currentNucleus is Cluster cluster) { + float spacing = 400f / cluster.siblingClusters.Length; + float margin = 10 + spacing / 2; + float xMin = 150 - size; + float xMax = 150 + size; + float yMin = 10 + margin - size / 2; + float yMax = 400 - margin + size; + Vector3[] verts = new Vector3[4] { + new(xMin, yMin, 0), + new(xMax, yMin, 0), + new(xMax, yMax, 0), + new(xMin, yMax, 0) + }; + Handles.color = Color.black; + Handles.DrawAAConvexPolygon(verts); + int row = 0; + foreach (Cluster sibling in cluster.siblingClusters) { + Vector3 pos = new(150, margin + row * spacing, 0.0f); + Handles.color = Color.white; + // The selected sibling highlight ring + Handles.DrawSolidDisc(pos, Vector3.forward, size + 2); + DrawNucleus(sibling, pos, maxValue, size); + row++; + } + GUIStyle style = new(EditorStyles.label) { + alignment = TextAnchor.UpperCenter, + normal = { textColor = Color.white }, + fontStyle = FontStyle.Bold, + }; + Vector3 labelPos = new(150, yMax + size + 5, 0); + string clusterName = cluster.name; + int colonPos = clusterName.IndexOf(":"); + if (colonPos > 0) { + string baseName = clusterName[..colonPos]; + Handles.Label(labelPos, baseName, style); + } + else + Handles.Label(labelPos, clusterName, style); + } + else { + if (this.currentNucleus is Neuron neuron) + maxValue = neuron.outputMagnitude; - // } + DrawNucleus(this.currentNucleus, position, maxValue, 20); + + } } else { float maxValue = 1; @@ -473,7 +463,7 @@ namespace NanoBrain { if (synapse.neuron is null) continue; - if (synapse.neuron.parent is Cluster cluster && + if (synapse.neuron.parent is Cluster cluster && //cluster.siblingClusters != null && synapse.neuron.parent != nucleus.parent) { @@ -558,6 +548,8 @@ namespace NanoBrain { string extName = nucleus.name[(colonPos1 + 2)..]; Handles.Label(labelPos1, extName, style); } + else + Handles.Label(labelPos1, "0", style); } else { if (parentCluster.siblingClusters != null && parentCluster.siblingClusters.Length > 1) { @@ -581,6 +573,8 @@ namespace NanoBrain { string extName = nucleus.name[(colonPos1 + 2)..]; Handles.Label(labelPos1, extName, style); } + else + Handles.Label(labelPos1, "0", style); } else { if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1) { @@ -595,7 +589,7 @@ namespace NanoBrain { } } - if (expandArray == false) { + if (expandArray == false || nucleus != currentNucleus) { // put name below nucleus Vector3 labelPos = position - Vector3.down * (size + 5); // below neuron style.alignment = TextAnchor.UpperCenter;