KatsBits Community

[MD5] EXPORT script for Blender 2.6x (OPEN)

keless · 228 · 262358

0 Members and 3 Guests are viewing this topic.

Offline Blayne Bradley

  • Newbie
    • Posts: 13
I GOT IT!!!! I needed to have a material and a texture thrown in. <("<)

I still don't know if this is everything assimp needs yet and can still break on me in a spectacular fashion but this is a good start.

Thanks for your help!


Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
Send the blend to info@katsbits.com and I'll take a look for you.

Heh, you fixed it whilst I was reading/posting! And yes, you need a material and texture/UV map assigned otherwise it'll throw out another error.


Offline Blayne Bradley

  • Newbie
    • Posts: 13
A'ight, I've encountered a problem, it doesn't seem to actually export the animation file and there isn't an error message.

I've also managed to load the mesh using assimp (although textures and materials are eluding me because ImageMagick seems broken, I sicked a 50 point bounty on it over at stackoverflow) but while the head is fine the rest of the body is horribly deformed after following the unparent-reparent steps in the linked tutorial, I'm not sure exactly I'm doing wrong.


Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
There's usually two reasons for the deformity you're describing, either; 1) the vertex weighting has some odd assignments (vertexes weighted to 'odd' bones may pull the mesh out of shape when it animates); or 2) when you set "Apply", the mesh and it's Origin point were not centered on Blenders 0,0,0 grid.

The upshot is that if you want the character to walk along a path (the curved line in the image from the previous page?), the mesh and armatures corresponding Origin Points need to be located at Blenders 0,0,0, that's the starting point from which the character and rig move - if it's 'off set' in some way the result is often the kind of corruption you're seeing.

Make sure also when you export, there is an active "Action" sequence shown in the Action Editor (when you select the Armature, the sequence should display in the Editor indicating it's the current active dataset). That's where the animation data comes from.

If you want/are able to, send me the file and I'll take a look (email above).


Offline Blayne Bradley

  • Newbie
    • Posts: 13
Blend file sent, to reiterate what I mentioned in the email, it looks like all the bones got moved to the origin of the mesh except for the head bone.



Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
You're almost there, you just have to reconsider the mechanics of animating relative to a game engine rather than Blender - there's a difference because Blender understands what the Scene data means and the way it's set up to make the character walk the line. Third-party game engines don't. To get a character to walk a path the way you want you have to fully animate it, i.e. the model has to be posed and keyframed the full distance and duration. In essence you're producing a unique sequence rather than looping a walk.

The way that should actually be done is to keep the root bone static, it should never move, the appearance of motion comes from the other bones moving in relation to the root, and away from it. If this isn't done the sequences gets mushed because the positional data of each keyframe is rooted at the origin and grid centre (0,0,0), that point, and manipulation from it, is what determines distance. So whilst the keyframes are thusly rooted, the Armature isn't, it's origin is moving with the mesh resulting in a collapsed sequence (gets squished like an accordion).

To correct this you need to unparent everything and then reassign an Armature modifier to the mesh, linked to the Armature. That's your basic structure. In the Action Editor when you animate, the "Control" bone should remain static, everything else being posed and keyframed appropriately relative to the sequence needed, in other words, you have to physically move the character incrementally along the guide and pose each step whilst doing so.

A couple of other observations.

When you create animated object you'll generally want to 'ground' them so the base of the feet sit on the on the horizontal plain. This is also where the mesh and armature origins are located (they are again, what determine the position of objects in game). Loading the little guy into a previewing tool it's buried up to the waist.

The mesh is collapsed when loaded because it doesn't have a properly formed 'default' pose - usually this is because the vertex weighting or pose data isn't corresponding properly to the mesh structure. The problem disappears once an md5anim file is loaded though.

Ideally you'll want to reduce the polycount of the mesh, 50k is super high so use a Decimate Modifier on it to reduce it to a reasonable level (anything under 2500 for the kind of simple structure you have there).

Hopefully all this make sense. If not ask away ;)


Offline Blayne Bradley

  • Newbie
    • Posts: 13
It's going to take me a minute to full absorb it all, I'll clarify that right now I just want to pull the mesh and render it at its rest pose; I don't want to animate it yet as I just want to test my engine one module at a time.

If I follow what you say it should still work for just making the T-Pose mesh right?

Edit: The absurd polycount size on the Mesh is because it was provided by my professor during my graphics course two semesters ago, (the course itself was horribly out of date so I've been working on updating the code to modern opengl specs) so for testing performance stuff I kept the absurd polycount size for academic purposes; practically when I make my own characters hopefully they won't be so absurdly large in numbers :D

Edit2: Still undergoing implosion with the file you sent me, is that because I'm not applying its animations?
Edit3: Yeah that's exactly what you're saying, I'm not loading the animation file so it ain't lookin' right.

Regarding animating a unique sequence, so you mean do what I did to keyframe it for 30 frames and then just keep repeating that while incrementally moving it bit by bit away from the control bone?

Edit4: Wouldn't it actually make more sense to not do movement in blender and do it in the engine?


Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
The characters Armature has not been reset so it carries a scale value, the likely cause of the mushed up mesh when its loaded without a supporting anim file - the Armature should carry a "Scale:" value of "1.0" indicating it's been 'reset' ("Apply") but if that's done now the rig will get messed up (this is why both mesh and Armature need to be reset before being parented and animated, if it's done after the fact it'll mess up any sequences that already exist; and why when making content the origin should always sit on the horizontal plain as a representation of the ground, you then build and animated relative to that).

Re: Edit 1. Make sure to triangulate the mesh before export (in Edit mode, Select All, press "Ctrl+T") otherwise a mesh like that can crash Blender when its parsed by the script.

Re: Edit 2. You should be able to export a single framed sequence (can be a couple of frames, they just need to be the exact same pose) so you have a posed character to work with.

Re: Edit 3. Yes, you animate the sequence as one long event. In this instance it might result in an animation that has the character walk, that is swing the arms and legs for a full cycle, 20 or so times over a duration of about 30 seconds and maybe 250 frames.

Re: Edit 4. That is infact how objects generally move, it's done in-game. There are different way to physically do it depending on what the character is supposed to do, but essentially you export a walk cycle, a loop of a couple of steps like the one you've already got (you can do either a 'static' or 'dynamic' animation - the character will loop standing on the spot, or will move a short distance away from the origin as part of the cycle) , and move the game object around based on controlled input (mouse/keyboard) whilst the loop is triggered to play. This gives the impression of an actual walk.

If you want the character to walk along a path, you'd normally set that up in game, treating the character as a scripted event (if the character is the player you'll usually script the event using a 'third-person' representation - its mechanically easier to script movement of a 'bot' than doing it to the object the player is observing the game through).


Offline Blayne Bradley

  • Newbie
    • Posts: 13
Thanks, I'll get back to fiddling with that in a moment as soon as I can get my animation code working :D

Is there a way in blender to make sure no vertex is affected by no more than four bones? I think that might be better than trying to get the code to work for 4+.


Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
As far as I'm aware there isn't a way to restrict vertex assignments like that. You can however, see which vertices are members of which vertex groups and then manage them by checking "Vertex Weight" in the Properties panel ("N") - obviously with 50k+ verts on the model you're using that will be quite a task!


Offline Blayne Bradley

  • Newbie
    • Posts: 13
As far as I'm aware there isn't a way to restrict vertex assignments like that. You can however, see which vertices are members of which vertex groups and then manage them by checking "Vertex Weight" in the Properties panel ("N") - obviously with 50k+ verts on the model you're using that will be quite a task!

Yeah :(


Offline Blayne Bradley

  • Newbie
    • Posts: 13
As far as I'm aware there isn't a way to restrict vertex assignments like that. You can however, see which vertices are members of which vertex groups and then manage them by checking "Vertex Weight" in the Properties panel ("N") - obviously with 50k+ verts on the model you're using that will be quite a task!

Huh, why isn't there a way to select all vertices by vertex group? That would be way easier, the only 'quick' solution would be to subdivide the mesh into a mesh for each vertex group.


Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
You can select vertices based on group.

With the mesh in Edit mode and Vertex selection active ("Ctrl+Tab"), click the "Object Data" properties button (the triangle with dots each corner). Find/expand the "Vertex Groups" subsection to reveal the "Vertex Groups Index", a list of vertex group assigned to the active mesh. Groups can be managed by selecting an entry and then clicking one of the buttons to "Select", "Deselect", "Assign" or "Remove" - individual vertices can be removed or assigned to different groups using these.

Do note however that checking "which groups are assigned to an individual vertex" and "which vertices are assigned to a group" are slightly different questions that address different aspects of the process - they may appear to be the same but it's a question of macro versus micro management of structure.


Offline Blayne Bradley

  • Newbie
    • Posts: 13
Stackoverflow to the rescue!

"In weight paint mode, select the Weight Tools panel in the toolbar, and run Limit Total, This removes vertex groups with lowest weights.

This defaults to 4 which is a common limit for game-engines."

This works! So in the future if some other poor fellow has the same question we know what to do. :D


Offline kat

  • Administrator
  • Hero Member
  • *
    • Posts: 2692
    • KatsBits
Learn something new everyday heh ;)

Be mindful how the tool is used though, there are obviously a lot of situations where more than four groups will be needed, especially on a whole character. With that said, it looks like it may be a good way to remove errant group assignments and clean up a mesh.