API Overview — @aspose/3d for TypeScript

Gói: @aspose/3d (v24.12.0) Ngôn ngữ: TypeScript / Node.js 18+ Giấy phép: MIT

@aspose/3d là một thư viện có giấy phép MIT để đọc, xây dựng và xuất các cảnh 3D trong Node.js. Nó đi kèm với các định nghĩa kiểu TypeScript đầy đủ, một phụ thuộc runtime duy nhất (xmldom), và hỗ trợ bảy định dạng tệp 3D chính. Tất cả I/O đều đồng bộ. Không cần addon gốc.


Enumerations

npm install @aspose/3d

Enumerations tsconfig.json cài đặt để giải quyết đường dẫn phụ đúng:

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true
  }
}

Các lớp lõi

Enumerations

Bộ chứa gốc cho một cảnh 3D. Tất cả nội dung; các nút, hình học, vật liệu và hoạt ảnh; được lưu trong một cây có gốc tại scene.rootNode.Sử dụng open() / openFromBuffer() để tải một tệp và save() / saveToBuffer() để xuất.

EnumerationsEnumerationsEnumerations
rootNodeNodeGốc của đồ thị cảnh
assetInfoAssetInfoSiêu dữ liệu tệp (người tạo, đơn vị, hệ tọa độ)
animationClipsAnimationClip[]Tất cả các clip hoạt ảnh trong cảnh
open(path, opts?)(string, LoadOptions?) → voidTải một tệp từ đĩa
openFromBuffer(buf, opts?)(Buffer, LoadOptions?) → voidTải từ bộ đệm trong bộ nhớ
save(path, opts?)(string, SaveOptions?) → voidLưu vào đĩa (định dạng được suy ra từ phần mở rộng)
saveToBuffer(ext, opts?)(string, SaveOptions?) → BufferLưu vào bộ đệm trong bộ nhớ
createAnimationClip(name)(string) → AnimationClipTạo và đăng ký một clip hoạt hình mới

Enumerations

Một nút cây có tên trong đồ thị cảnh. Các nút mang một tùy chọn Entity (mesh, camera, light) và một Transform định vị nút so với cha của nó.

EnumerationsEnumerationsEnumerations
namestringTên nút
childNodesNode[]Các nút con trực tiếp
entity`Entitynull`
transformTransformDịch chuyển, quay, tỉ lệ cục bộ
materialsMaterial[]Vật liệu được gán cho nút này
createChildNode(name)(string) → NodeThêm một nút con
getChildNode(name)`(string) → Nodenull`

Enumerations

Lưới đa giác; loại hình học chính. Mở rộng Geometry.

EnumerationsEnumerationsEnumerations
controlPointsVector4[]Vị trí đỉnh (w=1 cho vị trí)
polygonCountnumberSố lượng đa giác
createPolygon(indices)(number[]) → voidThêm một đa giác (tam giác hoặc tứ giác)
getElement(type)`(VertexElementType) → VertexElementnull`
createElement(type)(VertexElementType) → VertexElementTạo một phần tử đỉnh

Enumerations

Biến đổi cục bộ được áp dụng cho một nút.

EnumerationsEnumerationsEnumerations
translationVector3Vị trí cục bộ
eulerAnglesVector3Xoay Euler tính bằng độ (thứ tự XYZ)
rotationQuaternionXoay dưới dạng quaternion
scalingVector3Tỷ lệ cục bộ

Các lớp vật liệu

EnumerationsEnumerationsCác thuộc tính chính
LambertMaterialKhuếch tán + ánh sáng môi trườngdiffuseColor, ambientColor, transparency
PhongMaterialThêm specular + emissive vào LambertspecularColor, shininess, emissiveColor
PbrMaterialDựa trên vật lý cho glTF 2.0albedo, metallicFactor, roughnessFactor, emissiveColor

Các lớp toán học

EnumerationsEnumerations
Vector33-component double-precision vector (x, y, z)
Vector44-component vector for homogeneous math (x, y, z, w)
FVector3Biến thể độ chính xác đơn được sử dụng trong vertex data
Matrix44×4 transformation matrix; multiply, invert, decompose
QuaternionQuaternion quay; fromEulerAngle, toEulerAngles, slerp
BoundingBoxAxis-aligned bounding box; minimum, maximum, center, size, merge

Các lớp hoạt ảnh

EnumerationsEnumerations
AnimationClipClip có tên; chứa AnimationNode danh sách; truy cập qua scene.animationClips
AnimationNodeLiên kết một clip tới một nút cảnh có tên; chứa AnimationChannel danh sách
AnimationChannelNhắm mục tiêu một thuộc tính duy nhất (ví dụ: translation X); chứa một KeyframeSequence
KeyframeSequenceDanh sách có thứ tự của KeyFrame đối tượng với interpolationextrapolation
KeyFrameCặp thời gian/giá trị đơn

Enumerations

EnumerationsEnumerationsEnumerations
VertexElementTypeNORMAL, UV, VERTEX_COLOR, BINORMAL, TANGENTNgữ nghĩa phần tử đỉnh
MappingModeCONTROL_POINT, POLYGON_VERTEX, POLYGON, ALL_SAMECách dữ liệu ánh xạ tới hình học
ReferenceModeDIRECT, INDEX, INDEX_TO_DIRECTChiến lược lập chỉ mục cho dữ liệu phần tử đỉnh
InterpolationCONSTANT, LINEAR, BEZIERNội suy khung chính
ExtrapolationCONSTANT, GRADIENT, CYCLE, CYCLE_RELATIVE, OSCILLATEHành vi ngoài phạm vi keyframe

Các mô-đun Định dạng

Các lớp tùy chọn riêng cho định dạng được xuất khẩu từ các mô-đun con. Nhập chúng riêng biệt:

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

Mô-đun OBJ (@aspose/3d/formats/obj)

EnumerationsCác tùy chọn chính
ObjLoadOptionsenableMaterials, flipCoordinateSystem, scale, normalizeNormal

Mô-đun glTF/GLB (@aspose/3d/formats/gltf)

EnumerationsCác tùy chọn chính
GltfSaveOptionsbinaryMode (true → .glb), flipTexCoordV
GltfFormatGltfFormat.getInstance(): thể hiện định dạng cho scene.save()

Mô-đun STL (@aspose/3d/formats/stl)

EnumerationsCác tùy chọn chính
StlLoadOptionsN/A
StlSaveOptionsbinaryMode (false → ASCII, true → binary)

Mô-đun FBX (@aspose/3d/formats/fbx)

EnumerationsCác tùy chọn chính
FbxLoadOptionsN/A
FbxSaveOptionsembedTextures

Các Định Dạng Được Hỗ Trợ

EnumerationsEnumerationsEnumerationsEnumerations
Enumerations.objEnumerationsEnumerations
glTF 2.0.gltfEnumerationsEnumerations
Enumerations.glbEnumerationsEnumerations
STL.stlEnumerationsEnumerations
FBX.fbxKhông*Không*
COLLADA.daeEnumerationsEnumerations
3MF.3mfEnumerationsEnumerations

Ví Dụ Tham Khảo Nhanh

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

Xem Thêm

 Tiếng Việt