Python에서 3D를 시작하는 방법
전제 조건
- Python 3.8 이상
- pip 패키지 관리자
1단계 — 패키지 설치
PyPI에서 Python용 Aspose.3D FOSS 설치:
pip install aspose-3d-foss설치 확인:
import aspose.threed as a3d
print(a3d.__version__)2단계 — 첫 번째 3D 씬 만들기
Scene은 모든 3D 객체의 루트 컨테이너입니다. 생성자는 선택적인 엔터티, 상위 씬 및 이름을 허용합니다:
import aspose.threed as a3d
# Create an empty scene (CLM-3d-35d727)
scene = a3d.Scene()
# Access the root node of the scene (CLM-3d-859ac2)
root = scene.root_node()
print("Root node:", root)3단계 — 씬에 메시에 추가
Mesh은 폴리곤 기하학을 나타냅니다.Node은 엔티티를 씬 그래프에 연결합니다:
import aspose.threed as a3d
scene = a3d.Scene()
# Create a named mesh (CLM-3d-529c11)
mesh = a3d.Mesh("my_mesh")
# Create a node and attach the mesh (CLM-3d-0edae8)
node = a3d.Node("my_node", mesh)
# Add the node as a child of the root (CLM-3d-a403f5)
scene.root_node().add_child_node(node)4단계 — 기존 3D 파일 로드
Scene.open()은 디스크 또는 스트림에서 3D 파일을 로드합니다. 경로와 선택적
로드 옵션을 허용합니다:
import aspose.threed as a3d
# Load an OBJ file (CLM-3d-d84964)
scene = a3d.Scene()
scene.open("model.obj")
# Inspect the loaded scene
root = scene.root_node()
print("Child nodes:", len(root.child_nodes()))로드하기 전에 파일 형식을 감지하려면:
import aspose.threed as a3d
# Detect the format from a file name (CLM-3d-d2de62)
fmt = a3d.FileFormat.detect(None, "model.fbx")
if fmt:
print("Detected format:", fmt.extension())5단계 — 출력 파일에 저장
Scene.save()은 씬을 지원되는 모든 형식으로 내보냅니다. 권장되는 접근 방식은 확장자 기반 자동 감지입니다: Aspose.3D는 파일 확장자를 통해 형식을 추론합니다 (CLM-3d-8051bd, CLM-3d-b28d7a, CLM-3d-de8e1a):
import aspose.threed as a3d
scene = a3d.Scene()
# ... populate scene ...
# Save as Wavefront OBJ — extension auto-detects the format
scene.save("output.obj")
# Save as glTF 2.0 binary — .glb extension triggers binary GLB output
scene.save("output.glb")팩토리 메서드 FileFormat.WAVEFRONT_OBJ() 또는 FileFormat.GLTF2()를 사용하여 명시적인 형식을 전달할 수도 있지만, 확장자 자동 감지는 더 간단하고 휴대성이 높습니다.
다음 단계
- How to Load 3D Models in Python — 포맷, 옵션, 씬 그래프 탐색
- How to Convert 3D Models in Python — 배치 변환 워크플로우
- How to Build Mesh Geometry in Python — 제어점, 폴리곤, 노멀
- FAQ — 일반적인 질문 및 문제 해결