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;
}
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);
kb = BKE_keyblock_add_ctime(key, morph_name.c_str(), FALSE);
BKE_key_convert_from_mesh(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
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");
}
}
}

@ -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