PolygonModifier — Aspose.3D Python API Reference
패키지: aspose.threed.entities (aspose-3d-foss 26.1.0)
PolygonModifier 다각형 테셀레이션 작업을 제공하는 정적 유틸리티 클래스입니다 Mesh 및 Scene 객체에 대해. 모든 메서드는 클래스 메서드이며; PolygonModifier 직접 인스턴스화되지 않습니다.
from aspose.threed.entities import PolygonModifier주요 작업은 삼각형화입니다: ear-clipping 기법을 사용해 사각형 및 n-각형을 삼각형으로 변환합니다. 이는 삼각형 기하만 허용하는 포맷(STL, 일부 glTF 파이프라인)으로 내보내기 전에 필요합니다.
triangulate(arg) — 삼각형화 a Mesh
새로운 것을 반환합니다 Mesh 모든 다각형이 삼각형으로 변환된 형태입니다. 원본 메시는 수정되지 않습니다. 정점 요소 레이어(노멀, UV, 색상)는 새로운 메시로 복사됩니다.
@staticmethod
def triangulate(mesh: Mesh) -> Meshmesh | Mesh | 삼각형화할 원본 메시. |
반환값: Mesh — 삼각형 다각형만 포함하는 새로운 메시.
from aspose.threed.entities import Mesh, PolygonModifier
from aspose.threed.utilities import Vector4
mesh = Mesh()
for x, z in [(0, 0), (1, 0), (1, 1), (0, 1)]:
mesh.control_points.append(Vector4(float(x), 0.0, float(z), 1.0))
mesh.create_polygon(0, 1, 2, 3) # one quad
tri_mesh = PolygonModifier.triangulate(mesh)
print(tri_mesh.polygon_count) # 2triangulate(scene) — 모든 메시를 삼각형화 a Scene
전체 씬 그래프를 순회하며 모든 를 삼각형화합니다 Mesh 엔티티를 제자리에서 처리합니다. 이 호출 이후 씬에 비삼각형 다각형이 남지 않습니다.
@staticmethod
def triangulate(scene: Scene) -> Nonescene | Scene | 메시 엔티티가 삼각형화될 씬. |
반환값: None
from aspose.threed import Scene
from aspose.threed.entities import PolygonModifier
scene = Scene.from_file("model_with_quads.obj")
PolygonModifier.triangulate(scene)
scene.save("model_triangulated.stl")triangulate(control_points, polygon) — 단일 다각형을 삼각분할합니다
저수준 오버로드: 제어점 리스트와 하나의 폴리곤을 형성하는 정점 인덱스 리스트가 주어지면, fan 삼각형화에 의해 생성된 삼각형 인덱스 삼중항 리스트를 반환합니다.
@staticmethod
def triangulate(
control_points: list[Vector4],
polygon: list[int],
) -> list[list[int]]control_points | list[Vector4] | 전체 정점 위치 배열. |
polygon | list[int] | 다음에 대한 인덱스 control_points 분할할 다각형을 정의합니다. |
반환: list[list[int]] — 목록 [i, j, k] 삼중항으로, 각각은 하나의 출력 삼각형을 나타냅니다.
from aspose.threed.entities import PolygonModifier
from aspose.threed.utilities import Vector4
pts = [
Vector4(0.0, 0.0, 0.0, 1.0),
Vector4(1.0, 0.0, 0.0, 1.0),
Vector4(1.0, 1.0, 0.0, 1.0),
Vector4(0.0, 1.0, 0.0, 1.0),
]
quad_indices = [0, 1, 2, 3]
triangles = PolygonModifier.triangulate(pts, quad_indices)
print(triangles) # e.g. [[0, 1, 2], [0, 2, 3]]triangulate(control_points, polygons, generate_normals, normals_out) — 선택적 노멀 생성이 가능한 배치 삼각분할
다각형 인덱스 리스트들의 목록을 배치 삼각분할합니다. 선택적으로 각 출력 삼각형에 대한 면 노멀을 계산하고 이를 다음에 추가합니다. normals_out.
@staticmethod
def triangulate(
control_points: list[Vector4],
polygons: list[list[int]],
generate_normals: bool = False,
normals_out: list[Vector3] | None = None,
) -> list[list[int]]control_points | list[Vector4] | 정점 위치 배열. |
polygons | list[list[int]] | 다각형 정의 목록이며, 각 정의는 정점 인덱스 리스트입니다. |
generate_normals | bool | True, 각 출력 삼각형에 대한 면 노멀을 계산합니다. |
normals_out | `list[Vector3] | None` |
반환: list[list[int]] — 모든 출력 삼각형 삼중항을 순서대로.
from aspose.threed.entities import PolygonModifier
from aspose.threed.utilities import Vector4, Vector3
pts = [
Vector4(0, 0, 0, 1), Vector4(1, 0, 0, 1),
Vector4(1, 1, 0, 1), Vector4(0, 1, 0, 1),
]
polys = [[0, 1, 2, 3]]
normals: list[Vector3] = []
tris = PolygonModifier.triangulate(pts, polys, True, normals)
print(len(tris)) # 2
print(len(normals)) # 2