Scene — Aspose.3D FOSS for Java
Example
Example 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();Example
Example Scene class can be instantiated with no arguments to create an empty scene, or with optional parameters.
| Example | Example | Example |
|---|---|---|
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();Metode klase
| Example | Return Type | Example |
|---|---|---|
Scene.fromFile(String filePath) | Scene | Loads a scene from the specified file path, detecting the format automatically. |
Scene.fromFile(String filePath, LoadOptions options) | Scene | Učita scenu sa opcijama učitavanja specifičnim za format. |
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);Example
Sva svojstva se pristupaju putem getter/setter metoda.
| Example | Example | Example | Example | Example |
|---|---|---|---|---|
rootNode | Node | getRootNode() | – | Koreni čvor hijerarhije scene |
subScenes | List<Scene> | getSubScenes() | – | Podscene ugnježdene u ovoj sceni |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | Metapodaci sredstva kao što su autor, datum kreiranja i jedinice |
animationClips | List<AnimationClip> | getAnimationClips() | – | Animacioni klipovi definisani u sceni |
currentAnimationClip | AnimationClip | getCurrentAnimationClip() | setCurrentAnimationClip(AnimationClip) | Trenutno aktivni animacioni klip |
library | List<A3DObject> | getLibrary() | – | Korisnički definisani objekti metapodataka prikačeni na scenu |
name | String | getName() | setName(String) | Naziv objekta scene |
properties | PropertyCollection | getProperties() | – | Prilagođena svojstva vezana za scenu |
Example
| Example | Tip povratne vrednosti | Example |
|---|---|---|
save(String filePath) | void | Sačuva scenu u fajl; format se zaključuje iz ekstenzije |
save(String filePath, FileFormat format) | void | Sačuva scenu u fajl u navedenom FileFormat |
save(String filePath, SaveOptions options) | void | Sačuva scenu koristeći opcije za čuvanje specifične za format |
open(String filePath) | void | Otvara fajl u ovu scenu; format se zaključuje iz ekstenzije |
open(String filePath, LoadOptions options) | void | Otvara fajl sa opcijama učitavanja specifičnim za format |
getProperty(String name) | Object | Dobija vrednost svojstva po imenu |
findProperty(String name) | Property | Pronalaže svojstvo po imenu |
createAnimationClip(String name) | AnimationClip | Kreira novi nazvani klip animacije i dodaje ga u scenu |
getAnimationClip(String name) | AnimationClip | Pronalaže postojeći klip animacije po imenu, ili null ako nije pronađen |
clear() | void | Čisti sav sadržaj iz scene |
Example
Kreirajte scenu, dodajte mesh čvor i sačuvajte u 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);