Exporting Blender to Shiva via Collada DAE E-mail
Saturday, 25 September 2010 21:49

Well, doesn't time fly?

Over the last few months I've been busy doing .NET development, with little time or inclination to do any game work, compounded by a little issue with Shiva that completely blocked my evolving development pipeline.

Back when I'd purchased Shiva in May, I had planned for objects, levels, etc to be designed in Blender, which I'm very familiar with, followed by importing them into Shiva. Sure enough, my tests at the time showed that  Blender could export Collada DAE files and Shiva could read them just fine.

My first Shiva project was The Scout, a very simple demo that allowed me to trial the process of moving a model from Blender to Shiva. Sure enough, it was a big success, I was very happy with the final result, and it led to me purchasing Shiva.

It was when I began my second project that the pipeline blockage appeared, in the form of a hairball that wasn't really Shiva's fault.

Blender to Collada DAE to Shiva

It turned out that the current stable version of Blender (2.49) would discard skeletons when exporting to Collada. For those uninitiated in the ways of modern computer animation, a skeleton, much like in real life, is composed of bones which reside inside a model that is to be animated. The model is attached to the skeleton and and movement of the bones causes the model to bend and stretch.

With Blender's Collada exporter discarding the skeleton, to my horror, I discovered that I had no way of getting my models out of Blender and into Shiva.

Blender 2.49 to Blender 2.51 to Collada DAE to Shiva

Enter the new, unstable version of Blender, which is supposed to include a brand new, integrated, Collada exporter, written by a Google Summer of Code student.

At the time I began my investigation into exporting from Blender to Collada, the unstable version of the Blender 2.5x series had only recently acquired the Collada export code, and there were bugs.

My first foray into importing an animated model of a walking man produced a result that was not unlike the transporter accident in the first Star Trek movie. All of my poor model's limbs collapsed into the center of the object, and any attempt to play the animation just caused the model to writhe in agony.

I played around with the model for a few days, discovering a few rules that produced a superior mess that more closely resembled the original model, but the limbs would still collapse and the animation just wasn't right.

After spending approximately four days on this, I gave up.

Blender 2.49 to Blender 2.54 to Collada DAE to Shiva

Fast forward several months to late August and I decided to check out the Shiva forums to see if any progress had been made in getting animated models out of Blender. Surprisingly, an enterprising individual who goes by the handle ThunderZ, had reported in early August that had had successfully imported an animated model from Blender into Shiva. To back this up he included proof in the form of some images and an animation and promised a tutorial on how to do it.

Towards the end of August, my other work started to slow a bit, so, assuming ThunderZ would post his tutorial shortly, I decided to begin work on a new project with Shiva.

About three weeks later and I was ready to starting messing around with importing animated models. A quick check of the Shiva forums showed that there was no sign of ThunderZ's tutorial, just apologies for the delay and promises it was coming.

Another week passed and I was fed up. Unable to continue on my project without being sure I was going to be able to animate my characters, I decided to figure it out myself. Half the battle is knowing it can be done, and prior to ThunderZ's post, I doubted it could be done. I took a closer look at the image that ThunderZ had originally, and I noticed there was a solitary bone between the feet of his bird character that appeared to have several other bones in the body parented to it, without being directly connected.

This in itself isn't unusual, as a central bone can be used as a handle for positioning a model, however, remembering my issue with the collapsing limbs, I thought to myself: "Perhaps the way to stop the bones collapsing into the center is to parent them to a parent-less bone that is already at the center?"

An hour later, I had a robot model successfully imported into Shiva, waving it's arms and legs around just the way I'd animated them in Blender!

The secret for getting an animated model from Blender into Shiva

So, here it is, everything that needs to be done to successfully get an animated model into Blender, without going via expensive Windows applications. Surprisingly, it's not actually complicated, but missing even one rule can completely screw up an animated model.

  1. The model and the armature must both be positioned at 0,0,0 and have a scale of 1,1,1
    Shiva will attempt to center the armature at the center (0, 0, 0), so if you don't set it and the model there to start with, both the armature and model will be out of alignment.
  2. All bones which have no parent must be parented to a "root" bone that is positioned at 0,0,0
    This is what stops the disconnected bones collapsing to the center. It seems that Shiva, or Blender's Collada exporter, is resetting the position of bones that don't have a parent.
  3. All bones must have bone roll set to zero
    Unfortunately, you'll have to set the bone roll to zero and lose the ability to copy and paste poses with Blender's animation tools, otherwise, when Shiva imports the model, it'll twist the bones around to get them to zero, and distort your model.
  4. The first and last key frames of the animation must be the rest pose
    Blender and Shiva appear to use a different starting point for indexing the key frames. This means that Shiva's first key frame is actually the last key frame from Blender's point of view, so if you don't set it to the rest post, your model will be loaded in the rest pose, while the bones are in a completely different pose. Animating from there will make the model distort and twist in horrible ways. You can work around the issue of the rest pose key frames screwing up your awesome animation simply by setting the animation range to skip the unwanted frames at the beginning and end of the animation, once you get it into Shiva.
  5. The export must be done with the latest version of the Blender 2.5x series
    I've personally tested this with the version of 2.54 that's currently available on the Blender.org website, and it works, though the export has to be done in the Windows version currently. It's apparently got something to do with the version of the Collada export library that's compiled into the Windows version, and will hopefully make it's way to Linux in the near future.

Successfully exporting a Collada DAE file to Shiva

The above image shows the bones I used to achieve a successful export to Shiva. The spine and hip bones originally had no parent, so I've parented them to the large bone (root) that is between the feet of the robot. This bone is located at the center (0, 0, 0), so when the skeleton is imported into Shiva, it's got nowhere to go, so everything stays in place.

Special thanks to ThunderZ for figuring out rule number 2, but surely you could have just told us what it was!

blog comments powered by Disqus