public static void Run() { // ExStart:SplitAllMeshesofScenebyMaterial // The path to the documents directory. string input = RunExamples.GetDataFilePath("test.fbx"); // Load a 3D file Scene scene = new Scene(input); // Split all meshes PolygonModifier.SplitMesh(scene, SplitMeshPolicy.CloneData); // Save file var output = RunExamples.GetOutputFilePath("test-splitted.fbx"); scene.Save(output, FileFormat.FBX7500ASCII); // ExEnd:SplitAllMeshesofScenebyMaterial Console.WriteLine("\nSpliting all meshes of a scene per material successfully.\nFile saved at " + output); }
public static void Run() { // ExStart:SplitMeshbyMaterial // Create a mesh of box(A box is composed by 6 planes) Mesh box = (new Box()).ToMesh(); // Create a material element on this mesh VertexElementMaterial mat = (VertexElementMaterial)box.CreateElement(VertexElementType.Material, MappingMode.Polygon, ReferenceMode.Index); // And specify different material index for each plane mat.Indices.AddRange(new int[] { 0, 1, 2, 3, 4, 5 }); // Now split it into 6 sub meshes, we specified 6 different materials on each plane, each plane will become a sub mesh. // We used the CloneData policy, each plane will has the same control point information or control point-based vertex element information. Mesh[] planes = PolygonModifier.SplitMesh(box, SplitMeshPolicy.CloneData); mat.Indices.Clear(); mat.Indices.AddRange(new int[] { 0, 0, 0, 1, 1, 1 }); // Now split it into 2 sub meshes, first mesh will contains 0/1/2 planes, and second mesh will contains the 3/4/5th planes. // We used the CompactData policy, each plane will has its own control point information or control point-based vertex element information. planes = PolygonModifier.SplitMesh(box, SplitMeshPolicy.CompactData); // ExEnd:SplitMeshbyMaterial Console.WriteLine("\nSpliting a mesh by specifying the material successfully."); }