API Overview — @aspose/3d for TypeScript
Pakotne: @aspose/3d (v24.12.0) Valoda: TypeScript / Node.js 18+ Licence: MIT
@aspose/3d ir MIT licencēta bibliotēka 3D skenējumu lasīšanai, konstruēšanai un eksportēšanai Node.js vidē. Tā tiek piegādāta ar pilnīgiem TypeScript tipa definīcijām, vienu izpildlaika atkarību (xmldom), un atbalsta septiņas galvenās 3D failu formātus. Visa I/O ir sinhroniska. Nav vajadzīgi dabiskie papildinājumi.
npm install @aspose/3d{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true
}
}Pamatklases
Saknes konteineris 3D scenai. Visa saturs; mezgli, ģeometrija, materiāli un animācijas; tiek glabāts koks, kura sakne ir scene.rootNode.Izmantojiet open() / openFromBuffer() lai ielādētu failu un save() / saveToBuffer() eksportētu.
| —————————- | ——————————— | ——————————————————- |
| rootNode | Node | Sakne skenes grafā |
| assetInfo | AssetInfo | Faila metadati (radītājs, vienības, koordinātu sistēma) |
| animationClips | AnimationClip[] | Visi animācijas klipi scenā |
| open(path, opts?) | (string, LoadOptions?) → void | Ielādēt failu no diska |
| openFromBuffer(buf, opts?) | (Buffer, LoadOptions?) → void | Ielādēt no atmiņā esoša bufera |
| save(path, opts?) | Transform | Saglabāt uz diska (formāts noteikts no paplašinājuma) |
| saveToBuffer(ext, opts?) | (string, SaveOptions?) → Buffer | Saglabāt atmiņā esošā buferī |
| createAnimationClip(name) | (string) → AnimationClip | Izveidot un reģistrēt jaunu animācijas klipu |
Nosaukts koka mezgls ainas grafā. Mezgli nes neobligātu Entity (mesh, kamera, gaisma) un Transform kas pozicionē mezglu attiecībā pret tā vecāku.
| ————————- | ————————- | —————————————- |
| name | string | Mezgla nosaukums |
| childNodes | Node[] | Tieši bērna mezgli |
| entity | Entity | null | Pievienotā ģeometrija, kamera vai gaisma |
| transform | Transform | Lokāla pārvietošana, rotācija, mērogs |
| materials | Material[] | Materiāli, kas piešķirti šim mezglam |
| createChildNode(name) | (string) → Node | Pievienot bērna mezglu |
| getChildNode(name) | (string) → Node | null | Atrast bērnu pēc nosaukuma |
Poligonu režģis; galvenais ģeometrijas veids. Paplašina Geometry.
| ————————- | ——————————————– | ——————————————- |
| controlPoints | Vector4[] | Virsotnes pozīcijas (w=1 pozīcijām) |
| polygonCount | number | Poligonu skaits |
| createPolygon(indices) | (number[]) → void | Pievienot poligonu (trīsstūri vai kvadrāti) |
| getElement(type) | (VertexElementType) → VertexElement | null | Iegūt virsotnes elementu pēc semantikas |
| createElement(type) | (VertexElementType) → VertexElement | Izveidot virsotnes elementu |
Lokāla transformācija, kas piemērota mezglam.
| ————————- | ————————- | ———————————– |
| translation | Vector3 | Lokālā pozīcija |
| eulerAngles | Vector3 | Eilera rotācija grādos (XYZ secība) |
| rotation | Quaternion | Rotācija kā kvaternions |
| scaling | Vector3 | Lokālais mērogs |
Materiālu klases
| ————————- | ————————————– | ————————————————————– |
| LambertMaterial | Difūzs + apvidus ēnojums | diffuseColor, ambientColor, transparency |
| PhongMaterial | Pievieno spekulāro + emisīvo Lambertam | specularColor, shininess, emissiveColor |
| PbrMaterial | Fizikāli balstīts glTF 2.0 | albedo, metallicFactor, roughnessFactor, emissiveColor |
Matemātikas klases
| ————————- | —————————————————————————— |
| Vector3 | 3-component double-precision vector (x, y, z) |
| Vector4 | 4-component vector for homogeneous math (x, y, z, w) |
| FVector3 | Vienkāršas precizitātes variants, ko izmanto virsotņu datos |
| Matrix4 | 4×4 transformation matrix; multiply, invert, decompose |
| Quaternion | Rotācijas kvaternions; fromEulerAngle, toEulerAngles, slerp |
| BoundingBox | Axiālu izlīdzināta robežkaste; minimum, maximum, center, size, merge |
Animācijas klases
| ————————- | ———————————————————————————— |
| AnimationClip | Nosaukts klips; satur AnimationNode saraksts; piekļūst caur scene.animationClips |
| AnimationNode | Saista klipu ar nosauktu ainas mezglu; satur AnimationChannel saraksts |
| AnimationChannel | Mērķē uz vienu īpašību (piemēram, pārvietojums X); satur KeyframeSequence |
| KeyframeSequence | Kārtots saraksts ar KeyFrame objektus ar interpolation un extrapolation |
| KeyFrame | Viena laika/vērtības pāra |
| ————————- | ————————————————————– | ————————————————- |
| VertexElementType | NORMAL, UV, VERTEX_COLOR, BINORMAL, TANGENT | Virsotnes elementa semantika |
| MappingMode | CONTROL_POINT, POLYGON_VERTEX, POLYGON, ALL_SAME | Kā dati tiek kartēti uz ģeometriju |
| ReferenceMode | DIRECT, INDEX, INDEX_TO_DIRECT | Indeksēšanas stratēģija virsotnes elementa datiem |
| Interpolation | CONSTANT, LINEAR, BEZIER | Atslēgas kadru interpolācija |
| Extrapolation | CONSTANT, GRADIENT, CYCLE, CYCLE_RELATIVE, OSCILLATE | Uzvedība ārpus atslēgkadra diapazona |
Formāta moduļi
Formātam specifiskās opciju klases tiek eksportētas no apakšceļu moduļiem. Importējiet tās atsevišķi:
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';OBJ modulis (@aspose/3d/formats/obj)
| ————————- | ——————————————————————— |
| ObjLoadOptions | enableMaterials, flipCoordinateSystem, scale, normalizeNormal |
glTF/GLB Modulis (@aspose/3d/formats/gltf)
| ————————- | —————————————————————— |
| GltfSaveOptions | binaryMode (true → .glb), flipTexCoordV |
| GltfFormat | GltfFormat.getInstance(): formāta instance priekš scene.save() |
STL modulis (@aspose/3d/formats/stl)
| ————————- | ——————————————- |
| StlLoadOptions | N/A |
| StlSaveOptions | binaryMode (false → ASCII, true → binārs) |
FBX modulis (@aspose/3d/formats/fbx)
| ————————- | —————- |
| FbxLoadOptions | N/A |
| FbxSaveOptions | embedTextures |
Atbalstītie formāti
| ————————- | ————————- | ————————- | ————————- |
| FBX | .fbx | Nē* | Nē* |
Ātrais atsauces piemērs
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);