常见问题

常见问题

如何安装 @aspose/3d?

从 npm 安装。需要 Node.js 18 或更高版本:

npm install @aspose/3d

验证安装:

import { Scene } from '@aspose/3d';
const scene = new Scene();
console.log('@aspose/3d ready');

TypeScript 类型定义已随包一起捆绑。无需单独的 @types/ 包。


哪些文件格式受支持?

格式导入导出
OBJ (Wavefront)
glTF 2.0 / GLB
FBX (Autodesk)否*否*
STL (Stereo Lithography)
3MF (3D Manufacturing)
COLLADA (.dae)

如何加载 3D 文件?

创建一个 Scene 并调用 scene.open()

import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';

const scene = new Scene();
scene.open('model.obj', new ObjLoadOptions());

对于不需要特殊选项的格式,省略第二个参数:

const scene = new Scene();
scene.open('model.glb');

scene.open() 是异步的吗?

不。scene.open()scene.openFromBuffer() 是同步调用。如果需要非阻塞 I/O,请在 Node.js 工作线程中运行它们,或使用 setImmediate 包装。


如何保存为 glTF/GLB?

使用文件路径调用 scene.save()。格式会根据扩展名自动检测:

scene.save('output.glb');   // binary glTF
scene.save('output.gltf');  // JSON glTF
scene.save('output.obj');   // OBJ
scene.save('output.stl');   // STL

如何从缓冲区(内存中)加载?

使用 scene.openFromBuffer()

import * as fs from 'fs';
import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';

const buffer = fs.readFileSync('model.obj');
const scene = new Scene();
scene.openFromBuffer(buffer, new ObjLoadOptions());

错误:找不到模块 ‘@aspose/3d/formats/obj’

这需要 Node.js 12.7+ 包导出解析。确保您使用的是 Node.js 18+。对于 TypeScript,请在 tsconfig.json 中设置 "moduleResolution": "node16""bundler"

{
  "compilerOptions": {
    "moduleResolution": "node16",
    "target": "ES2020"
  }
}

node.entity 的类型是什么?

node.entity 被广泛类型化。要访问网格特定属性,请使用 'controlPoints' in node.entity 检查其是否存在,或使用来自 @aspose/3d/entitiesMesh 类:

import { Mesh } from '@aspose/3d/entities';

if (node.entity instanceof Mesh) {
    const mesh = node.entity;
    console.log(mesh.controlPoints.length);
}

该库可以在浏览器中运行吗?

该库专为 Node.js 设计。浏览器支持取决于打包工具的配置以及文件系统 API 被替换为内存替代方案。


该库是线程安全的吗?

每个 Scene 对象是独立的。使用来自不同 Node.js 工作线程的独立 Scene 实例是安全的,只要您不在没有外部同步的情况下跨线程共享单个场景。


支持哪些 Node.js 版本?

Node.js 18、20 和 22 正式受支持。建议使用 TypeScript 5.0+。


@aspose/3d 支持动画吗?

是的。动画系统包括 AnimationClipAnimationChannel,以及可从 @aspose/3d/animation 访问的关键帧曲线类型。


另请参阅

 中文