24 #include "COLLADABUPlatform.h"
54 const std::string &
id =
node->getName();
55 return id.empty() ?
node->getOriginalId().c_str() :
id.c_str();
58 FCurve *AnimationImporter::create_fcurve(
int array_index,
const char *rna_path)
67 void AnimationImporter::add_bezt(
FCurve *fcu,
75 bez.
vec[1][0] = frame;
76 bez.
vec[1][1] = value;
85 void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *
curve)
87 COLLADAFW::FloatOrDoubleArray &input =
curve->getInputValues();
88 COLLADAFW::FloatOrDoubleArray &
output =
curve->getOutputValues();
91 size_t dim =
curve->getOutDimension();
94 std::vector<FCurve *> &fcurves = curve_map[
curve->getUniqueId()];
102 for (i = 0; i < dim; i++) {
109 for (
unsigned int j = 0; j <
curve->getKeyCount(); j++) {
118 if (
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ||
119 curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP) {
120 COLLADAFW::FloatOrDoubleArray &intan =
curve->getInTangentValues();
121 COLLADAFW::FloatOrDoubleArray &outtan =
curve->getOutTangentValues();
124 unsigned int index = 2 * (j * dim + i);
131 if (
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) {
152 fcurves.push_back(fcu);
153 unused_curves.push_back(fcu);
158 "Output dimension of %d is not yet supported (animation id = %s)\n",
160 curve->getOriginalId().c_str());
164 void AnimationImporter::fcurve_deg_to_rad(
FCurve *cu)
166 for (
unsigned int i = 0; i < cu->
totvert; i++) {
174 void AnimationImporter::fcurve_scale(
FCurve *cu,
int scale)
176 for (
unsigned int i = 0; i < cu->
totvert; i++) {
178 cu->
bezt[i].
vec[1][1] *= scale;
179 cu->
bezt[i].
vec[0][1] *= scale;
180 cu->
bezt[i].
vec[2][1] *= scale;
184 void AnimationImporter::fcurve_is_used(
FCurve *fcu)
186 unused_curves.erase(std::remove(unused_curves.begin(), unused_curves.end(), fcu),
187 unused_curves.end());
190 void AnimationImporter::add_fcurves_to_object(
Main *bmain,
192 std::vector<FCurve *> &curves,
206 std::vector<FCurve *>::iterator it;
210 char *p = strstr(rna_path,
"rotation_euler");
211 bool is_rotation = p && *(p + strlen(
"rotation_euler")) ==
'\0';
215 fcurve_deg_to_rad(fcu);
219 for (it = curves.begin(), i = 0; it != curves.end(); it++, i++) {
223 if (array_index == -1) {
239 if (grp ==
nullptr) {
261 fcurves_actionGroup_map[grp].push_back(fcu);
275 for (
FCurve *unused_curve : unused_curves) {
279 if (!unused_curves.empty()) {
280 fprintf(stderr,
"removed %d unused curves\n", (
int)unused_curves.size());
286 if (
anim->getAnimationType() == COLLADAFW::Animation::ANIMATION_CURVE) {
287 COLLADAFW::AnimationCurve *
curve = (COLLADAFW::AnimationCurve *)
anim;
291 if (
curve->getInPhysicalDimension() != COLLADAFW::PHYSICAL_DIMENSION_TIME) {
292 fprintf(stderr,
"Inputs physical dimension is not time.\n");
300 if (
interp != COLLADAFW::AnimationCurve::INTERPOLATION_MIXED) {
303 case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
304 case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
305 animation_to_fcurves(
curve);
310 "CARDINAL, HERMITE and BSPLINE anim interpolation types not supported yet.\n");
316 fprintf(stderr,
"MIXED anim interpolation type is not supported yet.\n");
320 fprintf(stderr,
"FORMULA animation type is not supported yet.\n");
329 const COLLADAFW::UniqueId &animlist_id = animlist->getUniqueId();
330 animlist_map[animlist_id] = animlist;
335 if (uid_animated_map.find(animlist_id) == uid_animated_map.end()) {
362 virtual void AnimationImporter::change_eul_to_quat(
Object *ob,
bAction *act)
371 if (fcurves_actionGroup_map.find(grp) == fcurves_actionGroup_map.end()) {
375 std::vector<FCurve *> &rot_fcurves = fcurves_actionGroup_map[grp];
377 if (rot_fcurves.size() > 3) {
381 for (i = 0; i < rot_fcurves.size(); i++) {
382 eulcu[rot_fcurves[i]->array_index] = rot_fcurves[i];
385 char joint_path[100];
388 char grp_name_esc[
sizeof(grp->
name) * 2];
391 BLI_snprintf(joint_path,
sizeof(joint_path),
"pose.bones[\"%s\"]", grp_name_esc);
392 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.rotation_quaternion", joint_path);
395 create_fcurve(0, rna_path),
396 create_fcurve(1, rna_path),
397 create_fcurve(2, rna_path),
398 create_fcurve(3, rna_path),
403 float m4[4][4], irest[3][3];
407 for (i = 0; i < 3; i++) {
415 for (
int j = 0; j < cu->
totvert; j++) {
416 float frame = cu->
bezt[j].
vec[1][0];
425 float rot[3][3], rel[3][3], quat[4];
435 for (
int k = 0; k < 4; k++) {
436 create_bezt(quatcu[k], frame, quat[k],
U.ipo_new);
443 for (i = 0; i < 3; i++) {
454 for (i = 0; i < 4; i++) {
468 const char *rna_path,
472 std::vector<FCurve *>::iterator it;
474 for (it = curves->begin(), i = 0; it != curves->end(); it++, i++) {
478 if (array_index == -1) {
486 fcurve_scale(fcu, scale);
496 std::vector<FCurve *>::iterator it;
497 for (it = curves->begin(); it != curves->end(); it++) {
505 std::vector<FCurve *>::iterator iter;
506 for (iter = curves->begin(); iter != curves->end(); iter++) {
509 for (
unsigned int k = 0; k < fcu->
totvert; k++) {
511 float fra = fcu->
bezt[k].
vec[1][0];
513 if (std::find(frames->begin(), frames->end(), fra) == frames->end()) {
514 frames->push_back(fra);
523 if (COLLADABU::Math::Vector3::UNIT_X == axis) {
526 else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
529 else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
542 const COLLADAFW::AnimationList::AnimationBinding *binding,
543 std::vector<FCurve *> *curves,
547 COLLADAFW::Transformation::TransformationType tm_type =
transform->getTransformationType();
548 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
554 binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
556 if (!((!xyz && curves->size() == 1) || (xyz && curves->size() == 3) || is_matrix)) {
557 fprintf(stderr,
"expected %d curves, got %d\n", xyz ? 3 : 1, (
int)curves->size());
568 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, loc ?
"location" :
"scale");
571 BLI_strncpy(rna_path, loc ?
"location" :
"scale",
sizeof(rna_path));
574 switch (binding->animationClass) {
575 case COLLADAFW::AnimationList::POSITION_X:
578 case COLLADAFW::AnimationList::POSITION_Y:
581 case COLLADAFW::AnimationList::POSITION_Z:
584 case COLLADAFW::AnimationList::POSITION_XYZ:
590 "AnimationClass %d is not supported for %s.\n",
591 binding->animationClass,
592 loc ?
"TRANSLATE" :
"SCALE");
599 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.rotation_euler", joint_path);
602 BLI_strncpy(rna_path,
"rotation_euler",
sizeof(rna_path));
604 std::vector<FCurve *>::iterator iter;
605 for (iter = curves->begin(); iter != curves->end(); iter++) {
610 fcurve_deg_to_rad(fcu);
616 switch (binding->animationClass) {
617 case COLLADAFW::AnimationList::ANGLE: {
619 if (axis_index >= 0) {
626 case COLLADAFW::AnimationList::AXISANGLE:
631 "AnimationClass %d is not supported for ROTATE transformation.\n",
632 binding->animationClass);
637 case COLLADAFW::Transformation::MATRIX:
640 COLLADAFW::Matrix *mat = (COLLADAFW::Matrix *)
transform;
641 COLLADABU::Math::Matrix4 mat4 = mat->getMatrix();
642 switch (binding->animationClass) {
649 case COLLADAFW::Transformation::SKEW:
650 case COLLADAFW::Transformation::LOOKAT:
652 fprintf(stderr,
"Animation of SKEW and LOOKAT transformations is not supported yet.\n");
661 const char *anim_type)
664 BLI_strncpy(rna_path, anim_type,
sizeof(rna_path));
666 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
667 if (animlist ==
nullptr) {
669 "Collada: No animlist found for ID: %s of type %s\n",
670 listid.toAscii().c_str(),
675 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
677 std::vector<FCurve *> animcurves;
678 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
679 animcurves = curve_map[bindings[j].animation];
681 switch (bindings[j].animationClass) {
682 case COLLADAFW::AnimationList::COLOR_R:
685 case COLLADAFW::AnimationList::COLOR_G:
688 case COLLADAFW::AnimationList::COLOR_B:
691 case COLLADAFW::AnimationList::COLOR_RGB:
692 case COLLADAFW::AnimationList::COLOR_RGBA:
699 "AnimationClass %d is not supported for %s.\n",
700 bindings[j].animationClass,
704 std::vector<FCurve *>::iterator iter;
706 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
716 const char *anim_type)
719 if (animlist_map.find(listid) == animlist_map.end()) {
724 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
725 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
727 std::vector<FCurve *> animcurves;
728 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
729 animcurves = curve_map[bindings[j].animation];
731 BLI_strncpy(rna_path, anim_type,
sizeof(rna_path));
733 std::vector<FCurve *>::iterator iter;
735 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
739 if (
STREQ(
"spot_size", anim_type)) {
743 if (this->import_from_version.empty() ||
745 fcurve_deg_to_rad(fcu);
762 float xfov = (fov_type == CAMERA_YFOV) ?
777 const char *anim_type,
781 if (animlist_map.find(listid) == animlist_map.end()) {
786 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
787 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
789 std::vector<FCurve *> animcurves;
790 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
791 animcurves = curve_map[bindings[j].animation];
793 BLI_strncpy(rna_path, anim_type,
sizeof(rna_path));
796 std::vector<FCurve *>::iterator iter;
798 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
801 for (
unsigned int i = 0; i < fcu->
totvert; i++) {
817 std::vector<FCurve *> &animcurves,
818 COLLADAFW::Node *root,
819 COLLADAFW::Node *
node,
820 COLLADAFW::Transformation *tm)
822 bool is_joint =
node->getType() == COLLADAFW::Node::JOINT;
824 char joint_path[200];
829 std::vector<float> frames;
832 float irest_dae[4][4];
833 float rest[4][4], irest[4][4];
841 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
851 unsigned int totcu = 10;
852 const char *tm_str =
nullptr;
854 for (
int i = 0; i < totcu; i++) {
859 tm_str =
"rotation_quaternion";
872 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, tm_str);
877 newcu[i] = create_fcurve(axis, rna_path);
878 newcu[i]->
totvert = frames.size();
881 if (frames.empty()) {
887 std::vector<float>::iterator it;
895 for (it = frames.begin(); it != frames.end(); it++) {
912 float temp[4][4], par[4][4];
919 evaluate_joint_world_transform_at_frame(temp,
NULL,
node, fra);
929 float rot[4], loc[3], scale[3];
933 for (
int i = 0; i < totcu; i++) {
935 add_bezt(newcu[i], fra,
rot[i]);
938 add_bezt(newcu[i], fra, loc[i - 4]);
941 add_bezt(newcu[i], fra, scale[i - 7]);
951 for (
int i = 0; i < totcu; i++) {
959 fcurve_is_used(newcu[i]);
984 double aspect = camera->getAspectRatio().getValue();
987 const double yfov = camera->getYFov().getValue();
993 const double xfov = camera->getXFov().getValue();
998 aspect = xfov / yfov;
1019 COLLADAFW::Node *
node,
1020 std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map,
1021 std::multimap<COLLADAFW::UniqueId, Object *> &object_map,
1022 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map,
1023 std::map<COLLADAFW::UniqueId, Material *> uid_material_map)
1025 bool is_joint =
node->getType() == COLLADAFW::Node::JOINT;
1026 COLLADAFW::UniqueId uid =
node->getUniqueId();
1027 COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ?
node : root_map[uid];
1034 ob = object_map.find(uid) == object_map.end() ?
NULL : object_map.find(uid)->second;
1038 fprintf(stderr,
"cannot find Object for Node with id=\"%s\"\n",
node->getOriginalId().c_str());
1046 if ((animType->transform) != 0) {
1048 char joint_path[200];
1064 const COLLADAFW::TransformationPointerArray &nodeTransforms =
node->getTransformations();
1067 for (
unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
1068 COLLADAFW::Transformation *
transform = nodeTransforms[i];
1069 COLLADAFW::Transformation::TransformationType tm_type =
transform->getTransformationType();
1072 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
1074 const COLLADAFW::UniqueId &listid =
transform->getAnimationList();
1077 if (animlist_map.find(listid) == animlist_map.end()) {
1082 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1083 const COLLADAFW::AnimationList::AnimationBindings &bindings =
1084 animlist->getAnimationBindings();
1086 std::vector<FCurve *> animcurves;
1087 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
1088 animcurves = curve_map[bindings[j].animation];
1097 std::vector<FCurve *>::iterator iter;
1099 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
1103 fcurve_is_used(fcu);
1108 if (is_rotation && !(is_joint || is_matrix)) {
1114 if ((animType->light) != 0) {
1124 const COLLADAFW::InstanceLightPointerArray &nodeLights =
node->getInstanceLights();
1126 for (
unsigned int i = 0; i < nodeLights.getCount(); i++) {
1128 FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
1130 if ((animType->light & LIGHT_COLOR) != 0) {
1132 const COLLADAFW::UniqueId &listid =
col->getAnimationList();
1136 if ((animType->light & LIGHT_FOA) != 0) {
1137 const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle());
1138 const COLLADAFW::UniqueId &listid = foa->getAnimationList();
1142 if ((animType->light & LIGHT_FOE) != 0) {
1143 const COLLADAFW::AnimatableFloat *foe = &(light->getFallOffExponent());
1144 const COLLADAFW::UniqueId &listid = foe->getAnimationList();
1151 if (animType->camera != 0) {
1162 const COLLADAFW::InstanceCameraPointerArray &nodeCameras =
node->getInstanceCameras();
1164 for (
unsigned int i = 0; i < nodeCameras.getCount(); i++) {
1166 FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
1168 if ((animType->camera & CAMERA_XFOV) != 0) {
1169 const COLLADAFW::AnimatableFloat *xfov = &(camera->getXFov());
1170 const COLLADAFW::UniqueId &listid = xfov->getAnimationList();
1175 else if ((animType->camera & CAMERA_YFOV) != 0) {
1176 const COLLADAFW::AnimatableFloat *yfov = &(camera->getYFov());
1177 const COLLADAFW::UniqueId &listid = yfov->getAnimationList();
1182 else if ((animType->camera & CAMERA_XMAG) != 0) {
1183 const COLLADAFW::AnimatableFloat *xmag = &(camera->getXMag());
1184 const COLLADAFW::UniqueId &listid = xmag->getAnimationList();
1188 else if ((animType->camera & CAMERA_YMAG) != 0) {
1189 const COLLADAFW::AnimatableFloat *ymag = &(camera->getYMag());
1190 const COLLADAFW::UniqueId &listid = ymag->getAnimationList();
1194 if ((animType->camera & CAMERA_ZFAR) != 0) {
1195 const COLLADAFW::AnimatableFloat *zfar = &(camera->getFarClippingPlane());
1196 const COLLADAFW::UniqueId &listid = zfar->getAnimationList();
1200 if ((animType->camera & CAMERA_ZNEAR) != 0) {
1201 const COLLADAFW::AnimatableFloat *znear = &(camera->getNearClippingPlane());
1202 const COLLADAFW::UniqueId &listid = znear->getAnimationList();
1207 if (animType->material != 0) {
1217 const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms =
node->getInstanceGeometries();
1218 for (
unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
1219 const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
1220 for (
unsigned int j = 0; j < matBinds.getCount(); j++) {
1221 const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
1223 if (ef !=
nullptr) {
1224 Material *ma = uid_material_map[matuid];
1227 "Collada: Node %s refers to undefined material\n",
1228 node->getName().c_str());
1232 const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
1233 COLLADAFW::EffectCommon *efc = commonEffects[0];
1234 if ((animType->material & MATERIAL_SHININESS) != 0) {
1235 const COLLADAFW::FloatOrParam *shin = &(efc->getShininess());
1236 const COLLADAFW::UniqueId &listid = shin->getAnimationList();
1240 if ((animType->material & MATERIAL_IOR) != 0) {
1241 const COLLADAFW::FloatOrParam *ior = &(efc->getIndexOfRefraction());
1242 const COLLADAFW::UniqueId &listid = ior->getAnimationList();
1246 if ((animType->material & MATERIAL_SPEC_COLOR) != 0) {
1247 const COLLADAFW::ColorOrTexture *cot = &(efc->getSpecular());
1248 const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
1252 if ((animType->material & MATERIAL_DIFF_COLOR) != 0) {
1253 const COLLADAFW::ColorOrTexture *cot = &(efc->getDiffuse());
1254 const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
1266 std::vector<FCurve *> &animcurves,
1267 COLLADAFW::Node *root,
1268 COLLADAFW::Node *
node,
1269 COLLADAFW::Transformation *tm)
1272 char joint_path[200];
1275 std::vector<float> frames;
1281 std::vector<FCurve *>::iterator iter;
1282 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
1285 fcurve_deg_to_rad(fcu);
1289 float irest_dae[4][4];
1290 float rest[4][4], irest[4][4];
1297 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
1307 unsigned int totcu = 10;
1308 const char *tm_str =
nullptr;
1310 for (
int i = 0; i < totcu; i++) {
1315 tm_str =
"rotation_quaternion";
1319 tm_str =
"location";
1327 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, tm_str);
1329 newcu[i] = create_fcurve(axis, rna_path);
1330 newcu[i]->
totvert = frames.size();
1333 if (frames.empty()) {
1337 std::sort(frames.begin(), frames.end());
1341 std::vector<float>::iterator it;
1344 for (it = frames.begin(); it != frames.end(); it++) {
1379 for (
int i = 0; i < totcu; i++) {
1381 add_bezt(newcu[i], fra, qref.
quat()[i]);
1384 add_bezt(newcu[i], fra, loc[i - 4]);
1387 add_bezt(newcu[i], fra, scale[i - 7]);
1395 for (
int i = 0; i < totcu; i++) {
1398 fcurve_is_used(newcu[i]);
1409 const COLLADAFW::Node *
node,
1410 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map)
1412 AnimMix *
types =
new AnimMix();
1414 const COLLADAFW::TransformationPointerArray &nodeTransforms =
node->getTransformations();
1417 for (
unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
1418 COLLADAFW::Transformation *
transform = nodeTransforms[i];
1419 const COLLADAFW::UniqueId &listid =
transform->getAnimationList();
1422 if (animlist_map.find(listid) == animlist_map.end()) {
1426 types->transform =
types->transform | BC_NODE_TRANSFORM;
1429 const COLLADAFW::InstanceLightPointerArray &nodeLights =
node->getInstanceLights();
1431 for (
unsigned int i = 0; i < nodeLights.getCount(); i++) {
1433 FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
1438 if (
types->light != 0) {
1443 const COLLADAFW::InstanceCameraPointerArray &nodeCameras =
node->getInstanceCameras();
1444 for (
unsigned int i = 0; i < nodeCameras.getCount(); i++) {
1446 FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
1447 if (camera ==
nullptr) {
1452 const bool is_perspective_type = camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE;
1455 const COLLADAFW::Animatable *mag;
1456 const COLLADAFW::UniqueId listid = camera->getYMag().getAnimationList();
1457 if (animlist_map.find(listid) != animlist_map.end()) {
1458 mag = &(camera->getYMag());
1459 addition = (is_perspective_type) ? CAMERA_YFOV : CAMERA_YMAG;
1462 mag = &(camera->getXMag());
1463 addition = (is_perspective_type) ? CAMERA_XFOV : CAMERA_XMAG;
1470 if (
types->camera != 0) {
1475 const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms =
node->getInstanceGeometries();
1476 for (
unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
1477 const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
1478 for (
unsigned int j = 0; j < matBinds.getCount(); j++) {
1479 const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
1481 if (ef !=
nullptr) {
1482 const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
1483 if (!commonEffects.empty()) {
1484 COLLADAFW::EffectCommon *efc = commonEffects[0];
1486 &(efc->getShininess()), (
types->material), MATERIAL_SHININESS);
1488 &(efc->getSpecular().getColor()), (
types->material), MATERIAL_SPEC_COLOR);
1490 &(efc->getDiffuse().getColor()), (
types->material), MATERIAL_DIFF_COLOR);
1495 &(efc->getIndexOfRefraction()), (
types->material), MATERIAL_IOR);
1506 const COLLADAFW::UniqueId &listid = prop->getAnimationList();
1507 if (animlist_map.find(listid) != animlist_map.end()) {
1508 anim_type =
types | addition;
1519 COLLADAFW::Node *
node,
1520 COLLADAFW::Transformation::TransformationType tm_type)
1522 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
1525 const COLLADAFW::TransformationPointerArray &nodeTransforms =
node->getTransformations();
1529 for (i = 0; i < nodeTransforms.getCount(); i++) {
1530 COLLADAFW::Transformation *
transform = nodeTransforms[i];
1531 COLLADAFW::Transformation::TransformationType nodeTmType =
transform->getTransformationType();
1533 if (nodeTmType == tm_type) {
1535 const COLLADAFW::UniqueId &listid =
transform->getAnimationList();
1537 if (animlist_map.find(listid) != animlist_map.end()) {
1539 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1540 const COLLADAFW::AnimationList::AnimationBindings &bindings =
1541 animlist->getAnimationBindings();
1543 if (bindings.getCount()) {
1545 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
1546 std::vector<FCurve *> &curves = curve_map[bindings[j].animation];
1549 bindings[j].animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
1551 if ((!xyz && curves.size() == 1) || (xyz && curves.size() == 3) || is_matrix) {
1552 std::vector<FCurve *>::iterator iter;
1554 for (iter = curves.begin(); iter != curves.end(); iter++) {
1559 fcurve_deg_to_rad(fcu);
1562 for (
unsigned int k = 0; k < fcu->
totvert; k++) {
1564 float fra = fcu->
bezt[k].
vec[1][0];
1566 if (std::find(frames->begin(), frames->end(), fra) == frames->end()) {
1567 frames->push_back(fra);
1573 fprintf(stderr,
"expected %d curves, got %d\n", xyz ? 3 : 1, (
int)curves.size());
1586 COLLADAFW::Node *
node,
1587 std::map<COLLADAFW::UniqueId, Object *> &object_map,
1588 std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map,
1589 COLLADAFW::Transformation::TransformationType tm_type,
1594 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
1595 bool is_joint =
node->getType() == COLLADAFW::Node::JOINT;
1597 COLLADAFW::Node *root = root_map.find(
node->getUniqueId()) == root_map.end() ?
1599 root_map[
node->getUniqueId()];
1601 object_map[
node->getUniqueId()];
1604 fprintf(stderr,
"cannot find Object for Node with id=\"%s\"\n",
node->getOriginalId().c_str());
1609 std::vector<float> frames;
1615 float irest_dae[4][4];
1616 float rest[4][4], irest[4][4];
1624 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
1635 #ifdef ARMATURE_TEST
1637 job = get_joint_object(root,
node, par_job);
1640 if (frames.empty()) {
1644 std::sort(frames.begin(), frames.end());
1646 const char *tm_str =
nullptr;
1649 tm_str =
"rotation_quaternion";
1655 tm_str =
"location";
1657 case COLLADAFW::Transformation::MATRIX:
1664 char joint_path[200];
1672 unsigned int totcu = is_matrix ? 10 : (is_rotation ? 4 : 3);
1674 for (i = 0; i < totcu; i++) {
1680 tm_str =
"rotation_quaternion";
1684 tm_str =
"location";
1694 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, tm_str);
1699 newcu[i] = create_fcurve(axis, rna_path);
1701 #ifdef ARMATURE_TEST
1703 job_curves[i] = create_fcurve(axis, tm_str);
1708 std::vector<float>::iterator it;
1711 for (it = frames.begin(); it != frames.end(); it++) {
1728 float temp[4][4], par[4][4];
1744 float rot[4], loc[3], scale[3];
1756 case COLLADAFW::Transformation::MATRIX:
1766 for (i = 0; i < totcu; i++) {
1769 add_bezt(newcu[i], fra,
rot[i]);
1772 add_bezt(newcu[i], fra, loc[i - 4]);
1775 add_bezt(newcu[i], fra, scale[i - 7]);
1779 add_bezt(newcu[i], fra, val[i]);
1783 #ifdef ARMATURE_TEST
1804 for (i = 0; i < totcu; i++) {
1807 add_bezt(job_curves[i], fra,
rot[i]);
1810 add_bezt(job_curves[i], fra, loc[i - 4]);
1813 add_bezt(job_curves[i], fra, scale[i - 7]);
1817 add_bezt(job_curves[i], fra, val[i]);
1829 for (i = 0; i < totcu; i++) {
1837 #ifdef ARMATURE_TEST
1844 if (is_rotation || is_matrix) {
1861 COLLADAFW::Node *
node,
1864 const COLLADAFW::TransformationPointerArray &tms =
node->getTransformations();
1868 for (
unsigned int i = 0; i < tms.getCount(); i++) {
1869 COLLADAFW::Transformation *tm = tms[i];
1870 COLLADAFW::Transformation::TransformationType
type = tm->getTransformationType();
1875 std::string nodename =
node->getName().empty() ?
node->getOriginalId() :
node->getName();
1887 case COLLADAFW::Transformation::MATRIX:
1891 fprintf(stderr,
"unsupported transformation type %d\n",
type);
1903 const COLLADAFW::AnimationList::AnimationClass animclass,
1904 const COLLADAFW::Transformation::TransformationType
type)
1906 if (animclass == COLLADAFW::AnimationList::UNKNOWN_CLASS) {
1907 fprintf(stderr,
"%s: UNKNOWN animation class\n", path);
1911 "%s: animation class %d is not supported yet for transformation type %d\n",
1922 const char *node_id)
1924 const COLLADAFW::UniqueId &listid = tm->getAnimationList();
1925 COLLADAFW::Transformation::TransformationType
type = tm->getTransformationType();
1929 fprintf(stderr,
"animation of transformation %d is not supported yet\n",
type);
1933 if (animlist_map.find(listid) == animlist_map.end()) {
1937 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1938 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
1940 if (bindings.getCount()) {
1949 else if (is_translate) {
1953 for (
unsigned int index = 0; index < bindings.getCount(); index++) {
1954 const COLLADAFW::AnimationList::AnimationBinding &binding = bindings[index];
1955 std::vector<FCurve *> &curves = curve_map[binding.animation];
1956 COLLADAFW::AnimationList::AnimationClass animclass = binding.animationClass;
1961 BLI_snprintf(path,
sizeof(path),
"%s.rotate (binding %u)", node_id, index);
1964 BLI_snprintf(path,
sizeof(path),
"%s.scale (binding %u)", node_id, index);
1967 BLI_snprintf(path,
sizeof(path),
"%s.translate (binding %u)", node_id, index);
1969 case COLLADAFW::Transformation::MATRIX:
1970 BLI_snprintf(path,
sizeof(path),
"%s.matrix (binding %u)", node_id, index);
1977 if (curves.size() != 1) {
1978 fprintf(stderr,
"expected 1 curve, got %d\n", (
int)curves.size());
1983 if (animclass != COLLADAFW::AnimationList::ANGLE) {
1990 float ax[3] = {(
float)axis[0], (
float)axis[1], (
float)axis[2]};
1996 if (is_scale || is_translate) {
1997 bool is_xyz = animclass == COLLADAFW::AnimationList::POSITION_XYZ;
1999 if ((!is_xyz && curves.size() != 1) || (is_xyz && curves.size() != 3)) {
2001 fprintf(stderr,
"%s: expected 3 curves, got %d\n", path, (
int)curves.size());
2004 fprintf(stderr,
"%s: expected 1 curve, got %d\n", path, (
int)curves.size());
2009 switch (animclass) {
2010 case COLLADAFW::AnimationList::POSITION_X:
2013 case COLLADAFW::AnimationList::POSITION_Y:
2016 case COLLADAFW::AnimationList::POSITION_Z:
2019 case COLLADAFW::AnimationList::POSITION_XYZ:
2029 else if (
type == COLLADAFW::Transformation::MATRIX) {
2032 if (curves.size() != 16) {
2033 fprintf(stderr,
"%s: expected 16 curves, got %d\n", path, (
int)curves.size());
2037 COLLADABU::Math::Matrix4 matrix;
2060 return is_scale || is_translate;
2068 COLLADAFW::Node *root,
2069 COLLADAFW::Node *
node)
2074 float par[4][4], m[4][4];
2085 COLLADAFW::Node *
node,
2086 COLLADAFW::Node *end)
2107 COLLADAFW::NodePointerArray &children =
node->getChildNodes();
2108 for (
unsigned int i = 0; i < children.getCount(); i++) {
2117 #ifdef ARMATURE_TEST
2118 Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root,
2119 COLLADAFW::Node *
node,
2122 if (joint_objects.find(
node->getUniqueId()) == joint_objects.end()) {
2125 job->lay = BKE_scene_base_find(scene, job)->lay = 2;
2138 float temp[4][4], ipar[4][4];
2158 joint_objects[
node->getUniqueId()] = job;
2161 return joint_objects[
node->getUniqueId()];
2168 bool AnimationImporter::evaluate_joint_world_transform_at_frame(
2169 float mat[4][4],
float par[4][4], COLLADAFW::Node *
node, COLLADAFW::Node *end,
float fra)
2186 COLLADAFW::NodePointerArray &children =
node->getChildNodes();
2187 for (
int i = 0; i < children.getCount(); i++) {
2188 if (evaluate_joint_world_transform_at_frame(mat, m, children[i], end, fra)) {
2207 if (grp ==
nullptr) {
2229 this->import_from_version = import_from_version;
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 ListBase & get_animation_curves(Main *bmain, Material *ma)
static int get_animation_axis_index(const COLLADABU::Math::Vector3 &axis)
static const char * bc_get_joint_name(T *node)
typedef float(TangentPoint)[2]
Blender kernel action and pose functionality.
struct bPoseChannel * BKE_pose_channel_find_name(const struct bPose *pose, const char *name)
void action_groups_remove_channel(struct bAction *act, struct FCurve *fcu)
struct bActionGroup * BKE_action_group_find_name(struct bAction *act, const char name[])
void action_groups_add_channel(struct bAction *act, struct bActionGroup *agrp, struct FCurve *fcurve)
struct Bone * BKE_armature_find_bone_name(struct bArmature *arm, const char *name)
struct Main * CTX_data_main(const bContext *C)
float evaluate_fcurve(struct FCurve *fcu, float evaltime)
void BKE_fcurve_free(struct FCurve *fcu)
void calchandles_fcurve(struct FCurve *fcu)
struct FCurve * BKE_fcurve_create(void)
struct Material * BKE_object_material_get(struct Object *ob, short act)
General operations, lookup, etc. for blender objects.
void BKE_object_where_is_calc(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob)
void BKE_object_apply_mat4(struct Object *ob, const float mat[4][4], const bool use_compat, const 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])
bool invert_m4(float R[4][4])
void mat4_decompose(float loc[3], float quat[4], float size[3], const float wmat[4][4])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
void unit_m4(float m[4][4])
bool invert_m4_m4(float R[4][4], const float A[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])
void mat4_to_size(float size[3], const float M[4][4])
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
void eul_to_mat3(float mat[3][3], const float eul[3])
void mat3_to_quat(float q[4], const float mat[3][3])
void eul_to_quat(float quat[4], const float eul[3])
void mat4_to_quat(float q[4], const float mat[4][4])
void axis_angle_to_mat4(float R[4][4], const float axis[3], const float angle)
float fov_to_focallength(float fov, float sensor)
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_strdupn(const char *str, const size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, const size_t dst_maxncpy) ATTR_NONNULL()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t len)
#define BLT_I18NCONTEXT_ID_ACTION
#define CTX_DATA_(context, msgid)
void DEG_id_tag_update(struct ID *id, int flag)
void DEG_relations_tag_update(struct Main *bmain)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Color
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue TRANSLATE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue Rotate
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate SCALE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue Movie Ellipse Bokeh View Corner Anti Mix RGB Hue ROTATE
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White RGB Map Separate Set Z Dilate Combine Combine Color Channel Split ID Combine Luminance Directional Alpha Distance Hue TRANSFORM
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
void sort(btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V, int t)
Helper function of 3X3 SVD for sorting singular values.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
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)
void Assign_lens_animations(const COLLADAFW::UniqueId &listid, ListBase *AnimCurves, const double aspect, Camera *cam, const char *anim_type, int fov_type)
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)
Object * 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=NULL)
void unused_fcurve(std::vector< FCurve * > *curves)
void add_bone_animation_sampled(Object *ob, std::vector< FCurve * > &animcurves, COLLADAFW::Node *root, COLLADAFW::Node *node, COLLADAFW::Transformation *tm)
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 find_frames_old(std::vector< float > *frames, COLLADAFW::Node *node, COLLADAFW::Transformation::TransformationType tm_type)
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 set_import_from_version(std::string import_from_version)
void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count)
Object * get_armature_for_joint(COLLADAFW::Node *node)
bool get_joint_bind_mat(float m[4][4], COLLADAFW::Node *joint)
void rotate_to(Matrix &mat_to)
static void dae_matrix_to_mat4_(float out[4][4], const COLLADABU::Math::Matrix4 &in)
Object * bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name)
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray &array, unsigned int index)
void bc_decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size)
bAction * ED_id_action_ensure(Main *bmain, ID *id)
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
void *(* MEM_callocN)(size_t len, const char *str)
struct bActionGroup * next
struct bPoseChannel * next
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)