我有一些代码可以生成景观,将其转换为网格,然后进行渲染。
景观基于 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 级别一个网格会更好吗?