AnimationExporter - Quaternion to euler conversion ( in progress )

AnimationImporter 
- Action group assignment to bones
- Revert to conversion of angles from deg to rad.
This commit is contained in:
2011-06-16 15:04:37 +00:00
parent a90d30c863
commit 6aa524f357
4 changed files with 49 additions and 27 deletions

View File

@@ -86,35 +86,43 @@ void AnimationExporter::exportAnimations(Scene *sce)
//}
}
/*float * AnimationExporter::get_eul_source_for_quat(Object *ob )
float * AnimationExporter::get_eul_source_for_quat(Object *ob )
{
FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
const int keys = fcu->totvert;
float quat[keys][4];
float eul[keys][3];
const int keys = fcu->totvert;
float *quat = (float*)MEM_callocN(sizeof(float) * fcu->totvert * 4, "quat output source values");
float *eul = (float*)MEM_callocN(sizeof(float) * fcu->totvert * 3, "quat output source values");
float temp_quat[4];
float temp_eul[3];
while(fcu)
{
transformName = extract_transform_name( fcu->rna_path );
char * transformName = extract_transform_name( fcu->rna_path );
if( !strcmp(transformName, "rotation_quaternion") )
{
for ( int i = 0 ; i < fcu->totvert ; i+=)
for ( int i = 0 ; i < fcu->totvert ; i++)
{
quat[i][fcu->array_index] = fcu->bezt[i].vec[1][1];
*(quat + ( i * 4 ) + fcu->array_index) = fcu->bezt[i].vec[1][1];
}
}
fcu = fcu->next;
}
for ( int i = 0 ; i < fcu->totvert ; i+=)
for ( int i = 0 ; i < fcu->totvert ; i++)
{
quat_to_eul(eul[i],quat[i]);
for ( int j = 0;j<4;j++)
temp_quat[j] = quat[(i*4)+j];
quat_to_eul(temp_eul,temp_quat);
for (int k = 0;k<3;k++)
eul[i*3 + k] = temp_eul[k];
}
return eul;
}*/
}
std::string AnimationExporter::getObjectBoneName( Object* ob,const FCurve* fcu )
{
//hard-way to derive the bone name from rna_path. Must find more compact method
@@ -134,15 +142,16 @@ void AnimationExporter::exportAnimations(Scene *sce)
const char *axis_name = NULL;
char anim_id[200];
bool has_tangents = false;
bool quatRotation = false;
if ( !strcmp(transformName, "rotation_quaternion") )
{
//quatRotation = true;
const char *axis_names[] = {"", "X", "Y", "Z"};
quatRotation = true;
/*const char *axis_names[] = {"", "X", "Y", "Z"};
if (fcu->array_index < 4)
axis_name = axis_names[fcu->array_index];
axis_name = axis_names[fcu->array_index];*/
}
else
@@ -173,7 +182,19 @@ void AnimationExporter::exportAnimations(Scene *sce)
std::string input_id = create_source_from_fcurve(COLLADASW::InputSemantic::INPUT, fcu, anim_id, axis_name);
// create output source
std::string output_id = create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name);
std::string output_id ;
/*if(quatRotation)
{
float * eul = get_eul_source_for_quat(ob);
float * eul_axis =
for ( int i = 0 ; i< fcu->totvert ; i++)
eul_axis[i] = eul[i*3 + fcu->array_index];
output_id= create_source_from_array(COLLADASW::InputSemantic::OUTPUT, eul_axis , fcu->totvert, quatRotation, anim_id, axis_name);
}
else*/
output_id= create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name);
// create interpolations source
std::string interpolation_id = create_interpolation_source(fcu, anim_id, axis_name, &has_tangents);

View File

@@ -112,9 +112,7 @@ protected:
void get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length);
/*float * get_eul_source_for_quat(Object *ob );*/
/*std::string create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, const std::string& anim_id, int array_index);*/
float * get_eul_source_for_quat(Object *ob );
std::string create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name);

View File

@@ -170,8 +170,8 @@ void AnimationImporter::fcurve_deg_to_rad(FCurve *cu)
for (unsigned int i = 0; i < cu->totvert; i++) {
// TODO convert handles too
cu->bezt[i].vec[1][1] *= M_PI / 180.0f;
/*cu->bezt[i].vec[0][1] *= M_PI / 180.0f;
cu->bezt[i].vec[2][1] *= M_PI / 180.0f;*/
cu->bezt[i].vec[0][1] *= M_PI / 180.0f;
cu->bezt[i].vec[2][1] *= M_PI / 180.0f;
cu->bezt[i].vec[1][0];
}
}
@@ -677,8 +677,8 @@ void AnimationImporter:: Assign_transform_animations(std::vector<float>* frames,
FCurve* fcu = *iter;
//if transform is rotation the fcurves values must be turned in to radian.
/*if (is_rotation)
fcurve_deg_to_rad(fcu); */
if (is_rotation)
fcurve_deg_to_rad(fcu);
}
COLLADAFW::Rotate* rot = (COLLADAFW::Rotate*)transform;
COLLADABU::Math::Vector3& axis = rot->getRotationAxis();
@@ -735,6 +735,7 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
bAction * act;
bActionGroup *grp = NULL;
if (!ob->adt || !ob->adt->action) act = verify_adt_action((ID*)&ob->id, 1);
else act = ob->adt->action;
@@ -765,8 +766,7 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
copy_m4_m4(rest, bone->arm_mat);
invert_m4_m4(irest, rest);
}
const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
//for each transformation in node
@@ -803,7 +803,10 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
//Add the curves of the current animation to the object
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
FCurve * fcu = *iter;
BLI_addtail(AnimCurves, fcu);
if (ob->type == OB_ARMATURE)
add_bone_fcurve( ob, node , fcu );
else
BLI_addtail(AnimCurves, fcu);
}
}
std::sort(frames.begin(), frames.end());
@@ -812,7 +815,7 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
if (is_joint)
{
bPoseChannel *chan = get_pose_channel(ob->pose, bone_name);
chan->rotmode = ROT_MODE_QUAT;
chan->rotmode = ROT_MODE_EUL;
}
else
{

View File

@@ -256,7 +256,7 @@ void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW
COLLADAFW::NodePointerArray &children = node->getChildNodes();
for (i = 0; i < children.getCount(); i++) {
translate_anim_recursive(children[i], node, ob);
translate_anim_recursive(children[i], node, NULL);
}
}