Scene — Aspose.3D FOSS for .NET
Example
Example Scene class in Aspose.3D 充当 3D 内容的根容器,管理顶层对象并实现场景层次结构的父子关系管理。它提供对根节点和子场景的访问,构成加载、构建和保存 3D 场景的入口点。.
using Aspose.ThreeD;
// Create an empty scene
var scene = new Scene();
// Access the root node
Node root = scene.RootNode;Example
Example Scene 可以在不传入参数的情况下实例化该类,以创建一个空场景。.
using Aspose.ThreeD;
// Empty scene
var scene = new Scene();
// Set name via property
scene.Name = "myScene";
// Access the root node
Node root = scene.RootNode;Example
| Example | Example | Example | Example |
|---|---|---|---|
RootNode | Node | 获取 | 场景层次结构的根节点 |
AssetInfo | AssetInfo | 获取/设置 | 资产元数据,例如作者、创建日期和单位 |
AnimationClips | List<AnimationClip> | 获取 | 场景中定义的动画剪辑 |
CurrentAnimationClip | AnimationClip | 获取/设置 | 当前激活的动画剪辑 |
Library | IList<A3DObject> | 获取 | 附加到场景的用户自定义元数据对象 |
Name | string | 获取/设置 | 场景对象的名称 |
Properties | PropertyCollection | 获取 | 附加到场景的自定义属性 |
Example
| Example | 返回类型 | Example |
|---|---|---|
Open(string filePath) | void | 在此场景中打开文件;格式根据扩展名推断 |
Open(string filePath, LoadOptions options) | void | 使用特定格式的加载选项打开文件 |
Open(Stream stream) | void | 从流中打开,自动检测 |
Open(Stream stream, LoadOptions options) | void | 从流中打开,使用特定格式的加载选项 |
Open(Stream stream, string fileName) | void | 从流中打开,使用文件名进行格式检测 |
Save(string filePath) | void | 将场景保存到文件;格式根据扩展名推断 |
Save(string filePath, FileFormat format) | void | 在指定的(位置)保存场景 FileFormat |
Save(string filePath, SaveOptions options) | void | 使用特定格式的保存选项进行保存 |
Save(Stream stream, SaveOptions options) | void | 使用特定格式的保存选项保存到流 |
CreateAnimationClip(string name) | AnimationClip | 创建一个新的具名动画剪辑 |
GetAnimationClip(string name) | AnimationClip | 按名称查找已有的动画剪辑,或 null 如果未找到 |
Clear() | void | 清除场景中的所有内容 |
Example
创建一个场景,添加一个盒子节点,并保存为 GLB::
using Aspose.ThreeD;
using Aspose.ThreeD.Entities;
using Aspose.ThreeD.Formats;
// Create scene with a box primitive
var scene = new Scene();
var box = new Box(2, 2, 2);
var node = scene.RootNode.CreateChildNode("BoxNode", box);
// Save as GLB (format inferred from .glb extension)
scene.Save("box.glb");