Scene
Overview
The 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_nodeConstructor
The Scene class can be instantiated with no arguments to create an empty scene, or with optional parameters.
| Parameter | Type | Description |
|---|---|---|
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_nodeClass Methods
| Method | Return Type | Description |
|---|---|---|
Scene.from_file(file_path) | Scene | Loads a scene from the specified file path, detecting the format automatically. |
Scene.from_file(file_path, options) | Scene | Loads a scene with format-specific load options. |
from aspose.threed import Scene
from aspose.threed.formats import ObjLoadOptions
# Load from file (format detected from extension)
scene = Scene.from_file("model.obj")
# Load with options
opts = ObjLoadOptions()
scene = Scene.from_file("model.obj", opts)Properties
root_node and other scene-level attributes are properties; access them without parentheses.
| Name | Type | Description |
|---|---|---|
root_node | Node | Root node of the scene hierarchy. Access as a property: scene.root_node |
sub_scenes | list[Scene] | Sub-scenes nested within this scene |
asset_info | AssetInfo | Asset metadata such as author, creation date, and units |
animation_clips | list[AnimationClip] | Animation clips defined in the scene |
current_animation_clip | AnimationClip | None | The currently active animation clip. Read/write. |
library | list[CustomObject] | User-defined metadata objects attached to the scene. |
name | str | Name of the scene object |
properties | PropertyCollection | Custom properties attached to the scene |
Methods
| Method | Return Type | Description |
|---|---|---|
save(file_path) | None | Saves the scene to a file; format inferred from extension |
save(file_path, format) | None | Saves the scene to a file in the specified FileFormat |
save(file_path, options) | None | Saves the scene using format-specific save options |
find_node(name) | Optional[Node] | Finds a node by name in the scene hierarchy |
get_property(name) | Any | Gets a property value by name |
find_property(name) | Optional[Property] | Finds a property by name |
create_animation_clip(name) | AnimationClip | Creates a new named animation clip and adds it to the scene |
get_animation_clip(name) | AnimationClip | None | Finds an existing animation clip by name, or None if not found |
clear() | None | Clears all content from the scene |
Note: root_node is a property on the Scene class, not a method. Do not write scene.root_node(); the correct access is scene.root_node.
Example
Create a scene, add a mesh node, and save to GLB:
from aspose.threed import Scene, FileFormat
from aspose.threed.entities import Mesh
from aspose.threed.utilities import Vector4
# Create scene and mesh
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
scene.save("triangle.glb", FileFormat.GLTF2_BINARY)