Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com>2012-08-17 22:01:09 +0400
committerSukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com>2012-08-17 22:01:09 +0400
commit74f0263a1f2a3d936ed74200bd1bd6187d607848 (patch)
tree7b6603429fa0175ce5e6d9c48a32b44dbc7ed946 /source/blender/collada
parent43a2baa93591f62aa80274e772218b4ff348ed1d (diff)
[COLLADA]Mesh Controller improvements
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/ArmatureImporter.cpp59
-rw-r--r--source/blender/collada/ArmatureImporter.h3
-rw-r--r--source/blender/collada/ControllerExporter.cpp19
-rw-r--r--source/blender/collada/ControllerExporter.h3
-rw-r--r--source/blender/collada/DocumentImporter.cpp1
-rw-r--r--source/blender/collada/GeometryExporter.cpp2
-rw-r--r--source/blender/collada/MeshImporter.cpp7
-rw-r--r--source/blender/collada/MeshImporter.h3
8 files changed, 66 insertions, 31 deletions
diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp
index ad4e9b70e2b..e2402cf8184 100644
--- a/source/blender/collada/ArmatureImporter.cpp
+++ b/source/blender/collada/ArmatureImporter.cpp
@@ -633,12 +633,12 @@ bool ArmatureImporter::write_controller(const COLLADAFW::Controller *controller)
{
// - create and store armature object
- const COLLADAFW::UniqueId& skin_id = controller->getUniqueId();
+ const COLLADAFW::UniqueId& con_id = controller->getUniqueId();
if (controller->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_SKIN) {
COLLADAFW::SkinController *co = (COLLADAFW::SkinController *)controller;
// to be able to find geom id by controller id
- geom_uid_by_controller_uid[skin_id] = co->getSource();
+ geom_uid_by_controller_uid[con_id] = co->getSource();
const COLLADAFW::UniqueId& data_uid = co->getSkinControllerData();
if (skin_by_data_uid.find(data_uid) == skin_by_data_uid.end()) {
@@ -652,47 +652,48 @@ bool ArmatureImporter::write_controller(const COLLADAFW::Controller *controller)
else if (controller->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_MORPH) {
COLLADAFW::MorphController *co = (COLLADAFW::MorphController *)controller;
// to be able to find geom id by controller id
- geom_uid_by_controller_uid[skin_id] = co->getSource();
+ geom_uid_by_controller_uid[con_id] = co->getSource();
+ morph_controllers.push_back(co);
+// fprintf(stderr, "Morph controller is not supported yet.\n");
+ }
- COLLADAFW::UniqueIdArray& morphTargetIds = co->getMorphTargets();
- COLLADAFW::FloatOrDoubleArray& morphWeights = co->getMorphWeights();
+ return true;
+}
+
+void ArmatureImporter::make_shape_keys(){
+ std::vector<COLLADAFW::MorphController *>::iterator mc;
+
+ for (mc = morph_controllers.begin(); mc != morph_controllers.end(); mc++) {
+ COLLADAFW::UniqueIdArray& morphTargetIds = (*mc)->getMorphTargets();
+ COLLADAFW::FloatOrDoubleArray& morphWeights = (*mc)->getMorphWeights();
//Prereq: all the geometries must be imported and mesh objects must be made
- Object *source_ob = this->mesh_importer->get_object_by_geom_uid(co->getSource());
+ Object *source_ob = this->mesh_importer->get_object_by_geom_uid((*mc)->getSource());
Mesh *source_me = (Mesh*) source_ob->data;
- float *weight;
-
+ float weight;
+ Key *key = source_me->key = add_key((ID *)source_me);
+ key->type = KEY_RELATIVE;
+ KeyBlock *kb;
+ kb = add_keyblock_ctime(key, "Basis", FALSE);
+ mesh_to_key(source_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
- Object *ob = this->mesh_importer->get_object_by_geom_uid(morphTargetIds[i]);
- if(ob){
- Mesh *me = (Mesh*)ob->data;
- Key *key = ob_get_key(source_ob);
- KeyBlock *kb;
- int newkey = 0;
-
- if (key == NULL) {
- key = source_me->key = add_key((ID *)me);
- key->type = KEY_RELATIVE;
- newkey = 1;
- }
-
- kb = add_keyblock_ctime(key, morphTargetIds[i].toAscii().c_str(), FALSE);
+ Mesh *me = this->mesh_importer->get_mesh_by_geom_uid(morphTargetIds[i]);
+ if(me){
+ me->key = key;
+ kb = add_keyblock_ctime(key, me->id.name, FALSE);
mesh_to_key(me, kb);
- weight = morphWeights.getFloatValues()[i].getData();
- kb->curval = *weight;
+ weight = morphWeights.getFloatValues()->getData()[i];
+ kb->curval = weight;
//free object since it is added as shape key
- BKE_object_free(ob);
+ //BKE_object_free(ob);
}
else
fprintf(stderr, "Morph target geometry not found.\n");
- }
-// fprintf(stderr, "Morph controller is not supported yet.\n");
+ }
}
-
- return true;
}
diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h
index f6f2f53d18b..519ad4ac1c8 100644
--- a/source/blender/collada/ArmatureImporter.h
+++ b/source/blender/collada/ArmatureImporter.h
@@ -91,6 +91,7 @@ private:
std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> joint_by_uid; // contains all joints
std::vector<COLLADAFW::Node*> root_joints;
std::vector<COLLADAFW::Node*> finished_joints;
+ std::vector<COLLADAFW::MorphController*> morph_controllers;
std::map<COLLADAFW::UniqueId, Object*> joint_parent_map;
std::map<COLLADAFW::UniqueId, Object*> unskinned_armature_map;
@@ -152,6 +153,8 @@ public:
// here we add bones to armatures, having armatures previously created in write_controller
void make_armatures(bContext *C);
+ void make_shape_keys();
+
#if 0
// link with meshes, create vertex groups, assign weights
void link_armature(Object *ob_arm, const COLLADAFW::UniqueId& geom_id, const COLLADAFW::UniqueId& controller_data_id);
diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp
index f004676f799..3ce93140177 100644
--- a/source/blender/collada/ControllerExporter.cpp
+++ b/source/blender/collada/ControllerExporter.cpp
@@ -323,6 +323,9 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key)
{
BKE_libblock_free_us(&(G.main->mesh), me);
}
+
+ // can also try the base element and param alternative
+ add_weight_extras(key);
closeMorph();
closeController();
}
@@ -346,7 +349,7 @@ std::string ControllerExporter::add_morph_targets(Key *key, Object *ob)
//skip the basis
kb = kb->next;
for (; kb; kb = kb->next) {
- std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(id_name(kb));
+ std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(kb->name);
source.appendValues(geom_id);
}
@@ -383,6 +386,20 @@ std::string ControllerExporter::add_morph_weights(Key *key, Object *ob)
return source_id;
}
+//Added to implemente support for animations.
+void ControllerExporter::add_weight_extras(Key *key){
+ // can also try the base element and param alternative
+ COLLADASW::BaseExtraTechnique extra;
+
+ KeyBlock * kb = (KeyBlock*)key->block.first;
+ //skip the basis
+ kb = kb->next;
+ for (; kb; kb = kb->next) {
+ float weight = kb->curval;
+ extra.addExtraTechniqueParameter ("KHR", "morph_weights" , 0.000, "MORPH_WEIGHT_TO_TARGET");
+ }
+}
+
void ControllerExporter::add_joints_element(ListBase *defbase,
diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h
index 219f7409acf..7777031c6f0 100644
--- a/source/blender/collada/ControllerExporter.h
+++ b/source/blender/collada/ControllerExporter.h
@@ -36,6 +36,7 @@
#include "COLLADASWLibraryControllers.h"
#include "COLLADASWInputList.h"
#include "COLLADASWNode.h"
+#include "COLLADASWExtraTechnique.h"
#include "DNA_armature_types.h"
#include "DNA_listBase.h"
@@ -106,6 +107,8 @@ private:
std::string add_morph_weights(Key *key, Object *ob);
+ void add_weight_extras(Key *key);
+
std::string add_joints_source(Object *ob_arm, ListBase *defbase, const std::string& controller_id);
std::string add_inv_bind_mats_source(Object *ob_arm, ListBase *defbase, const std::string& controller_id);
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index a4d027f45b1..f7c835c6ce5 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -210,6 +210,7 @@ void DocumentImporter::finish()
}
armature_importer.set_tags_map(this->uid_tags_map);
armature_importer.make_armatures(mContext);
+ armature_importer.make_shape_keys();
#if 0
armature_importer.fix_animation();
diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp
index 078b4db312b..21c1b56d7b3 100644
--- a/source/blender/collada/GeometryExporter.cpp
+++ b/source/blender/collada/GeometryExporter.cpp
@@ -172,7 +172,7 @@ void GeometryExporter::operator()(Object *ob)
}
void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb){
- std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(id_name(kb));
+ std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(kb->name);
std::vector<Normal> nor;
std::vector<Face> norind;
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index ded937bf8f3..72926c050bb 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -945,6 +945,13 @@ Object *MeshImporter::get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid
return NULL;
}
+Mesh *MeshImporter::get_mesh_by_geom_uid(const COLLADAFW::UniqueId& mesh_uid)
+{
+ if (uid_mesh_map.find(mesh_uid) != uid_mesh_map.end())
+ return uid_mesh_map[mesh_uid];
+ return NULL;
+}
+
MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture,
Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map,
MTex *color_texture)
diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h
index e4c1aca395a..b420ef2d664 100644
--- a/source/blender/collada/MeshImporter.h
+++ b/source/blender/collada/MeshImporter.h
@@ -59,6 +59,7 @@ class MeshImporterBase
{
public:
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid) = 0;
+ virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId& mesh_uid) = 0;
};
class UVDataWrapper
@@ -148,6 +149,8 @@ public:
void bmeshConversion();
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
+
+ virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
MTex *assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture,
Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map,