Compare commits

..

No commits in common. "74aa48b446f03a2b3e8567c654fac7be8df85651" and "1dc9252a9b29dd1cbe1c06d9812530ac4ee8f0f4" have entirely different histories.

3 changed files with 18 additions and 47 deletions

View File

@ -213,12 +213,12 @@ namespace NanoBrain.Unity {
#region Full Graph
protected void DrawFullGraph() {
// if (this.currentNucleus == null) {
// Vector3 position = new(150, 210, 0);
// DrawAllOutputs(position);
// DrawOutputs(position);
// return;
// }
if (this.currentNucleus == null) {
Vector3 position = new(150, 210, 0);
DrawAllOutputs(position);
DrawOutputs(position);
return;
}
Dag dag = GenerateGraph(this.selectedOutput);
Dag.ComputeLayout(dag);
@ -271,8 +271,8 @@ namespace NanoBrain.Unity {
public Dag GenerateGraph(Nucleus rootNucleus) {
Dag dag = new();
// if (rootNucleus == null)
// return dag;
if (rootNucleus == null)
return dag;
int ix = 0;
Dag.Node receiver = new() {
@ -281,41 +281,18 @@ namespace NanoBrain.Unity {
};
dag.nodes.Add(receiver);
ix++;
if (rootNucleus == null)
DescendGraphFromRoot(ref ix, dag);
else
DescendGraph(receiver, ref ix, dag);
return dag;
}
private void DescendGraphFromRoot(ref int ix, Dag dag) {
foreach (Nucleus nucleus in this.currentCluster.outputs) {
string nucleusName = nucleus.name;
Dag.Node node = dag.FindNode(nucleusName);
if (node == null) {
node = new() {
id = ix,
nucleus = nucleus
};
dag.nodes.Add(node);
}
Dag.Edge edge = new() {
fromId = node.id,
toId = 0
};
dag.edges.Add(edge);
ix++;
DescendGraph(node, ref ix, dag);
}
}
private void DescendGraph(Dag.Node receiver, ref int ix, Dag dag) {
if (receiver.nucleus is not Neuron receiverNeuron)
Neuron receiverNeuron = receiver.nucleus as Neuron;
if (receiverNeuron == null)
return;
foreach (Synapse synapse in receiverNeuron.synapses) {
Nucleus nucleus = synapse.neuron;
if (nucleus.parent != null && currentNucleus != null && nucleus.parent != currentNucleus.parent) {
if (nucleus.parent != null && nucleus.parent != currentNucleus.parent) {
nucleus = nucleus.parent;
}
string nucleusName = nucleus.name;
@ -773,13 +750,13 @@ namespace NanoBrain.Unity {
Vector2 dir = to - from;
float len = dir.magnitude;
if (len <= Mathf.Epsilon) //len <= 2f * discRadius || )
if (len <= 2f * discRadius || len <= Mathf.Epsilon)
// line too short
return;
Vector2 n = dir / len; // normalized
Vector2 a = from;// + n * discRadius;
Vector2 b = to;// - n * discRadius;
Vector2 a = from + n * discRadius;
Vector2 b = to - n * discRadius;
Handles.DrawLine(a, b);
}

View File

@ -18,12 +18,13 @@ namespace NanoBrain.Unity {
currentClusterView.initialized = false;
}
private const float padding = 0f;//4f;
private const float graphHeight = 500f; // height reserved for the VisualElement
private static ClusterView currentClusterView;
private static UnityEngine.Object selectedTarget;
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
float height = EditorGUIUtility.singleLineHeight;
float height = EditorGUIUtility.singleLineHeight + padding;
if (Cluster_Drawer.currentClusterView == null)
// When no cluster is viewed
return height;
@ -31,10 +32,6 @@ namespace NanoBrain.Unity {
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
if (prefabProp.objectReferenceValue != null && Cluster_Drawer.currentClusterView.isOpen) {
height = graphHeight;
} else {
// Unclear why this is necessary,
// but without this, expanding the graph foldout is not possible
height += EditorGUIUtility.singleLineHeight;
}
return height;
}
@ -76,7 +73,7 @@ namespace NanoBrain.Unity {
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
// Draw the object field on the top line
Rect fieldRect = new(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);
Rect fieldRect = new(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight + padding);
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(fieldRect, prefabProp, label);
// If a new prefab has been selected

View File

@ -28,9 +28,6 @@ namespace NanoBrain.Unity {
name = name[..colonPos];
}
foreach (Node node in this.nodes) {
if (node.nucleus == null)
continue;
string nodeName = node.nucleus.name;
if (justBaseName) {
int colonPos = nodeName.IndexOf(":");