Revision: 37664
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=37664
Author:   jesterking
Date:     2011-06-20 12:43:10 +0000 (Mon, 20 Jun 2011)
Log Message:
-----------
Fix [#26912] [Collada] Screw up with names/ids on import
Reported by Valeriy Firsov

Use the node name if it exists, fall back to id otherwise.

Modified Paths:
--------------
    trunk/blender/source/blender/collada/AnimationImporter.cpp
    trunk/blender/source/blender/collada/ArmatureImporter.cpp
    trunk/blender/source/blender/collada/DocumentImporter.cpp
    trunk/blender/source/blender/collada/MeshImporter.cpp
    trunk/blender/source/blender/collada/SkinInfo.cpp
    trunk/blender/source/blender/collada/collada_internal.cpp

Modified: trunk/blender/source/blender/collada/AnimationImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/AnimationImporter.cpp  2011-06-20 
10:50:17 UTC (rev 37663)
+++ trunk/blender/source/blender/collada/AnimationImporter.cpp  2011-06-20 
12:43:10 UTC (rev 37664)
@@ -53,12 +53,12 @@
 
 #include <algorithm>
 
-// use this for retrieving bone names, since these must be unique
+// first try node name, if not available (since is optional), fall back to 
original id
 template<class T>
 static const char *bc_get_joint_name(T *node)
 {
-       const std::string& id = node->getOriginalId();
-       return id.size() ? id.c_str() : node->getName().c_str();
+       const std::string& id = node->getName();
+       return id.size() ? id.c_str() : node->getOriginalId().c_str();
 }
 
 FCurve *AnimationImporter::create_fcurve(int array_index, const char *rna_path)
@@ -827,7 +827,8 @@
 
                unit_m4(m);
 
-               if (!evaluate_animation(tm, m, fra, 
node->getOriginalId().c_str())) {
+               std::string nodename = node->getName().size() ? node->getName() 
: node->getOriginalId();
+               if (!evaluate_animation(tm, m, fra, nodename.c_str())) {
                        switch (type) {
                        case COLLADAFW::Transformation::ROTATE:
                                dae_rotate_to_mat4(tm, m);

Modified: trunk/blender/source/blender/collada/ArmatureImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/ArmatureImporter.cpp   2011-06-20 
10:50:17 UTC (rev 37663)
+++ trunk/blender/source/blender/collada/ArmatureImporter.cpp   2011-06-20 
12:43:10 UTC (rev 37664)
@@ -42,12 +42,12 @@
 
 #include "ArmatureImporter.h"
 
-// use this for retrieving bone names, since these must be unique
+// use node name, or fall back to original id if not present (name is optional)
 template<class T>
 static const char *bc_get_joint_name(T *node)
 {
-       const std::string& id = node->getOriginalId();
-       return id.size() ? id.c_str() : node->getName().c_str();
+       const std::string& id = node->getName();
+       return id.size() ? id.c_str() : node->getOriginalId().c_str();
 }
 
 ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase 
*mesh, AnimationImporterBase *anim, Scene *sce) :

Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp   2011-06-20 
10:50:17 UTC (rev 37663)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp   2011-06-20 
12:43:10 UTC (rev 37664)
@@ -441,7 +441,8 @@
                // check if object is not NULL
                if (!ob) return;
                
-               rename_id(&ob->id, (char*)node->getOriginalId().c_str());
+               std::string nodename = node->getName().size() ? node->getName() 
: node->getOriginalId();
+               rename_id(&ob->id, (char*)nodename.c_str());
 
                object_map[node->getUniqueId()] = ob;
                node_map[node->getUniqueId()] = node;
@@ -523,7 +524,7 @@
        if(mImportStage!=General)
                return true;
                
-       const std::string& str_mat_id = cmat->getOriginalId();
+       const std::string& str_mat_id = cmat->getName().size() ? 
cmat->getName() : cmat->getOriginalId();
        Material *ma = add_material((char*)str_mat_id.c_str());
        
        this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;

Modified: trunk/blender/source/blender/collada/MeshImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/MeshImporter.cpp       2011-06-20 
10:50:17 UTC (rev 37663)
+++ trunk/blender/source/blender/collada/MeshImporter.cpp       2011-06-20 
12:43:10 UTC (rev 37664)
@@ -62,7 +62,7 @@
 #include "MeshImporter.h"
 #include "collada_utils.h"
 
-// works for COLLADAFW::Node, COLLADAFW::Geometry
+// get node name, or fall back to original id if not present (name is optional)
 template<class T>
 static const char *bc_get_dae_name(T *node)
 {
@@ -835,7 +835,6 @@
        if (*color_texture &&
                strlen((*color_texture)->uvname) &&
                strcmp(layername, (*color_texture)->uvname) != 0) {
-               
                texture_face = (MTFace*)CustomData_get_layer_named(&me->fdata, 
CD_MTFACE,
                                                                                
                                   (*color_texture)->uvname);
                strcpy(layername, (*color_texture)->uvname);
@@ -905,7 +904,7 @@
        uid_object_map[*geom_uid] = ob;
        
        // name Object
-       const std::string& id = node->getOriginalId();
+       const std::string& id = node->getName().size() ? node->getName() : 
node->getOriginalId();
        if (id.length())
                rename_id(&ob->id, (char*)id.c_str());
        
@@ -917,6 +916,7 @@
        if (old_mesh->id.us == 0) free_libblock(&G.main->mesh, old_mesh);
        
        char layername[100];
+       layername[0] = '\0';
        MTFace *texture_face = NULL;
        MTex *color_texture = NULL;
        
@@ -959,7 +959,7 @@
                return true;
        }
        
-       const std::string& str_geom_id = mesh->getOriginalId();
+       const std::string& str_geom_id = mesh->getName().size() ? 
mesh->getName() : mesh->getOriginalId();
        Mesh *me = add_mesh((char*)str_geom_id.c_str());
 
        // store the Mesh pointer to link it later with an Object

Modified: trunk/blender/source/blender/collada/SkinInfo.cpp
===================================================================
--- trunk/blender/source/blender/collada/SkinInfo.cpp   2011-06-20 10:50:17 UTC 
(rev 37663)
+++ trunk/blender/source/blender/collada/SkinInfo.cpp   2011-06-20 12:43:10 UTC 
(rev 37664)
@@ -48,12 +48,12 @@
 #include "SkinInfo.h"
 #include "collada_utils.h"
 
-// use this for retrieving bone names, since these must be unique
+// use name, or fall back to original id if name not present (name is optional)
 template<class T>
 static const char *bc_get_joint_name(T *node)
 {
-       const std::string& id = node->getOriginalId();
-       return id.size() ? id.c_str() : node->getName().c_str();
+       const std::string& id = node->getName();
+       return id.size() ? id.c_str() : node->getOriginalId().c_str();
 }
 
 // This is used to store data passed in write_controller_data.

Modified: trunk/blender/source/blender/collada/collada_internal.cpp
===================================================================
--- trunk/blender/source/blender/collada/collada_internal.cpp   2011-06-20 
10:50:17 UTC (rev 37663)
+++ trunk/blender/source/blender/collada/collada_internal.cpp   2011-06-20 
12:43:10 UTC (rev 37664)
@@ -265,7 +265,7 @@
 
 std::string get_joint_id(Bone *bone, Object *ob_arm)
 {
-       return translate_id(id_name(ob_arm) + "_" + bone->name);
+       return translate_id(bone->name);
 }
 
 std::string get_camera_id(Object *ob)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to