private bool loadMD5Model(string fileName) { md5model = new MD5Model(); if (md5model.loadMD5MeshFile(fileName)) { md5model = null; return(true); } lb_md5MeshName.Text = fileName; md5model.buildBaseFrameVertices(); rawMesh = new XYZTrianglesList(); md5model.addToSimpleStaticMeshBuilder(rawMesh); gpuMesh = new DXVertexBufferXYZNormals(); gpuMesh.create(rawMesh, device); UpdateDirectXDisplay(); return(false); }
private void recreateGPUBuffers() { if (model == null) { vertexBuffer = null; return; } XYZTrianglesList l = new XYZTrianglesList(); model.iterateXYZTriangles(l); if (vertexBuffer != null) { vertexBuffer.destroyBuffer(); } if (l.getTrianglesCount() > 0) { vertexBuffer = new DXVertexBufferXYZNormals(); vertexBuffer.create(l, device); } }
public void create(XYZTrianglesList l, Device device) { // free previous buffer if (vertexBuffer != null) { vertexBuffer.Dispose(); vertexBuffer = null; } primitiveCount = l.getTrianglesCount(); if (primitiveCount == 0) { // "new VertexBuffer" causes exception if vertex count is 0 return; } vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionNormalColored), l.getTrianglesCount() * 3, device, 0, CustomVertex.PositionNormalColored.Format, Pool.Default); GraphicsStream stm = vertexBuffer.Lock(0, 0, 0); CustomVertex.PositionNormalColored[] verts = new CustomVertex.PositionNormalColored[l.getTrianglesCount() * 3]; // set triangle points for (int i = 0; i < l.getVertexCount(); i++) { Vec3 pos = l.getXYZ(i); verts[i].X = (float)pos.getX(); verts[i].Y = (float)pos.getY(); verts[i].Z = (float)pos.getZ(); Vec3 normal; l.calcTriangleNormal(i / 3, out normal); verts[i].Nx = (float)normal.getX(); verts[i].Ny = (float)normal.getY(); verts[i].Nz = (float)normal.getZ(); verts[i].Color = Color.White.ToArgb(); } stm.Write(verts); vertexBuffer.Unlock(); }