Copying animations between units

Last week started with a thought – “Copying skinning and animations from unit to unit should be trivial, right?”

Let’s see, but first – some intro:

Disposition

All games need to store their assets (models, textures, sfx, etc.). For most games assets are prepared and stored in a way that their engine requires. With a custom engine, this goes a bit other way round – engine is created around common formats of asset formats that engine’s creators chose. Of course each game (and Knights Province is not an exception) might eventually distill required pieces and rearrange them in a way to speed up data loading and enrich with engine-specific features (i.e. KP has add-on info for house building steps or vertex weights for terrain tiles).

I’m mostly using Lightwave 3D format (LWO) for in-game models. I’m fairly experienced with it and when I need to create or tweak a model – Lightwave 3D is my tool of choice. Currently ~90% of models in the game are in LWO format (to be distilled later on, to improve loadig times and save space). Since all models were mostly static in early games life and I knew how to model staticobjects, I used LW to model placeholder houses and units.

However, game also needs animations, and that’s something I’m not really experienced nor skilled at. So after creating sample unit animation I went to hire freelancers to do better models and animations. Now I had to deal with their preferences, since asking someone to create both good models AND requiring them to convert it to format unknown to them is a tough/expensive thing. Fortunately, there’s a common ground – FBX is kind of a standard file format when it comes to models and animations for games. Most freelancers use it (also OBJ, but it’s less common).

So I was tasked with extracting models and animations from FBX. Since LW can open FBX files, I decided simply to use LW to convert FBX and call it a day. LW animation format is quite complex (and complicated). To extract animation data needed for the game, I wrote a special Python plugin to export animation frames into a text file in compact and straightforward form. Because of all that, existing process of animation import is rather lengthy:

  1. Obtain FBX animation from freelancer
  2. Convert FBX to LWO
  3. Tweak skeleton setup in LW
  4. Export static skeleton from LW to game format with a Python plugin
  5. Export animation same way

In actuality that’s a tedious 19-step process prone to mistakes. It works okay for 2-3 models, but it’s unbearable for anything larger.

So far game has just a bunch of animations. It would be nice to reuse some, e.g. walking unit animation is the same for all citizen (for warriors it’s a bit different, since they walk with regard to carried weapon).

Idea

It would be great to copy common animations from models who have them to the rest (e.g. idle and walk animations).

To make things right, I decided to write FBX animation importer. It’s not strictly necessary for the task, but once I’m at animations, it’s better to fix several adjoined areas. I already had code to read and parse FBX file format (few in-game houses are actually FBX, not LWO models). Expanding the code with reading of skeletal and animation info should not be that hard .. so I thought.

Last week was dedicated to that task. Things learned and reinforced:

  1. Anything that seems trivial could easily take 20 hours because of unforeseen details, auxiliary things and need to wrap it all into a neat “API”.
  2. Even with unforeseen details, if something seems doable (i.e. without involving words “automatically” or “somehow” in its description), it’s really doable, just needs more time.
  3. The way FBX and LWO stack transformation operations is different (and learning that alone cost me a day).
  4. Automation is great. Writing a small dedicated tool to convert, copy and launch preview instead of manually doing the same – saved my sanity.
  5. When something seems about right, but not quite – it’s almost as good as wrong.
  6. Animation bugs are fun:

Plans

Now with swordsman animations working, I intend to:

  1. Re-import  existing unit animations (and throw out LWO animation code)
  2. Write methods for copying skinning between models
  3. Tweak couple stray errors in skinning
  4. Have all units have common walk/idle animation in Alpha 10
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to Copying animations between units

  1. Lautaro Zualet says:

    i wonder if those animations will be ready sometime in the future.

    • Krom says:

      I plan to get done with existing animations for Alpha 10. Other animations will still need a lot of work (e.g. unit work animations in houses)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.