private DisposableList <HLODBuildInfo> CreateBuildInfo(TerrainData data, SpaceNode root) { DisposableList <HLODBuildInfo> results = new DisposableList <HLODBuildInfo>(); Queue <SpaceNode> trevelQueue = new Queue <SpaceNode>(); Queue <int> parentQueue = new Queue <int>(); Queue <string> nameQueue = new Queue <string>(); Queue <int> depthQueue = new Queue <int>(); int maxDepth = 0; trevelQueue.Enqueue(root); parentQueue.Enqueue(-1); nameQueue.Enqueue("HLOD"); depthQueue.Enqueue(0); while (trevelQueue.Count > 0) { int currentNodeIndex = results.Count; string name = nameQueue.Dequeue(); SpaceNode node = trevelQueue.Dequeue(); int depth = depthQueue.Dequeue(); HLODBuildInfo info = new HLODBuildInfo { Name = name, ParentIndex = parentQueue.Dequeue(), Target = node, }; for (int i = 0; i < node.GetChildCount(); ++i) { trevelQueue.Enqueue(node.GetChild(i)); parentQueue.Enqueue(currentNodeIndex); nameQueue.Enqueue(name + "_" + (i + 1)); depthQueue.Enqueue(depth + 1); } info.Heightmap = CreateSubHightmap(node.Bounds); info.WorkingObjects.Add(CreateBakedTerrain(name, node.Bounds, info.Heightmap, depth, node.GetChildCount() == 0)); info.Distances.Add(depth); results.Add(info); if (depth > maxDepth) { maxDepth = depth; } } //convert depth to distance for (int i = 0; i < results.Count; ++i) { HLODBuildInfo info = results[i]; for (int di = 0; di < info.Distances.Count; ++di) { info.Distances[di] = maxDepth - info.Distances[di]; } } return(results); }
private static int GetTargetCount(SpaceNode node) { int count = 0; Stack <SpaceNode> searchNodes = new Stack <SpaceNode>(); searchNodes.Push(node); while (searchNodes.Count > 0) { SpaceNode curNode = searchNodes.Pop(); count += curNode.Objects.Count; for (int i = 0; i < curNode.GetChildCount(); ++i) { searchNodes.Push(curNode.GetChild(i)); } } return(count); }
private static DisposableList <HLODBuildInfo> CreateBuildInfo(SpaceNode root, float minObjectSize) { List <HLODBuildInfo> resultsCandidates = new List <HLODBuildInfo>(); Queue <SpaceNode> trevelQueue = new Queue <SpaceNode>(); Queue <int> parentQueue = new Queue <int>(); Queue <string> nameQueue = new Queue <string>(); Queue <int> levelQueue = new Queue <int>(); trevelQueue.Enqueue(root); parentQueue.Enqueue(-1); levelQueue.Enqueue(0); nameQueue.Enqueue(""); while (trevelQueue.Count > 0) { int currentNodeIndex = resultsCandidates.Count; string name = nameQueue.Dequeue(); SpaceNode node = trevelQueue.Dequeue(); HLODBuildInfo info = new HLODBuildInfo { Name = name, ParentIndex = parentQueue.Dequeue(), Target = node }; for (int i = 0; i < node.GetChildCount(); ++i) { trevelQueue.Enqueue(node.GetChild(i)); parentQueue.Enqueue(currentNodeIndex); nameQueue.Enqueue(name + "_" + (i + 1)); } resultsCandidates.Add(info); //it should add to every parent. List <MeshRenderer> meshRenderers = GetMeshRenderers(node.Objects, minObjectSize); List <Collider> colliders = GetColliders(node.Objects, minObjectSize); int distance = 0; while (currentNodeIndex >= 0) { var curInfo = resultsCandidates[currentNodeIndex]; for (int i = 0; i < meshRenderers.Count; ++i) { curInfo.WorkingObjects.Add(meshRenderers[i].ToWorkingObject(Allocator.Persistent)); curInfo.Distances.Add(distance); } for (int i = 0; i < colliders.Count; ++i) { curInfo.Colliders.Add(colliders[i].ToWorkingCollider()); } currentNodeIndex = curInfo.ParentIndex; distance += 1; } } DisposableList <HLODBuildInfo> results = new DisposableList <HLODBuildInfo>(); for (int i = 0; i < resultsCandidates.Count; ++i) { if (resultsCandidates[i].WorkingObjects.Count > 0) { results.Add(resultsCandidates[i]); } else { resultsCandidates[i].Dispose(); } } return(results); }