void VisStepBranchInto(VisData visData, Transform parent) { if (visData == null) { return; } GameObject rootObjToSpawn = new GameObject("vis" + visData.id); VisInstance iRootVis = rootObjToSpawn.AddComponent <VisInstance>(); iRootVis.Visi = visData; iRootVis.SetSceneHandler(this); rootObjToSpawn.transform.parent = parent; if (visData.leftChild != 0) { ushort uLeftChild = (ushort)(visData.leftChild & 0x3fff); VisData leftChild = visdata.Find(cc => cc.id == uLeftChild); VisStepBranchInto(leftChild, rootObjToSpawn.transform); } if (visData.rightChild != 0) { ushort uRightChild = (ushort)(visData.rightChild & 0x3fff); VisData rightChild = visdata.Find(cc => cc.id == uRightChild); VisStepBranchInto(rightChild, rootObjToSpawn.transform); } }
private void DrawQuads(VisData node, int depth, List <VisData> camList) { if (node.IsLeaf) { uint ptrQuadBlock = (uint)(uint)(((node.ptrQuadBlock) / LevelShift.Div) + LevelShift.Offset); uint numQuadBlock = node.numQuadBlock; for (int i = 0; i < numQuadBlock; i++) { long index = ptrQuadBlock + i; Gizmos.color = new Color(1, 0, 1, 0.333f); if (index < 0 && index > (visiQuadCompId.Count - 1)) { break; } VisiQuad quad = visiQuadCompId[(int)Mathf.Min(Mathf.Max(index, 0), visiQuadCompId.Count - 1)]; if (Vector3.Distance(quad.Position, camera.transform.position) < 32.0f) { Transform child = quad.transform.GetChild(1); child.gameObject.SetActive(false); child = quad.transform.GetChild(0); child.gameObject.SetActive(true); } else if (Vector3.Distance(quad.Position, camera.transform.position) < 128.0f) { Transform child = quad.transform.GetChild(1); child.gameObject.SetActive(true); child = quad.transform.GetChild(0); child.gameObject.SetActive(false); } else { Transform child = quad.transform.GetChild(1); child.gameObject.SetActive(false); child = quad.transform.GetChild(0); child.gameObject.SetActive(false); } } } else { VisData leftNode = visdata[node.leftChild & 0x3fff]; VisData rightNode = visdata[node.rightChild & 0x3fff]; Bounds bounds = node.bbox.GetBounds(); bool canRender = false; if (GeometryUtility.TestPlanesAABB(planes, bounds)) { canRender = true; } else if (depth > 0 && camList.Contains(node)) { canRender = true; depth--; } if (canRender) { DrawQuads(leftNode, depth - 1, camList); DrawQuads(rightNode, depth - 1, camList); } } }
private List <VisData> FindCameraNodes(VisData node, List <VisData> camList, int maxDepth) { List <VisData> visArr; if (maxDepth > 0) { maxDepth--; VisData leftNode = visdata[node.leftChild & 0x3fff]; VisData rightNode = visdata[node.rightChild & 0x3fff]; if (leftNode != null && !camList.Contains(leftNode) && leftNode.bbox.IsInside(camera.transform.position)) { visArr = FindCameraNodes(leftNode, camList, maxDepth); visArr.Add(leftNode); return(visArr); } if (rightNode != null && !camList.Contains(rightNode) && rightNode.bbox.IsInside(camera.transform.position)) { visArr = FindCameraNodes(rightNode, camList, maxDepth); visArr.Add(rightNode); return(visArr); } } visArr = new List <VisData>(); visArr.Add(node); return(visArr); }
void GenerateVis() { levelVisData = new GameObject("levelVisData"); levelVisData.transform.parent = transform; levelVisData.transform.localPosition = Vector3.zero; // Draw a semitransparent blue cube at the transforms position Gizmos.color = new Color(1, 0, 0, 0.5f); int i = 0; VisData rootVis = visdata[0]; VisStepBranchInto(rootVis, levelVisData.transform); }
private int levelShiftDivide = 92; // one step width /// <summary> /// Return QuadBlocks associated with the leaf, make sure you pass a leaf and not a branch. /// </summary> /// <param name="leaf"></param> public List <QuadBlock> GetListOfLeafQuadBlocks(VisData leaf) { List <QuadBlock> leafQuadBlocks = new List <QuadBlock>(); uint ptrQuadBlock = (uint)(((leaf.ptrQuadBlock) / levelShiftDivide) + levelShiftOffset); uint numQuadBlock = leaf.numQuadBlock; for (int i = 0; i < numQuadBlock; i++) { long index = ptrQuadBlock + i; QuadBlock quad = quads[(int)Math.Min(Math.Max(index, 0), quads.Count - 1)]; leafQuadBlocks.Add(quad); } return(leafQuadBlocks); }
/// <summary> /// Returns VisData children /// </summary> /// <param name="visData"></param> public List<VisData> GetVisDataChildren(VisData visData) { List<VisData> childVisData = new List<VisData>(); if (visData.leftChild != 0 && !visData.IsLeaf) // in the future: handle leaves different. Draw them? { ushort uLeftChild = (ushort)(visData.leftChild & 0x3fff); VisData leftChild = visdata.Find(cc => cc.id == uLeftChild); childVisData.Add(leftChild); } if (visData.rightChild != 0 && !visData.IsLeaf) // in the future: handle leaves different. Draw them? { ushort uRightChild = (ushort)(visData.rightChild & 0x3fff); VisData rightChild = visdata.Find(cc => cc.id == uRightChild); childVisData.Add(rightChild); } return childVisData; }