【发布时间】:2011-01-13 12:07:50
【问题描述】:
我有一些代码可以生成景观,将其转换为网格,然后进行渲染。
景观基于 3D 表,每个正表条目生成 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 级别一个网格会更好吗?
【问题讨论】:
-
好吧,将景观分割成 32x32x32 块似乎已经奏效,但奇怪的是错误发生了。
-
如何告诉 DirectX9 启用 32 位索引缓冲区?
标签: c# directx rendering mesh vertex