Quick Start
Quick Start
This guide shows the fastest path from installation to loading and saving a 3D file using
@aspose/3d for TypeScript. The package is MIT-licensed, pure JavaScript/TypeScript, and
requires no native binaries or platform-specific build tools.
Prerequisites
| Requirement | Detail |
|---|---|
| Node.js | 18 or later |
| OS | Windows, macOS, Linux, Docker |
| Package | @aspose/3d from npm |
Install
Install the package from npm. Type definitions are bundled with the package, so no
separate @types package is needed:
npm install @aspose/3d@24.12.0Load a 3D File
Call scene.open() with a path to load any supported format. The library detects the
format from the file extension. Access the scene hierarchy through scene.rootNode:
import { Scene } from "@aspose/3d";
const scene = new Scene();
scene.open("model.obj");
console.log(`Root node: ${scene.rootNode.name}`);Traverse the Scene Graph
A loaded scene is a tree of Node objects rooted at scene.rootNode. Use
a recursive walk to process each node and its children:
import { Scene, Node } from "@aspose/3d";
function walk(node: Node, depth: number = 0): void {
const indent = " ".repeat(depth * 2);
console.log(`${indent}Node: ${node.name}`);
for (const child of node.childNodes) {
walk(child, depth + 1);
}
}
const scene = new Scene();
scene.open("model.glb");
walk(scene.rootNode);Save to a Different Format
The library detects the output format from the file extension. Call scene.save() with
the output path to convert between formats:
import { Scene } from "@aspose/3d";
const scene = new Scene();
scene.open("model.obj");
scene.save("output.glb");
console.log("Converted to GLB.");Create a New Scene and Save
Construct a Scene with no arguments to start empty, add child nodes to
scene.rootNode, then call scene.save() to write the file:
import { Scene, Node } from "@aspose/3d";
const scene = new Scene();
const box = scene.rootNode.createChildNode("box");
scene.save("new_scene.obj");