public OctTree <TriangleBound> ConstructSceneOctree(List <TriangleInfo> sceneTriangles, Bounds bound) { int count = 0; AABBBoundBox maxBound = new AABBBoundBox(bound); _octree = new OctTree <TriangleBound>(maxBound); List <TriangleInfo> triangleList = new List <TriangleInfo>(triangleCountInOneGroup); foreach (TriangleInfo tri in sceneTriangles) { triangleList.Add(tri); if (triangleList.Count == triangleCountInOneGroup) { TriangleBound triangleBound = GroupBoundBox(triangleList); //boundList.Add(triangleBound); if (maxBound.Contains(triangleBound.GetBoundBox()) || maxBound.Overlap(triangleBound.boundBox)) { _octree.Insert(triangleBound); count++; } triangleList.Clear(); } } if (triangleList.Count != 0) { _octree.Insert(GroupBoundBox(triangleList)); count++; } Debug.Log(count); _octree.UpdateTree(); return(_octree); }
private TriangleBound GroupBoundBox(List <TriangleInfo> infoList) { TriangleBound triangeBound = new TriangleBound(); AABBBoundBox bound = new AABBBoundBox(Vector3.positiveInfinity, Vector3.negativeInfinity); triangeBound.triangles = new TriangleInfo[infoList.Count]; for (int i = 0; i < infoList.Count; i++) { triangeBound.triangles[i] = infoList[i]; bound.Extend(infoList[i].p1); bound.Extend(infoList[i].p2); bound.Extend(infoList[i].p3); } triangeBound.boundBox = bound; return(triangeBound); }