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_node

Constructor

The Scene class can be instantiated with no arguments to create an empty scene, or with optional parameters.

ParameterTypeDescription
namestrOptional name of the scene
entityEntityOptional entity to attach to the root node on creation
parent_sceneSceneOptional 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_node

Class Methods

MethodReturn TypeDescription
Scene.from_file(file_path)SceneLoads a scene from the specified file path, detecting the format automatically.
Scene.from_file(file_path, options)SceneLoads 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.

NameTypeDescription
root_nodeNodeRoot node of the scene hierarchy. Access as a property: scene.root_node
sub_sceneslist[Scene]Sub-scenes nested within this scene
asset_infoAssetInfoAsset metadata such as author, creation date, and units
animation_clipslist[AnimationClip]Animation clips defined in the scene
current_animation_clipAnimationClip | NoneThe currently active animation clip. Read/write.
librarylist[CustomObject]User-defined metadata objects attached to the scene.
namestrName of the scene object
propertiesPropertyCollectionCustom properties attached to the scene

Methods

MethodReturn TypeDescription
save(file_path)NoneSaves the scene to a file; format inferred from extension
save(file_path, format)NoneSaves the scene to a file in the specified FileFormat
save(file_path, options)NoneSaves the scene using format-specific save options
find_node(name)Optional[Node]Finds a node by name in the scene hierarchy
get_property(name)AnyGets a property value by name
find_property(name)Optional[Property]Finds a property by name
create_animation_clip(name)AnimationClipCreates a new named animation clip and adds it to the scene
get_animation_clip(name)AnimationClip | NoneFinds an existing animation clip by name, or None if not found
clear()NoneClears 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)

See Also