How to Get Started with Aspose.3D FOSS for TypeScript

How to Get Started with Aspose.3D FOSS for TypeScript

@aspose/3d for TypeScript is a free, MIT-licensed package for loading, manipulating, and saving 3D files in Node.js — no native binaries required, installable from npm.

Step-by-Step Guide

Step 1: Install the Package

Install from npm (Node.js 18 or later required):

npm install @aspose/3d@24.12.0

Verify the install loaded correctly:

import { Scene } from "@aspose/3d";
console.log("@aspose/3d loaded.");

Step 2: Import Required Classes

Import the classes you need from the package:

import { Scene, Node } from "@aspose/3d";

Step 3: Load a 3D File

Use scene.open() to load any supported format. The library detects the format automatically from the file extension:

import { Scene } from "@aspose/3d";

const scene = new Scene();
scene.open("model.obj");
console.log(`Loaded scene. Root node: ${scene.rootNode.name}`);

Or use the static factory method:

const scene = Scene.fromFile("model.glb");

Step 4: Traverse the Scene Graph

A loaded scene is a tree of Node objects rooted at scene.rootNode:

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 = Scene.fromFile("model.obj");
walk(scene.rootNode);

Step 5: Save to a Different Format

Use scene.save() to export to any supported output format. The library detects the output format from the file extension:

import { Scene } from "@aspose/3d";

const scene = Scene.fromFile("model.obj");
scene.save("output.glb");
console.log("Saved as GLB.");

Common Issues and Fixes

Error: ENOENT when calling scene.open() The path you passed does not exist. Use an absolute path or path.resolve() to ensure the file path is correct.

Unknown format error Ensure the file extension matches the actual format. The library detects format by extension for open() and fromFile(). Pass an explicit format parameter to override.

Empty scene after loading Some binary formats may require specific load options. Try using the explicit overload with format-specific options if the default load produces an empty scene.

TypeScript import errors Type definitions are bundled with the package. Ensure "moduleResolution": "bundler" or "node16" is set in your tsconfig.json.

Frequently Asked Questions

Does @aspose/3d require any native binaries?

No. The package is pure JavaScript/TypeScript with no native dependencies. It runs on any platform supporting Node.js 18 or later.

Which Node.js versions are supported?

Node.js 18 or later. The package runs on Windows, macOS, and Linux.

Is the library free for commercial use?

Yes. It is released under the MIT License. You may use, modify, and redistribute it for any purpose, including commercial applications.

Which 3D formats can I read and write?

The package supports OBJ, STL, glTF 2.0 / GLB, FBX, COLLADA, and PLY for both reading and writing. Use the extension-based scene.save() to export to any supported format.

Can I create a 3D scene from scratch?

Yes. Construct a Scene with no arguments, add child nodes to scene.rootNode, and save to the desired format.

See Also