protected void UpdateEdges() { sceneComponents.AcceptEdge(edgeComponent => { AbstractGraphEdge edge = edgeComponent.GetGraphEdge(); AbstractGraphNode startNode = edge.GetStartGraphNode(); AbstractGraphNode endNode = edge.GetEndGraphNode(); sceneComponents.GetNodeComponent(startNode.GetId()).ConnectedRb.Add(sceneComponents.GetNodeComponent(endNode.GetId()).Rb); sceneComponents.GetNodeComponent(endNode.GetId()).ConnectedRb.Add(sceneComponents.GetNodeComponent(startNode.GetId()).Rb); edgeComponent.UpdateGeometry( sceneComponents.GetNodeComponent(startNode.GetId()).GetVisualComponent().transform.position, sceneComponents.GetNodeComponent(endNode.GetId()).GetVisualComponent().transform.position); }); float MostEdgesNodeCount = 0; foreach (var n in sceneComponents.nodeComponents) { if (n.ConnectedRb.Count > MostEdgesNodeCount) { MostEdgesNodeCount = n.ConnectedRb.Count; } } foreach (var n in sceneComponents.nodeComponents) { if (n.ConnectedRb.Count == MostEdgesNodeCount) { n.SetPosition(Vector3.zero); } } }
public List <AbstractGraphEdge> FindEdges(long startOrEndNodeId, long endOrStartNodeId) { return(AllGraphEdges.FindAll(edge => { AbstractGraphNode startNode = edge.GetStartGraphNode(); AbstractGraphNode endNode = edge.GetEndGraphNode(); return (startNode.GetId() == startOrEndNodeId && endNode.GetId() == endOrStartNodeId) || (startNode.GetId() == endOrStartNodeId && endNode.GetId() == startOrEndNodeId); })); }
private void InitializeNodeComponent() { SpriteRenderer sprite = GetVisualComponent().GetComponent <SpriteRenderer> (); sprite.name = "Node_" + graphNode.GetId(); TextMesh text = GetVisualComponent().GetComponentInChildren <TextMesh>(); text.text = "" + graphNode.GetId(); }
private void InitializeNodeComponent() { SpriteRenderer sprite = GetVisualComponent().GetComponent <SpriteRenderer> (); sprite.name = "Node_" + graphNode.GetId(); TextMesh text = GetVisualComponent().GetComponentInChildren <TextMesh>(); text.text = "" + graphNode.GetTitle(); if (graphNode.GetNType() == "M") { GetVisualComponent().GetComponentInChildren <SpriteRenderer>().material.color = Color.yellow; } Node = GetVisualComponent().GetComponentInChildren <Node>(); Node.ID = graphNode.GetNid(); Node.Title = "ID: " + Node.ID + " " + graphNode.GetTitle(); Node.Content = graphNode.GetContent(); Node.FVdata = new NeoUnity.ForceVectorData(); Rb = Node.GetComponent <Rigidbody>(); LayerMask mask = 1 << LayerMask.NameToLayer("Node"); Physics.OverlapSphereNonAlloc(Rb.transform.position, GraphRenderer.Singleton.nodePhysXForceSphereRadius, aoundColliders, mask); // Physics.OverlapSphere calls gc //hitResult = Physics.OverlapSphere(Rb.transform.position, sphRadius, mask); }
public List <AbstractGraphEdge> FindEdges(long nodeId) { return(AllGraphEdges.FindAll(edge => { AbstractGraphNode startNode = edge.GetStartGraphNode(); AbstractGraphNode endNode = edge.GetEndGraphNode(); return startNode.GetId() == nodeId || endNode.GetId() == nodeId; })); }
private void DrawGraphEdge(AbstractGraphEdge edge) { if (graphSceneComponents.HasEdgeComponent(edge)) { return; } EdgeComponent edgeComponent = new EdgeComponent(edge, graphScenePrefabs.InstantiateEdge()); graphSceneComponents.AddEdgeComponent(edgeComponent); NodeComponent startNode = graphSceneComponents.GetNodeComponent(edgeComponent.GetGraphEdge().GetStartGraphNode().GetId()); NodeComponent endNode = graphSceneComponents.GetNodeComponent(edgeComponent.GetGraphEdge().GetEndGraphNode().GetId()); if (endNode == null) { return; } SpringJoint spring = endNode.GetVisualComponent().GetComponent <SpringJoint> (); spring.connectedBody = startNode.GetVisualComponent().GetComponent <Rigidbody> (); // checking if there is any other edge connecting the same nodes long sameNodeConnections = 0; graphSceneComponents.AcceptEdge(existingEdgeComponent => { AbstractGraphEdge existingEdge = existingEdgeComponent.GetGraphEdge(); AbstractGraphNode existingStartNode = existingEdge.GetStartGraphNode(); AbstractGraphNode existingEndNode = existingEdge.GetEndGraphNode(); if ( existingStartNode.GetId() == startNode.GetGraphNode().GetId() && existingEndNode.GetId() == endNode.GetGraphNode().GetId() || existingStartNode.GetId() == endNode.GetGraphNode().GetId() && existingEndNode.GetId() == startNode.GetGraphNode().GetId() ) { sameNodeConnections = sameNodeConnections + 1; } }); if (sameNodeConnections > 1) { edgeComponent.MultiEdge = true; } }
public GameObject InstantiateNode(AbstractGraphNode nodePointer) { if (nodePointer.GetSuburb() == true) { GameObject node = Instantiate(SuburbPrefab); node.transform.SetParent(transform); return(node); } else { if (nodePointer.GetId() == 0) { GameObject node = Instantiate(RootPrefab); node.transform.SetParent(transform); return(node); } else { GameObject node = Instantiate(NodePrefab); node.transform.SetParent(transform); return(node); } } }
public bool HasNodeComponent(AbstractGraphNode graphNode) { return(nodeComponents.Exists(nodeComponent => { return nodeComponent.GetGraphNode().GetId() == graphNode.GetId(); })); }
public void Update(float time) { graphSceneComponents.AcceptEdge(edgeComponent => { AbstractGraphEdge edge = edgeComponent.GetGraphEdge(); AbstractGraphNode startNode = edge.GetStartGraphNode(); AbstractGraphNode endNode = edge.GetEndGraphNode(); NodeComponent startNodeComponent = graphSceneComponents.GetNodeComponent(startNode.GetId()); NodeComponent endNodeComponent = graphSceneComponents.GetNodeComponent(endNode.GetId()); // ---- distance function start float distance = 1F / startNode.GetDegree(); distance *= 100; distance *= 4; SpringJoint springJoint = endNodeComponent.GetVisualComponent().GetComponent <SpringJoint>(); springJoint.maxDistance = distance; springJoint.minDistance = distance; SphereCollider collider = endNodeComponent.GetVisualComponent().GetComponent <SphereCollider>(); collider.radius = distance * 0.3F; endNodeComponent.GetVisualComponent().GetComponent <Rigidbody>().mass = 5; // ---- distance function end // magic Rigidbody body = endNodeComponent.GetVisualComponent().GetComponent <Rigidbody>(); body.inertiaTensor = new Vector3(0.01F, 0.01F, 0.01F); edgeComponent.UpdateGeometry( startNodeComponent.GetVisualComponent().transform.position, endNodeComponent.GetVisualComponent().transform.position); }); // graphLayout.DoLayout (time); }
public override bool IsAdjacent(AbstractGraphNode graphNode) { return(graphBackend.FindEdges(id, graphNode.GetId()).Count > 0); }