| 
									
										
										
										
											2011-02-23 10:52:22 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup collada | 
					
						
							| 
									
										
										
										
											2011-02-27 20:30:35 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 11:28:09 +01:00
										 |  |  | #include <cstddef>
 | 
					
						
							| 
									
										
										
										
											2011-02-27 20:30:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-12 06:25:04 +00:00
										 |  |  | /* COLLADABU_ASSERT, may be able to remove later */ | 
					
						
							|  |  |  | #include "COLLADABUPlatform.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #include "DNA_armature_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ED_keyframing.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_listbase.h"
 | 
					
						
							|  |  |  | #include "BLI_math.h"
 | 
					
						
							|  |  |  | #include "BLI_string.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-16 17:33:34 +01:00
										 |  |  | #include "BLI_string_utils.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-16 17:32:01 +10:00
										 |  |  | #include "BLT_translation.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-25 08:29:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #include "BKE_action.h"
 | 
					
						
							|  |  |  | #include "BKE_armature.h"
 | 
					
						
							|  |  |  | #include "BKE_fcurve.h"
 | 
					
						
							|  |  |  | #include "BKE_object.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "AnimationImporter.h"
 | 
					
						
							|  |  |  | #include "ArmatureImporter.h"
 | 
					
						
							| 
									
										
										
										
											2011-07-21 18:31:01 +00:00
										 |  |  | #include "MaterialExporter.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "collada_utils.h"
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* first try node name, if not available (since is optional), fall back to original id */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | template<class T> static const char *bc_get_joint_name(T *node) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const std::string &id = node->getName(); | 
					
						
							| 
									
										
										
										
											2020-07-03 14:59:27 +02:00
										 |  |  |   return id.empty() ? node->getOriginalId().c_str() : id.c_str(); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-06-05 08:41:09 +02:00
										 |  |  |   FCurve *fcu = BKE_fcurve_create(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED); | 
					
						
							|  |  |  |   fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path)); | 
					
						
							|  |  |  |   fcu->array_index = array_index; | 
					
						
							|  |  |  |   return fcu; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-03-11 12:44:02 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::add_bezt(FCurve *fcu, | 
					
						
							|  |  |  |                                  float frame, | 
					
						
							|  |  |  |                                  float value, | 
					
						
							|  |  |  |                                  eBezTriple_Interpolation ipo) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   // float fps = (float)FPS;
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   BezTriple bez; | 
					
						
							|  |  |  |   memset(&bez, 0, sizeof(BezTriple)); | 
					
						
							|  |  |  |   bez.vec[1][0] = frame; | 
					
						
							|  |  |  |   bez.vec[1][1] = value; | 
					
						
							|  |  |  |   bez.ipo = ipo; /* use default interpolation mode here... */ | 
					
						
							|  |  |  |   bez.f1 = bez.f2 = bez.f3 = SELECT; | 
					
						
							|  |  |  |   bez.h1 = bez.h2 = HD_AUTO; | 
					
						
							|  |  |  |   insert_bezt_fcurve(fcu, &bez, INSERTKEY_NOFLAGS); | 
					
						
							|  |  |  |   calchandles_fcurve(fcu); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* create one or several fcurves depending on the number of parameters being animated */ | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   COLLADAFW::FloatOrDoubleArray &input = curve->getInputValues(); | 
					
						
							|  |  |  |   COLLADAFW::FloatOrDoubleArray &output = curve->getOutputValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   float fps = (float)FPS; | 
					
						
							|  |  |  |   size_t dim = curve->getOutDimension(); | 
					
						
							|  |  |  |   unsigned int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::vector<FCurve *> &fcurves = curve_map[curve->getUniqueId()]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (dim) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     case 1: /* X, Y, Z or angle */ | 
					
						
							|  |  |  |     case 3: /* XYZ */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     case 4: | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     case 16: /* matrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |       for (i = 0; i < dim; i++) { | 
					
						
							| 
									
										
										
										
											2020-06-05 08:41:09 +02:00
										 |  |  |         FCurve *fcu = BKE_fcurve_create(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         fcu->flag = (FCURVE_VISIBLE | FCURVE_AUTO_HANDLES | FCURVE_SELECTED); | 
					
						
							|  |  |  |         fcu->array_index = 0; | 
					
						
							| 
									
										
										
										
											2019-10-01 21:38:44 +03:00
										 |  |  |         fcu->auto_smoothing = U.auto_smoothing_new; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for (unsigned int j = 0; j < curve->getKeyCount(); j++) { | 
					
						
							|  |  |  |           BezTriple bez; | 
					
						
							|  |  |  |           memset(&bez, 0, sizeof(BezTriple)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |           /* input, output */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           bez.vec[1][0] = bc_get_float_value(input, j) * fps; | 
					
						
							|  |  |  |           bez.vec[1][1] = bc_get_float_value(output, j * dim + i); | 
					
						
							|  |  |  |           bez.h1 = bez.h2 = HD_AUTO; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER || | 
					
						
							|  |  |  |               curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP) { | 
					
						
							|  |  |  |             COLLADAFW::FloatOrDoubleArray &intan = curve->getInTangentValues(); | 
					
						
							|  |  |  |             COLLADAFW::FloatOrDoubleArray &outtan = curve->getOutTangentValues(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |             /* intangent */ | 
					
						
							| 
									
										
										
										
											2019-11-27 10:47:39 +01:00
										 |  |  |             unsigned int index = 2 * (j * dim + i); | 
					
						
							|  |  |  |             bez.vec[0][0] = bc_get_float_value(intan, index) * fps; | 
					
						
							|  |  |  |             bez.vec[0][1] = bc_get_float_value(intan, index + 1); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |             /* outtangent */ | 
					
						
							| 
									
										
										
										
											2019-11-27 10:47:39 +01:00
										 |  |  |             bez.vec[2][0] = bc_get_float_value(outtan, index) * fps; | 
					
						
							|  |  |  |             bez.vec[2][1] = bc_get_float_value(outtan, index + 1); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) { | 
					
						
							|  |  |  |               bez.ipo = BEZT_IPO_BEZ; | 
					
						
							|  |  |  |               bez.h1 = bez.h2 = HD_AUTO_ANIM; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |               bez.ipo = BEZT_IPO_CONST; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           else { | 
					
						
							|  |  |  |             bez.ipo = BEZT_IPO_LIN; | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |           bez.ipo = U.ipo_new; /* use default interpolation mode here... */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           bez.f1 = bez.f2 = bez.f3 = SELECT; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           insert_bezt_fcurve(fcu, &bez, INSERTKEY_NOFLAGS); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         calchandles_fcurve(fcu); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         fcurves.push_back(fcu); | 
					
						
							|  |  |  |         unused_curves.push_back(fcu); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       fprintf(stderr, | 
					
						
							|  |  |  |               "Output dimension of %d is not yet supported (animation id = %s)\n", | 
					
						
							|  |  |  |               (int)dim, | 
					
						
							|  |  |  |               curve->getOriginalId().c_str()); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationImporter::fcurve_deg_to_rad(FCurve *cu) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (unsigned int i = 0; i < cu->totvert; i++) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* TODO convert handles too */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     cu->bezt[i].vec[1][1] *= DEG2RADF(1.0f); | 
					
						
							|  |  |  |     cu->bezt[i].vec[0][1] *= DEG2RADF(1.0f); | 
					
						
							|  |  |  |     cu->bezt[i].vec[2][1] *= DEG2RADF(1.0f); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 19:06:14 +02:00
										 |  |  | void AnimationImporter::fcurve_scale(FCurve *cu, int scale) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   for (unsigned int i = 0; i < cu->totvert; i++) { | 
					
						
							|  |  |  |     /* TODO convert handles too */ | 
					
						
							|  |  |  |     cu->bezt[i].vec[1][1] *= scale; | 
					
						
							|  |  |  |     cu->bezt[i].vec[0][1] *= scale; | 
					
						
							|  |  |  |     cu->bezt[i].vec[2][1] *= scale; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-11 18:41:35 +10:00
										 |  |  | void AnimationImporter::fcurve_is_used(FCurve *fcu) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu), | 
					
						
							|  |  |  |                       unused_curves.end()); | 
					
						
							| 
									
										
										
										
											2015-09-11 18:41:35 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::add_fcurves_to_object(Main *bmain, | 
					
						
							|  |  |  |                                               Object *ob, | 
					
						
							|  |  |  |                                               std::vector<FCurve *> &curves, | 
					
						
							|  |  |  |                                               char *rna_path, | 
					
						
							|  |  |  |                                               int array_index, | 
					
						
							|  |  |  |                                               Animation *animated) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bAction *act; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (!ob->adt || !ob->adt->action) { | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |     act = ED_id_action_ensure(bmain, (ID *)&ob->id); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     act = ob->adt->action; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<FCurve *>::iterator it; | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char *p = strstr(rna_path, "rotation_euler"); | 
					
						
							|  |  |  |   bool is_rotation = p && *(p + strlen("rotation_euler")) == '\0'; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* convert degrees to radians for rotation */ | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |   if (is_rotation) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     fcurve_deg_to_rad(fcu); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (it = curves.begin(), i = 0; it != curves.end(); it++, i++) { | 
					
						
							|  |  |  |     FCurve *fcu = *it; | 
					
						
							|  |  |  |     fcu->rna_path = BLI_strdupn(rna_path, strlen(rna_path)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (array_index == -1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       fcu->array_index = i; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       fcu->array_index = array_index; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (ob->type == OB_ARMATURE) { | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       bActionGroup *grp = nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       const char *bone_name = bc_get_joint_name(animated->node); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (bone_name) { | 
					
						
							|  |  |  |         /* try to find group */ | 
					
						
							|  |  |  |         grp = BKE_action_group_find_name(act, bone_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* no matching groups, so add one */ | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |         if (grp == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           /* Add a new group, and make it active */ | 
					
						
							|  |  |  |           grp = (bActionGroup *)MEM_callocN(sizeof(bActionGroup), "bActionGroup"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           grp->flag = AGRP_SELECTED; | 
					
						
							|  |  |  |           BLI_strncpy(grp->name, bone_name, sizeof(grp->name)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           BLI_addtail(&act->groups, grp); | 
					
						
							|  |  |  |           BLI_uniquename(&act->groups, | 
					
						
							|  |  |  |                          grp, | 
					
						
							|  |  |  |                          CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "Group"), | 
					
						
							|  |  |  |                          '.', | 
					
						
							|  |  |  |                          offsetof(bActionGroup, name), | 
					
						
							|  |  |  |                          64); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         /* add F-Curve to group */ | 
					
						
							|  |  |  |         action_groups_add_channel(act, grp, fcu); | 
					
						
							|  |  |  |         fcurve_is_used(fcu); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       if (is_rotation) { | 
					
						
							|  |  |  |         fcurves_actionGroup_map[grp].push_back(fcu); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       BLI_addtail(&act->curves, fcu); | 
					
						
							|  |  |  |       fcurve_is_used(fcu); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AnimationImporter::~AnimationImporter() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* free unused FCurves */ | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   for (std::vector<FCurve *>::iterator it = unused_curves.begin(); it != unused_curves.end(); | 
					
						
							|  |  |  |        it++) { | 
					
						
							| 
									
										
										
										
											2020-06-05 09:30:15 +02:00
										 |  |  |     BKE_fcurve_free(*it); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:59:27 +02:00
										 |  |  |   if (!unused_curves.empty()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     fprintf(stderr, "removed %d unused curves\n", (int)unused_curves.size()); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | bool AnimationImporter::write_animation(const COLLADAFW::Animation *anim) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (anim->getAnimationType() == COLLADAFW::Animation::ANIMATION_CURVE) { | 
					
						
							|  |  |  |     COLLADAFW::AnimationCurve *curve = (COLLADAFW::AnimationCurve *)anim; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* XXX Don't know if it's necessary
 | 
					
						
							|  |  |  |      * Should we check outPhysicalDimension? */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (curve->getInPhysicalDimension() != COLLADAFW::PHYSICAL_DIMENSION_TIME) { | 
					
						
							|  |  |  |       fprintf(stderr, "Inputs physical dimension is not time.\n"); | 
					
						
							|  |  |  |       return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* a curve can have mixed interpolation type,
 | 
					
						
							|  |  |  |      * in this case curve->getInterpolationTypes returns a list of interpolation types per key */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     COLLADAFW::AnimationCurve::InterpolationType interp = curve->getInterpolationType(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (interp != COLLADAFW::AnimationCurve::INTERPOLATION_MIXED) { | 
					
						
							|  |  |  |       switch (interp) { | 
					
						
							|  |  |  |         case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR: | 
					
						
							|  |  |  |         case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER: | 
					
						
							|  |  |  |         case COLLADAFW::AnimationCurve::INTERPOLATION_STEP: | 
					
						
							|  |  |  |           animation_to_fcurves(curve); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							| 
									
										
										
										
											2020-07-21 15:58:16 +10:00
										 |  |  |           /* TODO there are also CARDINAL, HERMITE, BSPLINE and STEP types. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           fprintf(stderr, | 
					
						
							|  |  |  |                   "CARDINAL, HERMITE and BSPLINE anim interpolation types not supported yet.\n"); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* not supported yet */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       fprintf(stderr, "MIXED anim interpolation type is not supported yet.\n"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     fprintf(stderr, "FORMULA animation type is not supported yet.\n"); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* called on post-process stage after writeVisualScenes */ | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | bool AnimationImporter::write_animation_list(const COLLADAFW::AnimationList *animlist) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const COLLADAFW::UniqueId &animlist_id = animlist->getUniqueId(); | 
					
						
							|  |  |  |   animlist_map[animlist_id] = animlist; | 
					
						
							| 
									
										
										
										
											2011-09-04 00:15:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* should not happen */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (uid_animated_map.find(animlist_id) == uid_animated_map.end()) { | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-09-04 00:15:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* for bones rna_path is like: pose.bones["bone-name"].rotation */ | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2011-09-04 00:15:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return true; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-17 14:00:09 +10:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \todo refactor read_node_transform to not automatically apply anything, | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |  * but rather return the transform matrix, so caller can do with it what is | 
					
						
							| 
									
										
										
										
											2020-06-17 14:00:09 +10:00
										 |  |  |  * necessary. Same for \ref get_node_mat | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | void AnimationImporter::read_node_transform(COLLADAFW::Node *node, Object *ob) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float mat[4][4]; | 
					
						
							|  |  |  |   TransformReader::get_node_mat(mat, node, &uid_animated_map, ob); | 
					
						
							|  |  |  |   if (ob) { | 
					
						
							|  |  |  |     copy_m4_m4(ob->obmat, mat); | 
					
						
							| 
									
										
										
										
											2020-11-06 14:25:30 +01:00
										 |  |  |     BKE_object_apply_mat4(ob, ob->obmat, false, false); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							|  |  |  | virtual void AnimationImporter::change_eul_to_quat(Object *ob, bAction *act) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bActionGroup *grp; | 
					
						
							|  |  |  |   int i; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (grp = (bActionGroup *)act->groups.first; grp; grp = grp->next) { | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     FCurve *eulcu[3] = {NULL, NULL, NULL}; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     if (fcurves_actionGroup_map.find(grp) == fcurves_actionGroup_map.end()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       continue; | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     std::vector<FCurve *> &rot_fcurves = fcurves_actionGroup_map[grp]; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     if (rot_fcurves.size() > 3) { | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |       continue; | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     for (i = 0; i < rot_fcurves.size(); i++) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       eulcu[rot_fcurves[i]->array_index] = rot_fcurves[i]; | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     char joint_path[100]; | 
					
						
							|  |  |  |     char rna_path[100]; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     BLI_snprintf(joint_path, sizeof(joint_path), "pose.bones[\"%s\"]", grp->name); | 
					
						
							|  |  |  |     BLI_snprintf(rna_path, sizeof(rna_path), "%s.rotation_quaternion", joint_path); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     FCurve *quatcu[4] = { | 
					
						
							|  |  |  |       create_fcurve(0, rna_path), | 
					
						
							|  |  |  |       create_fcurve(1, rna_path), | 
					
						
							|  |  |  |       create_fcurve(2, rna_path), | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |       create_fcurve(3, rna_path), | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     }; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, grp->name); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     float m4[4][4], irest[3][3]; | 
					
						
							|  |  |  |     invert_m4_m4(m4, chan->bone->arm_mat); | 
					
						
							|  |  |  |     copy_m3_m4(irest, m4); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (i = 0; i < 3; i++) { | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       FCurve *cu = eulcu[i]; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |       if (!cu) { | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |         continue; | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       for (int j = 0; j < cu->totvert; j++) { | 
					
						
							|  |  |  |         float frame = cu->bezt[j].vec[1][0]; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         float eul[3] = { | 
					
						
							|  |  |  |           eulcu[0] ? evaluate_fcurve(eulcu[0], frame) : 0.0f, | 
					
						
							|  |  |  |           eulcu[1] ? evaluate_fcurve(eulcu[1], frame) : 0.0f, | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |           eulcu[2] ? evaluate_fcurve(eulcu[2], frame) : 0.0f, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |         /* make eul relative to bone rest pose */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         float rot[3][3], rel[3][3], quat[4]; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-18 07:21:26 +02:00
										 |  |  | #  if 0
 | 
					
						
							|  |  |  |         eul_to_mat3(rot, eul); | 
					
						
							|  |  |  |         mul_m3_m3m3(rel, irest, rot); | 
					
						
							|  |  |  |         mat3_to_quat(quat, rel); | 
					
						
							|  |  |  | #  endif
 | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         eul_to_quat(quat, eul); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |         for (int k = 0; k < 4; k++) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           create_bezt(quatcu[k], frame, quat[k], U.ipo_new); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* now replace old Euler curves */ | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (i = 0; i < 3; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |       if (!eulcu[i]) { | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |         continue; | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       action_groups_remove_channel(act, eulcu[i]); | 
					
						
							| 
									
										
										
										
											2020-06-05 09:30:15 +02:00
										 |  |  |       BKE_fcurve_free(eulcu[i]); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     chan->rotmode = ROT_MODE_QUAT; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     for (i = 0; i < 4; i++) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       action_groups_add_channel(act, grp, quatcu[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bPoseChannel *pchan; | 
					
						
							|  |  |  |   for (pchan = (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan = pchan->next) { | 
					
						
							|  |  |  |     pchan->rotmode = ROT_MODE_QUAT; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* sets the rna_path and array index to curve */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::modify_fcurve(std::vector<FCurve *> *curves, | 
					
						
							|  |  |  |                                       const char *rna_path, | 
					
						
							| 
									
										
										
										
											2019-06-02 19:06:14 +02:00
										 |  |  |                                       int array_index, | 
					
						
							|  |  |  |                                       int scale) | 
					
						
							| 
									
										
										
										
											2011-09-04 00:15:59 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<FCurve *>::iterator it; | 
					
						
							|  |  |  |   int i; | 
					
						
							|  |  |  |   for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) { | 
					
						
							|  |  |  |     FCurve *fcu = *it; | 
					
						
							|  |  |  |     fcu->rna_path = BLI_strdup(rna_path); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (array_index == -1) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       fcu->array_index = i; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       fcu->array_index = array_index; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 19:06:14 +02:00
										 |  |  |     if (scale != 1) { | 
					
						
							|  |  |  |       fcurve_scale(fcu, scale); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     fcurve_is_used(fcu); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | void AnimationImporter::unused_fcurve(std::vector<FCurve *> *curves) | 
					
						
							| 
									
										
										
										
											2012-05-02 18:11:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* when an error happens and we can't actually use curve remove it from unused_curves */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<FCurve *>::iterator it; | 
					
						
							|  |  |  |   for (it = curves->begin(); it != curves->end(); it++) { | 
					
						
							|  |  |  |     FCurve *fcu = *it; | 
					
						
							|  |  |  |     fcurve_is_used(fcu); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-05-02 18:11:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | void AnimationImporter::find_frames(std::vector<float> *frames, std::vector<FCurve *> *curves) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  |   for (iter = curves->begin(); iter != curves->end(); iter++) { | 
					
						
							|  |  |  |     FCurve *fcu = *iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (unsigned int k = 0; k < fcu->totvert; k++) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* get frame value from bezTriple */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       float fra = fcu->bezt[k].vec[1][0]; | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* if frame already not added add frame to frames */ | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       if (std::find(frames->begin(), frames->end(), fra) == frames->end()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         frames->push_back(fra); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-27 11:18:10 +01:00
										 |  |  | static int get_animation_axis_index(const COLLADABU::Math::Vector3 &axis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   int index; | 
					
						
							|  |  |  |   if (COLLADABU::Math::Vector3::UNIT_X == axis) { | 
					
						
							|  |  |  |     index = 0; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (COLLADABU::Math::Vector3::UNIT_Y == axis) { | 
					
						
							|  |  |  |     index = 1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else if (COLLADABU::Math::Vector3::UNIT_Z == axis) { | 
					
						
							|  |  |  |     index = 2; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     index = -1; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return index; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* creates the rna_paths and array indices of fcurves from animations using transformation and
 | 
					
						
							|  |  |  |  * bound animation class of each animation. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::Assign_transform_animations( | 
					
						
							|  |  |  |     COLLADAFW::Transformation *transform, | 
					
						
							|  |  |  |     const COLLADAFW::AnimationList::AnimationBinding *binding, | 
					
						
							|  |  |  |     std::vector<FCurve *> *curves, | 
					
						
							|  |  |  |     bool is_joint, | 
					
						
							|  |  |  |     char *joint_path) | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType(); | 
					
						
							|  |  |  |   bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; | 
					
						
							|  |  |  |   bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* to check if the no of curves are valid */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE || | 
					
						
							|  |  |  |                tm_type == COLLADAFW::Transformation::SCALE) && | 
					
						
							|  |  |  |               binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) { | 
					
						
							|  |  |  |     fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, (int)curves->size()); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   char rna_path[100]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (tm_type) { | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::TRANSLATE: | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::SCALE: { | 
					
						
							|  |  |  |       bool loc = tm_type == COLLADAFW::Transformation::TRANSLATE; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, loc ? "location" : "scale"); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         BLI_strncpy(rna_path, loc ? "location" : "scale", sizeof(rna_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       switch (binding->animationClass) { | 
					
						
							|  |  |  |         case COLLADAFW::AnimationList::POSITION_X: | 
					
						
							|  |  |  |           modify_fcurve(curves, rna_path, 0); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::AnimationList::POSITION_Y: | 
					
						
							|  |  |  |           modify_fcurve(curves, rna_path, 1); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::AnimationList::POSITION_Z: | 
					
						
							|  |  |  |           modify_fcurve(curves, rna_path, 2); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::AnimationList::POSITION_XYZ: | 
					
						
							|  |  |  |           modify_fcurve(curves, rna_path, -1); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           unused_fcurve(curves); | 
					
						
							|  |  |  |           fprintf(stderr, | 
					
						
							|  |  |  |                   "AnimationClass %d is not supported for %s.\n", | 
					
						
							|  |  |  |                   binding->animationClass, | 
					
						
							|  |  |  |                   loc ? "TRANSLATE" : "SCALE"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::ROTATE: { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         BLI_snprintf(rna_path, sizeof(rna_path), "%s.rotation_euler", joint_path); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         BLI_strncpy(rna_path, "rotation_euler", sizeof(rna_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  |       for (iter = curves->begin(); iter != curves->end(); iter++) { | 
					
						
							|  |  |  |         FCurve *fcu = *iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |         /* if transform is rotation the fcurves values must be turned in to radian. */ | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |         if (is_rotation) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           fcurve_deg_to_rad(fcu); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       COLLADAFW::Rotate *rot = (COLLADAFW::Rotate *)transform; | 
					
						
							|  |  |  |       COLLADABU::Math::Vector3 &axis = rot->getRotationAxis(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       switch (binding->animationClass) { | 
					
						
							| 
									
										
										
										
											2019-11-27 11:18:10 +01:00
										 |  |  |         case COLLADAFW::AnimationList::ANGLE: { | 
					
						
							|  |  |  |           int axis_index = get_animation_axis_index(axis); | 
					
						
							|  |  |  |           if (axis_index >= 0) { | 
					
						
							|  |  |  |             modify_fcurve(curves, rna_path, axis_index); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |           else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             unused_fcurve(curves); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-11-27 11:18:10 +01:00
										 |  |  |         } break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         case COLLADAFW::AnimationList::AXISANGLE: | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |         /* TODO convert axis-angle to quat? or XYZ? */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         default: | 
					
						
							|  |  |  |           unused_fcurve(curves); | 
					
						
							|  |  |  |           fprintf(stderr, | 
					
						
							|  |  |  |                   "AnimationClass %d is not supported for ROTATE transformation.\n", | 
					
						
							|  |  |  |                   binding->animationClass); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::MATRIX: | 
					
						
							| 
									
										
										
										
											2018-04-16 17:08:27 +02:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |     { | 
					
						
							|  |  |  |       COLLADAFW::Matrix *mat = (COLLADAFW::Matrix *)transform; | 
					
						
							|  |  |  |       COLLADABU::Math::Matrix4 mat4 = mat->getMatrix(); | 
					
						
							|  |  |  |       switch (binding->animationClass) { | 
					
						
							|  |  |  |         case COLLADAFW::AnimationList::TRANSFORM: | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-04-16 17:08:27 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       unused_fcurve(curves); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::SKEW: | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::LOOKAT: | 
					
						
							|  |  |  |       unused_fcurve(curves); | 
					
						
							|  |  |  |       fprintf(stderr, "Animation of SKEW and LOOKAT transformations is not supported yet.\n"); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* creates the rna_paths and array indices of fcurves from animations using color and bound
 | 
					
						
							|  |  |  |  * animation class of each animation. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::Assign_color_animations(const COLLADAFW::UniqueId &listid, | 
					
						
							|  |  |  |                                                 ListBase *AnimCurves, | 
					
						
							|  |  |  |                                                 const char *anim_type) | 
					
						
							| 
									
										
										
										
											2011-07-03 17:26:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char rna_path[100]; | 
					
						
							|  |  |  |   BLI_strncpy(rna_path, anim_type, sizeof(rna_path)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList *animlist = animlist_map[listid]; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   if (animlist == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     fprintf(stderr, | 
					
						
							|  |  |  |             "Collada: No animlist found for ID: %s of type %s\n", | 
					
						
							|  |  |  |             listid.toAscii().c_str(), | 
					
						
							|  |  |  |             anim_type); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings(); | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* all the curves belonging to the current binding */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<FCurve *> animcurves; | 
					
						
							|  |  |  |   for (unsigned int j = 0; j < bindings.getCount(); j++) { | 
					
						
							|  |  |  |     animcurves = curve_map[bindings[j].animation]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (bindings[j].animationClass) { | 
					
						
							|  |  |  |       case COLLADAFW::AnimationList::COLOR_R: | 
					
						
							|  |  |  |         modify_fcurve(&animcurves, rna_path, 0); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case COLLADAFW::AnimationList::COLOR_G: | 
					
						
							|  |  |  |         modify_fcurve(&animcurves, rna_path, 1); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case COLLADAFW::AnimationList::COLOR_B: | 
					
						
							|  |  |  |         modify_fcurve(&animcurves, rna_path, 2); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case COLLADAFW::AnimationList::COLOR_RGB: | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       case COLLADAFW::AnimationList::COLOR_RGBA: /* to do-> set intensity */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         modify_fcurve(&animcurves, rna_path, -1); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         unused_fcurve(&animcurves); | 
					
						
							|  |  |  |         fprintf(stderr, | 
					
						
							|  |  |  |                 "AnimationClass %d is not supported for %s.\n", | 
					
						
							|  |  |  |                 bindings[j].animationClass, | 
					
						
							|  |  |  |                 "COLOR"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::vector<FCurve *>::iterator iter; | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* Add the curves of the current animation to the object */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { | 
					
						
							|  |  |  |       FCurve *fcu = *iter; | 
					
						
							|  |  |  |       BLI_addtail(AnimCurves, fcu); | 
					
						
							|  |  |  |       fcurve_is_used(fcu); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-07-03 17:26:02 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-04 19:30:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::Assign_float_animations(const COLLADAFW::UniqueId &listid, | 
					
						
							|  |  |  |                                                 ListBase *AnimCurves, | 
					
						
							|  |  |  |                                                 const char *anim_type) | 
					
						
							| 
									
										
										
										
											2011-07-04 19:30:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char rna_path[100]; | 
					
						
							|  |  |  |   if (animlist_map.find(listid) == animlist_map.end()) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* anim_type has animations */ | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList *animlist = animlist_map[listid]; | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings(); | 
					
						
							|  |  |  |   /* all the curves belonging to the current binding */ | 
					
						
							|  |  |  |   std::vector<FCurve *> animcurves; | 
					
						
							|  |  |  |   for (unsigned int j = 0; j < bindings.getCount(); j++) { | 
					
						
							|  |  |  |     animcurves = curve_map[bindings[j].animation]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BLI_strncpy(rna_path, anim_type, sizeof(rna_path)); | 
					
						
							|  |  |  |     modify_fcurve(&animcurves, rna_path, 0); | 
					
						
							|  |  |  |     std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  |     /* Add the curves of the current animation to the object */ | 
					
						
							|  |  |  |     for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { | 
					
						
							|  |  |  |       FCurve *fcu = *iter; | 
					
						
							|  |  |  |       /* All anim_types whose values are to be converted from Degree to Radians can be ORed here
 | 
					
						
							|  |  |  |        */ | 
					
						
							|  |  |  |       if (STREQ("spot_size", anim_type)) { | 
					
						
							|  |  |  |         /* NOTE: Do NOT convert if imported file was made by blender <= 2.69.10
 | 
					
						
							|  |  |  |          * Reason: old blender versions stored spot_size in radians (was a bug) | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |          */ | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |         if (this->import_from_version.empty() || | 
					
						
							|  |  |  |             BLI_strcasecmp_natural(this->import_from_version.c_str(), "2.69.10") != -1) { | 
					
						
							|  |  |  |           fcurve_deg_to_rad(fcu); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |       /** XXX What About animtype "rotation" ? */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       BLI_addtail(AnimCurves, fcu); | 
					
						
							|  |  |  |       fcurve_is_used(fcu); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-07-04 19:30:58 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | float AnimationImporter::convert_to_focal_length(float in_xfov, | 
					
						
							|  |  |  |                                                  int fov_type, | 
					
						
							|  |  |  |                                                  float aspect, | 
					
						
							|  |  |  |                                                  float sensorx) | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:09 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-31 14:25:09 +02:00
										 |  |  |   /* NOTE: Needs more testing (As we currently have no official test data for this) */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float xfov = (fov_type == CAMERA_YFOV) ? | 
					
						
							|  |  |  |                    (2.0f * atanf(aspect * tanf(DEG2RADF(in_xfov) * 0.5f))) : | 
					
						
							|  |  |  |                    DEG2RADF(in_xfov); | 
					
						
							|  |  |  |   return fov_to_focallength(xfov, sensorx); | 
					
						
							| 
									
										
										
										
											2018-03-28 17:56:09 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Lens animations must be stored in COLLADA by using FOV, | 
					
						
							|  |  |  |  * while blender internally uses focal length. | 
					
						
							|  |  |  |  * The imported animation curves must be converted appropriately. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::Assign_lens_animations(const COLLADAFW::UniqueId &listid, | 
					
						
							|  |  |  |                                                ListBase *AnimCurves, | 
					
						
							|  |  |  |                                                const double aspect, | 
					
						
							|  |  |  |                                                Camera *cam, | 
					
						
							|  |  |  |                                                const char *anim_type, | 
					
						
							|  |  |  |                                                int fov_type) | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char rna_path[100]; | 
					
						
							|  |  |  |   if (animlist_map.find(listid) == animlist_map.end()) { | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |   /* anim_type has animations */ | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList *animlist = animlist_map[listid]; | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings(); | 
					
						
							|  |  |  |   /* all the curves belonging to the current binding */ | 
					
						
							|  |  |  |   std::vector<FCurve *> animcurves; | 
					
						
							|  |  |  |   for (unsigned int j = 0; j < bindings.getCount(); j++) { | 
					
						
							|  |  |  |     animcurves = curve_map[bindings[j].animation]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |     BLI_strncpy(rna_path, anim_type, sizeof(rna_path)); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |     modify_fcurve(&animcurves, rna_path, 0); | 
					
						
							|  |  |  |     std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  |     /* Add the curves of the current animation to the object */ | 
					
						
							|  |  |  |     for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { | 
					
						
							|  |  |  |       FCurve *fcu = *iter; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |       for (unsigned int i = 0; i < fcu->totvert; i++) { | 
					
						
							|  |  |  |         fcu->bezt[i].vec[0][1] = convert_to_focal_length( | 
					
						
							|  |  |  |             fcu->bezt[i].vec[0][1], fov_type, aspect, cam->sensor_x); | 
					
						
							|  |  |  |         fcu->bezt[i].vec[1][1] = convert_to_focal_length( | 
					
						
							|  |  |  |             fcu->bezt[i].vec[1][1], fov_type, aspect, cam->sensor_x); | 
					
						
							|  |  |  |         fcu->bezt[i].vec[2][1] = convert_to_focal_length( | 
					
						
							|  |  |  |             fcu->bezt[i].vec[2][1], fov_type, aspect, cam->sensor_x); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       BLI_addtail(AnimCurves, fcu); | 
					
						
							|  |  |  |       fcurve_is_used(fcu); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::apply_matrix_curves(Object *ob, | 
					
						
							|  |  |  |                                             std::vector<FCurve *> &animcurves, | 
					
						
							|  |  |  |                                             COLLADAFW::Node *root, | 
					
						
							|  |  |  |                                             COLLADAFW::Node *node, | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  |                                             COLLADAFW::Transformation *tm) | 
					
						
							| 
									
										
										
										
											2011-08-10 19:43:40 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool is_joint = node->getType() == COLLADAFW::Node::JOINT; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   const char *bone_name = is_joint ? bc_get_joint_name(node) : nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char joint_path[200]; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::vector<float> frames; | 
					
						
							|  |  |  |   find_frames(&frames, &animcurves); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   float irest_dae[4][4]; | 
					
						
							|  |  |  |   float rest[4][4], irest[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (is_joint) { | 
					
						
							|  |  |  |     get_joint_rest_mat(irest_dae, root, node); | 
					
						
							|  |  |  |     invert_m4(irest_dae); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Bone *bone = BKE_armature_find_bone_name((bArmature *)ob->data, bone_name); | 
					
						
							|  |  |  |     if (!bone) { | 
					
						
							|  |  |  |       fprintf(stderr, "cannot find bone \"%s\"\n", bone_name); | 
					
						
							|  |  |  |       return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unit_m4(rest); | 
					
						
							|  |  |  |     copy_m4_m4(rest, bone->arm_mat); | 
					
						
							|  |  |  |     invert_m4_m4(irest, rest); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* new curves to assign matrix transform animation */ | 
					
						
							|  |  |  |   FCurve *newcu[10]; /* if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   unsigned int totcu = 10; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   const char *tm_str = nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char rna_path[200]; | 
					
						
							|  |  |  |   for (int i = 0; i < totcu; i++) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int axis = i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (i < 4) { | 
					
						
							|  |  |  |       tm_str = "rotation_quaternion"; | 
					
						
							|  |  |  |       axis = i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (i < 7) { | 
					
						
							|  |  |  |       tm_str = "location"; | 
					
						
							|  |  |  |       axis = i - 4; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       tm_str = "scale"; | 
					
						
							|  |  |  |       axis = i - 7; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_strncpy(rna_path, tm_str, sizeof(rna_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     newcu[i] = create_fcurve(axis, rna_path); | 
					
						
							|  |  |  |     newcu[i]->totvert = frames.size(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:59:27 +02:00
										 |  |  |   if (frames.empty()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::sort(frames.begin(), frames.end()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::vector<float>::iterator it; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |   float qref[4]; | 
					
						
							|  |  |  |   unit_qt(qref); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* sample values at each frame */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (it = frames.begin(); it != frames.end(); it++) { | 
					
						
							|  |  |  |     float fra = *it; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     float mat[4][4]; | 
					
						
							|  |  |  |     float matfra[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unit_m4(matfra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* calc object-space mat */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     evaluate_transform_at_frame(matfra, node, fra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* for joints, we need a special matrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* special matrix: iR * M * iR_dae * R
 | 
					
						
							|  |  |  |        * where R, iR are bone rest and inverse rest mats in world space (Blender bones), | 
					
						
							|  |  |  |        * iR_dae is joint inverse rest matrix (DAE) | 
					
						
							|  |  |  |        * and M is an evaluated joint world-space matrix (DAE) */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       float temp[4][4], par[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* calc M */ | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       calc_joint_parent_mat_rest(par, nullptr, root, node); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       mul_m4_m4m4(temp, par, matfra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |       evaluate_joint_world_transform_at_frame(temp, NULL, node, fra); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* calc special matrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       mul_m4_series(mat, irest, temp, irest_dae, rest); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       copy_m4_m4(mat, matfra); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     float rot[4], loc[3], scale[3]; | 
					
						
							|  |  |  |     mat4_decompose(loc, rot, scale, mat); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* add keys */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (int i = 0; i < totcu; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       if (i < 4) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         add_bezt(newcu[i], fra, rot[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else if (i < 7) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         add_bezt(newcu[i], fra, loc[i - 4]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         add_bezt(newcu[i], fra, scale[i - 7]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   Main *bmain = CTX_data_main(mContext); | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |   ED_id_action_ensure(bmain, (ID *)&ob->id); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   ListBase *curves = &ob->adt->action->curves; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* add curves */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (int i = 0; i < totcu; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       add_bone_fcurve(ob, node, newcu[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_addtail(curves, newcu[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |     fcurve_is_used(newcu[i]);  /* never added to unused */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (is_joint) { | 
					
						
							|  |  |  |     bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name); | 
					
						
							|  |  |  |     chan->rotmode = ROT_MODE_QUAT; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     ob->rotmode = ROT_MODE_QUAT; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-08-10 19:43:40 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2019-08-02 12:00:07 +10:00
										 |  |  |  * This function returns the aspect ration from the Collada camera. | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-06-01 18:19:39 +02:00
										 |  |  |  * Note:COLLADA allows to specify either XFov, or YFov alone. | 
					
						
							| 
									
										
										
										
											2012-11-12 07:33:01 +00:00
										 |  |  |  * In that case the aspect ratio can be determined from | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  |  * the viewport aspect ratio (which is 1:1 ?) | 
					
						
							|  |  |  |  * XXX: check this: its probably wrong! | 
					
						
							|  |  |  |  * If both values are specified, then the aspect ration is simply xfov/yfov | 
					
						
							| 
									
										
										
										
											2020-03-24 10:27:12 +11:00
										 |  |  |  * and if aspect ratio is defined, then .. well then its that one. | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-04 12:04:47 +02:00
										 |  |  | static double get_aspect_ratio(const COLLADAFW::Camera *camera) | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   double aspect = camera->getAspectRatio().getValue(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (aspect == 0) { | 
					
						
							|  |  |  |     const double yfov = camera->getYFov().getValue(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (yfov == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       aspect = 1; /* assume yfov and xfov are equal */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       const double xfov = camera->getXFov().getValue(); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       if (xfov == 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         aspect = 1; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         aspect = xfov / yfov; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return aspect; | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-07 12:47:00 +02:00
										 |  |  | static ListBase &get_animation_curves(Main *bmain, Material *ma) | 
					
						
							| 
									
										
										
										
											2018-04-06 12:42:38 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bAction *act; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (!ma->adt || !ma->adt->action) { | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |     act = ED_id_action_ensure(bmain, (ID *)&ma->id); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     act = ma->adt->action; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-04-06 12:42:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return act->curves; | 
					
						
							| 
									
										
										
										
											2018-04-06 12:42:38 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-08-05 21:35:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::translate_Animations( | 
					
						
							|  |  |  |     COLLADAFW::Node *node, | 
					
						
							|  |  |  |     std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map, | 
					
						
							|  |  |  |     std::multimap<COLLADAFW::UniqueId, Object *> &object_map, | 
					
						
							|  |  |  |     std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map, | 
					
						
							|  |  |  |     std::map<COLLADAFW::UniqueId, Material *> uid_material_map) | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool is_joint = node->getType() == COLLADAFW::Node::JOINT; | 
					
						
							|  |  |  |   COLLADAFW::UniqueId uid = node->getUniqueId(); | 
					
						
							|  |  |  |   COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ? node : root_map[uid]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Object *ob; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     ob = armature_importer->get_armature_for_joint(root); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     ob = object_map.find(uid) == object_map.end() ? NULL : object_map.find(uid)->second; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if (!ob) { | 
					
						
							|  |  |  |     fprintf(stderr, "cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str()); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   AnimationImporter::AnimMix *animType = get_animation_type(node, FW_object_map); | 
					
						
							|  |  |  |   bAction *act; | 
					
						
							|  |  |  |   Main *bmain = CTX_data_main(mContext); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ((animType->transform) != 0) { | 
					
						
							|  |  |  |     /* const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL; */ /* UNUSED */ | 
					
						
							|  |  |  |     char joint_path[200]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (!ob->adt || !ob->adt->action) { | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |       act = ED_id_action_ensure(bmain, (ID *)&ob->id); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       act = ob->adt->action; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* Get the list of animation curves of the object */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     ListBase *AnimCurves = &(act->curves); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* for each transformation in node */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { | 
					
						
							|  |  |  |       COLLADAFW::Transformation *transform = nodeTransforms[i]; | 
					
						
							|  |  |  |       COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; | 
					
						
							|  |  |  |       bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const COLLADAFW::UniqueId &listid = transform->getAnimationList(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* check if transformation has animations */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       if (animlist_map.find(listid) == animlist_map.end()) { | 
					
						
							|  |  |  |         continue; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       /* transformation has animations */ | 
					
						
							|  |  |  |       const COLLADAFW::AnimationList *animlist = animlist_map[listid]; | 
					
						
							|  |  |  |       const COLLADAFW::AnimationList::AnimationBindings &bindings = | 
					
						
							|  |  |  |           animlist->getAnimationBindings(); | 
					
						
							|  |  |  |       /* all the curves belonging to the current binding */ | 
					
						
							|  |  |  |       std::vector<FCurve *> animcurves; | 
					
						
							|  |  |  |       for (unsigned int j = 0; j < bindings.getCount(); j++) { | 
					
						
							|  |  |  |         animcurves = curve_map[bindings[j].animation]; | 
					
						
							|  |  |  |         if (is_matrix) { | 
					
						
							|  |  |  |           apply_matrix_curves(ob, animcurves, root, node, transform); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           /* calculate rnapaths and array index of fcurves according to transformation and
 | 
					
						
							|  |  |  |            * animation class */ | 
					
						
							|  |  |  |           Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  |           /* Add the curves of the current animation to the object */ | 
					
						
							|  |  |  |           for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { | 
					
						
							|  |  |  |             FCurve *fcu = *iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             BLI_addtail(AnimCurves, fcu); | 
					
						
							|  |  |  |             fcurve_is_used(fcu); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-02 19:06:14 +02:00
										 |  |  |       if (is_rotation && !(is_joint || is_matrix)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         ob->rotmode = ROT_MODE_EUL; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if ((animType->light) != 0) { | 
					
						
							|  |  |  |     Light *lamp = (Light *)ob->data; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (!lamp->adt || !lamp->adt->action) { | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |       act = ED_id_action_ensure(bmain, (ID *)&lamp->id); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       act = lamp->adt->action; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ListBase *AnimCurves = &(act->curves); | 
					
						
							|  |  |  |     const COLLADAFW::InstanceLightPointerArray &nodeLights = node->getInstanceLights(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (unsigned int i = 0; i < nodeLights.getCount(); i++) { | 
					
						
							|  |  |  |       const COLLADAFW::Light *light = (COLLADAFW::Light *) | 
					
						
							|  |  |  |           FW_object_map[nodeLights[i]->getInstanciatedObjectId()]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((animType->light & LIGHT_COLOR) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::Color *col = &(light->getColor()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = col->getAnimationList(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Assign_color_animations(listid, AnimCurves, "color"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if ((animType->light & LIGHT_FOA) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = foa->getAnimationList(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Assign_float_animations(listid, AnimCurves, "spot_size"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       if ((animType->light & LIGHT_FOE) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *foe = &(light->getFallOffExponent()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = foe->getAnimationList(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Assign_float_animations(listid, AnimCurves, "spot_blend"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (animType->camera != 0) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Camera *cam = (Camera *)ob->data; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (!cam->adt || !cam->adt->action) { | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |       act = ED_id_action_ensure(bmain, (ID *)&cam->id); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       act = cam->adt->action; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ListBase *AnimCurves = &(act->curves); | 
					
						
							|  |  |  |     const COLLADAFW::InstanceCameraPointerArray &nodeCameras = node->getInstanceCameras(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (unsigned int i = 0; i < nodeCameras.getCount(); i++) { | 
					
						
							|  |  |  |       const COLLADAFW::Camera *camera = (COLLADAFW::Camera *) | 
					
						
							|  |  |  |           FW_object_map[nodeCameras[i]->getInstanciatedObjectId()]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((animType->camera & CAMERA_XFOV) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *xfov = &(camera->getXFov()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = xfov->getAnimationList(); | 
					
						
							|  |  |  |         double aspect = get_aspect_ratio(camera); | 
					
						
							|  |  |  |         Assign_lens_animations(listid, AnimCurves, aspect, cam, "lens", CAMERA_XFOV); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       else if ((animType->camera & CAMERA_YFOV) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *yfov = &(camera->getYFov()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = yfov->getAnimationList(); | 
					
						
							|  |  |  |         double aspect = get_aspect_ratio(camera); | 
					
						
							|  |  |  |         Assign_lens_animations(listid, AnimCurves, aspect, cam, "lens", CAMERA_YFOV); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       else if ((animType->camera & CAMERA_XMAG) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *xmag = &(camera->getXMag()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = xmag->getAnimationList(); | 
					
						
							|  |  |  |         Assign_float_animations(listid, AnimCurves, "ortho_scale"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       else if ((animType->camera & CAMERA_YMAG) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *ymag = &(camera->getYMag()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = ymag->getAnimationList(); | 
					
						
							|  |  |  |         Assign_float_animations(listid, AnimCurves, "ortho_scale"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((animType->camera & CAMERA_ZFAR) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *zfar = &(camera->getFarClippingPlane()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = zfar->getAnimationList(); | 
					
						
							|  |  |  |         Assign_float_animations(listid, AnimCurves, "clip_end"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if ((animType->camera & CAMERA_ZNEAR) != 0) { | 
					
						
							|  |  |  |         const COLLADAFW::AnimatableFloat *znear = &(camera->getNearClippingPlane()); | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &listid = znear->getAnimationList(); | 
					
						
							|  |  |  |         Assign_float_animations(listid, AnimCurves, "clip_start"); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   if (animType->material != 0) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-05 11:23:58 +01:00
										 |  |  |     Material *ma = BKE_object_material_get(ob, 1); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (!ma->adt || !ma->adt->action) { | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |       act = ED_id_action_ensure(bmain, (ID *)&ma->id); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       act = ma->adt->action; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms = node->getInstanceGeometries(); | 
					
						
							|  |  |  |     for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) { | 
					
						
							|  |  |  |       const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings(); | 
					
						
							|  |  |  |       for (unsigned int j = 0; j < matBinds.getCount(); j++) { | 
					
						
							|  |  |  |         const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial(); | 
					
						
							|  |  |  |         const COLLADAFW::Effect *ef = (COLLADAFW::Effect *)(FW_object_map[matuid]); | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |         if (ef != nullptr) { /* can be NULL T28909. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           Material *ma = uid_material_map[matuid]; | 
					
						
							|  |  |  |           if (!ma) { | 
					
						
							|  |  |  |             fprintf(stderr, | 
					
						
							|  |  |  |                     "Collada: Node %s refers to undefined material\n", | 
					
						
							|  |  |  |                     node->getName().c_str()); | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           ListBase &AnimCurves = get_animation_curves(bmain, ma); | 
					
						
							|  |  |  |           const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects(); | 
					
						
							|  |  |  |           COLLADAFW::EffectCommon *efc = commonEffects[0]; | 
					
						
							|  |  |  |           if ((animType->material & MATERIAL_SHININESS) != 0) { | 
					
						
							|  |  |  |             const COLLADAFW::FloatOrParam *shin = &(efc->getShininess()); | 
					
						
							|  |  |  |             const COLLADAFW::UniqueId &listid = shin->getAnimationList(); | 
					
						
							|  |  |  |             Assign_float_animations(listid, &AnimCurves, "specular_hardness"); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if ((animType->material & MATERIAL_IOR) != 0) { | 
					
						
							|  |  |  |             const COLLADAFW::FloatOrParam *ior = &(efc->getIndexOfRefraction()); | 
					
						
							|  |  |  |             const COLLADAFW::UniqueId &listid = ior->getAnimationList(); | 
					
						
							|  |  |  |             Assign_float_animations(listid, &AnimCurves, "raytrace_transparency.ior"); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if ((animType->material & MATERIAL_SPEC_COLOR) != 0) { | 
					
						
							|  |  |  |             const COLLADAFW::ColorOrTexture *cot = &(efc->getSpecular()); | 
					
						
							|  |  |  |             const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList(); | 
					
						
							|  |  |  |             Assign_color_animations(listid, &AnimCurves, "specular_color"); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if ((animType->material & MATERIAL_DIFF_COLOR) != 0) { | 
					
						
							|  |  |  |             const COLLADAFW::ColorOrTexture *cot = &(efc->getDiffuse()); | 
					
						
							|  |  |  |             const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList(); | 
					
						
							|  |  |  |             Assign_color_animations(listid, &AnimCurves, "diffuse_color"); | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   delete animType; | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::add_bone_animation_sampled(Object *ob, | 
					
						
							|  |  |  |                                                    std::vector<FCurve *> &animcurves, | 
					
						
							|  |  |  |                                                    COLLADAFW::Node *root, | 
					
						
							|  |  |  |                                                    COLLADAFW::Node *node, | 
					
						
							|  |  |  |                                                    COLLADAFW::Transformation *tm) | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const char *bone_name = bc_get_joint_name(node); | 
					
						
							|  |  |  |   char joint_path[200]; | 
					
						
							|  |  |  |   armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path)); | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<float> frames; | 
					
						
							|  |  |  |   find_frames(&frames, &animcurves); | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* convert degrees to radians */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (tm->getTransformationType() == COLLADAFW::Transformation::ROTATE) { | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  |     for (iter = animcurves.begin(); iter != animcurves.end(); iter++) { | 
					
						
							|  |  |  |       FCurve *fcu = *iter; | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       fcurve_deg_to_rad(fcu); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float irest_dae[4][4]; | 
					
						
							|  |  |  |   float rest[4][4], irest[4][4]; | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   get_joint_rest_mat(irest_dae, root, node); | 
					
						
							|  |  |  |   invert_m4(irest_dae); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Bone *bone = BKE_armature_find_bone_name((bArmature *)ob->data, bone_name); | 
					
						
							|  |  |  |   if (!bone) { | 
					
						
							|  |  |  |     fprintf(stderr, "cannot find bone \"%s\"\n", bone_name); | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unit_m4(rest); | 
					
						
							|  |  |  |   copy_m4_m4(rest, bone->arm_mat); | 
					
						
							|  |  |  |   invert_m4_m4(irest, rest); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* new curves to assign matrix transform animation */ | 
					
						
							|  |  |  |   FCurve *newcu[10]; /* if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   unsigned int totcu = 10; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   const char *tm_str = nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   char rna_path[200]; | 
					
						
							|  |  |  |   for (int i = 0; i < totcu; i++) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int axis = i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (i < 4) { | 
					
						
							|  |  |  |       tm_str = "rotation_quaternion"; | 
					
						
							|  |  |  |       axis = i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (i < 7) { | 
					
						
							|  |  |  |       tm_str = "location"; | 
					
						
							|  |  |  |       axis = i - 4; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       tm_str = "scale"; | 
					
						
							|  |  |  |       axis = i - 7; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newcu[i] = create_fcurve(axis, rna_path); | 
					
						
							|  |  |  |     newcu[i]->totvert = frames.size(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:59:27 +02:00
										 |  |  |   if (frames.empty()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::sort(frames.begin(), frames.end()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 22:08:23 +02:00
										 |  |  |   BCQuat qref; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::vector<float>::iterator it; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* sample values at each frame */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (it = frames.begin(); it != frames.end(); it++) { | 
					
						
							|  |  |  |     float fra = *it; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 22:08:23 +02:00
										 |  |  |     Matrix mat; | 
					
						
							|  |  |  |     Matrix matfra; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     unit_m4(matfra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* calc object-space mat */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     evaluate_transform_at_frame(matfra, node, fra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* for joints, we need a special matrix
 | 
					
						
							|  |  |  |      * special matrix: iR * M * iR_dae * R | 
					
						
							|  |  |  |      * where R, iR are bone rest and inverse rest mats in world space (Blender bones), | 
					
						
							|  |  |  |      * iR_dae is joint inverse rest matrix (DAE) | 
					
						
							|  |  |  |      * and M is an evaluated joint world-space matrix (DAE). */ | 
					
						
							| 
									
										
										
										
											2019-05-28 22:08:23 +02:00
										 |  |  |     Matrix temp, par; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* calc M */ | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |     calc_joint_parent_mat_rest(par, nullptr, root, node); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     mul_m4_m4m4(temp, par, matfra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* evaluate_joint_world_transform_at_frame(temp, NULL, node, fra); */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* calc special matrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     mul_m4_series(mat, irest, temp, irest_dae, rest); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 22:08:23 +02:00
										 |  |  |     Vector loc, scale; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-28 22:08:23 +02:00
										 |  |  |     qref.rotate_to(mat); | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     copy_v3_v3(loc, mat[3]); | 
					
						
							|  |  |  |     mat4_to_size(scale, mat); | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* add keys */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (int i = 0; i < totcu; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       if (i < 4) { | 
					
						
							| 
									
										
										
										
											2019-05-28 22:08:23 +02:00
										 |  |  |         add_bezt(newcu[i], fra, qref.quat()[i]); | 
					
						
							| 
									
										
										
										
											2019-06-04 10:51:48 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       else if (i < 7) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         add_bezt(newcu[i], fra, loc[i - 4]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         add_bezt(newcu[i], fra, scale[i - 7]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   Main *bmain = CTX_data_main(mContext); | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |   ED_id_action_ensure(bmain, (ID *)&ob->id); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* add curves */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (int i = 0; i < totcu; i++) { | 
					
						
							|  |  |  |     add_bone_fcurve(ob, node, newcu[i]); | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |     fcurve_is_used(newcu[i]);  /* never added to unused */ | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name); | 
					
						
							|  |  |  |   chan->rotmode = ROT_MODE_QUAT; | 
					
						
							| 
									
										
										
										
											2012-02-18 06:22:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* Check if object is animated by checking if animlist_map
 | 
					
						
							|  |  |  |  * holds the animlist_id of node transforms */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | AnimationImporter::AnimMix *AnimationImporter::get_animation_type( | 
					
						
							|  |  |  |     const COLLADAFW::Node *node, | 
					
						
							|  |  |  |     std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map) | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   AnimMix *types = new AnimMix(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* for each transformation in node */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) { | 
					
						
							|  |  |  |     COLLADAFW::Transformation *transform = nodeTransforms[i]; | 
					
						
							|  |  |  |     const COLLADAFW::UniqueId &listid = transform->getAnimationList(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* check if transformation has animations */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (animlist_map.find(listid) == animlist_map.end()) { | 
					
						
							|  |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     types->transform = types->transform | BC_NODE_TRANSFORM; | 
					
						
							|  |  |  |     break; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   const COLLADAFW::InstanceLightPointerArray &nodeLights = node->getInstanceLights(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (unsigned int i = 0; i < nodeLights.getCount(); i++) { | 
					
						
							|  |  |  |     const COLLADAFW::Light *light = (COLLADAFW::Light *) | 
					
						
							|  |  |  |         FW_object_map[nodeLights[i]->getInstanciatedObjectId()]; | 
					
						
							|  |  |  |     types->light = setAnimType(&(light->getColor()), (types->light), LIGHT_COLOR); | 
					
						
							|  |  |  |     types->light = setAnimType(&(light->getFallOffAngle()), (types->light), LIGHT_FOA); | 
					
						
							|  |  |  |     types->light = setAnimType(&(light->getFallOffExponent()), (types->light), LIGHT_FOE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (types->light != 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const COLLADAFW::InstanceCameraPointerArray &nodeCameras = node->getInstanceCameras(); | 
					
						
							|  |  |  |   for (unsigned int i = 0; i < nodeCameras.getCount(); i++) { | 
					
						
							|  |  |  |     const COLLADAFW::Camera *camera = (COLLADAFW::Camera *) | 
					
						
							|  |  |  |         FW_object_map[nodeCameras[i]->getInstanciatedObjectId()]; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |     if (camera == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* Can happen if the node refers to an unknown camera. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       continue; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const bool is_perspective_type = camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int addition; | 
					
						
							|  |  |  |     const COLLADAFW::Animatable *mag; | 
					
						
							|  |  |  |     const COLLADAFW::UniqueId listid = camera->getYMag().getAnimationList(); | 
					
						
							|  |  |  |     if (animlist_map.find(listid) != animlist_map.end()) { | 
					
						
							|  |  |  |       mag = &(camera->getYMag()); | 
					
						
							|  |  |  |       addition = (is_perspective_type) ? CAMERA_YFOV : CAMERA_YMAG; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       mag = &(camera->getXMag()); | 
					
						
							|  |  |  |       addition = (is_perspective_type) ? CAMERA_XFOV : CAMERA_XMAG; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     types->camera = setAnimType(mag, (types->camera), addition); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     types->camera = setAnimType(&(camera->getFarClippingPlane()), (types->camera), CAMERA_ZFAR); | 
					
						
							|  |  |  |     types->camera = setAnimType(&(camera->getNearClippingPlane()), (types->camera), CAMERA_ZNEAR); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (types->camera != 0) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       break; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms = node->getInstanceGeometries(); | 
					
						
							|  |  |  |   for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) { | 
					
						
							|  |  |  |     const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings(); | 
					
						
							|  |  |  |     for (unsigned int j = 0; j < matBinds.getCount(); j++) { | 
					
						
							|  |  |  |       const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial(); | 
					
						
							|  |  |  |       const COLLADAFW::Effect *ef = (COLLADAFW::Effect *)(FW_object_map[matuid]); | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       if (ef != nullptr) { /* can be NULL T28909. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects(); | 
					
						
							|  |  |  |         if (!commonEffects.empty()) { | 
					
						
							|  |  |  |           COLLADAFW::EffectCommon *efc = commonEffects[0]; | 
					
						
							|  |  |  |           types->material = setAnimType( | 
					
						
							|  |  |  |               &(efc->getShininess()), (types->material), MATERIAL_SHININESS); | 
					
						
							|  |  |  |           types->material = setAnimType( | 
					
						
							|  |  |  |               &(efc->getSpecular().getColor()), (types->material), MATERIAL_SPEC_COLOR); | 
					
						
							|  |  |  |           types->material = setAnimType( | 
					
						
							|  |  |  |               &(efc->getDiffuse().getColor()), (types->material), MATERIAL_DIFF_COLOR); | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  |           types->material = setAnimType(&(efc->get()), (types->material), MATERIAL_TRANSPARENCY); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           types->material = setAnimType( | 
					
						
							|  |  |  |               &(efc->getIndexOfRefraction()), (types->material), MATERIAL_IOR); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return types; | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-06-16 19:25:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 22:05:33 +00:00
										 |  |  | int AnimationImporter::setAnimType(const COLLADAFW::Animatable *prop, int types, int addition) | 
					
						
							| 
									
										
										
										
											2011-07-09 19:33:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   int anim_type; | 
					
						
							|  |  |  |   const COLLADAFW::UniqueId &listid = prop->getAnimationList(); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (animlist_map.find(listid) != animlist_map.end()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     anim_type = types | addition; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     anim_type = types; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return anim_type; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-09 19:33:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* Is not used anymore. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::find_frames_old(std::vector<float> *frames, | 
					
						
							|  |  |  |                                         COLLADAFW::Node *node, | 
					
						
							|  |  |  |                                         COLLADAFW::Transformation::TransformationType tm_type) | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; | 
					
						
							|  |  |  |   bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* for each <rotate>, <translate>, etc. there is a separate Transformation */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unsigned int i; | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* find frames at which to sample plus convert all rotation keys to radians */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (i = 0; i < nodeTransforms.getCount(); i++) { | 
					
						
							|  |  |  |     COLLADAFW::Transformation *transform = nodeTransforms[i]; | 
					
						
							|  |  |  |     COLLADAFW::Transformation::TransformationType nodeTmType = transform->getTransformationType(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (nodeTmType == tm_type) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* get animation bindings for the current transformation */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       const COLLADAFW::UniqueId &listid = transform->getAnimationList(); | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* if transform is animated its animlist must exist. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       if (animlist_map.find(listid) != animlist_map.end()) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         const COLLADAFW::AnimationList *animlist = animlist_map[listid]; | 
					
						
							|  |  |  |         const COLLADAFW::AnimationList::AnimationBindings &bindings = | 
					
						
							|  |  |  |             animlist->getAnimationBindings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (bindings.getCount()) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |           /* for each AnimationBinding get the fcurves which animate the transform */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           for (unsigned int j = 0; j < bindings.getCount(); j++) { | 
					
						
							|  |  |  |             std::vector<FCurve *> &curves = curve_map[bindings[j].animation]; | 
					
						
							|  |  |  |             bool xyz = ((nodeTmType == COLLADAFW::Transformation::TRANSLATE || | 
					
						
							|  |  |  |                          nodeTmType == COLLADAFW::Transformation::SCALE) && | 
					
						
							|  |  |  |                         bindings[j].animationClass == COLLADAFW::AnimationList::POSITION_XYZ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ((!xyz && curves.size() == 1) || (xyz && curves.size() == 3) || is_matrix) { | 
					
						
							|  |  |  |               std::vector<FCurve *>::iterator iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |               for (iter = curves.begin(); iter != curves.end(); iter++) { | 
					
						
							|  |  |  |                 FCurve *fcu = *iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |                 /* if transform is rotation the fcurves values must be turned in to radian. */ | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |                 if (is_rotation) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                   fcurve_deg_to_rad(fcu); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 for (unsigned int k = 0; k < fcu->totvert; k++) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |                   /* get frame value from bezTriple */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                   float fra = fcu->bezt[k].vec[1][0]; | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |                   /* if frame already not added add frame to frames */ | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |                   if (std::find(frames->begin(), frames->end(), fra) == frames->end()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                     frames->push_back(fra); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |                   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                 } | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             else { | 
					
						
							|  |  |  |               fprintf(stderr, "expected %d curves, got %d\n", xyz ? 3 : 1, (int)curves.size()); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* prerequisites:
 | 
					
						
							|  |  |  |  * animlist_map - map animlist id -> animlist | 
					
						
							|  |  |  |  * curve_map - map anim id -> curve(s) */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | Object *AnimationImporter::translate_animation_OLD( | 
					
						
							|  |  |  |     COLLADAFW::Node *node, | 
					
						
							|  |  |  |     std::map<COLLADAFW::UniqueId, Object *> &object_map, | 
					
						
							|  |  |  |     std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map, | 
					
						
							|  |  |  |     COLLADAFW::Transformation::TransformationType tm_type, | 
					
						
							|  |  |  |     Object *par_job) | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE; | 
					
						
							|  |  |  |   bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX; | 
					
						
							|  |  |  |   bool is_joint = node->getType() == COLLADAFW::Node::JOINT; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   COLLADAFW::Node *root = root_map.find(node->getUniqueId()) == root_map.end() ? | 
					
						
							|  |  |  |                               node : | 
					
						
							|  |  |  |                               root_map[node->getUniqueId()]; | 
					
						
							|  |  |  |   Object *ob = is_joint ? armature_importer->get_armature_for_joint(node) : | 
					
						
							|  |  |  |                           object_map[node->getUniqueId()]; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   const char *bone_name = is_joint ? bc_get_joint_name(node) : nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (!ob) { | 
					
						
							|  |  |  |     fprintf(stderr, "cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str()); | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |     return nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-06-14 20:42:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* frames at which to sample */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   std::vector<float> frames; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   find_frames_old(&frames, node, tm_type); | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   unsigned int i; | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float irest_dae[4][4]; | 
					
						
							|  |  |  |   float rest[4][4], irest[4][4]; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (is_joint) { | 
					
						
							|  |  |  |     get_joint_rest_mat(irest_dae, root, node); | 
					
						
							|  |  |  |     invert_m4(irest_dae); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     Bone *bone = BKE_armature_find_bone_name((bArmature *)ob->data, bone_name); | 
					
						
							|  |  |  |     if (!bone) { | 
					
						
							|  |  |  |       fprintf(stderr, "cannot find bone \"%s\"\n", bone_name); | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       return nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     unit_m4(rest); | 
					
						
							|  |  |  |     copy_m4_m4(rest, bone->arm_mat); | 
					
						
							|  |  |  |     invert_m4_m4(irest, rest); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   Object *job = nullptr; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ARMATURE_TEST
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   FCurve *job_curves[10]; | 
					
						
							|  |  |  |   job = get_joint_object(root, node, par_job); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:59:27 +02:00
										 |  |  |   if (frames.empty()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return job; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::sort(frames.begin(), frames.end()); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   const char *tm_str = nullptr; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   switch (tm_type) { | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::ROTATE: | 
					
						
							|  |  |  |       tm_str = "rotation_quaternion"; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::SCALE: | 
					
						
							|  |  |  |       tm_str = "scale"; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::TRANSLATE: | 
					
						
							|  |  |  |       tm_str = "location"; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case COLLADAFW::Transformation::MATRIX: | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       return job; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   char rna_path[200]; | 
					
						
							|  |  |  |   char joint_path[200]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* new curves */ | 
					
						
							|  |  |  |   FCurve *newcu[10]; /* if tm_type is matrix, then create 10 curves: 4 rot, 3 loc, 3 scale */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   unsigned int totcu = is_matrix ? 10 : (is_rotation ? 4 : 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (i = 0; i < totcu; i++) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int axis = i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (is_matrix) { | 
					
						
							|  |  |  |       if (i < 4) { | 
					
						
							|  |  |  |         tm_str = "rotation_quaternion"; | 
					
						
							|  |  |  |         axis = i; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (i < 7) { | 
					
						
							|  |  |  |         tm_str = "location"; | 
					
						
							|  |  |  |         axis = i - 4; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         tm_str = "scale"; | 
					
						
							|  |  |  |         axis = i - 7; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_snprintf(rna_path, sizeof(rna_path), "%s.%s", joint_path, tm_str); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_strncpy(rna_path, tm_str, sizeof(rna_path)); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     newcu[i] = create_fcurve(axis, rna_path); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ARMATURE_TEST
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       job_curves[i] = create_fcurve(axis, tm_str); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::vector<float>::iterator it; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* sample values at each frame */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (it = frames.begin(); it != frames.end(); it++) { | 
					
						
							|  |  |  |     float fra = *it; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     float mat[4][4]; | 
					
						
							|  |  |  |     float matfra[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unit_m4(matfra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* calc object-space mat */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     evaluate_transform_at_frame(matfra, node, fra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* for joints, we need a special matrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* special matrix: iR * M * iR_dae * R
 | 
					
						
							|  |  |  |        * where R, iR are bone rest and inverse rest mats in world space (Blender bones), | 
					
						
							|  |  |  |        * iR_dae is joint inverse rest matrix (DAE) | 
					
						
							|  |  |  |        * and M is an evaluated joint world-space matrix (DAE). */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       float temp[4][4], par[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* calc M */ | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       calc_joint_parent_mat_rest(par, nullptr, root, node); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       mul_m4_m4m4(temp, par, matfra); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* evaluate_joint_world_transform_at_frame(temp, NULL, node, fra); */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |       /* calc special matrix */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       mul_m4_series(mat, irest, temp, irest_dae, rest); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       copy_m4_m4(mat, matfra); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     float val[4] = {}; | 
					
						
							|  |  |  |     float rot[4], loc[3], scale[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (tm_type) { | 
					
						
							|  |  |  |       case COLLADAFW::Transformation::ROTATE: | 
					
						
							|  |  |  |         mat4_to_quat(val, mat); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case COLLADAFW::Transformation::SCALE: | 
					
						
							|  |  |  |         mat4_to_size(val, mat); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case COLLADAFW::Transformation::TRANSLATE: | 
					
						
							|  |  |  |         copy_v3_v3(val, mat[3]); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       case COLLADAFW::Transformation::MATRIX: | 
					
						
							|  |  |  |         mat4_to_quat(rot, mat); | 
					
						
							|  |  |  |         copy_v3_v3(loc, mat[3]); | 
					
						
							|  |  |  |         mat4_to_size(scale, mat); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       default: | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* add keys */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (i = 0; i < totcu; i++) { | 
					
						
							|  |  |  |       if (is_matrix) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |         if (i < 4) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           add_bezt(newcu[i], fra, rot[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         else if (i < 7) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           add_bezt(newcu[i], fra, loc[i - 4]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           add_bezt(newcu[i], fra, scale[i - 7]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         add_bezt(newcu[i], fra, val[i]); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ARMATURE_TEST
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (is_joint) { | 
					
						
							|  |  |  |       switch (tm_type) { | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::ROTATE: | 
					
						
							|  |  |  |           mat4_to_quat(val, matfra); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::SCALE: | 
					
						
							|  |  |  |           mat4_to_size(val, matfra); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::TRANSLATE: | 
					
						
							|  |  |  |           copy_v3_v3(val, matfra[3]); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case MATRIX: | 
					
						
							|  |  |  |           mat4_to_quat(rot, matfra); | 
					
						
							|  |  |  |           copy_v3_v3(loc, matfra[3]); | 
					
						
							|  |  |  |           mat4_to_size(scale, matfra); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       for (i = 0; i < totcu; i++) { | 
					
						
							|  |  |  |         if (is_matrix) { | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |           if (i < 4) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             add_bezt(job_curves[i], fra, rot[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |           } | 
					
						
							|  |  |  |           else if (i < 7) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             add_bezt(job_curves[i], fra, loc[i - 4]); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |           } | 
					
						
							|  |  |  |           else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             add_bezt(job_curves[i], fra, scale[i - 7]); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |           add_bezt(job_curves[i], fra, val[i]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   Main *bmain = CTX_data_main(mContext); | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |   ED_id_action_ensure(bmain, (ID *)&ob->id); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   ListBase *curves = &ob->adt->action->curves; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* add curves */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   for (i = 0; i < totcu; i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       add_bone_fcurve(ob, node, newcu[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_addtail(curves, newcu[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ARMATURE_TEST
 | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     if (is_joint) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       BLI_addtail(&job->adt->action->curves, job_curves[i]); | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (is_rotation || is_matrix) { | 
					
						
							|  |  |  |     if (is_joint) { | 
					
						
							|  |  |  |       bPoseChannel *chan = BKE_pose_channel_find_name(ob->pose, bone_name); | 
					
						
							| 
									
										
										
										
											2019-06-04 10:51:48 +10:00
										 |  |  |       chan->rotmode = (is_matrix) ? ROT_MODE_QUAT : ROT_MODE_EUL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-06-02 19:06:14 +02:00
										 |  |  |       ob->rotmode = (is_matrix) ? ROT_MODE_QUAT : ROT_MODE_EUL; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return job; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* internal, better make it private
 | 
					
						
							|  |  |  |  * warning: evaluates only rotation and only assigns matrix transforms now | 
					
						
							|  |  |  |  * prerequisites: animlist_map, curve_map */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::evaluate_transform_at_frame(float mat[4][4], | 
					
						
							|  |  |  |                                                     COLLADAFW::Node *node, | 
					
						
							|  |  |  |                                                     float fra) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const COLLADAFW::TransformationPointerArray &tms = node->getTransformations(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unit_m4(mat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   for (unsigned int i = 0; i < tms.getCount(); i++) { | 
					
						
							|  |  |  |     COLLADAFW::Transformation *tm = tms[i]; | 
					
						
							|  |  |  |     COLLADAFW::Transformation::TransformationType type = tm->getTransformationType(); | 
					
						
							|  |  |  |     float m[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     unit_m4(m); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-03 14:59:27 +02:00
										 |  |  |     std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (!evaluate_animation(tm, m, fra, nodename.c_str())) { | 
					
						
							|  |  |  |       switch (type) { | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::ROTATE: | 
					
						
							|  |  |  |           dae_rotate_to_mat4(tm, m); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::TRANSLATE: | 
					
						
							|  |  |  |           dae_translate_to_mat4(tm, m); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::SCALE: | 
					
						
							|  |  |  |           dae_scale_to_mat4(tm, m); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::MATRIX: | 
					
						
							|  |  |  |           dae_matrix_to_mat4(tm, m); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           fprintf(stderr, "unsupported transformation type %d\n", type); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     float temp[4][4]; | 
					
						
							|  |  |  |     copy_m4_m4(temp, mat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     mul_m4_m4m4(mat, temp, m); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-08 08:07:48 +02:00
										 |  |  | static void report_class_type_unsupported(const char *path, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |                                           const COLLADAFW::AnimationList::AnimationClass animclass, | 
					
						
							|  |  |  |                                           const COLLADAFW::Transformation::TransformationType type) | 
					
						
							| 
									
										
										
										
											2013-07-15 10:50:04 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (animclass == COLLADAFW::AnimationList::UNKNOWN_CLASS) { | 
					
						
							|  |  |  |     fprintf(stderr, "%s: UNKNOWN animation class\n", path); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     fprintf(stderr, | 
					
						
							|  |  |  |             "%s: animation class %d is not supported yet for transformation type %d\n", | 
					
						
							|  |  |  |             path, | 
					
						
							|  |  |  |             animclass, | 
					
						
							|  |  |  |             type); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-07-15 10:50:04 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* return true to indicate that mat contains a sane value */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | bool AnimationImporter::evaluate_animation(COLLADAFW::Transformation *tm, | 
					
						
							|  |  |  |                                            float mat[4][4], | 
					
						
							|  |  |  |                                            float fra, | 
					
						
							|  |  |  |                                            const char *node_id) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const COLLADAFW::UniqueId &listid = tm->getAnimationList(); | 
					
						
							|  |  |  |   COLLADAFW::Transformation::TransformationType type = tm->getTransformationType(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (type != COLLADAFW::Transformation::ROTATE && type != COLLADAFW::Transformation::SCALE && | 
					
						
							|  |  |  |       type != COLLADAFW::Transformation::TRANSLATE && type != COLLADAFW::Transformation::MATRIX) { | 
					
						
							|  |  |  |     fprintf(stderr, "animation of transformation %d is not supported yet\n", type); | 
					
						
							|  |  |  |     return false; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   if (animlist_map.find(listid) == animlist_map.end()) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList *animlist = animlist_map[listid]; | 
					
						
							|  |  |  |   const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (bindings.getCount()) { | 
					
						
							|  |  |  |     float vec[3]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bool is_scale = (type == COLLADAFW::Transformation::SCALE); | 
					
						
							|  |  |  |     bool is_translate = (type == COLLADAFW::Transformation::TRANSLATE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_scale) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       dae_scale_to_v3(tm, vec); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (is_translate) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       dae_translate_to_v3(tm, vec); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (unsigned int index = 0; index < bindings.getCount(); index++) { | 
					
						
							|  |  |  |       const COLLADAFW::AnimationList::AnimationBinding &binding = bindings[index]; | 
					
						
							|  |  |  |       std::vector<FCurve *> &curves = curve_map[binding.animation]; | 
					
						
							|  |  |  |       COLLADAFW::AnimationList::AnimationClass animclass = binding.animationClass; | 
					
						
							|  |  |  |       char path[100]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       switch (type) { | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::ROTATE: | 
					
						
							|  |  |  |           BLI_snprintf(path, sizeof(path), "%s.rotate (binding %u)", node_id, index); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::SCALE: | 
					
						
							|  |  |  |           BLI_snprintf(path, sizeof(path), "%s.scale (binding %u)", node_id, index); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::TRANSLATE: | 
					
						
							|  |  |  |           BLI_snprintf(path, sizeof(path), "%s.translate (binding %u)", node_id, index); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         case COLLADAFW::Transformation::MATRIX: | 
					
						
							|  |  |  |           BLI_snprintf(path, sizeof(path), "%s.matrix (binding %u)", node_id, index); | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |         default: | 
					
						
							|  |  |  |           break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if (type == COLLADAFW::Transformation::ROTATE) { | 
					
						
							|  |  |  |         if (curves.size() != 1) { | 
					
						
							|  |  |  |           fprintf(stderr, "expected 1 curve, got %d\n", (int)curves.size()); | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |         /* TODO support other animclasses */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         if (animclass != COLLADAFW::AnimationList::ANGLE) { | 
					
						
							|  |  |  |           report_class_type_unsupported(path, animclass, type); | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         COLLADABU::Math::Vector3 &axis = ((COLLADAFW::Rotate *)tm)->getRotationAxis(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         float ax[3] = {(float)axis[0], (float)axis[1], (float)axis[2]}; | 
					
						
							|  |  |  |         float angle = evaluate_fcurve(curves[0], fra); | 
					
						
							|  |  |  |         axis_angle_to_mat4(mat, ax, angle); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2020-08-07 12:40:12 +02:00
										 |  |  |       if (is_scale || is_translate) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         bool is_xyz = animclass == COLLADAFW::AnimationList::POSITION_XYZ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((!is_xyz && curves.size() != 1) || (is_xyz && curves.size() != 3)) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |           if (is_xyz) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             fprintf(stderr, "%s: expected 3 curves, got %d\n", path, (int)curves.size()); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |           } | 
					
						
							|  |  |  |           else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |             fprintf(stderr, "%s: expected 1 curve, got %d\n", path, (int)curves.size()); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         switch (animclass) { | 
					
						
							|  |  |  |           case COLLADAFW::AnimationList::POSITION_X: | 
					
						
							|  |  |  |             vec[0] = evaluate_fcurve(curves[0], fra); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case COLLADAFW::AnimationList::POSITION_Y: | 
					
						
							|  |  |  |             vec[1] = evaluate_fcurve(curves[0], fra); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case COLLADAFW::AnimationList::POSITION_Z: | 
					
						
							|  |  |  |             vec[2] = evaluate_fcurve(curves[0], fra); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           case COLLADAFW::AnimationList::POSITION_XYZ: | 
					
						
							|  |  |  |             vec[0] = evaluate_fcurve(curves[0], fra); | 
					
						
							|  |  |  |             vec[1] = evaluate_fcurve(curves[1], fra); | 
					
						
							|  |  |  |             vec[2] = evaluate_fcurve(curves[2], fra); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |           default: | 
					
						
							|  |  |  |             report_class_type_unsupported(path, animclass, type); | 
					
						
							|  |  |  |             break; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else if (type == COLLADAFW::Transformation::MATRIX) { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |         /* for now, of matrix animation,
 | 
					
						
							|  |  |  |          * support only the case when all values are packed into one animation */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         if (curves.size() != 16) { | 
					
						
							|  |  |  |           fprintf(stderr, "%s: expected 16 curves, got %d\n", path, (int)curves.size()); | 
					
						
							|  |  |  |           return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         COLLADABU::Math::Matrix4 matrix; | 
					
						
							|  |  |  |         int mi = 0, mj = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (std::vector<FCurve *>::iterator it = curves.begin(); it != curves.end(); it++) { | 
					
						
							|  |  |  |           matrix.setElement(mi, mj, evaluate_fcurve(*it, fra)); | 
					
						
							|  |  |  |           mj++; | 
					
						
							|  |  |  |           if (mj == 4) { | 
					
						
							|  |  |  |             mi++; | 
					
						
							|  |  |  |             mj = 0; | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-04 12:26:24 +02:00
										 |  |  |         UnitConverter::dae_matrix_to_mat4_(mat, matrix); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (is_scale) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       size_to_mat4(mat, vec); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       copy_v3_v3(mat[3], vec); | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return is_scale || is_translate; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* gives a world-space mat of joint at rest position */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void AnimationImporter::get_joint_rest_mat(float mat[4][4], | 
					
						
							|  |  |  |                                            COLLADAFW::Node *root, | 
					
						
							|  |  |  |                                            COLLADAFW::Node *node) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* if bind mat is not available,
 | 
					
						
							|  |  |  |    * use "current" node transform, i.e. all those tms listed inside <node> */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (!armature_importer->get_joint_bind_mat(mat, node)) { | 
					
						
							|  |  |  |     float par[4][4], m[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |     calc_joint_parent_mat_rest(par, nullptr, root, node); | 
					
						
							|  |  |  |     get_node_mat(m, node, nullptr, nullptr); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     mul_m4_m4m4(mat, par, m); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* gives a world-space mat, end's mat not included */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | bool AnimationImporter::calc_joint_parent_mat_rest(float mat[4][4], | 
					
						
							|  |  |  |                                                    float par[4][4], | 
					
						
							|  |  |  |                                                    COLLADAFW::Node *node, | 
					
						
							|  |  |  |                                                    COLLADAFW::Node *end) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float m[4][4]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (node == end) { | 
					
						
							|  |  |  |     par ? copy_m4_m4(mat, par) : unit_m4(mat); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |   /* use bind matrix if available or calc "current" world mat */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (!armature_importer->get_joint_bind_mat(m, node)) { | 
					
						
							|  |  |  |     if (par) { | 
					
						
							|  |  |  |       float temp[4][4]; | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       get_node_mat(temp, node, nullptr, nullptr); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       mul_m4_m4m4(m, par, temp); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |       get_node_mat(m, node, nullptr, nullptr); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   COLLADAFW::NodePointerArray &children = node->getChildNodes(); | 
					
						
							|  |  |  |   for (unsigned int i = 0; i < children.getCount(); i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     if (calc_joint_parent_mat_rest(mat, m, children[i], end)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       return true; | 
					
						
							| 
									
										
										
										
											2019-05-31 22:51:19 +10:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef ARMATURE_TEST
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, | 
					
						
							|  |  |  |                                             COLLADAFW::Node *node, | 
					
						
							|  |  |  |                                             Object *par_job) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   if (joint_objects.find(node->getUniqueId()) == joint_objects.end()) { | 
					
						
							|  |  |  |     Object *job = bc_add_object(scene, OB_EMPTY, (char *)get_joint_name(node)); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     job->lay = BKE_scene_base_find(scene, job)->lay = 2; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     mul_v3_fl(job->scale, 0.5f); | 
					
						
							|  |  |  |     DEG_id_tag_update(&job->id, ID_RECALC_TRANSFORM); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-06 13:41:27 +11:00
										 |  |  |     ED_id_action_ensure((ID *)&job->id); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     job->rotmode = ROT_MODE_QUAT; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     float mat[4][4]; | 
					
						
							|  |  |  |     get_joint_rest_mat(mat, root, node); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (par_job) { | 
					
						
							|  |  |  |       float temp[4][4], ipar[4][4]; | 
					
						
							|  |  |  |       invert_m4_m4(ipar, par_job->obmat); | 
					
						
							|  |  |  |       copy_m4_m4(temp, mat); | 
					
						
							|  |  |  |       mul_m4_m4m4(mat, ipar, temp); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     bc_decompose(mat, job->loc, NULL, job->quat, job->scale); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     if (par_job) { | 
					
						
							|  |  |  |       job->parent = par_job; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       DEG_id_tag_update(&par_job->id, ID_RECALC_TRANSFORM); | 
					
						
							|  |  |  |       job->parsubstr[0] = 0; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     BKE_object_where_is_calc(scene, job); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  |     /* after parenting and layer change */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     DEG_relations_tag_update(CTX_data_main(C)); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     joint_objects[node->getUniqueId()] = job; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   return joint_objects[node->getUniqueId()]; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2019-04-30 13:41:21 +10:00
										 |  |  | /* recursively evaluates joint tree until end is found,
 | 
					
						
							|  |  |  |  * mat then is world-space matrix of end mat must be identity on enter, node must be root. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  | bool AnimationImporter::evaluate_joint_world_transform_at_frame( | 
					
						
							|  |  |  |     float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end, float fra) | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   float m[4][4]; | 
					
						
							|  |  |  |   if (par) { | 
					
						
							|  |  |  |     float temp[4][4]; | 
					
						
							|  |  |  |     evaluate_transform_at_frame(temp, node, node == end ? fra : 0.0f); | 
					
						
							|  |  |  |     mul_m4_m4m4(m, par, temp); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							|  |  |  |     evaluate_transform_at_frame(m, node, node == end ? fra : 0.0f); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (node == end) { | 
					
						
							|  |  |  |     copy_m4_m4(mat, m); | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  |     COLLADAFW::NodePointerArray &children = node->getChildNodes(); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     for (int i = 0; i < children.getCount(); i++) { | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |       if (evaluate_joint_world_transform_at_frame(mat, m, children[i], end, fra)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         return true; | 
					
						
							| 
									
										
										
										
											2019-05-31 23:21:16 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return false; | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AnimationImporter::add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurve *fcu) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const char *bone_name = bc_get_joint_name(node); | 
					
						
							|  |  |  |   bAction *act = ob->adt->action; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* try to find group */ | 
					
						
							|  |  |  |   bActionGroup *grp = BKE_action_group_find_name(act, bone_name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* no matching groups, so add one */ | 
					
						
							| 
									
										
										
										
											2020-11-06 17:49:09 +01:00
										 |  |  |   if (grp == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* Add a new group, and make it active */ | 
					
						
							|  |  |  |     grp = (bActionGroup *)MEM_callocN(sizeof(bActionGroup), "bActionGroup"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     grp->flag = AGRP_SELECTED; | 
					
						
							|  |  |  |     BLI_strncpy(grp->name, bone_name, sizeof(grp->name)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     BLI_addtail(&act->groups, grp); | 
					
						
							|  |  |  |     BLI_uniquename(&act->groups, | 
					
						
							|  |  |  |                    grp, | 
					
						
							|  |  |  |                    CTX_DATA_(BLT_I18NCONTEXT_ID_ACTION, "Group"), | 
					
						
							|  |  |  |                    '.', | 
					
						
							|  |  |  |                    offsetof(bActionGroup, name), | 
					
						
							|  |  |  |                    64); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* add F-Curve to group */ | 
					
						
							|  |  |  |   action_groups_add_channel(act, grp, fcu); | 
					
						
							| 
									
										
										
										
											2010-10-05 00:05:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-03 13:04:51 +01:00
										 |  |  | void AnimationImporter::set_import_from_version(std::string import_from_version) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   this->import_from_version = import_from_version; | 
					
						
							| 
									
										
										
										
											2014-02-03 13:04:51 +01:00
										 |  |  | } |