Compare commits
No commits in common. "74aa48b446f03a2b3e8567c654fac7be8df85651" and "1dc9252a9b29dd1cbe1c06d9812530ac4ee8f0f4" have entirely different histories.
74aa48b446
...
1dc9252a9b
@ -213,12 +213,12 @@ namespace NanoBrain.Unity {
|
|||||||
#region Full Graph
|
#region Full Graph
|
||||||
|
|
||||||
protected void DrawFullGraph() {
|
protected void DrawFullGraph() {
|
||||||
// if (this.currentNucleus == null) {
|
if (this.currentNucleus == null) {
|
||||||
// Vector3 position = new(150, 210, 0);
|
Vector3 position = new(150, 210, 0);
|
||||||
// DrawAllOutputs(position);
|
DrawAllOutputs(position);
|
||||||
// DrawOutputs(position);
|
DrawOutputs(position);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
Dag dag = GenerateGraph(this.selectedOutput);
|
Dag dag = GenerateGraph(this.selectedOutput);
|
||||||
Dag.ComputeLayout(dag);
|
Dag.ComputeLayout(dag);
|
||||||
@ -271,8 +271,8 @@ namespace NanoBrain.Unity {
|
|||||||
|
|
||||||
public Dag GenerateGraph(Nucleus rootNucleus) {
|
public Dag GenerateGraph(Nucleus rootNucleus) {
|
||||||
Dag dag = new();
|
Dag dag = new();
|
||||||
// if (rootNucleus == null)
|
if (rootNucleus == null)
|
||||||
// return dag;
|
return dag;
|
||||||
|
|
||||||
int ix = 0;
|
int ix = 0;
|
||||||
Dag.Node receiver = new() {
|
Dag.Node receiver = new() {
|
||||||
@ -281,41 +281,18 @@ namespace NanoBrain.Unity {
|
|||||||
};
|
};
|
||||||
dag.nodes.Add(receiver);
|
dag.nodes.Add(receiver);
|
||||||
ix++;
|
ix++;
|
||||||
if (rootNucleus == null)
|
|
||||||
DescendGraphFromRoot(ref ix, dag);
|
|
||||||
else
|
|
||||||
DescendGraph(receiver, ref ix, dag);
|
DescendGraph(receiver, ref ix, dag);
|
||||||
return 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) {
|
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;
|
return;
|
||||||
|
|
||||||
foreach (Synapse synapse in receiverNeuron.synapses) {
|
foreach (Synapse synapse in receiverNeuron.synapses) {
|
||||||
Nucleus nucleus = synapse.neuron;
|
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;
|
nucleus = nucleus.parent;
|
||||||
}
|
}
|
||||||
string nucleusName = nucleus.name;
|
string nucleusName = nucleus.name;
|
||||||
@ -773,13 +750,13 @@ namespace NanoBrain.Unity {
|
|||||||
|
|
||||||
Vector2 dir = to - from;
|
Vector2 dir = to - from;
|
||||||
float len = dir.magnitude;
|
float len = dir.magnitude;
|
||||||
if (len <= Mathf.Epsilon) //len <= 2f * discRadius || )
|
if (len <= 2f * discRadius || len <= Mathf.Epsilon)
|
||||||
// line too short
|
// line too short
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Vector2 n = dir / len; // normalized
|
Vector2 n = dir / len; // normalized
|
||||||
Vector2 a = from;// + n * discRadius;
|
Vector2 a = from + n * discRadius;
|
||||||
Vector2 b = to;// - n * discRadius;
|
Vector2 b = to - n * discRadius;
|
||||||
Handles.DrawLine(a, b);
|
Handles.DrawLine(a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,12 +18,13 @@ namespace NanoBrain.Unity {
|
|||||||
currentClusterView.initialized = false;
|
currentClusterView.initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const float padding = 0f;//4f;
|
||||||
private const float graphHeight = 500f; // height reserved for the VisualElement
|
private const float graphHeight = 500f; // height reserved for the VisualElement
|
||||||
private static ClusterView currentClusterView;
|
private static ClusterView currentClusterView;
|
||||||
private static UnityEngine.Object selectedTarget;
|
private static UnityEngine.Object selectedTarget;
|
||||||
|
|
||||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
|
||||||
float height = EditorGUIUtility.singleLineHeight;
|
float height = EditorGUIUtility.singleLineHeight + padding;
|
||||||
if (Cluster_Drawer.currentClusterView == null)
|
if (Cluster_Drawer.currentClusterView == null)
|
||||||
// When no cluster is viewed
|
// When no cluster is viewed
|
||||||
return height;
|
return height;
|
||||||
@ -31,10 +32,6 @@ namespace NanoBrain.Unity {
|
|||||||
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
||||||
if (prefabProp.objectReferenceValue != null && Cluster_Drawer.currentClusterView.isOpen) {
|
if (prefabProp.objectReferenceValue != null && Cluster_Drawer.currentClusterView.isOpen) {
|
||||||
height = graphHeight;
|
height = graphHeight;
|
||||||
} else {
|
|
||||||
// Unclear why this is necessary,
|
|
||||||
// but without this, expanding the graph foldout is not possible
|
|
||||||
height += EditorGUIUtility.singleLineHeight;
|
|
||||||
}
|
}
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
@ -76,7 +73,7 @@ namespace NanoBrain.Unity {
|
|||||||
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
SerializedProperty prefabProp = property.FindPropertyRelative(nameof(Cluster.prefab));
|
||||||
|
|
||||||
// Draw the object field on the top line
|
// 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.BeginChangeCheck();
|
||||||
EditorGUI.PropertyField(fieldRect, prefabProp, label);
|
EditorGUI.PropertyField(fieldRect, prefabProp, label);
|
||||||
// If a new prefab has been selected
|
// If a new prefab has been selected
|
||||||
|
|||||||
@ -28,9 +28,6 @@ namespace NanoBrain.Unity {
|
|||||||
name = name[..colonPos];
|
name = name[..colonPos];
|
||||||
}
|
}
|
||||||
foreach (Node node in this.nodes) {
|
foreach (Node node in this.nodes) {
|
||||||
if (node.nucleus == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string nodeName = node.nucleus.name;
|
string nodeName = node.nucleus.name;
|
||||||
if (justBaseName) {
|
if (justBaseName) {
|
||||||
int colonPos = nodeName.IndexOf(":");
|
int colonPos = nodeName.IndexOf(":");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user