void DrawDebug(QctreeNode <ModelObject> nodeTree) { if (nodeTree == null) { return; } Gizmos.color = Color.cyan; if (nodeTree.childNodes == null) { return; } foreach (QctreeNode <ModelObject> node in nodeTree.childNodes) { //Debug.Log(node.bounds.center); Gizmos.DrawWireCube(node.bounds.center, node.bounds.size); if (node.childNodes != null) { foreach (QctreeNode <ModelObject> chileNode in node.childNodes) { DrawDebug(chileNode); } } } }
public List <T> preOrder(QctreeNode <T> node) { if (node == null) { return(null); } List <T> orderGoList = new List <T>(); for (int g = 0; g < node.gameObjectsList.Count; g++) { orderGoList.Add(node.gameObjectsList[g]); } if (childNodes == null) { return(orderGoList); } for (int i = 0; i < 8; i++) { orderGoList.AddRange(childNodes[i].preOrder(childNodes[i])); //Debug.Log("for queryGoList: " + queryGoList.Count); } return(orderGoList); }
void SubDivide() { if (childNodes == null && level < maxLevel) //if (childNodes == null) { Debug.Log("SubDivide"); childNodes = new QctreeNode <T> [8]; float halfSizeX = bounds.size.x / 4; float halfSizeY = bounds.size.y / 4; float halfSizeZ = bounds.size.z / 4; Vector3 centerNew = new Vector3(bounds.center.x - halfSizeX, bounds.center.y + halfSizeY, bounds.center.z + halfSizeZ); Bounds boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[0] = new QctreeNode <T>(boundsNew, level + 1);//up left back centerNew = new Vector3(bounds.center.x - halfSizeX, bounds.center.y + halfSizeY, bounds.center.z - halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[1] = new QctreeNode <T>(boundsNew, level + 1);//up left front centerNew = new Vector3(bounds.center.x + halfSizeX, bounds.center.y + halfSizeY, bounds.center.z - halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[2] = new QctreeNode <T>(boundsNew, level + 1);//up right front centerNew = new Vector3(bounds.center.x + halfSizeX, bounds.center.y + halfSizeY, bounds.center.z + halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[3] = new QctreeNode <T>(boundsNew, level + 1);//up right back centerNew = new Vector3(bounds.center.x - halfSizeX, bounds.center.y - halfSizeY, bounds.center.z + halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[4] = new QctreeNode <T>(boundsNew, level + 1);//bottom left back centerNew = new Vector3(bounds.center.x - halfSizeX, bounds.center.y - halfSizeY, bounds.center.z - halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[5] = new QctreeNode <T>(boundsNew, level + 1);//bottom left front centerNew = new Vector3(bounds.center.x + halfSizeX, bounds.center.y - halfSizeY, bounds.center.z - halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[6] = new QctreeNode <T>(boundsNew, level + 1);//bottom right front centerNew = new Vector3(bounds.center.x + halfSizeX, bounds.center.y - halfSizeY, bounds.center.z + halfSizeZ); boundsNew = new Bounds(centerNew, bounds.size / 2); childNodes[7] = new QctreeNode <T>(boundsNew, level + 1);//bottom right back } }
// Use this for initialization void Start() { Spawns(); root = new QctreeNode <ModelObject>(new Bounds(Vector3.zero, new Vector3(100, 100, 100))); foreach (ModelObject g in listGo) { root.Insert(g); } //queryCenter = new Vector3(100, 100, 100); queryBound = new Bounds(queryCenter, new Vector3(30, 30, 30)); int nnn = root.QueryInBounds(queryBound).Count; Debug.Log("Count: " + nnn); listOrder = root.preOrder(root); Debug.Log(listOrder.Count); }