protected SceneTreeNode <T> GetContainerNode(T obj, int depth) { SceneTreeNode <T> result = null; int ix = -1; int iz = -1; int iy = m_ChildNodes.Length == 4 ? 0 : -1; int nodeIndex = 0; for (int i = ix; i <= 1; i += 2) { for (int k = iy; k <= 1; k += 2) { for (int j = iz; j <= 1; j += 2) { result = CreateNode(ref m_ChildNodes[nodeIndex], depth, m_Bounds.center + new Vector3(i * m_HalfSize.x * 0.5f, k * m_HalfSize.y * 0.5f, j * m_HalfSize.z * 0.5f), m_HalfSize, obj); if (result != null) { return(result); } nodeIndex += 1; } } } return(null); }
public SceneTreeNode <T> Insert(T obj, int depth, int maxDepth) { if (m_ObjectList.Contains(obj)) { return(this); } if (depth < maxDepth) { SceneTreeNode <T> node = GetContainerNode(obj, depth); if (node != null) { return(node.Insert(obj, depth + 1, maxDepth)); } } var n = m_ObjectList.AddFirst(obj); obj.SetLinkedListNode(0, n); return(this); }
protected SceneTreeNode <T> CreateNode(ref SceneTreeNode <T> node, int depth, Vector3 centerPos, Vector3 size, T obj) { SceneTreeNode <T> result = null; if (node == null) { Bounds bounds = new Bounds(centerPos, size); if (bounds.IsBoundsContainsAnotherBounds(obj.Bounds)) { SceneTreeNode <T> newNode = new SceneTreeNode <T>(bounds, depth + 1, m_ChildNodes.Length); node = newNode; result = node; } } else if (node.Bounds.IsBoundsContainsAnotherBounds(obj.Bounds)) { result = node; } return(result); }
public SceneTree(Vector3 center, Vector3 size, int maxDepth, bool ocTree) { this.m_MaxDepth = maxDepth; this.m_Root = new SceneTreeNode <T>(new Bounds(center, size), 0, ocTree ? 8 : 4); }