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

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

View File

@ -331,12 +331,16 @@ namespace NanoBrain {
continue;
drawnArrays.Add(clusterReceptor.nucleiArray);
}
// Oops...
else if (synapse.neuron.parent is Cluster cluster && cluster.clusterArray != null) {
if (drawnArrays.Contains(cluster.clusterArray.clusters))
else if (synapse.neuron.parent is Cluster cluster && cluster.siblingClusters != null) {
if (drawnArrays.Contains(cluster.siblingClusters))
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) {
float value = synapseNeuron.outputMagnitude * 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;
}
}
else if (nucleus is Cluster cluster && cluster.clusterArray != null) {
else if (nucleus is Cluster cluster) {
if (expandArray) {
// Put array indices above elements
style.alignment = TextAnchor.LowerCenter;
@ -457,13 +461,15 @@ namespace NanoBrain {
}
}
else {
// draw the array size label
if (color.grayscale > 0.5f)
style.normal.textColor = Color.black;
else
if (cluster.siblingClusters != null && cluster.siblingClusters.Length > 1) {
// draw the array size label
if (color.grayscale > 0.5f)
style.normal.textColor = Color.black;
else
style.normal.textColor = Color.white;
Handles.Label(labelPosition, cluster.siblingClusters.Length.ToString(), style);
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.Collections.Generic;
using UnityEngine;
@ -8,6 +9,7 @@ namespace NanoBrain {
public class ClusterArray : Nucleus {
public ClusterPrefab prefab;
[SerializeReference]
public Cluster[] clusters;
public Dictionary<int, Cluster> thingClusters = new();
@ -19,7 +21,7 @@ namespace NanoBrain {
for (int ix = 0; ix < size; ix++) {
Cluster cluster = new(prefab, parent);
cluster.defaultOutput.AddReceiver(receiver);
cluster.clusterArray = this;
//cluster.clusterArray = this;
this.clusters[ix] = cluster;
}
}
@ -31,7 +33,7 @@ namespace NanoBrain {
for (int ix = 0; ix < size; ix++) {
Cluster cluster = new(prefab, parent);
cluster.defaultOutput.AddReceiver(receiver);
cluster.clusterArray = this;
//cluster.clusterArray = this;
this.clusters[ix] = cluster;
}
}
@ -69,7 +71,7 @@ namespace NanoBrain {
Cluster sourceCluster = this.clusters[0];
Cluster newCluster = sourceCluster.Clone(prefab) as Cluster;
newCluster.name = $"{baseName}: {newLength - 1}";
newCluster.clusterArray = this;
//newCluster.clusterArray = this;
newClusters[newLength - 1] = newCluster;
this.clusters = newClusters;
}
@ -139,4 +141,5 @@ namespace NanoBrain {
}
}
}
}
*/

View File

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