Modo to Unreal

Part 2: Skeletal objects


Introduction

In part 1 we looked at the static mesh workflow, so now let's see how to export skeletal meshes from modo.
As of Nov. 2007, Modo does not support bones, so the exporter relies on simple guide primitives to generate the bone data. Therefore this workflow is for rigging rigid bodies (like vehicles) and simpler soft bodies (a mattress for example).

The carrier format is Collada 1.4.1, so although I use Unreal in this tutorial as the target platform, other Collada capable engines should be able to import the files as well.


Exporter features

Here is a quick rundown of the capabilities of the Collada exporter (v1.01):

3 export modes : OBJECT mode for single object export, RIGID for mechanical skeletal meshes and SOFT for things where vertices can be affected by more than one bone.

Multiple UV set export : Any UV set will be exported if the name is like "UV##", where # is a number.

Smoothing groups : Using the separated polygon technique, as described here.

Collision primitives : For OBJECT mode only. Box, Sphere and Convex hull.

Bones : For RIGID/SOFT modes only.

Vertex colors : Uses the RGB map with the name "Color". If that does not exist, then it exports 1,1,1 (white) color.


Related files

Collada_exporter.lua (v1.01) : The exporter script for modo. Creative Commons License

BoneTemplate.lxo : Template scene containing the bone definition items we'll use throughout the tutorial.

ObjectMode_example.lxo : Example file for simple object export. Contains a render mesh, box-, spherical- and convex hull collisions.

RigidBody_example.lxo : Example file for rigid body export.

SoftBody_example.lxo : Example file for soft body export.


Object mode

The workflow for simple objects are pretty much the same as described in part 1, yet there are a few differences:
First of all, we shoud not leave n-gons in the model, only triangles and quads.

The second, bigger difference is regarding the embedded box and sphere collision primitives: Instead of actually creating polygonal shapes, we use the items from the bone template file to define the primitives. (Or any properly named, unit sized box/sphere.)

">UBX" for box and ">USP" for sphere. They are units sized shapes, so we must make sure that we only use item mode transformations on them! We should also keep the first 4 characters of their name because those are important for the script. So ">USP_LampShell" works all right.

The convex hull should be named as ">UCX" but otherwise it's the same deal as before. The twist in this case is that the item itself should not be tranformed, so we must scale, move, rotate stuff in vertex, egde or polygon mode.

Before exporting we select the root mesh (the "StreetLight" item in this example) and make visible all collision items. Then running the script without any arguments will produce a file in the "Content directory". (That dir can be set in modo's preferences.) The file will be named as the root mesh. Unlike in the other export modes, you can have multiple objects in the same scene, each with its own set of collision primitives.

Unfortunately, for Unreal this method is inferior to the ASE pipline. In build 2306 and before, the static mesh import from collada has several issues:
- Discards collision meshes.
- Discards smoothing groups.
- Discards vertex colors.
- Names the mesh as like "FileName_ObjectName".

So for the time being I recommend using the ASE exporter instead.


Rigid body mode

This export mode is for exporting a hierarchy of rigid bodies as a skeletal object. Each item in the scene will be associated with exactly one bone.

Let's take a look at the rigid body example file:

The hierarchy of the the items define the structure of the skeleton. In the exported file there will only be one render object, and several bones, named after the related item, affecting only the related polygons.

When we are happy with the model and the hierarchy, there is one more task to do: we must define the pivot points of each layer. This will be the point where a bone connects to its parent. The pivot of the first (root) item is irrelevant.

When everything is ready, we just select the first layer, make sure that all children are visible, and run the script with the "rigid" argument:

@collada_exporter.lua rigid

The file will be created in the "content directory" with the name of the scene.
(I'll cover the Unreal import later in this article.)


Soft body mode

In this mode we have our render object as the root item, and several "bone" items under it, defining the skeletal structure.

The soft body example is a very simple scene:

The first layer is the object which will be affected by all the bones lower in the hierarchy. The child items define the bone influences. I recommend using the premade items from the bone template scene. (Just drag and drop to your scene.)

Let's take a closer look at the bone items:

They have additional geometry inside, which serve as a guidline when setting up the influence falloff.
The hardness of the falloff is set in the item's Spline Patch Level property. The valid range for that value is from 1 to 100.
The higher the number is, the more vertices inside the volume will be 100% influenced by the actual bone.
For example if the value is 1 then only vertices in the inner most 1% of the volume will be totally affected, others gradually less and less toward the edges:

If the hardness is set to 50, then the influences look like this:

These bone items must only be transformed in item mode.
As in the case of the rigid body mode, the pivots define the points where the bones will connect to their parents.
The naming convention is as follows: the name must be at least 5 characters long, and the first 4 character must be ">UBX" or ">USP". Those prefixes will be stripped during export, so the bone's name will be the rest of the name. (In the example above, ">UBX_Bone" becomes a bone called "Bone" in the collada file.

We can export the object by running the script with the "soft" argument:

@collada_exporter.lua soft

As always, the root mesh should be selected, and all children set visible.


Import

Let's import the exported files into unreal. (Here I use build 2306, but I'll update this section as soon as I get my hands on a newer version.)
In the generic browser choose Import from the file menu, and pick a .dae file.

The Package and Group inputfields define where the asset will be imported to. The name is the name of the asset if imported as a skeletal mesh (tick box at the bottom). If the object is imported as a static mesh, then the name will look like "FileName_ObjectName", because it is possible to store and import more than one object from a collada file.
We can select such objects in the next dialog:

Just click on Select All to import everything.

If everything went well then the asset appears in the proper place. (If Unreal crashes during import, then we have a problem. More on this later in the Tips and trick section.)

If the skeletal mesh looks like a mess, as shown on the left, then we have to turn CPU skinning on: Double click on the asset to start the AnimSet Editor. In the Properties pane, Mesh tab, SkeletalMesh dropdown tick the bForceCPUSkinning flag. The mesh should look normal.

 

The AnimSet Editor is also the place where we can set the shaders the object should use. The Properties/Mesh/SkeletalMesh/Materials contains slots for them. Simply select a shader in the generic browser and click the green arrow in a selected slot.


Tips, tricks, troubleshooting

There are a few things to keep in mind, so let's start with modo specific things:

- Restart modo if the script execution fails with something like
193: attempt to index local 'ptA' (a nil value)

- Make all child items visible if the script execution fails with something like
621: attempt to index a nil value.

- During export, the script tends to create empty texture locators. It is a known issue, we are working on it. Until then just delete all "Texture: (none)" locators.

- Make sure that the render mesh has only one child. Unreal can import hierarchies where the root item has more than one bone on the second level of the hierarchy, but then it won't generate any constraints for them.

- Only create the hierarchy after all bones are in place and scaled properly. At the moment there is no way to transform bones without affecting all its children. So even for tweaking you have to disassemble the hierarchy and rebuild after the adjustments.

- It's a good idea to properly name the bones, especially when dealing with comples skeletons. It makes easier rebuilding the hierarchy.

- Select the Render item in the shader tree before parenting stuff with the "parent in place" command. (Or deselect anything there.) Due to a bug, the "parent in place" command will re-parent not just selected mesh items, but materials, shaders, textures, etc. too. They disappear from the shader tree and it is not easy to undo things if such an operation went unnoticed, because those items won't show up anywhere in the UI. If stuff disappears from the shader tree, this issue is a suspect.
If the damage has been done, then unparent everything, duplicate everything and delete the original items.
Of course, drag'n'drop parenting is unaffected by this issue.

- Delete all keyframes on all channels for all items before parenting. Due to a bug, Modo keeps creating keyframes for items, even if the "auto key creation" option is off. Keyframes screw up parenting, so before doing that, select all items, select all 9 transform channels, right click and "Remove key".
<- Keep those rings empty.

 

The Unreal specific rules and considerations are as follows:

- Unreal does not import vertex colors.

- Unreal only imports vertex normals from skeletal objects. Static meshes imported from a Collada file will not have any hard edges.

- Unreal only imports 1 UV for skeletal objects.

- One bone covering all vertices can cause problems. Auto bone collision generation in Phat usually fails, and Ued tends to crash when we manually add collision to bones. Try to avoid this setup.

- The skeleton probably has issues if automatic bone collision primitive generation fails, and doesn't generate proper collision for all bones. Ued will probably crash whan manually adding primitives. If so, try the following:

Step 1: Restart UEd, and try to add the bone which crashed UEd last time. If it crashes again...

Step 2: ...then try to add another bone before the adding the problematic one. If it still crashes...

Step 3 : ...then move/scale that bone a bit in modo. If it still crashes...

Step 4 : ...then make the root bone cover everything. (I know I've just said that it can cause problems, but at this point you have nothing to lose. :)

- Unreal tends to crash when overwriting existing skeletal objects. It seems to be allergic to other running processes (like modo) and certain topologies. You'll see which object needs to be deleted before re-importing.

- Unreal crashes after 10+ concecutive imports in a row. So the crash does not neccessarily means that the object has issues.

- Unreal crashes if a bone does not affect at least 1 vertex.

- Make sure that each vertex is affected by at least one bone at least a little bit. Otherwise UEd crashes on import or screws up the bone weights big time. To make it easier to check for stray vertices I made the bone materials transparent and blue:

By selecting all vertices in the root item, points (almost) outside the volumes show up in bright orange. Edges partially outside the influence zones don't matter.