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();Методи на класа
| 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 | Зарежда сцена с опции за зареждане, специфични за формата. |
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
Всички свойства се достъпват чрез методи за получаване/задаване.
| Example | Example | Example | Example | Example |
|---|---|---|---|---|
rootNode | Node | getRootNode() | – | Коренов възел на йерархията на сцената |
subScenes | List<Scene> | getSubScenes() | – | Подсцени, вложени в тази сцена |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | Метаданни на ресурса, като автор, дата на създаване и единици |
animationClips | List<AnimationClip> | getAnimationClips() | – | Анимационни клипове, дефинирани в сцената |
currentAnimationClip | AnimationClip | getCurrentAnimationClip() | setCurrentAnimationClip(AnimationClip) | Текущият активен анимационен клип |
library | List<A3DObject> | getLibrary() | – | Потребителски дефинирани обекти с метаданни, прикрепени към сцената |
name | String | getName() | setName(String) | Име на обекта на сцената |
properties | PropertyCollection | getProperties() | – | Персонализирани свойства, прикрепени към сцената |
Example
| Example | Тип на връщане | Example |
|---|---|---|
save(String filePath) | void | Записва сцената във файл; форматът се определя от разширението |
save(String filePath, FileFormat format) | void | Записва сцената във файл в зададения FileFormat |
save(String filePath, SaveOptions options) | void | Записва сцената, използвайки специфични за формата опции за запис |
open(String filePath) | void | Отваря файл в тази сцена; форматът се определя от разширението |
open(String filePath, LoadOptions options) | void | Отваря файл със специфични за формата опции за зареждане |
getProperty(String name) | Object | Получава стойност на свойство по име |
findProperty(String name) | Property | Намира свойство по име |
createAnimationClip(String name) | AnimationClip | Създава нов именуван анимационен клип и го добавя към сцената |
getAnimationClip(String name) | AnimationClip | Намира съществуващ анимационен клип по име, или null ако не е намерен |
clear() | void | Изчиства цялото съдържание от сцената |
Example
Създайте сцена, добавете мрежов възел и запазете в 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);