Hi there,
I stumbled upon a question regarding VertexBuffers. Hope you can help : )
I want to load an array of floats (v1.x, v1.y, v1.z, v2.x, v2.y, …) representing my positions into a vertex buffer. It somehow works, but the mesh is distorted:
var allVerticesCount = 0;
var allIndicesCount = 0;
foreach( var mesh in meshArray )
{
allVerticesCount += mesh.Positions.Length / 3;
allIndicesCount += mesh.TriangleIndicesCount;
}
var vertexBuffer = new VertexBuffer(
graphicsDevice,
typeof( VertexPosition ),
allVerticesCount,
BufferUsage.None);
var indexBuffer = new IndexBuffer(
graphicsDevice,
typeof( int ),
allIndicesCount,
BufferUsage.WriteOnly );
var vertexOffset = 0;
var indexOffset = 0;
foreach( var mesh in meshArray )
{
vertexBuffer.SetData(
vertexOffset * vertexBuffer.VertexDeclaration.VertexStride,
mesh.Positions,
0,
mesh.Positions.Length,
vertexBuffer.VertexDeclaration.VertexStride );
vertexOffset += mesh.Positions.Length / 3;
indexBuffer.SetData(
indexOffset,
mesh.GetTriangleIndices(),
0,
mesh.TriangleIndicesCount );
indexOffset += mesh.TriangleIndicesCount;
}
I am not quite sure if I understand, what the offset does. I want to load multiple meshes and set the offset vor every new mesh accordingly.
Thanks for having a look : )
Cheers,
Georg