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.
| Parameter | Type | Description |
|---|---|---|
entity | Entity | Optional entity to attach to the root node on creation |
parentScene | Scene | Optional parent scene (for sub-scenes); requires a name |
name | String | Scene 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
| Method | Return Type | Description |
|---|---|---|
Scene.fromFile(String filePath) | Scene | Loads a scene from the specified file path, detecting the format automatically. |
Scene.fromFile(String filePath, LoadOptions options) | Scene | Loads 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.
| Name | Type | Getter | Setter | Description |
|---|---|---|---|---|
rootNode | Node | getRootNode() | – | Root node of the scene hierarchy |
subScenes | List<Scene> | getSubScenes() | – | Sub-scenes nested within this scene |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | Asset metadata such as author, creation date, and units |
animationClips | List<AnimationClip> | getAnimationClips() | – | Animation clips defined in the scene |
currentAnimationClip | AnimationClip | getCurrentAnimationClip() | setCurrentAnimationClip(AnimationClip) | The currently active animation clip |
library | List<A3DObject> | getLibrary() | – | User-defined metadata objects attached to the scene |
name | String | getName() | setName(String) | Name of the scene object |
properties | PropertyCollection | getProperties() | – | Custom properties attached to the scene |
Methods
| Method | Return Type | Description |
|---|---|---|
save(String filePath) | void | Saves the scene to a file; format inferred from extension |
save(String filePath, FileFormat format) | void | Saves the scene to a file in the specified FileFormat |
save(String filePath, SaveOptions options) | void | Saves the scene using format-specific save options |
open(String filePath) | void | Opens a file into this scene; format inferred from extension |
open(String filePath, LoadOptions options) | void | Opens a file with format-specific load options |
getProperty(String name) | Object | Gets a property value by name |
findProperty(String name) | Property | Finds a property by name |
createAnimationClip(String name) | AnimationClip | Creates a new named animation clip and adds it to the scene |
getAnimationClip(String name) | AnimationClip | Finds an existing animation clip by name, or null if not found |
clear() | void | Clears 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);