TypeScript에서 3D 모델을 저장하는 방법
Aspose.3D FOSS for TypeScript는 단일 모양으로 지원되는 모든 형식에 장면을 저장합니다. scene.save() 전화. 출력 형식은 파일 확장에서 자동으로 감지됩니다.이 가이드는 각 형식을 저장하고 형태 특정 옵션을 사용합니다.
단계별 가이드
단계 1 : 설치 @aspose/3d
asposefoss/3d is not yet published — build from source until it ships. See the project README for build instructions.
단계 2: 장면을 충전하거나 구축하십시오.
기존 파일을 업로드하거나 저장하기 전에 스케치를 프로그래밍으로 만들거나.
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
// Load from file
const scene = new Scene();
scene.open('source.obj', new ObjLoadOptions());
// Or create a new empty scene
const emptyScene = new Scene();단계 3: 자동 감지 형식으로 저장
scene.save(path) 파일 확장에서 출력 형식을 감지합니다 :
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
const scene = new Scene();
scene.open('input.obj', new ObjLoadOptions());
// Save as binary glTF
scene.save('output.glb');
// Save as JSON glTF
scene.save('output.gltf');
// Save as STL
scene.save('output.stl');
// Save as OBJ
scene.save('output.obj');
// Save as 3MF
scene.save('output.3mf');
// Save as COLLADA
scene.save('output.dae');단계 4: 형식 특정 SaveOptions 사용
얇은 제어를 위해, 포맷 특정 옵션 개체를 통과하십시오 :
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
const scene = new Scene();
scene.open('model.obj', new ObjLoadOptions());
// Export to GLB with specific options
const saveOptions = new GltfSaveOptions();
saveOptions.binaryMode = true; // produce GLB (binary glTF)
scene.save('output.glb', saveOptions);5단계 : 버퍼에 저장 (기억에서)
사용하기 scene.saveToBuffer() 생산을 위해서 A Buffer 디스크에 글을 쓰지 않고:
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
const scene = new Scene();
scene.open('model.obj', new ObjLoadOptions());
const buffer = scene.saveToBuffer('glb');
console.log(`Buffer size: ${buffer.length} bytes`);
// Send via HTTP, upload to S3, etc.
단계 6 : 출력 확인하기
저장 후, 파일이 존재하고 0 크기가 아닌 확인하십시오 :
import * as fs from 'fs';
const stats = fs.statSync('output.glb');
console.log(`Saved output.glb: ${stats.size} bytes`);지원 모터리시스
| 확장 | 형식 | 노트 |
|---|---|---|
.glb | GTTF 2.0 바이너리 | glTF에 대한 권장; 모든 자산은 단일 파일에 삽입 |
.gltf | 녹음기 2.0 JSON | 분리된 .bin 그리고 JSON과 함께 텍스트 파일 |
.obj | 웨이브 프론트 OBJ | 글쓰기 .mtl 파일 옆에 있는 .obj 물질이 존재할 때 |
.stl | STL | 기본 : 바이너리 STL; 사용 StlSaveOptions.binaryMode = false ASCII 텍스트 |
.fbx | 오토데스크 FBX | 안 들어오는 것 scene.save() 자기 탐지; 사용 StlExporter 붕괴 경로 |
.3mf | 3D Manufacturing | 3D 인쇄 작업 흐름에 적합합니다. |
.dae | COLLADA | XML 기반 교환 형식 |
일반적인 문제와 해결책
Error: Unsupported format 절약할 때
파일 확장 프로그램이 지원되는 형식과 일치하는지 확인합니다. 도서관은 형식을 탐지하기 위해 확장을 사용합니다; 이름을 가진 파일 output.xyz 실패할 것 이다.
.obj 파일이 저장되지만 자료가 부족합니다.
에 대한 정보는 문서관(.mtl1) 자동으로 옆에 서명한다. .obj.두 파일은 다시 열 때 동일한 디렉토리에 있어야 합니다.만이 지질을 필요로 하는 경우, 설정 ObjSaveOptions.enableMaterials = false.
큰 .gltf 분리된 텍스트를 가지고
사용하기 .glb 대신에 그대는 .gltf; 그것은 단일 자체 콘텐츠 파일에 바이너리 데이터를 결합합니다. GltfSaveOptions.binaryMode = true A를 통과할 때 GltfSaveOptions 사례를 니다.
자주 묻는 질문들
한 번에 여러 형식으로 저장할 수 있습니까?
예; 전화 scene.save() 여러 가지 길로 여러 번 :
scene.save('output.glb');
scene.save('output.stl');
scene.save('output.obj');저축이 장면을 바꾸는가?
아니오 니. scene.save() 스크린 그래프에서 읽을만한 작업입니다.당신은 부작용없이 여러 형식으로 같은 장면을 저장할 수 있습니다.
원본 파일을 과장할 수 있나요?
똑같은 길을 가는 것과 같은 길로 가고, scene.save() 당신이 사용한 것들에 대해서는 scene.open().도서관은 뷔페에 글을 쓰고 디스크에 써야 한다.