12#include "COLLADABUPlatform.h"
45 const std::string &
id = node->getName();
46 return id.empty() ? node->getOriginalId().c_str() :
id.c_str();
49FCurve *AnimationImporter::create_fcurve(
int array_index,
const char *rna_path)
58void AnimationImporter::add_bezt(
FCurve *fcu,
66 bez.
vec[1][0] = frame;
67 bez.
vec[1][1] = value;
75void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *curve)
77 COLLADAFW::FloatOrDoubleArray &input = curve->getInputValues();
78 COLLADAFW::FloatOrDoubleArray &output = curve->getOutputValues();
81 size_t dim = curve->getOutDimension();
84 std::vector<FCurve *> &fcurves = curve_map[curve->getUniqueId()];
92 for (i = 0; i < dim; i++) {
99 for (
uint j = 0; j < curve->getKeyCount(); j++) {
108 if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ||
109 curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP)
111 COLLADAFW::FloatOrDoubleArray &intan = curve->getInTangentValues();
112 COLLADAFW::FloatOrDoubleArray &outtan = curve->getOutTangentValues();
115 uint index = 2 * (j * dim + i);
122 if (curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) {
143 fcurves.push_back(fcu);
144 unused_curves.push_back(fcu);
150 "Output dimension of %d is not yet supported (animation id = %s)\n",
152 curve->getOriginalId().c_str());
156void AnimationImporter::fcurve_deg_to_rad(
FCurve *cu)
166void AnimationImporter::fcurve_scale(
FCurve *cu,
int scale)
170 cu->
bezt[i].
vec[1][1] *= scale;
171 cu->
bezt[i].
vec[0][1] *= scale;
172 cu->
bezt[i].
vec[2][1] *= scale;
176void AnimationImporter::fcurve_is_used(
FCurve *fcu)
178 unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu),
179 unused_curves.end());
185 for (
FCurve *unused_curve : unused_curves) {
189 if (!unused_curves.empty()) {
190 fprintf(stderr,
"removed %d unused curves\n",
int(unused_curves.size()));
196 if (anim->getAnimationType() == COLLADAFW::Animation::ANIMATION_CURVE) {
197 COLLADAFW::AnimationCurve *curve = (COLLADAFW::AnimationCurve *)anim;
201 if (curve->getInPhysicalDimension() != COLLADAFW::PHYSICAL_DIMENSION_TIME) {
202 fprintf(stderr,
"Inputs physical dimension is not time.\n");
208 COLLADAFW::AnimationCurve::InterpolationType
interp = curve->getInterpolationType();
210 if (
interp != COLLADAFW::AnimationCurve::INTERPOLATION_MIXED) {
212 case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
213 case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
214 case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
215 animation_to_fcurves(curve);
220 "CARDINAL, HERMITE and BSPLINE anim interpolation types not supported yet.\n");
226 fprintf(stderr,
"MIXED anim interpolation type is not supported yet.\n");
230 fprintf(stderr,
"FORMULA animation type is not supported yet.\n");
238 const COLLADAFW::UniqueId &animlist_id = animlist->getUniqueId();
239 animlist_map[animlist_id] = animlist;
244 if (uid_animated_map.find(animlist_id) == uid_animated_map.end()) {
266 const char *rna_path,
270 std::vector<FCurve *>::iterator it;
272 for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) {
276 if (array_index == -1) {
284 fcurve_scale(fcu, scale);
294 std::vector<FCurve *>::iterator it;
295 for (it = curves->begin(); it != curves->end(); it++) {
303 std::vector<FCurve *>::iterator iter;
304 for (iter = curves->begin(); iter != curves->end(); iter++) {
309 float fra = fcu->
bezt[k].
vec[1][0];
311 if (std::find(frames->begin(), frames->end(), fra) == frames->end()) {
312 frames->push_back(fra);
321 if (COLLADABU::Math::Vector3::UNIT_X == axis) {
324 else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
327 else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
337 COLLADAFW::Transformation *transform,
338 const COLLADAFW::AnimationList::AnimationBinding *binding,
339 std::vector<FCurve *> *curves,
343 COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
344 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
345 bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
349 (
ELEM(tm_type, COLLADAFW::Transformation::TRANSLATE, COLLADAFW::Transformation::SCALE) &&
350 binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
352 if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) {
353 fprintf(stderr,
"expected %d curves, got %d\n", xyz ? 3 : 1,
int(curves->size()));
360 case COLLADAFW::Transformation::TRANSLATE:
361 case COLLADAFW::Transformation::SCALE: {
362 bool loc = tm_type == COLLADAFW::Transformation::TRANSLATE;
364 SNPRINTF(rna_path,
"%s.%s", joint_path, loc ?
"location" :
"scale");
367 STRNCPY(rna_path, loc ?
"location" :
"scale");
370 switch (binding->animationClass) {
371 case COLLADAFW::AnimationList::POSITION_X:
374 case COLLADAFW::AnimationList::POSITION_Y:
377 case COLLADAFW::AnimationList::POSITION_Z:
380 case COLLADAFW::AnimationList::POSITION_XYZ:
386 "AnimationClass %d is not supported for %s.\n",
387 binding->animationClass,
388 loc ?
"TRANSLATE" :
"SCALE");
393 case COLLADAFW::Transformation::ROTATE: {
395 SNPRINTF(rna_path,
"%s.rotation_euler", joint_path);
398 STRNCPY(rna_path,
"rotation_euler");
400 std::vector<FCurve *>::iterator iter;
401 for (iter = curves->begin(); iter != curves->end(); iter++) {
406 fcurve_deg_to_rad(fcu);
409 const COLLADAFW::Rotate *
rot = (COLLADAFW::Rotate *)transform;
410 const COLLADABU::Math::Vector3 &axis =
rot->getRotationAxis();
412 switch (binding->animationClass) {
413 case COLLADAFW::AnimationList::ANGLE: {
415 if (axis_index >= 0) {
423 case COLLADAFW::AnimationList::AXISANGLE:
428 "AnimationClass %d is not supported for ROTATE transformation.\n",
429 binding->animationClass);
434 case COLLADAFW::Transformation::MATRIX:
437 COLLADAFW::Matrix *mat = (COLLADAFW::Matrix *)transform;
438 COLLADABU::Math::Matrix4
mat4 = mat->getMatrix();
439 switch (binding->animationClass) {
440 case COLLADAFW::AnimationList::TRANSFORM:
446 case COLLADAFW::Transformation::SKEW:
447 case COLLADAFW::Transformation::LOOKAT:
449 fprintf(stderr,
"Animation of SKEW and LOOKAT transformations is not supported yet.\n");
456 const char *anim_type)
461 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
462 if (animlist ==
nullptr) {
464 "Collada: No animlist found for ID: %s of type %s\n",
465 listid.toAscii().c_str(),
470 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
472 std::vector<FCurve *> animcurves;
473 for (
uint j = 0; j < bindings.getCount(); j++) {
474 animcurves = curve_map[bindings[j].animation];
476 switch (bindings[j].animationClass) {
477 case COLLADAFW::AnimationList::COLOR_R:
480 case COLLADAFW::AnimationList::COLOR_G:
483 case COLLADAFW::AnimationList::COLOR_B:
486 case COLLADAFW::AnimationList::COLOR_RGB:
487 case COLLADAFW::AnimationList::COLOR_RGBA:
494 "AnimationClass %d is not supported for %s.\n",
495 bindings[j].animationClass,
499 std::vector<FCurve *>::iterator iter;
501 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
511 const char *anim_type)
514 if (animlist_map.find(listid) == animlist_map.end()) {
519 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
520 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
522 std::vector<FCurve *> animcurves;
523 for (
uint j = 0; j < bindings.getCount(); j++) {
524 animcurves = curve_map[bindings[j].animation];
528 std::vector<FCurve *>::iterator iter;
530 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
534 if (
STREQ(
"spot_size", anim_type)) {
538 if (this->import_from_version.empty() ||
541 fcurve_deg_to_rad(fcu);
558 float xfov = (fov_type == CAMERA_YFOV) ?
568 const char *anim_type,
572 if (animlist_map.find(listid) == animlist_map.end()) {
577 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
578 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
580 std::vector<FCurve *> animcurves;
581 for (
uint j = 0; j < bindings.getCount(); j++) {
582 animcurves = curve_map[bindings[j].animation];
587 std::vector<FCurve *>::iterator iter;
589 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
608 std::vector<FCurve *> &animcurves,
609 COLLADAFW::Node *root,
610 COLLADAFW::Node *node,
611 COLLADAFW::Transformation *tm)
613 bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
615 char joint_path[200];
620 std::vector<float> frames;
623 float irest_dae[4][4];
624 float rest[4][4], irest[4][4];
632 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
643 const char *tm_str =
nullptr;
645 for (
int i = 0; i < totcu; i++) {
650 tm_str =
"rotation_quaternion";
663 SNPRINTF(rna_path,
"%s.%s", joint_path, tm_str);
668 newcu[i] = create_fcurve(axis, rna_path);
669 newcu[i]->
totvert = frames.size();
672 if (frames.empty()) {
676 std::sort(frames.begin(), frames.end());
678 std::vector<float>::iterator it;
681 for (it = frames.begin(); it != frames.end(); it++) {
698 float temp[4][4], par[4][4];
711 float rot[4], loc[3], scale[3];
715 for (
int i = 0; i < totcu; i++) {
717 add_bezt(newcu[i], fra,
rot[i]);
720 add_bezt(newcu[i], fra, loc[i - 4]);
723 add_bezt(newcu[i], fra, scale[i - 7]);
733 for (
int i = 0; i < totcu; i++) {
741 fcurve_is_used(newcu[i]);
766 double aspect = camera->getAspectRatio().getValue();
769 const double yfov = camera->getYFov().getValue();
775 const double xfov = camera->getXFov().getValue();
780 aspect = xfov / yfov;
801 COLLADAFW::Node *node,
802 std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map,
803 std::multimap<COLLADAFW::UniqueId, Object *> &object_map,
804 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map,
805 std::map<COLLADAFW::UniqueId, Material *> uid_material_map)
807 bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
808 COLLADAFW::UniqueId uid = node->getUniqueId();
809 COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ?
node : root_map[uid];
816 ob = object_map.find(uid) == object_map.end() ? nullptr : object_map.find(uid)->second;
820 fprintf(stderr,
"cannot find Object for Node with id=\"%s\"\n", node->getOriginalId().c_str());
828 if ((animType->transform) != 0) {
830 char joint_path[200];
846 const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations();
849 for (
uint i = 0; i < nodeTransforms.getCount(); i++) {
850 COLLADAFW::Transformation *transform = nodeTransforms[i];
851 COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
853 bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
854 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
856 const COLLADAFW::UniqueId &listid = transform->getAnimationList();
859 if (animlist_map.find(listid) == animlist_map.end()) {
864 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
865 const COLLADAFW::AnimationList::AnimationBindings &bindings =
866 animlist->getAnimationBindings();
868 std::vector<FCurve *> animcurves;
869 for (
uint j = 0; j < bindings.getCount(); j++) {
870 animcurves = curve_map[bindings[j].animation];
879 std::vector<FCurve *>::iterator iter;
881 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
890 if (is_rotation && !(is_joint || is_matrix)) {
896 if ((animType->light) != 0) {
906 const COLLADAFW::InstanceLightPointerArray &nodeLights = node->getInstanceLights();
908 for (
uint i = 0; i < nodeLights.getCount(); i++) {
909 const COLLADAFW::Light *light = (COLLADAFW::Light *)
910 FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
912 if ((animType->light & LIGHT_COLOR) != 0) {
913 const COLLADAFW::Color *
col = &light->getColor();
914 const COLLADAFW::UniqueId &listid =
col->getAnimationList();
918 if ((animType->light & LIGHT_FOA) != 0) {
919 const COLLADAFW::AnimatableFloat *foa = &light->getFallOffAngle();
920 const COLLADAFW::UniqueId &listid = foa->getAnimationList();
924 if ((animType->light & LIGHT_FOE) != 0) {
925 const COLLADAFW::AnimatableFloat *foe = &light->getFallOffExponent();
926 const COLLADAFW::UniqueId &listid = foe->getAnimationList();
933 if (animType->camera != 0) {
944 const COLLADAFW::InstanceCameraPointerArray &nodeCameras = node->getInstanceCameras();
946 for (
uint i = 0; i < nodeCameras.getCount(); i++) {
947 const COLLADAFW::Camera *camera = (COLLADAFW::Camera *)
948 FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
950 if ((animType->camera & CAMERA_XFOV) != 0) {
951 const COLLADAFW::AnimatableFloat *xfov = &camera->getXFov();
952 const COLLADAFW::UniqueId &listid = xfov->getAnimationList();
957 else if ((animType->camera & CAMERA_YFOV) != 0) {
958 const COLLADAFW::AnimatableFloat *yfov = &camera->getYFov();
959 const COLLADAFW::UniqueId &listid = yfov->getAnimationList();
964 else if ((animType->camera & CAMERA_XMAG) != 0) {
965 const COLLADAFW::AnimatableFloat *xmag = &camera->getXMag();
966 const COLLADAFW::UniqueId &listid = xmag->getAnimationList();
970 else if ((animType->camera & CAMERA_YMAG) != 0) {
971 const COLLADAFW::AnimatableFloat *ymag = &camera->getYMag();
972 const COLLADAFW::UniqueId &listid = ymag->getAnimationList();
976 if ((animType->camera & CAMERA_ZFAR) != 0) {
977 const COLLADAFW::AnimatableFloat *zfar = &camera->getFarClippingPlane();
978 const COLLADAFW::UniqueId &listid = zfar->getAnimationList();
982 if ((animType->camera & CAMERA_ZNEAR) != 0) {
983 const COLLADAFW::AnimatableFloat *znear = &camera->getNearClippingPlane();
984 const COLLADAFW::UniqueId &listid = znear->getAnimationList();
989 if (animType->material != 0) {
999 const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms = node->getInstanceGeometries();
1000 for (
uint i = 0; i < nodeGeoms.getCount(); i++) {
1001 const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
1002 for (
uint j = 0; j < matBinds.getCount(); j++) {
1003 const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
1004 const COLLADAFW::Effect *ef = (COLLADAFW::Effect *)(FW_object_map[matuid]);
1005 if (ef !=
nullptr) {
1006 Material *ma = uid_material_map[matuid];
1009 "Collada: Node %s refers to undefined material\n",
1010 node->getName().c_str());
1014 const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
1015 COLLADAFW::EffectCommon *efc = commonEffects[0];
1016 if ((animType->material & MATERIAL_SHININESS) != 0) {
1017 const COLLADAFW::FloatOrParam *shin = &efc->getShininess();
1018 const COLLADAFW::UniqueId &listid = shin->getAnimationList();
1022 if ((animType->material & MATERIAL_IOR) != 0) {
1023 const COLLADAFW::FloatOrParam *ior = &efc->getIndexOfRefraction();
1024 const COLLADAFW::UniqueId &listid = ior->getAnimationList();
1028 if ((animType->material & MATERIAL_SPEC_COLOR) != 0) {
1029 const COLLADAFW::ColorOrTexture *cot = &efc->getSpecular();
1030 const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
1034 if ((animType->material & MATERIAL_DIFF_COLOR) != 0) {
1035 const COLLADAFW::ColorOrTexture *cot = &efc->getDiffuse();
1036 const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
1048 const COLLADAFW::Node *node,
1049 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map)
1051 AnimMix *types =
new AnimMix();
1053 const COLLADAFW::TransformationPointerArray &nodeTransforms = node->getTransformations();
1056 for (
uint i = 0; i < nodeTransforms.getCount(); i++) {
1057 COLLADAFW::Transformation *transform = nodeTransforms[i];
1058 const COLLADAFW::UniqueId &listid = transform->getAnimationList();
1061 if (animlist_map.find(listid) == animlist_map.end()) {
1065 types->transform = types->transform | BC_NODE_TRANSFORM;
1068 const COLLADAFW::InstanceLightPointerArray &nodeLights = node->getInstanceLights();
1070 for (
uint i = 0; i < nodeLights.getCount(); i++) {
1071 const COLLADAFW::Light *light = (COLLADAFW::Light *)
1072 FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
1073 types->light =
setAnimType(&light->getColor(), (types->light), LIGHT_COLOR);
1074 types->light =
setAnimType(&light->getFallOffAngle(), (types->light), LIGHT_FOA);
1075 types->light =
setAnimType(&light->getFallOffExponent(), (types->light), LIGHT_FOE);
1077 if (types->light != 0) {
1082 const COLLADAFW::InstanceCameraPointerArray &nodeCameras = node->getInstanceCameras();
1083 for (
uint i = 0; i < nodeCameras.getCount(); i++) {
1084 const COLLADAFW::Camera *camera = (COLLADAFW::Camera *)
1085 FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
1086 if (camera ==
nullptr) {
1091 const bool is_perspective_type = camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE;
1094 const COLLADAFW::Animatable *mag;
1095 const COLLADAFW::UniqueId listid = camera->getYMag().getAnimationList();
1096 if (animlist_map.find(listid) != animlist_map.end()) {
1097 mag = &camera->getYMag();
1098 addition = (is_perspective_type) ? CAMERA_YFOV : CAMERA_YMAG;
1101 mag = &camera->getXMag();
1102 addition = (is_perspective_type) ? CAMERA_XFOV : CAMERA_XMAG;
1104 types->camera =
setAnimType(mag, (types->camera), addition);
1106 types->camera =
setAnimType(&camera->getFarClippingPlane(), (types->camera), CAMERA_ZFAR);
1107 types->camera =
setAnimType(&camera->getNearClippingPlane(), (types->camera), CAMERA_ZNEAR);
1109 if (types->camera != 0) {
1114 const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms = node->getInstanceGeometries();
1115 for (
uint i = 0; i < nodeGeoms.getCount(); i++) {
1116 const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
1117 for (
uint j = 0; j < matBinds.getCount(); j++) {
1118 const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
1119 const COLLADAFW::Effect *ef = (COLLADAFW::Effect *)(FW_object_map[matuid]);
1120 if (ef !=
nullptr) {
1121 const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
1122 if (!commonEffects.empty()) {
1123 COLLADAFW::EffectCommon *efc = commonEffects[0];
1125 &efc->getShininess(), (types->material), MATERIAL_SHININESS);
1127 &efc->getSpecular().getColor(), (types->material), MATERIAL_SPEC_COLOR);
1129 &efc->getDiffuse().getColor(), (types->material), MATERIAL_DIFF_COLOR);
1131 types->material =
setAnimType(&(efc->get()), (types->material), MATERIAL_TRANSPARENCY);
1134 &efc->getIndexOfRefraction(), (types->material), MATERIAL_IOR);
1145 const COLLADAFW::UniqueId &listid = prop->getAnimationList();
1146 if (animlist_map.find(listid) != animlist_map.end()) {
1147 anim_type = types | addition;
1157 COLLADAFW::Node *node,
1160 const COLLADAFW::TransformationPointerArray &tms = node->getTransformations();
1164 for (
uint i = 0; i < tms.getCount(); i++) {
1165 COLLADAFW::Transformation *tm = tms[i];
1166 COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
1171 std::string nodename = node->getName().empty() ? node->getOriginalId() : node->getName();
1174 case COLLADAFW::Transformation::ROTATE:
1177 case COLLADAFW::Transformation::TRANSLATE:
1180 case COLLADAFW::Transformation::SCALE:
1183 case COLLADAFW::Transformation::MATRIX:
1187 fprintf(stderr,
"unsupported transformation type %d\n", type);
1199 const COLLADAFW::AnimationList::AnimationClass animclass,
1200 const COLLADAFW::Transformation::TransformationType type)
1202 if (animclass == COLLADAFW::AnimationList::UNKNOWN_CLASS) {
1203 fprintf(stderr,
"%s: UNKNOWN animation class\n", path);
1207 "%s: animation class %d is not supported yet for transformation type %d\n",
1217 const char *node_id)
1219 const COLLADAFW::UniqueId &listid = tm->getAnimationList();
1220 COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
1223 COLLADAFW::Transformation::ROTATE,
1224 COLLADAFW::Transformation::SCALE,
1225 COLLADAFW::Transformation::TRANSLATE,
1226 COLLADAFW::Transformation::MATRIX))
1228 fprintf(stderr,
"animation of transformation %d is not supported yet\n", type);
1232 if (animlist_map.find(listid) == animlist_map.end()) {
1236 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1237 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
1239 if (bindings.getCount()) {
1242 bool is_scale = (type == COLLADAFW::Transformation::SCALE);
1243 bool is_translate = (type == COLLADAFW::Transformation::TRANSLATE);
1248 else if (is_translate) {
1252 for (
uint index = 0; index < bindings.getCount(); index++) {
1253 const COLLADAFW::AnimationList::AnimationBinding &binding = bindings[index];
1254 std::vector<FCurve *> &curves = curve_map[binding.animation];
1255 COLLADAFW::AnimationList::AnimationClass animclass = binding.animationClass;
1259 case COLLADAFW::Transformation::ROTATE:
1260 SNPRINTF(path,
"%s.rotate (binding %u)", node_id, index);
1262 case COLLADAFW::Transformation::SCALE:
1263 SNPRINTF(path,
"%s.scale (binding %u)", node_id, index);
1265 case COLLADAFW::Transformation::TRANSLATE:
1266 SNPRINTF(path,
"%s.translate (binding %u)", node_id, index);
1268 case COLLADAFW::Transformation::MATRIX:
1269 SNPRINTF(path,
"%s.matrix (binding %u)", node_id, index);
1275 if (type == COLLADAFW::Transformation::ROTATE) {
1276 if (curves.size() != 1) {
1277 fprintf(stderr,
"expected 1 curve, got %d\n",
int(curves.size()));
1282 if (animclass != COLLADAFW::AnimationList::ANGLE) {
1287 COLLADABU::Math::Vector3 &axis = ((COLLADAFW::Rotate *)tm)->getRotationAxis();
1295 if (is_scale || is_translate) {
1296 bool is_xyz = animclass == COLLADAFW::AnimationList::POSITION_XYZ;
1298 if ((!is_xyz && curves.size() != 1) || (is_xyz && curves.size() != 3)) {
1300 fprintf(stderr,
"%s: expected 3 curves, got %d\n", path,
int(curves.size()));
1303 fprintf(stderr,
"%s: expected 1 curve, got %d\n", path,
int(curves.size()));
1308 switch (animclass) {
1309 case COLLADAFW::AnimationList::POSITION_X:
1312 case COLLADAFW::AnimationList::POSITION_Y:
1315 case COLLADAFW::AnimationList::POSITION_Z:
1318 case COLLADAFW::AnimationList::POSITION_XYZ:
1328 else if (type == COLLADAFW::Transformation::MATRIX) {
1331 if (curves.size() != 16) {
1332 fprintf(stderr,
"%s: expected 16 curves, got %d\n", path,
int(curves.size()));
1336 COLLADABU::Math::Matrix4 matrix;
1339 for (
const FCurve *curve : curves) {
1359 return is_scale || is_translate;
1366 COLLADAFW::Node *root,
1367 COLLADAFW::Node *node)
1372 float par[4][4], m[4][4];
1382 COLLADAFW::Node *node,
1383 COLLADAFW::Node *end)
1404 COLLADAFW::NodePointerArray &children = node->getChildNodes();
1405 for (
uint i = 0; i < children.getCount(); i++) {
1423 if (grp ==
nullptr) {
1425 grp = MEM_cnew<bActionGroup>(
"bActionGroup");
1445 this->import_from_version = import_from_version;
Functions to work with AnimData.
Functions to modify FCurves.
static const char * bc_get_joint_name(T *node)
static ListBase & get_animation_curves(Main *bmain, Material *ma)
static void report_class_type_unsupported(const char *path, const COLLADAFW::AnimationList::AnimationClass animclass, const COLLADAFW::Transformation::TransformationType type)
static double get_aspect_ratio(const COLLADAFW::Camera *camera)
static int get_animation_axis_index(const COLLADABU::Math::Vector3 &axis)
Blender kernel action and pose functionality.
void action_groups_add_channel(bAction *act, bActionGroup *agrp, FCurve *fcurve)
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
bActionGroup * BKE_action_group_find_name(bAction *act, const char name[])
Bone * BKE_armature_find_bone_name(bArmature *arm, const char *name)
Main * CTX_data_main(const bContext *C)
void BKE_fcurve_handles_recalc(FCurve *fcu)
FCurve * BKE_fcurve_create(void)
float evaluate_fcurve(const FCurve *fcu, float evaltime)
void BKE_fcurve_free(FCurve *fcu)
struct Material * BKE_object_material_get(struct Object *ob, short act)
General operations, lookup, etc. for blender objects.
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void mat4_decompose(float loc[3], float quat[4], float size[3], const float wmat[4][4])
void unit_m4(float m[4][4])
void size_to_mat4(float R[4][4], const float size[3])
#define mul_m4_series(...)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool invert_m4(float mat[4][4])
void axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
float fov_to_focallength(float hfov, float sensor)
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
#define STRNCPY(dst, src)
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define SNPRINTF(dst, format,...)
int char char int int int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
void BLI_uniquename(const struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_maxncpy) ATTR_NONNULL(1
#define BLT_I18NCONTEXT_ID_ACTION
#define CTX_DATA_(context, msgid)
Read Guarded memory(de)allocation.
void get_joint_rest_mat(float mat[4][4], COLLADAFW::Node *root, COLLADAFW::Node *node)
float convert_to_focal_length(float in_xfov, int fov_type, float aspect, float sensorx)
void find_frames(std::vector< float > *frames, std::vector< FCurve * > *curves)
void Assign_float_animations(const COLLADAFW::UniqueId &listid, ListBase *AnimCurves, const char *anim_type)
bool evaluate_animation(COLLADAFW::Transformation *tm, float mat[4][4], float fra, const char *node_id)
void read_node_transform(COLLADAFW::Node *node, Object *ob)
void Assign_transform_animations(COLLADAFW::Transformation *transform, const COLLADAFW::AnimationList::AnimationBinding *binding, std::vector< FCurve * > *curves, bool is_joint, char *joint_path)
int setAnimType(const COLLADAFW::Animatable *prop, int type, int addition)
void Assign_color_animations(const COLLADAFW::UniqueId &listid, ListBase *AnimCurves, const char *anim_type)
bool write_animation_list(const COLLADAFW::AnimationList *animlist)
AnimMix * get_animation_type(const COLLADAFW::Node *node, std::map< COLLADAFW::UniqueId, const COLLADAFW::Object * > FW_object_map)
void unused_fcurve(std::vector< FCurve * > *curves)
void add_bone_fcurve(Object *ob, COLLADAFW::Node *node, FCurve *fcu)
void modify_fcurve(std::vector< FCurve * > *curves, const char *rna_path, int array_index, int scale=1)
bool calc_joint_parent_mat_rest(float mat[4][4], float par[4][4], COLLADAFW::Node *node, COLLADAFW::Node *end)
void evaluate_transform_at_frame(float mat[4][4], COLLADAFW::Node *node, float fra)
void apply_matrix_curves(Object *ob, std::vector< FCurve * > &animcurves, COLLADAFW::Node *root, COLLADAFW::Node *node, COLLADAFW::Transformation *tm)
void 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)
bool write_animation(const COLLADAFW::Animation *anim)
void Assign_lens_animations(const COLLADAFW::UniqueId &listid, ListBase *AnimCurves, double aspect, Camera *cam, const char *anim_type, int fov_type)
void set_import_from_version(std::string import_from_version)
void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t joint_path_maxncpy)
Object * get_armature_for_joint(COLLADAFW::Node *node)
bool get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint)
static void dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::Matrix4 &in)
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray &array, uint index)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
ccl_device_inline float2 interp(const float2 a, const float2 b, float t)
bAction * id_action_ensure(Main *bmain, ID *id)
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
Lesser Key-framing API call.
ObjectRuntimeHandle * runtime