Mesh — Aspose.3D FOSS for Java

Package: com.aspose.threed (aspose-3d-foss 26.1.0)

Mesh stores polygon geometry as a list of control points (vertex positions) and a list of polygon faces. Each polygon face is a list of zero-based indices into the control points array. Faces may be triangles, quads, or higher-arity polygons. Additional per-vertex data – normals, UV coordinates, vertex colours – is attached as VertexElement layers.

public class Mesh extends Geometry

Inheritance

A3DObject -> SceneObject -> Entity -> Geometry -> Mesh


Examples

Build a single triangle mesh from scratch:

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");

Build a quad mesh (note: triangulate() is a stub — see warning below):

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");

Properties

PropertyTypeGetterSetterDescription
controlPointsList<Vector4>getControlPoints()Vertex position array. Each entry is a Vector4(x, y, z, w) where w is 1.0 for position data. Add vertices by calling add() on the returned list.
polygonCountintgetPolygonCount()Number of polygon faces defined on this mesh.
polygonsList<int[]>getPolygons()All face definitions as a list of index arrays. Each inner array holds the vertex indices (into controlPoints) for one face.
edgesList<Integer>getEdges()Raw edge index data. Primarily for internal use and advanced topology queries.
vertexElementsList<VertexElement>getVertexElements()All vertex element layers currently attached to this mesh (normals, UVs, colours, etc.).
visiblebooleangetVisible()setVisible(boolean)When false, the mesh is hidden in viewers that respect visibility.
castShadowsbooleangetCastShadows()setCastShadows(boolean)Whether this mesh casts shadows in renderers that support shadow maps.
receiveShadowsbooleangetReceiveShadows()setReceiveShadows(boolean)Whether this mesh receives shadows from other shadow-casting geometry.

Methods

createPolygon(int... indices)

Define a new polygon face by providing the vertex indices in order. The indices reference positions in getControlPoints(). Accepts three or more indices for triangles, quads, and n-gons.

ParameterTypeDescription
indicesint...Vertex index arguments in winding order (typically counter-clockwise when viewed from outside).

Returns: 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());   // 2

triangulate()

Stub: Returns a clone of the original mesh. Intended to split all polygons into triangles using fan triangulation, but actual triangulation logic is not yet implemented. The original mesh is not modified.

Returns: Mesh – a clone of the original mesh (stub behaviour).

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()

Return this Mesh as a Mesh instance. For Mesh objects this is an identity operation (returns this). Defined on the Geometry base class to provide a uniform conversion interface when working with generic Geometry references.

Returns: Mesh

import com.aspose.threed.*;

Mesh ensureMesh(Geometry geom) {
    return geom.toMesh();
}

createElement(VertexElementType elementType, MappingMode mappingMode, ReferenceMode referenceMode)

Add a new VertexElement layer of the specified type to the mesh. Use this to attach normals, tangents, binormals, vertex colours, and smoothing groups.

ParameterTypeDescription
elementTypeVertexElementTypeThe kind of data this layer holds (e.g., VertexElementType.NORMAL).
mappingModeMappingModeHow the data maps to geometry: CONTROL_POINT, POLYGON_VERTEX, POLYGON, etc.
referenceModeReferenceModeHow indices are used: DIRECT or INDEX_TO_DIRECT.

Returns: 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)

Add a UV coordinate layer to the mesh. This is the preferred method for attaching texture coordinate data.

ParameterTypeDescription
uvMappingTextureMappingThe UV channel purpose: DIFFUSE, SPECULAR, NORMAL, AMBIENT, etc.
mappingModeMappingModeHow UVs map to geometry elements.
referenceModeReferenceModeIndexing mode: DIRECT or INDEX_TO_DIRECT.

Returns: 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
);

Boolean and Optimization Methods (Stubs)

The following methods exist on Mesh but are stubs that return a clone of the original mesh without performing their intended operation.

Important: union, difference, intersect, and doBoolean are static methods, not instance methods. Call them as Mesh.union(a, b), not a.union(b).

MethodReturn TypeDescription
static Mesh.union(Mesh a, Mesh b)MeshStub: returns a clone of a. Intended for CSG union.
static Mesh.difference(Mesh a, Mesh b)MeshStub: returns a clone of a. Intended for CSG subtraction.
static Mesh.intersect(Mesh a, Mesh b)MeshStub: returns a clone of a. Intended for CSG intersection.
static Mesh.doBoolean(BooleanOperation op, Mesh a, Matrix4 ma, Mesh b, Matrix4 mb)MeshStub: returns a clone of a. Intended for general CSG with transforms.
optimize(boolean removeVertices)MeshStub: returns a clone. Four parameter overloads: optimize(boolean), optimize(boolean, float), optimize(boolean, float, float), optimize(boolean, float, float, float).
optimize2(boolean removeVertices)MeshStub: returns a clone. Alternative optimization entry point.

See Also