fix #34284 Collada: update problem for vertex weights directly after import.

This commit is contained in:
Gaia Clary 2013-02-17 18:33:10 +00:00
parent 85b6bbe6cd
commit ee64cbaf39
2 changed files with 58 additions and 36 deletions

@ -415,10 +415,23 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
break; 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); ob_arm = skin.set_armature(shared);
else }
else {
ob_arm = skin.create_armature(scene); //once for every armature ob_arm = skin.create_armature(scene); //once for every armature
}
// enter armature edit mode // enter armature edit mode
ED_armature_to_edit(ob_arm); 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 //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()); Object *source_ob = this->mesh_importer->get_object_by_geom_uid((*mc)->getSource());
Mesh *source_me = (Mesh*) source_ob->data; if (source_ob) {
//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);
//insert other shape keys Mesh *source_me = (Mesh*) source_ob->data;
for (int i = 0 ; i < morphTargetIds.getCount() ; i++ ) { //insert key to source mesh
//better to have a seperate map of morph objects, Key *key = source_me->key = BKE_key_add((ID *)source_me);
//This'll do for now since only mesh morphing is imported key->type = KEY_RELATIVE;
KeyBlock *kb;
Mesh *me = this->mesh_importer->get_mesh_by_geom_uid(morphTargetIds[i]);
if (me) { //insert basis key
me->key = key; kb = BKE_keyblock_add_ctime(key, "Basis", FALSE);
std::string morph_name = *this->mesh_importer->get_geometry_name(me->id.name); BKE_key_convert_from_mesh(source_me, kb);
kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), FALSE); //insert other shape keys
BKE_key_convert_from_mesh(me, kb); 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]);
//apply weights if (me) {
weight = morphWeights.getFloatValues()->getData()[i]; me->key = key;
kb->curval = weight; std::string morph_name = *this->mesh_importer->get_geometry_name(me->id.name);
}
else { kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), FALSE);
fprintf(stderr, "Morph target geometry not found.\n"); 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");
}
} }
} }

@ -180,14 +180,16 @@ void DocumentImporter::finish()
{ {
if (mImportStage != General) if (mImportStage != General)
return; 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 */ /** TODO Break up and put into 2-pass parsing of DAE */
std::vector<const COLLADAFW::VisualScene *>::iterator it; std::vector<const COLLADAFW::VisualScene *>::iterator it;
for (it = vscenes.begin(); it != vscenes.end(); it++) { for (it = vscenes.begin(); it != vscenes.end(); it++) {
PointerRNA sceneptr, unit_settings; PointerRNA sceneptr, unit_settings;
PropertyRNA *system, *scale; 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 // for scene unit settings: system, scale_length
@ -228,7 +230,6 @@ void DocumentImporter::finish()
} }
// update scene // update scene
Main *bmain = CTX_data_main(mContext);
DAG_scene_sort(bmain, sce); DAG_scene_sort(bmain, sce);
DAG_ids_flush_update(bmain, 0); DAG_ids_flush_update(bmain, 0);
WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL); 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.set_tags_map(this->uid_tags_map);
armature_importer.make_armatures(mContext); armature_importer.make_armatures(mContext);
armature_importer.make_shape_keys(); armature_importer.make_shape_keys();
DAG_scene_sort(bmain, sce);
DAG_ids_flush_update(bmain, 0);
#if 0 #if 0
armature_importer.fix_animation(); armature_importer.fix_animation();
@ -273,8 +276,8 @@ void DocumentImporter::finish()
} }
libnode_ob.clear(); libnode_ob.clear();
DAG_scene_sort(CTX_data_main(mContext), sce); DAG_scene_sort(bmain, sce);
DAG_ids_flush_update(CTX_data_main(mContext), 0); 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) { 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. //Check if Object is armature, by checking if immediate child is a JOINT node.
if (is_armature(node)) { if (is_armature(node)) {
ob = bc_add_object(sce, OB_ARMATURE, NULL); ob = bc_add_object(sce, OB_ARMATURE, name.c_str());
} }
else { else {
ob = bc_add_object(sce, OB_EMPTY, NULL); ob = bc_add_object(sce, OB_EMPTY, NULL);
} }
objects_done->push_back(ob); objects_done->push_back(ob);
} }
// XXX: if there're multiple instances, only one is stored // XXX: if there're multiple instances, only one is stored