Scene
بسته: @aspose/3d (v24.12.0)
Scene ریشهٔ مخزن برای یک گراف صحنهٔ سهبعدی در @aspose/3d. این سلسلهمراتب گرهها، فرادادهها و کلیپهای انیمیشن را نگه میدارد و رابط I/O اصلی برای بارگذاری و ذخیرهسازی فایلهای سهبعدی را فراهم میکند.
export class Scene extends SceneObjectColladaSaveOptions
A3DObject ← SceneObject ← Scene
ColladaSaveOptions
یک فایل OBJ را بارگذاری کنید و تعداد گرههای فرزند در ریشهٔ گراف صحنه را چاپ کنید.
import { Scene } from '@aspose/3d';
const scene = new Scene();
scene.open('model.obj');
function countNodes(node: any): number {
let total = 1;
for (const child of node.childNodes) {
total += countNodes(child);
}
return total;
}
const nodeCount = countNodes(scene.rootNode);
console.log(`Total nodes in scene: ${nodeCount}`);ColladaSaveOptions
| Name | Type | Access | Description |
|---|---|---|---|
VERSION | `` | Read | Gets the version. |
rootNode | Node | Read | Gets the root node. |
subScenes | Scene[] | Read | Gets the sub scenes. |
library | CustomObject[] | Read | Gets the library. |
assetInfo | AssetInfo | Read/Write | Gets the asset info. |
animationClips | AnimationClip[] | Read | Gets the animation clips. |
currentAnimationClip | `AnimationClip | null` | Read/Write |
poses | any[] | Read | Gets the poses. |
| Signature | Description |
|---|---|
constructor() | Creates a scene containing the specified entity |
constructor(entity: Entity) | |
constructor(parentScene: Scene, name: string) | |
constructor() | |
clear() | Removes all nodes, assets and animation data from the scene |
createAnimationClip(name: string) → AnimationClip | Creates a new animation clip with the given name |
getAnimationClip(name: string) → `AnimationClip | null` |
open(fileOrStream: any, options: any) | Loads scene data from a file path or stream using options |
| `openFromBuffer(buffer: Buffer | Uint8Array, options: any)` |
save(fileOrStream: any, formatOrOptions: any, options: any) | Writes the scene to a file or stream |
saveToBuffer(format: string, _options: any) → Buffer | Returns a Buffer containing the scene in the given format |
render(_camera: any, _file_name_or_bitmap: any, _size: any, _format: any, _options: any) | Not implemented in the FOSS edition — throws at runtime. Renders the scene with the camera to an image |
fromFile(fileName: string) → Scene | Loads a scene from the specified file and returns the scene |
toString() → string |
ColladaSaveOptions
open(fileOrStream, options?)
یک فایل 3D را از مسیر فایل یا یک Buffer به صحنه بارگذاری میکند و محتوای موجود را جایگزین میکند.
open(fileOrStream: string | Buffer, options?: LoadOptions): voidColladaSaveOptions
fileOrStream string | Buffer
مسیر فایل منبع، یا یک Buffer حاوی دادههای خام فایل.
options LoadOptions (اختیاری)
گزینههای بارگذاری مخصوص فرمت. ارسال کنید undefined برای استفاده از پیشفرضها.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene();
scene.open(‘input.fbx’);
console.log(Loaded scene with root node: ${scene.rootNode.name});
---
### openFromBuffer(buffer, options?)
فایلی 3D را از حافظهٔ درونحافظهای بارگذاری میکند `Buffer`. این بارگذاری ترجیحی است زمانی که دادههای فایل قبلاً در حافظه خوانده شدهاند.
```typescript
openFromBuffer(buffer: Buffer, options?: LoadOptions): voidColladaSaveOptions
buffer Buffer
یک Node.js Buffer حاوی محتوای کامل فایل.
گزینههای بارگذاری مخصوص فرمت.
ColladaSaveOptions
void
ColladaSaveOptions
import { Scene } from '@aspose/3d';
import { readFileSync } from 'fs';
const data = readFileSync('model.glb');
const scene = new Scene();
scene.openFromBuffer(data);
console.log(`Animation clips: ${scene.animationClips.length}`);save(fileOrStream, formatOrOptions?, options?)
صحنه را در یک فایل ذخیره میکند. قالب از پسوند فایل استخراج میشود، یا میتوانید یک قالبخاص SaveOptions نمونه (یا یک FileFormat singleton) به عنوان آرگومان دوم.
save(fileOrStream: string, formatOrOptions?: FileFormat | SaveOptions, options?: SaveOptions): voidColladaSaveOptions
fileOrStream string
مسیر فایل مقصد. پسوند تعیینکنندهٔ فرمت خروجی است (مثلاً., .glb → GLB, .gltf → glTF JSON،, .stl → STL).
formatOrOptions FileFormat | SaveOptions (اختیاری)
یا یک تکنماد فرمت (مثلاً., GltfFormat.getInstance()) یا یک فرمتخاص SaveOptions زیرکلاس.
options SaveOptions (اختیاری)
گزینههای ذخیرهسازی مخصوص فرمت هنگامیکه یک FileFormat به عنوان آرگومان دوم ارسال میشود.
ColladaSaveOptions
void
ColladaSaveOptions
const scene = new Scene(); scene.open(‘input.obj’);
// Format inferred from extension scene.save(‘output.glb’); console.log(‘Scene saved as GLB.’);
---
### createAnimationClip(name)
یک کلیپ انیمیشن نامدار جدید ایجاد میکند و آن را به صحنهٔ `animationClips` مجموعه.
```typescript
createAnimationClip(name: string): AnimationClipColladaSaveOptions
name string
یک نام توصیفی برای کلیپ انیمیشن جدید.
ColladaSaveOptions
AnimationClip
مورد تازه ایجاد شده AnimationClip نمونه.
ColladaSaveOptions
const scene = new Scene();
const clip = scene.createAnimationClip(‘WalkCycle’);
console.log(Created clip: ${clip.name});
console.log(Total clips: ${scene.animationClips.length});