API Overview — @aspose/3d for TypeScript

แพคเกจ: @aspose/3d (v24.12.0) ภาษา: TypeScript / Node.js 18+ สัญญาอนุญาต: MIT

@aspose/3d เป็นไลบรารีที่มีสัญญาอนุญาต MIT สำหรับการอ่าน, สร้าง, และส่งออกฉาก 3D ใน Node.js มาพร้อมกับการกำหนดประเภท TypeScript ที่สมบูรณ์, ขึ้นอยู่กับ runtime เพียงหนึ่งตัว ( «<SEG_7»> )xmldom), รองรับไฟล์ฟอร์แมต 3D หลักเจ็ดรูปแบบ การทำ I/O ทั้งหมดเป็นแบบ synchronous ไม่ต้องใช้ native addons.


Properties

npm install @aspose/3d

Properties tsconfig.json การตั้งค่าสำหรับการแก้ไขเส้นทางย่อยอย่างถูกต้อง:

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

คลาสหลัก

Properties

คอนเทนเนอร์รากสำหรับฉาก 3D เนื้อหาทั้งหมด; โหนด, เรขาคณิต, วัสดุ, และแอนิเมชัน; จะถูกจัดเก็บในต้นไม้ที่มีรากที่ scene.rootNode.ใช้ open() / openFromBuffer() เพื่อโหลดไฟล์และ save() / saveToBuffer() เพื่อส่งออก.

PropertiesPropertiesProperties
rootNodeNodeรากของกราฟฉาก
assetInfoAssetInfoเมตาดาต้าไฟล์ (ผู้สร้าง, หน่วย, ระบบพิกัด)
animationClipsAnimationClip[]คลิปแอนิเมชันทั้งหมดในฉาก
open(path, opts?)(string, LoadOptions?) → voidโหลดไฟล์จากดิสก์
openFromBuffer(buf, opts?)(Buffer, LoadOptions?) → voidโหลดจากบัฟเฟอร์ในหน่วยความจำ
save(path, opts?)(string, SaveOptions?) → voidบันทึกลงดิสก์ (รูปแบบสรุปจากส่วนขยาย)
saveToBuffer(ext, opts?)(string, SaveOptions?) → Bufferบันทึกลงบัฟเฟอร์ในหน่วยความจำ
createAnimationClip(name)(string) → AnimationClipสร้างและลงทะเบียนคลิปแอนิเมชันใหม่

Properties

โหนดต้นไม้ที่มีชื่อในกราฟฉาก โหนดบรรจุตัวเลือกเสริม Entity (mesh, camera, light) และ Transform ที่กำหนดตำแหน่งของโหนดสัมพันธ์กับโหนดแม่ของมัน.

PropertiesPropertiesProperties
namestringชื่อโหนด
childNodesNode[]โหนดลูกโดยตรง
entity`Entitynull`
transformTransformการแปล, การหมุน, การสเกล
materialsMaterial[]วัสดุที่กำหนดให้กับโหนดนี้
createChildNode(name)(string) → Nodeเพิ่มโหนดลูก
getChildNode(name)`(string) → Nodenull`

Properties

Polygon mesh; ประเภทเรขาคณิตหลัก ขยายจาก Geometry.

PropertiesPropertiesProperties
controlPointsVector4[]ตำแหน่งเวอร์เท็กซ์ (w=1 สำหรับตำแหน่ง)
polygonCountnumberจำนวนโพลิกอน
createPolygon(indices)(number[]) → voidเพิ่มโพลิกอน (สามเหลี่ยมหรือสี่เหลี่ยม)
getElement(type)`(VertexElementType) → VertexElementnull`
createElement(type)(VertexElementType) → VertexElementสร้างองค์ประกอบเวอร์เท็กซ์

Properties

การแปลงเชิงพื้นที่แบบโลคัลที่ใช้กับโหนด.

PropertiesPropertiesProperties
translationVector3ตำแหน่งท้องถิ่น
eulerAnglesVector3การหมุนออยเลอร์เป็นองศา (ลำดับ XYZ)
rotationQuaternionการหมุนเป็นควอเทอร์เนียน
scalingVector3สเกลท้องถิ่น

คลาสวัสดุ

PropertiesPropertiesคุณสมบัติหลัก
LambertMaterialการเชดดิ้งแบบกระจาย + แสงรอบด้านdiffuseColor, ambientColor, transparency
PhongMaterialเพิ่ม specular + emissive ให้กับ LambertspecularColor, shininess, emissiveColor
PbrMaterialอิงฟิสิกส์สำหรับ glTF 2.0albedo, metallicFactor, roughnessFactor, emissiveColor

คลาสคณิตศาสตร์

PropertiesProperties
Vector33-component double-precision vector (x, y, z)
Vector44-component vector for homogeneous math (x, y, z, w)
FVector3เวอร์ชันความแม่นยำเดี่ยวที่ใช้ในข้อมูลเวอร์เท็กซ์
Matrix44×4 transformation matrix; multiply, invert, decompose
Quaternionควอเทอร์เนียนการหมุน; fromEulerAngle, toEulerAngles, slerp
BoundingBoxกล่องขอบเขตที่จัดแนวตามแกน; minimum, maximum, center, size, merge

คลาสแอนิเมชัน

PropertiesProperties
AnimationClipคลิปที่ตั้งชื่อ; มี AnimationNode รายการ; เข้าถึงผ่าน scene.animationClips
AnimationNodeผูกคลิปกับโหนดซีนที่ตั้งชื่อ; มี AnimationChannel รายการ
AnimationChannelเป้าหมายเป็นคุณสมบัติเดียว (เช่น translation X); เก็บ KeyframeSequence
KeyframeSequenceรายการที่เรียงลำดับของ KeyFrame อ็อบเจกต์ที่มี interpolation และ extrapolation
KeyFrameคู่เวลา/ค่าเดียว

Properties

PropertiesPropertiesProperties
VertexElementTypeNORMAL, UV, VERTEX_COLOR, BINORMAL, TANGENTความหมายขององค์ประกอบเวอร์เท็กซ์
MappingModeCONTROL_POINT, POLYGON_VERTEX, POLYGON, ALL_SAMEวิธีที่ข้อมูลแมปกับเรขาคณิต
ReferenceModeDIRECT, INDEX, INDEX_TO_DIRECTกลยุทธ์การทำดัชนีสำหรับข้อมูลองค์ประกอบเวอร์เท็กซ์
InterpolationCONSTANT, LINEAR, BEZIERการอินเทอร์โพเลชันของคีย์เฟรม
ExtrapolationCONSTANT, GRADIENT, CYCLE, CYCLE_RELATIVE, OSCILLATEพฤติกรรมนอกช่วงคีย์เฟรม

โมดูลฟอร์แมต

คลาสตัวเลือกเฉพาะฟอร์แมตจะถูกส่งออกจากโมดูลย่อยของเส้นทาง แยกนำเข้าแต่ละคลาสตามต้องการ:

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 (@aspose/3d/formats/obj)

Propertiesตัวเลือกคีย์
ObjLoadOptionsenableMaterials, flipCoordinateSystem, scale, normalizeNormal

โมดูล glTF/GLB (@aspose/3d/formats/gltf)

Propertiesตัวเลือกคีย์
GltfSaveOptionsbinaryMode (true → .glb), flipTexCoordV
GltfFormatGltfFormat.getInstance(): อินสแตนซ์รูปแบบสำหรับ scene.save()

โมดูล STL (@aspose/3d/formats/stl)

Propertiesตัวเลือกสำคัญ
StlLoadOptionsN/A
StlSaveOptionsbinaryMode (false → ASCII, true → binary)

โมดูล FBX (@aspose/3d/formats/fbx)

Propertiesตัวเลือกสำคัญ
FbxLoadOptionsN/A
FbxSaveOptionsembedTextures

รูปแบบที่รองรับ

PropertiesPropertiesPropertiesProperties
Properties.objPropertiesProperties
glTF 2.0.gltfPropertiesProperties
Properties.glbPropertiesProperties
STL.stlPropertiesProperties
FBX.fbxไม่*ไม่*
COLLADA.daePropertiesProperties
3MF.3mfPropertiesProperties

ตัวอย่างอ้างอิงอย่างรวดเร็ว

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

ดูเพิ่มเติม

 ภาษาไทย