Scene
Methods
Methods Scene class in Aspose.3D serves as the root container for 3D content, managing top-level objects and enabling parent/child relationship management for the scene hierarchy. It provides access to root nodes and sub-scenes, forming the entry point for loading, constructing, and saving 3D scenes.
from aspose.threed import Scene
# Create an empty scene
scene = Scene()
# Access the root node: root_node is a property, not a method call
root = scene.root_nodeMethods
Methods Scene class can be instantiated with no arguments to create an empty scene, or with optional parameters.
| Methods | Methods | Methods |
|---|---|---|
name | str | Optional name of the scene |
entity | Entity | Optional entity to attach to the root node on creation |
parent_scene | Scene | Optional parent scene (for sub-scenes) |
from aspose.threed import Scene
# Empty scene
scene = Scene()
# Access the root node (property, not a method)
root = scene.root_nodeMetode Kelas
| Methods | Tipe Pengembalian | Methods |
|---|---|---|
Scene.from_file(file_path) | Scene | Memuat adegan dari jalur file yang ditentukan, mendeteksi format secara otomatis. Menerima tepat satu argumen. |
from aspose.threed import Scene
from aspose.threed.formats import ObjLoadOptions
# Load from file (format detected from extension)
scene = Scene.from_file("model.obj")
# To pass load options, use scene.open() instead:
opts = ObjLoadOptions()
scene = Scene()
scene.open("model.obj", opts)Methods
root_node dan atribut tingkat adegan lainnya adalah properti; akses mereka tanpa tanda kurung.
| Methods | Methods | Methods |
|---|---|---|
root_node | Node | Node akar dari hierarki adegan. Diakses sebagai properti: scene.root_node |
sub_scenes | list[Scene] | Sub-adegan yang bersarang dalam adegan ini |
asset_info | AssetInfo | Metadata aset seperti penulis, tanggal pembuatan, dan satuan |
animation_clips | list[AnimationClip] | Klip animasi yang didefinisikan dalam adegan |
current_animation_clip | `AnimationClip | None` |
library | list[CustomObject] | Objek metadata yang didefinisikan pengguna yang terlampir pada adegan. |
name | str | Nama objek adegan |
properties | PropertyCollection | Properti khusus yang terlampir pada adegan |
Methods
| Methods | Tipe Pengembalian | Methods |
|---|---|---|
save(file_path) | None | Menyimpan adegan ke file; format diperkirakan dari ekstensi |
save(file_path, format) | None | Menyimpan adegan ke file dalam yang ditentukan FileFormat |
save(file_path, options) | None | Menyimpan adegan menggunakan opsi penyimpanan khusus format |
get_property(name) | Any | Mendapatkan nilai properti berdasarkan nama |
find_property(name) | Optional[Property] | Menemukan properti berdasarkan nama |
create_animation_clip(name) | AnimationClip | Membuat klip animasi bernama baru dan menambahkannya ke adegan |
get_animation_clip(name) | `AnimationClip | None` |
clear() | None | Menghapus semua konten dari adegan |
Catatan: root_node adalah properti pada Scene kelas, bukan metode. Jangan menulis scene.root_node(); akses yang benar adalah scene.root_node.
Methods
Buat sebuah adegan, tambahkan node mesh, dan simpan ke GLB:
from aspose.threed import Scene
from aspose.threed.entities import Mesh
from aspose.threed.formats import GltfSaveOptions
from aspose.threed.utilities import Vector4
# Create scene and mesh
# Note: control_points returns a copy — use _control_points to add vertices
scene = Scene()
mesh = Mesh()
mesh._control_points.append(Vector4(0, 0, 0, 1))
mesh._control_points.append(Vector4(1, 0, 0, 1))
mesh._control_points.append(Vector4(0.5, 1, 0, 1))
mesh.create_polygon(0, 1, 2)
# Add node to root: root_node is a property
node = scene.root_node.create_child_node("triangle", mesh)
# Save as GLB using GltfSaveOptions with binary_mode
opts = GltfSaveOptions()
opts.binary_mode = True
scene.save("triangle.glb", opts)