public void Add(Tri t) { if (tris != null) { tris.Add(t); } else { if (boundsChildA.Intersects(t.Bounds)) { if (childA == null) { childA = new SpatialBinaryTreeNode(level + 1, maxLevels, boundsChildA); } childA.Add(t); } if (boundsChildB.Intersects(t.Bounds)) { if (childB == null) { childB = new SpatialBinaryTreeNode(level + 1, maxLevels, boundsChildB); } childB.Add(t); } } }
public SpatialBinaryTree(Mesh m, int maxLevels, bool outputProgress = false) { var boundingBox = new BoundingBox( new Interval(m.vertices.Min(v => v.x), m.vertices.Max(v => v.x)), new Interval(m.vertices.Min(v => v.y), m.vertices.Max(v => v.y)), new Interval(m.vertices.Min(v => v.z), m.vertices.Max(v => v.z))); root = new SpatialBinaryTreeNode(0, maxLevels, boundingBox); var triCount = m.triangles.Length / 3; for (var i = 0; i < triCount; i++) { var v1 = m.vertices[m.triangles[i * 3]]; var v2 = m.vertices[m.triangles[i * 3 + 1]]; var v3 = m.vertices[m.triangles[i * 3 + 2]]; var t = new Tri(v1, v2, v3); Add(t); if (triCount > 20 && (i % (triCount / 20) == 0)) { Debug.Log("Spatial Tree Progress: " + (i + 1) + " / " + triCount); } } }
public SpatialBinaryTree(Mesh m, int maxLevels) { var boundingBox = new BoundingBox( new Interval(m.vertices.Min(v => v.x), m.vertices.Max(v => v.x)), new Interval(m.vertices.Min(v => v.y), m.vertices.Max(v => v.y)), new Interval(m.vertices.Min(v => v.z), m.vertices.Max(v => v.z))); root = new SpatialBinaryTreeNode(0, maxLevels, boundingBox); var triCount = m.triangles.Length / 3; for (var i = 0; i < triCount; i++) { var v1 = m.vertices[m.triangles[i * 3]]; var v2 = m.vertices[m.triangles[i * 3 + 1]]; var v3 = m.vertices[m.triangles[i * 3 + 2]]; var t = new Tri(v1, v2, v3); Add(t); } }