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.

ExampleExampleExample
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();

Методи на класа

ExampleReturn TypeExample
Scene.fromFile(String filePath)SceneLoads 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

Всички свойства се достъпват чрез методи за получаване/задаване.

ExampleExampleExampleExampleExample
rootNodeNodegetRootNode()Коренов възел на йерархията на сцената
subScenesList<Scene>getSubScenes()Подсцени, вложени в тази сцена
assetInfoAssetInfogetAssetInfo()setAssetInfo(AssetInfo)Метаданни на ресурса, като автор, дата на създаване и единици
animationClipsList<AnimationClip>getAnimationClips()Анимационни клипове, дефинирани в сцената
currentAnimationClipAnimationClipgetCurrentAnimationClip()setCurrentAnimationClip(AnimationClip)Текущият активен анимационен клип
libraryList<A3DObject>getLibrary()Потребителски дефинирани обекти с метаданни, прикрепени към сцената
nameStringgetName()setName(String)Име на обекта на сцената
propertiesPropertyCollectiongetProperties()Персонализирани свойства, прикрепени към сцената

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);

Вижте също

 Български