Scene

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

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

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

Metode klase

Return Type
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)

root_node and other scene-level attributes are properties; access them without parentheses.

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_clip`AnimationClipNone`
librarylist[CustomObject]Korisnički definirani objekti metapodataka priloženi sceni.
namestrNaziv objekta scene
propertiesPropertyCollectionPrilagođena svojstva priložena sceni

Tip povratne vrijednosti
save(file_path)NoneSpremi scenu u datoteku; format se zaključuje iz ekstenzije
save(file_path, format)NoneSpremi scenu u datoteku u navedenom FileFormat
save(file_path, options)NoneSpremi scenu koristeći opcije specifične za format
get_property(name)AnyDohvaća vrijednost svojstva po imenu
find_property(name)Optional[Property]Pronalaže svojstvo po imenu
create_animation_clip(name)AnimationClipStvara novi animacijski isječak s imenom i dodaje ga u scenu
get_animation_clip(name)`AnimationClipNone`
clear()NoneČisti sav sadržaj iz scene

Napomena: root_node je svojstvo na Scene klasi, a ne metodi. Nemojte pisati scene.root_node(); ispravan pristup je scene.root_node.

Stvorite scenu, dodajte mesh čvor i spremite u 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
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)

Vidi također

 Hrvatski