Java에서 3D 모델을 로드하는 방법
aspose-3d-foss for Java은 3D 파일을 여는 간단한 API를 제공합니다. 파일을 Scene 객체에 로드한 후에는 노드 계층을 탐색하고 기하학 데이터를 읽을 수 있습니다.
단계별 가이드
1단계: 패키지 설치
Maven 의존성을 추가하십시오:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-3d-foss</artifactId>
<version>26.1.0</version>
</dependency>2단계: Scene 클래스 가져오기
import com.aspose.threed.Scene;
import com.aspose.threed.Node;
import com.aspose.threed.Mesh;3단계: 파일 로드
Scene scene = new Scene();
scene.open("model.obj");또는 정적 팩토리를 사용하세요:
Scene scene = Scene.fromFile("model.obj");지원되는 형식: OBJ, STL, glTF 2.0 / GLB, FBX (binary only — ASCII FBX는 지원되지 않으며 예외를 발생시킵니다. ImportException).
4단계: Scene 노드 순회
void walk(Node node, int depth) {
String indent = " ".repeat(depth * 2);
System.out.println(indent + "Node: " + node.getName());
for (Node child : node.getChildNodes()) {
walk(child, depth + 1);
}
}
walk(scene.getRootNode(), 0);5단계: Mesh 데이터 접근
for (Node node : scene.getRootNode().getChildNodes()) {
if (node.getEntity() instanceof Mesh) {
Mesh mesh = (Mesh) node.getEntity();
System.out.println("Mesh '" + node.getName() + "': " +
mesh.getControlPoints().size() + " vertices, " +
mesh.getPolygonCount() + " polygons");
}
}일반적인 문제 및 해결책
로드 시 예외
파일이 손상되지 않았으며 포맷이 지원되는지 확인하세요 (OBJ, STL, glTF, FBX).
엔터티 접근 시 NullPointerException
모든 노드가 기하학을 포함하는 것은 아닙니다. 항상 확인하십시오 node.getEntity() instanceof Mesh 캐스팅하기 전에.
좌표계 불일치
사용하십시오 ObjLoadOptions.setFlipCoordinateSystem(true) 또는 로드 후 회전을 적용하십시오.
자주 묻는 질문 (FAQ)
로드할 수 있는 형식은 무엇인가요?
OBJ, STL (binary 및 ASCII), glTF 2.0 / GLB, 그리고 FBX. FBX의 경우, 오직 binary FBX 가 지원됩니다. ASCII FBX 파일은 예외를 발생시킵니다. ImportException("ASCII FBX format not yet supported - only binary FBX is supported").
InputStream에서 로드할 수 있나요?
예. scene.open() 하나를 받아들입니다. InputStream.
이 라이브러리는 스레드 안전한가요?
각 Scene 인스턴스는 독립적입니다. 별도의 스레드에서 별도의 인스턴스로 개별 파일을 로드하는 것은 안전합니다.