Rendering Adegan dan Ekspor

@aspose/3d adalah perpustakaan pemrosesan dan konversi, dan tidak melakukan rendering GPU atau menghasilkan file gambar. “Rendering” dalam konteks perpustakaan ini berarti mengekspor sebuah adegan ke format yang dapat dikonsumsi oleh renderer hilir, mesin game, atau penampil.

Halaman ini mencakup semua jalur ekspor: penyimpanan berbasis file, output buffer dalam memori, opsi khusus format, dan cara menyiapkan scene untuk target hilir umum (Three.js, Babylon.js, penampil model, dan mesin game).

Ekspor Dasar

Panggil scene.save() dengan jalur file. Perpustakaan ini menebak format output dari ekstensi file:

import { Scene } from '@aspose/3d';

const scene = new Scene();
scene.open('input.obj');  // use a supported format (OBJ, glTF, GLB, STL, 3MF, COLLADA)

scene.save('output.glb');    // GLB (binary glTF)
scene.save('output.stl');    // STL
scene.save('output.dae');    // COLLADA
scene.save('output.3mf');    // 3MF

Mengekspor ke GLB (Direkomendasikan untuk Web dan Game)

GLB (binary glTF 2.0) adalah satu file mandiri yang menyertakan semua data mesh, material, dan tekstur. Ini adalah format output yang direkomendasikan untuk penampil web (Three.js, Babylon.js, model-viewer) dan mesin game (Godot, Unity melalui importer):

import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

const scene = new Scene();
scene.open('source.obj');

const opts = new GltfSaveOptions();
opts.binaryMode = true;    // produce .glb instead of .gltf + .bin

scene.save('output.glb', opts);
console.log('GLB export complete');

Setel binaryMode = true untuk menghasilkan file GLB yang berdiri sendiri. Ketika false, outputnya adalah sebuah .gltf file JSON dengan sebuah .bin buffer sidecar.

Mengekspor ke glTF (Format JSON untuk Inspeksi)

Varian JSON (.gltf + .bin) berguna selama pengembangan karena JSON dapat dibaca manusia:

import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

const scene = new Scene();
scene.open('input.dae');  // COLLADA is fully supported; FBX is not wired into scene.open()

const opts = new GltfSaveOptions();
opts.binaryMode = false;  // JSON + .bin sidecar

scene.save('output.gltf', opts);

Mengekspor ke STL (Alur Kerja Pencetakan 3D)

STL hanya berisi geometri (tanpa material, tanpa animasi). Ini adalah format pertukaran standar untuk slicer pencetakan 3D:

import { Scene } from '@aspose/3d';
import { StlSaveOptions } from '@aspose/3d/formats/stl';

const scene = new Scene();
scene.open('model.obj');

const opts = new StlSaveOptions();
opts.binaryMode = true;   // binary STL is more compact than ASCII

scene.save('output.stl', opts);

Setel binaryMode = false untuk menghasilkan ASCII STL, yang dapat dibaca sebagai teks tetapi lebih besar.

Mengekspor ke FBX (Alur Kerja Alat DCC)

Catatan: Kelas impor dan ekspor FBX ada di dalam perpustakaan, tetapi deteksi otomatis format FBX tidak terhubung ke scene.open() atau scene.save(). Memanggil scene.save('output.fbx', opts) tidak akan memanggil ekspor FBX — .fbx ekstensi tidak dikenali oleh dispatcher penyimpanan dan pemanggilan akan kembali ke output OBJ. Gunakan FbxExporter kelas secara langsung jika Anda memerlukan I/O FBX. Tabel dukungan format menandai FBX sebagai No* untuk alasan ini.

Jika Anda perlu mengekspor ke format yang diterima oleh Blender, Maya, atau Unreal Engine, gunakan GLB atau COLLADA sebagai gantinya — keduanya sepenuhnya terintegrasi ke dalam scene.save():

import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

const scene = new Scene();
scene.open('input.dae');

// GLB is fully supported and widely accepted by DCC tools
const opts = new GltfSaveOptions();
opts.binaryMode = true;
scene.save('output.glb', opts);

Ekspor In-Memory dengan saveToBuffer()

Untuk fungsi serverless, respons HTTP, dan pipeline streaming, ekspor langsung ke Buffer tanpa menulis ke disk:

import { Scene } from '@aspose/3d';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

function convertToGlbBuffer(inputPath: string): Buffer {
    const scene = new Scene();
    scene.open(inputPath);

    const opts = new GltfSaveOptions();
    opts.binaryMode = true;

    return scene.saveToBuffer('glb', opts);
}

// Express.js / HTTP response example
// const glbBuffer = convertToGlbBuffer('model.obj');
// res.setHeader('Content-Type', 'model/gltf-binary');
// res.send(glbBuffer);

saveToBuffer() menerima string format sebagai argumen pertama (misalnya. 'glb', 'stl', 'obj') dan objek opsi yang sama seperti save().

Menggabungkan openFromBuffer() dan saveToBuffer()

Pipeline konversi sepenuhnya dalam memori tanpa I/O disk pada tahap mana pun:

import { Scene } from '@aspose/3d';
import { ObjLoadOptions } from '@aspose/3d/formats/obj';
import { GltfSaveOptions } from '@aspose/3d/formats/gltf';

function objBufferToGlbBuffer(objData: Buffer): Buffer {
    const scene = new Scene();

    const loadOpts = new ObjLoadOptions();
    loadOpts.enableMaterials = true;
    scene.openFromBuffer(objData, loadOpts);

    const saveOpts = new GltfSaveOptions();
    saveOpts.binaryMode = true;

    return scene.saveToBuffer('glb', saveOpts);
}

Menyiapkan Scene untuk Renderer Spesifik

Three.js / Babylon.js (Web)

Renderer ini secara native memuat file GLB. Ekspor dengan binaryMode = true. Jika tekstur direferensikan dari OBJ sumber, pastikan .mtl dan file gambar berada dalam lokasi yang sama saat memuat.

model-viewer (Web Component)

Menerima .glb langsung. Pengaturan ekspor yang sama seperti Three.js.

Godot Engine

Impor GLB melalui importer Godot (Project → Import). Gunakan binaryMode = true. Godot secara native mendukung material PBR dari glTF 2.0.

Blender

Untuk fidelitas impor terbaik gunakan glTF (output.gltf + output.bin) atau GLB (output.glb). Pengimpor glTF 2.0 Blender menangani material PBR dan animasi. Catatan: FBX output via scene.save() tidak didukung — deteksi otomatis format FBX tidak terhubung ke dispatcher penyimpanan.

3D Printing (Slicers: Cura, PrusaSlicer, Bambu Studio)

Ekspor ke STL atau 3MF. Gunakan 3MF ketika Anda memerlukan warna atau metadata material yang dipertahankan. Gunakan STL untuk kompatibilitas maksimal.

Perbandingan Format Ekspor

FormatEkstensiBahanAnimasiFile TunggalTerbaik Untuk
GLB.glbPBR (glTF 2.0)YaYaWeb, game, pengiriman umum
glTF.gltfPBR (glTF 2.0)YaTidak (+ .bin)Pengembangan, inspeksi
STL.stlTidakTidakYa3D printing, geometry-only
FBX.fbxPhong/PBRTidak*Tidak*Pengimpor/pengekspor ada tetapi tidak terhubung ke deteksi otomatis
COLLADA.daeYaYaYaPertukaran lintas-DCC
3MF.3mfWarna/materialTidakYaPencetakan 3D modern

Masalah Ekspor Umum

GejalaPenyebabPerbaikan
Output GLB terbuka sebagai JSON di penampilbinaryMode dibiarkan sebagai falseAtur opts.binaryMode = true
Tekstur hilang dalam output GLBbinaryMode tidak diaturAtur opts.binaryMode = true untuk GLB mandiri
File STL tidak memiliki warna di slicerFormat STL tidak mendukung warnaGunakan 3MF untuk data berwarna
saveToBuffer mengembalikan buffer kosongArgumen string format hilang atau salahBerikan string format, misalnya. 'glb', 'stl', atau 'obj'
FBX terbuka tanpa animasi di BlenderFile sumber (OBJ/STL) tidak memiliki animasiAnimasi hanya diteruskan jika ada di sumber
File output sangat besarOBJ sumber memiliki banyak vertex duplikatOutput biner GLB sudah menghilangkan duplikasi; periksa kualitas aset sumber

Lihat Juga

 Bahasa Indonesia