Saturday, November 17, 2012

Blender to UDK FBX Skeletal Mesh 1p Arms and Weapon WorkFlow

Posting my notes here so that people can learn from my mistakes...

Was hoping for some input on improving my blender to UDK 1p (1st person) arms + weapon animations. My workflow is as follows:

Blender Setup

Got some good information here:

Keep these suggestions in mind.

However, for whatever reason, the scale settings he sets up do NOT work for me at all, still WAY too small in UDK viewer, but I do edit the fbx exporter script for blender as he suggest.

Blender Units

I do set up my scale for blender (using blender units - the default) with Grid Floor Settings as follows:
Lines: 100
Scale: 8
Subdivisions: 8

Using these settings, my arms are ~95 blender units (BU) long from fingertip to fingertip. ~8 BU along the Y axis, and ~8 BU along the Z. (The shoulders are almost round on my model)

The shotgun I'm using is ~52 BU long.

Mesh and Armature Requirements

Once I have the scale set, I use CTRL+A to "bake" the scale in blender. Otherwise your size won't change at all in UDK. In blender, under the "N" toolbar, the scale MUST read 1.00 for everything.

My armature has a root bone at 0,0,0. I don't think it has to be called root_bone, but that is what I name it. I then have my basic armature setup with IK constraints. I also have 4 IK bones, used to control the hands and elbows. I have my two Hand IK bones as CHILDREN of my root_bone. (Right now I wait to parent them until just before export, seems to work fine). I want to use them as Sockets in UDK.
None of my IK bones have "deform" checked in the bone tab in blender.

DO NOT do anything fancy (ie blender specific) stuff with your armature. IK constraints sure, custom shapes for IK bones, sure, but nothing like curved/segmented bones. Those won't work when exporting. Trust me, I almost cried about not being able to use curved bones when animating.... much more difficult. If anyone discovers how this could work in UDK you would be my hero.

Setup a Reusable Scale Object 

Once that is all set up, I usually export it several million times to get the scale exactly right in udk. Then I usually append (SHIFT+F1) a 3p mesh, size it so it looks correct, then create a box that shows the basic size of a human in UDK. That way I have a "measuring stick" I can pull up at any time. Using "M" I move those measuring sticks to another layer, or save them to a separate blend file. This way I can easily append these objects to any blend file to check the sizing of my models.

Shotgun Armature Settings and Difficulties

My shotgun armature has 6 bones, but should contain a:
root_bone - controls the entire gun
muzzle_flash - used in UDK for creating a muzzle flash
along with your usual stuff like trigger, slide, etc.

This is where I have issues.
I can't get the shotgun to appear correctly socketed in UDK (I have to manually set it up in UDK)
I have tried setting root bone to 0,0,0 then rotating/moving the gun so it would look correct in the human hand.
I have tried exporting it with the root bone offset of 0,0,0 (by 30 units or so along the X axis)
Nothing seems to work, but at least I can adjust the offset in UDK
If someone knows how to fix this, that would be great.

I usually export the gun as a skeletal mesh now (don't export animations)
In object mode, select the GUN MESH AND ARMATURE, both must be selected.
Again, make sure your scale is baked.
For my fbx export settings:

Check "Selected Objects"
Leave scale at 1.00 (It didn't even seem to ever work for me?)
Leave forward and up at default
Just select Armature and Mesh, nothing else
"Apply Modifiers" should be checked
Only Deform Bones I usually leave unchecked, since my IK bones aren't deformed.
Uncheck Include animation.
The rest should be self-explanatory.

Animating the Mesh

Then I start Animation, which unfortunately I am weak at in Blender, so if someone could improve my knowledge of this that would be great.

Then I take the root_bone of my shotgun, and use an IK constraint to child the root_bone to my right_hand IK. Then I clear inverse, and clear the "scale" settings for the IK constraint and in object mode position the gun so it looks correct in the hand. This means when I move or rotate my hand IK the gun moves with it.

I first create a "Base_Pose" Action that is just my mesh in the default arms out pose.

Next I create a new action, do my animation, save my file.
For each UDK animation I want, I create a new action. Udk will import each action is as a different animation.

I think go back to the Base_Pose action (arms out) and select my arms armature and mesh, then choose export.

First I just export it as a skeletal mesh, and you can either uncheck include anims on fbx export, or import into udk. I usually do it on export, for a smaller file size, keeps things nice and neat.

I then import it into UDK (check Use TOAs Ref Pose).

I again double-check the size in UDK, make sure it looks correct. If you parented the Hand IK bones to the root bone, they should show up in your skeletal mesh. All the other IK bones you did not parent should not show up. I create a socket in the R Hand IK, and add my shotgun as the skeletal mesh. I then spend an annoying few minutes setting up the offset so it is in the hand correctly.

Animation Exportation Gotchas

Then go back to blender and for some reason (I may have done something wrong in blender?) you can't just export again, with animations.

I have to switch back to animation mode in blender, select my animation I created, and scrub the slider to make sure it moves (sometimes switch to pose mode and back). Then I can export the animations. If I don't do this, when I import the animations, they are only one frame (which is odd, since they show up fine in the Autodesk converter).

Speaking of which, to update your blender fbx files to the newest version, run them through the free Autodesk converter.

I then import the animations into a new animation set (uncheck the anim rotation only setting on import) and test. They should work fine.

The big gotcha

Currently, for some unexplained reason, UDK will import all of your blender actions at one single frame range... whatever you had set in blender, so all of your animations will be the same length.  Which doesn't work. Some people said it works fine in the December 11 and May 12 UDK downloads, but it certainly doesn't work with the June and Nov 12 UDK downloads, as I have tested both.

So you need to use Autodesk FBX Viewer to open your fbx files, use the take manager to select the takes you want to keep, then chose export takes as individual fbx files.  Then when you import them into UDK they will have the correct number of frames.

That is the basic workflow I use in blender for fbx animation.

I am hoping everyone can either learn from this or give me suggestions on how to improve this, as I have almost no experience with either UDK or blender, just started a few weeks ago.