10 #include "COLLADABUPlatform.h"
40 const std::string &
id =
node->getName();
41 return id.empty() ?
node->getOriginalId().c_str() :
id.c_str();
44 FCurve *AnimationImporter::create_fcurve(
int array_index,
const char *rna_path)
53 void AnimationImporter::add_bezt(
FCurve *fcu,
61 bez.
vec[1][0] = frame;
62 bez.
vec[1][1] = value;
70 void AnimationImporter::animation_to_fcurves(COLLADAFW::AnimationCurve *
curve)
72 COLLADAFW::FloatOrDoubleArray &
input =
curve->getInputValues();
73 COLLADAFW::FloatOrDoubleArray &
output =
curve->getOutputValues();
76 size_t dim =
curve->getOutDimension();
79 std::vector<FCurve *> &fcurves = curve_map[
curve->getUniqueId()];
87 for (i = 0; i < dim; i++) {
94 for (
unsigned int j = 0; j <
curve->getKeyCount(); j++) {
103 if (
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER ||
104 curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_STEP) {
105 COLLADAFW::FloatOrDoubleArray &intan =
curve->getInTangentValues();
106 COLLADAFW::FloatOrDoubleArray &outtan =
curve->getOutTangentValues();
109 unsigned int index = 2 * (j * dim + i);
116 if (
curve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) {
137 fcurves.push_back(fcu);
138 unused_curves.push_back(fcu);
143 "Output dimension of %d is not yet supported (animation id = %s)\n",
145 curve->getOriginalId().c_str());
149 void AnimationImporter::fcurve_deg_to_rad(
FCurve *cu)
151 for (
unsigned int i = 0; i < cu->
totvert; i++) {
159 void AnimationImporter::fcurve_scale(
FCurve *cu,
int scale)
161 for (
unsigned int i = 0; i < cu->
totvert; i++) {
163 cu->
bezt[i].
vec[1][1] *= scale;
164 cu->
bezt[i].
vec[0][1] *= scale;
165 cu->
bezt[i].
vec[2][1] *= scale;
169 void AnimationImporter::fcurve_is_used(
FCurve *fcu)
171 unused_curves.erase(
std::remove(unused_curves.begin(), unused_curves.end(), fcu),
172 unused_curves.end());
175 void AnimationImporter::add_fcurves_to_object(
Main *bmain,
177 std::vector<FCurve *> &
curves,
191 std::vector<FCurve *>::iterator it;
195 char *p = strstr(rna_path,
"rotation_euler");
196 bool is_rotation = p && *(p + strlen(
"rotation_euler")) ==
'\0';
200 fcurve_deg_to_rad(fcu);
204 for (it =
curves.begin(), i = 0; it !=
curves.end(); it++, i++) {
208 if (array_index == -1) {
224 if (grp ==
nullptr) {
226 grp = MEM_cnew<bActionGroup>(
"bActionGroup");
246 fcurves_actionGroup_map[grp].push_back(fcu);
260 for (
FCurve *unused_curve : unused_curves) {
264 if (!unused_curves.empty()) {
265 fprintf(stderr,
"removed %d unused curves\n", (
int)unused_curves.size());
271 if (
anim->getAnimationType() == COLLADAFW::Animation::ANIMATION_CURVE) {
272 COLLADAFW::AnimationCurve *
curve = (COLLADAFW::AnimationCurve *)
anim;
276 if (
curve->getInPhysicalDimension() != COLLADAFW::PHYSICAL_DIMENSION_TIME) {
277 fprintf(stderr,
"Inputs physical dimension is not time.\n");
285 if (
interp != COLLADAFW::AnimationCurve::INTERPOLATION_MIXED) {
288 case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
289 case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
290 animation_to_fcurves(
curve);
295 "CARDINAL, HERMITE and BSPLINE anim interpolation types not supported yet.\n");
301 fprintf(stderr,
"MIXED anim interpolation type is not supported yet.\n");
305 fprintf(stderr,
"FORMULA animation type is not supported yet.\n");
313 const COLLADAFW::UniqueId &animlist_id = animlist->getUniqueId();
314 animlist_map[animlist_id] = animlist;
319 if (uid_animated_map.find(animlist_id) == uid_animated_map.end()) {
341 virtual void AnimationImporter::change_eul_to_quat(
Object *ob,
bAction *act)
350 if (fcurves_actionGroup_map.find(grp) == fcurves_actionGroup_map.end()) {
354 std::vector<FCurve *> &rot_fcurves = fcurves_actionGroup_map[grp];
356 if (rot_fcurves.size() > 3) {
360 for (i = 0; i < rot_fcurves.size(); i++) {
361 eulcu[rot_fcurves[i]->array_index] = rot_fcurves[i];
364 char joint_path[100];
367 char grp_name_esc[
sizeof(grp->
name) * 2];
370 BLI_snprintf(joint_path,
sizeof(joint_path),
"pose.bones[\"%s\"]", grp_name_esc);
371 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.rotation_quaternion", joint_path);
374 create_fcurve(0, rna_path),
375 create_fcurve(1, rna_path),
376 create_fcurve(2, rna_path),
377 create_fcurve(3, rna_path),
382 float m4[4][4], irest[3][3];
386 for (i = 0; i < 3; i++) {
394 for (
int j = 0; j < cu->
totvert; j++) {
395 float frame = cu->
bezt[j].
vec[1][0];
404 float rot[3][3], rel[3][3], quat[4];
414 for (
int k = 0; k < 4; k++) {
415 create_bezt(quatcu[k], frame, quat[k],
U.ipo_new);
422 for (i = 0; i < 3; i++) {
433 for (i = 0; i < 4; i++) {
446 const char *rna_path,
450 std::vector<FCurve *>::iterator it;
452 for (it =
curves->begin(), i = 0; it !=
curves->end(); it++, i++) {
456 if (array_index == -1) {
464 fcurve_scale(fcu, scale);
474 std::vector<FCurve *>::iterator it;
483 std::vector<FCurve *>::iterator iter;
484 for (iter =
curves->begin(); iter !=
curves->end(); iter++) {
487 for (
unsigned int k = 0; k < fcu->
totvert; k++) {
489 float fra = fcu->
bezt[k].
vec[1][0];
491 if (std::find(frames->begin(), frames->end(), fra) == frames->end()) {
492 frames->push_back(fra);
501 if (COLLADABU::Math::Vector3::UNIT_X == axis) {
504 else if (COLLADABU::Math::Vector3::UNIT_Y == axis) {
507 else if (COLLADABU::Math::Vector3::UNIT_Z == axis) {
518 const COLLADAFW::AnimationList::AnimationBinding *binding,
519 std::vector<FCurve *> *
curves,
523 COLLADAFW::Transformation::TransformationType tm_type =
transform->getTransformationType();
524 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
525 bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
528 bool xyz = ((tm_type == COLLADAFW::Transformation::TRANSLATE ||
529 tm_type == COLLADAFW::Transformation::SCALE) &&
530 binding->animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
532 if (!((!xyz &&
curves->size() == 1) || (xyz &&
curves->size() == 3) || is_matrix)) {
533 fprintf(stderr,
"expected %d curves, got %d\n", xyz ? 3 : 1, (
int)
curves->size());
540 case COLLADAFW::Transformation::TRANSLATE:
541 case COLLADAFW::Transformation::SCALE: {
542 bool loc = tm_type == COLLADAFW::Transformation::TRANSLATE;
544 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, loc ?
"location" :
"scale");
547 BLI_strncpy(rna_path, loc ?
"location" :
"scale",
sizeof(rna_path));
550 switch (binding->animationClass) {
551 case COLLADAFW::AnimationList::POSITION_X:
554 case COLLADAFW::AnimationList::POSITION_Y:
557 case COLLADAFW::AnimationList::POSITION_Z:
560 case COLLADAFW::AnimationList::POSITION_XYZ:
566 "AnimationClass %d is not supported for %s.\n",
567 binding->animationClass,
568 loc ?
"TRANSLATE" :
"SCALE");
573 case COLLADAFW::Transformation::ROTATE: {
575 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.rotation_euler", joint_path);
578 BLI_strncpy(rna_path,
"rotation_euler",
sizeof(rna_path));
580 std::vector<FCurve *>::iterator iter;
581 for (iter =
curves->begin(); iter !=
curves->end(); iter++) {
586 fcurve_deg_to_rad(fcu);
589 COLLADAFW::Rotate *
rot = (COLLADAFW::Rotate *)
transform;
592 switch (binding->animationClass) {
593 case COLLADAFW::AnimationList::ANGLE: {
595 if (axis_index >= 0) {
602 case COLLADAFW::AnimationList::AXISANGLE:
607 "AnimationClass %d is not supported for ROTATE transformation.\n",
608 binding->animationClass);
613 case COLLADAFW::Transformation::MATRIX:
616 COLLADAFW::Matrix *mat = (COLLADAFW::Matrix *)
transform;
617 COLLADABU::Math::Matrix4
mat4 = mat->getMatrix();
618 switch (binding->animationClass) {
619 case COLLADAFW::AnimationList::TRANSFORM:
625 case COLLADAFW::Transformation::SKEW:
626 case COLLADAFW::Transformation::LOOKAT:
628 fprintf(stderr,
"Animation of SKEW and LOOKAT transformations is not supported yet.\n");
635 const char *anim_type)
638 BLI_strncpy(rna_path, anim_type,
sizeof(rna_path));
640 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
641 if (animlist ==
nullptr) {
643 "Collada: No animlist found for ID: %s of type %s\n",
644 listid.toAscii().c_str(),
649 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
651 std::vector<FCurve *> animcurves;
652 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
653 animcurves = curve_map[bindings[j].animation];
655 switch (bindings[j].animationClass) {
656 case COLLADAFW::AnimationList::COLOR_R:
659 case COLLADAFW::AnimationList::COLOR_G:
662 case COLLADAFW::AnimationList::COLOR_B:
665 case COLLADAFW::AnimationList::COLOR_RGB:
666 case COLLADAFW::AnimationList::COLOR_RGBA:
673 "AnimationClass %d is not supported for %s.\n",
674 bindings[j].animationClass,
678 std::vector<FCurve *>::iterator iter;
680 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
690 const char *anim_type)
693 if (animlist_map.find(listid) == animlist_map.end()) {
698 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
699 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
701 std::vector<FCurve *> animcurves;
702 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
703 animcurves = curve_map[bindings[j].animation];
705 BLI_strncpy(rna_path, anim_type,
sizeof(rna_path));
707 std::vector<FCurve *>::iterator iter;
709 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
713 if (
STREQ(
"spot_size", anim_type)) {
717 if (this->import_from_version.empty() ||
719 fcurve_deg_to_rad(fcu);
736 float xfov = (fov_type == CAMERA_YFOV) ?
746 const char *anim_type,
750 if (animlist_map.find(listid) == animlist_map.end()) {
755 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
756 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
758 std::vector<FCurve *> animcurves;
759 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
760 animcurves = curve_map[bindings[j].animation];
762 BLI_strncpy(rna_path, anim_type,
sizeof(rna_path));
765 std::vector<FCurve *>::iterator iter;
767 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
770 for (
unsigned int i = 0; i < fcu->
totvert; i++) {
786 std::vector<FCurve *> &animcurves,
787 COLLADAFW::Node *root,
788 COLLADAFW::Node *
node,
789 COLLADAFW::Transformation *tm)
791 bool is_joint =
node->getType() == COLLADAFW::Node::JOINT;
793 char joint_path[200];
798 std::vector<float> frames;
801 float irest_dae[4][4];
802 float rest[4][4], irest[4][4];
810 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
820 unsigned int totcu = 10;
821 const char *tm_str =
nullptr;
823 for (
int i = 0; i < totcu; i++) {
828 tm_str =
"rotation_quaternion";
841 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, tm_str);
846 newcu[i] = create_fcurve(axis, rna_path);
847 newcu[i]->
totvert = frames.size();
850 if (frames.empty()) {
856 std::vector<float>::iterator it;
864 for (it = frames.begin(); it != frames.end(); it++) {
881 float temp[4][4], par[4][4];
888 evaluate_joint_world_transform_at_frame(temp,
NULL,
node, fra);
898 float rot[4], loc[3], scale[3];
902 for (
int i = 0; i < totcu; i++) {
904 add_bezt(newcu[i], fra,
rot[i]);
907 add_bezt(newcu[i], fra, loc[i - 4]);
910 add_bezt(newcu[i], fra, scale[i - 7]);
920 for (
int i = 0; i < totcu; i++) {
928 fcurve_is_used(newcu[i]);
953 double aspect =
camera->getAspectRatio().getValue();
956 const double yfov =
camera->getYFov().getValue();
962 const double xfov =
camera->getXFov().getValue();
967 aspect = xfov / yfov;
988 COLLADAFW::Node *
node,
989 std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map,
990 std::multimap<COLLADAFW::UniqueId, Object *> &object_map,
991 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map,
992 std::map<COLLADAFW::UniqueId, Material *> uid_material_map)
994 bool is_joint =
node->getType() == COLLADAFW::Node::JOINT;
995 COLLADAFW::UniqueId uid =
node->getUniqueId();
996 COLLADAFW::Node *root = root_map.find(uid) == root_map.end() ?
node : root_map[uid];
1003 ob = object_map.find(uid) == object_map.end() ?
NULL : object_map.find(uid)->second;
1007 fprintf(stderr,
"cannot find Object for Node with id=\"%s\"\n",
node->getOriginalId().c_str());
1015 if ((animType->transform) != 0) {
1017 char joint_path[200];
1033 const COLLADAFW::TransformationPointerArray &nodeTransforms =
node->getTransformations();
1036 for (
unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
1037 COLLADAFW::Transformation *
transform = nodeTransforms[i];
1038 COLLADAFW::Transformation::TransformationType tm_type =
transform->getTransformationType();
1040 bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
1041 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
1043 const COLLADAFW::UniqueId &listid =
transform->getAnimationList();
1046 if (animlist_map.find(listid) == animlist_map.end()) {
1051 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1052 const COLLADAFW::AnimationList::AnimationBindings &bindings =
1053 animlist->getAnimationBindings();
1055 std::vector<FCurve *> animcurves;
1056 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
1057 animcurves = curve_map[bindings[j].animation];
1066 std::vector<FCurve *>::iterator iter;
1068 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
1072 fcurve_is_used(fcu);
1077 if (is_rotation && !(is_joint || is_matrix)) {
1083 if ((animType->light) != 0) {
1093 const COLLADAFW::InstanceLightPointerArray &nodeLights =
node->getInstanceLights();
1095 for (
unsigned int i = 0; i < nodeLights.getCount(); i++) {
1097 FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
1099 if ((animType->light & LIGHT_COLOR) != 0) {
1101 const COLLADAFW::UniqueId &listid =
col->getAnimationList();
1105 if ((animType->light & LIGHT_FOA) != 0) {
1106 const COLLADAFW::AnimatableFloat *foa = &(light->getFallOffAngle());
1107 const COLLADAFW::UniqueId &listid = foa->getAnimationList();
1111 if ((animType->light & LIGHT_FOE) != 0) {
1112 const COLLADAFW::AnimatableFloat *foe = &(light->getFallOffExponent());
1113 const COLLADAFW::UniqueId &listid = foe->getAnimationList();
1120 if (animType->camera != 0) {
1131 const COLLADAFW::InstanceCameraPointerArray &nodeCameras =
node->getInstanceCameras();
1133 for (
unsigned int i = 0; i < nodeCameras.getCount(); i++) {
1135 FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
1137 if ((animType->camera & CAMERA_XFOV) != 0) {
1138 const COLLADAFW::AnimatableFloat *xfov = &(
camera->getXFov());
1139 const COLLADAFW::UniqueId &listid = xfov->getAnimationList();
1144 else if ((animType->camera & CAMERA_YFOV) != 0) {
1145 const COLLADAFW::AnimatableFloat *yfov = &(
camera->getYFov());
1146 const COLLADAFW::UniqueId &listid = yfov->getAnimationList();
1151 else if ((animType->camera & CAMERA_XMAG) != 0) {
1152 const COLLADAFW::AnimatableFloat *xmag = &(
camera->getXMag());
1153 const COLLADAFW::UniqueId &listid = xmag->getAnimationList();
1157 else if ((animType->camera & CAMERA_YMAG) != 0) {
1158 const COLLADAFW::AnimatableFloat *ymag = &(
camera->getYMag());
1159 const COLLADAFW::UniqueId &listid = ymag->getAnimationList();
1163 if ((animType->camera & CAMERA_ZFAR) != 0) {
1164 const COLLADAFW::AnimatableFloat *zfar = &(
camera->getFarClippingPlane());
1165 const COLLADAFW::UniqueId &listid = zfar->getAnimationList();
1169 if ((animType->camera & CAMERA_ZNEAR) != 0) {
1170 const COLLADAFW::AnimatableFloat *znear = &(
camera->getNearClippingPlane());
1171 const COLLADAFW::UniqueId &listid = znear->getAnimationList();
1176 if (animType->material != 0) {
1186 const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms =
node->getInstanceGeometries();
1187 for (
unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
1188 const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
1189 for (
unsigned int j = 0; j < matBinds.getCount(); j++) {
1190 const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
1192 if (ef !=
nullptr) {
1193 Material *ma = uid_material_map[matuid];
1196 "Collada: Node %s refers to undefined material\n",
1197 node->getName().c_str());
1201 const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
1202 COLLADAFW::EffectCommon *efc = commonEffects[0];
1203 if ((animType->material & MATERIAL_SHININESS) != 0) {
1204 const COLLADAFW::FloatOrParam *shin = &(efc->getShininess());
1205 const COLLADAFW::UniqueId &listid = shin->getAnimationList();
1209 if ((animType->material & MATERIAL_IOR) != 0) {
1210 const COLLADAFW::FloatOrParam *
ior = &(efc->getIndexOfRefraction());
1211 const COLLADAFW::UniqueId &listid =
ior->getAnimationList();
1215 if ((animType->material & MATERIAL_SPEC_COLOR) != 0) {
1216 const COLLADAFW::ColorOrTexture *cot = &(efc->getSpecular());
1217 const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
1221 if ((animType->material & MATERIAL_DIFF_COLOR) != 0) {
1222 const COLLADAFW::ColorOrTexture *cot = &(efc->getDiffuse());
1223 const COLLADAFW::UniqueId &listid = cot->getColor().getAnimationList();
1235 std::vector<FCurve *> &animcurves,
1236 COLLADAFW::Node *root,
1237 COLLADAFW::Node *
node,
1238 COLLADAFW::Transformation *tm)
1241 char joint_path[200];
1244 std::vector<float> frames;
1248 if (tm->getTransformationType() == COLLADAFW::Transformation::ROTATE) {
1250 std::vector<FCurve *>::iterator iter;
1251 for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
1254 fcurve_deg_to_rad(fcu);
1258 float irest_dae[4][4];
1259 float rest[4][4], irest[4][4];
1266 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
1276 unsigned int totcu = 10;
1277 const char *tm_str =
nullptr;
1279 for (
int i = 0; i < totcu; i++) {
1284 tm_str =
"rotation_quaternion";
1288 tm_str =
"location";
1296 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, tm_str);
1298 newcu[i] = create_fcurve(axis, rna_path);
1299 newcu[i]->
totvert = frames.size();
1302 if (frames.empty()) {
1306 std::sort(frames.begin(), frames.end());
1310 std::vector<float>::iterator it;
1313 for (it = frames.begin(); it != frames.end(); it++) {
1348 for (
int i = 0; i < totcu; i++) {
1350 add_bezt(newcu[i], fra, qref.
quat()[i]);
1353 add_bezt(newcu[i], fra, loc[i - 4]);
1356 add_bezt(newcu[i], fra, scale[i - 7]);
1364 for (
int i = 0; i < totcu; i++) {
1367 fcurve_is_used(newcu[i]);
1376 const COLLADAFW::Node *
node,
1377 std::map<COLLADAFW::UniqueId, const COLLADAFW::Object *> FW_object_map)
1379 AnimMix *
types =
new AnimMix();
1381 const COLLADAFW::TransformationPointerArray &nodeTransforms =
node->getTransformations();
1384 for (
unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
1385 COLLADAFW::Transformation *
transform = nodeTransforms[i];
1386 const COLLADAFW::UniqueId &listid =
transform->getAnimationList();
1389 if (animlist_map.find(listid) == animlist_map.end()) {
1393 types->transform =
types->transform | BC_NODE_TRANSFORM;
1396 const COLLADAFW::InstanceLightPointerArray &nodeLights =
node->getInstanceLights();
1398 for (
unsigned int i = 0; i < nodeLights.getCount(); i++) {
1400 FW_object_map[nodeLights[i]->getInstanciatedObjectId()];
1405 if (
types->light != 0) {
1410 const COLLADAFW::InstanceCameraPointerArray &nodeCameras =
node->getInstanceCameras();
1411 for (
unsigned int i = 0; i < nodeCameras.getCount(); i++) {
1413 FW_object_map[nodeCameras[i]->getInstanciatedObjectId()];
1419 const bool is_perspective_type =
camera->getCameraType() == COLLADAFW::Camera::PERSPECTIVE;
1422 const COLLADAFW::Animatable *mag;
1423 const COLLADAFW::UniqueId listid =
camera->getYMag().getAnimationList();
1424 if (animlist_map.find(listid) != animlist_map.end()) {
1425 mag = &(
camera->getYMag());
1426 addition = (is_perspective_type) ? CAMERA_YFOV : CAMERA_YMAG;
1429 mag = &(
camera->getXMag());
1430 addition = (is_perspective_type) ? CAMERA_XFOV : CAMERA_XMAG;
1437 if (
types->camera != 0) {
1442 const COLLADAFW::InstanceGeometryPointerArray &nodeGeoms =
node->getInstanceGeometries();
1443 for (
unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
1444 const COLLADAFW::MaterialBindingArray &matBinds = nodeGeoms[i]->getMaterialBindings();
1445 for (
unsigned int j = 0; j < matBinds.getCount(); j++) {
1446 const COLLADAFW::UniqueId &matuid = matBinds[j].getReferencedMaterial();
1448 if (ef !=
nullptr) {
1449 const COLLADAFW::CommonEffectPointerArray &commonEffects = ef->getCommonEffects();
1450 if (!commonEffects.empty()) {
1451 COLLADAFW::EffectCommon *efc = commonEffects[0];
1453 &(efc->getShininess()), (
types->material), MATERIAL_SHININESS);
1455 &(efc->getSpecular().getColor()), (
types->material), MATERIAL_SPEC_COLOR);
1457 &(efc->getDiffuse().getColor()), (
types->material), MATERIAL_DIFF_COLOR);
1462 &(efc->getIndexOfRefraction()), (
types->material), MATERIAL_IOR);
1473 const COLLADAFW::UniqueId &listid = prop->getAnimationList();
1474 if (animlist_map.find(listid) != animlist_map.end()) {
1475 anim_type =
types | addition;
1485 COLLADAFW::Node *
node,
1486 COLLADAFW::Transformation::TransformationType tm_type)
1488 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
1489 bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
1491 const COLLADAFW::TransformationPointerArray &nodeTransforms =
node->getTransformations();
1495 for (i = 0; i < nodeTransforms.getCount(); i++) {
1496 COLLADAFW::Transformation *
transform = nodeTransforms[i];
1497 COLLADAFW::Transformation::TransformationType nodeTmType =
transform->getTransformationType();
1499 if (nodeTmType == tm_type) {
1501 const COLLADAFW::UniqueId &listid =
transform->getAnimationList();
1503 if (animlist_map.find(listid) != animlist_map.end()) {
1505 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1506 const COLLADAFW::AnimationList::AnimationBindings &bindings =
1507 animlist->getAnimationBindings();
1509 if (bindings.getCount()) {
1511 for (
unsigned int j = 0; j < bindings.getCount(); j++) {
1512 std::vector<FCurve *> &
curves = curve_map[bindings[j].animation];
1513 bool xyz = ((nodeTmType == COLLADAFW::Transformation::TRANSLATE ||
1514 nodeTmType == COLLADAFW::Transformation::SCALE) &&
1515 bindings[j].animationClass == COLLADAFW::AnimationList::POSITION_XYZ);
1517 if ((!xyz &&
curves.size() == 1) || (xyz &&
curves.size() == 3) || is_matrix) {
1518 std::vector<FCurve *>::iterator iter;
1520 for (iter =
curves.begin(); iter !=
curves.end(); iter++) {
1525 fcurve_deg_to_rad(fcu);
1528 for (
unsigned int k = 0; k < fcu->
totvert; k++) {
1530 float fra = fcu->
bezt[k].
vec[1][0];
1532 if (std::find(frames->begin(), frames->end(), fra) == frames->end()) {
1533 frames->push_back(fra);
1539 fprintf(stderr,
"expected %d curves, got %d\n", xyz ? 3 : 1, (
int)
curves.size());
1549 COLLADAFW::Node *
node,
1550 std::map<COLLADAFW::UniqueId, Object *> &object_map,
1551 std::map<COLLADAFW::UniqueId, COLLADAFW::Node *> &root_map,
1552 COLLADAFW::Transformation::TransformationType tm_type,
1556 bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
1557 bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
1558 bool is_joint =
node->getType() == COLLADAFW::Node::JOINT;
1560 COLLADAFW::Node *root = root_map.find(
node->getUniqueId()) == root_map.end() ?
1562 root_map[
node->getUniqueId()];
1564 object_map[
node->getUniqueId()];
1567 fprintf(stderr,
"cannot find Object for Node with id=\"%s\"\n",
node->getOriginalId().c_str());
1572 std::vector<float> frames;
1578 float irest_dae[4][4];
1579 float rest[4][4], irest[4][4];
1587 fprintf(stderr,
"cannot find bone \"%s\"\n", bone_name);
1598 #ifdef ARMATURE_TEST
1600 job = get_joint_object(root,
node, par_job);
1603 if (frames.empty()) {
1607 std::sort(frames.begin(), frames.end());
1609 const char *tm_str =
nullptr;
1611 case COLLADAFW::Transformation::ROTATE:
1612 tm_str =
"rotation_quaternion";
1614 case COLLADAFW::Transformation::SCALE:
1617 case COLLADAFW::Transformation::TRANSLATE:
1618 tm_str =
"location";
1620 case COLLADAFW::Transformation::MATRIX:
1627 char joint_path[200];
1635 unsigned int totcu = is_matrix ? 10 : (is_rotation ? 4 : 3);
1637 for (i = 0; i < totcu; i++) {
1643 tm_str =
"rotation_quaternion";
1647 tm_str =
"location";
1657 BLI_snprintf(rna_path,
sizeof(rna_path),
"%s.%s", joint_path, tm_str);
1662 newcu[i] = create_fcurve(axis, rna_path);
1664 #ifdef ARMATURE_TEST
1666 job_curves[i] = create_fcurve(axis, tm_str);
1671 std::vector<float>::iterator it;
1674 for (it = frames.begin(); it != frames.end(); it++) {
1691 float temp[4][4], par[4][4];
1707 float rot[4], loc[3], scale[3];
1710 case COLLADAFW::Transformation::ROTATE:
1713 case COLLADAFW::Transformation::SCALE:
1716 case COLLADAFW::Transformation::TRANSLATE:
1719 case COLLADAFW::Transformation::MATRIX:
1729 for (i = 0; i < totcu; i++) {
1732 add_bezt(newcu[i], fra,
rot[i]);
1735 add_bezt(newcu[i], fra, loc[i - 4]);
1738 add_bezt(newcu[i], fra, scale[i - 7]);
1742 add_bezt(newcu[i], fra, val[i]);
1746 #ifdef ARMATURE_TEST
1749 case COLLADAFW::Transformation::ROTATE:
1752 case COLLADAFW::Transformation::SCALE:
1755 case COLLADAFW::Transformation::TRANSLATE:
1767 for (i = 0; i < totcu; i++) {
1770 add_bezt(job_curves[i], fra,
rot[i]);
1773 add_bezt(job_curves[i], fra, loc[i - 4]);
1776 add_bezt(job_curves[i], fra, scale[i - 7]);
1780 add_bezt(job_curves[i], fra, val[i]);
1792 for (i = 0; i < totcu; i++) {
1800 #ifdef ARMATURE_TEST
1807 if (is_rotation || is_matrix) {
1821 COLLADAFW::Node *
node,
1824 const COLLADAFW::TransformationPointerArray &tms =
node->getTransformations();
1828 for (
unsigned int i = 0; i < tms.getCount(); i++) {
1829 COLLADAFW::Transformation *tm = tms[i];
1830 COLLADAFW::Transformation::TransformationType
type = tm->getTransformationType();
1835 std::string nodename =
node->getName().empty() ?
node->getOriginalId() :
node->getName();
1838 case COLLADAFW::Transformation::ROTATE:
1841 case COLLADAFW::Transformation::TRANSLATE:
1844 case COLLADAFW::Transformation::SCALE:
1847 case COLLADAFW::Transformation::MATRIX:
1851 fprintf(stderr,
"unsupported transformation type %d\n",
type);
1863 const COLLADAFW::AnimationList::AnimationClass animclass,
1864 const COLLADAFW::Transformation::TransformationType
type)
1866 if (animclass == COLLADAFW::AnimationList::UNKNOWN_CLASS) {
1867 fprintf(stderr,
"%s: UNKNOWN animation class\n", path);
1871 "%s: animation class %d is not supported yet for transformation type %d\n",
1881 const char *node_id)
1883 const COLLADAFW::UniqueId &listid = tm->getAnimationList();
1884 COLLADAFW::Transformation::TransformationType
type = tm->getTransformationType();
1886 if (
type != COLLADAFW::Transformation::ROTATE &&
type != COLLADAFW::Transformation::SCALE &&
1887 type != COLLADAFW::Transformation::TRANSLATE &&
type != COLLADAFW::Transformation::MATRIX) {
1888 fprintf(stderr,
"animation of transformation %d is not supported yet\n",
type);
1892 if (animlist_map.find(listid) == animlist_map.end()) {
1896 const COLLADAFW::AnimationList *animlist = animlist_map[listid];
1897 const COLLADAFW::AnimationList::AnimationBindings &bindings = animlist->getAnimationBindings();
1899 if (bindings.getCount()) {
1902 bool is_scale = (
type == COLLADAFW::Transformation::SCALE);
1903 bool is_translate = (
type == COLLADAFW::Transformation::TRANSLATE);
1908 else if (is_translate) {
1912 for (
unsigned int index = 0; index < bindings.getCount(); index++) {
1913 const COLLADAFW::AnimationList::AnimationBinding &binding = bindings[index];
1914 std::vector<FCurve *> &
curves = curve_map[binding.animation];
1915 COLLADAFW::AnimationList::AnimationClass animclass = binding.animationClass;
1919 case COLLADAFW::Transformation::ROTATE:
1920 BLI_snprintf(path,
sizeof(path),
"%s.rotate (binding %u)", node_id, index);
1922 case COLLADAFW::Transformation::SCALE:
1923 BLI_snprintf(path,
sizeof(path),
"%s.scale (binding %u)", node_id, index);
1925 case COLLADAFW::Transformation::TRANSLATE:
1926 BLI_snprintf(path,
sizeof(path),
"%s.translate (binding %u)", node_id, index);
1928 case COLLADAFW::Transformation::MATRIX:
1929 BLI_snprintf(path,
sizeof(path),
"%s.matrix (binding %u)", node_id, index);
1935 if (
type == COLLADAFW::Transformation::ROTATE) {
1936 if (
curves.size() != 1) {
1937 fprintf(stderr,
"expected 1 curve, got %d\n", (
int)
curves.size());
1942 if (animclass != COLLADAFW::AnimationList::ANGLE) {
1949 float ax[3] = {(
float)axis[0], (
float)axis[1], (
float)axis[2]};
1955 if (is_scale || is_translate) {
1956 bool is_xyz = animclass == COLLADAFW::AnimationList::POSITION_XYZ;
1958 if ((!is_xyz &&
curves.size() != 1) || (is_xyz &&
curves.size() != 3)) {
1960 fprintf(stderr,
"%s: expected 3 curves, got %d\n", path, (
int)
curves.size());
1963 fprintf(stderr,
"%s: expected 1 curve, got %d\n", path, (
int)
curves.size());
1968 switch (animclass) {
1969 case COLLADAFW::AnimationList::POSITION_X:
1972 case COLLADAFW::AnimationList::POSITION_Y:
1975 case COLLADAFW::AnimationList::POSITION_Z:
1978 case COLLADAFW::AnimationList::POSITION_XYZ:
1988 else if (
type == COLLADAFW::Transformation::MATRIX) {
1991 if (
curves.size() != 16) {
1992 fprintf(stderr,
"%s: expected 16 curves, got %d\n", path, (
int)
curves.size());
1996 COLLADABU::Math::Matrix4 matrix;
2019 return is_scale || is_translate;
2026 COLLADAFW::Node *root,
2027 COLLADAFW::Node *
node)
2032 float par[4][4], m[4][4];
2042 COLLADAFW::Node *
node,
2043 COLLADAFW::Node *end)
2064 COLLADAFW::NodePointerArray &children =
node->getChildNodes();
2065 for (
unsigned int i = 0; i < children.getCount(); i++) {
2074 #ifdef ARMATURE_TEST
2075 Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root,
2076 COLLADAFW::Node *
node,
2079 if (joint_objects.find(
node->getUniqueId()) == joint_objects.end()) {
2082 job->lay = BKE_scene_base_find(scene, job)->lay = 2;
2095 float temp[4][4], ipar[4][4];
2115 joint_objects[
node->getUniqueId()] = job;
2118 return joint_objects[
node->getUniqueId()];
2125 bool AnimationImporter::evaluate_joint_world_transform_at_frame(
2126 float mat[4][4],
float par[4][4], COLLADAFW::Node *
node, COLLADAFW::Node *end,
float fra)
2143 COLLADAFW::NodePointerArray &children =
node->getChildNodes();
2144 for (
int i = 0; i < children.getCount(); i++) {
2145 if (evaluate_joint_world_transform_at_frame(mat, m, children[i], end, fra)) {
2164 if (grp ==
nullptr) {
2166 grp = MEM_cnew<bActionGroup>(
"bActionGroup");
2186 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 BKE_fcurve_handles_recalc(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], 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])
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 axis_angle_to_mat4(float R[4][4], const float axis[3], float angle)
void mat4_to_quat(float q[4], const float mat[4][4])
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])
int BLI_strcasecmp_natural(const char *s1, const char *s2) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
size_t size_t char size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL()
bool BLI_uniquename(struct ListBase *list, void *vlink, const char *defname, char delim, int name_offset, size_t name_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.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Retrieve a color or the default fallback if none is specified Separate Split a vector into its and Z components Generates normals with round corners and may slow down renders Vector Displace the surface along an arbitrary direction White Return a random value or color based on an input seed Float Map an input float to a curve and outputs a float value Separate Color
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between camera
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)
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 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 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)
ccl_global KernelShaderEvalInput ccl_global float * output
ccl_global KernelShaderEvalInput * input
bAction * ED_id_action_ensure(Main *bmain, ID *id)
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
bool remove(void *owner, const AttributeIDRef &attribute_id)
static const pxr::TfToken ior("ior", pxr::TfToken::Immortal)
struct bActionGroup * next
struct bPoseChannel * next