はじめに

Aspose.3D FOSS for TypeScript (@aspose/3d) は、主に Node.js 用に設計されたオープンソース、MIT ライセンスの 3D ファイルフォーマットライブラリです。3D モデルビューア、フォーマットコンバータ、ジオメトリ処理ツール、またはサーバーサイドの 3D パイプラインを構築する開発者は、単一コマンドでインストールできます(Installation guide を参照)。すぐに 3D コンテンツの読み込み、構築、エクスポートを開始できます。このライブラリは Node.js の require('fs') と Buffer を使用します。ブラウザでの使用は、これらの API 用の適切なシムが必要で、公式にはサポートされていません。

このライブラリは、主要なインターチェンジフォーマット — OBJ、glTF 2.0 / GLB、STL、3MF、COLLADA をインポートとエクスポートの両方でサポートします。FBX のインポーター/エクスポータークラスは存在しますが、まだフォーマット自動検出には組み込まれていません。シーングラフ API は、3D オーサリングツールで馴染みのあるモデルを鏡像のように再現します:Scene が rootNode を保持し、各 Node は子ノードとエンティティオブジェクト(Mesh、Camera、Light)を保持でき、変換階層は読み書きのために完全にアクセス可能です。

主な機能

  • マルチフォーマット I/O: OBJ のインポートとエクスポート( .mtl マテリアル)、glTF 2.0 / GLB、STL(バイナリおよび ASCII)、3MF、そして COLLADA をファイルパスとインメモリの両方から Buffer オブジェクト。FBX のサポートはまだ自動検出に組み込まれていません。
  • シーングラフ API: Scene, Node, Mesh, Camera, Light 完全な親子管理を備えた階層構造;ノードを再帰的に走査するには node.childNodes
  • PBR マテリアルシステム: Lambert、Phong、そして PBR(metallic/roughness)マテリアルにアクセス可能 via node.material
  • メッシュ操作: 生の頂点データへアクセス mesh.controlPoints (配列 Vector4), ポリゴンインデックスへ mesh.polygonCount, および頂点要素チャンネルへ mesh.getElement()
  • 数学ユーティリティ: Vector2, Vector3, Vector4, Matrix4, Quaternion, 空間計算のためのバウンディングボックスタイプ
  • アニメーションシステム: キーフレームアニメーションを使用した AnimationClip, AnimationChannel, および補間曲線(リニア、ベジエ、TCBスプライン)
  • フォーマット固有のオプション: フォーマット別 LoadOptions / SaveOptions クラスは座標の反転、スケール、マテリアルの読み込み、その他を制御します

はじめに

ソースからパッケージをビルドします。Node.js 18 以上が必要です;TypeScript 5.0 以上を推奨します。

git clone https://github.com/aspose-3d-foss/Aspose.3D-FOSS-for-TypeScript.git
cd Aspose.3D-FOSS-for-TypeScript
npm install
npm run build

OBJ ファイルをロードしてシーンを検査する:

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

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

for (const node of scene.rootNode.childNodes) {
    if (node.entity && 'controlPoints' in node.entity) {
        const mesh = node.entity as any;
        console.log(`Mesh "${node.name}": ${mesh.controlPoints.length} vertices`);
    }
}

シーン グラフ API

すべてのシーンは Node オブジェクトのツリーで、scene.rootNode をルートとしています。addChildNode() で階層を構築し、entity プロパティを介して Camera や Light といったエンティティをノードに付属させ、transform と globalTransform を通じて各ノードのローカルまたはワールド空間の変換を読み取ります。

import { Scene, Node, Camera, Light } from '@aspose/3d';

const scene = new Scene();

const cameraNode = new Node('MainCamera');
cameraNode.entity = new Camera('MainCamera');
scene.rootNode.addChildNode(cameraNode);

const lightNode = new Node('KeyLight');
lightNode.entity = new Light('KeyLight');
scene.rootNode.addChildNode(lightNode);

for (const child of scene.rootNode.childNodes) {
    console.log(`${child.name}: ${child.entity?.constructor.name}`);
}

数学ユーティリティ

Vector3、Vector4、Matrix4、および Quaternion はライブラリ内のすべての幾何演算を支えます。Vector3 と Vector4 は x/y/z(/w) コンポーネントに加えて length、dot()、cross() を公開します;Matrix4 は m00–m33 を通じてアクセスできる 4×4 グリッドで、transpose() と concatenate() を備えています;Quaternion は回転数学のために normalize()、conjugate()、inverse()、dot() を提供します。

import { Vector3, Quaternion, Matrix4 } from '@aspose/3d/utilities';

const position = new Vector3(1.0, 2.0, 3.0);
const rotation = new Quaternion(1.0, 0.0, 0.0, 0.0);
const transform = new Matrix4();

console.log(`length=${position.length} determinant=${transform.determinant}`);
console.log(`rotation w=${rotation.w} x=${rotation.x} y=${rotation.y} z=${rotation.z}`);

参照

関連リソース