Scene — Aspose.3D FOSS for Java

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.

import com.aspose.threed.Scene;

// Create an empty scene
Scene scene = new Scene();

// Access the root node via getter method
Node root = scene.getRootNode();

Constructor

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

ParameterTypeDescription
entityEntityOptional entity to attach to the root node on creation
parentSceneSceneOptional parent scene (for sub-scenes); requires a name
nameStringScene name (only used with the two-argument Scene(Scene, String) constructor)
import com.aspose.threed.Scene;

// Empty scene
Scene scene = new Scene();

// Scene with an initial entity
Scene scene = new Scene(new Mesh());

// Access the root node (getter method)
Node root = scene.getRootNode();

Class Methods

MethodReturn TypeDescription
Scene.fromFile(String filePath)SceneLoads a scene from the specified file path, detecting the format automatically.
Scene.fromFile(String filePath, LoadOptions options)SceneLoads a scene with format-specific load options.
import com.aspose.threed.Scene;


// Load from file (format detected from extension)
Scene scene = Scene.fromFile("model.obj");

// Load with options
ObjLoadOptions opts = new ObjLoadOptions();
Scene scene = Scene.fromFile("model.obj", opts);

Properties

All properties are accessed via getter/setter methods.

NameTypeGetterSetterDescription
rootNodeNodegetRootNode()Root node of the scene hierarchy
subScenesList<Scene>getSubScenes()Sub-scenes nested within this scene
assetInfoAssetInfogetAssetInfo()setAssetInfo(AssetInfo)Asset metadata such as author, creation date, and units
animationClipsList<AnimationClip>getAnimationClips()Animation clips defined in the scene
currentAnimationClipAnimationClipgetCurrentAnimationClip()setCurrentAnimationClip(AnimationClip)The currently active animation clip
libraryList<A3DObject>getLibrary()User-defined metadata objects attached to the scene
nameStringgetName()setName(String)Name of the scene object
propertiesPropertyCollectiongetProperties()Custom properties attached to the scene

Methods

MethodReturn TypeDescription
save(String filePath)voidSaves the scene to a file; format inferred from extension
save(String filePath, FileFormat format)voidSaves the scene to a file in the specified FileFormat
save(String filePath, SaveOptions options)voidSaves the scene using format-specific save options
open(String filePath)voidOpens a file into this scene; format inferred from extension
open(String filePath, LoadOptions options)voidOpens a file with format-specific load options
getProperty(String name)ObjectGets a property value by name
findProperty(String name)PropertyFinds a property by name
createAnimationClip(String name)AnimationClipCreates a new named animation clip and adds it to the scene
getAnimationClip(String name)AnimationClipFinds an existing animation clip by name, or null if not found
clear()voidClears all content from the scene

Example

Create a scene, add a mesh node, and save to GLB:

import com.aspose.threed.Scene;
import com.aspose.threed.FileFormat;



// Create scene and mesh
Scene scene = new Scene();
Mesh mesh = new Mesh();
mesh.getControlPoints().add(new Vector4(0, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(1, 0, 0, 1));
mesh.getControlPoints().add(new Vector4(0.5, 1, 0, 1));
mesh.createPolygon(0, 1, 2);

// Add node to root
Node node = scene.getRootNode().createChildNode("triangle", mesh);

// Save as GLB
GltfSaveOptions glbOpts = new GltfSaveOptions();
glbOpts.setContentType(FileContentType.BINARY);
scene.save("triangle.glb", glbOpts);

See Also