Some whitespace changes
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
* $Id$
|
||||
*
|
||||
* ***** BEGIN GPL LICENSE BLOCK *****
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed.
|
||||
*
|
||||
* ***** END GPL LICENSE BLOCK *****
|
||||
*/
|
||||
|
||||
#include "GeometryExporter.h"
|
||||
#include "AnimationExporter.h"
|
||||
@@ -30,10 +30,10 @@ template<class Functor>
|
||||
void forEachObjectInScene(Scene *sce, Functor &f)
|
||||
{
|
||||
Base *base= (Base*) sce->base.first;
|
||||
|
||||
|
||||
while(base) {
|
||||
Object *ob = base->object;
|
||||
|
||||
|
||||
f(ob);
|
||||
|
||||
base= base->next;
|
||||
@@ -61,7 +61,7 @@ void AnimationExporter::operator() (Object *ob)
|
||||
bool isMatAnim = false;
|
||||
|
||||
//Export transform animations
|
||||
if(ob->adt && ob->adt->action)
|
||||
if(ob->adt && ob->adt->action)
|
||||
{
|
||||
fcu = (FCurve*)ob->adt->action->curves.first;
|
||||
|
||||
@@ -72,21 +72,21 @@ void AnimationExporter::operator() (Object *ob)
|
||||
for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
|
||||
write_bone_animation_matrix(ob, bone);
|
||||
}
|
||||
|
||||
|
||||
while (fcu) {
|
||||
//for armature animations as objects
|
||||
if ( ob->type == OB_ARMATURE )
|
||||
transformName = fcu->rna_path;
|
||||
else
|
||||
transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
|
||||
if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
|
||||
(!strcmp(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL)||
|
||||
(!strcmp(transformName, "rotation_quaternion")))
|
||||
dae_animation(ob ,fcu, transformName, false);
|
||||
fcu = fcu->next;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Export Lamp parameter animations
|
||||
@@ -94,8 +94,8 @@ void AnimationExporter::operator() (Object *ob)
|
||||
{
|
||||
fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
|
||||
while (fcu) {
|
||||
transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
if ((!strcmp(transformName, "color")) || (!strcmp(transformName, "spot_size"))|| (!strcmp(transformName, "spot_blend"))||
|
||||
(!strcmp(transformName, "distance")) )
|
||||
dae_animation(ob , fcu, transformName, true );
|
||||
@@ -108,8 +108,8 @@ void AnimationExporter::operator() (Object *ob)
|
||||
{
|
||||
fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
|
||||
while (fcu) {
|
||||
transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
if ((!strcmp(transformName, "lens"))||
|
||||
(!strcmp(transformName, "ortho_scale"))||
|
||||
(!strcmp(transformName, "clip_end"))||(!strcmp(transformName, "clip_start")))
|
||||
@@ -129,7 +129,7 @@ void AnimationExporter::operator() (Object *ob)
|
||||
fcu = (FCurve*)ma->adt->action->curves.first;
|
||||
while (fcu) {
|
||||
transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
|
||||
if ((!strcmp(transformName, "specular_hardness"))||(!strcmp(transformName, "specular_color"))
|
||||
||(!strcmp(transformName, "diffuse_color"))||(!strcmp(transformName, "alpha"))||
|
||||
(!strcmp(transformName, "ior")))
|
||||
@@ -137,384 +137,384 @@ void AnimationExporter::operator() (Object *ob)
|
||||
fcu = fcu->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//euler sources from quternion sources
|
||||
float * AnimationExporter::get_eul_source_for_quat(Object *ob )
|
||||
//euler sources from quternion sources
|
||||
float * AnimationExporter::get_eul_source_for_quat(Object *ob )
|
||||
{
|
||||
FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
|
||||
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)
|
||||
{
|
||||
FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
|
||||
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)
|
||||
{
|
||||
char * transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
if( !strcmp(transformName, "rotation_quaternion") ) {
|
||||
for ( int i = 0 ; i < fcu->totvert ; i++){
|
||||
*(quat + ( i * 4 ) + fcu->array_index) = fcu->bezt[i].vec[1][1];
|
||||
}
|
||||
}
|
||||
fcu = fcu->next;
|
||||
char * transformName = extract_transform_name( fcu->rna_path );
|
||||
|
||||
if( !strcmp(transformName, "rotation_quaternion") ) {
|
||||
for ( int i = 0 ; i < fcu->totvert ; i++){
|
||||
*(quat + ( i * 4 ) + fcu->array_index) = fcu->bezt[i].vec[1][1];
|
||||
}
|
||||
|
||||
for ( int i = 0 ; i < keys ; 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];
|
||||
|
||||
}
|
||||
MEM_freeN(quat);
|
||||
return eul;
|
||||
|
||||
}
|
||||
|
||||
//Get proper name for bones
|
||||
std::string AnimationExporter::getObjectBoneName( Object* ob,const FCurve* fcu )
|
||||
{
|
||||
//hard-way to derive the bone name from rna_path. Must find more compact method
|
||||
std::string rna_path = std::string(fcu->rna_path);
|
||||
|
||||
char* boneName = strtok((char *)rna_path.c_str(), "\"");
|
||||
boneName = strtok(NULL,"\"");
|
||||
|
||||
if( boneName != NULL )
|
||||
return /*id_name(ob) + "_" +*/ std::string(boneName);
|
||||
else
|
||||
return id_name(ob);
|
||||
}
|
||||
|
||||
//convert f-curves to animation curves and write
|
||||
void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material * ma )
|
||||
{
|
||||
const char *axis_name = NULL;
|
||||
char anim_id[200];
|
||||
|
||||
bool has_tangents = false;
|
||||
bool quatRotation = false;
|
||||
|
||||
if ( !strcmp(transformName, "rotation_quaternion") )
|
||||
{
|
||||
fprintf(stderr, "quaternion rotation curves are not supported. rotation curve will not be exported\n");
|
||||
quatRotation = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//axis names for colors
|
||||
else if ( !strcmp(transformName, "color")||!strcmp(transformName, "specular_color")||!strcmp(transformName, "diffuse_color")||
|
||||
(!strcmp(transformName, "alpha")))
|
||||
{
|
||||
const char *axis_names[] = {"R", "G", "B"};
|
||||
if (fcu->array_index < 3)
|
||||
fcu = fcu->next;
|
||||
}
|
||||
|
||||
for ( int i = 0 ; i < keys ; 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];
|
||||
|
||||
}
|
||||
MEM_freeN(quat);
|
||||
return eul;
|
||||
|
||||
}
|
||||
|
||||
//Get proper name for bones
|
||||
std::string AnimationExporter::getObjectBoneName( Object* ob,const FCurve* fcu )
|
||||
{
|
||||
//hard-way to derive the bone name from rna_path. Must find more compact method
|
||||
std::string rna_path = std::string(fcu->rna_path);
|
||||
|
||||
char* boneName = strtok((char *)rna_path.c_str(), "\"");
|
||||
boneName = strtok(NULL,"\"");
|
||||
|
||||
if( boneName != NULL )
|
||||
return /*id_name(ob) + "_" +*/ std::string(boneName);
|
||||
else
|
||||
return id_name(ob);
|
||||
}
|
||||
|
||||
//convert f-curves to animation curves and write
|
||||
void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material * ma )
|
||||
{
|
||||
const char *axis_name = NULL;
|
||||
char anim_id[200];
|
||||
|
||||
bool has_tangents = false;
|
||||
bool quatRotation = false;
|
||||
|
||||
if ( !strcmp(transformName, "rotation_quaternion") )
|
||||
{
|
||||
fprintf(stderr, "quaternion rotation curves are not supported. rotation curve will not be exported\n");
|
||||
quatRotation = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//axis names for colors
|
||||
else if ( !strcmp(transformName, "color")||!strcmp(transformName, "specular_color")||!strcmp(transformName, "diffuse_color")||
|
||||
(!strcmp(transformName, "alpha")))
|
||||
{
|
||||
const char *axis_names[] = {"R", "G", "B"};
|
||||
if (fcu->array_index < 3)
|
||||
axis_name = axis_names[fcu->array_index];
|
||||
}
|
||||
|
||||
//axis names for transforms
|
||||
else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
|
||||
(!strcmp(transformName, "rotation_euler"))||(!strcmp(transformName, "rotation_quaternion")))
|
||||
{
|
||||
const char *axis_names[] = {"X", "Y", "Z"};
|
||||
if (fcu->array_index < 3)
|
||||
axis_name = axis_names[fcu->array_index];
|
||||
}
|
||||
|
||||
//no axis name. single parameter.
|
||||
else{
|
||||
axis_name = "";
|
||||
}
|
||||
|
||||
std::string ob_name = std::string("null");
|
||||
|
||||
//Create anim Id
|
||||
if (ob->type == OB_ARMATURE)
|
||||
{
|
||||
ob_name = getObjectBoneName( ob , fcu);
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s.%s", (char*)translate_id(ob_name).c_str(),
|
||||
transformName, axis_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ma)
|
||||
ob_name = id_name(ob) + "_material";
|
||||
else
|
||||
ob_name = id_name(ob);
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
|
||||
fcu->rna_path, axis_name);
|
||||
}
|
||||
|
||||
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
|
||||
|
||||
// create input source
|
||||
std::string input_id = create_source_from_fcurve(COLLADASW::InputSemantic::INPUT, fcu, anim_id, axis_name);
|
||||
|
||||
// create output source
|
||||
std::string output_id ;
|
||||
|
||||
//quat rotations are skipped for now, because of complications with determining axis.
|
||||
if(quatRotation)
|
||||
{
|
||||
float * eul = get_eul_source_for_quat(ob);
|
||||
float * eul_axis = (float*)MEM_callocN(sizeof(float) * fcu->totvert, "quat output source values");
|
||||
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);
|
||||
MEM_freeN(eul);
|
||||
MEM_freeN(eul_axis);
|
||||
}
|
||||
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);
|
||||
|
||||
// handle tangents (if required)
|
||||
std::string intangent_id;
|
||||
std::string outtangent_id;
|
||||
|
||||
if (has_tangents) {
|
||||
// create in_tangent source
|
||||
intangent_id = create_source_from_fcurve(COLLADASW::InputSemantic::IN_TANGENT, fcu, anim_id, axis_name);
|
||||
|
||||
// create out_tangent source
|
||||
outtangent_id = create_source_from_fcurve(COLLADASW::InputSemantic::OUT_TANGENT, fcu, anim_id, axis_name);
|
||||
}
|
||||
|
||||
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
|
||||
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
|
||||
std::string empty;
|
||||
sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
|
||||
|
||||
// this input is required
|
||||
sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
|
||||
|
||||
if (has_tangents) {
|
||||
sampler.addInput(COLLADASW::InputSemantic::IN_TANGENT, COLLADABU::URI(empty, intangent_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUT_TANGENT, COLLADABU::URI(empty, outtangent_id));
|
||||
}
|
||||
|
||||
addSampler(sampler);
|
||||
|
||||
std::string target ;
|
||||
|
||||
if ( !is_param )
|
||||
target = translate_id(ob_name)
|
||||
+ "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true);
|
||||
else
|
||||
{
|
||||
if ( ob->type == OB_LAMP )
|
||||
target = get_light_id(ob)
|
||||
+ "/" + get_light_param_sid(fcu->rna_path, -1, axis_name, true);
|
||||
|
||||
if ( ob->type == OB_CAMERA )
|
||||
target = get_camera_id(ob)
|
||||
+ "/" + get_camera_param_sid(fcu->rna_path, -1, axis_name, true);
|
||||
|
||||
if( ma )
|
||||
target = translate_id(id_name(ma)) + "-effect"
|
||||
+"/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true);
|
||||
}
|
||||
addChannel(COLLADABU::URI(empty, sampler_id), target);
|
||||
|
||||
closeAnimation();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//write bone animations in transform matrix sources
|
||||
void AnimationExporter::write_bone_animation_matrix(Object *ob_arm, Bone *bone)
|
||||
//axis names for transforms
|
||||
else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
|
||||
(!strcmp(transformName, "rotation_euler"))||(!strcmp(transformName, "rotation_quaternion")))
|
||||
{
|
||||
if (!ob_arm->adt)
|
||||
return;
|
||||
|
||||
//This will only export animations of bones in deform group.
|
||||
/*if(!is_bone_deform_group(bone))
|
||||
return;*/
|
||||
|
||||
sample_and_write_bone_animation_matrix(ob_arm, bone);
|
||||
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
|
||||
write_bone_animation_matrix(ob_arm, child);
|
||||
const char *axis_names[] = {"X", "Y", "Z"};
|
||||
if (fcu->array_index < 3)
|
||||
axis_name = axis_names[fcu->array_index];
|
||||
}
|
||||
|
||||
bool AnimationExporter::is_bone_deform_group(Bone * bone)
|
||||
//no axis name. single parameter.
|
||||
else{
|
||||
axis_name = "";
|
||||
}
|
||||
|
||||
std::string ob_name = std::string("null");
|
||||
|
||||
//Create anim Id
|
||||
if (ob->type == OB_ARMATURE)
|
||||
{
|
||||
bool is_def;
|
||||
//Check if current bone is deform
|
||||
if((bone->flag & BONE_NO_DEFORM) == 0 ) return true;
|
||||
//Check child bones
|
||||
else
|
||||
{
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next){
|
||||
//loop through all the children until deform bone is found, and then return
|
||||
is_def = is_bone_deform_group(child);
|
||||
if (is_def) return true;
|
||||
}
|
||||
}
|
||||
//no deform bone found in children also
|
||||
return false;
|
||||
ob_name = getObjectBoneName( ob , fcu);
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s.%s", (char*)translate_id(ob_name).c_str(),
|
||||
transformName, axis_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (ma)
|
||||
ob_name = id_name(ob) + "_material";
|
||||
else
|
||||
ob_name = id_name(ob);
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
|
||||
fcu->rna_path, axis_name);
|
||||
}
|
||||
|
||||
void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
|
||||
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
|
||||
|
||||
// create input source
|
||||
std::string input_id = create_source_from_fcurve(COLLADASW::InputSemantic::INPUT, fcu, anim_id, axis_name);
|
||||
|
||||
// create output source
|
||||
std::string output_id ;
|
||||
|
||||
//quat rotations are skipped for now, because of complications with determining axis.
|
||||
if(quatRotation)
|
||||
{
|
||||
bArmature *arm = (bArmature*)ob_arm->data;
|
||||
int flag = arm->flag;
|
||||
std::vector<float> fra;
|
||||
//char prefix[256];
|
||||
float * eul = get_eul_source_for_quat(ob);
|
||||
float * eul_axis = (float*)MEM_callocN(sizeof(float) * fcu->totvert, "quat output source values");
|
||||
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);
|
||||
MEM_freeN(eul);
|
||||
MEM_freeN(eul_axis);
|
||||
}
|
||||
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);
|
||||
|
||||
FCurve* fcu = (FCurve*)ob_arm->adt->action->curves.first;
|
||||
while(fcu)
|
||||
{
|
||||
std::string bone_name = getObjectBoneName(ob_arm,fcu);
|
||||
int val = BLI_strcasecmp((char*)bone_name.c_str(),bone->name);
|
||||
if(val==0) break;
|
||||
fcu = fcu->next;
|
||||
// handle tangents (if required)
|
||||
std::string intangent_id;
|
||||
std::string outtangent_id;
|
||||
|
||||
if (has_tangents) {
|
||||
// create in_tangent source
|
||||
intangent_id = create_source_from_fcurve(COLLADASW::InputSemantic::IN_TANGENT, fcu, anim_id, axis_name);
|
||||
|
||||
// create out_tangent source
|
||||
outtangent_id = create_source_from_fcurve(COLLADASW::InputSemantic::OUT_TANGENT, fcu, anim_id, axis_name);
|
||||
}
|
||||
|
||||
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
|
||||
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
|
||||
std::string empty;
|
||||
sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
|
||||
|
||||
// this input is required
|
||||
sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
|
||||
|
||||
if (has_tangents) {
|
||||
sampler.addInput(COLLADASW::InputSemantic::IN_TANGENT, COLLADABU::URI(empty, intangent_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUT_TANGENT, COLLADABU::URI(empty, outtangent_id));
|
||||
}
|
||||
|
||||
addSampler(sampler);
|
||||
|
||||
std::string target ;
|
||||
|
||||
if ( !is_param )
|
||||
target = translate_id(ob_name)
|
||||
+ "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true);
|
||||
else
|
||||
{
|
||||
if ( ob->type == OB_LAMP )
|
||||
target = get_light_id(ob)
|
||||
+ "/" + get_light_param_sid(fcu->rna_path, -1, axis_name, true);
|
||||
|
||||
if ( ob->type == OB_CAMERA )
|
||||
target = get_camera_id(ob)
|
||||
+ "/" + get_camera_param_sid(fcu->rna_path, -1, axis_name, true);
|
||||
|
||||
if( ma )
|
||||
target = translate_id(id_name(ma)) + "-effect"
|
||||
+"/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true);
|
||||
}
|
||||
addChannel(COLLADABU::URI(empty, sampler_id), target);
|
||||
|
||||
closeAnimation();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//write bone animations in transform matrix sources
|
||||
void AnimationExporter::write_bone_animation_matrix(Object *ob_arm, Bone *bone)
|
||||
{
|
||||
if (!ob_arm->adt)
|
||||
return;
|
||||
|
||||
//This will only export animations of bones in deform group.
|
||||
/*if(!is_bone_deform_group(bone))
|
||||
return;*/
|
||||
|
||||
sample_and_write_bone_animation_matrix(ob_arm, bone);
|
||||
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
|
||||
write_bone_animation_matrix(ob_arm, child);
|
||||
}
|
||||
|
||||
bool AnimationExporter::is_bone_deform_group(Bone * bone)
|
||||
{
|
||||
bool is_def;
|
||||
//Check if current bone is deform
|
||||
if((bone->flag & BONE_NO_DEFORM) == 0 ) return true;
|
||||
//Check child bones
|
||||
else
|
||||
{
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next){
|
||||
//loop through all the children until deform bone is found, and then return
|
||||
is_def = is_bone_deform_group(child);
|
||||
if (is_def) return true;
|
||||
}
|
||||
}
|
||||
//no deform bone found in children also
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!(fcu)) return;
|
||||
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
|
||||
if (!pchan)
|
||||
return;
|
||||
|
||||
find_frames(ob_arm, fra);
|
||||
void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
|
||||
{
|
||||
bArmature *arm = (bArmature*)ob_arm->data;
|
||||
int flag = arm->flag;
|
||||
std::vector<float> fra;
|
||||
//char prefix[256];
|
||||
|
||||
if (flag & ARM_RESTPOS) {
|
||||
arm->flag &= ~ARM_RESTPOS;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
FCurve* fcu = (FCurve*)ob_arm->adt->action->curves.first;
|
||||
while(fcu)
|
||||
{
|
||||
std::string bone_name = getObjectBoneName(ob_arm,fcu);
|
||||
int val = BLI_strcasecmp((char*)bone_name.c_str(),bone->name);
|
||||
if(val==0) break;
|
||||
fcu = fcu->next;
|
||||
}
|
||||
|
||||
if (fra.size()) {
|
||||
dae_baked_animation(fra ,ob_arm, bone );
|
||||
}
|
||||
if(!(fcu)) return;
|
||||
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
|
||||
if (!pchan)
|
||||
return;
|
||||
|
||||
if (flag & ARM_RESTPOS)
|
||||
arm->flag = flag;
|
||||
find_frames(ob_arm, fra);
|
||||
|
||||
if (flag & ARM_RESTPOS) {
|
||||
arm->flag &= ~ARM_RESTPOS;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
|
||||
void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm , Bone *bone)
|
||||
{
|
||||
std::string ob_name = id_name(ob_arm);
|
||||
std::string bone_name = bone->name;
|
||||
char anim_id[200];
|
||||
|
||||
if (!fra.size())
|
||||
return;
|
||||
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
|
||||
(char*)translate_id(bone_name).c_str(), "pose_matrix");
|
||||
|
||||
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
|
||||
|
||||
// create input source
|
||||
std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, fra, false, anim_id, "");
|
||||
|
||||
// create output source
|
||||
std::string output_id;
|
||||
output_id = create_4x4_source( fra, ob_arm , bone , anim_id);
|
||||
|
||||
// create interpolations source
|
||||
std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, "");
|
||||
|
||||
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
|
||||
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
|
||||
std::string empty;
|
||||
sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
|
||||
|
||||
// TODO create in/out tangents source
|
||||
|
||||
// this input is required
|
||||
sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
|
||||
|
||||
addSampler(sampler);
|
||||
|
||||
std::string target = translate_id(bone_name) + "/transform";
|
||||
addChannel(COLLADABU::URI(empty, sampler_id), target);
|
||||
|
||||
closeAnimation();
|
||||
if (fra.size()) {
|
||||
dae_baked_animation(fra ,ob_arm, bone );
|
||||
}
|
||||
|
||||
// dae_bone_animation -> add_bone_animation
|
||||
// (blend this into dae_bone_animation)
|
||||
void AnimationExporter::dae_bone_animation(std::vector<float> &fra, float *values, int tm_type, int axis, std::string ob_name, std::string bone_name)
|
||||
{
|
||||
const char *axis_names[] = {"X", "Y", "Z"};
|
||||
const char *axis_name = NULL;
|
||||
char anim_id[200];
|
||||
bool is_rot = tm_type == 0;
|
||||
|
||||
if (!fra.size())
|
||||
return;
|
||||
if (flag & ARM_RESTPOS)
|
||||
arm->flag = flag;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
|
||||
char rna_path[200];
|
||||
BLI_snprintf(rna_path, sizeof(rna_path), "pose.bones[\"%s\"].%s", bone_name.c_str(),
|
||||
tm_type == 0 ? "rotation_quaternion" : (tm_type == 1 ? "scale" : "location"));
|
||||
void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm , Bone *bone)
|
||||
{
|
||||
std::string ob_name = id_name(ob_arm);
|
||||
std::string bone_name = bone->name;
|
||||
char anim_id[200];
|
||||
|
||||
if (axis > -1)
|
||||
axis_name = axis_names[axis];
|
||||
|
||||
std::string transform_sid = get_transform_sid(NULL, tm_type, axis_name, false);
|
||||
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
|
||||
(char*)translate_id(bone_name).c_str(), (char*)transform_sid.c_str());
|
||||
if (!fra.size())
|
||||
return;
|
||||
|
||||
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
|
||||
(char*)translate_id(bone_name).c_str(), "pose_matrix");
|
||||
|
||||
// create input source
|
||||
std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, fra, is_rot, anim_id, axis_name);
|
||||
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
|
||||
|
||||
// create output source
|
||||
std::string output_id;
|
||||
if (axis == -1)
|
||||
output_id = create_xyz_source(values, fra.size(), anim_id);
|
||||
else
|
||||
output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, values, fra.size(), is_rot, anim_id, axis_name);
|
||||
// create input source
|
||||
std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, fra, false, anim_id, "");
|
||||
|
||||
// create interpolations source
|
||||
std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, axis_name);
|
||||
// create output source
|
||||
std::string output_id;
|
||||
output_id = create_4x4_source( fra, ob_arm , bone , anim_id);
|
||||
|
||||
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
|
||||
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
|
||||
std::string empty;
|
||||
sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
|
||||
// create interpolations source
|
||||
std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, "");
|
||||
|
||||
// TODO create in/out tangents source
|
||||
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
|
||||
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
|
||||
std::string empty;
|
||||
sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
|
||||
|
||||
// this input is required
|
||||
sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
|
||||
// TODO create in/out tangents source
|
||||
|
||||
addSampler(sampler);
|
||||
// this input is required
|
||||
sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
|
||||
|
||||
std::string target = translate_id(ob_name + "_" + bone_name) + "/" + transform_sid;
|
||||
addChannel(COLLADABU::URI(empty, sampler_id), target);
|
||||
addSampler(sampler);
|
||||
|
||||
closeAnimation();
|
||||
}
|
||||
std::string target = translate_id(bone_name) + "/transform";
|
||||
addChannel(COLLADABU::URI(empty, sampler_id), target);
|
||||
|
||||
float AnimationExporter::convert_time(float frame)
|
||||
{
|
||||
return FRA2TIME(frame);
|
||||
}
|
||||
closeAnimation();
|
||||
}
|
||||
|
||||
float AnimationExporter::convert_angle(float angle)
|
||||
{
|
||||
return COLLADABU::Math::Utils::radToDegF(angle);
|
||||
}
|
||||
// dae_bone_animation -> add_bone_animation
|
||||
// (blend this into dae_bone_animation)
|
||||
void AnimationExporter::dae_bone_animation(std::vector<float> &fra, float *values, int tm_type, int axis, std::string ob_name, std::string bone_name)
|
||||
{
|
||||
const char *axis_names[] = {"X", "Y", "Z"};
|
||||
const char *axis_name = NULL;
|
||||
char anim_id[200];
|
||||
bool is_rot = tm_type == 0;
|
||||
|
||||
std::string AnimationExporter::get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic)
|
||||
{
|
||||
switch(semantic) {
|
||||
if (!fra.size())
|
||||
return;
|
||||
|
||||
char rna_path[200];
|
||||
BLI_snprintf(rna_path, sizeof(rna_path), "pose.bones[\"%s\"].%s", bone_name.c_str(),
|
||||
tm_type == 0 ? "rotation_quaternion" : (tm_type == 1 ? "scale" : "location"));
|
||||
|
||||
if (axis > -1)
|
||||
axis_name = axis_names[axis];
|
||||
|
||||
std::string transform_sid = get_transform_sid(NULL, tm_type, axis_name, false);
|
||||
|
||||
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
|
||||
(char*)translate_id(bone_name).c_str(), (char*)transform_sid.c_str());
|
||||
|
||||
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
|
||||
|
||||
// create input source
|
||||
std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, fra, is_rot, anim_id, axis_name);
|
||||
|
||||
// create output source
|
||||
std::string output_id;
|
||||
if (axis == -1)
|
||||
output_id = create_xyz_source(values, fra.size(), anim_id);
|
||||
else
|
||||
output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, values, fra.size(), is_rot, anim_id, axis_name);
|
||||
|
||||
// create interpolations source
|
||||
std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, axis_name);
|
||||
|
||||
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
|
||||
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
|
||||
std::string empty;
|
||||
sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
|
||||
sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
|
||||
|
||||
// TODO create in/out tangents source
|
||||
|
||||
// this input is required
|
||||
sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
|
||||
|
||||
addSampler(sampler);
|
||||
|
||||
std::string target = translate_id(ob_name + "_" + bone_name) + "/" + transform_sid;
|
||||
addChannel(COLLADABU::URI(empty, sampler_id), target);
|
||||
|
||||
closeAnimation();
|
||||
}
|
||||
|
||||
float AnimationExporter::convert_time(float frame)
|
||||
{
|
||||
return FRA2TIME(frame);
|
||||
}
|
||||
|
||||
float AnimationExporter::convert_angle(float angle)
|
||||
{
|
||||
return COLLADABU::Math::Utils::radToDegF(angle);
|
||||
}
|
||||
|
||||
std::string AnimationExporter::get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic)
|
||||
{
|
||||
switch(semantic) {
|
||||
case COLLADASW::InputSemantic::INPUT:
|
||||
return INPUT_SOURCE_ID_SUFFIX;
|
||||
case COLLADASW::InputSemantic::OUTPUT:
|
||||
@@ -527,14 +527,14 @@ void AnimationExporter::operator() (Object *ob)
|
||||
return OUTTANGENT_SOURCE_ID_SUFFIX;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param,
|
||||
COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform)
|
||||
{
|
||||
switch(semantic) {
|
||||
void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param,
|
||||
COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform)
|
||||
{
|
||||
switch(semantic) {
|
||||
case COLLADASW::InputSemantic::INPUT:
|
||||
param.push_back("TIME");
|
||||
break;
|
||||
@@ -547,14 +547,14 @@ void AnimationExporter::operator() (Object *ob)
|
||||
param.push_back(axis);
|
||||
}
|
||||
else
|
||||
if ( transform )
|
||||
{
|
||||
param.push_back("TRANSFORM");
|
||||
}else{ //assumes if axis isn't specified all axises are added
|
||||
param.push_back("X");
|
||||
param.push_back("Y");
|
||||
param.push_back("Z");
|
||||
}
|
||||
if ( transform )
|
||||
{
|
||||
param.push_back("TRANSFORM");
|
||||
}else{ //assumes if axis isn't specified all axises are added
|
||||
param.push_back("X");
|
||||
param.push_back("Y");
|
||||
param.push_back("Z");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case COLLADASW::InputSemantic::IN_TANGENT:
|
||||
@@ -564,12 +564,12 @@ void AnimationExporter::operator() (Object *ob)
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length)
|
||||
{
|
||||
switch (semantic) {
|
||||
void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length)
|
||||
{
|
||||
switch (semantic) {
|
||||
case COLLADASW::InputSemantic::INPUT:
|
||||
*length = 1;
|
||||
values[0] = convert_time(bezt->vec[1][0]);
|
||||
@@ -583,9 +583,9 @@ void AnimationExporter::operator() (Object *ob)
|
||||
values[0] = bezt->vec[1][1];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case COLLADASW::InputSemantic::IN_TANGENT:
|
||||
*length = 2;
|
||||
*length = 2;
|
||||
values[0] = convert_time(bezt->vec[0][0]);
|
||||
if (bezt->ipo != BEZT_IPO_BEZ) {
|
||||
// We're in a mixed interpolation scenario, set zero as it's irrelevant but value might contain unused data
|
||||
@@ -598,7 +598,7 @@ void AnimationExporter::operator() (Object *ob)
|
||||
values[1] = bezt->vec[0][1];
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case COLLADASW::InputSemantic::OUT_TANGENT:
|
||||
*length = 2;
|
||||
values[0] = convert_time(bezt->vec[2][0]);
|
||||
@@ -617,283 +617,283 @@ void AnimationExporter::operator() (Object *ob)
|
||||
default:
|
||||
*length = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
|
||||
//bool is_rotation = !strcmp(fcu->rna_path, "rotation");
|
||||
bool is_angle = false;
|
||||
|
||||
if (strstr(fcu->rna_path, "rotation")) is_angle = true;
|
||||
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(fcu->totvert);
|
||||
|
||||
switch (semantic) {
|
||||
//bool is_rotation = !strcmp(fcu->rna_path, "rotation");
|
||||
bool is_angle = false;
|
||||
|
||||
if (strstr(fcu->rna_path, "rotation")) is_angle = true;
|
||||
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(fcu->totvert);
|
||||
|
||||
switch (semantic) {
|
||||
case COLLADASW::InputSemantic::INPUT:
|
||||
case COLLADASW::InputSemantic::OUTPUT:
|
||||
source.setAccessorStride(1);
|
||||
source.setAccessorStride(1);
|
||||
break;
|
||||
case COLLADASW::InputSemantic::IN_TANGENT:
|
||||
case COLLADASW::InputSemantic::OUT_TANGENT:
|
||||
source.setAccessorStride(2);
|
||||
source.setAccessorStride(2);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, is_angle, axis_name, false);
|
||||
|
||||
source.prepareToAppendValues();
|
||||
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
float values[3]; // be careful!
|
||||
int length = 0;
|
||||
get_source_values(&fcu->bezt[i], semantic, is_angle, values, &length);
|
||||
for (int j = 0; j < length; j++)
|
||||
source.appendValues(values[j]);
|
||||
}
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
}
|
||||
|
||||
//Currently called only to get OUTPUT source values ( if rotation and hence the axis is also specified )
|
||||
std::string AnimationExporter::create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(tot);
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, is_rot, axis_name, false);
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, is_angle, axis_name, false);
|
||||
|
||||
source.prepareToAppendValues();
|
||||
source.prepareToAppendValues();
|
||||
|
||||
for (int i = 0; i < tot; i++) {
|
||||
float val = v[i];
|
||||
////if (semantic == COLLADASW::InputSemantic::INPUT)
|
||||
// val = convert_time(val);
|
||||
//else
|
||||
if (is_rot)
|
||||
val *= 180.0f / M_PI;
|
||||
source.appendValues(val);
|
||||
}
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
float values[3]; // be careful!
|
||||
int length = 0;
|
||||
get_source_values(&fcu->bezt[i], semantic, is_angle, values, &length);
|
||||
for (int j = 0; j < length; j++)
|
||||
source.appendValues(values[j]);
|
||||
}
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
}
|
||||
|
||||
//Currently called only to get OUTPUT source values ( if rotation and hence the axis is also specified )
|
||||
std::string AnimationExporter::create_source_from_array(COLLADASW::InputSemantic::Semantics semantic, float *v, int tot, bool is_rot, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(tot);
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, is_rot, axis_name, false);
|
||||
|
||||
source.prepareToAppendValues();
|
||||
|
||||
for (int i = 0; i < tot; i++) {
|
||||
float val = v[i];
|
||||
////if (semantic == COLLADASW::InputSemantic::INPUT)
|
||||
// val = convert_time(val);
|
||||
//else
|
||||
if (is_rot)
|
||||
val *= 180.0f / M_PI;
|
||||
source.appendValues(val);
|
||||
}
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
}
|
||||
// only used for sources with INPUT semantic
|
||||
std::string AnimationExporter::create_source_from_vector(COLLADASW::InputSemantic::Semantics semantic, std::vector<float> &fra, bool is_rot, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
std::string AnimationExporter::create_source_from_vector(COLLADASW::InputSemantic::Semantics semantic, std::vector<float> &fra, bool is_rot, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(fra.size());
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, is_rot, axis_name, false);
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(fra.size());
|
||||
source.setAccessorStride(1);
|
||||
|
||||
source.prepareToAppendValues();
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, is_rot, axis_name, false);
|
||||
|
||||
std::vector<float>::iterator it;
|
||||
for (it = fra.begin(); it != fra.end(); it++) {
|
||||
float val = *it;
|
||||
//if (semantic == COLLADASW::InputSemantic::INPUT)
|
||||
val = convert_time(val);
|
||||
/*else if (is_rot)
|
||||
val = convert_angle(val);*/
|
||||
source.appendValues(val);
|
||||
}
|
||||
source.prepareToAppendValues();
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
std::vector<float>::iterator it;
|
||||
for (it = fra.begin(); it != fra.end(); it++) {
|
||||
float val = *it;
|
||||
//if (semantic == COLLADASW::InputSemantic::INPUT)
|
||||
val = convert_time(val);
|
||||
/*else if (is_rot)
|
||||
val = convert_angle(val);*/
|
||||
source.appendValues(val);
|
||||
}
|
||||
|
||||
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames , Object * ob_arm, Bone *bone , const std::string& anim_id)
|
||||
{
|
||||
COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
source.finish();
|
||||
|
||||
COLLADASW::Float4x4Source source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(frames.size());
|
||||
source.setAccessorStride(16);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, false, NULL, true);
|
||||
return source_id;
|
||||
}
|
||||
|
||||
source.prepareToAppendValues();
|
||||
|
||||
bPoseChannel *parchan = NULL;
|
||||
bPoseChannel *pchan = NULL;
|
||||
bPose *pose = ob_arm->pose;
|
||||
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames , Object * ob_arm, Bone *bone , const std::string& anim_id)
|
||||
{
|
||||
COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
|
||||
pchan = get_pose_channel(pose, bone->name);
|
||||
COLLADASW::Float4x4Source source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(frames.size());
|
||||
source.setAccessorStride(16);
|
||||
|
||||
if (!pchan)
|
||||
return "";
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, false, NULL, true);
|
||||
|
||||
parchan = pchan->parent;
|
||||
source.prepareToAppendValues();
|
||||
|
||||
enable_fcurves(ob_arm->adt->action, bone->name);
|
||||
bPoseChannel *parchan = NULL;
|
||||
bPoseChannel *pchan = NULL;
|
||||
bPose *pose = ob_arm->pose;
|
||||
|
||||
std::vector<float>::iterator it;
|
||||
int j = 0;
|
||||
for (it = frames.begin(); it != frames.end(); it++) {
|
||||
float mat[4][4], ipar[4][4];
|
||||
pchan = get_pose_channel(pose, bone->name);
|
||||
|
||||
float ctime = bsystem_time(scene, ob_arm, *it, 0.0f);
|
||||
if (!pchan)
|
||||
return "";
|
||||
|
||||
BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
|
||||
where_is_pose_bone(scene, ob_arm, pchan, ctime, 1);
|
||||
parchan = pchan->parent;
|
||||
|
||||
// compute bone local mat
|
||||
if (bone->parent) {
|
||||
invert_m4_m4(ipar, parchan->pose_mat);
|
||||
mul_m4_m4m4(mat, pchan->pose_mat, ipar);
|
||||
}
|
||||
else
|
||||
copy_m4_m4(mat, pchan->pose_mat);
|
||||
UnitConverter converter;
|
||||
enable_fcurves(ob_arm->adt->action, bone->name);
|
||||
|
||||
float outmat[4][4];
|
||||
converter.mat4_to_dae(outmat,mat);
|
||||
std::vector<float>::iterator it;
|
||||
int j = 0;
|
||||
for (it = frames.begin(); it != frames.end(); it++) {
|
||||
float mat[4][4], ipar[4][4];
|
||||
|
||||
float ctime = bsystem_time(scene, ob_arm, *it, 0.0f);
|
||||
|
||||
source.appendValues(outmat);
|
||||
|
||||
BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
|
||||
where_is_pose_bone(scene, ob_arm, pchan, ctime, 1);
|
||||
|
||||
j++;
|
||||
// compute bone local mat
|
||||
if (bone->parent) {
|
||||
invert_m4_m4(ipar, parchan->pose_mat);
|
||||
mul_m4_m4m4(mat, pchan->pose_mat, ipar);
|
||||
}
|
||||
else
|
||||
copy_m4_m4(mat, pchan->pose_mat);
|
||||
UnitConverter converter;
|
||||
|
||||
enable_fcurves(ob_arm->adt->action, NULL);
|
||||
float outmat[4][4];
|
||||
converter.mat4_to_dae(outmat,mat);
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
}
|
||||
// only used for sources with OUTPUT semantic ( locations and scale)
|
||||
std::string AnimationExporter::create_xyz_source(float *v, int tot, const std::string& anim_id)
|
||||
{
|
||||
COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
source.appendValues(outmat);
|
||||
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(tot);
|
||||
source.setAccessorStride(3);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, false, NULL, false);
|
||||
|
||||
source.prepareToAppendValues();
|
||||
|
||||
for (int i = 0; i < tot; i++) {
|
||||
source.appendValues(*v, *(v + 1), *(v + 2));
|
||||
v += 3;
|
||||
}
|
||||
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
j++;
|
||||
}
|
||||
|
||||
std::string AnimationExporter::create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
|
||||
enable_fcurves(ob_arm->adt->action, NULL);
|
||||
|
||||
COLLADASW::NameSource source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(fcu->totvert);
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
param.push_back("INTERPOLATION");
|
||||
source.finish();
|
||||
|
||||
source.prepareToAppendValues();
|
||||
return source_id;
|
||||
}
|
||||
// only used for sources with OUTPUT semantic ( locations and scale)
|
||||
std::string AnimationExporter::create_xyz_source(float *v, int tot, const std::string& anim_id)
|
||||
{
|
||||
COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
|
||||
std::string source_id = anim_id + get_semantic_suffix(semantic);
|
||||
|
||||
*has_tangents = false;
|
||||
COLLADASW::FloatSourceF source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(tot);
|
||||
source.setAccessorStride(3);
|
||||
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
if (fcu->bezt[i].ipo==BEZT_IPO_BEZ) {
|
||||
source.appendValues(BEZIER_NAME);
|
||||
*has_tangents = true;
|
||||
} else if (fcu->bezt[i].ipo==BEZT_IPO_CONST) {
|
||||
source.appendValues(STEP_NAME);
|
||||
} else { // BEZT_IPO_LIN
|
||||
source.appendValues(LINEAR_NAME);
|
||||
}
|
||||
}
|
||||
// unsupported? -- HERMITE, CARDINAL, BSPLINE, NURBS
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
add_source_parameters(param, semantic, false, NULL, false);
|
||||
|
||||
source.finish();
|
||||
source.prepareToAppendValues();
|
||||
|
||||
return source_id;
|
||||
for (int i = 0; i < tot; i++) {
|
||||
source.appendValues(*v, *(v + 1), *(v + 2));
|
||||
v += 3;
|
||||
}
|
||||
|
||||
std::string AnimationExporter::fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
|
||||
source.finish();
|
||||
|
||||
COLLADASW::NameSource source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(tot);
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
param.push_back("INTERPOLATION");
|
||||
return source_id;
|
||||
}
|
||||
|
||||
source.prepareToAppendValues();
|
||||
std::string AnimationExporter::create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
|
||||
|
||||
for (int i = 0; i < tot; i++) {
|
||||
COLLADASW::NameSource source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(fcu->totvert);
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
param.push_back("INTERPOLATION");
|
||||
|
||||
source.prepareToAppendValues();
|
||||
|
||||
*has_tangents = false;
|
||||
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
if (fcu->bezt[i].ipo==BEZT_IPO_BEZ) {
|
||||
source.appendValues(BEZIER_NAME);
|
||||
*has_tangents = true;
|
||||
} else if (fcu->bezt[i].ipo==BEZT_IPO_CONST) {
|
||||
source.appendValues(STEP_NAME);
|
||||
} else { // BEZT_IPO_LIN
|
||||
source.appendValues(LINEAR_NAME);
|
||||
}
|
||||
}
|
||||
// unsupported? -- HERMITE, CARDINAL, BSPLINE, NURBS
|
||||
|
||||
source.finish();
|
||||
source.finish();
|
||||
|
||||
return source_id;
|
||||
return source_id;
|
||||
}
|
||||
|
||||
std::string AnimationExporter::fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name)
|
||||
{
|
||||
std::string source_id = anim_id + get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
|
||||
|
||||
COLLADASW::NameSource source(mSW);
|
||||
source.setId(source_id);
|
||||
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
|
||||
source.setAccessorCount(tot);
|
||||
source.setAccessorStride(1);
|
||||
|
||||
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
|
||||
param.push_back("INTERPOLATION");
|
||||
|
||||
source.prepareToAppendValues();
|
||||
|
||||
for (int i = 0; i < tot; i++) {
|
||||
source.appendValues(LINEAR_NAME);
|
||||
}
|
||||
|
||||
std::string AnimationExporter::get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
|
||||
{
|
||||
std::string tm_name;
|
||||
// when given rna_path, determine tm_type from it
|
||||
if (rna_path) {
|
||||
char *name = extract_transform_name(rna_path);
|
||||
source.finish();
|
||||
|
||||
if (!strcmp(name, "color"))
|
||||
tm_type = 1;
|
||||
else if (!strcmp(name, "spot_size"))
|
||||
tm_type = 2;
|
||||
else if (!strcmp(name, "spot_blend"))
|
||||
tm_type = 3;
|
||||
else if (!strcmp(name, "distance"))
|
||||
tm_type = 4;
|
||||
else
|
||||
tm_type = -1;
|
||||
}
|
||||
return source_id;
|
||||
}
|
||||
|
||||
switch (tm_type) {
|
||||
std::string AnimationExporter::get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
|
||||
{
|
||||
std::string tm_name;
|
||||
// when given rna_path, determine tm_type from it
|
||||
if (rna_path) {
|
||||
char *name = extract_transform_name(rna_path);
|
||||
|
||||
if (!strcmp(name, "color"))
|
||||
tm_type = 1;
|
||||
else if (!strcmp(name, "spot_size"))
|
||||
tm_type = 2;
|
||||
else if (!strcmp(name, "spot_blend"))
|
||||
tm_type = 3;
|
||||
else if (!strcmp(name, "distance"))
|
||||
tm_type = 4;
|
||||
else
|
||||
tm_type = -1;
|
||||
}
|
||||
|
||||
switch (tm_type) {
|
||||
case 1:
|
||||
tm_name = "color";
|
||||
break;
|
||||
@@ -906,43 +906,43 @@ void AnimationExporter::operator() (Object *ob)
|
||||
case 4:
|
||||
tm_name = "blender/blender_dist";
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
tm_name = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (tm_name.size()) {
|
||||
if (axis_name != "")
|
||||
return tm_name + "." + std::string(axis_name);
|
||||
else
|
||||
return tm_name;
|
||||
}
|
||||
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
|
||||
{
|
||||
std::string tm_name;
|
||||
// when given rna_path, determine tm_type from it
|
||||
if (rna_path) {
|
||||
char *name = extract_transform_name(rna_path);
|
||||
|
||||
if (!strcmp(name, "lens"))
|
||||
tm_type = 0;
|
||||
else if (!strcmp(name, "ortho_scale"))
|
||||
tm_type = 1;
|
||||
else if (!strcmp(name, "clip_end"))
|
||||
tm_type = 2;
|
||||
else if (!strcmp(name, "clip_start"))
|
||||
tm_type = 3;
|
||||
|
||||
else
|
||||
tm_type = -1;
|
||||
}
|
||||
if (tm_name.size()) {
|
||||
if (axis_name != "")
|
||||
return tm_name + "." + std::string(axis_name);
|
||||
else
|
||||
return tm_name;
|
||||
}
|
||||
|
||||
switch (tm_type) {
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
|
||||
{
|
||||
std::string tm_name;
|
||||
// when given rna_path, determine tm_type from it
|
||||
if (rna_path) {
|
||||
char *name = extract_transform_name(rna_path);
|
||||
|
||||
if (!strcmp(name, "lens"))
|
||||
tm_type = 0;
|
||||
else if (!strcmp(name, "ortho_scale"))
|
||||
tm_type = 1;
|
||||
else if (!strcmp(name, "clip_end"))
|
||||
tm_type = 2;
|
||||
else if (!strcmp(name, "clip_start"))
|
||||
tm_type = 3;
|
||||
|
||||
else
|
||||
tm_type = -1;
|
||||
}
|
||||
|
||||
switch (tm_type) {
|
||||
case 0:
|
||||
tm_name = "xfov";
|
||||
break;
|
||||
@@ -955,56 +955,56 @@ void AnimationExporter::operator() (Object *ob)
|
||||
case 3:
|
||||
tm_name = "znear";
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
tm_name = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (tm_name.size()) {
|
||||
if (axis_name != "")
|
||||
return tm_name + "." + std::string(axis_name);
|
||||
else
|
||||
return tm_name;
|
||||
}
|
||||
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
// Assign sid of the animated parameter or transform
|
||||
// for rotation, axis name is always appended and the value of append_axis is ignored
|
||||
std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
|
||||
{
|
||||
std::string tm_name;
|
||||
bool is_rotation =false;
|
||||
// when given rna_path, determine tm_type from it
|
||||
if (rna_path) {
|
||||
char *name = extract_transform_name(rna_path);
|
||||
if (tm_name.size()) {
|
||||
if (axis_name != "")
|
||||
return tm_name + "." + std::string(axis_name);
|
||||
else
|
||||
return tm_name;
|
||||
}
|
||||
|
||||
if (!strcmp(name, "rotation_euler"))
|
||||
tm_type = 0;
|
||||
else if (!strcmp(name, "rotation_quaternion"))
|
||||
tm_type = 1;
|
||||
else if (!strcmp(name, "scale"))
|
||||
tm_type = 2;
|
||||
else if (!strcmp(name, "location"))
|
||||
tm_type = 3;
|
||||
else if (!strcmp(name, "specular_hardness"))
|
||||
tm_type = 4;
|
||||
else if (!strcmp(name, "specular_color"))
|
||||
tm_type = 5;
|
||||
else if (!strcmp(name, "diffuse_color"))
|
||||
tm_type = 6;
|
||||
else if (!strcmp(name, "alpha"))
|
||||
tm_type = 7;
|
||||
else if (!strcmp(name, "ior"))
|
||||
tm_type = 8;
|
||||
|
||||
else
|
||||
tm_type = -1;
|
||||
}
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
switch (tm_type) {
|
||||
// Assign sid of the animated parameter or transform
|
||||
// for rotation, axis name is always appended and the value of append_axis is ignored
|
||||
std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
|
||||
{
|
||||
std::string tm_name;
|
||||
bool is_rotation =false;
|
||||
// when given rna_path, determine tm_type from it
|
||||
if (rna_path) {
|
||||
char *name = extract_transform_name(rna_path);
|
||||
|
||||
if (!strcmp(name, "rotation_euler"))
|
||||
tm_type = 0;
|
||||
else if (!strcmp(name, "rotation_quaternion"))
|
||||
tm_type = 1;
|
||||
else if (!strcmp(name, "scale"))
|
||||
tm_type = 2;
|
||||
else if (!strcmp(name, "location"))
|
||||
tm_type = 3;
|
||||
else if (!strcmp(name, "specular_hardness"))
|
||||
tm_type = 4;
|
||||
else if (!strcmp(name, "specular_color"))
|
||||
tm_type = 5;
|
||||
else if (!strcmp(name, "diffuse_color"))
|
||||
tm_type = 6;
|
||||
else if (!strcmp(name, "alpha"))
|
||||
tm_type = 7;
|
||||
else if (!strcmp(name, "ior"))
|
||||
tm_type = 8;
|
||||
|
||||
else
|
||||
tm_type = -1;
|
||||
}
|
||||
|
||||
switch (tm_type) {
|
||||
case 0:
|
||||
case 1:
|
||||
tm_name = "rotation";
|
||||
@@ -1031,173 +1031,173 @@ void AnimationExporter::operator() (Object *ob)
|
||||
case 8:
|
||||
tm_name = "index_of_refraction";
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
tm_name = "";
|
||||
break;
|
||||
}
|
||||
|
||||
if (tm_name.size()) {
|
||||
if (is_rotation)
|
||||
return tm_name + std::string(axis_name) + ".ANGLE";
|
||||
else
|
||||
if (axis_name != "")
|
||||
return tm_name + "." + std::string(axis_name);
|
||||
else
|
||||
return tm_name;
|
||||
}
|
||||
|
||||
return std::string("");
|
||||
}
|
||||
|
||||
char* AnimationExporter::extract_transform_name(char *rna_path)
|
||||
{
|
||||
char *dot = strrchr(rna_path, '.');
|
||||
return dot ? (dot + 1) : rna_path;
|
||||
}
|
||||
|
||||
//find keyframes of all the objects animations
|
||||
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra)
|
||||
{
|
||||
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
|
||||
|
||||
for (; fcu; fcu = fcu->next) {
|
||||
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
float f = fcu->bezt[i].vec[1][0];
|
||||
if (std::find(fra.begin(), fra.end(), f) == fra.end())
|
||||
fra.push_back(f);
|
||||
}
|
||||
|
||||
if (tm_name.size()) {
|
||||
if (is_rotation)
|
||||
return tm_name + std::string(axis_name) + ".ANGLE";
|
||||
}
|
||||
|
||||
// keep the keys in ascending order
|
||||
std::sort(fra.begin(), fra.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// enable fcurves driving a specific bone, disable all the rest
|
||||
// if bone_name = NULL enable all fcurves
|
||||
void AnimationExporter::enable_fcurves(bAction *act, char *bone_name)
|
||||
{
|
||||
FCurve *fcu;
|
||||
char prefix[200];
|
||||
|
||||
if (bone_name)
|
||||
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
|
||||
|
||||
for (fcu = (FCurve*)act->curves.first; fcu; fcu = fcu->next) {
|
||||
if (bone_name) {
|
||||
if (!strncmp(fcu->rna_path, prefix, strlen(prefix)))
|
||||
fcu->flag &= ~FCURVE_DISABLED;
|
||||
else
|
||||
if (axis_name != "")
|
||||
return tm_name + "." + std::string(axis_name);
|
||||
else
|
||||
return tm_name;
|
||||
fcu->flag |= FCURVE_DISABLED;
|
||||
}
|
||||
else {
|
||||
fcu->flag &= ~FCURVE_DISABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AnimationExporter::hasAnimations(Scene *sce)
|
||||
{
|
||||
Base *base= (Base*) sce->base.first;
|
||||
|
||||
while(base) {
|
||||
Object *ob = base->object;
|
||||
|
||||
FCurve *fcu = 0;
|
||||
//Check for object transform animations
|
||||
if(ob->adt && ob->adt->action)
|
||||
fcu = (FCurve*)ob->adt->action->curves.first;
|
||||
//Check for Lamp parameter animations
|
||||
else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
|
||||
fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
|
||||
//Check for Camera parameter animations
|
||||
else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
|
||||
fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
|
||||
|
||||
//Check Material Effect parameter animations.
|
||||
for(int a = 0; a < ob->totcol; a++)
|
||||
{
|
||||
Material *ma = give_current_material(ob, a+1);
|
||||
if (!ma) continue;
|
||||
if(ma->adt && ma->adt->action)
|
||||
{
|
||||
fcu = (FCurve*)ma->adt->action->curves.first;
|
||||
}
|
||||
}
|
||||
|
||||
return std::string("");
|
||||
if ( fcu)
|
||||
return true;
|
||||
base= base->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
char* AnimationExporter::extract_transform_name(char *rna_path)
|
||||
{
|
||||
char *dot = strrchr(rna_path, '.');
|
||||
return dot ? (dot + 1) : rna_path;
|
||||
}
|
||||
//------------------------------- Not used in the new system.--------------------------------------------------------
|
||||
void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
|
||||
{
|
||||
if (rotmode > 0)
|
||||
find_frames(ob, fra, prefix, "rotation_euler");
|
||||
else if (rotmode == ROT_MODE_QUAT)
|
||||
find_frames(ob, fra, prefix, "rotation_quaternion");
|
||||
/*else if (rotmode == ROT_MODE_AXISANGLE)
|
||||
;*/
|
||||
}
|
||||
|
||||
//find keyframes of all the objects animations
|
||||
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra)
|
||||
{
|
||||
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
|
||||
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
|
||||
{
|
||||
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
|
||||
|
||||
for (; fcu; fcu = fcu->next) {
|
||||
|
||||
for (; fcu; fcu = fcu->next) {
|
||||
if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
|
||||
continue;
|
||||
|
||||
char *name = extract_transform_name(fcu->rna_path);
|
||||
if (!strcmp(name, tm_name)) {
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
float f = fcu->bezt[i].vec[1][0]; //
|
||||
float f = fcu->bezt[i].vec[1][0];
|
||||
if (std::find(fra.begin(), fra.end(), f) == fra.end())
|
||||
fra.push_back(f);
|
||||
}
|
||||
}
|
||||
|
||||
// keep the keys in ascending order
|
||||
std::sort(fra.begin(), fra.end());
|
||||
}
|
||||
|
||||
|
||||
// keep the keys in ascending order
|
||||
std::sort(fra.begin(), fra.end());
|
||||
}
|
||||
|
||||
// enable fcurves driving a specific bone, disable all the rest
|
||||
// if bone_name = NULL enable all fcurves
|
||||
void AnimationExporter::enable_fcurves(bAction *act, char *bone_name)
|
||||
{
|
||||
FCurve *fcu;
|
||||
char prefix[200];
|
||||
void AnimationExporter::write_bone_animation(Object *ob_arm, Bone *bone)
|
||||
{
|
||||
if (!ob_arm->adt)
|
||||
return;
|
||||
|
||||
if (bone_name)
|
||||
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
|
||||
//write bone animations for 3 transform types
|
||||
//i=0 --> rotations
|
||||
//i=1 --> scale
|
||||
//i=2 --> location
|
||||
for (int i = 0; i < 3; i++)
|
||||
sample_and_write_bone_animation(ob_arm, bone, i);
|
||||
|
||||
for (fcu = (FCurve*)act->curves.first; fcu; fcu = fcu->next) {
|
||||
if (bone_name) {
|
||||
if (!strncmp(fcu->rna_path, prefix, strlen(prefix)))
|
||||
fcu->flag &= ~FCURVE_DISABLED;
|
||||
else
|
||||
fcu->flag |= FCURVE_DISABLED;
|
||||
}
|
||||
else {
|
||||
fcu->flag &= ~FCURVE_DISABLED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool AnimationExporter::hasAnimations(Scene *sce)
|
||||
{
|
||||
Base *base= (Base*) sce->base.first;
|
||||
|
||||
while(base) {
|
||||
Object *ob = base->object;
|
||||
|
||||
FCurve *fcu = 0;
|
||||
//Check for object transform animations
|
||||
if(ob->adt && ob->adt->action)
|
||||
fcu = (FCurve*)ob->adt->action->curves.first;
|
||||
//Check for Lamp parameter animations
|
||||
else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
|
||||
fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
|
||||
//Check for Camera parameter animations
|
||||
else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
|
||||
fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
|
||||
|
||||
//Check Material Effect parameter animations.
|
||||
for(int a = 0; a < ob->totcol; a++)
|
||||
{
|
||||
Material *ma = give_current_material(ob, a+1);
|
||||
if (!ma) continue;
|
||||
if(ma->adt && ma->adt->action)
|
||||
{
|
||||
fcu = (FCurve*)ma->adt->action->curves.first;
|
||||
}
|
||||
}
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
|
||||
write_bone_animation(ob_arm, child);
|
||||
}
|
||||
|
||||
if ( fcu)
|
||||
return true;
|
||||
base= base->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type)
|
||||
{
|
||||
bArmature *arm = (bArmature*)ob_arm->data;
|
||||
int flag = arm->flag;
|
||||
std::vector<float> fra;
|
||||
char prefix[256];
|
||||
|
||||
//------------------------------- Not used in the new system.--------------------------------------------------------
|
||||
void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
|
||||
{
|
||||
if (rotmode > 0)
|
||||
find_frames(ob, fra, prefix, "rotation_euler");
|
||||
else if (rotmode == ROT_MODE_QUAT)
|
||||
find_frames(ob, fra, prefix, "rotation_quaternion");
|
||||
/*else if (rotmode == ROT_MODE_AXISANGLE)
|
||||
;*/
|
||||
}
|
||||
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name);
|
||||
|
||||
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
|
||||
{
|
||||
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
|
||||
|
||||
for (; fcu; fcu = fcu->next) {
|
||||
if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
|
||||
continue;
|
||||
|
||||
char *name = extract_transform_name(fcu->rna_path);
|
||||
if (!strcmp(name, tm_name)) {
|
||||
for (unsigned int i = 0; i < fcu->totvert; i++) {
|
||||
float f = fcu->bezt[i].vec[1][0]; //
|
||||
if (std::find(fra.begin(), fra.end(), f) == fra.end())
|
||||
fra.push_back(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// keep the keys in ascending order
|
||||
std::sort(fra.begin(), fra.end());
|
||||
}
|
||||
|
||||
void AnimationExporter::write_bone_animation(Object *ob_arm, Bone *bone)
|
||||
{
|
||||
if (!ob_arm->adt)
|
||||
return;
|
||||
|
||||
//write bone animations for 3 transform types
|
||||
//i=0 --> rotations
|
||||
//i=1 --> scale
|
||||
//i=2 --> location
|
||||
for (int i = 0; i < 3; i++)
|
||||
sample_and_write_bone_animation(ob_arm, bone, i);
|
||||
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
|
||||
write_bone_animation(ob_arm, child);
|
||||
}
|
||||
|
||||
void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type)
|
||||
{
|
||||
bArmature *arm = (bArmature*)ob_arm->data;
|
||||
int flag = arm->flag;
|
||||
std::vector<float> fra;
|
||||
char prefix[256];
|
||||
|
||||
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name);
|
||||
|
||||
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
|
||||
if (!pchan)
|
||||
return;
|
||||
//Fill frame array with key frame values framed at @param:transform_type
|
||||
switch (transform_type) {
|
||||
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
|
||||
if (!pchan)
|
||||
return;
|
||||
//Fill frame array with key frame values framed at @param:transform_type
|
||||
switch (transform_type) {
|
||||
case 0:
|
||||
find_rotation_frames(ob_arm, fra, prefix, pchan->rotmode);
|
||||
break;
|
||||
@@ -1209,77 +1209,77 @@ void AnimationExporter::operator() (Object *ob)
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
// exit rest position
|
||||
if (flag & ARM_RESTPOS) {
|
||||
arm->flag &= ~ARM_RESTPOS;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
//v array will hold all values which will be exported.
|
||||
if (fra.size()) {
|
||||
float *values = (float*)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames");
|
||||
sample_animation(values, fra, transform_type, bone, ob_arm, pchan);
|
||||
|
||||
if (transform_type == 0) {
|
||||
// write x, y, z curves separately if it is rotation
|
||||
float *axisValues = (float*)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (unsigned int j = 0; j < fra.size(); j++)
|
||||
axisValues[j] = values[j * 3 + i];
|
||||
|
||||
dae_bone_animation(fra, axisValues, transform_type, i, id_name(ob_arm), bone->name);
|
||||
}
|
||||
MEM_freeN(axisValues);
|
||||
}
|
||||
else {
|
||||
// write xyz at once if it is location or scale
|
||||
dae_bone_animation(fra, values, transform_type, -1, id_name(ob_arm), bone->name);
|
||||
}
|
||||
|
||||
MEM_freeN(values);
|
||||
}
|
||||
|
||||
// restore restpos
|
||||
if (flag & ARM_RESTPOS)
|
||||
arm->flag = flag;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
|
||||
void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan)
|
||||
{
|
||||
bPoseChannel *parchan = NULL;
|
||||
bPose *pose = ob_arm->pose;
|
||||
// exit rest position
|
||||
if (flag & ARM_RESTPOS) {
|
||||
arm->flag &= ~ARM_RESTPOS;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
//v array will hold all values which will be exported.
|
||||
if (fra.size()) {
|
||||
float *values = (float*)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames");
|
||||
sample_animation(values, fra, transform_type, bone, ob_arm, pchan);
|
||||
|
||||
pchan = get_pose_channel(pose, bone->name);
|
||||
if (transform_type == 0) {
|
||||
// write x, y, z curves separately if it is rotation
|
||||
float *axisValues = (float*)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");
|
||||
|
||||
if (!pchan)
|
||||
return;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (unsigned int j = 0; j < fra.size(); j++)
|
||||
axisValues[j] = values[j * 3 + i];
|
||||
|
||||
parchan = pchan->parent;
|
||||
|
||||
enable_fcurves(ob_arm->adt->action, bone->name);
|
||||
|
||||
std::vector<float>::iterator it;
|
||||
for (it = frames.begin(); it != frames.end(); it++) {
|
||||
float mat[4][4], ipar[4][4];
|
||||
|
||||
float ctime = bsystem_time(scene, ob_arm, *it, 0.0f);
|
||||
|
||||
|
||||
BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
|
||||
where_is_pose_bone(scene, ob_arm, pchan, ctime, 1);
|
||||
|
||||
// compute bone local mat
|
||||
if (bone->parent) {
|
||||
invert_m4_m4(ipar, parchan->pose_mat);
|
||||
mul_m4_m4m4(mat, pchan->pose_mat, ipar);
|
||||
dae_bone_animation(fra, axisValues, transform_type, i, id_name(ob_arm), bone->name);
|
||||
}
|
||||
else
|
||||
copy_m4_m4(mat, pchan->pose_mat);
|
||||
MEM_freeN(axisValues);
|
||||
}
|
||||
else {
|
||||
// write xyz at once if it is location or scale
|
||||
dae_bone_animation(fra, values, transform_type, -1, id_name(ob_arm), bone->name);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
MEM_freeN(values);
|
||||
}
|
||||
|
||||
// restore restpos
|
||||
if (flag & ARM_RESTPOS)
|
||||
arm->flag = flag;
|
||||
where_is_pose(scene, ob_arm);
|
||||
}
|
||||
|
||||
void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan)
|
||||
{
|
||||
bPoseChannel *parchan = NULL;
|
||||
bPose *pose = ob_arm->pose;
|
||||
|
||||
pchan = get_pose_channel(pose, bone->name);
|
||||
|
||||
if (!pchan)
|
||||
return;
|
||||
|
||||
parchan = pchan->parent;
|
||||
|
||||
enable_fcurves(ob_arm->adt->action, bone->name);
|
||||
|
||||
std::vector<float>::iterator it;
|
||||
for (it = frames.begin(); it != frames.end(); it++) {
|
||||
float mat[4][4], ipar[4][4];
|
||||
|
||||
float ctime = bsystem_time(scene, ob_arm, *it, 0.0f);
|
||||
|
||||
|
||||
BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
|
||||
where_is_pose_bone(scene, ob_arm, pchan, ctime, 1);
|
||||
|
||||
// compute bone local mat
|
||||
if (bone->parent) {
|
||||
invert_m4_m4(ipar, parchan->pose_mat);
|
||||
mul_m4_m4m4(mat, pchan->pose_mat, ipar);
|
||||
}
|
||||
else
|
||||
copy_m4_m4(mat, pchan->pose_mat);
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
mat4_to_eul(v, mat);
|
||||
break;
|
||||
@@ -1289,12 +1289,10 @@ void AnimationExporter::operator() (Object *ob)
|
||||
case 2:
|
||||
copy_v3_v3(v, mat[3]);
|
||||
break;
|
||||
}
|
||||
|
||||
v += 3;
|
||||
}
|
||||
|
||||
enable_fcurves(ob_arm->adt->action, NULL);
|
||||
v += 3;
|
||||
}
|
||||
|
||||
|
||||
enable_fcurves(ob_arm->adt->action, NULL);
|
||||
}
|
||||
|
||||
@@ -89,17 +89,17 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
|
||||
{
|
||||
COLLADAFW::FloatOrDoubleArray& input = curve->getInputValues();
|
||||
COLLADAFW::FloatOrDoubleArray& output = curve->getOutputValues();
|
||||
|
||||
|
||||
if( curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ||
|
||||
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP ) {
|
||||
COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
|
||||
COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
|
||||
COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
|
||||
COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
|
||||
}
|
||||
|
||||
float fps = (float)FPS;
|
||||
size_t dim = curve->getOutDimension();
|
||||
unsigned int i;
|
||||
|
||||
|
||||
std::vector<FCurve*>& fcurves = curve_map[curve->getUniqueId()];
|
||||
|
||||
switch (dim) {
|
||||
@@ -110,18 +110,18 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
|
||||
{
|
||||
for (i = 0; i < dim; i++ ) {
|
||||
FCurve *fcu = (FCurve*)MEM_callocN(sizeof(FCurve), "FCurve");
|
||||
|
||||
|
||||
fcu->flag = (FCURVE_VISIBLE|FCURVE_AUTO_HANDLES|FCURVE_SELECTED);
|
||||
// fcu->rna_path = BLI_strdupn(path, strlen(path));
|
||||
fcu->array_index = 0;
|
||||
fcu->totvert = curve->getKeyCount();
|
||||
|
||||
|
||||
// create beztriple for each key
|
||||
for (unsigned int j = 0; j < curve->getKeyCount(); j++) {
|
||||
BezTriple bez;
|
||||
memset(&bez, 0, sizeof(BezTriple));
|
||||
|
||||
|
||||
|
||||
// input, output
|
||||
bez.vec[1][0] = bc_get_float_value(input, j) * fps;
|
||||
bez.vec[1][1] = bc_get_float_value(output, j * dim + i);
|
||||
@@ -131,20 +131,20 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
|
||||
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP)
|
||||
{
|
||||
COLLADAFW::FloatOrDoubleArray& intan = curve->getInTangentValues();
|
||||
COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
|
||||
COLLADAFW::FloatOrDoubleArray& outtan = curve->getOutTangentValues();
|
||||
|
||||
// intangent
|
||||
bez.vec[0][0] = bc_get_float_value(intan, (j * 2 * dim ) + (2 * i)) * fps;
|
||||
bez.vec[0][1] = bc_get_float_value(intan, (j * 2 * dim )+ (2 * i) + 1);
|
||||
bez.vec[0][0] = bc_get_float_value(intan, (j * 2 * dim ) + (2 * i)) * fps;
|
||||
bez.vec[0][1] = bc_get_float_value(intan, (j * 2 * dim )+ (2 * i) + 1);
|
||||
|
||||
// outtangent
|
||||
bez.vec[2][0] = bc_get_float_value(outtan, (j * 2 * dim ) + (2 * i)) * fps;
|
||||
bez.vec[2][1] = bc_get_float_value(outtan, (j * 2 * dim )+ (2 * i) + 1);
|
||||
if(curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER)
|
||||
// outtangent
|
||||
bez.vec[2][0] = bc_get_float_value(outtan, (j * 2 * dim ) + (2 * i)) * fps;
|
||||
bez.vec[2][1] = bc_get_float_value(outtan, (j * 2 * dim )+ (2 * i) + 1);
|
||||
if(curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER)
|
||||
bez.ipo = BEZT_IPO_BEZ;
|
||||
else
|
||||
bez.ipo = BEZT_IPO_CONST;
|
||||
//bez.h1 = bez.h2 = HD_AUTO;
|
||||
else
|
||||
bez.ipo = BEZT_IPO_CONST;
|
||||
//bez.h1 = bez.h2 = HD_AUTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -153,7 +153,7 @@ void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
|
||||
}
|
||||
// bez.ipo = U.ipo_new; /* use default interpolation mode here... */
|
||||
bez.f1 = bez.f2 = bez.f3 = SELECT;
|
||||
|
||||
|
||||
insert_bezt_fcurve(fcu, &bez, 0);
|
||||
}
|
||||
|
||||
@@ -306,9 +306,9 @@ bool AnimationImporter::write_animation(const COLLADAFW::Animation* anim)
|
||||
bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList* animlist)
|
||||
{
|
||||
const COLLADAFW::UniqueId& animlist_id = animlist->getUniqueId();
|
||||
|
||||
|
||||
animlist_map[animlist_id] = animlist;
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
// should not happen
|
||||
@@ -317,10 +317,10 @@ bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList* ani
|
||||
}
|
||||
|
||||
// for bones rna_path is like: pose.bones["bone-name"].rotation
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -433,7 +433,7 @@ virtual void AnimationImporter::change_eul_to_quat(Object *ob, bAction *act)
|
||||
|
||||
//sets the rna_path and array index to curve
|
||||
void AnimationImporter::modify_fcurve(std::vector<FCurve*>* curves , char* rna_path , int array_index )
|
||||
{
|
||||
{
|
||||
std::vector<FCurve*>::iterator it;
|
||||
int i;
|
||||
for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) {
|
||||
@@ -450,18 +450,18 @@ void AnimationImporter::modify_fcurve(std::vector<FCurve*>* curves , char* rna_p
|
||||
void AnimationImporter::find_frames( std::vector<float>* frames , std::vector<FCurve*>* curves)
|
||||
{
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
for (iter = curves->begin(); iter != curves->end(); iter++) {
|
||||
FCurve *fcu = *iter;
|
||||
|
||||
for (unsigned int k = 0; k < fcu->totvert; k++) {
|
||||
//get frame value from bezTriple
|
||||
float fra = fcu->bezt[k].vec[1][0];
|
||||
//if frame already not added add frame to frames
|
||||
if (std::find(frames->begin(), frames->end(), fra) == frames->end())
|
||||
frames->push_back(fra);
|
||||
|
||||
}
|
||||
for (iter = curves->begin(); iter != curves->end(); iter++) {
|
||||
FCurve *fcu = *iter;
|
||||
|
||||
for (unsigned int k = 0; k < fcu->totvert; k++) {
|
||||
//get frame value from bezTriple
|
||||
float fra = fcu->bezt[k].vec[1][0];
|
||||
//if frame already not added add frame to frames
|
||||
if (std::find(frames->begin(), frames->end(), fra) == frames->end())
|
||||
frames->push_back(fra);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//creates the rna_paths and array indices of fcurves from animations using transformation and bound animation class of each animation.
|
||||
@@ -472,18 +472,18 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
|
||||
COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
|
||||
bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
|
||||
bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
|
||||
|
||||
|
||||
//to check if the no of curves are valid
|
||||
bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE ||tm_type == COLLADAFW::Transformation::SCALE) && binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
|
||||
|
||||
|
||||
|
||||
|
||||
if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) {
|
||||
fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, (int)curves->size());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
char rna_path[100];
|
||||
|
||||
|
||||
switch (tm_type) {
|
||||
case COLLADAFW::Transformation::TRANSLATE:
|
||||
case COLLADAFW::Transformation::SCALE:
|
||||
@@ -495,80 +495,80 @@ void AnimationImporter:: Assign_transform_animations(COLLADAFW::Transformation *
|
||||
BLI_strncpy(rna_path, loc ? "location" : "scale", sizeof(rna_path));
|
||||
|
||||
switch (binding->animationClass) {
|
||||
case COLLADAFW::AnimationList::POSITION_X:
|
||||
modify_fcurve(curves, rna_path, 0 );
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_Y:
|
||||
modify_fcurve(curves, rna_path, 1 );
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_Z:
|
||||
modify_fcurve(curves, rna_path, 2 );
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_XYZ:
|
||||
modify_fcurve(curves, rna_path, -1 );
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
|
||||
binding->animationClass, loc ? "TRANSLATE" : "SCALE");
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_X:
|
||||
modify_fcurve(curves, rna_path, 0 );
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_Y:
|
||||
modify_fcurve(curves, rna_path, 1 );
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_Z:
|
||||
modify_fcurve(curves, rna_path, 2 );
|
||||
break;
|
||||
case COLLADAFW::AnimationList::POSITION_XYZ:
|
||||
modify_fcurve(curves, rna_path, -1 );
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
|
||||
binding->animationClass, loc ? "TRANSLATE" : "SCALE");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
case COLLADAFW::Transformation::ROTATE:
|
||||
{
|
||||
if (is_joint)
|
||||
BLI_snprintf(rna_path, sizeof(rna_path), "%s.rotation_euler", joint_path);
|
||||
else
|
||||
BLI_strncpy(rna_path, "rotation_euler", sizeof(rna_path));
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
for (iter = curves->begin(); iter != curves->end(); iter++) {
|
||||
FCurve* fcu = *iter;
|
||||
|
||||
|
||||
//if transform is rotation the fcurves values must be turned in to radian.
|
||||
if (is_rotation)
|
||||
fcurve_deg_to_rad(fcu);
|
||||
}
|
||||
COLLADAFW::Rotate* rot = (COLLADAFW::Rotate*)transform;
|
||||
COLLADABU::Math::Vector3& axis = rot->getRotationAxis();
|
||||
|
||||
|
||||
switch (binding->animationClass) {
|
||||
case COLLADAFW::AnimationList::ANGLE:
|
||||
if (COLLADABU::Math::Vector3::UNIT_X == axis) {
|
||||
modify_fcurve(curves, rna_path, 0 );
|
||||
}
|
||||
else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
|
||||
modify_fcurve(curves, rna_path, 1 );
|
||||
}
|
||||
else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
|
||||
modify_fcurve(curves, rna_path, 2 );
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::AnimationList::AXISANGLE:
|
||||
// TODO convert axis-angle to quat? or XYZ?
|
||||
default:
|
||||
fprintf(stderr, "AnimationClass %d is not supported for ROTATE transformation.\n",
|
||||
binding->animationClass);
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::AnimationList::ANGLE:
|
||||
if (COLLADABU::Math::Vector3::UNIT_X == axis) {
|
||||
modify_fcurve(curves, rna_path, 0 );
|
||||
}
|
||||
|
||||
else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
|
||||
modify_fcurve(curves, rna_path, 1 );
|
||||
}
|
||||
else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
|
||||
modify_fcurve(curves, rna_path, 2 );
|
||||
}
|
||||
break;
|
||||
case COLLADAFW::AnimationList::AXISANGLE:
|
||||
// TODO convert axis-angle to quat? or XYZ?
|
||||
default:
|
||||
fprintf(stderr, "AnimationClass %d is not supported for ROTATE transformation.\n",
|
||||
binding->animationClass);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case COLLADAFW::Transformation::MATRIX:
|
||||
/*{
|
||||
COLLADAFW::Matrix* mat = (COLLADAFW::Matrix*)transform;
|
||||
COLLADABU::Math::Matrix4 mat4 = mat->getMatrix();
|
||||
switch (binding->animationClass) {
|
||||
case COLLADAFW::AnimationList::TRANSFORM:
|
||||
|
||||
}
|
||||
COLLADAFW::Matrix* mat = (COLLADAFW::Matrix*)transform;
|
||||
COLLADABU::Math::Matrix4 mat4 = mat->getMatrix();
|
||||
switch (binding->animationClass) {
|
||||
case COLLADAFW::AnimationList::TRANSFORM:
|
||||
|
||||
}
|
||||
}*/
|
||||
break;
|
||||
case COLLADAFW::Transformation::SKEW:
|
||||
case COLLADAFW::Transformation::LOOKAT:
|
||||
fprintf(stderr, "Animation of SKEW and LOOKAT transformations is not supported yet.\n");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//creates the rna_paths and array indices of fcurves from animations using color and bound animation class of each animation.
|
||||
@@ -576,15 +576,15 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
|
||||
{
|
||||
char rna_path[100];
|
||||
BLI_strncpy(rna_path,anim_type, sizeof(rna_path));
|
||||
|
||||
|
||||
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
||||
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
|
||||
//all the curves belonging to the current binding
|
||||
std::vector<FCurve*> animcurves;
|
||||
//all the curves belonging to the current binding
|
||||
std::vector<FCurve*> animcurves;
|
||||
for (unsigned int j = 0; j < bindings.getCount(); j++) {
|
||||
animcurves = curve_map[bindings[j].animation];
|
||||
|
||||
switch (bindings[j].animationClass) {
|
||||
animcurves = curve_map[bindings[j].animation];
|
||||
|
||||
switch (bindings[j].animationClass) {
|
||||
case COLLADAFW::AnimationList::COLOR_R:
|
||||
modify_fcurve(&animcurves, rna_path, 0 );
|
||||
break;
|
||||
@@ -598,13 +598,13 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
|
||||
case COLLADAFW::AnimationList::COLOR_RGBA: // to do-> set intensity
|
||||
modify_fcurve(&animcurves, rna_path, -1 );
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
fprintf(stderr, "AnimationClass %d is not supported for %s.\n",
|
||||
bindings[j].animationClass, "COLOR" );
|
||||
bindings[j].animationClass, "COLOR" );
|
||||
}
|
||||
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
//Add the curves of the current animation to the object
|
||||
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
||||
FCurve * fcu = *iter;
|
||||
@@ -612,7 +612,7 @@ void AnimationImporter:: Assign_color_animations(const COLLADAFW::UniqueId& list
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, char * anim_type)
|
||||
@@ -625,7 +625,7 @@ void AnimationImporter:: Assign_float_animations(const COLLADAFW::UniqueId& list
|
||||
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
||||
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
|
||||
//all the curves belonging to the current binding
|
||||
std::vector<FCurve*> animcurves;
|
||||
std::vector<FCurve*> animcurves;
|
||||
for (unsigned int j = 0; j < bindings.getCount(); j++) {
|
||||
animcurves = curve_map[bindings[j].animation];
|
||||
|
||||
@@ -671,28 +671,28 @@ void AnimationImporter::apply_matrix_curves( Object * ob, std::vector<FCurve*>&
|
||||
copy_m4_m4(rest, bone->arm_mat);
|
||||
invert_m4_m4(irest, rest);
|
||||
}
|
||||
// new curves to assign matrix transform animation
|
||||
// new curves to assign matrix transform animation
|
||||
FCurve *newcu[10]; // if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale
|
||||
unsigned int totcu = 10 ;
|
||||
const char *tm_str = NULL;
|
||||
const char *tm_str = NULL;
|
||||
char rna_path[200];
|
||||
for (int i = 0; i < totcu; i++) {
|
||||
|
||||
int axis = i;
|
||||
|
||||
if (i < 4) {
|
||||
tm_str = "rotation_quaternion";
|
||||
axis = i;
|
||||
}
|
||||
else if (i < 7) {
|
||||
tm_str = "location";
|
||||
axis = i - 4;
|
||||
}
|
||||
else {
|
||||
tm_str = "scale";
|
||||
axis = i - 7;
|
||||
}
|
||||
|
||||
if (i < 4) {
|
||||
tm_str = "rotation_quaternion";
|
||||
axis = i;
|
||||
}
|
||||
else if (i < 7) {
|
||||
tm_str = "location";
|
||||
axis = i - 4;
|
||||
}
|
||||
else {
|
||||
tm_str = "scale";
|
||||
axis = i - 7;
|
||||
}
|
||||
|
||||
|
||||
if (is_joint)
|
||||
BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str);
|
||||
@@ -702,11 +702,11 @@ void AnimationImporter::apply_matrix_curves( Object * ob, std::vector<FCurve*>&
|
||||
newcu[i]->totvert = frames.size();
|
||||
}
|
||||
|
||||
if (frames.size() == 0)
|
||||
if (frames.size() == 0)
|
||||
return;
|
||||
|
||||
std::sort(frames.begin(), frames.end());
|
||||
|
||||
std::sort(frames.begin(), frames.end());
|
||||
|
||||
std::vector<float>::iterator it;
|
||||
|
||||
// sample values at each frame
|
||||
@@ -717,7 +717,7 @@ std::sort(frames.begin(), frames.end());
|
||||
float matfra[4][4];
|
||||
|
||||
unit_m4(matfra);
|
||||
|
||||
|
||||
// calc object-space mat
|
||||
evaluate_transform_at_frame(matfra, node, fra);
|
||||
|
||||
@@ -743,23 +743,23 @@ std::sort(frames.begin(), frames.end());
|
||||
}
|
||||
|
||||
float rot[4], loc[3], scale[3];
|
||||
|
||||
mat4_to_quat(rot, mat);
|
||||
/*for ( int i = 0 ; i < 4 ; i ++ )
|
||||
{
|
||||
rot[i] = rot[i] * (180 / M_PI);
|
||||
}*/
|
||||
copy_v3_v3(loc, mat[3]);
|
||||
mat4_to_size(scale, mat);
|
||||
|
||||
|
||||
mat4_to_quat(rot, mat);
|
||||
/*for ( int i = 0 ; i < 4 ; i ++ )
|
||||
{
|
||||
rot[i] = rot[i] * (180 / M_PI);
|
||||
}*/
|
||||
copy_v3_v3(loc, mat[3]);
|
||||
mat4_to_size(scale, mat);
|
||||
|
||||
// add keys
|
||||
for (int i = 0; i < totcu; i++) {
|
||||
if (i < 4)
|
||||
add_bezt(newcu[i], fra, rot[i]);
|
||||
else if (i < 7)
|
||||
add_bezt(newcu[i], fra, loc[i - 4]);
|
||||
else
|
||||
add_bezt(newcu[i], fra, scale[i - 7]);
|
||||
if (i < 4)
|
||||
add_bezt(newcu[i], fra, rot[i]);
|
||||
else if (i < 7)
|
||||
add_bezt(newcu[i], fra, loc[i - 4]);
|
||||
else
|
||||
add_bezt(newcu[i], fra, scale[i - 7]);
|
||||
}
|
||||
}
|
||||
verify_adt_action((ID*)&ob->id, 1);
|
||||
@@ -774,13 +774,13 @@ std::sort(frames.begin(), frames.end());
|
||||
BLI_addtail(curves, newcu[i]);
|
||||
}
|
||||
|
||||
if (is_joint) {
|
||||
bPoseChannel *chan = get_pose_channel(ob->pose, bone_name);
|
||||
chan->rotmode = ROT_MODE_QUAT;
|
||||
}
|
||||
else {
|
||||
ob->rotmode = ROT_MODE_QUAT;
|
||||
}
|
||||
if (is_joint) {
|
||||
bPoseChannel *chan = get_pose_channel(ob->pose, bone_name);
|
||||
chan->rotmode = ROT_MODE_QUAT;
|
||||
}
|
||||
else {
|
||||
ob->rotmode = ROT_MODE_QUAT;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -804,24 +804,24 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
|
||||
bAction * act;
|
||||
bActionGroup *grp = NULL;
|
||||
|
||||
|
||||
if ( (animType->transform) != 0 )
|
||||
{
|
||||
const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL;
|
||||
char joint_path[200];
|
||||
const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL;
|
||||
char joint_path[200];
|
||||
|
||||
if ( is_joint )
|
||||
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
|
||||
|
||||
|
||||
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
|
||||
|
||||
|
||||
if (!ob->adt || !ob->adt->action) act = verify_adt_action((ID*)&ob->id, 1);
|
||||
else act = ob->adt->action;
|
||||
|
||||
//Get the list of animation curves of the object
|
||||
ListBase *AnimCurves = &(act->curves);
|
||||
|
||||
//Get the list of animation curves of the object
|
||||
ListBase *AnimCurves = &(act->curves);
|
||||
|
||||
const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
|
||||
|
||||
|
||||
//for each transformation in node
|
||||
for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
|
||||
COLLADAFW::Transformation *transform = nodeTransforms[i];
|
||||
@@ -829,10 +829,10 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
|
||||
bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
|
||||
bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
|
||||
|
||||
|
||||
const COLLADAFW::UniqueId& listid = transform->getAnimationList();
|
||||
|
||||
//check if transformation has animations
|
||||
|
||||
//check if transformation has animations
|
||||
if (animlist_map.find(listid) == animlist_map.end()) continue ;
|
||||
else
|
||||
{
|
||||
@@ -840,25 +840,25 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
||||
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
|
||||
//all the curves belonging to the current binding
|
||||
std::vector<FCurve*> animcurves;
|
||||
std::vector<FCurve*> animcurves;
|
||||
for (unsigned int j = 0; j < bindings.getCount(); j++) {
|
||||
animcurves = curve_map[bindings[j].animation];
|
||||
if ( is_matrix )
|
||||
apply_matrix_curves(ob, animcurves, root , node, transform );
|
||||
else {
|
||||
animcurves = curve_map[bindings[j].animation];
|
||||
if ( is_matrix )
|
||||
apply_matrix_curves(ob, animcurves, root , node, transform );
|
||||
else {
|
||||
//calculate rnapaths and array index of fcurves according to transformation and animation class
|
||||
Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path );
|
||||
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
//Add the curves of the current animation to the object
|
||||
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
||||
FCurve * fcu = *iter;
|
||||
if ((ob->type == OB_ARMATURE))
|
||||
add_bone_fcurve( ob, node , fcu );
|
||||
else
|
||||
BLI_addtail(AnimCurves, fcu);
|
||||
}
|
||||
Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path );
|
||||
|
||||
std::vector<FCurve*>::iterator iter;
|
||||
//Add the curves of the current animation to the object
|
||||
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
|
||||
FCurve * fcu = *iter;
|
||||
if ((ob->type == OB_ARMATURE))
|
||||
add_bone_fcurve( ob, node , fcu );
|
||||
else
|
||||
BLI_addtail(AnimCurves, fcu);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_rotation) {
|
||||
@@ -880,7 +880,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
Lamp * lamp = (Lamp*) ob->data;
|
||||
|
||||
if (!lamp->adt || !lamp->adt->action) act = verify_adt_action((ID*)&lamp->id, 1);
|
||||
else act = lamp->adt->action;
|
||||
else act = lamp->adt->action;
|
||||
|
||||
ListBase *AnimCurves = &(act->curves);
|
||||
const COLLADAFW::InstanceLightPointerArray& nodeLights = node->getInstanceLights();
|
||||
@@ -892,23 +892,23 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
{
|
||||
const COLLADAFW::Color *col = &(light->getColor());
|
||||
const COLLADAFW::UniqueId& listid = col->getAnimationList();
|
||||
|
||||
|
||||
Assign_color_animations(listid, AnimCurves, "color");
|
||||
}
|
||||
if ((animType->light & LIGHT_FOA) != 0 )
|
||||
{
|
||||
const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle());
|
||||
const COLLADAFW::UniqueId& listid = foa->getAnimationList();
|
||||
|
||||
|
||||
Assign_float_animations( listid ,AnimCurves, "spot_size");
|
||||
}
|
||||
if ( (animType->light & LIGHT_FOE) != 0 )
|
||||
{
|
||||
const COLLADAFW::AnimatableFloat *foe = &(light->getFallOffExponent());
|
||||
const COLLADAFW::UniqueId& listid = foe->getAnimationList();
|
||||
|
||||
|
||||
Assign_float_animations( listid ,AnimCurves, "spot_blend");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -918,7 +918,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
Camera * camera = (Camera*) ob->data;
|
||||
|
||||
if (!camera->adt || !camera->adt->action) act = verify_adt_action((ID*)&camera->id, 1);
|
||||
else act = camera->adt->action;
|
||||
else act = camera->adt->action;
|
||||
|
||||
ListBase *AnimCurves = &(act->curves);
|
||||
const COLLADAFW::InstanceCameraPointerArray& nodeCameras= node->getInstanceCameras();
|
||||
@@ -957,12 +957,12 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
}
|
||||
}
|
||||
if ( animType->material != 0){
|
||||
Material *ma = give_current_material(ob, 1);
|
||||
if (!ma->adt || !ma->adt->action) act = verify_adt_action((ID*)&ma->id, 1);
|
||||
else act = ma->adt->action;
|
||||
Material *ma = give_current_material(ob, 1);
|
||||
if (!ma->adt || !ma->adt->action) act = verify_adt_action((ID*)&ma->id, 1);
|
||||
else act = ma->adt->action;
|
||||
|
||||
ListBase *AnimCurves = &(act->curves);
|
||||
|
||||
|
||||
const COLLADAFW::InstanceGeometryPointerArray& nodeGeoms = node->getInstanceGeometries();
|
||||
for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
|
||||
const COLLADAFW::MaterialBindingArray& matBinds = nodeGeoms[i]->getMaterialBindings();
|
||||
@@ -988,7 +988,7 @@ void AnimationImporter::translate_Animations ( COLLADAFW::Node * node ,
|
||||
const COLLADAFW::UniqueId& listid = cot->getColor().getAnimationList();
|
||||
Assign_color_animations( listid, AnimCurves , "specular_color" );
|
||||
}
|
||||
|
||||
|
||||
if((animType->material & MATERIAL_DIFF_COLOR) != 0){
|
||||
const COLLADAFW::ColorOrTexture *cot = &(efc->getDiffuse());
|
||||
const COLLADAFW::UniqueId& listid = cot->getColor().getAnimationList();
|
||||
@@ -1005,15 +1005,15 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
|
||||
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map)
|
||||
{
|
||||
AnimMix *types = new AnimMix();
|
||||
|
||||
|
||||
const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
|
||||
|
||||
|
||||
//for each transformation in node
|
||||
for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
|
||||
COLLADAFW::Transformation *transform = nodeTransforms[i];
|
||||
const COLLADAFW::UniqueId& listid = transform->getAnimationList();
|
||||
|
||||
//check if transformation has animations
|
||||
|
||||
//check if transformation has animations
|
||||
if (animlist_map.find(listid) == animlist_map.end()) continue ;
|
||||
else
|
||||
{
|
||||
@@ -1028,9 +1028,9 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
|
||||
types->light = setAnimType(&(light->getColor()),(types->light), LIGHT_COLOR);
|
||||
types->light = setAnimType(&(light->getFallOffAngle()),(types->light), LIGHT_FOA);
|
||||
types->light = setAnimType(&(light->getFallOffExponent()),(types->light), LIGHT_FOE);
|
||||
|
||||
|
||||
if ( types->light != 0) break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
const COLLADAFW::InstanceCameraPointerArray& nodeCameras = node->getInstanceCameras();
|
||||
@@ -1039,9 +1039,9 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
|
||||
|
||||
if ( camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE )
|
||||
{
|
||||
types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XFOV);
|
||||
types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XFOV);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
types->camera = setAnimType(&(camera->getXMag()),(types->camera), CAMERA_XMAG);
|
||||
}
|
||||
@@ -1063,7 +1063,7 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
|
||||
types->material = setAnimType(&(efc->getShininess()),(types->material), MATERIAL_SHININESS);
|
||||
types->material = setAnimType(&(efc->getSpecular().getColor()),(types->material), MATERIAL_SPEC_COLOR);
|
||||
types->material = setAnimType(&(efc->getDiffuse().getColor()),(types->material), MATERIAL_DIFF_COLOR);
|
||||
// types->material = setAnimType(&(efc->get()),(types->material), MATERIAL_TRANSPARENCY);
|
||||
// types->material = setAnimType(&(efc->get()),(types->material), MATERIAL_TRANSPARENCY);
|
||||
types->material = setAnimType(&(efc->getIndexOfRefraction()),(types->material), MATERIAL_IOR);
|
||||
}
|
||||
}
|
||||
@@ -1101,7 +1101,7 @@ void AnimationImporter::find_frames_old(std::vector<float> * frames, COLLADAFW::
|
||||
|
||||
const COLLADAFW::AnimationList *animlist = animlist_map[listid];
|
||||
const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
|
||||
|
||||
|
||||
if (bindings.getCount()) {
|
||||
//for each AnimationBinding get the fcurves which animate the transform
|
||||
for (unsigned int j = 0; j < bindings.getCount(); j++) {
|
||||
@@ -1113,7 +1113,7 @@ void AnimationImporter::find_frames_old(std::vector<float> * frames, COLLADAFW::
|
||||
|
||||
for (iter = curves.begin(); iter != curves.end(); iter++) {
|
||||
FCurve *fcu = *iter;
|
||||
|
||||
|
||||
//if transform is rotation the fcurves values must be turned in to radian.
|
||||
if (is_rotation)
|
||||
fcurve_deg_to_rad(fcu);
|
||||
@@ -1448,9 +1448,9 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float
|
||||
COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
|
||||
|
||||
if (type != COLLADAFW::Transformation::ROTATE &&
|
||||
type != COLLADAFW::Transformation::SCALE &&
|
||||
type != COLLADAFW::Transformation::TRANSLATE &&
|
||||
type != COLLADAFW::Transformation::MATRIX) {
|
||||
type != COLLADAFW::Transformation::SCALE &&
|
||||
type != COLLADAFW::Transformation::TRANSLATE &&
|
||||
type != COLLADAFW::Transformation::MATRIX) {
|
||||
fprintf(stderr, "animation of transformation %d is not supported yet\n", type);
|
||||
return false;
|
||||
}
|
||||
@@ -1572,7 +1572,7 @@ bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, float
|
||||
|
||||
COLLADAFW::Matrix tm(matrix);
|
||||
dae_matrix_to_mat4(&tm, mat);
|
||||
|
||||
|
||||
std::vector<FCurve*>::iterator it;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -88,7 +88,7 @@ private:
|
||||
void add_fcurves_to_object(Object *ob, std::vector<FCurve*>& curves, char *rna_path, int array_index, Animation *animated);
|
||||
|
||||
int typeFlag;
|
||||
|
||||
|
||||
enum lightAnim
|
||||
{
|
||||
// INANIMATE = 0,
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
#if 0
|
||||
virtual void change_eul_to_quat(Object *ob, bAction *act);
|
||||
#endif
|
||||
|
||||
|
||||
void translate_Animations( COLLADAFW::Node * Node ,
|
||||
std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& root_map,
|
||||
std::map<COLLADAFW::UniqueId, Object*>& object_map ,
|
||||
@@ -161,7 +161,7 @@ public:
|
||||
|
||||
void Assign_color_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves ,char * anim_type);
|
||||
void Assign_float_animations(const COLLADAFW::UniqueId& listid, ListBase *AnimCurves, char * anim_type);
|
||||
|
||||
|
||||
int setAnimType ( const COLLADAFW::Animatable * prop , int type, int addition);
|
||||
|
||||
void modify_fcurve(std::vector<FCurve*>* curves , char* rna_path , int array_index );
|
||||
@@ -206,5 +206,5 @@ public:
|
||||
|
||||
void extra_data_importer(std::string elementName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -188,7 +188,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm)
|
||||
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
|
||||
add_bone_node(child, ob_arm);
|
||||
}
|
||||
node.end();
|
||||
node.end();
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
|
||||
if ( it != finished_joints.end()) return;
|
||||
|
||||
float mat[4][4];
|
||||
float obmat[4][4];
|
||||
float obmat[4][4];
|
||||
|
||||
// object-space
|
||||
get_node_mat(obmat, node, NULL, NULL);
|
||||
@@ -296,7 +296,7 @@ void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW:
|
||||
et->setData("tip_z",&z);
|
||||
float vec[3] = {x,y,z};
|
||||
copy_v3_v3(leaf.bone->tail, leaf.bone->head);
|
||||
add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec);
|
||||
add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec);
|
||||
}else
|
||||
leaf_bones.push_back(leaf);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ private:
|
||||
|
||||
void fix_leaf_bones();
|
||||
|
||||
void set_pose ( Object * ob_arm , COLLADAFW::Node * root_node ,char * parentname, float parent_mat[][4]);
|
||||
void set_pose ( Object * ob_arm , COLLADAFW::Node * root_node ,char * parentname, float parent_mat[][4]);
|
||||
|
||||
|
||||
#if 0
|
||||
@@ -171,7 +171,7 @@ public:
|
||||
|
||||
// gives a world-space mat
|
||||
bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint);
|
||||
|
||||
|
||||
void set_tags_map( TagsMap& tags_map);
|
||||
|
||||
};
|
||||
|
||||
@@ -411,7 +411,7 @@ int MeshImporter::count_new_tris(COLLADAFW::Mesh *mesh, Mesh *me)
|
||||
}
|
||||
|
||||
// TODO: import uv set names
|
||||
void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //TODO:: Refactor. Possibly replace by iterators
|
||||
void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //TODO:: Refactor. Possibly replace by iterators
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
|
||||
@@ -266,9 +266,9 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
|
||||
// ^ bone index can be -1 meaning weight toward bind shape, how to express this in Blender?
|
||||
|
||||
// for each vertex in weight indices
|
||||
// for each bone index in vertex
|
||||
// add vertex to group at group index
|
||||
// treat group index -1 specially
|
||||
// for each bone index in vertex
|
||||
// add vertex to group at group index
|
||||
// treat group index -1 specially
|
||||
|
||||
// get def group by index with BLI_findlink
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[][4],
|
||||
|
||||
double dmat[4][4];
|
||||
UnitConverter* converter = new UnitConverter();
|
||||
converter->mat4_to_dae_double(dmat,local);
|
||||
converter->mat4_to_dae_double(dmat,local);
|
||||
|
||||
TransformBase::decompose(local, loc, rot, NULL, scale);
|
||||
if ( node.getType() == COLLADASW::Node::JOINT)
|
||||
|
||||
Reference in New Issue
Block a user