[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49961] branches/soc-2012-bratwurst/source /blender/collada: [COLLADA]Mesh Controller improvements
Sukhitha Jayathilake
pr.jayathilake at gmail.com
Fri Aug 17 20:01:09 CEST 2012
Revision: 49961
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49961
Author: phabtar
Date: 2012-08-17 18:01:09 +0000 (Fri, 17 Aug 2012)
Log Message:
-----------
[COLLADA]Mesh Controller improvements
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h
branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.cpp
branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.h
branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp
branches/soc-2012-bratwurst/source/blender/collada/GeometryExporter.cpp
branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.cpp
branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.h
Modified: branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp 2012-08-17 18:01:09 UTC (rev 49961)
@@ -633,12 +633,12 @@
{
// - 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 @@
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;
}
Modified: branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.h 2012-08-17 18:01:09 UTC (rev 49961)
@@ -91,6 +91,7 @@
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 @@
// 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);
Modified: branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.cpp 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.cpp 2012-08-17 18:01:09 UTC (rev 49961)
@@ -323,6 +323,9 @@
{
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 @@
//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,8 +386,22 @@
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,
const std::string& joints_source_id, const std::string& inv_bind_mat_source_id)
{
Modified: branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.h 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/ControllerExporter.h 2012-08-17 18:01:09 UTC (rev 49961)
@@ -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 @@
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);
Modified: branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp 2012-08-17 18:01:09 UTC (rev 49961)
@@ -210,6 +210,7 @@
}
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();
Modified: branches/soc-2012-bratwurst/source/blender/collada/GeometryExporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/GeometryExporter.cpp 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/GeometryExporter.cpp 2012-08-17 18:01:09 UTC (rev 49961)
@@ -172,7 +172,7 @@
}
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;
Modified: branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.cpp 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.cpp 2012-08-17 18:01:09 UTC (rev 49961)
@@ -945,6 +945,13 @@
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)
Modified: branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.h 2012-08-17 17:52:26 UTC (rev 49960)
+++ branches/soc-2012-bratwurst/source/blender/collada/MeshImporter.h 2012-08-17 18:01:09 UTC (rev 49961)
@@ -59,6 +59,7 @@
{
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 @@
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,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list