3D 메시지를 구축하는 방법은 Python에서 Aspose.3D로 구성됩니다.

3D 메시지를 구축하는 방법은 Python에서 Aspose.3D로 구성됩니다.

Aspose.3D FOSS for Python은 3D 지메트리를 완전히 코드에 구축 할 수 있습니다 : 외부 모델링 도구가 필요하지 않습니다. Mesh,에 따라 좌석을 쌓아 놓으라(control_points(이제는 정의에 대한 설명)polygons), 정상과 같은 선택적 인 vertex 속성을 추가하고, 지원되는 형식으로 장면을 저장합니다.

단계별 가이드

단계 1 : 패키지를 설치합니다.

PyPI에서 Aspose.3D FOSS를 설치합니다.이 도구 체인에는 원주민 확장이나 컴파일러가 필요하지 않습니다.

asposefoss/3d is not yet published — build from source until it ships. See the project README for build instructions.

설치를 확인하십시오 :

from aspose.threed import Scene
print("Aspose.3D FOSS ready")

지원되는 Python 버전: 3.7, 3.8, 3.9, 3.10, 3.11, 3.12.


단계 2: 장면과 노드를 만드는 방법

각 메시지는 장면 그래프 내부에 살 필요가 있습니다. Scene 그리고 이름을 추가하십시오. Node 메시지를 유지하기 위해 :

from aspose.threed import Scene

scene = Scene()
node = scene.root_node.create_child_node("triangle")

노드 이름은 수출 된 파일에 보존되며, 데뷔 및 나중에 복구하는 데 유용합니다. node.get_child("triangle").


단계 3: Mesh Object 만들기

즉시 A Mesh 선택적 설명 이름으로 :

from aspose.threed.entities import Mesh

mesh = Mesh("triangle")

은 처음에는 비어있다 : 수직이 없고, 폴리곤도 없습니다.당신은 다음 단계로 그것을 인구화합니다.


단계 4 : 컨트롤 포인트를 추가 (위치)

컨트롤 포인트는 좌석 위치입니다. 각 궤도는 하나로 저장됩니다. Vector4(x, y, z, w) 어디서 w=1 3D 공간에서 포인트를 나타냅니다 :

from aspose.threed.utilities import Vector4

##Vertex 0: origin
# Note: control_points returns a copy of the internal vertex list.
# Appending to the returned copy discards the vertex silently.
# Use _control_points to mutate the backing list directly.
# This is a known library limitation — a public add_control_point() API is not yet available.
mesh._control_points.append(Vector4(0.0, 0.0, 0.0, 1.0))

##Vertex 1: 1 unit along X
mesh._control_points.append(Vector4(1.0, 0.0, 0.0, 1.0))

##Vertex 2: apex
mesh._control_points.append(Vector4(0.5, 1.0, 0.0, 1.0))

print(f"Vertices added: {len(mesh.control_points)}")

중요한 것 :mesh.control_points 돌아오는 A 코피 내부 링크 목록 (Getter executes) list(self._control_points)* 부르며 mesh.control_points.append(v) 복사본에 붙여 있고, 이 아닌, 그래서 척추는 조용히 떨어져 있습니다. mesh._control_points.append(v) 추가 좌석.개인 국가에 액세스하여 _control_points 알려진 작업자입니다; 인터페이스는 도서관의 미래 버전에서 변경될 수 있습니다.


5단계 : 폴리곤 얼굴을 만드는 방법

Vertex 지표를 사용하여 얼굴 topology를 정의합니다.Vertex 인덱스를 통과하십시오. create_polygon().3개의 지표가 삼각형을 생성하고 4개는 쿼드를 생성을 한다.:

##Triangle: connect vertices 0 → 1 → 2
mesh.create_polygon(0, 1, 2)

print(f"Polygon count: {mesh.polygon_count}")

4 개의 쿼드 메시지에 대해 네 가지 지표를 통과 할 것입니다 : mesh.create_polygon(0, 1, 2, 3).

지표는 유효한 위치가 있어야 합니다. control_points (0 기반, 범위 내) 휘팅 순서는 외부 표면 정상에 대 한 반 시간입니다.


단계 6 : Vertex 정상을 추가합니다.

Vertex 정상은 A로 저장됩니다. VertexElement 에 붙어있다. 사용하기 mesh.create_element() 와 함께 VertexElementType.NORMAL, MappingMode.CONTROL_POINT,그리고, 그리고 ReferenceMode.DIRECT:

from aspose.threed.entities import VertexElementType, MappingMode, ReferenceMode, VertexElementNormal
from aspose.threed.utilities import Vector4, FVector4

##Create the normal element (returns VertexElementNormal, a VertexElementFVector subclass)
normals: VertexElementNormal = mesh.create_element(
    VertexElementType.NORMAL,
    MappingMode.CONTROL_POINT,
    ReferenceMode.DIRECT
)

##One normal per vertex: all pointing out of the XY plane (0, 0, 1)
normals.set_data([
    FVector4(0, 0, 1, 0),   # vertex 0
    FVector4(0, 0, 1, 0),   # vertex 1
    FVector4(0, 0, 1, 0),   # vertex 2
])

print("Normal layer attached.")

MappingMode.CONTROL_POINT 1개는 정상으로 니다. ReferenceMode.DIRECT 즉, 정상 데이터는 통제 포인트와 동일한 순서로 읽혀집니다 ( 추가 인덱스 버퍼가 없습니다).

정상적인 벡터 사용 FVector4(x, y, z, w) 와 함께 w=0 위치가 아닌 방향을 지정하는 것. FVector4 단일 정확도 유연 벡터; vertex 속의 데이터를 지정합니다. VertexElementFVector 이 유형의 하위 클래스는 사용됩니다.


단계 7 : 둥지에 메시지를 붙이고 저장합니다.

노드에 메시지를 추가하고, 그 다음 장면을 저장합니다 :

node.add_entity(mesh)

scene.save("triangle.gltf")
print("Saved triangle.gltf")

전체 작업 스크립트 (모든 단계가 결합되어 있습니다):

from aspose.threed import Scene
from aspose.threed.entities import Mesh, VertexElementType, MappingMode, ReferenceMode, VertexElementNormal
from aspose.threed.utilities import Vector3, Vector4, FVector4

scene = Scene()
node = scene.root_node.create_child_node("triangle")

mesh = Mesh("triangle")

##Add 3 vertices (x, y, z, w)
# Use _control_points to mutate the backing list directly (control_points returns a copy)
mesh._control_points.append(Vector4(0.0, 0.0, 0.0, 1.0))
mesh._control_points.append(Vector4(1.0, 0.0, 0.0, 1.0))
mesh._control_points.append(Vector4(0.5, 1.0, 0.0, 1.0))

##Create a triangle polygon
mesh.create_polygon(0, 1, 2)

##Add normals (create_element returns VertexElementNormal, a VertexElementFVector subclass)
normals: VertexElementNormal = mesh.create_element(VertexElementType.NORMAL, MappingMode.CONTROL_POINT, ReferenceMode.DIRECT)
normals.set_data([
    FVector4(0, 0, 1, 0),
    FVector4(0, 0, 1, 0),
    FVector4(0, 0, 1, 0),
])

node.add_entity(mesh)
scene.save("triangle.gltf")

일반적인 문제들

문제결의안
IndexError 안에 있는 create_polygon모든 지표가 내부에 있는지 확인하십시오. range(len(mesh.control_points)).지표는 0 기반입니다.
0 좌석으로 수출하는 메쉬mesh.control_points.append(...) 침묵적으로 좌석을 분리하기 때문에 재산은 복사본을 반환합니다. mesh._control_points.append(...) 대신에 그랬다.
정상 계산은 vertex 계정과 일치하지 않습니다.사용하는 경우 MappingMode.CONTROL_POINT + ReferenceMode.DIRECT, normals.data 정확하게 있어야 합니다. len(control_points) 입장에 들어가기.
실종된 파일에서 구출한 메시지확인해 보세요 node.add_entity(mesh) 이전에 전화를 받았습니다. scene.save().어떤 노드에 붙어 있지 않은 은 수출되지 않습니다.
잘못된 휘발성 순서 ( 얼굴이 보이지 않는 것처럼 보인다)시각이 있는 베르텍 순서가 외부 표면 정상을 생성합니다. create_polygon 그것을 게 하라.
polygon_count 0 돌아오는 것polygon_count 같은 목록을 읽고, polygons.만약 create_polygon 전화를 받지 않았고, 목록이 텅 비어있다.
정상은 시청자에서 잘못된 것처럼 보입니다.모든 정상 벡터가 단위 길이에 있는지 확인하십시오. n / abs(n) 또는 사전 정상화된 값을 통과합니다.

자주 묻는 질문들

그 사이의 차이점은 무엇인가 Vector3 그리고 Vector4 컨트롤 포인트를 위해?

control_points 가게들 Vector4 상품명 : The Objects w 구성 요소는 동일한 조율입니다 : 사용 w=1 Vertex 위치 및 w=0 일반적인 방향과 같은 벡터를 사용합니다. Vector3 변환 (변역, 규모)에 사용되지만 지질 저장소는 아닙니다.

삼각형 대신에 쿼드로 메시지를 만들 수 있습니까?

예요, 전화 mesh.create_polygon(0, 1, 2, 3) 일부 저장 목표 (STL, 3MF)는 삼각형을 필요로하고 자동으로 쿼드를 삼위일체화합니다. glTF 및 COLLADA는 퀘드를 보존합니다.

UV 조율을 어떻게 추가할 수 있습니까?

사용하기 mesh.create_element_uv(TextureMapping.DIFFUSE, MappingMode.POLYGON_VERTEX) A를 만들기 위해서 VertexElementUV 채널을 녹여서 그 채를 인구화하라. data 목록은 Vector4 UV 조정의 사용 x 그리고 y; z 그리고 w 0 : 첫 번째 논쟁은 1의 원칙이 되어야 한다. TextureMapping 지속적인 (예를 들어,., TextureMapping.DIFFUSE) UV 레이어가 속한 텍스트 슬롯을 확인합니다.

은 정상적으로 수출하기 위해 필요한가?

No. 정상은 선택적입니다. 놓치면 대부분의 시청자는 폴리곤 바람 순서에서 얼굴별 정상을 계산합니다. 명시적인 per-vertex 정상이 추가하면 더 부드러운 그림자가 생성됩니다.

한 노드에 여러 개의 메시지를 추가할 수 있습니까?

예요, 전화 node.add_entity(mesh) 여러 번.모든 전화는 새로운 엔티티를 추가합니다. node.entities.일부 형식은 수출 중 하나로 여러 개의 단체를 융합할 수 있습니다.

어떻게 혼합 된 폴리곤 유형으로 마스크를 삼각화 할 수 있습니까?

전화기 mesh.triangulate() 모든 쿼드와 N-곤을 위치한 삼각형으로 변환하는 데 도움이됩니다.이것은 단지 삼위일체를 지원하는 형식에 저장하기 전에 유용합니다.

 한국어