分割网格

每个素材分割场景的所有网格

开发人员可能需要将场景的所有网格拆分为每个材质的几个子网格。split_mesh 方法不会拆分场景的网格 (如果已为其指定了单个材质)。开发人员现在可以使用 Aspose.3D for Python via .NET API 来实现此目的。

下面的代码示例按材质拆分场景的所有网格。每个子网格共享相同的直接数据,并且仅在索引上有所不同。

from aspose.threed import FileFormat, Scene
from aspose.threed.entities import PolygonModifier, SplitMeshPolicy

#  For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
#  The path to the documents directory.
input = "data-dir"  + "test.fbx"
#  Load a 3D file
scene = Scene(input)
#  Split all meshes
PolygonModifier.split_mesh(scene, SplitMeshPolicy.CLONE_DATA)
#  Save file
output = "out"  + "test-splitted.fbx"
scene.save(output, FileFormat.FBX7500ASCII)

通过指定材质来分割网格

Aspose.3D for Python via .NET API 允许开发人员通过手动指定材质来拆分网格。“分割网格” 选项创建单独的对象,每个子网格将仅使用一种材质。

分割盒子的网格

此帮助主题创建了框的网格,以保持代码的全面和简短。开发人员可以按照以下帮助主题中的说明手动构建网格: 创建 3D 立方体网格。此外,一个盒子由6个平面组成,每个平面将成为一个子网格。下面的代码示例通过手动指定材质来拆分原始网格。

from aspose import pycore
from aspose.threed.entities import Box, MappingMode, PolygonModifier, ReferenceMode, SplitMeshPolicy, VertexElementMaterial, VertexElementType

#  For complete examples and data files, please go to https:# github.com/aspose-3d/Aspose.3D-for-.NET
#  Create a mesh of box(A box is composed by 6 planes)
box = Box().to_mesh()
#  Create a material element on this mesh
mat = pycore.cast(VertexElementMaterial, box.create_element(VertexElementType.MATERIAL, MappingMode.POLYGON, ReferenceMode.INDEX))
#  And specify different material index for each plane
mat.indices.extend([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.
planes = PolygonModifier.split_mesh(box, SplitMeshPolicy.CLONE_DATA)
mat.indices.clear()
mat.indices.extend([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.split_mesh(box, SplitMeshPolicy.COMPACT_DATA)