public void Load(NavTreeReader reader, SpatialNode parent) { this.parent = parent; Load(reader); }
public void Rebuild(List <Vector3> vertices) { if (isStatic) { // if a node is static, then it is a leaf node and will always retain it's state return; } if (containsStatic) { // if a node contains a static node, then it must be a parent node. for (int i = 0; i < 8; i++) { children[i].Rebuild(vertices); } } else { // a node that is non-static and does not contain a static node must be a leaf node, or a non-static node that contains a temporary obstruction. List <Vector3> verticesInBounds = new List <Vector3>(); obstructed = false; for (int i = 0; i < vertices.Count; i++) { if (InBounds(vertices[i])) { obstructed = true; verticesInBounds.Add(vertices[i]); } } // if this node is obstructed, then it's children must be build downward if (obstructed && path.Length < NavTreeManager.instance.maxTreeDepth) { children = new SpatialNode[8]; for (int i = 0; i < 8; i++) { // assemble path int[] childPath = new int[path.Length + 1]; for (int k = 0; k < path.Length; k++) { childPath[k] = path[k]; } childPath[path.Length] = i; // start at center of bottom right front corner( one * size / 4) // add size to x if index is even // add size to y if index / 2 is equal to 0 or 2 // add size to z if index / 4 is greater than 1 Vector3 childPosition = position - Vector3.one * size / 4 + new Vector3( (i % 2) * (size / 2), (i / 2) % 2 == 0 || (i / 2) % 2 == 2 ? size / 2 : 0, (i / 4) * size / 2 ); children[i] = new SpatialNode( childPosition, size / 2, childPath, this, tree, verticesInBounds ); } } else { // if this node contains no vertices, delete all of it's children children = null; } } }
private float DistToNode(Vector3 position, SpatialNode node) { return((position - node.position).sqrMagnitude); }