| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * $Id: DocumentExporter.cpp 36898 2011-05-25 17:14:31Z phabtar $ | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** 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"
 | 
					
						
							| 
									
										
										
										
											2011-07-17 17:30:41 +00:00
										 |  |  | #include "MaterialExporter.h"
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | template<class Functor> | 
					
						
							|  |  |  | void forEachObjectInScene(Scene *sce, Functor &f) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Base *base= (Base*) sce->base.first; | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	while(base) { | 
					
						
							|  |  |  | 		Object *ob = base->object; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 		f(ob); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		base= base->next; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationExporter::exportAnimations(Scene *sce) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if(hasAnimations(sce)) { | 
					
						
							|  |  |  | 			this->scene = sce; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			openLibrary(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			forEachObjectInScene(sce, *this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			closeLibrary(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// called for each exported object
 | 
					
						
							|  |  |  | 	void AnimationExporter::operator() (Object *ob)  | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  | 		FCurve *fcu; | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		char * transformName ; | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 		bool isMatAnim = false; | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  |         if(ob->adt && ob->adt->action)       | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 			if ( ob->type == OB_ARMATURE ) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				bArmature *arm = (bArmature*)ob->data; | 
					
						
							|  |  |  | 				for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) | 
					
						
							|  |  |  | 					bake_bone_animation(ob, bone); | 
					
						
							|  |  |  | 			     | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 			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")))  | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 					dae_animation(ob ,fcu, transformName, false); | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 				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")))  | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 					dae_animation(ob , fcu, transformName, true ); | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 				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 ); | 
					
						
							|  |  |  | 				 | 
					
						
							| 
									
										
										
										
											2011-07-06 19:00:40 +00:00
										 |  |  | 				if ((!strcmp(transformName, "lens"))|| | 
					
						
							| 
									
										
										
										
											2011-07-07 18:40:46 +00:00
										 |  |  | 					(!strcmp(transformName, "ortho_scale"))|| | 
					
						
							| 
									
										
										
										
											2011-07-31 05:04:12 +00:00
										 |  |  | 					(!strcmp(transformName, "clip_end"))||(!strcmp(transformName, "clip_start")))  | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 					dae_animation(ob , fcu, transformName, true ); | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 				fcu = fcu->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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 ); | 
					
						
							|  |  |  | 					 | 
					
						
							| 
									
										
										
										
											2011-07-27 18:38:44 +00:00
										 |  |  | 					if ((!strcmp(transformName, "specular_hardness"))||(!strcmp(transformName, "specular_color")) | 
					
						
							| 
									
										
										
										
											2011-08-06 06:11:31 +00:00
										 |  |  | 						||(!strcmp(transformName, "diffuse_color"))||(!strcmp(transformName, "alpha"))|| | 
					
						
							|  |  |  | 						(!strcmp(transformName, "ior")))  | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 						dae_animation(ob ,fcu, transformName, true, ma ); | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 					fcu = fcu->next; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-08-06 06:11:31 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  | 		//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;
 | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 						         | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		//if (ob->type == OB_ARMATURE) {
 | 
					
						
							|  |  |  | 		//	if (!ob->data) return;
 | 
					
						
							|  |  |  | 		//	bArmature *arm = (bArmature*)ob->data;
 | 
					
						
							|  |  |  | 		//	while(fcu)
 | 
					
						
							|  |  |  | 		//	{ 		
 | 
					
						
							|  |  |  | 		//		transformName = extract_transform_name( fcu->rna_path );
 | 
					
						
							|  |  |  | 		//	//	std::string ob_name =  getObjectBoneName( ob , fcu);
 | 
					
						
							|  |  |  | 		//	//	for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
 | 
					
						
							|  |  |  | 		//	//		write_bone_animation(ob, bone);
 | 
					
						
							|  |  |  | 		//		dae_animation(ob, fcu, ob_name, transformName);
 | 
					
						
							|  |  |  | 		//		fcu = fcu->next;
 | 
					
						
							|  |  |  | 		//	}
 | 
					
						
							|  |  |  | 		//}
 | 
					
						
							|  |  |  | 		//else {
 | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 	float * AnimationExporter::get_eul_source_for_quat(Object *ob ) | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		FCurve *fcu = (FCurve*)ob->adt->action->curves.first; | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 		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]; | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 			while(fcu) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 				char * transformName = extract_transform_name( fcu->rna_path ); | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 				 | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 				if( !strcmp(transformName, "rotation_quaternion") )	{  | 
					
						
							|  |  |  | 					for ( int i = 0 ; i < fcu->totvert ; i++){ | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 						*(quat + ( i * 4 ) + fcu->array_index) = fcu->bezt[i].vec[1][1]; | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 					fcu = fcu->next; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 			for ( int i = 0 ; i < fcu->totvert ; i++){ | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 				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]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return eul; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 	std::string AnimationExporter::getObjectBoneName( Object* ob,const FCurve* fcu )  | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		//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 ) | 
					
						
							| 
									
										
										
										
											2011-06-25 07:23:23 +00:00
										 |  |  | 			return /*id_name(ob) + "_" +*/ std::string(boneName); | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		else		 | 
					
						
							|  |  |  | 			return id_name(ob); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 	void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material * ma ) | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		const char *axis_name = NULL; | 
					
						
							|  |  |  | 		char anim_id[200]; | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		bool has_tangents = false; | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 		bool quatRotation = false; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		if ( !strcmp(transformName, "rotation_quaternion") ) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 			quatRotation = true; | 
					
						
							|  |  |  | 			/*const char *axis_names[] = {"", "X", "Y", "Z"};
 | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 			if (fcu->array_index < 4) | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 			axis_name = axis_names[fcu->array_index];*/ | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-07 18:40:46 +00:00
										 |  |  | 		//maybe a list or a vector of float animations
 | 
					
						
							| 
									
										
										
										
											2011-07-28 18:25:23 +00:00
										 |  |  | 		else if ( !strcmp(transformName, "color")||!strcmp(transformName, "specular_color")||!strcmp(transformName, "diffuse_color")|| | 
					
						
							|  |  |  | 			      (!strcmp(transformName, "alpha"))) | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			const char *axis_names[] = {"R", "G", "B"}; | 
					
						
							|  |  |  | 			if (fcu->array_index < 3) | 
					
						
							|  |  |  | 			axis_name = axis_names[fcu->array_index]; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 		else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) || | 
					
						
							|  |  |  | 				(!strcmp(transformName, "rotation_euler"))) | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			const char *axis_names[] = {"X", "Y", "Z"}; | 
					
						
							|  |  |  | 			if (fcu->array_index < 3) | 
					
						
							|  |  |  | 			axis_name = axis_names[fcu->array_index]; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 		else{ | 
					
						
							|  |  |  | 			axis_name = ""; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		std::string ob_name = std::string("null"); | 
					
						
							|  |  |  | 		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  | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 			if (ma) | 
					
						
							| 
									
										
										
										
											2011-07-17 18:51:03 +00:00
										 |  |  | 				ob_name = id_name(ob) + "_material"; | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 				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); | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		// check rna_path is one of: rotation, scale, location
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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
 | 
					
						
							| 
									
										
										
										
											2011-06-16 15:04:37 +00:00
										 |  |  | 		std::string output_id ; | 
					
						
							|  |  |  | 	     | 
					
						
							|  |  |  | 		/*if(quatRotation) 
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  |             float * eul  = get_eul_source_for_quat(ob); | 
					
						
							|  |  |  | 			float * eul_axis =  | 
					
						
							|  |  |  | 				for ( int i = 0 ; i< fcu->totvert ; i++) | 
					
						
							|  |  |  | 					eul_axis[i] = eul[i*3 + fcu->array_index]; | 
					
						
							|  |  |  | 			output_id= create_source_from_array(COLLADASW::InputSemantic::OUTPUT, eul_axis , fcu->totvert, quatRotation, anim_id, axis_name); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 else*/  | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		output_id= create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// create interpolations source
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		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); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		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)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		addSampler(sampler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-02 05:05:03 +00:00
										 |  |  | 		std::string target ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		if ( !is_param ) | 
					
						
							| 
									
										
										
										
											2011-07-02 05:05:03 +00:00
										 |  |  | 			target = translate_id(ob_name) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			+ "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true); | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		else  | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			if ( ob->type == OB_LAMP ) | 
					
						
							|  |  |  | 				target = get_light_id(ob) | 
					
						
							|  |  |  | 				+ "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true); | 
					
						
							| 
									
										
										
										
											2011-07-02 05:05:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 			if ( ob->type == OB_CAMERA ) | 
					
						
							|  |  |  | 				target = get_camera_id(ob) | 
					
						
							|  |  |  | 				+ "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true); | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if( ma )  | 
					
						
							|  |  |  | 				target = translate_id(id_name(ma)) + "-effect" | 
					
						
							| 
									
										
										
										
											2011-08-06 06:11:31 +00:00
										 |  |  | 						+"/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true); | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		addChannel(COLLADABU::URI(empty, sampler_id), target); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		closeAnimation(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 	void AnimationExporter::bake_bone_animation(Object *ob_arm, Bone *bone) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (!ob_arm->adt) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  | 		sample_and_bake_bone_animation(ob_arm, bone); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) | 
					
						
							|  |  |  | 			bake_bone_animation(ob_arm, child); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 	void AnimationExporter::sample_and_bake_bone_animation(Object *ob_arm, Bone *bone) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-08-07 18:15:40 +00:00
										 |  |  | 		find_frames(ob_arm, fra); | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (flag & ARM_RESTPOS) { | 
					
						
							|  |  |  | 			arm->flag &= ~ARM_RESTPOS; | 
					
						
							|  |  |  | 			where_is_pose(scene, ob_arm); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (fra.size()) { | 
					
						
							|  |  |  | 			//int total = fra.back() - fra.front();
 | 
					
						
							|  |  |  | 			float *values = (float*)MEM_callocN(sizeof(float) * 16 * fra.size(), "temp. anim frames"); | 
					
						
							|  |  |  | 			sample_animation(values, fra, bone, ob_arm, pchan); | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			dae_baked_animation(fra ,values, id_name(ob_arm), bone->name ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-08-07 19:22:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (flag & ARM_RESTPOS)  | 
					
						
							|  |  |  | 			arm->flag = flag; | 
					
						
							|  |  |  | 		where_is_pose(scene, ob_arm); | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	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; | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  |         //Fill frame array with key frame values framed at @param:transform_type
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		switch (transform_type) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 			find_rotation_frames(ob_arm, fra, prefix, pchan->rotmode); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 1: | 
					
						
							|  |  |  | 			find_frames(ob_arm, fra, prefix, "scale"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 2: | 
					
						
							|  |  |  | 			find_frames(ob_arm, fra, prefix, "location"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// exit rest position
 | 
					
						
							|  |  |  | 		if (flag & ARM_RESTPOS) { | 
					
						
							|  |  |  | 			arm->flag &= ~ARM_RESTPOS; | 
					
						
							|  |  |  | 			where_is_pose(scene, ob_arm); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  |         //v array will hold all values which will be exported. 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		if (fra.size()) { | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			float *values = (float*)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames"); | 
					
						
							|  |  |  | 			sample_animation(values, fra, transform_type, bone, ob_arm, pchan); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			if (transform_type == 0) { | 
					
						
							|  |  |  | 				// write x, y, z curves separately if it is rotation
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 				float *axisValues = (float*)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");    | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				for (int i = 0; i < 3; i++) { | 
					
						
							|  |  |  | 					for (unsigned int j = 0; j < fra.size(); j++) | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 						axisValues[j] = values[j * 3 + i]; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 					dae_bone_animation(fra, axisValues, transform_type, i, id_name(ob_arm), bone->name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 				MEM_freeN(axisValues); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				// write xyz at once if it is location or scale
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 				dae_bone_animation(fra, values, transform_type, -1, id_name(ob_arm), bone->name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			MEM_freeN(values); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// restore restpos
 | 
					
						
							|  |  |  | 		if (flag & ARM_RESTPOS)  | 
					
						
							|  |  |  | 			arm->flag = flag; | 
					
						
							|  |  |  | 		where_is_pose(scene, ob_arm); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 	void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, 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; | 
					
						
							| 
									
										
										
										
											2011-08-07 19:22:39 +00:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 		enable_fcurves(ob_arm->adt->action, bone->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			//BKE_animsys_evaluate_animdata(&ob_arm->id, ob_arm->adt, *it, ADT_RECALC_ANIM);
 | 
					
						
							| 
									
										
										
										
											2011-08-06 06:11:31 +00:00
										 |  |  | 			BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM); | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 			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); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  | 			for ( int i = 0; i < 4 ; i++) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				for ( int k = 0;  k<4 ; k++ ) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					v[j*16 + 4*i + k] = mat[i][k]; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				 | 
					
						
							|  |  |  | 			}   | 
					
						
							|  |  |  | 		//	copy_m4_m4(v[j*16 + i], mat ) ;
 | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			j++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		enable_fcurves(ob_arm->adt->action, NULL); | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 	void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		bPoseChannel *parchan = NULL; | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		bPose *pose = ob_arm->pose; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		pchan = get_pose_channel(pose, bone->name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-24 20:27:27 +00:00
										 |  |  | 			//BKE_animsys_evaluate_animdata(&ob_arm->id, ob_arm->adt, *it, ADT_RECALC_ANIM);
 | 
					
						
							|  |  |  | 			//BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			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; | 
					
						
							|  |  |  | 			case 1: | 
					
						
							|  |  |  | 				mat4_to_size(v, mat); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 2: | 
					
						
							|  |  |  | 				copy_v3_v3(v, mat[3]); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			v += 3; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		enable_fcurves(ob_arm->adt->action, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 	void AnimationExporter::dae_baked_animation(std::vector<float> &fra, float *values, std::string ob_name, std::string 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( values, fra.size(), 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(ob_name + "_" + bone_name) + "/transform"; | 
					
						
							|  |  |  | 		addChannel(COLLADABU::URI(empty, sampler_id), target); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		closeAnimation(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	// dae_bone_animation -> add_bone_animation
 | 
					
						
							|  |  |  | 	// (blend this into dae_bone_animation)
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 	void AnimationExporter::dae_bone_animation(std::vector<float> &fra, float *values, int tm_type, int axis, std::string ob_name, std::string bone_name) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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) | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			output_id = create_xyz_source(values, fra.size(), anim_id); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, values, fra.size(), is_rot, anim_id, axis_name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		// create interpolations source
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, axis_name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		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) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 		return COLLADABU::Math::Utils::radToDegF(angle); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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: | 
					
						
							|  |  |  | 			return OUTPUT_SOURCE_ID_SUFFIX; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::INTERPOLATION: | 
					
						
							|  |  |  | 			return INTERPOLATION_SOURCE_ID_SUFFIX; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::IN_TANGENT: | 
					
						
							|  |  |  | 			return INTANGENT_SOURCE_ID_SUFFIX; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::OUT_TANGENT: | 
					
						
							|  |  |  | 			return OUTTANGENT_SOURCE_ID_SUFFIX; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return ""; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param, | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 							   COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		switch(semantic) { | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::INPUT: | 
					
						
							|  |  |  | 			param.push_back("TIME"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::OUTPUT: | 
					
						
							|  |  |  | 			if (is_rot) { | 
					
						
							|  |  |  | 				param.push_back("ANGLE"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				if (axis) { | 
					
						
							|  |  |  | 					param.push_back(axis); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 				else  | 
					
						
							|  |  |  | 				if ( transform ) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					param.push_back("TRANSFORM");   | 
					
						
							|  |  |  | 				}else{                           //assumes if axis isn't specified all axises are added
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 					param.push_back("X"); | 
					
						
							|  |  |  | 					param.push_back("Y"); | 
					
						
							|  |  |  | 					param.push_back("Z"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::IN_TANGENT: | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::OUT_TANGENT: | 
					
						
							|  |  |  | 			param.push_back("X"); | 
					
						
							|  |  |  | 			param.push_back("Y"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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]); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::OUTPUT: | 
					
						
							|  |  |  | 			*length = 1; | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			if (rotation) { | 
					
						
							|  |  |  | 				values[0] = (bezt->vec[1][1]) * 180.0f/M_PI; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			else { | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				values[0] = bezt->vec[1][1]; | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		case COLLADASW::InputSemantic::IN_TANGENT: | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		*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
 | 
					
						
							|  |  |  | 				values[0] = 0;	 | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 				values[1] = 0; 	 | 
					
						
							|  |  |  | 		    } | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 		    else if (rotation) { | 
					
						
							|  |  |  | 				values[1] = (bezt->vec[0][1]) * 180.0f/M_PI; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 				values[1] = bezt->vec[0][1]; | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		case COLLADASW::InputSemantic::OUT_TANGENT: | 
					
						
							|  |  |  | 			*length = 2; | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			values[0] = convert_time(bezt->vec[2][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
 | 
					
						
							|  |  |  | 				values[0] = 0;	 | 
					
						
							|  |  |  | 				values[1] = 0;	 | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			else if (rotation) { | 
					
						
							| 
									
										
										
										
											2011-07-04 15:33:39 +00:00
										 |  |  | 				values[1] = (bezt->vec[2][1]) * 180.0f/M_PI; | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 				values[1] = bezt->vec[2][1]; | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//bool is_rotation = !strcmp(fcu->rna_path, "rotation");
 | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		bool is_angle = false; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-07-06 18:34:01 +00:00
										 |  |  | 		if (strstr(fcu->rna_path, "rotation")) is_angle = true; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		COLLADASW::FloatSourceF source(mSW); | 
					
						
							|  |  |  | 		source.setId(source_id); | 
					
						
							|  |  |  | 		source.setArrayId(source_id + ARRAY_ID_SUFFIX); | 
					
						
							|  |  |  | 		source.setAccessorCount(fcu->totvert); | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		switch (semantic) { | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::INPUT: | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::OUTPUT: | 
					
						
							|  |  |  | 		source.setAccessorStride(1);			 | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::IN_TANGENT: | 
					
						
							|  |  |  | 		case COLLADASW::InputSemantic::OUT_TANGENT: | 
					
						
							|  |  |  | 		source.setAccessorStride(2);			 | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 		add_source_parameters(param, semantic, is_angle, axis_name, false); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (unsigned int i = 0; i < fcu->totvert; i++) { | 
					
						
							|  |  |  | 			float values[3]; // be careful!
 | 
					
						
							|  |  |  | 			int length = 0; | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 			get_source_values(&fcu->bezt[i], semantic, is_angle, values, &length); | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 				for (int j = 0; j < length; j++) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				source.appendValues(values[j]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  |     //Currently called only to get OUTPUT source values ( if rotation and hence the axis is also specified )
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	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(); | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 		add_source_parameters(param, semantic, is_rot, axis_name,  false); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < tot; i++) { | 
					
						
							|  |  |  | 			float val = v[i]; | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			////if (semantic == COLLADASW::InputSemantic::INPUT)
 | 
					
						
							|  |  |  | 			//	val = convert_time(val);
 | 
					
						
							|  |  |  | 			//else
 | 
					
						
							|  |  |  | 				if (is_rot)                        | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 				val *= 180.0f / M_PI; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			source.appendValues(val); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | // only used for sources with INPUT semantic
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	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(); | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 		add_source_parameters(param, semantic, is_rot, axis_name, false); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		std::vector<float>::iterator it; | 
					
						
							|  |  |  | 		for (it = fra.begin(); it != fra.end(); it++) { | 
					
						
							|  |  |  | 			float val = *it; | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			//if (semantic == COLLADASW::InputSemantic::INPUT)
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				val = convert_time(val); | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			/*else if (is_rot)
 | 
					
						
							|  |  |  | 				val = convert_angle(val);*/ | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			source.appendValues(val); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 	std::string AnimationExporter::create_4x4_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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		COLLADASW::Float4x4Source source(mSW); | 
					
						
							|  |  |  | 		source.setId(source_id); | 
					
						
							|  |  |  | 		source.setArrayId(source_id + ARRAY_ID_SUFFIX); | 
					
						
							|  |  |  | 		source.setAccessorCount(tot); | 
					
						
							|  |  |  | 		source.setAccessorStride(16); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList(); | 
					
						
							|  |  |  | 		add_source_parameters(param, semantic, false, NULL, false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < tot; i++) { | 
					
						
							|  |  |  | 			for ( int j  = 0 ; j < 4 ; j++ ) | 
					
						
							|  |  |  | 				source.appendValues(*(v+j*4), *(v + 4*j +1), *(v + 2 + 4*j), *(v+3 + 4*j)); | 
					
						
							|  |  |  | 			v += 16; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 	// only used for sources with OUTPUT semantic ( locations and scale)
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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(); | 
					
						
							| 
									
										
										
										
											2011-08-05 18:32:39 +00:00
										 |  |  | 		add_source_parameters(param, semantic, false, NULL, false); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		source.prepareToAppendValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < tot; i++) { | 
					
						
							|  |  |  | 			source.appendValues(*v, *(v + 1), *(v + 2)); | 
					
						
							|  |  |  | 			v += 3; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 	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); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		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(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	std::string AnimationExporter::fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		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); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		source.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return source_id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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; | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  |         bool is_rotation =false; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		// when given rna_path, determine tm_type from it
 | 
					
						
							|  |  |  | 		if (rna_path) { | 
					
						
							|  |  |  | 			char *name = extract_transform_name(rna_path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 			if (!strcmp(name, "rotation_euler")) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				tm_type = 0; | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 			else if (!strcmp(name, "rotation_quaternion")) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				tm_type = 1; | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 			else if (!strcmp(name, "scale")) | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				tm_type = 2; | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 			else if (!strcmp(name, "location")) | 
					
						
							|  |  |  | 				tm_type = 3; | 
					
						
							| 
									
										
										
										
											2011-07-02 05:05:03 +00:00
										 |  |  | 			else if (!strcmp(name, "color")) | 
					
						
							|  |  |  | 				tm_type = 4; | 
					
						
							| 
									
										
										
										
											2011-07-04 15:33:39 +00:00
										 |  |  | 			else if (!strcmp(name, "spot_size")) | 
					
						
							|  |  |  | 				tm_type = 5; | 
					
						
							|  |  |  | 			else if (!strcmp(name, "spot_blend")) | 
					
						
							|  |  |  | 				tm_type = 6; | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 			else if (!strcmp(name, "lens")) | 
					
						
							|  |  |  | 				tm_type = 7; | 
					
						
							| 
									
										
										
										
											2011-07-06 19:00:40 +00:00
										 |  |  |             else if (!strcmp(name, "ortho_scale")) | 
					
						
							|  |  |  | 				tm_type = 8; | 
					
						
							| 
									
										
										
										
											2011-07-31 05:04:12 +00:00
										 |  |  | 			else if (!strcmp(name, "clip_end")) | 
					
						
							| 
									
										
										
										
											2011-07-07 18:40:46 +00:00
										 |  |  | 				tm_type = 9; | 
					
						
							| 
									
										
										
										
											2011-07-31 05:04:12 +00:00
										 |  |  | 			else if (!strcmp(name, "clip_start")) | 
					
						
							| 
									
										
										
										
											2011-07-09 15:15:17 +00:00
										 |  |  | 				tm_type = 10; | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 			else if (!strcmp(name, "specular_hardness")) | 
					
						
							|  |  |  | 				tm_type = 11; | 
					
						
							| 
									
										
										
										
											2011-07-27 16:29:28 +00:00
										 |  |  | 			else if (!strcmp(name, "specular_color")) | 
					
						
							|  |  |  | 				tm_type = 12; | 
					
						
							| 
									
										
										
										
											2011-07-27 18:38:44 +00:00
										 |  |  | 			else if (!strcmp(name, "diffuse_color")) | 
					
						
							|  |  |  | 				tm_type = 13; | 
					
						
							| 
									
										
										
										
											2011-07-28 18:25:23 +00:00
										 |  |  | 			else if (!strcmp(name, "alpha")) | 
					
						
							|  |  |  | 				tm_type = 14; | 
					
						
							| 
									
										
										
										
											2011-08-06 06:11:31 +00:00
										 |  |  | 			else if (!strcmp(name, "ior")) | 
					
						
							|  |  |  | 				tm_type = 15; | 
					
						
							| 
									
										
										
										
											2011-07-09 15:15:17 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			else | 
					
						
							|  |  |  | 				tm_type = -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		switch (tm_type) { | 
					
						
							|  |  |  | 		case 0: | 
					
						
							|  |  |  | 		case 1: | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 			tm_name = "rotation"; | 
					
						
							|  |  |  | 			is_rotation = true; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 	    case 2: | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			tm_name = "scale"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-06-05 18:58:22 +00:00
										 |  |  | 		case 3: | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			tm_name = "location"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-02 05:05:03 +00:00
										 |  |  | 		case 4: | 
					
						
							|  |  |  | 			tm_name = "color"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-04 15:33:39 +00:00
										 |  |  | 		case 5: | 
					
						
							|  |  |  | 			tm_name = "fall_off_angle"; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case 6: | 
					
						
							|  |  |  | 			tm_name = "fall_off_exponent"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 		case 7: | 
					
						
							|  |  |  | 			tm_name = "xfov"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-06 19:00:40 +00:00
										 |  |  | 		case 8: | 
					
						
							|  |  |  | 			tm_name = "xmag"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-07 18:40:46 +00:00
										 |  |  | 		case 9: | 
					
						
							|  |  |  | 			tm_name = "zfar"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-09 15:15:17 +00:00
										 |  |  | 		case 10: | 
					
						
							|  |  |  | 			tm_name = "znear"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-18 17:33:03 +00:00
										 |  |  | 		case 11: | 
					
						
							|  |  |  | 			tm_name = "shininess"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-27 16:29:28 +00:00
										 |  |  | 		case 12: | 
					
						
							|  |  |  | 			tm_name = "specular"; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2011-07-27 18:38:44 +00:00
										 |  |  | 		case 13: | 
					
						
							|  |  |  | 			tm_name = "diffuse"; | 
					
						
							|  |  |  | 			break;	 | 
					
						
							| 
									
										
										
										
											2011-07-28 18:25:23 +00:00
										 |  |  | 		case 14: | 
					
						
							|  |  |  | 			tm_name = "transparency"; | 
					
						
							|  |  |  | 			break;	 | 
					
						
							| 
									
										
										
										
											2011-08-06 06:11:31 +00:00
										 |  |  | 		case 15: | 
					
						
							|  |  |  | 			tm_name = "index_of_refraction"; | 
					
						
							|  |  |  | 			break;	 | 
					
						
							| 
									
										
										
										
											2011-07-28 18:25:23 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		default: | 
					
						
							|  |  |  | 			tm_name = ""; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (tm_name.size()) { | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 			if (is_rotation) | 
					
						
							|  |  |  | 				return tm_name + std::string(axis_name); | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			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; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 	void AnimationExporter::find_all_frames(Object *ob, std::vector<float> &fra) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		FCurve *fcu= (FCurve*)ob->adt->action->curves.first; | 
					
						
							|  |  |  | 		std::vector<float> keys; | 
					
						
							|  |  |  | 		for (unsigned int i = 0; i < fcu->totvert; i++) { | 
					
						
							|  |  |  | 					float f = fcu->bezt[i].vec[1][0];     //
 | 
					
						
							|  |  |  | 					if (std::find(keys.begin(), keys.end(), f) == keys.end())    | 
					
						
							|  |  |  | 						keys.push_back(f); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		std::sort(keys.begin(), keys.end()); | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 		float first, last; | 
					
						
							|  |  |  | 		std::vector<float>::reference ref = keys.front(); | 
					
						
							|  |  |  | 		first = ref; | 
					
						
							|  |  |  | 		ref = keys.back(); | 
					
						
							|  |  |  | 		last = ref; | 
					
						
							|  |  |  | 		for (float i = first ; i != last ; i+=1.0f ) | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2011-08-05 17:19:31 +00:00
										 |  |  | 			fra.push_back(i);  | 
					
						
							| 
									
										
										
										
											2011-08-03 19:12:18 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-08-07 18:15:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	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); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// keep the keys in ascending order
 | 
					
						
							|  |  |  | 		std::sort(fra.begin(), fra.end()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 	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++) { | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 					float f = fcu->bezt[i].vec[1][0];     //
 | 
					
						
							|  |  |  | 					if (std::find(fra.begin(), fra.end(), f) == fra.end())    | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 						fra.push_back(f); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// keep the keys in ascending order
 | 
					
						
							|  |  |  | 		std::sort(fra.begin(), fra.end()); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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)
 | 
					
						
							|  |  |  | 			;*/ | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// 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 | 
					
						
							|  |  |  | 					fcu->flag |= FCURVE_DISABLED; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else { | 
					
						
							|  |  |  | 				fcu->flag &= ~FCURVE_DISABLED; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	bool AnimationExporter::hasAnimations(Scene *sce) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		Base *base= (Base*) sce->base.first; | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 		while(base) { | 
					
						
							|  |  |  | 			Object *ob = base->object; | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			FCurve *fcu = 0; | 
					
						
							| 
									
										
										
										
											2011-05-29 19:27:30 +00:00
										 |  |  | 			if(ob->adt && ob->adt->action)       | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 				fcu = (FCurve*)ob->adt->action->curves.first; | 
					
						
							| 
									
										
										
										
											2011-06-30 18:24:45 +00:00
										 |  |  | 			else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action ) | 
					
						
							|  |  |  | 				fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first); | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 			else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action ) | 
					
						
							|  |  |  | 				fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first); | 
					
						
							| 
									
										
										
										
											2011-07-17 17:30:41 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 		    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;	 | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-06 17:41:14 +00:00
										 |  |  | 			if ( fcu) return true; | 
					
						
							| 
									
										
										
										
											2011-05-26 17:07:38 +00:00
										 |  |  | 			base= base->next; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} |