public AddTriangles ( List |
||
triangles | List |
|
Résultat | void |
/** * Create a new BSPTree instance from @mesh using @transform * to transform all vertices, normals, and tangents. */ public static BSPTree FromMesh(Mesh mesh, Matrix4x4 transform) { BSPTree tree = new BSPTree(); // get a list of all triangles in @mesh List <Triangle> meshTriangles = GetMeshTriangles(mesh); // loop through each triangle and transform its vertices by @transform for (int i = 0; i < meshTriangles.Count; i++) { Triangle tri = meshTriangles[i]; for (int vi = 0; vi < 3; vi++) { Vertex vtx = TransformVertex(tri.GetVertexByIndex(vi), transform); tri.SetVertexByIndex(vi, vtx); } tri.RebuildOrientationPlane(); meshTriangles[i] = tri; } tree.AddTriangles(meshTriangles); return(tree); }
/** * Returns geometry corresponding to volume @a that is divided into * two separate pieces by @b. Return results in the form of two BSPTree * instances: @side and @side2. */ public static void Slice(BSPTree a, BSPTree b, out BSPTree side1, out BSPTree side2) { side1 = a.Clone(); BSPTree bClone = b.Clone(); List <Triangle> side1Discarded = new List <Triangle>(); bClone.Invert(); bClone.ClipByTree(a, false); side1.ClipByTree(b, true, side1Discarded); side1.AddTriangles(bClone.GetAllTriangles()); bClone.Invert(); side2 = new BSPTree(); side2.AddTriangles(bClone.GetAllTriangles()); side2.AddTriangles(side1Discarded); }
/** * Returns geometry corresponding to volume that is occupied by @a, * but not by @b. */ public static BSPTree Subtract(BSPTree a, BSPTree b) { BSPTree aClone = a.Clone(); BSPTree bClone = b.Clone(); float startTime = Time.realtimeSinceStartup; bClone.Invert(); bClone.ClipByTree(a, false); aClone.ClipByTree(b); aClone.AddTriangles(bClone.GetAllTriangles()); return(aClone); }
/** * Returns geometry corresponding to volume @a that is divided into * two separate pieces by @b. Return results in the form of two BSPTree * instances: @side and @side2. */ public static void Slice(BSPTree a, BSPTree b, out BSPTree side1, out BSPTree side2) { side1 = a.Clone(); BSPTree bClone = b.Clone(); List<Triangle> side1Discarded = new List<Triangle>(); bClone.Invert (); bClone.ClipByTree (a, false); side1.ClipByTree (b, true, side1Discarded); side1.AddTriangles(bClone.GetAllTriangles()); bClone.Invert(); side2 = new BSPTree(); side2.AddTriangles(bClone.GetAllTriangles()); side2.AddTriangles(side1Discarded); }