Exporting Animated .md5 models from blender

Introduction

This tutorial was made using Blender version 2.43. It is an example of exporting a simple animated object with one bone.

Prerequisites

There appears to be two loaders for .md5 models, one at Java.net and one at SourceForge
As far as I know the more advanced and supported one is option 2 from sourceforge, but they both work.

Option1

  • Get the md5 code from Java.net the module name is jme-contrib: Its in the cvs repository at cvs.dev.java.net (same as jme).
Checking out jme-contrib from repository in Eclipse

1.right-click on jme-contrib→kproject-md5 and select 'check out as…' then check out as a new Java project using the new project wizard.
2.Now right click on project→properties→Java build path→projects tab→add and add jme project to build path.
3.Also in Java build path, click the Source tab→Add folder… and add both 'kproject-md5/src' and 'kproject-md5/src-jme'. In addition, add 'kproject-md5/data' to properly load test data. You may have to edit the 'kproject-md5/data' folder to be simply 'data' if you get a blank screen and errors upon running JmeMD5Test. Project is now ready.
4.Run the test 'JmeMD5Test' in src-jme to confirm that it works.

Option2

  • Get the .md5 code from SourceForge
Getting the md5 code from SourceForge is as easy as typing in these 2 commands
cvs -d:pserver:anonymous@md5reader.cvs.sourceforge.net:/cvsroot/md5reader login

Hit enter when asked for password.

cvs -z3 -d:pserver:anonymous@md5reader.cvs.sourceforge.net:/cvsroot/md5reader co -P md5reader2

or in Eclipse:

  • connection type: pserver
  • user: anonymous
  • host: md5reader.cvs.sourceforge.net
  • path /cvsroot/md5reader

Tutorial

Adding bone to Mesh

The model used in this tutorial is a textured sphere created in Exporting .obj Models From Blender

1.In object mode hit spacebar→Add→Armature
2.In object mode select the sphere then shift-select the armature so that they are both selected
3.Hit ctrl-p→Armature→Create From Closest Bones
4.In edit mode hit 'a' to select all vertices, on Link and Materials tab under 'Vertex Groups' click 'assign' to assign verticies to bone
(model can be exported w/o animation after this step, skip to step 7)

Animating Model

5.In object mode select the armature(bone) then enter pose mode. Then change screen to SR:1-Animtion
6.Hit 'i'→LocRot to insert the first keyframe then skip to frame 11, rotate model(r key), and hit 'i'→LocRot again.Go back to SR:2-Model

Exporting Model

7. (This step is only necessary when using code from jme-contrib)
With sphere selected in edit mode hit shift-ctrl-n to recalculate normals inside(this may not be necessary), save the file as a .blend.
(I've found that saving as .blend applies the changes to normals otherwise they dont get flipped when exporting.)
8.Export model as .md5 File→Export→Doom3 MD5, just select a location for your model and animation to export to and export it!
9.Load into JME, dont forget to put your texture(s) in the right location, and youre done.
10.You are most likely going to need to edit the <shader ””> line in .md5mesh file, see troubleshooting.

Tips

  • Use 'Top' view in blender (Y up X right or hit keypad '7') as front view and you wont have to rotate your model in jme.In other words, In top view in blender your character will look like this
                                                     o
                                                    -|-
                                                     ^
    
  • When UV mapping your model any seams marked as edges (ctrl-e mark seam) might be noticable so place seams in hard to see places.
  • When UV mapping dont use smart projections or youll probably have seams where you dont want them. Instead manually mark seams and use unwrap.
  • To attach another model to part of your model use
    bodyInstance.addChild( head, "Shoulders" );

    see MarineTest in MD5Reader2 the head is attached to “Shoulders” bone.

  • Its possible to smoothly transition from one animation to another using some of these methods
    runningAnimator.fadeOut(.1f, false); standingAnimator.fadeIn(.5f); standingAnimator.fadeTo(0,1);

    you'll have to experiment with the right methods and numbers to get your animations looking perfect.

Troubleshooting

Problem: No model displaying but mesh and triangle stats are listed when using loader from Sourceforge

The loader cant find your texture.

  • Put all your model stuff in the models folder (example.md5mesh, example.md5anim, texture.tga)
  • Your texture must be a .tga file and it must NOT use RLE compression
  • Open your example.md5mesh file with an editor and replace shader ”” with shader “models/texture” or whatever the path is to the texture file
  • Specify NO file extension for the targa file. Example: models/texture NOT models/texture.tga
  • If your model contains more then one mesh then there are more than one shader ”” lines you need to change
  • The texture file might need to contain an alpha channel(?)

Problem: Texture "flickers" or looks distorted when scaling model

  • Your normals are off, try
    bodyInstance.setNormalsMode(SceneElement.NM_GL_NORMALIZE_PROVIDED)

Problem: animation not rotated the same as model

  • Currently there is a bug in lines 202 and 225 in Md5AnimReader. If you change
    frame.positions[it] = new Vector3f(tz, ty, tx)

    to:

    frame.positions[it] = new Vector3f(tx, ty, tz)

    in both lines the animation will be properly rotated.

This fixes the blender animation, but the sarge walking animation supplied with the code walks to the right insted of forward so this isnt a real fix.

Problem: Texture looks blocky or distorted

  • To load without S3TC, change line 90 in MD5DefaultSkin to:
    return TextureManager.loadTexture( url, Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR, Image.GUESS_FORMAT_NO_S3TC, 0.0f, true );

Problem: Shadows dont update with animation

  • Try adding the following code to SkeletalAnimationController in the animate method
    Geometry geom=(Geometry)instance.getChild(0);
            
            for(int x=0;x<geom.getBatchCount();x++) {
                geom.getBatch(x).setHasDirtyVertices(true);
            }

Problem: mesh not showing or partially showing in jme

  • Make sure ALL verticies are assigned to a bone(step 4), any verticies not assigned to a bone will not be exported.

Links


/var/www/wiki/data/pages/exporting_animated_.md5_models_from_blender.txt · Last modified: 2009/07/28 18:44 (external edit)  
Recent changes · Show pagesource · Login

Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

subscribe to jME latest jme headlines


site design by bleedcrimson designs © 2008