diff options
author | Sukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com> | 2011-07-06 21:41:14 +0400 |
---|---|---|
committer | Sukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com> | 2011-07-06 21:41:14 +0400 |
commit | 1e14e2f465c749b5fe39c1a22ea562059b9fad65 (patch) | |
tree | fb68f149643757ce1cc571220d8b5ae58cdf0d4b | |
parent | eb6ac55e93527e12866f60cc8b8059b7705d6b5a (diff) |
camera lens (COLLADA xfov ) animation export
-rw-r--r-- | source/blender/collada/AnimationExporter.cpp | 102 | ||||
-rw-r--r-- | source/blender/collada/AnimationExporter.h | 3 | ||||
-rw-r--r-- | source/blender/collada/CameraExporter.cpp | 4 |
3 files changed, 71 insertions, 38 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index 6ebaef30a9c..c100166a682 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -56,18 +56,50 @@ void AnimationExporter::exportAnimations(Scene *sce) void AnimationExporter::operator() (Object *ob) { FCurve *fcu; + char * transformName ; if(ob->adt && ob->adt->action) - fcu = (FCurve*)ob->adt->action->curves.first; - else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action ) - fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first); - else return; + { + fcu = (FCurve*)ob->adt->action->curves.first; + while (fcu) { + 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; + } + } + if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action ) + { + fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first); + while (fcu) { + transformName = extract_transform_name( fcu->rna_path ); + + if ((!strcmp(transformName, "color")) || + (!strcmp(transformName, "spot_size"))|| + (!strcmp(transformName, "spot_blend"))) + dae_animation(ob ,fcu, transformName,true ); + fcu = fcu->next; + } + } + + if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action ) + { + fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first); + while (fcu) { + transformName = extract_transform_name( fcu->rna_path ); + + if ((!strcmp(transformName, "lens"))) + dae_animation(ob ,fcu, transformName,true ); + 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 // fcu = (FCurve*)ob->adt->action->curves.first; - char * transformName = extract_transform_name( fcu->rna_path ); - - + //if (ob->type == OB_ARMATURE) { // if (!ob->data) return; // bArmature *arm = (bArmature*)ob->data; @@ -82,21 +114,7 @@ void AnimationExporter::exportAnimations(Scene *sce) // } //} //else { - while (fcu) { - 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")) || - (!strcmp(transformName, "color")) || - (!strcmp(transformName, "spot_size"))|| - (!strcmp(transformName, "spot_blend"))) - dae_animation(ob ,fcu, transformName ); - - - fcu = fcu->next; - } - //} + } float * AnimationExporter::get_eul_source_for_quat(Object *ob ) @@ -150,7 +168,7 @@ void AnimationExporter::exportAnimations(Scene *sce) return id_name(ob); } - void AnimationExporter::dae_animation(Object* ob, FCurve *fcu/*, std::string ob_name*/ , char* transformName ) + void AnimationExporter::dae_animation(Object* ob, FCurve *fcu/*, std::string ob_name*/ , char* transformName , bool is_param ) { const char *axis_name = NULL; @@ -166,7 +184,9 @@ void AnimationExporter::exportAnimations(Scene *sce) if (fcu->array_index < 4) axis_name = axis_names[fcu->array_index];*/ } - else if ( !strcmp(transformName, "spot_size")||!strcmp(transformName, "spot_blend") ) + else if ( !strcmp(transformName, "spot_size")|| + !strcmp(transformName, "spot_blend")|| + !strcmp(transformName, "lens")) { axis_name = ""; } @@ -252,13 +272,19 @@ void AnimationExporter::exportAnimations(Scene *sce) std::string target ; - if ( ob->type == OB_LAMP ) - target = get_light_id(ob) - + "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true); - else + 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_transform_sid(fcu->rna_path, -1, axis_name, true); + if ( ob->type == OB_CAMERA ) + target = get_camera_id(ob) + + "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true); + } addChannel(COLLADABU::URI(empty, sampler_id), target); closeAnimation(); @@ -569,9 +595,9 @@ void AnimationExporter::exportAnimations(Scene *sce) std::string source_id = anim_id + get_semantic_suffix(semantic); //bool is_rotation = !strcmp(fcu->rna_path, "rotation"); - bool is_rotation = false; + bool is_angle = false; - if (strstr(fcu->rna_path, "rotation")) is_rotation = true; + if (strstr(fcu->rna_path, "rotation")||strstr(fcu->rna_path, "lens")) is_angle = true; COLLADASW::FloatSourceF source(mSW); source.setId(source_id); @@ -591,14 +617,14 @@ void AnimationExporter::exportAnimations(Scene *sce) COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); - add_source_parameters(param, semantic, is_rotation, axis_name); + add_source_parameters(param, semantic, is_angle, axis_name); 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_rotation, values, &length); + get_source_values(&fcu->bezt[i], semantic, is_angle, values, &length); for (int j = 0; j < length; j++) source.appendValues(values[j]); } @@ -777,6 +803,8 @@ void AnimationExporter::exportAnimations(Scene *sce) tm_type = 5; else if (!strcmp(name, "spot_blend")) tm_type = 6; + else if (!strcmp(name, "lens")) + tm_type = 7; else tm_type = -1; } @@ -802,6 +830,10 @@ void AnimationExporter::exportAnimations(Scene *sce) case 6: tm_name = "fall_off_exponent"; break; + case 7: + tm_name = "xfov"; + break; + default: tm_name = ""; break; @@ -890,10 +922,10 @@ void AnimationExporter::exportAnimations(Scene *sce) fcu = (FCurve*)ob->adt->action->curves.first; else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action ) fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first); + else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action ) + fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first); //The Scene has animations if object type is armature or object has f-curve or object is a Lamp which has f-curves - if ((ob->type == OB_ARMATURE && ob->data) || fcu) { - return true; - } + if ( fcu) return true; base= base->next; } return false; diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h index 85e5e23d0f0..481cacbd4c8 100644 --- a/source/blender/collada/AnimationExporter.h +++ b/source/blender/collada/AnimationExporter.h @@ -33,6 +33,7 @@ extern "C" #include "DNA_action_types.h" #include "DNA_curve_types.h" #include "DNA_lamp_types.h" +#include "DNA_camera_types.h" #include "DNA_armature_types.h" #include "BKE_DerivedMesh.h" @@ -90,7 +91,7 @@ public: protected: - void dae_animation(Object* ob, FCurve *fcu, char* transformName); + void dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param); void write_bone_animation(Object *ob_arm, Bone *bone); diff --git a/source/blender/collada/CameraExporter.cpp b/source/blender/collada/CameraExporter.cpp index e3feab6b76c..c4d9a4a0df0 100644 --- a/source/blender/collada/CameraExporter.cpp +++ b/source/blender/collada/CameraExporter.cpp @@ -73,7 +73,7 @@ void CamerasExporter::operator()(Object *ob, Scene *sce) if (cam->type == CAM_PERSP) { COLLADASW::PerspectiveOptic persp(mSW); - persp.setXFov(lens_to_angle(cam->lens)*(180.0f/M_PI)); + persp.setXFov(lens_to_angle(cam->lens)*(180.0f/M_PI),"XFov"); persp.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch),false,cam_name); persp.setZFar(cam->clipend); persp.setZNear(cam->clipsta); @@ -82,7 +82,7 @@ void CamerasExporter::operator()(Object *ob, Scene *sce) } else { COLLADASW::OrthographicOptic ortho(mSW); - ortho.setXMag(cam->ortho_scale); + ortho.setXMag(cam->ortho_scale,"XMag"); ortho.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch)); ortho.setZFar(cam->clipend); ortho.setZNear(cam->clipsta); |