Python에서 3D 모델을 최적화하는 방법
문제
대용량 3D 모델 파일은 로드 및 전송 속도가 느릴 수 있습니다. Python에서 Aspose.3D를 사용할 때 파일 크기를 줄이고 불필요한 씬 데이터를 제거하기 위한 실용적인 단계가 있습니다; 주로 압축된 바이너리 포맷으로 내보내고 씬 그래프에서 사용되지 않는 노드를 정리함으로써 가능합니다.
전제 조건
- Python 3.7 이상
aspose-3d-foss패키지가 다음을 통해 설치됨pip install aspose-3d-foss- 3D 입력 파일 (OBJ, STL, FBX, glTF, 또는 3MF)
최적화 기법
컴팩트 바이너리 형식으로 변환
파일 크기를 줄이는 가장 효과적인 방법 중 하나는 씬을 glTF 바이너리(.glb). GLB 포맷은 기하와 재질을 하나의 바이너리 파일에 압축하여, OBJ나 ASCII FBX와 같은 텍스트 기반 포맷보다 훨씬 작고 로드 속도가 빠릅니다.
from aspose.threed import Scene, FileFormat
scene = Scene.from_file("model.obj")
scene.save("model.glb", FileFormat.GLTF2_BINARY)메시 검사 및 개수 세기
처리하기 전에 씬에 포함된 메시 노드 수를 파악하는 것이 유용합니다. 이는 예상보다 크거나 복잡한 씬을 식별하는 데 도움이 됩니다.
from aspose.threed import Scene
from aspose.threed.entities import Mesh
scene = Scene.from_file("model.obj")
mesh_count = 0
for node in scene.root_node.child_nodes:
if isinstance(node.entity, Mesh):
mesh_count += 1
print(f" Mesh '{node.name}': {len(node.entity.control_points)} vertices, "
f"{node.entity.polygon_count} polygons")
print(f"Total meshes: {mesh_count}")사용되지 않는(제외된) 노드 제거
제외된 것으로 표시된 노드는 렌더링되지 않습니다. 내보내기 중에 이러한 노드를 식별하고 건너뛰면 씬의 용량을 줄일 수 있습니다. The excluded attribute는 ~에 대한 속성입니다 Entity, 메서드 호출이 아닙니다.
from aspose.threed import Scene
from aspose.threed.entities import Mesh
scene = Scene.from_file("model.obj")
active_nodes = []
for node in scene.root_node.child_nodes:
entity = node.entity
if entity is not None and not entity.excluded:
active_nodes.append(node.name)
print(f"Active (non-excluded) nodes: {active_nodes}")코드 예시
이 예제는 씬을 로드하고, 메시 통계를 보고하며, 컴팩트한 GLB 형식으로 저장합니다: Aspose.3D를 통해 제공되는 주요 실용적 최적화입니다.
from aspose.threed import Scene, FileFormat
from aspose.threed.entities import Mesh
# Load the input model
scene = Scene.from_file("input.obj")
# Inspect mesh count and vertex totals
total_vertices = 0
for node in scene.root_node.child_nodes:
if isinstance(node.entity, Mesh):
mesh = node.entity
total_vertices += len(mesh.control_points)
print(f"Total vertices before export: {total_vertices}")
# Save to compact binary GLB: smaller and faster to load than OBJ
scene.save("output.glb", FileFormat.GLTF2_BINARY)
print("Saved as GLB (binary glTF)")최적화 범위에 대한 참고 사항
Aspose.3D는 메쉬 디시메이션이나 폴리곤 감소 알고리즘을 제공하지 않습니다. 파일 크기 감소는 주로 다음을 통해 달성됩니다:
- 바이너리 형식으로 내보내기 (OBJ 또는 ASCII FBX 대신 GLB)
- 사용자 처리 로직에서 제외된 또는 빈 노드를 건너뛰기
특정 퍼센트의 속도 향상이나 메모리 감소에 대한 주장은 입력 데이터에 따라 달라지며 일반적으로 보장될 수 없습니다.