diff options
author | Sukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com> | 2012-08-19 22:36:02 +0400 |
---|---|---|
committer | Sukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com> | 2012-08-19 22:36:02 +0400 |
commit | fad0a9954eeedaf5cfedf8f239529c8eb4157715 (patch) | |
tree | c6ed633152f834cb9a62c279a5e982441ed39713 /source/blender/collada | |
parent | db15c047834fc85d7c55791b4105ff2ff9db574a (diff) |
Code cleanup
Diffstat (limited to 'source/blender/collada')
-rw-r--r-- | source/blender/collada/AnimationExporter.cpp | 9 | ||||
-rw-r--r-- | source/blender/collada/ArmatureExporter.cpp | 18 | ||||
-rw-r--r-- | source/blender/collada/ArmatureImporter.cpp | 42 | ||||
-rw-r--r-- | source/blender/collada/ArmatureImporter.h | 3 | ||||
-rw-r--r-- | source/blender/collada/ControllerExporter.cpp | 20 | ||||
-rw-r--r-- | source/blender/collada/ControllerExporter.h | 3 | ||||
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 5 |
7 files changed, 33 insertions, 67 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp index e4808796d7a..9e7660b0c29 100644 --- a/source/blender/collada/AnimationExporter.cpp +++ b/source/blender/collada/AnimationExporter.cpp @@ -242,13 +242,6 @@ float *AnimationExporter::get_eul_source_for_quat(Object *ob) } -//from Bake animation script -void AnimationExporter::getBakedPoseData(Object *obarm, int startFrame, int endFrame, bool ActionBake = false, bool ActionBakeFirstFrame = true) -{ - - -} - //Get proper name for bones std::string AnimationExporter::getObjectBoneName(Object *ob, const FCurve *fcu) { @@ -973,8 +966,6 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj calc_ob_mat_at_time(ob, ctime, mat); } - //BIK_release_tree(scene, ob, ctime); - UnitConverter converter; double outmat[4][4]; diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index 765b09c92d3..36993eae7b6 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -111,24 +111,10 @@ bool ArmatureExporter::add_instance_controller(Object *ob) return true; } -//void ArmatureExporter::export_controllers(Scene *sce) -//{ -// scene = sce; -// -// openLibrary(); -// -// GeometryFunctor gf; -// gf.forEachMeshObjectInExportSet<ArmatureExporter>(sce, *this, this->export_settings->export_set); -// -// closeLibrary(); -//} - void ArmatureExporter::operator()(Object *ob) { Object *ob_arm = bc_get_assigned_armature(ob); - //if (ob_arm /*&& !already_written(ob_arm)*/); -// export_controller(ob, ob_arm); } #if 0 @@ -279,9 +265,9 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW: } else { - //pose mat is object space - //copy_m4_m4(mat, pchan->pose_mat); + //copy_m4_m4(mat, pchan->pose_mat); + //pose mat is object space //New change: export bone->arm_mat copy_m4_m4(mat, bone->arm_mat); } diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp index e2402cf8184..d9b2a8d91ed 100644 --- a/source/blender/collada/ArmatureImporter.cpp +++ b/source/blender/collada/ArmatureImporter.cpp @@ -93,8 +93,7 @@ void ArmatureImporter::create_bone(SkinInfo* skin, COLLADAFW::Node *node, EditBo float mat[4][4]; float obmat[4][4]; - float bonemat[3][3]; - + // TODO rename from Node "name" attrs later EditBone *bone = ED_armature_edit_bone_add(arm, (char *)bc_get_joint_name(node)); totbone++; @@ -118,7 +117,6 @@ void ArmatureImporter::create_bone(SkinInfo* skin, COLLADAFW::Node *node, EditBo if (parent) bone->parent = parent; - ////mult_m4_m4m4(mat, ob_arm->obmat , mat); float loc[3], size[3], rot[3][3]; float angle; float vec[3] = {0.0f, 0.5f, 0.0f}; @@ -211,9 +209,7 @@ void ArmatureImporter::fix_leaf_bones( ) float vec[3] = {0.0f, 0.0f, 0.1f}; sub_v3_v3v3(vec, leaf.bone->tail , leaf.bone->head); - mul_v3_fl(vec, leaf_bone_length); - add_v3_v3v3(leaf.bone->tail, leaf.bone->head , vec); } @@ -338,7 +334,6 @@ void ArmatureImporter::create_armature_bones( ) fix_leaf_bones(); // exit armature edit mode - unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm; ED_armature_from_edit(ob_arm); @@ -434,7 +429,6 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin) totbone = 0; // bone_direction_row = 1; // TODO: don't default to Y but use asset and based on it decide on default row leaf_bone_length = FLT_MAX; - // min_angle = 360.0f; // minimum angle between bone head-tail and a row of bone matrix // create bones /* @@ -464,22 +458,14 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin) ED_armature_edit_free(ob_arm); DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA); - // set_leaf_bone_shapes(ob_arm); - // set_euler_rotmode(); } - -// root - if this joint is the top joint in hierarchy, if a joint -// is a child of a node (not joint), root should be true since -// this is where we build armature bones from - void ArmatureImporter::set_pose(Object *ob_arm, COLLADAFW::Node *root_node, const char *parentname, float parent_mat[][4]) { char *bone_name = (char *) bc_get_joint_name(root_node); float mat[4][4]; float obmat[4][4]; - float ax[3]; float angle = 0.0f; // object-space @@ -517,6 +503,10 @@ void ArmatureImporter::set_pose(Object *ob_arm, COLLADAFW::Node *root_node, con } + +// root - if this joint is the top joint in hierarchy, if a joint +// is a child of a node (not joint), root should be true since +// this is where we build armature bones from void ArmatureImporter::add_joint(COLLADAFW::Node *node, bool root, Object *parent, Scene *sce) { joint_by_uid[node->getUniqueId()] = node; @@ -632,7 +622,6 @@ bool ArmatureImporter::write_skin_controller_data(const COLLADAFW::SkinControlle bool ArmatureImporter::write_controller(const COLLADAFW::Controller *controller) { // - create and store armature object - const COLLADAFW::UniqueId& con_id = controller->getUniqueId(); if (controller->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_SKIN) { @@ -653,8 +642,8 @@ bool ArmatureImporter::write_controller(const COLLADAFW::Controller *controller) COLLADAFW::MorphController *co = (COLLADAFW::MorphController *)controller; // to be able to find geom id by controller id geom_uid_by_controller_uid[con_id] = co->getSource(); + //Shape keys are applied in DocumentImporter->finish() morph_controllers.push_back(co); -// fprintf(stderr, "Morph controller is not supported yet.\n"); } return true; @@ -662,33 +651,40 @@ bool ArmatureImporter::write_controller(const COLLADAFW::Controller *controller) void ArmatureImporter::make_shape_keys(){ std::vector<COLLADAFW::MorphController *>::iterator mc; - + float weight; + for (mc = morph_controllers.begin(); mc != morph_controllers.end(); mc++) { + //Controller data 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((*mc)->getSource()); + Mesh *source_me = (Mesh*) source_ob->data; - float weight; - Key *key = source_me->key = add_key((ID *)source_me); + //insert key to source mesh + Key *key = source_me->key = add_key((ID *)source_me); key->type = KEY_RELATIVE; KeyBlock *kb; + + //insert basis key kb = add_keyblock_ctime(key, "Basis", FALSE); mesh_to_key(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 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); + + //apply weights weight = morphWeights.getFloatValues()->getData()[i]; kb->curval = weight; - - //free object since it is added as shape key - //BKE_object_free(ob); } else fprintf(stderr, "Morph target geometry not found.\n"); diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h index 519ad4ac1c8..4171e8cc92b 100644 --- a/source/blender/collada/ArmatureImporter.h +++ b/source/blender/collada/ArmatureImporter.h @@ -141,9 +141,6 @@ public: ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, AnimationImporterBase *anim, Scene *sce); ~ArmatureImporter(); - // root - if this joint is the top joint in hierarchy, if a joint - // is a child of a node (not joint), root should be true since - // this is where we build armature bones from void add_joint(COLLADAFW::Node *node, bool root, Object *parent, Scene *sce); #if 0 diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp index 3ce93140177..9e0180e422b 100644 --- a/source/blender/collada/ControllerExporter.cpp +++ b/source/blender/collada/ControllerExporter.cpp @@ -120,7 +120,7 @@ void ControllerExporter::operator()(Object *ob) Object *ob_arm = bc_get_assigned_armature(ob); Key *key = ob_get_key(ob); - if (ob_arm /*&& !already_written(ob_arm)*/) + if (ob_arm) export_skin_controller(ob, ob_arm); if(key){ export_morph_controller(ob, key); @@ -200,12 +200,11 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm) bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; - if (this->export_settings->apply_modifiers) { + if (this->export_settings->apply_modifiers) me = bc_to_mesh_apply_modifiers(scene, ob, this->export_settings->export_mesh_type); - } - else { + else me = (Mesh *)ob->data; - } + BKE_mesh_tessface_ensure(me); if (!me->dvert) return; @@ -298,8 +297,6 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key) } BKE_mesh_tessface_ensure(me); - //if (!me->dvert) return; - std::string controller_name = id_name(ob) + "-morph"; std::string controller_id = get_controller_id(key, ob); @@ -324,7 +321,8 @@ 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 + //support for animations + //can also try the base element and param alternative add_weight_extras(key); closeMorph(); closeController(); @@ -346,7 +344,7 @@ std::string ControllerExporter::add_morph_targets(Key *key, Object *ob) source.prepareToAppendValues(); KeyBlock * kb = (KeyBlock*)key->block.first; - //skip the basis + //skip the basis kb = kb->next; for (; kb; kb = kb->next) { std::string geom_id = get_geometry_id(ob, false) + "_morph_" + translate_id(kb->name); @@ -375,7 +373,7 @@ std::string ControllerExporter::add_morph_weights(Key *key, Object *ob) source.prepareToAppendValues(); KeyBlock * kb = (KeyBlock*)key->block.first; - //skip the basis + //skip the basis kb = kb->next; for (; kb; kb = kb->next) { float weight = kb->curval; @@ -392,7 +390,7 @@ void ControllerExporter::add_weight_extras(Key *key){ COLLADASW::BaseExtraTechnique extra; KeyBlock * kb = (KeyBlock*)key->block.first; - //skip the basis + //skip the basis kb = kb->next; for (; kb; kb = kb->next) { float weight = kb->curval; diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h index 7777031c6f0..4355fb6c28f 100644 --- a/source/blender/collada/ControllerExporter.h +++ b/source/blender/collada/ControllerExporter.h @@ -55,9 +55,6 @@ class SceneExporter; -// XXX exporter writes wrong data for shared armatures. A separate -// controller should be written for each armature-mesh binding how do -// we make controller ids then? class ControllerExporter : public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter { public: diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 1b98d9d6353..77f97e54fc5 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -377,8 +377,8 @@ Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod anim_importer.read_node_transform(source_node, obn); } - DAG_scene_sort(CTX_data_main(mContext), sce); - DAG_ids_flush_update(CTX_data_main(mContext), 0); + /*DAG_scene_sort(CTX_data_main(mContext), sce); + DAG_ids_flush_update(CTX_data_main(mContext), 0);*/ COLLADAFW::NodePointerArray &children = source_node->getChildNodes(); if (children.getCount()) { @@ -495,6 +495,7 @@ void DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent read_transform = false; } + // if node is empty - create empty object // XXX empty node may not mean it is empty object, not sure about this if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) { |