diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/collada/ArmatureImporter.cpp | 75 | ||||
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 19 |
2 files changed, 58 insertions, 36 deletions
diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index fefad7dd8ec..c270a1e6b20 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -415,10 +415,23 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin) break; } - if (shared) + if (!shared && this->joint_parent_map.size() > 0) { + // All armatures have been created while creating the Node tree. + // The Collada exporter currently does not create a + // strict relationship between geometries and armatures + // So when we reimport a Blender collada file, then we have + // to guess what is meant. + // XXX This is not safe when we have more than one armatures + // in the import. + shared = this->joint_parent_map.begin()->second; + } + + if (shared) { ob_arm = skin.set_armature(shared); - else + } + else { ob_arm = skin.create_armature(scene); //once for every armature + } // enter armature edit mode ED_armature_to_edit(ob_arm); @@ -659,38 +672,44 @@ void ArmatureImporter::make_shape_keys() //Prereq: all the geometries must be imported and mesh objects must be made Object *source_ob = this->mesh_importer->get_object_by_geom_uid((*mc)->getSource()); - Mesh *source_me = (Mesh*) source_ob->data; - //insert key to source mesh - Key *key = source_me->key = BKE_key_add((ID *)source_me); - key->type = KEY_RELATIVE; - KeyBlock *kb; - - //insert basis key - kb = BKE_keyblock_add_ctime(key, "Basis", FALSE); - BKE_key_convert_from_mesh(source_me, kb); + if (source_ob) { - //insert other shape keys - for (int i = 0 ; i < morphTargetIds.getCount() ; i++ ) { - //better to have a seperate map of morph objects, - //This'll do for now since only mesh morphing is imported - - Mesh *me = this->mesh_importer->get_mesh_by_geom_uid(morphTargetIds[i]); + Mesh *source_me = (Mesh*) source_ob->data; + //insert key to source mesh + Key *key = source_me->key = BKE_key_add((ID *)source_me); + key->type = KEY_RELATIVE; + KeyBlock *kb; - if (me) { - me->key = key; - std::string morph_name = *this->mesh_importer->get_geometry_name(me->id.name); + //insert basis key + kb = BKE_keyblock_add_ctime(key, "Basis", FALSE); + BKE_key_convert_from_mesh(source_me, kb); + + //insert other shape keys + for (int i = 0 ; i < morphTargetIds.getCount() ; i++ ) { + //better to have a seperate map of morph objects, + //This'll do for now since only mesh morphing is imported - kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), FALSE); - BKE_key_convert_from_mesh(me, kb); + Mesh *me = this->mesh_importer->get_mesh_by_geom_uid(morphTargetIds[i]); - //apply weights - weight = morphWeights.getFloatValues()->getData()[i]; - kb->curval = weight; - } - else { - fprintf(stderr, "Morph target geometry not found.\n"); + if (me) { + me->key = key; + std::string morph_name = *this->mesh_importer->get_geometry_name(me->id.name); + + kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), FALSE); + BKE_key_convert_from_mesh(me, kb); + + //apply weights + weight = morphWeights.getFloatValues()->getData()[i]; + kb->curval = weight; + } + else { + fprintf(stderr, "Morph target geometry not found.\n"); + } } } + else { + fprintf(stderr, "Morph target object not found.\n"); + } } } diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 8af4d0652d9..b1103d78394 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -180,14 +180,16 @@ void DocumentImporter::finish() { if (mImportStage != General) return; - + + Main *bmain = CTX_data_main(mContext); + // TODO: create a new scene except the selected <visual_scene> - use current blender scene for it + Scene *sce = CTX_data_scene(mContext); + /** TODO Break up and put into 2-pass parsing of DAE */ std::vector<const COLLADAFW::VisualScene *>::iterator it; for (it = vscenes.begin(); it != vscenes.end(); it++) { PointerRNA sceneptr, unit_settings; PropertyRNA *system, *scale; - // TODO: create a new scene except the selected <visual_scene> - use current blender scene for it - Scene *sce = CTX_data_scene(mContext); // for scene unit settings: system, scale_length @@ -228,7 +230,6 @@ void DocumentImporter::finish() } // update scene - Main *bmain = CTX_data_main(mContext); DAG_scene_sort(bmain, sce); DAG_ids_flush_update(bmain, 0); WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL); @@ -241,6 +242,8 @@ void DocumentImporter::finish() armature_importer.set_tags_map(this->uid_tags_map); armature_importer.make_armatures(mContext); armature_importer.make_shape_keys(); + DAG_scene_sort(bmain, sce); + DAG_ids_flush_update(bmain, 0); #if 0 armature_importer.fix_animation(); @@ -273,8 +276,8 @@ void DocumentImporter::finish() } libnode_ob.clear(); - DAG_scene_sort(CTX_data_main(mContext), sce); - DAG_ids_flush_update(CTX_data_main(mContext), 0); + DAG_scene_sort(bmain, sce); + DAG_ids_flush_update(bmain, 0); } } @@ -541,13 +544,13 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) { //Check if Object is armature, by checking if immediate child is a JOINT node. if (is_armature(node)) { - ob = bc_add_object(sce, OB_ARMATURE, NULL); + ob = bc_add_object(sce, OB_ARMATURE, name.c_str()); } else { ob = bc_add_object(sce, OB_EMPTY, NULL); } - objects_done->push_back(ob); + } // XXX: if there're multiple instances, only one is stored |