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(); }
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); } }