Mesh — Aspose.3D FOSS for Java

패키지: com.aspose.threed (aspose-3d-foss 26.1.0)

Mesh 다각형 기하학을 제어점(정점 위치) 목록과 다각형 면 목록으로 저장합니다. 각 다각형 면은 제어점 배열에 대한 0부터 시작하는 인덱스 목록입니다. 면은 삼각형, 사각형 또는 더 높은 차수의 다각형일 수 있습니다. 추가적인 정점당 데이터—노멀, UV 좌표, 정점 색상—는 VertexElement 레이어.

public class Mesh extends Geometry

Methods

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

MethodsMethodsMethodsMethodsMethods
controlPointsList<Vector4>getControlPoints()정점 위치 배열. 각 항목은 Vector4(x, y, z, w) 어디에 w 이다 1.0 위치 데이터용입니다. 호출하여 정점을 추가합니다 add() 반환된 리스트에.
polygonCountintgetPolygonCount()이 메시에 정의된 다각형 면의 수.
polygonsList<int[]>getPolygons()모든 면 정의는 인덱스 배열 목록으로 제공됩니다. 각 내부 배열은 정점 인덱스(에 대한)를 보유합니다. controlPoints) 한 면에 대해.
edgesList<Integer>getEdges()원시 엣지 인덱스 데이터. 주로 내부 사용 및 고급 토폴로지 쿼리를 위해 제공됩니다.
vertexElementsList<VertexElement>getVertexElements()현재 이 메시에 연결된 모든 정점 요소 레이어(노멀, UV, 색상 등).
visiblebooleangetVisible()setVisible(boolean)Methods false, 이 메시는 가시성을 존중하는 뷰어에서 숨겨집니다.
castShadowsbooleangetCastShadows()setCastShadows(boolean)이 메시가 섀도우 맵을 지원하는 렌더러에서 그림자를 투사하는지 여부.
receiveShadowsbooleangetReceiveShadows()setReceiveShadows(boolean)이 메시가 다른 그림자 투사 지오메트리로부터 그림자를 받는지 여부.

Methods

createPolygon(int... indices)

정점 인덱스를 순서대로 제공하여 새로운 폴리곤 면을 정의합니다. 인덱스는 위치를 참조합니다. getControlPoints(). 삼각형, 사각형 및 n-곤에 대해 세 개 이상의 인덱스를 허용합니다.

MethodsMethodsMethods
indicesint...정점 인덱스 인자는 와인딩 순서(보통 외부에서 볼 때 반시계 방향)로 지정됩니다.

반환: 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()

스텁: 원본 메쉬의 복제본을 반환합니다. 팬 삼각분할을 사용하여 모든 폴리곤을 삼각형으로 분할하려는 의도이지만, 실제 삼각분할 로직은 아직 구현되지 않았습니다. 원본 메쉬는 수정되지 않습니다.

반환: 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 as a Mesh 인스턴스. 용 Mesh objects 이것은 항등 연산입니다 (반환 this). 정의된 대상은 Geometry 기본 클래스이며, 일반적인 Geometry 참조입니다.

반환: Mesh

import com.aspose.threed.*;

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

createElement(VertexElementType elementType, MappingMode mappingMode, ReferenceMode referenceMode)

새 항목 추가 VertexElement 지정된 유형의 레이어를 메시에 추가합니다. 이를 사용하여 노멀, 탄젠트, 바이노멀, 정점 색상 및 스무딩 그룹을 연결합니다.

MethodsMethodsMethods
elementTypeVertexElementType이 레이어가 보유하는 데이터 종류 (예:., VertexElementType.NORMAL).
mappingModeMappingMode데이터가 지오메트리에 매핑되는 방식: CONTROL_POINT, POLYGON_VERTEX, POLYGON, 등.
referenceModeReferenceMode인덱스가 사용되는 방식: 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)

메시(mesh)에 UV 좌표 레이어를 추가합니다. 텍스처 좌표 데이터를 연결하는 권장 방법입니다.

MethodsMethodsMethods
uvMappingTextureMappingUV 채널의 목적: DIFFUSE, SPECULAR, NORMAL, AMBIENT, 등.
mappingModeMappingModeUV가 기하학 요소에 매핑되는 방식.
referenceModeReferenceMode인덱싱 모드: 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 union을 위해 의도되었습니다.
static Mesh.difference(Mesh a, Mesh b)Mesh스텁: 다음의 복제본을 반환합니다 a. CSG subtraction을 위해 의도되었습니다.
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스텁: 복제본을 반환합니다. 대체 최적화 진입점.

또 보기

 한국어