API Overview — @aspose/3d for TypeScript
패키지: @aspose/3d (v24.12.0) 언어: TypeScript / Node.js 18+ 라이선스: MIT
@aspose/3d MIT 라이선스를 가진 라이브러리로, Node.js에서 3D 씬을 읽고, 구성하고, 내보내는 기능을 제공합니다. 완전한 TypeScript 타입 정의와 단일 런타임 종속성 (xmldom), 그리고 주요 3D 파일 포맷 7가지를 지원합니다. 모든 I/O는 동기식이며, 네이티브 애드온이 필요하지 않습니다.
npm install @aspose/3d{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true
}
}핵심 클래스
3D 씬의 루트 컨테이너입니다. 모든 콘텐츠(노드, 기하, 재질, 애니메이션)는 다음을 루트로 하는 트리에 저장됩니다. scene.rootNode.사용 open() / openFromBuffer() 파일을 로드하고 save() / saveToBuffer() 내보내기.
| —————————- | ——————————— | ————————- |
| rootNode | Node | 씬 그래프의 루트 |
| assetInfo | AssetInfo | 파일 메타데이터(작성자, 단위, 좌표계) |
| animationClips | AnimationClip[] | 씬에 포함된 모든 애니메이션 클립 |
| open(path, opts?) | (string, LoadOptions?) → void | 디스크에서 파일 로드 |
| openFromBuffer(buf, opts?) | (Buffer, LoadOptions?) → void | 인메모리 버퍼에서 로드 |
| save(path, opts?) | Transform | 디스크에 저장 (확장자에서 형식 추론) |
| saveToBuffer(ext, opts?) | (string, SaveOptions?) → Buffer | 인메모리 버퍼에 저장 |
| createAnimationClip(name) | (string) → AnimationClip | 새 애니메이션 클립을 생성하고 등록 |
씬 그래프에서 이름이 지정된 트리 노드입니다. 노드는 선택적인 Entity (mesh, camera, light)와 Transform 노드를 부모에 상대적으로 위치시키는.
| ————————- | ————————- | —————————– |
| name | string | 노드 이름 |
| childNodes | Node[] | 직접 자식 노드 |
| entity | Entity | null | 첨부된 geometry, camera 또는 light |
| transform | Transform | 로컬 변환, 회전, 스케일 |
| materials | Material[] | 이 노드에 할당된 Materials |
| createChildNode(name) | (string) → Node | 자식 노드 추가 |
| getChildNode(name) | (string) → Node | null | 이름으로 자식 찾기 |
폴리곤 메시; 기본 기하학 유형. 확장 Geometry.
| ————————- | ——————————————– | ————————- |
| controlPoints | Vector4[] | 버텍스 위치 (w=1은 위치에 해당) |
| polygonCount | number | 폴리곤 수 |
| createPolygon(indices) | (number[]) → void | 폴리곤 추가 (삼각형 또는 사각형) |
| getElement(type) | (VertexElementType) → VertexElement | null | 시맨틱으로 버텍스 요소 가져오기 |
| createElement(type) | (VertexElementType) → VertexElement | 버텍스 요소 생성 |
노드에 적용되는 로컬 변환.
| ————————- | ————————- | ————————- |
| translation | Vector3 | 로컬 위치 |
| eulerAngles | Vector3 | 도 단위의 오일러 회전 (XYZ 순서) |
| rotation | Quaternion | 쿼터니언 회전 |
| scaling | Vector3 | 로컬 스케일 |
재질 클래스
| ————————- | ——————————– | ————————————————————– |
| LambertMaterial | 디퓨즈 + 앰비언트 셰이딩 | diffuseColor, ambientColor, transparency |
| PhongMaterial | Lambert에 specular + emissive를 추가 | specularColor, shininess, emissiveColor |
| PbrMaterial | glTF 2.0용 물리 기반 | albedo, metallicFactor, roughnessFactor, emissiveColor |
수학 클래스
| ————————- | ———————————————————— |
| Vector3 | 3-component double-precision vector (x, y, z) |
| Vector4 | 4-component vector for homogeneous math (x, y, z, w) |
| FVector3 | 버텍스 데이터에 사용되는 단정밀도 변형 |
| Matrix4 | 4×4 transformation matrix; multiply, invert, decompose |
| Quaternion | 회전 쿼터니언; fromEulerAngle, toEulerAngles, slerp |
| BoundingBox | 축 정렬 경계 상자; minimum, maximum, center, size, merge |
애니메이션 클래스
| ————————- | ————————————————————— |
| AnimationClip | 이름이 지정된 클립; 포함 AnimationNode 목록; 통해 접근 scene.animationClips |
| AnimationNode | 클립을 이름이 지정된 씬 노드에 바인딩; 포함 AnimationChannel 목록 |
| AnimationChannel | 단일 속성(예: translation X)을 목표로 함; 보유 KeyframeSequence |
| KeyframeSequence | 정렬된 목록 KeyFrame 다음과 같은 객체 interpolation 및 extrapolation |
| KeyFrame | 단일 시간/값 쌍 |
| ————————- | ————————————————————– | ————————- |
| VertexElementType | NORMAL, UV, VERTEX_COLOR, BINORMAL, TANGENT | 버텍스 요소 시맨틱 |
| MappingMode | CONTROL_POINT, POLYGON_VERTEX, POLYGON, ALL_SAME | 데이터가 기하학에 매핑되는 방법 |
| ReferenceMode | DIRECT, INDEX, INDEX_TO_DIRECT | 버텍스 요소 데이터에 대한 인덱싱 전략 |
| Interpolation | CONSTANT, LINEAR, BEZIER | 키프레임 보간 |
| Extrapolation | CONSTANT, GRADIENT, CYCLE, CYCLE_RELATIVE, OSCILLATE | 키프레임 범위 외의 동작 |
포맷 모듈
포맷별 옵션 클래스는 서브 경로 모듈에서 내보내집니다. 별도로 임포트하세요:
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
import { GltfSaveOptions, GltfFormat } from '@aspose/3d/formats/gltf';
import { StlLoadOptions, StlSaveOptions } from '@aspose/3d/formats/stl';
import { FbxLoadOptions, FbxSaveOptions } from '@aspose/3d/formats/fbx';
import { ColladaLoadOptions } from '@aspose/3d/formats/collada';
import { ThreeMfSaveOptions } from '@aspose/3d/formats/3mf';OBJ 모듈 (@aspose/3d/formats/obj)
| ————————- | ——————————————————————— |
| ObjLoadOptions | enableMaterials, flipCoordinateSystem, scale, normalizeNormal |
glTF/GLB 모듈 (@aspose/3d/formats/gltf)
| ————————- | ————————————————– |
| GltfSaveOptions | binaryMode (true → .glb), flipTexCoordV |
| GltfFormat | GltfFormat.getInstance(): 형식 인스턴스 scene.save() |
STL 모듈 (@aspose/3d/formats/stl)
| ————————- | ——————————————- |
| StlLoadOptions | N/A |
| StlSaveOptions | binaryMode (false → ASCII, true → binary) |
FBX 모듈 (@aspose/3d/formats/fbx)
| ————————- | ————— |
| FbxLoadOptions | N/A |
| FbxSaveOptions | embedTextures |
지원 포맷
| ————————- | ————————- | ————————- | ————————- |
| FBX | .fbx | 아니오* | 아니오* |
빠른 참조 예제
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';
// Load OBJ with materials
const scene = new Scene();
const loadOpts = new ObjLoadOptions();
loadOpts.enableMaterials = true;
scene.open('input.obj', loadOpts);
// Inspect root nodes
for (const node of scene.rootNode.childNodes) {
console.log(`Node: ${node.name}, entity: ${node.entity?.constructor.name}`);
}
// Export as GLB (binary glTF)
const saveOpts = new GltfSaveOptions();
saveOpts.binaryMode = true;
scene.save('output.glb', saveOpts);