From BlenderWiki

Jump to: navigation, search

Full COLLADA Animation support for Blender

This project was proposed for GSoC 2011 and is now one of the 17 accepted projects for GSoC from Blender. The Project acceptance was announced on 25th April, 2011. The Project Proposal can be found here.

All of the necessary information for now can be found in the proposal.

>> Current State :- Finished for GSoC.

>> Diary and Notes.

Additional Links

Completed Features

Bezier Curves

Support for animations in Bezier interpolated curves. For f-curves with Bezier Interpolations in-tangent and out-tangent sources for the animation sampler is made when exporting animations to COLLADA. Export was adopted by a patch by cclife. Import of animation Curves with Bezier or Step interpolation type is supported also.

Improved Object animation support

Object animations worked in the previous system except for some discrepancies in rotations. This is solved. when exporting Object(Mesh, camera, Light or Armature) animations their f-curves are directly converted to animation curve sampler source values. Exporting armatures with objects parented to it is fixed also.

Comparison of the old System with the new System

Old animation export system vs the new export system :-

Old COLLADA Anim System.png
New COLLADA Anim System.png

At the final stages of the project, when implementing baked armature animation support, features from the old system was also included in the new system.

Export Armature Bone Animations

Export procedure

When exporting Armature bone animations the bones are sent to another animation export system. Which for each bone:-

  • Take all the key frames from the f-curves belonging to the bone.
  • calculate bones pose matrix at each frame.
  • Write the matrices at each frame in bone animation output source with param type "transform" and float4x4 sources.
  • Set channel target to Joint nodes matrix type transform with sid "transform". To set this, all the joint nodes are exported with matrix type transformations.
  • Because of transform matrix source writing for bone animations any type of animations on bones can be supported to export.
Bone animation export.png

New Animation Importer

Developed a new system for Animation importing. More details about the procedure is here: new import system


Support for Animations of non skin deforming bones

Prior to the project only skin deforming bones are exported with the armature exporter and bones are also imported depending that they have associated skin controller data. With the project Armature importer was edited so that bones without skin controller data can also be imported. So their animations can also be imported if there are any. Such bone animation support is demonstrated here: As shown in the video location of the bones are imported correctly. But due to the orientation not being imported correctly the animations also tend to go awry. This was fixed after the midterm. The bone role is set with a correct algorithm so the bones orientation is also more accurate. The relevant code is in the ArmatureImporter::create_bones() :

get_node_mat(obmat, node, NULL, NULL);
float loc[3], size[3], rot[3][3];
mat4_to_loc_rot_size( loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle );
bone->roll=angle;

With the new system Import Armature animations parented to other objects is also possible.

Light parameter animation

Export and import of animations of the following parameters of light is supported:

  • Color
  • spot Size ( Fall of angle in COLLADA)
  • spot blend


Camera Parameter animation

Export and import of animations of the following parameters of cameras is supported:

  • lens
  • Ortho scale
  • clip start
  • clip end

Material Effect parameter animation

Export and import of animations of the following parameters of Materials is supported:

  • Specular color
  • Specular hardness
  • Transparency ( export only )
  • Raytrace transparency index of refraction

Support for Combination of animations

This was achieved through setting flags for animations of each node.

Blender profile for tip

The tip bone(s) of an armature is exported in a separate blender profile. This profile was later added to bones which have more than one child. Because when importing joint nodes like this arbitrary values are assigned to the leaf bones and bones which have more than one child. To clarify this the profile was added so that the leaf bone tail can be properly assigned. This was disabled in the final stages because of bugs discovered in importing exports of fully rigified armatures.

Blender tip profile.png

Rigged Armature Animation Support

Initially rigged armature export and import was tried in the final stage. Although it failed during normal unbaked export and import, it was possible after baking the animations. The procedure followed is described in this video also:-

  1. Go in to pose mode
  2. go to bake action window.( Press space in 3D view and type Bake action)
  3. Select start and end frames in the baking window
  4. Check "Clear Constraints" and uncheck "Only selected"
  5. Bake action
  6. Export the scene.

Also additionally for smaller files, only deform bones can be selected and animation can be baked only to them. Then when exporting to Collada select the mesh and the deform bones. Then in the COLLADA export window "export only selected" option can be selected to export to a smaller dae file.

Unfinished

  • Support for Hermite and B-Spline interpolation types.
  • Conversion of quaternion rotations to euler rotations before exporting for Objects. Because Opencollada is incompatible with quat rotations.
  • Automate Armature Animation Baking. This is still tentative. The option would be to duplicate the armature with the animations and bake the action to the duplicate armature. Then export the data of that duplicate armature. For this the python script for Animation baking needs to be converted to C++ also. On the other hand automation will reduce flexibility for some cases. Because Users can always run the python script according to their preferences.
  • Test the system for exceptional cases.
  • Camera Aspect ratio animations.
  • Blender specific animations in blender profile. This was postponed to the later stages after the project because a new system for blender profile animations needs to be developed.
  • texture parameter animations.

Discussions

This section will discuss the issues I've encountered along the project timeline.

Exporting f-curve Sources

When Exporting f-curves, we can export output source values of all axises in one array instead of having 3 different arrays for each axis. At least that's what happens in bone animation exporting

Also one alternate approach in creating semantic sources is to have larger arrays with count and stride edited according to the semantic. The code would be much smoother with expense of larger collada docs. However, Discussed with jesterking on the above matter and agreed on exporting single dimension sources for each axis.

Unskinned Armature animation support

Currently the system is able to import only animations of armatures if they are skinned only. This can be improved by Having a separate list of unskinned armatures. This surely will help to test the systems functionality. But this doesn't help the bugs of importing skinned armatures. The problem remains when importing documents without animation tags. So after discussing with jesterking, decided to improve the armature import system also. Would be great to receive as much help as I can get on that area.

Bone orientation import

It can be verified that the animations are assigned to each bone accurately. But the animation taken as a whole for the armature, is still faulty. This is due to the inaccuracy of the bones rest orientations being applied when importing armatures.

When importing bones only the joint node transform matrix is read out and the world space matrix is calculated by multiplying with parent matrices and so on. And only the location attribute is derived from that space matrix and applied to the bone-> head attribute. The tail is derived from child bone's heads and so on. Other attributes of bones are defaulted. Because of this method the bone positions are imported accurately. But the orientation is not what's exported. So the animations of the whole armature gets messed up.

When exporting bones the bones pose matrix is used to determine the node transformation matrix. So tried to set bones pose matrix directly when importing joint node transforms also. This didn't solve the issue. Must be further tested. But setting pose matrices only will not obviously solve the issue. Because it works when exporting as the pose matrix holds all the constraints and transformations of the bones which can be directly used to get the transformation matrix. But when imported the imported transformation would have to be decomposed into relevant attributes which the pose matrix is made of. Currently working on that. Main concern is deriving the roll attribute of the bone when importing joint nodes.

Campbell Barton(ideasman_42) pointed out that the algorithm is faulty and setting the pose matrix is not going to solve the problem. Somehow the setting the bone roll by using the joint node matrices will solve the overall problem. The algorithm for it needs to be developed however.