将网格转换为三角形网格,将原始形状转换为网格
Contents
[
Hide
]
使用顶点的自定义内存布局将网格转换为三角形网格
Aspose。3D for Java API 支持使用顶点的自定义内存布局将网格转换为三角形网格。顶点的自定义内存布局由代码示例中的 VertexDeclaration
类动态定义。
此帮助主题从框和球体创建网格,以保持代码的全面和简短。开发人员可以按照以下帮助主题中的说明手动构建网格: 创建 3D 立方体网格。
开发人员可能会将网格转换为三角形网格,因为任何复杂 (表面) 结构都可以表示为一堆三角形。三角形是最原子的几何形状。因此,它几乎被用作任何东西的基础。此代码示例使用自定义内存布局将框转换为三角形网格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize scene object | |
Scene scene = new Scene(); | |
// Initialize Node class object | |
Node cubeNode = new Node("box"); | |
// Get mesh of the Box | |
Mesh box = (new Box()).toMesh(); | |
// Create a customized vertex layout | |
VertexDeclaration vd = new VertexDeclaration(); | |
VertexField position = vd.addField(VertexFieldDataType.F_VECTOR4, VertexFieldSemantic.POSITION); | |
vd.addField(VertexFieldDataType.F_VECTOR3, VertexFieldSemantic.NORMAL); | |
// Get a triangle mesh | |
TriMesh triMesh = TriMesh.fromMesh(box); | |
// ExEnd:ConvertBoxMeshtoTriangleMeshCustomMemoryLayout | |
// Point node to the Mesh geometry | |
cubeNode.setEntity(box); | |
// Add Node to a scene | |
scene.getRootNode().getChildNodes().add(cubeNode); | |
// The path to the documents directory. | |
String MyDir = RunExamples.getDataDir() + RunExamples.getOutputFilePath("BoxToTriangleMeshCustomMemoryLayoutScene.fbx"); | |
// Save 3D scene in the supported file formats | |
scene.save(MyDir, FileFormat.FBX7400ASCII); |
将原始形状转换为网格
Aspose.3D for Java API 支持将任何基本形状转换为网格。原始形状包括最基本的和使用过的对象,如长方体、球体、平面、圆柱体和圆环。
在导出为任何 3D 文件格式时,任何实现接口IMeshConvertible的类都可以转换为mesh。
将球体原语转换为网格
球体是三维空间中完美的圆形几何物体,从运动球到太空中的行星无处不在。让我们使用球体原语来创建网格。 下面的代码示例将球体转换为网格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize object by Sphere class | |
IMeshConvertible convertible = new Sphere(); | |
// Convert a Sphere to Mesh | |
Mesh mesh = convertible.toMesh(); |
将框转换为网格
盒子描述了各种容器和容器,这些容器和容器永久用作存储或临时使用,通常用于运输内容物。让我们使用框原语来创建网格。下面的代码示例将框转换为网格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize object by Box class | |
IMeshConvertible convertible = new Box(); | |
// Convert a Box to Mesh | |
Mesh mesh = convertible.toMesh(); |
将平面转换为网格
平面无限延伸而没有厚度。一个平面的例子是坐标平面。让我们使用平面原语创建网格。下面的代码示例将平面转换为网格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize object by Plane class | |
IMeshConvertible convertible = new Plane(); | |
// Convert a Plane to Mesh | |
Mesh mesh = convertible.toMesh(); |
将圆柱体转换为网格
圆柱体是最基本的曲线几何形状之一,由与给定直线 (圆柱体的轴) 相距固定距离的点形成的表面。它可以在许多地方使用,例如作为房屋前面的支柱或汽车驱动轴。让我们使用圆柱原语创建网格。下面的代码示例将圆柱体转换为网格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize object by Cylinder class | |
IMeshConvertible convertible = new Cylinder(); | |
// Convert a Cylinder to Mesh | |
Mesh mesh = convertible.toMesh(); |
将圆环转换为网格
圆环是通过在三维空间中绕与圆共面的轴旋转圆而产生的旋转表面。如果旋转轴不接触圆,则表面呈环形,称为圆环。让我们使用圆环原语来创建网格。下面的代码示例将圆环转换为网格。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize object by Torus class | |
IMeshConvertible convertible = new Torus(); | |
// Convert a Torus to Mesh | |
Mesh mesh = convertible.toMesh(); |