Page Menu
Home
Search
Configure Global Search
Log In
Files
F17908
collada_import.diff
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
kanttori (kanttori)
Nov 13 2013, 4:04 PM
Size
12 KB
Subscribers
None
collada_import.diff
View Options
Index: source/blender/collada/DocumentImporter.cpp
===================================================================
--- source/blender/collada/DocumentImporter.cpp (revision 43870)
+++ source/blender/collada/DocumentImporter.cpp (working copy)
@@ -232,10 +232,16 @@
}
}
-
void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW::Node *par = NULL, Object *parob = NULL)
{
- if (par && par->getType() == COLLADAFW::Node::JOINT) {
+ // The split in #29246, rootmap must point at actual root when
+ // calculating bones in apply_curves_as_matrix.
+ // This has to do with inverse bind poses being world space
+ // (the sources for skinned bones' restposes) and the way
+ // non-skinning nodes have their "restpose" recursively calculated.
+ // XXX TODO: design issue, how to support unrelated joints taking
+ // part in skinning.
+ if (par) { // && par->getType() == COLLADAFW::Node::JOINT) {
// par is root if there's no corresp. key in root_map
if (root_map.find(par->getUniqueId()) == root_map.end())
root_map[node->getUniqueId()] = par;
Index: source/blender/collada/AnimationImporter.h
===================================================================
--- source/blender/collada/AnimationImporter.h (revision 43870)
+++ source/blender/collada/AnimationImporter.h (working copy)
@@ -148,11 +148,12 @@
std::map<COLLADAFW::UniqueId, Object*>& object_map ,
std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map);
- AnimMix* get_animation_type( const COLLADAFW::Node * node , std::map<COLLADAFW::UniqueId,const COLLADAFW::Object*> FW_object_map ) ;
+ AnimMix* get_animation_type( const COLLADAFW::Node * node , std::map<COLLADAFW::UniqueId,const COLLADAFW::Object*> FW_object_map );
- void apply_matrix_curves( Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root ,COLLADAFW::Node* node,
- COLLADAFW::Transformation * tm );
+ void apply_curves_via_matrix( Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root ,COLLADAFW::Node* node);
+ bool transform_compatibility(COLLADAFW::Node*);
+
void Assign_transform_animations(COLLADAFW::Transformation* transform ,
const COLLADAFW::AnimationList::AnimationBinding * binding,
std::vector<FCurve*>* curves, bool is_joint, char * joint_path);
Index: source/blender/collada/collada_utils.cpp
===================================================================
--- source/blender/collada/collada_utils.cpp (revision 43870)
+++ source/blender/collada/collada_utils.cpp (working copy)
@@ -67,6 +67,9 @@
return bc_test_parent_loop(par->parent, ob);
}
+// TODO: there should be a version which is regular blender-style and
+// one for node-parenting always with unit/identity parentinverse
+
// a shortened version of parent_set_exec()
// if is_parent_space is true then ob->obmat will be multiplied by par->obmat before parenting
int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
@@ -92,13 +95,20 @@
mult_m4_m4m4(mat, par->obmat, ob->obmat);
copy_m4_m4(ob->obmat, mat);
}
-
+
+ // Imo objects from collada should always have identity parentinvs.
+ // unless it's extracted from the transforms somehow
+ unit_m4(ob->parentinv);
// apply child obmat (i.e. decompose it into rot/loc/size)
- object_apply_mat4(ob, ob->obmat, 0, 0);
+ object_apply_mat4(ob, ob->obmat, 0, is_parent_space);
- // compute parentinv
- what_does_parent(sce, ob, &workob);
- invert_m4_m4(ob->parentinv, workob.obmat);
+ // One case in ArmatureImporter has is_parent_space false
+ if(!is_parent_space)
+ {
+ // compute parentinv
+ what_does_parent(sce, ob, &workob);
+ invert_m4_m4(ob->parentinv, workob.obmat);
+ }
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
par->recalc |= OB_RECALC_OB;
Index: source/blender/collada/AnimationImporter.cpp
===================================================================
--- source/blender/collada/AnimationImporter.cpp (revision 43870)
+++ source/blender/collada/AnimationImporter.cpp (working copy)
@@ -634,9 +634,60 @@
}
-void AnimationImporter::apply_matrix_curves( Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root ,COLLADAFW::Node* node,
- COLLADAFW::Transformation * tm )
+// TODO: if parentinverse-matrix is read from transforms then
+// it's part must be ignored here and elsewhere
+// TODO: could add detection of different euler combinations
+// or axis/angle support.
+bool AnimationImporter::transform_compatibility(COLLADAFW::Node* node)
{
+ const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
+
+ std::list<COLLADAFW::Transformation::TransformationType> types;
+
+ types.push_back(COLLADAFW::Transformation::TRANSLATE);
+ types.push_back(COLLADAFW::Transformation::ROTATE);
+ types.push_back(COLLADAFW::Transformation::SCALE);
+
+ std::list<COLLADABU::Math::Vector3> axises;
+
+ axises.push_back(COLLADABU::Math::Vector3(0,0,1));
+ axises.push_back(COLLADABU::Math::Vector3(0,1,0));
+ axises.push_back(COLLADABU::Math::Vector3(1,0,0));
+
+ for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
+ COLLADAFW::Transformation *transform = nodeTransforms[i];
+ COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
+
+ // Skip types that don't match current transform
+ while(types.size() && tm_type != types.front()) types.pop_front();
+ if(!types.size()) return false;
+
+ if(tm_type == COLLADAFW::Transformation::ROTATE)
+ {
+ COLLADAFW::Rotate* rotate = dynamic_cast<COLLADAFW::Rotate*>(transform);
+ BLI_assert(rotate);
+
+ while(axises.size() && rotate->getRotationAxis() != axises.front())
+ axises.pop_front();
+ if(!axises.size()) return false;
+ axises.pop_front();
+
+ // If this was the last rotate transform allowed
+ if(!axises.size()) types.pop_front();
+ }
+ else
+ {
+ // Other transforms are only present once
+ types.pop_front();
+ }
+ }
+
+ return true;
+}
+
+
+void AnimationImporter::apply_curves_via_matrix( Object * ob, std::vector<FCurve*>& animcurves, COLLADAFW::Node* root ,COLLADAFW::Node* node)
+{
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL;
char joint_path[200];
@@ -713,7 +764,6 @@
// calc object-space mat
evaluate_transform_at_frame(matfra, node, fra);
-
// for joints, we need a special matrix
if (is_joint) {
// special matrix: iR * M * iR_dae * R
@@ -798,12 +848,14 @@
if ( (animType->transform) != 0 )
{
- const char *bone_name = is_joint ? bc_get_joint_name(node) : NULL;
char joint_path[200];
if ( is_joint )
armature_importer->get_rna_path_for_joint(node, joint_path, sizeof(joint_path));
+ // Afaik joints never have compatible transforms because blender always
+ // has some offset between bones from restpose.
+ bool compatible_transform = !is_joint && transform_compatibility(node);
if (!ob->adt || !ob->adt->action) act = verify_adt_action((ID*)&ob->id, 1);
else act = ob->adt->action;
@@ -813,56 +865,69 @@
const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
- //for each transformation in node
- for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
- COLLADAFW::Transformation *transform = nodeTransforms[i];
- COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
+ // compatible transform, objects only
+ if(compatible_transform)
+ {
+ //for each transformation in node
+ for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
+ COLLADAFW::Transformation *transform = nodeTransforms[i];
+ COLLADAFW::Transformation::TransformationType tm_type = transform->getTransformationType();
- bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
- bool is_matrix = tm_type == COLLADAFW::Transformation::MATRIX;
+ bool is_rotation = tm_type == COLLADAFW::Transformation::ROTATE;
+ const COLLADAFW::UniqueId& listid = transform->getAnimationList();
- const COLLADAFW::UniqueId& listid = transform->getAnimationList();
-
- //check if transformation has animations
- if (animlist_map.find(listid) == animlist_map.end()) continue ;
- else
- {
- //transformation has animations
- const COLLADAFW::AnimationList *animlist = animlist_map[listid];
- const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
- //all the curves belonging to the current binding
- std::vector<FCurve*> animcurves;
- for (unsigned int j = 0; j < bindings.getCount(); j++) {
- animcurves = curve_map[bindings[j].animation];
- if ( is_matrix )
- apply_matrix_curves(ob, animcurves, root , node, transform );
- else {
+ //check if transformation has animations
+ if (animlist_map.find(listid) == animlist_map.end()) continue ;
+ else
+ {
+ //transformation has animations
+ const COLLADAFW::AnimationList *animlist = animlist_map[listid];
+ const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
+ //all the curves belonging to the current binding
+ std::vector<FCurve*> animcurves;
+ for (unsigned int j = 0; j < bindings.getCount(); j++) {
+ animcurves = curve_map[bindings[j].animation];
//calculate rnapaths and array index of fcurves according to transformation and animation class
- Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path );
+ Assign_transform_animations(transform, &bindings[j], &animcurves, is_joint, joint_path );
std::vector<FCurve*>::iterator iter;
//Add the curves of the current animation to the object
for (iter = animcurves.begin(); iter != animcurves.end(); iter++) {
- FCurve * fcu = *iter;
- if ((ob->type == OB_ARMATURE))
- add_bone_fcurve( ob, node , fcu );
- else
- BLI_addtail(AnimCurves, fcu);
+ BLI_addtail(AnimCurves, *iter);
}
}
}
+ // TODO: compatible animation is always euler
+ if (is_rotation) {
+ ob->rotmode = ROT_MODE_EUL;
+ }
}
- if (is_rotation) {
- if (is_joint)
+ }
+ else
+ {
+ // animcurves are only used to find frames to bake
+ std::vector<FCurve*> animcurves;
+
+ //for each transformation in node
+ for (unsigned int i = 0; i < nodeTransforms.getCount(); i++) {
+ COLLADAFW::Transformation *transform = nodeTransforms[i];
+ const COLLADAFW::UniqueId& listid = transform->getAnimationList();
+
+ //check if transformation has animations
+ if (animlist_map.find(listid) == animlist_map.end()) continue ;
+ else
{
- bPoseChannel *chan = get_pose_channel(ob->pose, bone_name);
- chan->rotmode = ROT_MODE_EUL;
+ //transformation has animations
+ const COLLADAFW::AnimationList *animlist = animlist_map[listid];
+ const COLLADAFW::AnimationList::AnimationBindings& bindings = animlist->getAnimationBindings();
+ //all the curves belonging to the current binding
+ for (unsigned int j = 0; j < bindings.getCount(); j++) {
+ const std::vector<FCurve*>& ac = curve_map[bindings[j].animation];
+ animcurves.insert(animcurves.end(), ac.begin(), ac.end());
+ }
}
- else
- {
- ob->rotmode = ROT_MODE_EUL;
- }
}
+ apply_curves_via_matrix(ob, animcurves, root , node);
}
}
@@ -1278,7 +1343,6 @@
calc_joint_parent_mat_rest(par, NULL, root, node);
mult_m4_m4m4(temp, par, matfra);
- // evaluate_joint_world_transform_at_frame(temp, NULL, , node, fra);
// calc special matrix
mul_serie_m4(mat, irest, temp, irest_dae, rest, NULL, NULL, NULL, NULL);
@@ -1392,7 +1456,8 @@
}
// internal, better make it private
-// warning: evaluates only rotation and only assigns matrix transforms now
+// evaluates supported transforms into single matrix
+// OLD: warning: evaluates only rotation and only assigns matrix transforms now
// prerequisites: animlist_map, curve_map
void AnimationImporter::evaluate_transform_at_frame(float mat[4][4], COLLADAFW::Node *node, float fra)
{
@@ -1406,12 +1471,12 @@
float m[4][4];
unit_m4(m);
- if ( type != COLLADAFW::Transformation::MATRIX )
- continue;
+ /*if ( type != COLLADAFW::Transformation::MATRIX )
+ continue;*/
std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
if (!evaluate_animation(tm, m, fra, nodename.c_str())) {
- /*switch (type) {
+ switch (type) {
case COLLADAFW::Transformation::ROTATE:
dae_rotate_to_mat4(tm, m);
break;
@@ -1426,8 +1491,8 @@
break;
default:
fprintf(stderr, "unsupported transformation type %d\n", type);
- }*/
- dae_matrix_to_mat4(tm, m);
+ }
+ //dae_matrix_to_mat4(tm, m);
}
@@ -1511,7 +1576,8 @@
COLLADABU::Math::Vector3& axis = ((COLLADAFW::Rotate*)tm)->getRotationAxis();
float ax[3] = {axis[0], axis[1], axis[2]};
- float angle = evaluate_fcurve(curves[0], fra);
+ // These curves have not been blenderized.
+ float angle = DEG2RADF(evaluate_fcurve(curves[0], fra));
axis_angle_to_mat4(mat, ax, angle);
return true;
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
cb/c3/dbaabec211a9b347534c335dc73f
Event Timeline
Log In to Comment