Scene — Aspose.3D FOSS for Java
Example
Example Scene 在 Aspose.3D 中的类充当 3D 内容的根容器,管理顶层对象并实现场景层次结构的父子关系管理。它提供对根节点和子场景的访问,构成加载、构建和保存 3D 场景的入口点。.
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 可以在不传入参数的情况下实例化,以创建一个空场景,或使用可选参数。.
| Example | Example | Example |
|---|---|---|
entity | Entity | 在创建时可选的要附加到根节点的实体 |
parentScene | Scene | 可选父场景(用于子场景);需要一个名称 |
name | String | 场景名称(仅在使用两个参数时使用) Scene(Scene, String) 构造函数) |
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 | 返回类型 | Example |
|---|---|---|
Scene.fromFile(String filePath) | Scene | 从指定的文件路径加载场景,自动检测格式。. |
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
所有属性均通过 getter/setter 方法访问。.
| 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);