Mesh
패키지: aspose.threed.entities (aspose-3d-foss 26.1.0)
Mesh 다각형 기하학을 제어점(정점 위치) 목록과 다각형 면 목록으로 저장합니다. 각 다각형 면은 제어점 배열에 대한 0부터 시작하는 인덱스 목록입니다. 면은 삼각형, 사각형 또는 더 높은 차수의 다각형일 수 있습니다. 추가적인 정점당 데이터인 노멀, UV 좌표, 정점 색상은 다음과 같이 첨부됩니다 VertexElement 레이어.
class Mesh(Geometry):Methods
A3DObject → SceneObject → Entity → Geometry → Mesh
Methods
스크래치부터 단일 삼각형 메시를 구축합니다:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
# Create the mesh and add three vertex positions
# IMPORTANT: control_points returns a copy of the internal list.
# Append to _control_points directly — appending to control_points discards the vertex.
# This is a known library limitation; a public mutation API does not yet exist.
mesh = Mesh()
mesh._control_points.append(Vector4(0.0, 0.0, 0.0, 1.0)) # vertex 0
mesh._control_points.append(Vector4(1.0, 0.0, 0.0, 1.0)) # vertex 1
mesh._control_points.append(Vector4(0.5, 1.0, 0.0, 1.0)) # vertex 2
# Define one triangle face using vertex indices
mesh.create_polygon(0, 1, 2)
# Attach to a scene and save
scene = Scene()
scene.root_node.create_child_node("triangle", mesh)
scene.save("triangle.stl")쿼드 메쉬를 만들고 내보내기 전에 삼각형화합니다:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
mesh = Mesh()
# Four corners of a unit square in the XZ plane
# Use _control_points to mutate the backing list (control_points returns a copy)
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))
# One quad face
mesh.create_polygon(0, 1, 2, 3)
print(f"Polygons before triangulate: {mesh.polygon_count}") # 1
triangulated = mesh.triangulate()
print(f"Polygons after triangulate: {triangulated.polygon_count}") # 2
scene = Scene()
scene.root_node.create_child_node("quad", triangulated)
scene.save("quad.glb")Methods
control_points, polygon_count, polygons, edges, 그리고 vertex_elements 모두 속성; 괄호 없이 접근하십시오.
| Methods | Methods | Methods | Methods |
|---|---|---|---|
control_points | list[Vector4] | 읽기 | 정점 위치 배열. 각 항목은 a Vector4(x, y, z, w) 어디에 w 이다 1.0 위치 데이터용. 복사본을 반환합니다 — 반환된 리스트에 추가하지 마세요. 사용하세요 mesh._control_points.append(v) 정점을 추가하려면 (알려진 제한 사항; 공개 변이 API는 아직 제공되지 않음). |
polygon_count | int | 읽기 | 이 메시에서 정의된 폴리곤 면의 수. |
polygons | list[list[int]] | 읽기 | 모든 면 정의는 인덱스 리스트들의 리스트 형태입니다. 각 내부 리스트는 정점 인덱스를 포함합니다 ( control_points) 한 면에 대해. |
edges | list[int] | 읽기 | 원시 엣지 인덱스 데이터. 주로 내부 사용 및 고급 토폴로지 쿼리를 위해 제공됩니다. |
vertex_elements | list[VertexElement] | 읽기 | 현재 이 메시에 연결된 모든 정점 요소 레이어(노멀, UV, 색상 등). |
visible | bool | 읽기/쓰기 | Methods False, 이 메시는 가시성을 존중하는 뷰어에서 숨겨집니다. |
cast_shadows | bool | 읽기/쓰기 | 이 메시가 shadow maps를 지원하는 렌더러에서 그림자를 드리우는지 여부. |
receive_shadows | bool | 읽기/쓰기 | 이 메시가 다른 그림자를 드리우는 기하학으로부터 그림자를 받는지 여부. |
Methods
create_polygon(*indices)
정점 인덱스를 순서대로 제공하여 새로운 폴리곤 면을 정의합니다. 인덱스는 위치를 참조합니다. control_points.삼각형, 사각형 및 n-각형에 대해 세 개 이상의 인덱스를 허용합니다.
| Methods | Methods | Methods |
|---|---|---|
*indices | int | 정점 인덱스 인자는 와인딩 순서대로 제공됩니다(보통 외부에서 볼 때 반시계 방향). |
반환: None
mesh = Mesh()
# ... populate control_points ...
mesh.create_polygon(0, 1, 2) # triangle
mesh.create_polygon(0, 1, 2, 3) # quad
print(mesh.polygon_count) # 2triangulate()
새로운 것을 반환합니다. Mesh 모든 폴리곤이 팬 삼각분할을 사용하여 삼각형으로 분할된 형태입니다. 원본 메시는 수정되지 않습니다. 삼각형 전용 기하학을 요구하는 포맷(예: STL 또는 일부 glTF 파이프라인)으로 내보내기 전에 유용합니다.
반환: Mesh; 삼각형만 포함하는 새로운 메시.
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
mesh = Mesh()
# Use _control_points to mutate the backing list (control_points returns a copy)
for v in [(0,0,0), (1,0,0), (1,1,0), (0,1,0)]:
mesh._control_points.append(Vector4(*v, 1.0))
mesh.create_polygon(0, 1, 2, 3) # one quad
tri_mesh = mesh.triangulate()
print(tri_mesh.polygon_count) # 2to_mesh()
이것을 반환 Mesh as a Mesh 인스턴스. For Mesh objects 이 경우 이는 항등 연산입니다 (returns self). 정의된 Geometry 기본 클래스는 일반적인 작업 시 일관된 변환 인터페이스를 제공하도록 Geometry 참조.
반환값: Mesh
from aspose.threed.entities import Geometry
def ensure_mesh(geom: Geometry):
return geom.to_mesh()create_element(element_type, mapping_mode, reference_mode)
새로 추가 VertexElement 지정된 유형의 레이어를 메시에 추가합니다. 이를 사용하여 노멀, 탄젠트, 바이노멀, 정점 색상 및 스무딩 그룹을 연결합니다.
| Methods | Methods | Methods |
|---|---|---|
element_type | VertexElementType | 이 레이어가 보유하는 데이터 종류 (예:., VertexElementType.NORMAL). |
mapping_mode | MappingMode | 데이터가 지오메트리에 매핑되는 방식: CONTROL_POINT, POLYGON_VERTEX, POLYGON, 등. |
reference_mode | ReferenceMode | 인덱스 사용 방식: DIRECT 또는 INDEX_TO_DIRECT. |
반환값: VertexElement
from aspose.threed.entities import Mesh, VertexElementType, MappingMode, ReferenceMode
from aspose.threed.utilities import Vector4
mesh = Mesh()
# Use _control_points to mutate the backing list (control_points returns a copy)
mesh._control_points.append(Vector4(0, 0, 0, 1))
mesh._control_points.append(Vector4(1, 0, 0, 1))
mesh._control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)
normal_element = mesh.create_element(
VertexElementType.NORMAL,
MappingMode.CONTROL_POINT,
ReferenceMode.DIRECT,
)create_element_uv(uv_mapping, mapping_mode, reference_mode)
메시에 UV 좌표 레이어를 추가합니다. 이는 텍스처 좌표 데이터를 연결하는 권장 방법입니다.
| Methods | Methods | Methods |
|---|---|---|
uv_mapping | TextureMapping | UV 채널 목적: DIFFUSE, SPECULAR, NORMAL, AMBIENT, 등. |
mapping_mode | MappingMode | UV가 기하학 요소에 매핑되는 방법. |
reference_mode | ReferenceMode | 인덱싱 모드: DIRECT 또는 INDEX_TO_DIRECT. |
반환값: VertexElementUV
from aspose.threed.entities import Mesh, TextureMapping, MappingMode, ReferenceMode
mesh = Mesh()
# ... define control_points and polygons ...
uv_element = mesh.create_element_uv(
TextureMapping.DIFFUSE,
MappingMode.POLYGON_VERTEX,
ReferenceMode.INDEX_TO_DIRECT,
)