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) konstruktorius) |
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();Klasės metodai
| Example | Grąžinimo tipas | Example |
|---|---|---|
Scene.fromFile(String filePath) | Scene | Įkelia sceną iš nurodyto failo kelio, automatiškai aptikdamas formatą. |
Scene.fromFile(String filePath, LoadOptions options) | Scene | Įkelia sceną su formatui būdingomis įkėlimo parinktimis. |
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
Visos savybės pasiekiamos per getter/setter metodus.
| Example | Example | Example | Example | Example |
|---|---|---|---|---|
rootNode | Node | getRootNode() | – | Šakninis mazgas scenos hierarchijoje. |
subScenes | List<Scene> | getSubScenes() | – | Po-scenos, įdėtos į šią sceną |
assetInfo | AssetInfo | getAssetInfo() | setAssetInfo(AssetInfo) | Turto metaduomenys, tokie kaip autorius, sukūrimo data ir vienetai |
animationClips | List<AnimationClip> | getAnimationClips() | – | Scenoje apibrėžti animacijos klipai |
currentAnimationClip | AnimationClip | getCurrentAnimationClip() | setCurrentAnimationClip(AnimationClip) | Šiuo metu aktyvus animacijos klipas |
library | List<A3DObject> | getLibrary() | – | Vartotojo apibrėžti metaduomenų objektai, prisegti prie scenos |
name | String | getName() | setName(String) | Scenos objekto pavadinimas |
properties | PropertyCollection | getProperties() | – | Pasirinktinės savybės, prisegtos prie scenos |
Example
| Example | Grąžinimo tipas | Example |
|---|---|---|
save(String filePath) | void | Išsaugo sceną į failą; formatas nustatomas pagal plėtinį |
save(String filePath, FileFormat format) | void | Išsaugo sceną į failą nurodytu FileFormat |
save(String filePath, SaveOptions options) | void | Išsaugo sceną naudodama formatui būdingus išsaugojimo parametrus |
open(String filePath) | void | Atveria failą šioje scenoje; formatas nustatomas pagal plėtinį |
open(String filePath, LoadOptions options) | void | Atveria failą su formatui būdingais įkėlimo parametrais |
getProperty(String name) | Object | Gauti savybės reikšmę pagal pavadinimą |
findProperty(String name) | Property | Randa savybę pagal pavadinimą |
createAnimationClip(String name) | AnimationClip | Sukuria naują pavadintą animacijos klipą ir prideda jį prie scenos |
getAnimationClip(String name) | AnimationClip | Randa esamą animacijos klipą pagal pavadinimą, arba null jei nerasta |
clear() | void | Išvalo visą turinį iš scenos |
Example
Sukurkite sceną, pridėkite tinklo (mesh) mazgą ir išsaugokite į 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);