private void RealizeNode(MCMesh m) { Debug.Log("Realizing node!"); GameObject clone = UnityEngine.Object.Instantiate(MeshPrefab, new Vector3(0, 0, 0), Quaternion.identity); Color c = UtilFuncs.SinColor(m.nodeDepth * 3f); clone.GetComponent <MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f); clone.transform.localScale = Vector3.one * (WorldSize * m.nodeSize / Resolution); clone.name = "Node " + m.nodeID + ", Depth " + m.nodeDepth; MeshFilter mf = clone.GetComponent <MeshFilter>(); Mesh um = new UnityEngine.Mesh(); um.SetVertices(m.Vertices); um.SetNormals(m.Normals); um.triangles = m.Triangles; mf.mesh = um; clone.GetComponent <Transform>().SetParent(Parent); clone.GetComponent <Transform>().SetPositionAndRotation(m.nodePosition * WorldSize, Quaternion.identity); UnityObjects[m.nodeID] = clone; }
GameObject Meshify(Chunks.Chunk chunk) { GameObject clone = Object.Instantiate(ChunkPrefab, new Vector3(0, 0, 0), Quaternion.identity); Color c = UtilFuncs.SinColor(chunk.LOD * 3f); clone.GetComponent <MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f); clone.GetComponent <MeshRenderer>().material.SetInt("_LOD", chunk.LOD); clone.GetComponent <MeshRenderer>().material.SetVector("_ChunkPosition", new Vector4(chunk.Position.x, chunk.Position.y, chunk.Position.z)); clone.name = "BENCHMARK test Node " + chunk.Key + ", LOD " + chunk.LOD; MeshFilter mf = clone.GetComponent <MeshFilter>(); mf.mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; mf.mesh.SetVertices(chunk.Vertices); mf.mesh.SetNormals(chunk.Normals); //mf.mesh.SetUVs(0, chunk.LOD1Vertices); //mf.mesh.SetUVs(1, chunk.LOD1Normals); mf.mesh.triangles = chunk.Triangles; clone.GetComponent <Transform>().SetPositionAndRotation(chunk.Position, Quaternion.identity); clone.GetComponent <Transform>().localScale = Vector3.one * ((float)MinimumChunkSize / (float)Resolution) * Mathf.Pow(2, chunk.LOD); chunk.UnityObject = clone; return(clone); }
public void MeshNode(Node node, ref float totalPolyganizeNodeTime, ref float totalAllBeforeTime, System.Diagnostics.Stopwatch sw) { sw.Start(); GameObject clone = Object.Instantiate(MeshPrefab, new Vector3(0, 0, 0), Quaternion.identity); Color c = UtilFuncs.SinColor(node.Depth * 3f); clone.GetComponent <MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f); clone.transform.localScale = Vector3.one * (WorldSize * node.Size / Resolution); clone.name = "Node " + node.ID + ", Depth " + node.Depth; MeshFilter mf = clone.GetComponent <MeshFilter>(); sw.Stop(); totalAllBeforeTime += (float)sw.ElapsedMilliseconds / 1000f; sw.Reset(); sw.Start(); MCMesh mcm = SE.Octree.Ops.PolyganizeNode(node, WorldSize, Resolution); Mesh m = new Mesh(); m.SetVertices(mcm.Vertices); m.SetNormals(mcm.Normals); m.triangles = mcm.Triangles; mf.mesh = m; sw.Stop(); totalPolyganizeNodeTime += (float)sw.ElapsedMilliseconds / 1000f; clone.GetComponent <Transform>().SetParent(Parent); clone.GetComponent <Transform>().SetPositionAndRotation(node.Position * WorldSize, Quaternion.identity); UnityObjects[node.ID] = clone; }
public void ExtractSparseOctreeAux(Node node, RT.CS.Node sNode) { for (int i = 0; i < 8; i++) { Node child = node.children[i]; if (child != null) { if (sNode.children == null) { sNode.children = new RT.CS.Node[8]; } sNode.children[i] = new RT.CS.Node(child.position, child.size, sNode.level + 1, false); if (child.chunk != null) { sNode.leaf = true; sNode.color = UtilFuncs.SinColor(sNode.position.x + sNode.position.y + sNode.position.z); sNode.normal = Vector3.up; } else { ExtractSparseOctreeAux(child, sNode.children[i]); } } } }
public void ClearLastRayNodeList() { foreach (Node node in currentlyRayedNodes) { //Debug.Log("Clearing node..."); node.Color = UtilFuncs.SinColor(node.Depth); node.Color.a = 0.8f; } currentlyRayedNodes.Clear(); }
public virtual ColoredBox GetColoredBox() { ColoredBox box = new ColoredBox(); box.Center = GetCenter(); box.Color = UtilFuncs.SinColor(level * 2f); box.Color.a = 0.07f; box.Size = Vector3.one * (float)size; return(box); }
public static void DrawOctreeGizmosRecursive(Node node, int depth) { if (node == null) { return; } Gizmos.color = UtilFuncs.SinColor(depth); Gizmos.DrawWireCube(node.position + (Vector3.one * node.size) / 2, node.size * Vector3.one); for (int i = 0; i < 8; i++) { DrawOctreeGizmosRecursive(node.children[i], depth + 1); } }
public void ConstructNode(Node node, int maxDepth, UtilFuncs.Sampler sample) { node.Color = UtilFuncs.SinColor(node.Depth); node.Color.a = 0.8f; if (node.Depth == maxDepth) { node.IsLeaf = true; Vector3 center = node.Min + (Vector3.one * node.Size) / 2f; node.ContainsSurface = sample(center.x, center.y, 0) < 0 ? true : false; node.CompletelyFilled = node.ContainsSurface; } else { node.IsLeaf = false; node.Children = new Node[4]; node.CompletelyFilled = true; for (int i = 0; i < 4; i++) { //Debug.Log("Created child with depth " + (node.Depth + 1)); node.Children[i] = new Node(); node.Children[i].Parent = node; node.Children[i].Size = node.Size / 2f; node.Children[i].Min = node.Min + Constants.qoffsets[i] * (node.Size / 2f); node.Children[i].Depth = node.Depth + 1; ConstructNode(node.Children[i], maxDepth, sample); node.ContainsSurface |= node.Children[i].ContainsSurface; if (!node.Children[i].CompletelyFilled) { node.CompletelyFilled = false; } } if (!node.ContainsSurface) { node.Children = null; node.IsLeaf = true; } if (node.CompletelyFilled) // All children have surface { node.Children = null; node.IsLeaf = true; } } }
public void UploadChunk(Chunk chunk) { Interlocked.Decrement(ref NumChunksRemaining); //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); //sw.Start(); if (chunk.State == ChunkState.Cancelled) { return; } //Debug.Log("Uploading chunk..."); chunk.State = ChunkState.Uploading; GameObject clone = UnityObjectPool.GetObject(); Color c = UtilFuncs.SinColor(chunk.LOD * 3f); clone.GetComponent <MeshRenderer>().material.color = new Color(c.r, c.g, c.b, 0.9f); clone.GetComponent <MeshRenderer>().material.SetInt("_LOD", chunk.LOD); clone.GetComponent <MeshRenderer>().material.SetVector("_ChunkPosition", new Vector4(chunk.Position.x, chunk.Position.y, chunk.Position.z)); clone.name = "Node " + chunk.Key + ", LOD " + chunk.LOD; MeshFilter mf = clone.GetComponent <MeshFilter>(); mf.mesh.SetVertices(chunk.Vertices); mf.mesh.SetNormals(chunk.Normals); //mf.mesh.SetUVs(0, chunk.LOD1Vertices); //mf.mesh.SetUVs(1, chunk.LOD1Normals); mf.mesh.triangles = chunk.Triangles; clone.GetComponent <Transform>().SetParent(Parent); clone.GetComponent <Transform>().SetPositionAndRotation(chunk.Position, Quaternion.identity); clone.GetComponent <Transform>().localScale = Vector3.one * ((float)MinimumChunkSize / (float)Resolution) * Mathf.Pow(2, chunk.LOD); chunk.State = ChunkState.Completed; chunk.UnityObject = clone; //sw.Stop(); //Debug.Log("Uploading mesh took " + sw.ElapsedMilliseconds + "ms"); }
public static void DrawNode(Node node, float worldSize) { Gizmos.color = UtilFuncs.SinColor(((float)(node.Depth) * 15f)); UnityEngine.Gizmos.DrawWireCube((node.Position + new Vector3(node.Size / 2f, node.Size / 2f, node.Size / 2f)) * worldSize, node.Size * Vector3.one * worldSize); }