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
Enumerations tsconfig.json cài đặt để giải quyết đường dẫn phụ đúng:
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.
| Enumerations | Enumerations | Enumerations |
|---|
rootNode | Node | Gốc của đồ thị cảnh |
assetInfo | AssetInfo | Siêu dữ liệu tệp (người tạo, đơn vị, hệ tọa độ) |
animationClips | AnimationClip[] | Tất cả các clip hoạt ảnh trong cảnh |
open(path, opts?) | (string, LoadOptions?) → void | Tải một tệp từ đĩa |
openFromBuffer(buf, opts?) | (Buffer, LoadOptions?) → void | Tải từ bộ đệm trong bộ nhớ |
save(path, opts?) | (string, SaveOptions?) → void | Lưu vào đĩa (định dạng được suy ra từ phần mở rộng) |
saveToBuffer(ext, opts?) | (string, SaveOptions?) → Buffer | Lưu vào bộ đệm trong bộ nhớ |
createAnimationClip(name) | (string) → AnimationClip | Tạ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ó.
| Enumerations | Enumerations | Enumerations |
|---|
name | string | Tên nút |
childNodes | Node[] | Các nút con trực tiếp |
entity | `Entity | null` |
transform | Transform | Dịch chuyển, quay, tỉ lệ cục bộ |
materials | Material[] | Vật liệu được gán cho nút này |
createChildNode(name) | (string) → Node | Thêm một nút con |
getChildNode(name) | `(string) → Node | null` |
Enumerations
Lưới đa giác; loại hình học chính. Mở rộng Geometry.
| Enumerations | Enumerations | Enumerations |
|---|
controlPoints | Vector4[] | Vị trí đỉnh (w=1 cho vị trí) |
polygonCount | number | Số lượng đa giác |
createPolygon(indices) | (number[]) → void | Thêm một đa giác (tam giác hoặc tứ giác) |
getElement(type) | `(VertexElementType) → VertexElement | null` |
createElement(type) | (VertexElementType) → VertexElement | Tạo một phần tử đỉnh |
Enumerations
Biến đổi cục bộ được áp dụng cho một nút.
| Enumerations | Enumerations | Enumerations |
|---|
translation | Vector3 | Vị trí cục bộ |
eulerAngles | Vector3 | Xoay Euler tính bằng độ (thứ tự XYZ) |
rotation | Quaternion | Xoay dưới dạng quaternion |
scaling | Vector3 | Tỷ lệ cục bộ |
Các lớp vật liệu
| Enumerations | Enumerations | Các thuộc tính chính |
|---|
LambertMaterial | Khuếch tán + ánh sáng môi trường | diffuseColor, ambientColor, transparency |
PhongMaterial | Thêm specular + emissive vào Lambert | specularColor, shininess, emissiveColor |
PbrMaterial | Dựa trên vật lý cho glTF 2.0 | albedo, metallicFactor, roughnessFactor, emissiveColor |
Các lớp toán học
| Enumerations | Enumerations |
|---|
Vector3 | 3-component double-precision vector (x, y, z) |
Vector4 | 4-component vector for homogeneous math (x, y, z, w) |
FVector3 | Biến thể độ chính xác đơn được sử dụng trong vertex data |
Matrix4 | 4×4 transformation matrix; multiply, invert, decompose |
Quaternion | Quaternion quay; fromEulerAngle, toEulerAngles, slerp |
BoundingBox | Axis-aligned bounding box; minimum, maximum, center, size, merge |
Các lớp hoạt ảnh
| Enumerations | Enumerations |
|---|
AnimationClip | Clip có tên; chứa AnimationNode danh sách; truy cập qua scene.animationClips |
AnimationNode | Liên kết một clip tới một nút cảnh có tên; chứa AnimationChannel danh sách |
AnimationChannel | Nhắm mục tiêu một thuộc tính duy nhất (ví dụ: translation X); chứa một KeyframeSequence |
KeyframeSequence | Danh sách có thứ tự của KeyFrame đối tượng với interpolation và extrapolation |
KeyFrame | Cặp thời gian/giá trị đơn |
Enumerations
| Enumerations | Enumerations | Enumerations |
|---|
VertexElementType | NORMAL, UV, VERTEX_COLOR, BINORMAL, TANGENT | Ngữ nghĩa phần tử đỉnh |
MappingMode | CONTROL_POINT, POLYGON_VERTEX, POLYGON, ALL_SAME | Cách dữ liệu ánh xạ tới hình học |
ReferenceMode | DIRECT, INDEX, INDEX_TO_DIRECT | Chiến lược lập chỉ mục cho dữ liệu phần tử đỉnh |
Interpolation | CONSTANT, LINEAR, BEZIER | Nội suy khung chính |
Extrapolation | CONSTANT, GRADIENT, CYCLE, CYCLE_RELATIVE, OSCILLATE | Hà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:
Mô-đun OBJ (@aspose/3d/formats/obj)
| Enumerations | Các tùy chọn chính |
|---|
ObjLoadOptions | enableMaterials, flipCoordinateSystem, scale, normalizeNormal |
Mô-đun glTF/GLB (@aspose/3d/formats/gltf)
| Enumerations | Các tùy chọn chính |
|---|
GltfSaveOptions | binaryMode (true → .glb), flipTexCoordV |
GltfFormat | GltfFormat.getInstance(): thể hiện định dạng cho scene.save() |
Mô-đun STL (@aspose/3d/formats/stl)
| Enumerations | Các tùy chọn chính |
|---|
StlLoadOptions | N/A |
StlSaveOptions | binaryMode (false → ASCII, true → binary) |
Mô-đun FBX (@aspose/3d/formats/fbx)
| Enumerations | Các tùy chọn chính |
|---|
FbxLoadOptions | N/A |
FbxSaveOptions | embedTextures |
Các Định Dạng Được Hỗ Trợ
| Enumerations | Enumerations | Enumerations | Enumerations |
|---|
| Enumerations | .obj | Enumerations | Enumerations |
| glTF 2.0 | .gltf | Enumerations | Enumerations |
| Enumerations | .glb | Enumerations | Enumerations |
| STL | .stl | Enumerations | Enumerations |
| FBX | .fbx | Không* | Không* |
| COLLADA | .dae | Enumerations | Enumerations |
| 3MF | .3mf | Enumerations | Enumerations |
Ví Dụ Tham Khảo Nhanh
Xem Thêm