托管 Direct3DX 网格顶点/索引限制?
我有一些代码可以生成景观,将其转换为网格,然后渲染它。
景观基于三维表格,每个正表格条目生成 4 个顶点。我在开始时定义了表格大小。
问题在于
Mesh mesh = new Mesh(indexes.Count/3,vertexes.Count, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device);
,索引是索引的缩写数组,而顶点是包含我的顶点的 CustomVertex.PositionNormalTextured 数组。
我的代码对于小尺寸(例如 32x32x32)工作正常,但对于像 64x64x64 这样的东西,它会在上面的行上崩溃,并出现以下错误
Microsoft.DirectX.Direct3D.Direct3DXException was unhandled
Message=Error in the application.
Source=Microsoft.DirectX.Direct3DX
ErrorCode=-2005530516
ErrorString=D3DERR_INVALIDCALL
StackTrace:
at Microsoft.DirectX.Direct3D.Mesh..ctor(Int32 numFaces, Int32 numVertices, MeshFlags options, VertexFormats vertexFormat, Device device)
at mycode.Form1.Landscape() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 488
at mycode.Form1.GenerateGeometry() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 223
at mycode.Form1..ctor() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 40
at mycode.Program.Main() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
在它崩溃的点上,索引的计数为 231,480,顶点的计数为
154,320更好的主意是将其分成 64 个网格,每个 Z 层一个网格?
I have some code that generates a landscape, transforms it into a mesh and then renders it.
The landscape is based on a three-dimensional table and generates 4 vertices per positive table entry. I define the table size at the start.
The problem there is
Mesh mesh = new Mesh(indexes.Count/3,vertexes.Count, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device);
where indexes is an array of shorts for indices and vertexes is an array of CustomVertex.PositionNormalTextured holding my vertices.
My code works fine for small sizes (e.g. 32x32x32) but for something like 64x64x64 it crashes on the above line with the following error
Microsoft.DirectX.Direct3D.Direct3DXException was unhandled
Message=Error in the application.
Source=Microsoft.DirectX.Direct3DX
ErrorCode=-2005530516
ErrorString=D3DERR_INVALIDCALL
StackTrace:
at Microsoft.DirectX.Direct3D.Mesh..ctor(Int32 numFaces, Int32 numVertices, MeshFlags options, VertexFormats vertexFormat, Device device)
at mycode.Form1.Landscape() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 488
at mycode.Form1.GenerateGeometry() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 223
at mycode.Form1..ctor() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Form1.cs:line 40
at mycode.Program.Main() in d:\Files\My Documents\Visual Studio 2010\Projects\mycode\mycode\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
At the point at which it crashes indexes has a count of 231,480 and vertexes has a count of 154,320
would it be a better idea to split it into 64 meshes, one for each Z level?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您的网格默认为 16 位索引缓冲区。我再也找不到 Managed DirectX 的文档(MS 在大多数地方都删除了它),但看看您是否可以明确告诉它使用 32 位索引缓冲区。
Sounds like your mesh is defaulting to a 16-bit index buffer. I can't find the documentation for Managed DirectX anymore (MS removed it most everywhere) but see if you can explicitly tell it to use a 32-bit index buffer.