private int xAddNode(TGeoNode node) { int i = xNodes.Count; xNodes.Add(node); return(i); }
protected void xSubdivide(int treeNodeIndex) { if (xTriTree[treeNodeIndex].children[0] < 0) { int[] subNodes = new int[3]; for (int i = 0; i < 3; i++) { int v1 = xTriTree[treeNodeIndex].vertices[i]; int v2 = xTriTree[treeNodeIndex].vertices[(i + 1) % 3]; int v12 = xFindNodesCommonAdjacency(v1, v2, xSubdivisionLevel + 1); if (v12 < 0) { TGeoNode newnode = new TGeoNode(); newnode.position = (xNodes[v1].position + xNodes[v2].position).normalized; newnode.radius = 1f; newnode.adjacency = new List <int[]>(); v12 = xAddNode(newnode); xConnectNodes(v12, v1, xSubdivisionLevel + 1); xConnectNodes(v12, v2, xSubdivisionLevel + 1); } subNodes[i] = v12; } xConnectNodes(subNodes[0], subNodes[1], xSubdivisionLevel + 1); xConnectNodes(subNodes[1], subNodes[2], xSubdivisionLevel + 1); xConnectNodes(subNodes[2], subNodes[0], xSubdivisionLevel + 1); // /\ // / \ // /----\ // / \ / \ // /___\/___\ xAddTriTreeNode(new int[3] { xTriTree[treeNodeIndex].vertices[0], subNodes[0], subNodes[2] }, treeNodeIndex); xAddTriTreeNode(new int[3] { xTriTree[treeNodeIndex].vertices[1], subNodes[1], subNodes[0] }, treeNodeIndex); xAddTriTreeNode(new int[3] { xTriTree[treeNodeIndex].vertices[2], subNodes[2], subNodes[1] }, treeNodeIndex); xAddTriTreeNode(new int[3] { subNodes[0], subNodes[1], subNodes[2] }, treeNodeIndex); } else { foreach (int childNode in xTriTree[treeNodeIndex].children) { xSubdivide(childNode); } } }
public void BuildIcosahedron() { const float A = 0.5f; const float B = 0.30901699437f; // 1/(1+Sqrt(5)) Vector3[] icoverts = new Vector3[12] { new Vector3(0f, -B, -A), new Vector3(0f, -B, A), new Vector3(0f, B, -A), new Vector3(0f, B, A), new Vector3(-A, 0f, -B), new Vector3(-A, 0f, B), new Vector3(A, 0f, -B), new Vector3(A, 0f, B), new Vector3(-B, -A, 0f), new Vector3(-B, A, 0f), new Vector3(B, -A, 0f), new Vector3(B, A, 0f) }; int[][] icotris = new int[20][] { new int[3] { 2, 9, 11 }, new int[3] { 3, 11, 9 }, new int[3] { 3, 5, 1 }, new int[3] { 3, 1, 7 }, new int[3] { 2, 6, 0 }, new int[3] { 2, 0, 4 }, new int[3] { 1, 8, 10 }, new int[3] { 0, 10, 8 }, new int[3] { 9, 4, 5 }, new int[3] { 8, 5, 4 }, new int[3] { 11, 7, 6 }, new int[3] { 10, 6, 7 }, new int[3] { 3, 9, 5 }, new int[3] { 3, 7, 11 }, new int[3] { 2, 4, 9 }, new int[3] { 2, 11, 6 }, new int[3] { 0, 8, 4 }, new int[3] { 0, 6, 10 }, new int[3] { 1, 5, 8 }, new int[3] { 1, 10, 7 } }; int[][] icoadj = new int[12][] { new int[5] { 8, 2, 4, 10, 6 }, new int[5] { 8, 10, 3, 5, 7 }, new int[5] { 0, 9, 11, 4, 6 }, new int[5] { 7, 9, 11, 5, 1 }, new int[5] { 0, 9, 2, 5, 8 }, new int[5] { 8, 1, 3, 4, 9 }, new int[5] { 0, 2, 11, 10, 7 }, new int[5] { 11, 1, 10, 3, 6 }, new int[5] { 0, 1, 10, 4, 5 }, new int[5] { 3, 2, 11, 4, 5 }, new int[5] { 8, 1, 6, 0, 7 }, new int[5] { 9, 2, 3, 6, 7 } }; for (int i = 0; i < icoverts.Length; i++) { TGeoNode node = new TGeoNode(); node.position = icoverts[i].normalized; node.radius = 1f; node.adjacency.Add(icoadj[i]); xNodes.Add(node); } for (int i = 0; i < icotris.Length; i++) { xAddTriTreeNode(icotris[i]); } }