XNA 3DS Model Loader
October 8th, 2006 by proj
Took me some time to get around to posting this but I thought it would be nice to get this to anyone who needs it. The content pipeline will remove the need to use this as you can use the fxb format from max but I may end up porting this as an importer/procesor for the content pipeline mesh type.
Here’s the files you need: Model Loader Mesh Wrapper
I haven’t tested the smoothing groups feature out yet. You may need to tweak that if you want to try using smoothing groups.
Here’s some example code on how this is used:
List<Mesh> meshes = new List<Mesh>();
// Load all 3ds data and populate meshes
MeshLoader loader = new MeshLoader();
loader.Load(new BinaryReader(new FileStream(@"Modelsattscout.3ds", FileMode.Open)));
loader.LoadAllMeshes(meshes, 1.0f);
// Render meshes
foreach(Mesh mesh in meshes)
{
mesh.SubmitPrimitives(graphicsDevice, effect);
}
Related posts:







Nice!
Hi,
I was gong to convert your code to vb.net for use in XNA, but do you have a working version (Sample application), as I am getting errors i.e.
Error 1 The type or namespace name ‘SceneEffect’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Tridex\Desktop\MD5Char\MD5Char\MD5Char\Mesh.cs 99 57 MD5Char
and
Error 1 The type or namespace name ‘VertexPositionNormal’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Tridex\Desktop\MD5Char\MD5Char\MD5Char\Mesh.cs 32 17 MD5Char
Hi problems compiling, do you have a working app so I can try it out with vb.net XNA , current errors:
Error 1 The type or namespace name ‘VertexPositionNormal’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Tridex\Desktop\MD5Char\MD5Char\MD5Char\Mesh.cs 32 17 MD5Char
and
Error 2 The type or namespace name ‘SceneEffect’ could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Tridex\Desktop\MD5Char\MD5Char\MD5Char\Mesh.cs 99 57 MD5Char
Hey Tridex, Sorry I just ripped this code out of my project without some of the accompanying engine objects.
I will post a sample application tonight that you can play with.
If you can’t wait till then I will explain what the missing classes do:
VertexPositionNormal is a custom vertex format that has only Vector3 Position and Vector3 Normal.
SceneEffect is a XNA Effect class wrapper that understands the scene object system and can automatically populate the effect parameters from the scene. In this code there is a state object that can do per-mesh modifications of the effect parameters for ambient, diffuse and specular color contributions.
Sorry for the messy code dump. I realized that this would be difficult for some people to integrate, the important part is the ModelLoader class which is mostly stand alone. You can integrate it with your own mesh class if you desire.
hi ,
thanks for the reply,
Hey I noticed you have some of the animation loading code for the 3ds, (you genius!!)
Would it be possible to use this with the objects (Mesh class you have created)? if not could you point me to a site were I could find out how to do this !!! as I like the studio max animation system!!!
if so that means vb.net conversion will not need to use the content piple like stuff!!! (Freedom is a good thing)
Can’t wait for the demo application!!!
Cheers!!!
I don’t have time to do anything with the keyframes ATM but I may investigate it. I have to get a sample file that contains keyframes and other chunk data in order to test it.
I just posted an update that contains a full sample using the model loader.
[…] .3DS Loader […]
cool
[…] Jacob Repp has made a 3DS model loader. (Loader Source) (Wrapper Source) […]