在 C# 管理的 DirectX 中制作自定义网格
我需要使用 C# 中的托管 DirectX 在运行时制作 DirectX 3D 网格。 我无法找到有关如何执行此操作的任何信息。
- 不,我无法使用 3D 建模程序来制作我的对象。 它们的尺寸和形状必须精确,并且在运行时之前我没有任何尺寸或形状信息。
- 不,我无法从现有的 DirectX 网格功能构建模型。 (一个简单的例子:DirectX 可以让您使用圆锥体网格和圆柱体网格轻松地为铅笔建模。当然,您必须为铅笔携带两个网格,而不仅仅是一个,并正确定位和定向每个网格。但是您甚至无法制作铅笔纵向分成两半的模型,因为没有提供半圆柱体或半圆锥体网格。)
- 在运行时,我已经计算了所有顶点,并知道要连接哪些顶点来形成必要的三角形。
- 我所需要的只是纯色。 我不需要纹理贴图。
可以使用以下 DirectX 调用获得球体网格:Mesh sphere = Mesh.Sphere(device, sphereRadius, sphereSlices, sphereStacks);
该网格是在运行时构建的。
我需要知道的是如何制作类似的功能:网格形状 = MakeCustomMesh(device, vertexlist, trianglelist);
其中两个列表可以是任何合适的容器/格式。
如果有人可以向我指出托管 DirectX (C#) 示例代码,即使它只是从 3 个硬编码的三角形构建网格,那也将是一个很大的好处。
I need to make a DirectX 3D mesh at run time using Managed DirectX from C#. I have not been able to locate any information on how to do this.
- No, I can't use a 3D modeler program to make my objects. They must be precisely sized and shaped, and I don't have ANY of the size or shape information until runtime.
- No, I can't build up the model from existing DirectX mesh capabilities. (A simple example: DirectX would let you easily model a pencil by using a cone mesh and a cylinder mesh. Of course, you have to carry around two meshes for your pencil, not just one, and properly position and orient each. But you can not even make a model of a pencil split in half lengthwise as there is no half cylinder nor half cone mesh provided.)
- At runtime, I have all of the vertices already computed and know which ones to connect to make the necessary triangles.
- All I need is a solid color. I don't need to texture map.
One can get a mesh of a sphere using this DirectX call:Mesh sphere = Mesh.Sphere(device, sphereRadius, sphereSlices, sphereStacks);
This mesh is built at runtime.
What I need to know is how to make a similar function:Mesh shape = MakeCustomMesh(device, vertexlist, trianglelist);
where the two lists could be any suitable container/format.
If anyone can point me to managed DirectX (C#) sample code, even if it just builds a mesh from 3 hardcoded triangles, that would be a great benefit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MDXInfo 上有一些示例代码展示了如何执行此操作。 这将创建一个具有多个子集的网格 - 如果您不需要它,那就更容易了。
基本上,您只需创建网格:
然后,您可以获取网格顶点缓冲区和索引缓冲区,并使用以下方法覆盖它:
然后,适当填充索引和顶点。
There's some sample code showing how to do this on MDXInfo. This creates a mesh with multiple subsets - if you don't need that, it's even easier.
Basically, you just create the mesh:
Then, you can grab the mesh vertex buffer and index buffer, and overwrite it, using:
Then, fill in the indices and vertices appropriately.