From 44326c9fe976127b6a63862ea538dfd28cce5404 Mon Sep 17 00:00:00 2001 From: Sukhitha Prabhath Jayathilake Date: Sun, 17 Jul 2011 18:51:03 +0000 Subject: [PATCH] Material Animation export. (on going) --- source/blender/collada/AnimationExporter.cpp | 57 +++++++++++++------- source/blender/collada/AnimationExporter.h | 2 +- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 81dae097315..5b7853f8af7 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -58,6 +58,7 @@ void AnimationExporter::exportAnimations(Scene *sce) { FCurve *fcu; char * transformName ; + bool isMatAnim = false; if(ob->adt && ob->adt->action) { fcu = (FCurve*)ob->adt->action->curves.first; @@ -67,7 +68,7 @@ void AnimationExporter::exportAnimations(Scene *sce) 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); + dae_animation(ob ,fcu, transformName, false , isMatAnim); fcu = fcu->next; } } @@ -80,7 +81,7 @@ void AnimationExporter::exportAnimations(Scene *sce) if ((!strcmp(transformName, "color")) || (!strcmp(transformName, "spot_size"))|| (!strcmp(transformName, "spot_blend"))) - dae_animation(ob ,fcu, transformName,true ); + dae_animation(ob , fcu, transformName, true, isMatAnim ); fcu = fcu->next; } } @@ -94,10 +95,28 @@ void AnimationExporter::exportAnimations(Scene *sce) if ((!strcmp(transformName, "lens"))|| (!strcmp(transformName, "ortho_scale"))|| (!strcmp(transformName, "clipend"))||(!strcmp(transformName, "clipsta"))) - dae_animation(ob ,fcu, transformName,true ); + dae_animation(ob , fcu, transformName, true, isMatAnim ); fcu = fcu->next; } } + + 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) + { + isMatAnim = true; + fcu = (FCurve*)ma->adt->action->curves.first; + while (fcu) { + transformName = extract_transform_name( fcu->rna_path ); + + if ((!strcmp(transformName, "specular_hardness"))) + dae_animation(ob ,fcu, transformName, true, isMatAnim ); + fcu = fcu->next; + } + } + } //if (!ob->adt || !ob->adt->action) // fcu = (FCurve*)((Lamp*)ob->data)->adt->action->curves.first; //this is already checked in hasAnimations() //else @@ -132,18 +151,15 @@ void AnimationExporter::exportAnimations(Scene *sce) { char * transformName = extract_transform_name( fcu->rna_path ); - if( !strcmp(transformName, "rotation_quaternion") ) - { - for ( int i = 0 ; i < fcu->totvert ; i++) - { + 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; } - for ( int i = 0 ; i < fcu->totvert ; i++) - { + for ( int i = 0 ; i < fcu->totvert ; i++){ for ( int j = 0;j<4;j++) temp_quat[j] = quat[(i*4)+j]; @@ -171,7 +187,7 @@ void AnimationExporter::exportAnimations(Scene *sce) return id_name(ob); } - void AnimationExporter::dae_animation(Object* ob, FCurve *fcu/*, std::string ob_name*/ , char* transformName , bool is_param ) + void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, bool isMatAnim ) { const char *axis_name = NULL; @@ -188,24 +204,23 @@ void AnimationExporter::exportAnimations(Scene *sce) axis_name = axis_names[fcu->array_index];*/ } //maybe a list or a vector of float animations - else if ( !strcmp(transformName, "spot_size")||!strcmp(transformName, "spot_blend")|| - !strcmp(transformName, "lens")||!strcmp(transformName, "ortho_scale")||!strcmp(transformName, "clipend")|| - !strcmp(transformName, "clipsta")) - { - axis_name = ""; - } else if ( !strcmp(transformName, "color") ) { const char *axis_names[] = {"R", "G", "B"}; if (fcu->array_index < 3) axis_name = axis_names[fcu->array_index]; } - else + else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) || + (!strcmp(transformName, "rotation_euler"))) { const char *axis_names[] = {"X", "Y", "Z"}; if (fcu->array_index < 3) axis_name = axis_names[fcu->array_index]; } + else{ + axis_name = ""; + } + std::string ob_name = std::string("null"); if (ob->type == OB_ARMATURE) { @@ -215,9 +230,11 @@ void AnimationExporter::exportAnimations(Scene *sce) } 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); + if (isMatAnim) + ob_name = id_name(ob) + "_material"; + else + BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(), + fcu->rna_path, axis_name); } // check rna_path is one of: rotation, scale, location diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index 5185458d71c..bdbfcfcca73 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -94,7 +94,7 @@ public: protected: - void dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param); + void dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, bool isMatAnim); void write_bone_animation(Object *ob_arm, Bone *bone);