圆柱体在三维场景中常被使用。在不同的图形处理应用程序中,您可能需要创建不同类型的圆柱体。在这里,我们将讨论如何制作各种类型的三维圆柱体,具有不同的变换和变化。它解释了如何在 C# 中以编程方式创建一个具有剪切底部、剪切顶部和不同 theta 长度的风扇圆柱体的 3D 圆柱体。

以编程方式创建 3D 圆柱体 – C# API 安装

Aspose.3D for .NET API 可以用于创建或操作 3D 场景和对象。此外,您不需要安装任何其他 3D 处理应用程序或工具来使用该 API。只需从 新版本 页面快速配置 API,或运行以下 NuGet 安装命令:

PM> Install-Package Aspose.3D

在 C# 中制作圆柱体

您可以通过以下步骤在三维场景中制作圆柱体:

  1. 初始化 Scene 类的对象。
  2. 设置顶点以变换底部的偏移量。
  3. 将圆柱体添加到场景中。
  4. 创建另一个圆柱体并自定义剪切底部。
  5. 添加圆柱体并 保存 输出场景。

以下代码片段演示了如何遵循这些步骤并在 C# 中以编程方式制作圆柱体:

// Create a scene
Scene scene = new Scene();
// Create cylinder 1
var cylinder1 = new Aspose.ThreeD.Entities.Cylinder(2, 2, 10, 20, 1, false);
// Set OffsetBottom
cylinder1.OffsetBottom = new Aspose.ThreeD.Utilities.Vector3(5, 3, 0);
// Add cylinder to without a ShearBottom to the scene
scene.RootNode.CreateChildNode(cylinder1);
// Create cylinder 2
var cylinder2 = new Aspose.ThreeD.Entities.Cylinder(2, 2, 10, 20, 1, false);
// Customized shear bottom for cylinder 2
cylinder2.ShearBottom = new Aspose.ThreeD.Utilities.Vector2(0, 0.83);
// Add cylinder 2 to the scene
scene.RootNode.CreateChildNode(cylinder2).Transform.Translation = new Aspose.ThreeD.Utilities.Vector3(10, 0, 0);
// Save scene
scene.Save("CustomizedCylinder.obj", FileFormat.WavefrontOBJ);

此外,以下图像显示了使用上述代码片段生成的输出图像。

制作 3D 圆柱体 C#

在 C# 中创建风扇圆柱体

以下步骤说明了如何在 3D 场景中创建风扇圆柱体:

  1. 创建 Scene 类对象。
  2. 创建一个圆柱体并将 GenerateFanCylinder 设置为 true。
  3. 设置 theta 的长度并创建一个子节点。
  4. 创建一个没有风扇的圆柱体并重复上述步骤。
  5. 保存输出场景。

以下代码片段详细说明了如何在 C# 中以编程方式创建风扇圆柱体:

// Create a Scene
Scene scene = new Scene();
// Create a cylinder
var fan = new Aspose.ThreeD.Entities.Cylinder(2, 2, 10, 20, 1, false);
// Set GenerateGanCylinder to true
fan.GenerateFanCylinder = true;
// Set ThetaLength
fan.ThetaLength = Aspose.ThreeD.Utilities.MathUtils.ToRadian(270);
// Create ChildNode
scene.RootNode.CreateChildNode(fan).Transform.Translation = new Aspose.ThreeD.Utilities.Vector3(10, 0, 0);
// Create a cylinder without a fan
var nonfan = new Aspose.ThreeD.Entities.Cylinder(2, 2, 10, 20, 1, false);
// Set GenerateGanCylinder to false
nonfan.GenerateFanCylinder = false;
// Set ThetaLengeth
nonfan.ThetaLength = Aspose.ThreeD.Utilities.MathUtils.ToRadian(270);
// Create ChildNode
scene.RootNode.CreateChildNode(nonfan);
// Save scene
scene.Save("FanCylinder.obj", FileFormat.WavefrontOBJ);

以下截图显示了使用此示例代码创建的输出场景:

制作 3D 风扇圆柱体 C#

获取免费临时许可证

您可以请求 免费临时许可证 来测试 API 的全部功能。

结论

在本文中,您已学习如何在 C# 中以编程方式创建 3D 圆柱体。它涵盖了如何修改代码片段以创建各种圆柱体形状。此外,您还可以通过查看 文档 部分探索 API 的许多其他功能。如有任何疑问,请通过 论坛 与我们联系。

另见

在 C# 中将 MA 转换为 USDZ 文件