API Overview — @aspose/3d for TypeScript

Pachet: @aspose/3d (v24.12.0) Limbaj: TypeScript / Node.js 18+ Licență: MIT

@aspose/3d este o bibliotecă MIT-licensed pentru citirea, construirea și exportarea scenelor 3D în Node.js. Vine cu definiții complete de tipuri TypeScript, o singură dependență la runtime.xmldom), și acceptă șapte formate majore de fișiere 3D. Toate operațiile I/O sunt sincronizate. Nu sunt necesare addon-uri native.


npm install @aspose/3d
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true
  }
}

Clase de bază

Containerul rădăcină pentru o scenă 3D. Tot conținutul; noduri, geometrie, materiale și animații; este stocat într-un arbore cu rădăcina la scene.rootNode. Folosește open() / openFromBuffer() pentru a încărca un fișier și save() / saveToBuffer() pentru export.

| —————————- | ——————————— | ————————————————————– | | rootNode | Node | Rădăcina graficului scenei | | assetInfo | AssetInfo | Metadatele fișierului (creator, unități, sistem de coordonate) | | animationClips | AnimationClip[] | Toate clipurile de animație din scenă | | open(path, opts?) | (string, LoadOptions?) → void | Încarcă un fișier de pe disc | | openFromBuffer(buf, opts?) | (Buffer, LoadOptions?) → void | Încarcă dintr-un buffer în memorie | | save(path, opts?) | Transform | Salvează pe disc (format dedus din extensie) | | saveToBuffer(ext, opts?) | (string, SaveOptions?) → Buffer | Salvează în buffer în memorie | | createAnimationClip(name) | (string) → AnimationClip | Creează și înregistrează un nou clip de animație |

Un nod de arbore denumit în graficul scenei. Nodurile poartă un opțional Entity (mesh, cameră, lumină) și un Transform care poziționează nodul relativ la părintele său.

| ————————- | ————————- | ———————————— | | name | string | Nume nod | | childNodes | Node[] | Noduri copil directe | | entity | Entity | null | Geometrie, cameră sau lumină atașată | | transform | Transform | Translație, rotație și scară locale | | materials | Material[] | Materiale atribuite acestui nod | | createChildNode(name) | (string) → Node | Adaugă un nod copil | | getChildNode(name) | (string) → Node | null | Găsește un copil după nume |

Plasă poligonală; tipul principal de geometrie. Extinde Geometry.

| ————————- | ——————————————– | ——————————————– | | controlPoints | Vector4[] | Poziții ale vârfurilor (w=1 pentru poziții) | | polygonCount | number | Număr de poligoane | | createPolygon(indices) | (number[]) → void | Adaugă un poligon (triunghi sau cvadrilater) | | getElement(type) | (VertexElementType) → VertexElement | null | Obține un element de vârf după semantică | | createElement(type) | (VertexElementType) → VertexElement | Creează un element de vârf |

Transformare locală aplicată unui nod.

| ————————- | ————————- | ———————————- | | translation | Vector3 | Poziție locală | | eulerAngles | Vector3 | Rotire Euler în grade (ordine XYZ) | | rotation | Quaternion | Rotire ca quaternion | | scaling | Vector3 | Scară locală |


Clase de material

| ————————- | ———————————– | ————————————————————– | | LambertMaterial | Umbrare difuză + ambientală | diffuseColor, ambientColor, transparency | | PhongMaterial | Adaugă specular + emisiv la Lambert | specularColor, shininess, emissiveColor | | PbrMaterial | Bazat pe fizică pentru glTF 2.0 | albedo, metallicFactor, roughnessFactor, emissiveColor |


Clase matematice

| ————————- | ———————————————————————————— | | Vector3 | 3-component double-precision vector (x, y, z) | | Vector4 | 4-component vector for homogeneous math (x, y, z, w) | | FVector3 | Variantă cu precizie simplă utilizată în datele de vârf | | Matrix4 | 4×4 transformation matrix; multiply, invert, decompose | | Quaternion | Cuaternion de rotație; fromEulerAngle, toEulerAngles, slerp | | BoundingBox | Cutie de delimitare aliniată pe axe; minimum, maximum, center, size, merge |


Clase de animație

| ————————- | ——————————————————————————— | | AnimationClip | Clip numit; conține AnimationNode listă; accesată prin scene.animationClips | | AnimationNode | Leagă un clip de un nod de scenă numit; conține AnimationChannel listă | | AnimationChannel | Vizează o singură proprietate (de ex. translație X); deține un KeyframeSequence | | KeyframeSequence | Listă ordonată de KeyFrame obiecte cu interpolation și extrapolation | | KeyFrame | Pereche unică timp/valoare |


| ————————- | ————————————————————– | —————————————————— | | VertexElementType | NORMAL, UV, VERTEX_COLOR, BINORMAL, TANGENT | Semantică element vertex | | MappingMode | CONTROL_POINT, POLYGON_VERTEX, POLYGON, ALL_SAME | Cum se mapază datele la geometrie | | ReferenceMode | DIRECT, INDEX, INDEX_TO_DIRECT | Strategie de indexare pentru datele elementului vertex | | Interpolation | CONSTANT, LINEAR, BEZIER | Interpolare cadru cheie | | Extrapolation | CONSTANT, GRADIENT, CYCLE, CYCLE_RELATIVE, OSCILLATE | Comportament în afara intervalului cadrelor cheie |


Module de format

Clasele de opțiuni specifice formatului sunt exportate din modulele sub-căilor. Importați-le separat:

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';

Modul OBJ (@aspose/3d/formats/obj)

| ————————- | ——————————————————————— | | ObjLoadOptions | enableMaterials, flipCoordinateSystem, scale, normalizeNormal |

Modul glTF/GLB (@aspose/3d/formats/gltf)

| ————————- | ——————————————————————- | | GltfSaveOptions | binaryMode (true → .glb), flipTexCoordV | | GltfFormat | GltfFormat.getInstance():instanță de format pentru scene.save() |

Modul STL (@aspose/3d/formats/stl)

| ————————- | —————————————— | | StlLoadOptions | N/A | | StlSaveOptions | binaryMode (false → ASCII, true → binar) |

Modul FBX (@aspose/3d/formats/fbx)

| ————————- | ————— | | FbxLoadOptions | N/A | | FbxSaveOptions | embedTextures |


Formate suportate

| ————————- | ————————- | ————————- | ————————- | | FBX | .fbx | Nu* | Nu* |


Exemplu de referință rapidă

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);

Vezi și

 Română