Subscribe

XNA 3DS Model Loader

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

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Technorati
  • Reddit
  • Digg
  • del.icio.us
  • StumbleUpon
  • DZone
  • ThisNext

Related posts:

9 Responses to “XNA 3DS Model Loader”

  1. on 09 Oct 2006 at 1:01 am zygote

    Nice! :)

  2. on 09 Oct 2006 at 8:11 am tridex

    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

  3. on 09 Oct 2006 at 8:18 am tridex

    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

  4. on 09 Oct 2006 at 9:12 pm proj

    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.

  5. on 10 Oct 2006 at 12:58 am tridex

    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!!!

  6. on 10 Oct 2006 at 3:14 am proj

    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.

  7. on 11 Oct 2006 at 2:57 pm Slevi » Blog Archive » XNA updates

    […] .3DS Loader […]

  8. on 11 Oct 2006 at 11:14 pm Koray

    cool :)

  9. on 23 Oct 2006 at 2:50 pm XNAtutorial.com

    […] Jacob Repp has made a 3DS model loader. (Loader Source) (Wrapper Source) […]

Trackback URI | Comments RSS

Leave a Reply