public NodeDS Node(NodeDS treeDS) { return(client.Node(treeDS)); }
void TestLoadGraph() { int kern = cs.FindKernel("HookesLaw"); print(kern); cs.SetFloat("springLength", _springLength); cs.SetFloat("springk", springk); //RenderTexture tex = new RenderTexture(256, 256, 24); // renderTarget.enableRandomWrite = true; renderTarget.Create(); // // cs.SetTexture(kern, "res", renderTarget); // cs.Dispatch(kern, 50, 50, 1); // var nodeLookup = new Dictionary <string, Node>(); var sr = new System.IO.StringReader(_dataFile.text); //var lines = _dataFile.text.Split(new string[]{"\r\n", "\r", "\n"}, StringSplitOptions.None); while (true) { var line = sr.ReadLine(); if (line == null) { break; } if (line.Trim().Length > 0) { var tokens = line.Split(new string[] { "\t", " " }, StringSplitOptions.None); var n1tok = tokens[0]; var n2tok = tokens[1]; if (!nodeLookup.ContainsKey(n1tok)) { nodeLookup[n1tok] = CreateRandomNode(); } if (!nodeLookup.ContainsKey(n2tok)) { nodeLookup[n2tok] = CreateRandomNode(); } CreateEdge(nodeLookup[n1tok], nodeLookup[n2tok]); } if (_nodes.Count >= _maxGraphSize) { break; } } print("nodes: " + _nodes.Count); int nodeCount = _nodes.Count; adjacencyMatrix = new int[_nodes.Count * _nodes.Count]; nodeAcc = new Vector3[_nodes.Count * _nodes.Count]; nodeVel = new Vector3[_nodes.Count]; nodeAccBuffer = new ComputeBuffer(nodeAcc.Length, 3 * 4); nodeVelBuffer = new ComputeBuffer(nodeVel.Length, 3 * 4); for (int i = 0; i < nodeAcc.Length; ++i) { nodeAcc [i] = new Vector3(); adjacencyMatrix [i] = new int(); } for (int i = 0; i < nodeVel.Length; ++i) { nodeVel[i] = new Vector3(); } shaderInput = new NodeDS[_nodes.Count]; for (int i = 0; i < _nodes.Count; ++i) { shaderInput[i] = new NodeDS { pos = _nodes[i].pos, acc = new Vector3(), vel = _nodes[i].vel }; } dataBuffer = new ComputeBuffer(shaderInput.Length, 3 * 4 * 3); dataBuffer.SetData(shaderInput); shaderEdges = new EdgeDS[_edges.Count]; for (int i = 0; i < _edges.Count; ++i) { shaderEdges [i] = new EdgeDS(); shaderEdges [i].id1 = _nodes.IndexOf(_edges [i].Body1); shaderEdges [i].id2 = _nodes.IndexOf(_edges [i].Body2); adjacencyMatrix [nodeCount * shaderEdges [i].id2 + shaderEdges [i].id1] = 1; } edgeBuffer = new ComputeBuffer(shaderEdges.Length, 4 * 2); edgeBuffer.SetData(shaderEdges); adjacencyMatrixBuffer = new ComputeBuffer(adjacencyMatrix.Length, 4); adjacencyMatrixBuffer.SetData(adjacencyMatrix); for (int i = 0; i < nodeCount; ++i) { shaderInput[i].pos = _nodes[i].pos; shaderInput[i].acc = new Vector3(); shaderInput[i].vel = _nodes[i].vel; } }