Merging pepper to trunk at revision 39791.
[blender.git] / source / blender / collada / AnimationExporter.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed.
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include "GeometryExporter.h"
26 #include "AnimationExporter.h"
27 #include "MaterialExporter.h"
28
29 template<class Functor>
30 void forEachObjectInScene(Scene *sce, Functor &f)
31 {
32         Base *base= (Base*) sce->base.first;
33         
34         while(base) {
35                 Object *ob = base->object;
36                         
37                 f(ob);
38
39                 base= base->next;
40         }
41 }
42
43 void AnimationExporter::exportAnimations(Scene *sce)
44 {
45         if(hasAnimations(sce)) {
46                 this->scene = sce;
47
48                 openLibrary();
49
50                 forEachObjectInScene(sce, *this);
51
52                 closeLibrary();
53         }
54 }
55
56 // called for each exported object
57 void AnimationExporter::operator() (Object *ob) 
58 {
59         FCurve *fcu;
60         char * transformName ;
61         bool isMatAnim = false;
62
63         //Export transform animations
64         if(ob->adt && ob->adt->action)      
65         {
66                 fcu = (FCurve*)ob->adt->action->curves.first;
67
68                 //transform matrix export for bones are temporarily disabled here.
69                 if ( ob->type == OB_ARMATURE )
70                 {
71                         bArmature *arm = (bArmature*)ob->data;
72                         for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
73                                 write_bone_animation_matrix(ob, bone);
74                 }
75                 
76                 while (fcu) {
77                         //for armature animations as objects
78                         if ( ob->type == OB_ARMATURE )
79                                 transformName =  fcu->rna_path;
80                         else 
81                                 transformName = extract_transform_name( fcu->rna_path );
82                 
83                         if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
84                                 (!strcmp(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL)||
85                                 (!strcmp(transformName, "rotation_quaternion"))) 
86                                 dae_animation(ob ,fcu, transformName, false);
87                         fcu = fcu->next;
88                 }
89         
90         }
91
92         //Export Lamp parameter animations
93         if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
94         {
95                 fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
96                 while (fcu) {
97                 transformName = extract_transform_name( fcu->rna_path );
98                         
99                         if ((!strcmp(transformName, "color")) || (!strcmp(transformName, "spot_size"))|| (!strcmp(transformName, "spot_blend"))||
100                                 (!strcmp(transformName, "distance")) ) 
101                                 dae_animation(ob , fcu, transformName, true );
102                         fcu = fcu->next;
103                 }
104         }
105
106         //Export Camera parameter animations
107         if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
108         {               
109                 fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
110                 while (fcu) {
111                 transformName = extract_transform_name( fcu->rna_path );
112                         
113                         if ((!strcmp(transformName, "lens"))||
114                                 (!strcmp(transformName, "ortho_scale"))||
115                                 (!strcmp(transformName, "clip_end"))||(!strcmp(transformName, "clip_start"))) 
116                                 dae_animation(ob , fcu, transformName, true );
117                         fcu = fcu->next;
118                 }
119         }
120
121         //Export Material parameter animations.
122         for(int a = 0; a < ob->totcol; a++)
123         {
124                 Material *ma = give_current_material(ob, a+1);
125                 if (!ma) continue;
126                 if(ma->adt && ma->adt->action)
127                 {
128                         isMatAnim = true;
129                         fcu = (FCurve*)ma->adt->action->curves.first;
130                         while (fcu) {
131                                 transformName = extract_transform_name( fcu->rna_path );
132                                 
133                                 if ((!strcmp(transformName, "specular_hardness"))||(!strcmp(transformName, "specular_color"))
134                                         ||(!strcmp(transformName, "diffuse_color"))||(!strcmp(transformName, "alpha"))||
135                                         (!strcmp(transformName, "ior"))) 
136                                         dae_animation(ob ,fcu, transformName, true, ma );
137                                 fcu = fcu->next;
138                         }
139                 }
140                 
141         }
142 }
143
144         //euler sources from quternion sources
145         float * AnimationExporter::get_eul_source_for_quat(Object *ob )
146         {
147                 FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
148                 const int keys = fcu->totvert;  
149                 float *quat = (float*)MEM_callocN(sizeof(float) * fcu->totvert * 4, "quat output source values");  
150                 float *eul = (float*)MEM_callocN(sizeof(float) * fcu->totvert * 3, "quat output source values");
151                 float temp_quat[4];
152                 float temp_eul[3];
153                         while(fcu)
154                         {
155                                 char * transformName = extract_transform_name( fcu->rna_path );
156                                 
157                                 if( !strcmp(transformName, "rotation_quaternion") )     { 
158                                         for ( int i = 0 ; i < fcu->totvert ; i++){
159                                                 *(quat + ( i * 4 ) + fcu->array_index) = fcu->bezt[i].vec[1][1];
160                                         }
161                                 }
162                                         fcu = fcu->next;
163                         }
164
165                         for ( int i = 0 ; i < keys ; i++){
166                                 for ( int j = 0;j<4;j++)
167                                         temp_quat[j] = quat[(i*4)+j];
168
169                                 quat_to_eul(temp_eul,temp_quat);
170
171                                 for (int k = 0;k<3;k++)
172                                         eul[i*3 + k] = temp_eul[k];
173
174                         }
175         MEM_freeN(quat);
176                 return eul;
177
178         }
179
180         //Get proper name for bones
181         std::string AnimationExporter::getObjectBoneName( Object* ob,const FCurve* fcu ) 
182         {
183                 //hard-way to derive the bone name from rna_path. Must find more compact method
184                 std::string rna_path = std::string(fcu->rna_path);
185
186                 char* boneName = strtok((char *)rna_path.c_str(), "\"");
187                 boneName = strtok(NULL,"\"");
188                 
189                 if( boneName != NULL )
190                         return /*id_name(ob) + "_" +*/ std::string(boneName);
191                 else            
192                         return id_name(ob);
193         }
194
195         //convert f-curves to animation curves and write
196         void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformName , bool is_param, Material * ma )
197         {
198                 const char *axis_name = NULL;
199                 char anim_id[200];
200                 
201                 bool has_tangents = false;
202                 bool quatRotation = false;
203                 
204                 if ( !strcmp(transformName, "rotation_quaternion") )
205                 {
206                         fprintf(stderr, "quaternion rotation curves are not supported. rotation curve will not be exported\n");
207                         quatRotation = true;
208                         return;
209                 }
210                 
211                 //axis names for colors
212                 else if ( !strcmp(transformName, "color")||!strcmp(transformName, "specular_color")||!strcmp(transformName, "diffuse_color")||
213                                   (!strcmp(transformName, "alpha")))
214                 {
215                         const char *axis_names[] = {"R", "G", "B"};
216                         if (fcu->array_index < 3)
217                         axis_name = axis_names[fcu->array_index];
218                 }
219
220                 //axis names for transforms
221                 else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
222                                 (!strcmp(transformName, "rotation_euler"))||(!strcmp(transformName, "rotation_quaternion")))
223                 {
224                         const char *axis_names[] = {"X", "Y", "Z"};
225                         if (fcu->array_index < 3)
226                         axis_name = axis_names[fcu->array_index];
227                 }
228
229                 //no axis name. single parameter.
230                 else{
231                         axis_name = "";
232                 }
233                 
234                 std::string ob_name = std::string("null");
235
236                 //Create anim Id
237                 if (ob->type == OB_ARMATURE) 
238                 {   
239                         ob_name =  getObjectBoneName( ob , fcu);
240                         BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s.%s", (char*)translate_id(ob_name).c_str(),
241                                 transformName, axis_name);
242                 }
243                 else 
244                 {
245                         if (ma)
246                                 ob_name = id_name(ob) + "_material";
247                         else
248                                 ob_name = id_name(ob);
249                         BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
250                                  fcu->rna_path, axis_name);
251                 }
252                 
253                 openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
254
255                 // create input source
256                 std::string input_id = create_source_from_fcurve(COLLADASW::InputSemantic::INPUT, fcu, anim_id, axis_name);
257
258                 // create output source
259                 std::string output_id ;
260                 
261                 //quat rotations are skipped for now, because of complications with determining axis.
262                 if(quatRotation) 
263                 {
264                         float * eul  = get_eul_source_for_quat(ob);
265                         float * eul_axis = (float*)MEM_callocN(sizeof(float) * fcu->totvert, "quat output source values");
266                                 for ( int i = 0 ; i< fcu->totvert ; i++)
267                                         eul_axis[i] = eul[i*3 + fcu->array_index];
268                         output_id= create_source_from_array(COLLADASW::InputSemantic::OUTPUT, eul_axis , fcu->totvert, quatRotation, anim_id, axis_name);
269                         MEM_freeN(eul);
270                         MEM_freeN(eul_axis);
271                 }
272                 else 
273                 {
274                         output_id= create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name);
275                 }
276                 // create interpolations source
277                 std::string interpolation_id = create_interpolation_source(fcu, anim_id, axis_name, &has_tangents);
278
279                 // handle tangents (if required)
280                 std::string intangent_id;
281                 std::string outtangent_id;
282                 
283                 if (has_tangents) {
284                         // create in_tangent source
285                         intangent_id = create_source_from_fcurve(COLLADASW::InputSemantic::IN_TANGENT, fcu, anim_id, axis_name);
286
287                         // create out_tangent source
288                         outtangent_id = create_source_from_fcurve(COLLADASW::InputSemantic::OUT_TANGENT, fcu, anim_id, axis_name);
289                 }
290
291                 std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
292                 COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
293                 std::string empty;
294                 sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
295                 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
296
297                 // this input is required
298                 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
299
300                 if (has_tangents) {
301                         sampler.addInput(COLLADASW::InputSemantic::IN_TANGENT, COLLADABU::URI(empty, intangent_id));
302                         sampler.addInput(COLLADASW::InputSemantic::OUT_TANGENT, COLLADABU::URI(empty, outtangent_id));
303                 }
304
305                 addSampler(sampler);
306
307                 std::string target ;
308
309                 if ( !is_param )
310                         target = translate_id(ob_name)
311                         + "/" + get_transform_sid(fcu->rna_path, -1, axis_name, true);
312                 else 
313                 {
314                         if ( ob->type == OB_LAMP )
315                                 target = get_light_id(ob)
316                                 + "/" + get_light_param_sid(fcu->rna_path, -1, axis_name, true);
317
318                         if ( ob->type == OB_CAMERA )
319                                 target = get_camera_id(ob)
320                                 + "/" + get_camera_param_sid(fcu->rna_path, -1, axis_name, true);
321
322                         if( ma ) 
323                                 target = translate_id(id_name(ma)) + "-effect"
324                                                 +"/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true);
325                 }
326                 addChannel(COLLADABU::URI(empty, sampler_id), target);
327
328                 closeAnimation();
329         }
330
331
332         
333         //write bone animations in transform matrix sources
334         void AnimationExporter::write_bone_animation_matrix(Object *ob_arm, Bone *bone)
335         {
336                 if (!ob_arm->adt)
337                         return;
338                 
339                 //This will only export animations of bones in deform group.
340                 /*if(!is_bone_deform_group(bone))
341                         return;*/
342                 
343                 sample_and_write_bone_animation_matrix(ob_arm, bone);
344
345                 for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
346                         write_bone_animation_matrix(ob_arm, child);
347         }
348
349         bool AnimationExporter::is_bone_deform_group(Bone * bone)
350         {   
351                 bool is_def;
352                 //Check if current bone is deform
353                 if((bone->flag & BONE_NO_DEFORM) == 0 ) return true;
354                 //Check child bones
355                 else 
356                 {   
357                         for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next){
358                                 //loop through all the children until deform bone is found, and then return
359                                 is_def = is_bone_deform_group(child);
360                                 if (is_def) return true;
361                         }
362                 }
363         //no deform bone found in children also
364                 return false;
365         }
366
367         void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
368         {
369                 bArmature *arm = (bArmature*)ob_arm->data;
370                 int flag = arm->flag;
371                 std::vector<float> fra;
372                 //char prefix[256];
373
374                 FCurve* fcu = (FCurve*)ob_arm->adt->action->curves.first;
375                 while(fcu)
376                 {
377                         std::string bone_name = getObjectBoneName(ob_arm,fcu);
378                         int val = BLI_strcasecmp((char*)bone_name.c_str(),bone->name);
379                         if(val==0) break;
380                         fcu = fcu->next;
381                 }
382
383                 if(!(fcu)) return; 
384                 bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
385                 if (!pchan)
386                         return;
387         
388                 find_frames(ob_arm, fra);
389
390                 if (flag & ARM_RESTPOS) {
391                         arm->flag &= ~ARM_RESTPOS;
392                         where_is_pose(scene, ob_arm);
393                 }
394
395                 if (fra.size()) {
396                         dae_baked_animation(fra ,ob_arm, bone );
397                 }
398
399                 if (flag & ARM_RESTPOS) 
400                         arm->flag = flag;
401                 where_is_pose(scene, ob_arm);
402         }
403
404         void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm , Bone *bone)
405         {
406                 std::string ob_name = id_name(ob_arm);
407                 std::string bone_name = bone->name;
408                 char anim_id[200];
409                 
410                 if (!fra.size())
411                         return;
412
413                 BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
414                                          (char*)translate_id(bone_name).c_str(), "pose_matrix");
415
416                 openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
417
418                 // create input source
419                 std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, fra, false, anim_id, "");
420
421                 // create output source
422                 std::string output_id;
423                 output_id = create_4x4_source( fra, ob_arm , bone ,  anim_id);
424
425                 // create interpolations source
426                 std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, "");
427
428                 std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
429                 COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
430                 std::string empty;
431                 sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
432                 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
433
434                 // TODO create in/out tangents source
435
436                 // this input is required
437                 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
438
439                 addSampler(sampler);
440
441                 std::string target = translate_id(bone_name) + "/transform";
442                 addChannel(COLLADABU::URI(empty, sampler_id), target);
443
444                 closeAnimation();
445         }
446
447         // dae_bone_animation -> add_bone_animation
448         // (blend this into dae_bone_animation)
449         void AnimationExporter::dae_bone_animation(std::vector<float> &fra, float *values, int tm_type, int axis, std::string ob_name, std::string bone_name)
450         {
451                 const char *axis_names[] = {"X", "Y", "Z"};
452                 const char *axis_name = NULL;
453                 char anim_id[200];
454                 bool is_rot = tm_type == 0;
455                 
456                 if (!fra.size())
457                         return;
458
459                 char rna_path[200];
460                 BLI_snprintf(rna_path, sizeof(rna_path), "pose.bones[\"%s\"].%s", bone_name.c_str(),
461                                          tm_type == 0 ? "rotation_quaternion" : (tm_type == 1 ? "scale" : "location"));
462
463                 if (axis > -1)
464                         axis_name = axis_names[axis];
465                 
466                 std::string transform_sid = get_transform_sid(NULL, tm_type, axis_name, false);
467                 
468                 BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
469                                          (char*)translate_id(bone_name).c_str(), (char*)transform_sid.c_str());
470
471                 openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
472
473                 // create input source
474                 std::string input_id = create_source_from_vector(COLLADASW::InputSemantic::INPUT, fra, is_rot, anim_id, axis_name);
475
476                 // create output source
477                 std::string output_id;
478                 if (axis == -1)
479                         output_id = create_xyz_source(values, fra.size(), anim_id);
480                 else
481                         output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, values, fra.size(), is_rot, anim_id, axis_name);
482
483                 // create interpolations source
484                 std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, axis_name);
485
486                 std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
487                 COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
488                 std::string empty;
489                 sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(empty, input_id));
490                 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(empty, output_id));
491
492                 // TODO create in/out tangents source
493
494                 // this input is required
495                 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION, COLLADABU::URI(empty, interpolation_id));
496
497                 addSampler(sampler);
498
499                 std::string target = translate_id(ob_name + "_" + bone_name) + "/" + transform_sid;
500                 addChannel(COLLADABU::URI(empty, sampler_id), target);
501
502                 closeAnimation();
503         }
504
505         float AnimationExporter::convert_time(float frame)
506         {
507                 return FRA2TIME(frame);
508         }
509
510         float AnimationExporter::convert_angle(float angle)
511         {
512                 return COLLADABU::Math::Utils::radToDegF(angle);
513         }
514
515         std::string AnimationExporter::get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic)
516         {
517                 switch(semantic) {
518                 case COLLADASW::InputSemantic::INPUT:
519                         return INPUT_SOURCE_ID_SUFFIX;
520                 case COLLADASW::InputSemantic::OUTPUT:
521                         return OUTPUT_SOURCE_ID_SUFFIX;
522                 case COLLADASW::InputSemantic::INTERPOLATION:
523                         return INTERPOLATION_SOURCE_ID_SUFFIX;
524                 case COLLADASW::InputSemantic::IN_TANGENT:
525                         return INTANGENT_SOURCE_ID_SUFFIX;
526                 case COLLADASW::InputSemantic::OUT_TANGENT:
527                         return OUTTANGENT_SOURCE_ID_SUFFIX;
528                 default:
529                         break;
530                 }
531                 return "";
532         }
533
534         void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param,
535                                                            COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform)
536         {
537                 switch(semantic) {
538                 case COLLADASW::InputSemantic::INPUT:
539                         param.push_back("TIME");
540                         break;
541                 case COLLADASW::InputSemantic::OUTPUT:
542                         if (is_rot) {
543                                 param.push_back("ANGLE");
544                         }
545                         else {
546                                 if (axis) {
547                                         param.push_back(axis);
548                                 }
549                                 else 
550                                 if ( transform )
551                                 {
552                                         param.push_back("TRANSFORM");  
553                                 }else{                           //assumes if axis isn't specified all axises are added
554                                         param.push_back("X");
555                                         param.push_back("Y");
556                                         param.push_back("Z");
557                                 }
558                         }
559                         break;
560                 case COLLADASW::InputSemantic::IN_TANGENT:
561                 case COLLADASW::InputSemantic::OUT_TANGENT:
562                         param.push_back("X");
563                         param.push_back("Y");
564                         break;
565                 default:
566                         break;
567                 }
568         }
569
570         void AnimationExporter::get_source_values(BezTriple *bezt, COLLADASW::InputSemantic::Semantics semantic, bool rotation, float *values, int *length)
571         {
572                 switch (semantic) {
573                 case COLLADASW::InputSemantic::INPUT:
574                         *length = 1;
575                         values[0] = convert_time(bezt->vec[1][0]);
576                         break;
577                 case COLLADASW::InputSemantic::OUTPUT:
578                         *length = 1;
579                         if (rotation) {
580                                 values[0] = (bezt->vec[1][1]) * 180.0f/M_PI;
581                         }
582                         else {
583                                 values[0] = bezt->vec[1][1];
584                         }
585                         break;
586                 
587                 case COLLADASW::InputSemantic::IN_TANGENT:
588                 *length = 2;
589                         values[0] = convert_time(bezt->vec[0][0]);
590                         if (bezt->ipo != BEZT_IPO_BEZ) {
591                                 // We're in a mixed interpolation scenario, set zero as it's irrelevant but value might contain unused data
592                                 values[0] = 0;  
593                                 values[1] = 0;  
594                         }
595                         else if (rotation) {
596                                 values[1] = (bezt->vec[0][1]) * 180.0f/M_PI;
597                         } else {
598                                 values[1] = bezt->vec[0][1];
599                         }
600                         break;
601                 
602                 case COLLADASW::InputSemantic::OUT_TANGENT:
603                         *length = 2;
604                         values[0] = convert_time(bezt->vec[2][0]);
605                         if (bezt->ipo != BEZT_IPO_BEZ) {
606                                 // We're in a mixed interpolation scenario, set zero as it's irrelevant but value might contain unused data
607                                 values[0] = 0;  
608                                 values[1] = 0;  
609                         }
610                         else if (rotation) {
611                                 values[1] = (bezt->vec[2][1]) * 180.0f/M_PI;
612                         } else {
613                                 values[1] = bezt->vec[2][1];
614                         }
615                         break;
616                         break;
617                 default:
618                         *length = 0;
619                         break;
620                 }
621         }
622
623         std::string AnimationExporter::create_source_from_fcurve(COLLADASW::InputSemantic::Semantics semantic, FCurve *fcu, const std::string& anim_id, const char *axis_name)
624         {
625                 std::string source_id = anim_id + get_semantic_suffix(semantic);
626
627                 //bool is_rotation = !strcmp(fcu->rna_path, "rotation");
628                 bool is_angle = false;
629                 
630                 if (strstr(fcu->rna_path, "rotation")) is_angle = true;
631                 
632                 COLLADASW::FloatSourceF source(mSW);
633                 source.setId(source_id);
634                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
635                 source.setAccessorCount(fcu->totvert);
636                 
637                 switch (semantic) {
638                 case COLLADASW::InputSemantic::INPUT:
639                 case COLLADASW::InputSemantic::OUTPUT:
640                 source.setAccessorStride(1);                    
641                         break;
642                 case COLLADASW::InputSemantic::IN_TANGENT:
643                 case COLLADASW::InputSemantic::OUT_TANGENT:
644                 source.setAccessorStride(2);                    
645                         break;
646                 }
647                 
648                 
649                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
650                 add_source_parameters(param, semantic, is_angle, axis_name, false);
651
652                 source.prepareToAppendValues();
653
654                 for (unsigned int i = 0; i < fcu->totvert; i++) {
655                         float values[3]; // be careful!
656                         int length = 0;
657                         get_source_values(&fcu->bezt[i], semantic, is_angle, values, &length);
658                                 for (int j = 0; j < length; j++)
659                                 source.appendValues(values[j]);
660                 }
661
662                 source.finish();
663
664                 return source_id;
665         }
666
667         //Currently called only to get OUTPUT source values ( if rotation and hence the axis is also specified )
668         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)
669         {
670                 std::string source_id = anim_id + get_semantic_suffix(semantic);
671
672                 COLLADASW::FloatSourceF source(mSW);
673                 source.setId(source_id);
674                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
675                 source.setAccessorCount(tot);
676                 source.setAccessorStride(1);
677                 
678                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
679                 add_source_parameters(param, semantic, is_rot, axis_name,  false);
680
681                 source.prepareToAppendValues();
682
683                 for (int i = 0; i < tot; i++) {
684                         float val = v[i];
685                         ////if (semantic == COLLADASW::InputSemantic::INPUT)
686                         //      val = convert_time(val);
687                         //else
688                                 if (is_rot)                       
689                                 val *= 180.0f / M_PI;
690                         source.appendValues(val);
691                 }
692
693                 source.finish();
694
695                 return source_id;
696         }
697 // only used for sources with INPUT semantic
698         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)
699         {
700                 std::string source_id = anim_id + get_semantic_suffix(semantic);
701
702                 COLLADASW::FloatSourceF source(mSW);
703                 source.setId(source_id);
704                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
705                 source.setAccessorCount(fra.size());
706                 source.setAccessorStride(1);
707                 
708                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
709                 add_source_parameters(param, semantic, is_rot, axis_name, false);
710
711                 source.prepareToAppendValues();
712
713                 std::vector<float>::iterator it;
714                 for (it = fra.begin(); it != fra.end(); it++) {
715                         float val = *it;
716                         //if (semantic == COLLADASW::InputSemantic::INPUT)
717                                 val = convert_time(val);
718                         /*else if (is_rot)
719                                 val = convert_angle(val);*/
720                         source.appendValues(val);
721                 }
722
723                 source.finish();
724
725                 return source_id;
726         }
727
728         std::string AnimationExporter::create_4x4_source(std::vector<float> &frames , Object * ob_arm, Bone *bone , const std::string& anim_id)
729         {
730                 COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
731                 std::string source_id = anim_id + get_semantic_suffix(semantic);
732
733                 COLLADASW::Float4x4Source source(mSW);
734                 source.setId(source_id);
735                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
736                 source.setAccessorCount(frames.size());
737                 source.setAccessorStride(16);
738                 
739                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
740                 add_source_parameters(param, semantic, false, NULL, true);
741
742                 source.prepareToAppendValues();
743                 
744                 bPoseChannel *parchan = NULL;
745                 bPoseChannel *pchan = NULL;
746                 bPose *pose = ob_arm->pose;
747
748                 pchan = get_pose_channel(pose, bone->name);
749
750                 if (!pchan)
751                         return "";
752
753                 parchan = pchan->parent;
754
755                 enable_fcurves(ob_arm->adt->action, bone->name);
756
757                 std::vector<float>::iterator it;
758                 int j = 0;
759                 for (it = frames.begin(); it != frames.end(); it++) {
760                         float mat[4][4], ipar[4][4];
761
762                         float ctime = bsystem_time(scene, ob_arm, *it, 0.0f);
763
764                         BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
765                         where_is_pose_bone(scene, ob_arm, pchan, ctime, 1);
766
767                         // compute bone local mat
768                         if (bone->parent) {
769                                 invert_m4_m4(ipar, parchan->pose_mat);
770                                 mul_m4_m4m4(mat, pchan->pose_mat, ipar);
771                         }
772                         else
773                                 copy_m4_m4(mat, pchan->pose_mat);
774                         UnitConverter converter;
775
776                         float outmat[4][4];
777                         converter.mat4_to_dae(outmat,mat);
778
779
780                         source.appendValues(outmat);
781                         
782
783                         j++;
784                 }
785
786                 enable_fcurves(ob_arm->adt->action, NULL);
787
788                 source.finish();
789
790                 return source_id;
791         }
792         // only used for sources with OUTPUT semantic ( locations and scale)
793         std::string AnimationExporter::create_xyz_source(float *v, int tot, const std::string& anim_id)
794         {
795                 COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
796                 std::string source_id = anim_id + get_semantic_suffix(semantic);
797
798                 COLLADASW::FloatSourceF source(mSW);
799                 source.setId(source_id);
800                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
801                 source.setAccessorCount(tot);
802                 source.setAccessorStride(3);
803                 
804                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
805                 add_source_parameters(param, semantic, false, NULL, false);
806
807                 source.prepareToAppendValues();
808
809                 for (int i = 0; i < tot; i++) {
810                         source.appendValues(*v, *(v + 1), *(v + 2));
811                         v += 3;
812                 }
813
814                 source.finish();
815
816                 return source_id;
817         }
818
819         std::string AnimationExporter::create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents)
820         {
821                 std::string source_id = anim_id + get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
822
823                 COLLADASW::NameSource source(mSW);
824                 source.setId(source_id);
825                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
826                 source.setAccessorCount(fcu->totvert);
827                 source.setAccessorStride(1);
828                 
829                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
830                 param.push_back("INTERPOLATION");
831
832                 source.prepareToAppendValues();
833
834                 *has_tangents = false;
835
836                 for (unsigned int i = 0; i < fcu->totvert; i++) {
837                         if (fcu->bezt[i].ipo==BEZT_IPO_BEZ) {
838                                 source.appendValues(BEZIER_NAME);
839                                 *has_tangents = true;
840                         } else if (fcu->bezt[i].ipo==BEZT_IPO_CONST) {
841                                 source.appendValues(STEP_NAME);
842                         } else { // BEZT_IPO_LIN
843                                 source.appendValues(LINEAR_NAME);
844                         }
845                 }
846                 // unsupported? -- HERMITE, CARDINAL, BSPLINE, NURBS
847
848                 source.finish();
849
850                 return source_id;
851         }
852
853         std::string AnimationExporter::fake_interpolation_source(int tot, const std::string& anim_id, const char *axis_name)
854         {
855                 std::string source_id = anim_id + get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
856
857                 COLLADASW::NameSource source(mSW);
858                 source.setId(source_id);
859                 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
860                 source.setAccessorCount(tot);
861                 source.setAccessorStride(1);
862                 
863                 COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
864                 param.push_back("INTERPOLATION");
865
866                 source.prepareToAppendValues();
867
868                 for (int i = 0; i < tot; i++) {
869                         source.appendValues(LINEAR_NAME);
870                 }
871
872                 source.finish();
873
874                 return source_id;
875         }
876
877         std::string AnimationExporter::get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
878         {
879                 std::string tm_name;
880                 // when given rna_path, determine tm_type from it
881                 if (rna_path) {
882                         char *name = extract_transform_name(rna_path);
883
884                         if (!strcmp(name, "color"))
885                                 tm_type = 1;
886                         else if (!strcmp(name, "spot_size"))
887                                 tm_type = 2;
888                         else if (!strcmp(name, "spot_blend"))
889                                 tm_type = 3;
890                         else if (!strcmp(name, "distance"))
891                                 tm_type = 4;
892                         else
893                                 tm_type = -1;
894                 }
895
896                 switch (tm_type) {
897                 case 1:
898                         tm_name = "color";
899                         break;
900                 case 2:
901                         tm_name = "fall_off_angle";
902                         break;
903                 case 3:
904                         tm_name = "fall_off_exponent";
905                         break;
906                 case 4:
907                         tm_name = "blender/blender_dist";
908                         break;
909                 
910                 default:
911                         tm_name = "";
912                         break;
913                 }
914            
915                 if (tm_name.size()) {
916                         if (axis_name != "")
917                                 return tm_name + "." + std::string(axis_name);
918                         else 
919                                 return tm_name;
920                 }
921
922                 return std::string("");
923         }
924         
925         std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
926         {
927                 std::string tm_name;
928                 // when given rna_path, determine tm_type from it
929                 if (rna_path) {
930                         char *name = extract_transform_name(rna_path);
931
932                         if (!strcmp(name, "lens"))
933                                 tm_type = 0;
934                         else if (!strcmp(name, "ortho_scale"))
935                                 tm_type = 1;
936                         else if (!strcmp(name, "clip_end"))
937                                 tm_type = 2;
938                         else if (!strcmp(name, "clip_start"))
939                                 tm_type = 3;
940                         
941                         else
942                                 tm_type = -1;
943                 }
944
945                 switch (tm_type) {
946                 case 0:
947                         tm_name = "xfov";
948                         break;
949                 case 1:
950                         tm_name = "xmag";
951                         break;
952                 case 2:
953                         tm_name = "zfar";
954                         break;
955                 case 3:
956                         tm_name = "znear";
957                         break;
958                 
959                 default:
960                         tm_name = "";
961                         break;
962                 }
963            
964                 if (tm_name.size()) {
965                         if (axis_name != "")
966                                 return tm_name + "." + std::string(axis_name);
967                         else 
968                                 return tm_name;
969                 }
970
971                 return std::string("");
972         }
973
974         // Assign sid of the animated parameter or transform 
975         // for rotation, axis name is always appended and the value of append_axis is ignored
976         std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
977         {
978                 std::string tm_name;
979                 bool is_rotation =false;
980                 // when given rna_path, determine tm_type from it
981                 if (rna_path) {
982                         char *name = extract_transform_name(rna_path);
983
984                         if (!strcmp(name, "rotation_euler"))
985                                 tm_type = 0;
986                         else if (!strcmp(name, "rotation_quaternion"))
987                                 tm_type = 1;
988                         else if (!strcmp(name, "scale"))
989                                 tm_type = 2;
990                         else if (!strcmp(name, "location"))
991                                 tm_type = 3;
992                         else if (!strcmp(name, "specular_hardness"))
993                                 tm_type = 4;
994                         else if (!strcmp(name, "specular_color"))
995                                 tm_type = 5;
996                         else if (!strcmp(name, "diffuse_color"))
997                                 tm_type = 6;
998                         else if (!strcmp(name, "alpha"))
999                                 tm_type = 7;
1000                         else if (!strcmp(name, "ior"))
1001                                 tm_type = 8;
1002                         
1003                         else
1004                                 tm_type = -1;
1005                 }
1006
1007                 switch (tm_type) {
1008                 case 0:
1009                 case 1:
1010                         tm_name = "rotation";
1011                         is_rotation = true;
1012                         break;
1013                 case 2:
1014                         tm_name = "scale";
1015                         break;
1016                 case 3:
1017                         tm_name = "location";
1018                         break;
1019                 case 4:
1020                         tm_name = "shininess";
1021                         break;
1022                 case 5:
1023                         tm_name = "specular";
1024                         break;
1025                 case 6:
1026                         tm_name = "diffuse";
1027                         break;  
1028                 case 7:
1029                         tm_name = "transparency";
1030                         break;  
1031                 case 8:
1032                         tm_name = "index_of_refraction";
1033                         break;  
1034                 
1035                 default:
1036                         tm_name = "";
1037                         break;
1038                 }
1039            
1040                 if (tm_name.size()) {
1041                         if (is_rotation)
1042                                 return tm_name + std::string(axis_name) + ".ANGLE";
1043                         else
1044                                 if (axis_name != "")
1045                                         return tm_name + "." + std::string(axis_name);
1046                                 else 
1047                                         return tm_name;
1048                 }
1049
1050                 return std::string("");
1051         }
1052
1053         char* AnimationExporter::extract_transform_name(char *rna_path)
1054         {
1055                 char *dot = strrchr(rna_path, '.');
1056                 return dot ? (dot + 1) : rna_path;
1057         }
1058
1059         //find keyframes of all the objects animations
1060         void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra)
1061         {
1062                 FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
1063
1064                 for (; fcu; fcu = fcu->next) {
1065                         
1066                         for (unsigned int i = 0; i < fcu->totvert; i++) {
1067                                 float f = fcu->bezt[i].vec[1][0];     //
1068                                 if (std::find(fra.begin(), fra.end(), f) == fra.end())   
1069                                         fra.push_back(f);
1070                         }
1071                 }
1072
1073                 // keep the keys in ascending order
1074                 std::sort(fra.begin(), fra.end());
1075         }
1076
1077                 
1078
1079         // enable fcurves driving a specific bone, disable all the rest
1080         // if bone_name = NULL enable all fcurves
1081         void AnimationExporter::enable_fcurves(bAction *act, char *bone_name)
1082         {
1083                 FCurve *fcu;
1084                 char prefix[200];
1085
1086                 if (bone_name)
1087                         BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
1088
1089                 for (fcu = (FCurve*)act->curves.first; fcu; fcu = fcu->next) {
1090                         if (bone_name) {
1091                                 if (!strncmp(fcu->rna_path, prefix, strlen(prefix)))
1092                                         fcu->flag &= ~FCURVE_DISABLED;
1093                                 else
1094                                         fcu->flag |= FCURVE_DISABLED;
1095                         }
1096                         else {
1097                                 fcu->flag &= ~FCURVE_DISABLED;
1098                         }
1099                 }
1100         }
1101         
1102         bool AnimationExporter::hasAnimations(Scene *sce)
1103         {
1104                 Base *base= (Base*) sce->base.first;
1105                 
1106                 while(base) {
1107                         Object *ob = base->object;
1108                         
1109                         FCurve *fcu = 0;
1110                         //Check for object transform animations
1111                         if(ob->adt && ob->adt->action)      
1112                                 fcu = (FCurve*)ob->adt->action->curves.first;
1113                         //Check for Lamp parameter animations
1114                         else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
1115                                 fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
1116                         //Check for Camera parameter animations
1117                         else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
1118                                 fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
1119                         
1120                         //Check Material Effect parameter animations.
1121                         for(int a = 0; a < ob->totcol; a++)
1122                         {
1123                                 Material *ma = give_current_material(ob, a+1);
1124                                 if (!ma) continue;
1125                                 if(ma->adt && ma->adt->action)
1126                                 {
1127                                         fcu = (FCurve*)ma->adt->action->curves.first;   
1128                                 }
1129                         }
1130
1131                         if ( fcu) 
1132                                 return true;
1133                         base= base->next;
1134                 }
1135                 return false;
1136         }
1137
1138         //------------------------------- Not used in the new system.--------------------------------------------------------
1139         void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
1140         {
1141                 if (rotmode > 0)
1142                         find_frames(ob, fra, prefix, "rotation_euler");
1143                 else if (rotmode == ROT_MODE_QUAT)
1144                         find_frames(ob, fra, prefix, "rotation_quaternion");
1145                 /*else if (rotmode == ROT_MODE_AXISANGLE)
1146                         ;*/
1147         }
1148
1149         void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
1150         {
1151                 FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
1152
1153                 for (; fcu; fcu = fcu->next) {
1154                         if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
1155                                 continue;
1156
1157                         char *name = extract_transform_name(fcu->rna_path);
1158                         if (!strcmp(name, tm_name)) {
1159                                 for (unsigned int i = 0; i < fcu->totvert; i++) {
1160                                         float f = fcu->bezt[i].vec[1][0];     //
1161                                         if (std::find(fra.begin(), fra.end(), f) == fra.end())   
1162                                                 fra.push_back(f);
1163                                 }
1164                         }
1165                 }
1166
1167                 // keep the keys in ascending order
1168                 std::sort(fra.begin(), fra.end());
1169         }
1170
1171         void AnimationExporter::write_bone_animation(Object *ob_arm, Bone *bone)
1172         {
1173                 if (!ob_arm->adt)
1174                         return;
1175                 
1176                 //write bone animations for 3 transform types
1177                 //i=0 --> rotations
1178                 //i=1 --> scale
1179                 //i=2 --> location
1180                 for (int i = 0; i < 3; i++)
1181                         sample_and_write_bone_animation(ob_arm, bone, i);
1182                 
1183                 for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
1184                         write_bone_animation(ob_arm, child);
1185         }
1186
1187         void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type)
1188         {
1189                 bArmature *arm = (bArmature*)ob_arm->data;
1190                 int flag = arm->flag;
1191                 std::vector<float> fra;
1192                 char prefix[256];
1193
1194                 BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name);
1195
1196                 bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
1197                 if (!pchan)
1198                         return;
1199                 //Fill frame array with key frame values framed at @param:transform_type
1200                 switch (transform_type) {
1201                 case 0:
1202                         find_rotation_frames(ob_arm, fra, prefix, pchan->rotmode);
1203                         break;
1204                 case 1:
1205                         find_frames(ob_arm, fra, prefix, "scale");
1206                         break;
1207                 case 2:
1208                         find_frames(ob_arm, fra, prefix, "location");
1209                         break;
1210                 default:
1211                         return;
1212                 }
1213
1214                 // exit rest position
1215                 if (flag & ARM_RESTPOS) {
1216                         arm->flag &= ~ARM_RESTPOS;
1217                         where_is_pose(scene, ob_arm);
1218                 }
1219                 //v array will hold all values which will be exported. 
1220                 if (fra.size()) {
1221                         float *values = (float*)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames");
1222                         sample_animation(values, fra, transform_type, bone, ob_arm, pchan);
1223
1224                         if (transform_type == 0) {
1225                                 // write x, y, z curves separately if it is rotation
1226                                 float *axisValues = (float*)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");   
1227                         
1228                                 for (int i = 0; i < 3; i++) {
1229                                         for (unsigned int j = 0; j < fra.size(); j++)
1230                                                 axisValues[j] = values[j * 3 + i];
1231
1232                                         dae_bone_animation(fra, axisValues, transform_type, i, id_name(ob_arm), bone->name);
1233                                 }
1234                                 MEM_freeN(axisValues);
1235                         }
1236                         else {
1237                                 // write xyz at once if it is location or scale
1238                                 dae_bone_animation(fra, values, transform_type, -1, id_name(ob_arm), bone->name);
1239                         }
1240
1241                         MEM_freeN(values);
1242                 }
1243
1244                 // restore restpos
1245                 if (flag & ARM_RESTPOS) 
1246                         arm->flag = flag;
1247                 where_is_pose(scene, ob_arm);
1248         }
1249
1250         void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan)
1251         {
1252                 bPoseChannel *parchan = NULL;
1253                 bPose *pose = ob_arm->pose;
1254
1255                 pchan = get_pose_channel(pose, bone->name);
1256
1257                 if (!pchan)
1258                         return;
1259
1260                 parchan = pchan->parent;
1261
1262                 enable_fcurves(ob_arm->adt->action, bone->name);
1263
1264                 std::vector<float>::iterator it;
1265                 for (it = frames.begin(); it != frames.end(); it++) {
1266                         float mat[4][4], ipar[4][4];
1267
1268                         float ctime = bsystem_time(scene, ob_arm, *it, 0.0f);
1269
1270
1271                         BKE_animsys_evaluate_animdata(scene , &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
1272                         where_is_pose_bone(scene, ob_arm, pchan, ctime, 1);
1273
1274                         // compute bone local mat
1275                         if (bone->parent) {
1276                                 invert_m4_m4(ipar, parchan->pose_mat);
1277                                 mul_m4_m4m4(mat, pchan->pose_mat, ipar);
1278                         }
1279                         else
1280                                 copy_m4_m4(mat, pchan->pose_mat);
1281
1282                         switch (type) {
1283                         case 0:
1284                                 mat4_to_eul(v, mat);
1285                                 break;
1286                         case 1:
1287                                 mat4_to_size(v, mat);
1288                                 break;
1289                         case 2:
1290                                 copy_v3_v3(v, mat[3]);
1291                                 break;
1292                         }
1293
1294                         v += 3;
1295                 }
1296
1297                 enable_fcurves(ob_arm->adt->action, NULL);
1298         }
1299
1300