Mesh — Aspose.3D FOSS for Java
包:: com.aspose.threed (aspose-3d-foss 26.1.0)
Mesh 将多边形几何存储为控制点(顶点位置)列表和多边形面列表。每个多边形面是指向控制点数组的零基索引列表。面可以是三角形、四边形或更高阶多边形。额外的每顶点数据——法线、UV 坐标、顶点颜色——作为 VertexElement 图层。.
public class Mesh extends GeometryMethods
A3DObject -> SceneObject -> Entity -> Geometry -> Mesh
Methods
从零开始构建单个三角形网格::
import com.aspose.threed.Scene;
import com.aspose.threed.*;
// Create the mesh and add three vertex positions
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0.0, 0.0, 0.0, 1.0)); // vertex 0
mesh.getControlPoints().add(new Vector4(1.0, 0.0, 0.0, 1.0)); // vertex 1
mesh.getControlPoints().add(new Vector4(0.5, 1.0, 0.0, 1.0)); // vertex 2
// Define one triangle face using vertex indices
mesh.createPolygon(0, 1, 2);
// Attach to a scene and save
Scene scene = new Scene();
scene.getRootNode().createChildNode("triangle", mesh);
scene.save("triangle.stl");构建四边形网格(注意:triangulate() 是一个存根 —— 请参见下面的警告)::
import com.aspose.threed.Scene;
import com.aspose.threed.*;
Mesh mesh = new Mesh();
// Four corners of a unit square in the XZ plane
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 0, 1, 1.0));
mesh.getControlPoints().add(new Vector4(0, 0, 1, 1.0));
// One quad face
mesh.createPolygon(0, 1, 2, 3);
System.out.println("Polygons before triangulate: " + mesh.getPolygonCount()); // 1
// WARNING: triangulate() is a stub — it returns a clone, NOT a triangulated mesh.
// The polygon count will remain 1 (not 2).
Mesh triangulated = mesh.triangulate();
System.out.println("Polygons after triangulate: " + triangulated.getPolygonCount()); // still 1
Scene scene = new Scene();
scene.getRootNode().createChildNode("quad", triangulated);
// When saving to STL, pass triangle-only meshes to avoid vertex loss or malformed output.
scene.save("quad.glb");Methods
| Methods | Methods | Methods | Methods | Methods |
|---|---|---|---|---|
controlPoints | List<Vector4> | getControlPoints() | – | 顶点位置数组。每个条目是一个 Vector4(x, y, z, w) 其中 w 是 1.0 用于位置数据。通过调用 add() 在返回的列表上。. |
polygonCount | int | getPolygonCount() | – | 此网格上定义的多边形面数。. |
polygons | List<int[]> | getPolygons() | – | 所有面定义为索引数组的列表。每个内部数组保存顶点索引(into controlPoints) 用于一个面。. |
edges | List<Integer> | getEdges() | – | 原始边索引数据。主要用于内部使用和高级拓扑查询。. |
vertexElements | List<VertexElement> | getVertexElements() | – | 当前附加到此网格的所有顶点元素层(法线、UV、颜色等)。. |
visible | boolean | getVisible() | setVisible(boolean) | Methods false,,在尊重可见性的查看器中,网格会被隐藏。. |
castShadows | boolean | getCastShadows() | setCastShadows(boolean) | 此网格是否在支持阴影贴图的渲染器中投射阴影。. |
receiveShadows | boolean | getReceiveShadows() | setReceiveShadows(boolean) | 此网格是否接收来自其他投射阴影几何体的阴影。. |
Methods
createPolygon(int... indices)
通过按顺序提供顶点索引来定义一个新的多边形面。索引引用的位置在 getControlPoints().。接受三个或更多索引用于三角形、四边形和 n‑gons。.
| Methods | Methods | Methods |
|---|---|---|
indices | int... | 顶点索引参数按环绕顺序(通常在从外部观看时为逆时针)提供。. |
返回:: void
Mesh mesh = new Mesh();
// ... populate control points ...
mesh.createPolygon(0, 1, 2); // triangle
mesh.createPolygon(0, 1, 2, 3); // quad
System.out.println(mesh.getPolygonCount()); // 2triangulate()
存根:: 返回原始网格的克隆。旨在使用扇形三角剖分将所有多边形拆分为三角形,但实际的三角剖分逻辑尚未实现。原始网格未被修改。.
返回:: Mesh – 原始网格的克隆(存根行为)。.
import com.aspose.threed.*;
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1.0));
mesh.getControlPoints().add(new Vector4(1, 1, 0, 1.0));
mesh.getControlPoints().add(new Vector4(0, 1, 0, 1.0));
mesh.createPolygon(0, 1, 2, 3); // one quad
Mesh triMesh = mesh.triangulate();
// Note: currently returns a clone, not a triangulated mesh
System.out.println(triMesh.getPolygonCount());toMesh()
返回此 Mesh 作为一个 Mesh 实例。 对于 Mesh 对象 这是一种恒等操作(返回 this) 在 Geometry 基类,以在处理通用 Geometry 引用。.
返回:: Mesh
import com.aspose.threed.*;
Mesh ensureMesh(Geometry geom) {
return geom.toMesh();
}createElement(VertexElementType elementType, MappingMode mappingMode, ReferenceMode referenceMode)
添加一个新的 VertexElement 将指定类型的层添加到网格。使用此功能来附加法线、切线、双切线、顶点颜色和平滑组。.
| Methods | Methods | Methods |
|---|---|---|
elementType | VertexElementType | 此层所持有的数据类型(例如,., VertexElementType.NORMAL). |
mappingMode | MappingMode | 数据如何映射到几何体:: CONTROL_POINT, POLYGON_VERTEX, POLYGON,,等。. |
referenceMode | ReferenceMode | 索引的使用方式:: DIRECT 或 INDEX_TO_DIRECT. |
返回:: VertexElement
import com.aspose.threed.*;
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(0.5, 1, 0, 1));
mesh.createPolygon(0, 1, 2);
VertexElement normalElement = mesh.createElement(
VertexElementType.NORMAL,
MappingMode.CONTROL_POINT,
ReferenceMode.DIRECT
);createElementUV(TextureMapping uvMapping, MappingMode mappingMode, ReferenceMode referenceMode)
向网格添加 UV 坐标层。这是附加纹理坐标数据的首选方法。.
| Methods | Methods | Methods |
|---|---|---|
uvMapping | TextureMapping | UV 通道的用途:: DIFFUSE, SPECULAR, NORMAL, AMBIENT,,等。. |
mappingMode | MappingMode | UV 如何映射到几何元素。. |
referenceMode | ReferenceMode | 索引模式:: DIRECT 或 INDEX_TO_DIRECT. |
返回:: VertexElementUV
import com.aspose.threed.*;
Mesh mesh = new Mesh();
// ... define control points and polygons ...
VertexElementUV uvElement = mesh.createElementUV(
TextureMapping.DIFFUSE,
MappingMode.POLYGON_VERTEX,
ReferenceMode.INDEX_TO_DIRECT
);布尔运算和优化方法(存根)
以下方法存在于 Mesh 但它们是 存根 返回原始网格的克隆而不执行其预期的操作。.
重要:: union, difference, intersect,,并且 doBoolean 是 静态方法, 不是实例方法。调用它们为 Mesh.union(a, b), 不是 a.union(b).
| Methods | 返回类型 | Methods |
|---|---|---|
static Mesh.union(Mesh a, Mesh b) | Mesh | 桩:: 返回一个克隆 a. 用于 CSG 并集。. |
static Mesh.difference(Mesh a, Mesh b) | Mesh | 存根:: 返回一个克隆 a. 用于 CSG 减法。. |
static Mesh.intersect(Mesh a, Mesh b) | Mesh | 存根:: 返回其克隆 a. 用于 CSG 相交。. |
static Mesh.doBoolean(BooleanOperation op, Mesh a, Matrix4 ma, Mesh b, Matrix4 mb) | Mesh | 存根:: 返回其克隆 a. 旨在用于一般的 CSG(带有变换)。. |
optimize(boolean removeVertices) | Mesh | 存根: 返回一个克隆。四个参数重载: optimize(boolean), optimize(boolean, float), optimize(boolean, float, float), optimize(boolean, float, float, float). |
optimize2(boolean removeVertices) | Mesh | 存根: 返回一个克隆。替代的优化入口点。. |