3D 포맷 지원
Aspose.3D FOSS for TypeScript는 7가지 주요 3D 파일 포맷을 읽고 씁니다. 로드 시 포맷 감지는 자동이며, 라이브러리는 바이너리 매직 넘버를 검사하므로 소스 포맷을 지정할 필요가 없습니다. 포맷별 옵션 클래스는 패키지의 하위 경로에서 가져옵니다. @aspose/3d 패키지.
지원되는 형식
| 포맷 | 확장자 | 읽기 | 쓰기 | 포맷 클래스 | 참고 |
|---|---|---|---|---|---|
| Wavefront OBJ | .obj | 예 | 예 | ObjFormat | 읽음 .mtl 재료; 작성 .mtl 함께 .obj |
| glTF 2.0 | .gltf | 예 | 예 | GltfFormat | JSON 텍스트 + .bin sidecar |
| GLB | .glb | 예 | 예 | GltfFormat | Binary glTF; 설정 binaryMode = true |
| STL | .stl | 예 | 예 | StlFormat | 바이너리 및 ASCII 모드 |
| 3MF | .3mf | 예 | 예 | ThreeMfFormat | 3D Manufacturing Format |
| FBX | .fbx | 아니오* | 아니오* | FbxFormat | Importer/exporter는 존재하지만 형식 자동 감지는 연결되어 있지 않으며; via를 통해 사용할 수 없습니다 scene.open() |
| COLLADA | .dae | 예 | 예 | ColladaFormat | 필요 xmldom (자동 설치됨) |
OBJ (Wavefront)
OBJ는 in에서 가져오기와 내보내기를 모두 지원합니다 @aspose/3d. OBJ로 저장할 때, 재질 라이브러리 (.mtl)는 자동으로 옆에 작성됩니다 .obj 파일. 사용 ObjLoadOptions 재질 로딩 및 좌표계 동작을 제어합니다.
다음에 대한 주요 옵션 ObjLoadOptions:
| 옵션 | 유형 | 기본값 | 효과 |
|---|---|---|---|
enableMaterials | boolean | true | 다음 구문 분석 .mtl 다음에 의해 참조된 파일 mtllib |
flipCoordinateSystem | boolean | false | 오른손 좌표계에 맞게 Y/Z 축을 뒤집습니다 |
scale | number | 1.0 | 로드 시 모든 정점에 적용되는 균일 스케일 |
normalizeNormal | boolean | true | 정점 법선을 단위 길이로 정규화합니다 |
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
const scene = new Scene();
const opts = new ObjLoadOptions();
opts.enableMaterials = true;
opts.normalizeNormal = true;
scene.open('model.obj', opts);
console.log(`Loaded ${scene.rootNode.childNodes.length} top-level node(s)`);OBJ를 어떤 쓰기 가능한 형식으로 변환하려면, 로드한 뒤 호출하십시오 scene.save() 대상 형식 클래스와 함께.
glTF 및 GLB
glTF 2.0은 웹 및 게임 엔진 사용을 위한 권장 교환 형식입니다. 라이브러리는 동일한 GltfFormat 클래스를 두 경우 모두 사용합니다 .gltf (JSON + 사이드카) 및 .glb (바이너리, 자체 포함) 출력. 이를 전환하려면 GltfSaveOptions.binaryMode.
glTF 또는 GLB 로드:
import { Scene } from '@aspose/3d';
import { GltfLoadOptions } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('model.gltf', new GltfLoadOptions());
// or
scene.open('model.glb'); // format detected from magic bytes
JSON glTF로 내보내기 (.gltf + .bin):
import { Scene } from '@aspose/3d';
import { GltfSaveOptions, GltfFormat } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('input.fbx');
const opts = new GltfSaveOptions();
opts.binaryMode = false; // produces output.gltf + output.bin
scene.save('output.gltf', GltfFormat.getInstance(), opts);바이너리 GLB로 내보내기 (.glb):
import { Scene } from '@aspose/3d';
import { GltfSaveOptions, GltfFormat } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('input.obj');
const opts = new GltfSaveOptions();
opts.binaryMode = true; // single self-contained file
scene.save('output.glb', GltfFormat.getInstance(), opts);사용 binaryMode = true 프로덕션 자산 전달에 사용합니다. 단일 .glb 텍스트와 바이너리 쌍으로 분리된 것보다 브라우저와 엔진에서 더 빠르게 로드됩니다.
STL
STL은 CAD 및 3D 프린팅에 사용되는 삼각형 메시 형식입니다. 이진 및 ASCII STL 모두 입력과 출력에 지원됩니다. StlSaveOptions.binaryMode 출력이 이진(컴팩트)인지 ASCII(사람이 읽을 수 있는)인지 제어합니다.
import { Scene } from '@aspose/3d';
import { StlLoadOptions, StlSaveOptions } from '@aspose/3d/formats/stl';
const scene = new Scene();
scene.open('model.stl', new StlLoadOptions());
// Export as binary STL (default, compact)
const binaryOpts = new StlSaveOptions();
binaryOpts.binaryMode = true;
scene.save('output_binary.stl', binaryOpts);
// Export as ASCII STL (human-readable)
const asciiOpts = new StlSaveOptions();
asciiOpts.binaryMode = false;
scene.save('output_ascii.stl', asciiOpts);STL은 삼각형 형태의 기하와 정점 법선만 저장합니다. 재질 및 UV 데이터는 STL에 보존되지 않습니다.
3MF (3D Manufacturing Format)
3MF is an XML-based format designed for additive manufacturing. It supports color and material metadata alongside geometry. Use it when exchanging files with 3D printing slicers or manufacturing workflows.
import { Scene } from '@aspose/3d';
import { ThreeMfSaveOptions } from '@aspose/3d/formats/3mf';
const scene = new Scene();
scene.open('model.3mf');
// Re-export as 3MF
scene.save('output.3mf', new ThreeMfSaveOptions());3MF files are ZIP archives internally. The library handles archive creation and extraction automatically.
FBX
경고: FBX 가져오기 및 내보내기 클래스 (FbxImporter, FbxExporter) 라이브러리에 존재하지만 FBX 형식 자동 감지는 연결되어 있지 않습니다 에 scene.open() 또는 scene.save(). 호출하는 scene.open('file.fbx') FBX 가져오기기를 호출하지 않습니다 — 파일은 STL 대체 경로로 넘어갑니다. scene.save('output.fbx', opts) FBX 내보내기기를 호출하지 않습니다. 위의 형식 지원 표는 FBX를 No* 이러한 이유로 표시합니다. 완전한 가져오기 및 내보내기를 위해 GLB 또는 COLLADA를 사용하십시오. scene.open() / scene.save().
COLLADA (DAE)
COLLADA는 다양한 DCC 툴(Blender, Maya, Cinema 4D)에서 지원되는 XML 기반 교환 포맷입니다. 이 라이브러리는 xmldom XML 파싱을 위한 의존성; 이는 자동으로 설치됩니다 npm install @aspose/3d.
import { Scene } from '@aspose/3d';
import { ColladaSaveOptions } from '@aspose/3d/formats/collada';
const scene = new Scene();
scene.open('model.dae');
// Re-export as COLLADA
const saveOpts = new ColladaSaveOptions();
scene.save('output.dae', saveOpts);COLLADA 파일에는 단위 스케일 메타데이터가 포함될 수 있습니다 (<unit> 요소). 이 라이브러리는 로드 시 단위 변환을 자동으로 적용합니다.
포맷 자동 감지
파일 경로에서 로드할 때, 라이브러리는 파일 확장자를 사용하기 전에 바이너리 매직 넘버를 통해 형식 감지를 시도합니다. 이는 GLB 파일을 이름으로 로드할 수 있음을 의미합니다 .bin 또는 STL 파일을 이름으로 .model 형식을 명시적으로 지정하지 않아도 됩니다.
로드할 때 Buffer 와 scene.openFromBuffer(), 매직 넘버 감지가 주요 메커니즘입니다:
import { Scene } from '@aspose/3d';
import * as fs from 'fs';
const buffer = fs.readFileSync('model.glb');
const scene = new Scene();
scene.openFromBuffer(buffer); // format detected from magic bytes: 'glTF'
console.log(`Root has ${scene.rootNode.childNodes.length} child node(s)`);신뢰할 수 있는 매직 넘버를 가진 포맷: GLB (glTF), STL 바이너리 (80바이트 헤더 + 삼각형 개수), 3MF (ZIP 매직 PK). OBJ와 COLLADA는 텍스트 기반이며 파일 확장자 또는 전달하는 옵션 클래스에 의해 감지됩니다.
팁
- OBJ는 가져오기와 내보내기를 모두 지원합니다: OBJ로 저장할 때,
.mtl재질 파일이 자동으로 옆에 작성됩니다.obj파일. - 웹 전송에는 GLB를 사용하세요: 자체 포함 바이너리 형식은 CORS 문제를 피합니다
.bin사이드카와 함께 사용 시 WebGL 렌더러에서 더 빠르게 로드됩니다. - 형식별 옵션을 전달하세요: 일반
scene.open(path)대부분의 형식에 대해 작동하지만, 로더 옵션 클래스를 전달하면 OBJ 재질 로드 또는 STL 좌표 정규화와 같은 형식별 동작을 활성화할 수 있습니다. xmldom는 COLLADA에 필요합니다:자동으로 설치됩니다. 추가하지 마세요.peerDependencies또는 제거하려고 시도하지 마세요; COLLADA 리더가 직접 호출합니다.
일반적인 문제
| 증상 | 가능한 원인 | 해결 방법 |
|---|---|---|
| OBJ 재질이 로드 후 비어 있습니다 | enableMaterials 설정되지 않음 | 통과 ObjLoadOptions 와 enableMaterials = true |
GLB가 생성합니다 .bin sidecar | binaryMode 기본값으로 false | 설정 opts.binaryMode = true 에서 GltfSaveOptions |
scene.open() “unsupported format” 오류를 발생시킵니다 | 파일 확장자를 인식할 수 없습니다 | 일치하는 것을 전달하세요 *LoadOptions 클래스 또는 사용 openFromBuffer() |
| COLLADA 로드가 XML 오류로 실패합니다 | xmldom 누락되었거나 일치하지 않음 | 실행 npm install @aspose/3d 다시; xmldom 직접적인 종속성입니다 |
| ASCII 내보내기에서 STL 노멀 손실 | ASCII STL은 면당 법선을 생략합니다 | 사용 binaryMode = true 법선 보존 출력을 위해 |
또 보기
- 특징 및 기능: 씬 그래프, 메시, 재료, 애니메이션 및 수학 API.
- 씬 그래프: 노드 트리를 구축하고 순회합니다.
- How to Build a 3D Mesh Programmatically