Scene.Open

Open(Stream, FileFormat, CancellationToken)

使用指定的文件格式从给定流打开场景。

public void Open(Stream stream, FileFormat format, CancellationToken cancellationToken = default)
参数类型描述
streamStream输入流,用户负责关闭该流。
格式FileFormat文件格式。
cancellationTokenCancellationToken加载任务的取消令牌

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码演示如何从流中打开场景

Scene scene = new Scene();
using (var stream = new FileStream("input.fbx", FileMode.Open))
{
    scene.Open(stream, FileFormat.GLTF2);
}

另请参见


Open(Stream, LoadOptions, CancellationToken)

使用指定的 IO 配置从给定流打开场景。

public void Open(Stream stream, LoadOptions options, CancellationToken cancellationToken = default)
参数类型描述
streamStream输入流,用户负责关闭该流。
选项LoadOptions更详细的打开流的配置。
cancellationTokenCancellationToken加载任务的取消令牌

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码演示如何使用额外的加载选项从流中打开场景

Scene scene = new Scene();
using (var stream = new FileStream("input.fbx", FileMode.Open))
{
    var opt = new FbxLoadOptions();
    opt.LookupPaths.Add("textures");
    scene.Open(stream, opt);
}

另请参见


Open(Stream)

从给定流打开场景

public void Open(Stream stream)
参数类型描述
streamStream输入流,用户负责关闭该流。

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码演示如何从流中打开场景

Scene scene = new Scene();
using (var stream = new FileStream("input.fbx", FileMode.Open))
{
    scene.Open(stream);
}

另请参见


Open(Stream, CancellationToken)

从给定流打开场景

public void Open(Stream stream, CancellationToken cancellationToken)
参数类型描述
streamStream输入流,用户负责关闭该流。
cancellationTokenCancellationToken加载任务的取消令牌

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码演示如何使用取消令牌从流中打开场景

Scene scene = new Scene();
CancellationTokenSource cts = new CancellationTokenSource();
using (var stream = new FileStream("input.fbx", FileMode.Open))
{
    scene.Open(stream, cts.Token);
}

另请参见


Open(string, FileFormat, CancellationToken)

使用指定的文件格式从给定路径打开场景。

public void Open(string fileName, FileFormat format, CancellationToken cancellationToken = default)
参数类型描述
fileName字符串文件名。
格式FileFormat文件格式。
cancellationTokenCancellationToken加载任务的取消令牌

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码展示了如何使用取消令牌从文件名打开场景

Scene scene = new Scene();
CancellationTokenSource cts = new CancellationTokenSource();
scene.Open("input.fbx", FileFormat.FBX7400ASCII, cts.Token);

另请参见


Open(string, LoadOptions)

使用指定的文件格式从给定路径打开场景。

public void Open(string fileName, LoadOptions options)
参数类型描述
fileName字符串文件名。
选项LoadOptions更详细的打开流的配置。

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码展示了如何使用额外加载选项从文件名打开场景

Scene scene = new Scene();
var opts = new FbxLoadOptions();
opts.LookupPaths.Add("textures");
scene.Open("input.fbx", opts);

另请参见


Open(string, LoadOptions, CancellationToken)

使用指定的文件格式从给定路径打开场景。

public void Open(string fileName, LoadOptions options, CancellationToken cancellationToken)
参数类型描述
fileName字符串文件名。
选项LoadOptions更详细的打开流的配置。
cancellationTokenCancellationToken加载任务的取消令牌

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码展示了如何使用额外加载选项和取消令牌从文件名打开场景

var cts = new CancellationTokenSource();
Scene scene = new Scene();
var opts = new FbxLoadOptions();
opts.LookupPaths.Add("textures");
scene.Open("input.fbx", opts, cts.Token);

另请参见


Open(string)

从给定路径打开场景

public void Open(string fileName)
参数类型描述
fileName字符串文件名。

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码展示了如何从文件名打开场景

Scene scene = new Scene();
scene.Open("input.fbx");

另请参见


Open(string, CancellationToken)

从给定路径打开场景

public void Open(string fileName, CancellationToken cancellationToken)
参数类型描述
fileName字符串文件名。
cancellationTokenCancellationToken加载任务的取消令牌

异常

异常条件
IOException读取输入失败时抛出
ImportException当输入不是有效的 3D 格式时抛出

示例

以下代码展示了如何从文件名打开场景以及取消令牌源

var cts = new CancellationTokenSource();
Scene scene = new Scene();
scene.Open("input.fbx", cts.Token);

另请参见