3D文档控件Aspose.3D实用教程:使用 C# 构建 OBJ 到 U3D 转换器
如果您希望以编程方式加速 .NET 中 3D 文件格式的转换,那么本指南非常适合您。在本篇教程中,我们将演示如何借助Aspose.3D for .NET,通过几行代码在 C# 中构建OBJ到U3D 的转换器。Aspose.3D for .NET是目前遥遥领先的3D 渲染 SDK 之一,它除了 3D 文件格式转换之外,还可以进行 3D 文件处理、读取、写入等等。
Aspose.3D官方试用版下载
安装 3D 渲染 SDK
此 .NET SDK 不依赖任何第三方库,安装非常简单。因此,让我们通过下载DLL文件来安装Aspose.3D for .NET ,或者您也可以在NuGet 包管理器中运行以下命令:
Install-Package Aspose.3D
使用 C# 构建 OBJ 到 U3D 转换器 - 代码片段
你会发现实现起来非常简单直接。没什么复杂的,只需要调用几个方法就可以了。
让我们先来看看这些步骤。
- 创建Scene类的对象。
- 调用Open方法加载源 OBJ 文件。
- 初始化U3dSaveOptions类的实例以访问将场景导出为 U3D 文件的选项。
- Save方法将以 U3D 文件格式保存输出文件。
以下代码示例展示了如何在 C# 中将 OBJ 构建为 U3D:
using Aspose.ThreeD; using Aspose.ThreeD.Formats; namespace AsposeThreeD {class Graphics{// Convert OBJ to PLY in C#static void Main(string[] args){// Define the directory path.String dataDir = "data";License lic = new License();lic.SetLicense("License.lic");// Create an object of the Scene class. Scene scene = new Scene();// Invoke the Open method to load the Source OBJ file. scene.Open(dataDir + "Aspose3D.obj");// Initialize an instance of the U3dSaveOptions class to access the options for exporting scene as U3D file. var u3dSaveOptions = new U3dSaveOptions();// The Save method will save the output file in U3D file format.scene.Save(dataDir + "/sample.u3d", u3dSaveOptions);}} }
输出:
总结
Aspose.3D for .NET是 .NET 开发人员的优选工具。它支持多种 3D 文件格式,例如 3DS、PLY、STP 等。以上,我们讲解了如何使用 C# 将 OBJ 文件转换为 U3D 文件。当然,您也可以根据需要扩展工具的功能。