change model (fbx) vertex type?

I want to draw models with my own effect, which expect vertices with just position, normal and texture. However, I suspect that some of my models have more than that in their vertices structure.
How can I have control over the vertex type MonoGame use for its loaded models?

And if its not possible, is it a good idea to extract the model vertices and construct my own vertex buffer? or will it be nightmare in complicated models for whatever reason?

Thanks!

Answering self for future seekers… I wasn’t able to change vertex type but in the end I didn’t have to. The following code will draw the model with my own custom effect:

// update world / view / projection matrix
_effect.Parameters["World"].SetValue(_world);
_effect.Parameters["View"].SetValue(_view);
_effect.Parameters["Projection"].SetValue(_proj);

// iterate model meshes
foreach (ModelMesh mesh in _model.Meshes)
{
        // set texture
        _effect.Parameters["Texture"].SetValue(((BasicEffect)(mesh.Effects[0])).Texture);

	// render mesh parts
	foreach (ModelMeshPart part in mesh.MeshParts)
	{
		device.SetVertexBuffer(part.VertexBuffer);
		device.Indices = part.IndexBuffer;

		// render the buffer with effect
		foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
		{
			pass.Apply();
			device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, part.StartIndex, part.PrimitiveCount);
		};
	}
}

The code above is a simplified version of my code I hope there’s no typo there.

Note that it only support 1 texture per mesh and that in my models I applied transformation at export time, eg mesh transformations are already in vertrices position.

And my shader vertex input looks like this:

struct VertexShaderInput
{
	float4 Position : POSITION;
	float3 Normal   : NORMAL;
	float2 TexCoord : TEXCOORD;
};

If you want this to be a little neater you can do what Shawn Hargreaves suggests in a blog post and set your custom effect at build time. https://blogs.msdn.microsoft.com/shawnhar/2006/12/07/rendering-a-model-with-a-custom-effect/

This will only work on the develop branch because of some bugs in mgcb in 3.5

1 Like