1

我有一些代码可以生成景观,将其转换为网格,然后进行渲染。

景观基于 3D 表,每个正表条目生成 4 个顶点。我在一开始就定义了表格大小。

存在的问题

Mesh mesh = new Mesh(indexes.Count/3,vertexes.Count, MeshFlags.Managed, CustomVertex.PositionNormalTextured.Format, device);

其中indexes 是索引的short 数组,vertexes 是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 级别一个网格会更好吗?

4

1 回答 1

0

听起来您的网格默认为 16 位索引缓冲区。我再也找不到 Managed DirectX 的文档(MS 在所有地方都删除了它),但看看你是否可以明确告诉它使用 32 位索引缓冲区。

于 2011-03-29T22:53:15.430 回答