From d27863733710ab23749b21755be245bc7a303f12 Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Mon, 20 Jun 2011 12:43:10 +0000 Subject: 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. --- source/blender/collada/AnimationImporter.cpp | 9 +++++---- source/blender/collada/ArmatureImporter.cpp | 6 +++--- source/blender/collada/DocumentImporter.cpp | 5 +++-- source/blender/collada/MeshImporter.cpp | 8 ++++---- source/blender/collada/SkinInfo.cpp | 6 +++--- source/blender/collada/collada_internal.cpp | 2 +- 6 files changed, 19 insertions(+), 17 deletions(-) (limited to 'source') diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp index a166324bde7..336f127b11f 100644 --- a/source/blender/collada/AnimationImporter.cpp +++ b/source/blender/collada/AnimationImporter.cpp @@ -53,12 +53,12 @@ #include -// 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 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 @@ void AnimationImporter::evaluate_transform_at_frame(float mat[4][4], COLLADAFW:: 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); diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index 8987e4ffaf7..8b8e89fd4f5 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -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 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) : diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 0502102f7c4..78ee444bb4e 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -441,7 +441,8 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren // 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 @@ bool DocumentImporter::writeMaterial( const COLLADAFW::Material* cmat ) 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; diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index 806be14d0ed..d1977d15fb2 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -62,7 +62,7 @@ extern "C" { #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 static const char *bc_get_dae_name(T *node) { @@ -835,7 +835,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri 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 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta 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 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta 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 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom) 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 diff --git a/source/blender/collada/SkinInfo.cpp b/source/blender/collada/SkinInfo.cpp index 10780de2e70..83b9449c8f2 100644 --- a/source/blender/collada/SkinInfo.cpp +++ b/source/blender/collada/SkinInfo.cpp @@ -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 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. diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp index 4f4d16d3b0d..9cb6a227fc9 100644 --- a/source/blender/collada/collada_internal.cpp +++ b/source/blender/collada/collada_internal.cpp @@ -265,7 +265,7 @@ std::string get_light_id(Object *ob) 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) -- cgit v1.2.3