diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /source/blender/collada/ArmatureExporter.cpp | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'source/blender/collada/ArmatureExporter.cpp')
-rw-r--r-- | source/blender/collada/ArmatureExporter.cpp | 389 |
1 files changed, 194 insertions, 195 deletions
diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp index de4c4794547..ea1e98caf58 100644 --- a/source/blender/collada/ArmatureExporter.cpp +++ b/source/blender/collada/ArmatureExporter.cpp @@ -18,7 +18,6 @@ * \ingroup collada */ - #include "COLLADASWBaseInputElement.h" #include "COLLADASWInstanceController.h" #include "COLLADASWPrimitves.h" @@ -47,263 +46,263 @@ extern "C" { #include "collada_utils.h" // write bone nodes -void ArmatureExporter::add_armature_bones( - Object *ob_arm, - ViewLayer *view_layer, - SceneExporter *se, - std::vector<Object *>& child_objects) +void ArmatureExporter::add_armature_bones(Object *ob_arm, + ViewLayer *view_layer, + SceneExporter *se, + std::vector<Object *> &child_objects) { - // write bone nodes + // write bone nodes - bArmature *armature = (bArmature *)ob_arm->data; - bool is_edited = armature->edbo != NULL; + bArmature *armature = (bArmature *)ob_arm->data; + bool is_edited = armature->edbo != NULL; - if (!is_edited) { - ED_armature_to_edit(armature); - } + if (!is_edited) { + ED_armature_to_edit(armature); + } - for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { - // start from root bones - if (!bone->parent) { - add_bone_node(bone, ob_arm, se, child_objects); - } - } + for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { + // start from root bones + if (!bone->parent) { + add_bone_node(bone, ob_arm, se, child_objects); + } + } - if (!is_edited) { - ED_armature_edit_free(armature); - } + if (!is_edited) { + ED_armature_edit_free(armature); + } } -void ArmatureExporter::write_bone_URLs(COLLADASW::InstanceController &ins, Object *ob_arm, Bone *bone) +void ArmatureExporter::write_bone_URLs(COLLADASW::InstanceController &ins, + Object *ob_arm, + Bone *bone) { - if (bc_is_root_bone(bone, this->export_settings->deform_bones_only)) { - std::string joint_id = translate_id(id_name(ob_arm) + "_" + bone->name); - ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id)); - } - else { - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - write_bone_URLs(ins, ob_arm, child); - } - } + if (bc_is_root_bone(bone, this->export_settings->deform_bones_only)) { + std::string joint_id = translate_id(id_name(ob_arm) + "_" + bone->name); + ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id)); + } + else { + for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + write_bone_URLs(ins, ob_arm, child); + } + } } bool ArmatureExporter::add_instance_controller(Object *ob) { - Object *ob_arm = bc_get_assigned_armature(ob); - bArmature *arm = (bArmature *)ob_arm->data; + Object *ob_arm = bc_get_assigned_armature(ob); + bArmature *arm = (bArmature *)ob_arm->data; - const std::string& controller_id = get_controller_id(ob_arm, ob); + const std::string &controller_id = get_controller_id(ob_arm, ob); - COLLADASW::InstanceController ins(mSW); - ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id)); + COLLADASW::InstanceController ins(mSW); + ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id)); - Mesh *me = (Mesh *)ob->data; - if (!me->dvert) return false; + Mesh *me = (Mesh *)ob->data; + if (!me->dvert) + return false; - // write root bone URLs - Bone *bone; - for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) { - write_bone_URLs(ins, ob_arm, bone); - } + // write root bone URLs + Bone *bone; + for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) { + write_bone_URLs(ins, ob_arm, bone); + } - InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only); + InstanceWriter::add_material_bindings( + ins.getBindMaterial(), ob, this->export_settings->active_uv_only); - ins.add(); - return true; + ins.add(); + return true; } #if 0 void ArmatureExporter::operator()(Object *ob) { - Object *ob_arm = bc_get_assigned_armature(ob); + Object *ob_arm = bc_get_assigned_armature(ob); } bool ArmatureExporter::already_written(Object *ob_arm) { - return std::find(written_armatures.begin(), written_armatures.end(), ob_arm) != written_armatures.end(); + return std::find(written_armatures.begin(), written_armatures.end(), ob_arm) != written_armatures.end(); } void ArmatureExporter::wrote(Object *ob_arm) { - written_armatures.push_back(ob_arm); + written_armatures.push_back(ob_arm); } void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<Object *>& objects, Scene *sce) { - objects.clear(); + objects.clear(); - Base *base = (Base *) sce->base.first; - while (base) { - Object *ob = base->object; + Base *base = (Base *) sce->base.first; + while (base) { + Object *ob = base->object; - if (ob->type == OB_MESH && get_assigned_armature(ob) == ob_arm) { - objects.push_back(ob); - } + if (ob->type == OB_MESH && get_assigned_armature(ob) == ob_arm) { + objects.push_back(ob); + } - base = base->next; - } + base = base->next; + } } #endif // parent_mat is armature-space -void ArmatureExporter::add_bone_node( - Bone *bone, - Object *ob_arm, - SceneExporter *se, - std::vector<Object *>& child_objects) +void ArmatureExporter::add_bone_node(Bone *bone, + Object *ob_arm, + SceneExporter *se, + std::vector<Object *> &child_objects) { - if (!(this->export_settings->deform_bones_only && bone->flag & BONE_NO_DEFORM)) { - std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name); - std::string node_name = std::string(bone->name); - std::string node_sid = get_joint_sid(bone); - - COLLADASW::Node node(mSW); - - node.setType(COLLADASW::Node::JOINT); - node.setNodeId(node_id); - node.setNodeName(node_name); - node.setNodeSid(node_sid); - - if (this->export_settings->use_blender_profile) - { - if (bone->parent) { - if (bone->flag & BONE_CONNECTED) { - node.addExtraTechniqueParameter("blender", "connect", true); - } - } - std::string layers = BoneExtended::get_bone_layers(bone->layer); - node.addExtraTechniqueParameter("blender", "layer", layers); - - bArmature *armature = (bArmature *)ob_arm->data; - EditBone *ebone = bc_get_edit_bone(armature, bone->name); - if (ebone && ebone->roll != 0) - { - node.addExtraTechniqueParameter("blender", "roll", ebone->roll); - } - if (bc_is_leaf_bone(bone)) - { - node.addExtraTechniqueParameter("blender", "tip_x", bone->arm_tail[0] - bone->arm_head[0]); - node.addExtraTechniqueParameter("blender", "tip_y", bone->arm_tail[1] - bone->arm_head[1]); - node.addExtraTechniqueParameter("blender", "tip_z", bone->arm_tail[2] - bone->arm_head[2]); - } - } - - node.start(); - - add_bone_transform(ob_arm, bone, node); - - // Write nodes of childobjects, remove written objects from list - std::vector<Object *>::iterator i = child_objects.begin(); - - while (i != child_objects.end()) { - if ((*i)->partype == PARBONE && STREQ((*i)->parsubstr, bone->name)) { - float backup_parinv[4][4]; - copy_m4_m4(backup_parinv, (*i)->parentinv); - - // crude, temporary change to parentinv - // so transform gets exported correctly. - - // Add bone tail- translation... don't know why - // bone parenting is against the tail of a bone - // and not it's head, seems arbitrary. - (*i)->parentinv[3][1] += bone->length; - - // OPEN_SIM_COMPATIBILITY - // TODO: when such objects are animated as - // single matrix the tweak must be applied - // to the result. - if (export_settings->open_sim) { - // tweak objects parentinverse to match compatibility - float temp[4][4]; - - copy_m4_m4(temp, bone->arm_mat); - temp[3][0] = temp[3][1] = temp[3][2] = 0.0f; - - mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv); - } - - se->writeNodes(*i); - copy_m4_m4((*i)->parentinv, backup_parinv); - i = child_objects.erase(i); - } - else i++; - } - - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(child, ob_arm, se, child_objects); - } - node.end(); - } - else { - for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { - add_bone_node(child, ob_arm, se, child_objects); - } - } + if (!(this->export_settings->deform_bones_only && bone->flag & BONE_NO_DEFORM)) { + std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name); + std::string node_name = std::string(bone->name); + std::string node_sid = get_joint_sid(bone); + + COLLADASW::Node node(mSW); + + node.setType(COLLADASW::Node::JOINT); + node.setNodeId(node_id); + node.setNodeName(node_name); + node.setNodeSid(node_sid); + + if (this->export_settings->use_blender_profile) { + if (bone->parent) { + if (bone->flag & BONE_CONNECTED) { + node.addExtraTechniqueParameter("blender", "connect", true); + } + } + std::string layers = BoneExtended::get_bone_layers(bone->layer); + node.addExtraTechniqueParameter("blender", "layer", layers); + + bArmature *armature = (bArmature *)ob_arm->data; + EditBone *ebone = bc_get_edit_bone(armature, bone->name); + if (ebone && ebone->roll != 0) { + node.addExtraTechniqueParameter("blender", "roll", ebone->roll); + } + if (bc_is_leaf_bone(bone)) { + node.addExtraTechniqueParameter("blender", "tip_x", bone->arm_tail[0] - bone->arm_head[0]); + node.addExtraTechniqueParameter("blender", "tip_y", bone->arm_tail[1] - bone->arm_head[1]); + node.addExtraTechniqueParameter("blender", "tip_z", bone->arm_tail[2] - bone->arm_head[2]); + } + } + + node.start(); + + add_bone_transform(ob_arm, bone, node); + + // Write nodes of childobjects, remove written objects from list + std::vector<Object *>::iterator i = child_objects.begin(); + + while (i != child_objects.end()) { + if ((*i)->partype == PARBONE && STREQ((*i)->parsubstr, bone->name)) { + float backup_parinv[4][4]; + copy_m4_m4(backup_parinv, (*i)->parentinv); + + // crude, temporary change to parentinv + // so transform gets exported correctly. + + // Add bone tail- translation... don't know why + // bone parenting is against the tail of a bone + // and not it's head, seems arbitrary. + (*i)->parentinv[3][1] += bone->length; + + // OPEN_SIM_COMPATIBILITY + // TODO: when such objects are animated as + // single matrix the tweak must be applied + // to the result. + if (export_settings->open_sim) { + // tweak objects parentinverse to match compatibility + float temp[4][4]; + + copy_m4_m4(temp, bone->arm_mat); + temp[3][0] = temp[3][1] = temp[3][2] = 0.0f; + + mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv); + } + + se->writeNodes(*i); + copy_m4_m4((*i)->parentinv, backup_parinv); + i = child_objects.erase(i); + } + else + i++; + } + + for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + add_bone_node(child, ob_arm, se, child_objects); + } + node.end(); + } + else { + for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) { + add_bone_node(child, ob_arm, se, child_objects); + } + } } -void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node) +void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node &node) { - //bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name); - - float mat[4][4]; - float bone_rest_mat[4][4]; /* derived from bone->arm_mat */ - float parent_rest_mat[4][4]; /* derived from bone->parent->arm_mat */ - - bool has_restmat = bc_get_property_matrix(bone, "rest_mat", mat); + //bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name); - if (!has_restmat) { + float mat[4][4]; + float bone_rest_mat[4][4]; /* derived from bone->arm_mat */ + float parent_rest_mat[4][4]; /* derived from bone->parent->arm_mat */ - /* Have no restpose matrix stored, try old style <= Blender 2.78 */ + bool has_restmat = bc_get_property_matrix(bone, "rest_mat", mat); - bc_create_restpose_mat(this->export_settings, bone, bone_rest_mat, bone->arm_mat, true); + if (!has_restmat) { - if (bone->parent) { - // get bone-space matrix from parent pose - /*bPoseChannel *parchan = BKE_pose_channel_find_name(ob_arm->pose, bone->parent->name); - float invpar[4][4]; - invert_m4_m4(invpar, parchan->pose_mat); - mul_m4_m4m4(mat, invpar, pchan->pose_mat);*/ - float invpar[4][4]; - bc_create_restpose_mat(this->export_settings, bone->parent, parent_rest_mat, bone->parent->arm_mat, true); + /* Have no restpose matrix stored, try old style <= Blender 2.78 */ - invert_m4_m4(invpar, parent_rest_mat); - mul_m4_m4m4(mat, invpar, bone_rest_mat); + bc_create_restpose_mat(this->export_settings, bone, bone_rest_mat, bone->arm_mat, true); - } - else { - copy_m4_m4(mat, bone_rest_mat); - } + if (bone->parent) { + // get bone-space matrix from parent pose + /*bPoseChannel *parchan = BKE_pose_channel_find_name(ob_arm->pose, bone->parent->name); + float invpar[4][4]; + invert_m4_m4(invpar, parchan->pose_mat); + mul_m4_m4m4(mat, invpar, pchan->pose_mat);*/ + float invpar[4][4]; + bc_create_restpose_mat( + this->export_settings, bone->parent, parent_rest_mat, bone->parent->arm_mat, true); - // OPEN_SIM_COMPATIBILITY - if (export_settings->open_sim) { - // Remove rotations vs armature from transform - // parent_rest_rot * mat * irest_rot - float temp[4][4]; - copy_m4_m4(temp, bone_rest_mat); - temp[3][0] = temp[3][1] = temp[3][2] = 0.0f; - invert_m4(temp); + invert_m4_m4(invpar, parent_rest_mat); + mul_m4_m4m4(mat, invpar, bone_rest_mat); + } + else { + copy_m4_m4(mat, bone_rest_mat); + } - mul_m4_m4m4(mat, mat, temp); + // OPEN_SIM_COMPATIBILITY + if (export_settings->open_sim) { + // Remove rotations vs armature from transform + // parent_rest_rot * mat * irest_rot + float temp[4][4]; + copy_m4_m4(temp, bone_rest_mat); + temp[3][0] = temp[3][1] = temp[3][2] = 0.0f; + invert_m4(temp); - if (bone->parent) { - copy_m4_m4(temp, parent_rest_mat); - temp[3][0] = temp[3][1] = temp[3][2] = 0.0f; + mul_m4_m4m4(mat, mat, temp); - mul_m4_m4m4(mat, temp, mat); - } - } - } + if (bone->parent) { + copy_m4_m4(temp, parent_rest_mat); + temp[3][0] = temp[3][1] = temp[3][2] = 0.0f; - if (this->export_settings->limit_precision) - bc_sanitize_mat(mat, LIMITTED_PRECISION); + mul_m4_m4m4(mat, temp, mat); + } + } + } - TransformWriter::add_node_transform(node, mat, NULL); + if (this->export_settings->limit_precision) + bc_sanitize_mat(mat, LIMITTED_PRECISION); + TransformWriter::add_node_transform(node, mat, NULL); } std::string ArmatureExporter::get_controller_id(Object *ob_arm, Object *ob) { - return translate_id(id_name(ob_arm)) + "_" + translate_id(id_name(ob)) + SKIN_CONTROLLER_ID_SUFFIX; + return translate_id(id_name(ob_arm)) + "_" + translate_id(id_name(ob)) + + SKIN_CONTROLLER_ID_SUFFIX; } |