Integrated clusterarray in cluster

This commit is contained in:
Pascal Serrarens 2026-04-17 11:50:10 +02:00
parent e40dd234f9
commit bc0a79688d
5 changed files with 654 additions and 545 deletions

View File

@ -189,17 +189,21 @@ namespace NanoBrain {
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
} else if (this.currentNucleus is Cluster cluster && cluster.clusterArray != null) { }
else if (this.currentNucleus is Cluster cluster) {
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
EditorGUILayout.IntField("Array size", cluster.clusterArray.clusters.Count()); if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1)
EditorGUILayout.IntField("Array size", cluster.siblingClusters.Count());
else
EditorGUILayout.IntField("Array size", 1);
if (GUILayout.Button("Add")) { if (GUILayout.Button("Add")) {
Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name); Undo.RecordObject(prefabAsset, "Array add " + prefabAsset.name);
cluster.clusterArray.Add(this.prefab); cluster.AddInstance(this.prefab);
anythingChanged = true; anythingChanged = true;
} }
if (GUILayout.Button("Del")) { if (GUILayout.Button("Del")) {
Undo.RecordObject(prefabAsset, "Array delete " + prefabAsset.name); Undo.RecordObject(prefabAsset, "Array delete " + prefabAsset.name);
cluster.clusterArray.Remove(); cluster.RemoveInstance();
anythingChanged = true; anythingChanged = true;
} }
EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal();
@ -408,12 +412,12 @@ namespace NanoBrain {
case Nucleus.Type.Receptor: case Nucleus.Type.Receptor:
AddReceptorInput(nucleus); AddReceptorInput(nucleus);
break; break;
case Nucleus.Type.ClusterReceptor: // case Nucleus.Type.ClusterReceptor:
AddClusterReceptorInput(nucleus); // AddClusterReceptorInput(nucleus);
break; // break;
case Nucleus.Type.ClusterArray: // case Nucleus.Type.ClusterArray:
AddClusterArrayInput(nucleus); // AddClusterArrayInput(nucleus);
break; // break;
default: default:
break; break;
} }
@ -465,12 +469,12 @@ namespace NanoBrain {
var editor = Editor.CreateEditor(subCluster.prefab); var editor = Editor.CreateEditor(subCluster.prefab);
} }
protected virtual void AddClusterArrayInput(Nucleus nucleus) { // protected virtual void AddClusterArrayInput(Nucleus nucleus) {
ClusterPickerWindow.ShowPicker(prefab => OnPickedClusterArray(nucleus, prefab), "Select Cluster"); // ClusterPickerWindow.ShowPicker(prefab => OnPickedClusterArray(nucleus, prefab), "Select Cluster");
} // }
private void OnPickedClusterArray(Nucleus nucleus, ClusterPrefab selectedPrefab) { // private void OnPickedClusterArray(Nucleus nucleus, ClusterPrefab selectedPrefab) {
_ = new ClusterArray(selectedPrefab, this.prefab, 1, nucleus); // _ = new ClusterArray(selectedPrefab, this.prefab, 1, nucleus);
} // }
int selectedConnectNucleus = -1; int selectedConnectNucleus = -1;
// Connect to another nucleus in the same cluster // Connect to another nucleus in the same cluster

View File

@ -331,12 +331,16 @@ namespace NanoBrain {
continue; continue;
drawnArrays.Add(clusterReceptor.nucleiArray); drawnArrays.Add(clusterReceptor.nucleiArray);
} }
// Oops... else if (synapse.neuron.parent is Cluster cluster && cluster.siblingClusters != null) {
else if (synapse.neuron.parent is Cluster cluster && cluster.clusterArray != null) { if (drawnArrays.Contains(cluster.siblingClusters))
if (drawnArrays.Contains(cluster.clusterArray.clusters))
continue; continue;
drawnArrays.Add(cluster.clusterArray.clusters); drawnArrays.Add(cluster.siblingClusters);
} }
// else if (synapse.neuron.parent is Cluster cluster && cluster.clusterArray != null) {
// if (drawnArrays.Contains(cluster.clusterArray.clusters))
// continue;
// drawnArrays.Add(cluster.clusterArray.clusters);
// }
if (synapse.neuron is Neuron synapseNeuron) { if (synapse.neuron is Neuron synapseNeuron) {
float value = synapseNeuron.outputMagnitude * synapse.weight; float value = synapseNeuron.outputMagnitude * synapse.weight;
// Debug.Log($"{synapse.nucleus.name}: {value} {length(synapse.nucleus.outputValue)} {synapse.weight}"); // Debug.Log($"{synapse.nucleus.name}: {value} {length(synapse.nucleus.outputValue)} {synapse.weight}");
@ -445,7 +449,7 @@ namespace NanoBrain {
style.normal.textColor = Color.white; style.normal.textColor = Color.white;
} }
} }
else if (nucleus is Cluster cluster && cluster.clusterArray != null) { else if (nucleus is Cluster cluster) {
if (expandArray) { if (expandArray) {
// Put array indices above elements // Put array indices above elements
style.alignment = TextAnchor.LowerCenter; style.alignment = TextAnchor.LowerCenter;
@ -457,13 +461,15 @@ namespace NanoBrain {
} }
} }
else { else {
// draw the array size label if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1) {
if (color.grayscale > 0.5f) // draw the array size label
style.normal.textColor = Color.black; if (color.grayscale > 0.5f)
else style.normal.textColor = Color.black;
else
style.normal.textColor = Color.white;
Handles.Label(labelPosition, cluster.siblingClusters.Length.ToString(), style);
style.normal.textColor = Color.white; style.normal.textColor = Color.white;
Handles.Label(labelPosition, cluster.clusterArray.clusters.Length.ToString(), style); }
style.normal.textColor = Color.white;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
/*
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
@ -8,6 +9,7 @@ namespace NanoBrain {
public class ClusterArray : Nucleus { public class ClusterArray : Nucleus {
public ClusterPrefab prefab; public ClusterPrefab prefab;
[SerializeReference]
public Cluster[] clusters; public Cluster[] clusters;
public Dictionary<int, Cluster> thingClusters = new(); public Dictionary<int, Cluster> thingClusters = new();
@ -19,7 +21,7 @@ namespace NanoBrain {
for (int ix = 0; ix < size; ix++) { for (int ix = 0; ix < size; ix++) {
Cluster cluster = new(prefab, parent); Cluster cluster = new(prefab, parent);
cluster.defaultOutput.AddReceiver(receiver); cluster.defaultOutput.AddReceiver(receiver);
cluster.clusterArray = this; //cluster.clusterArray = this;
this.clusters[ix] = cluster; this.clusters[ix] = cluster;
} }
} }
@ -31,7 +33,7 @@ namespace NanoBrain {
for (int ix = 0; ix < size; ix++) { for (int ix = 0; ix < size; ix++) {
Cluster cluster = new(prefab, parent); Cluster cluster = new(prefab, parent);
cluster.defaultOutput.AddReceiver(receiver); cluster.defaultOutput.AddReceiver(receiver);
cluster.clusterArray = this; //cluster.clusterArray = this;
this.clusters[ix] = cluster; this.clusters[ix] = cluster;
} }
} }
@ -69,7 +71,7 @@ namespace NanoBrain {
Cluster sourceCluster = this.clusters[0]; Cluster sourceCluster = this.clusters[0];
Cluster newCluster = sourceCluster.Clone(prefab) as Cluster; Cluster newCluster = sourceCluster.Clone(prefab) as Cluster;
newCluster.name = $"{baseName}: {newLength - 1}"; newCluster.name = $"{baseName}: {newLength - 1}";
newCluster.clusterArray = this; //newCluster.clusterArray = this;
newClusters[newLength - 1] = newCluster; newClusters[newLength - 1] = newCluster;
this.clusters = newClusters; this.clusters = newClusters;
} }
@ -140,3 +142,4 @@ namespace NanoBrain {
} }
} }
*/

View File

@ -55,8 +55,8 @@ public abstract class Nucleus {
MemoryCell, MemoryCell,
Cluster, Cluster,
Receptor, Receptor,
ClusterReceptor, //ClusterReceptor,
ClusterArray, //ClusterArray,
} }
#region Synapses #region Synapses