Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/collada/ArmatureImporter.cpp
| Show First 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | int ArmatureImporter::create_bone(SkinInfo *skin, | ||||
| BoneExtended &be = add_bone_extended(bone, node, totchild, layer_labels, extended_bones); | BoneExtended &be = add_bone_extended(bone, node, totchild, layer_labels, extended_bones); | ||||
| int layer = be.get_bone_layers(); | int layer = be.get_bone_layers(); | ||||
| if (layer) { | if (layer) { | ||||
| bone->layer = layer; | bone->layer = layer; | ||||
| } | } | ||||
| arm->layer |= layer; /* ensure that all populated bone layers are visible after import */ | arm->layer |= layer; /* ensure that all populated bone layers are visible after import */ | ||||
| float *tail = be.get_tail(); | float *tail = be.get_tail(); | ||||
| int use_connect = be.get_use_connect(); | |||||
| switch (use_connect) { | |||||
| case 1: | |||||
| bone->flag |= BONE_CONNECTED; | |||||
| break; | |||||
| case -1: /* Connect type not specified */ | |||||
| case 0: | |||||
| bone->flag &= ~BONE_CONNECTED; | |||||
| break; | |||||
| } | |||||
| if (be.has_roll()) { | if (be.has_roll()) { | ||||
| bone->roll = be.get_roll(); | bone->roll = be.get_roll(); | ||||
| } | } | ||||
| else { | else { | ||||
| float angle; | float angle; | ||||
| mat4_to_loc_rot_size(loc, rot, size, mat); | mat4_to_loc_rot_size(loc, rot, size, mat); | ||||
| mat3_to_vec_roll(rot, nullptr, &angle); | mat3_to_vec_roll(rot, nullptr, &angle); | ||||
| bone->roll = angle; | bone->roll = angle; | ||||
| } | } | ||||
| copy_v3_v3(bone->head, mat[3]); | copy_v3_v3(bone->head, mat[3]); | ||||
| if (bone_is_skinned && this->import_settings->keep_bind_info) { | if (bone_is_skinned && this->import_settings->keep_bind_info) { | ||||
| float rest_mat[4][4]; | float rest_mat[4][4]; | ||||
| get_node_mat(rest_mat, node, nullptr, nullptr, nullptr); | get_node_mat(rest_mat, node, nullptr, nullptr, nullptr); | ||||
| bc_set_IDPropertyMatrix(bone, "bind_mat", joint_bind_mat); | bc_set_IDPropertyMatrix(bone, "bind_mat", joint_bind_mat); | ||||
| bc_set_IDPropertyMatrix(bone, "rest_mat", rest_mat); | bc_set_IDPropertyMatrix(bone, "rest_mat", rest_mat); | ||||
| } | } | ||||
| add_v3_v3v3(bone->tail, bone->head, tail); /* tail must be non zero */ | add_v3_v3v3(bone->tail, bone->head, tail); /* tail must be non zero */ | ||||
| // Set use connect flag if the document said to use it, otherwise ensure the flag is cleared | |||||
| bool use_connect = be.get_use_connect(); | |||||
gaiaclary: Just curious: Why is this code moved down from its previous location? | |||||
| if (use_connect) { | |||||
| bone->flag |= BONE_CONNECTED; | |||||
| } | |||||
| else { | |||||
| bone->flag &= ~BONE_CONNECTED; | |||||
| } | |||||
| /* find smallest bone length in armature (used later for leaf bone length) */ | /* find smallest bone length in armature (used later for leaf bone length) */ | ||||
| if (parent) { | if (parent) { | ||||
| if (use_connect == 1) { | if (use_connect) { | ||||
| copy_v3_v3(parent->tail, bone->head); | copy_v3_v3(parent->tail, bone->head); | ||||
| } | } | ||||
| /* guess reasonable leaf bone length */ | /* guess reasonable leaf bone length */ | ||||
| float length = len_v3v3(parent->head, bone->head); | float length = len_v3v3(parent->head, bone->head); | ||||
| if ((length < leaf_bone_length || totbone == 0) && length > MINIMUM_BONE_LENGTH) { | if ((length < leaf_bone_length || totbone == 0) && length > MINIMUM_BONE_LENGTH) { | ||||
| leaf_bone_length = length; | leaf_bone_length = length; | ||||
| } | } | ||||
| Show All 9 Lines | int ArmatureImporter::create_bone(SkinInfo *skin, | ||||
| } | } | ||||
| bone->length = len_v3v3(bone->head, bone->tail); | bone->length = len_v3v3(bone->head, bone->tail); | ||||
| joint_by_uid[node->getUniqueId()] = node; | joint_by_uid[node->getUniqueId()] = node; | ||||
| finished_joints.push_back(node); | finished_joints.push_back(node); | ||||
| be.set_chain_length(chain_length + 1); | be.set_chain_length(chain_length + 1); | ||||
| // Set scale inherit mode | |||||
| bone->inherit_scale_mode = be.get_inherit_scale(); | |||||
| // Set local location flag if the document said to use it, otherwise ensure the flag is cleared | |||||
| if (be.get_use_local_location()) { | |||||
| bone->flag |= BONE_NO_LOCAL_LOCATION; | |||||
| } | |||||
| else { | |||||
| bone->flag &= ~BONE_NO_LOCAL_LOCATION; | |||||
| } | |||||
| return chain_length + 1; | return chain_length + 1; | ||||
| } | } | ||||
| /** | /** | ||||
| * Collada only knows Joints, hence bones at the end of a bone chain | * Collada only knows Joints, hence bones at the end of a bone chain | ||||
| * don't have a defined length. This function guesses reasonable | * don't have a defined length. This function guesses reasonable | ||||
| * tail locations for the affected bones (nodes which don't have any connected child) | * tail locations for the affected bones (nodes which don't have any connected child) | ||||
| * Hint: The extended_bones set gets populated in ArmatureImporter::create_bone | * Hint: The extended_bones set gets populated in ArmatureImporter::create_bone | ||||
| ▲ Show 20 Lines • Show All 838 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| BoneExtended *be = new BoneExtended(bone); | BoneExtended *be = new BoneExtended(bone); | ||||
| extended_bones[bone->name] = be; | extended_bones[bone->name] = be; | ||||
| TagsMap::iterator etit; | TagsMap::iterator etit; | ||||
| ExtraTags *et = nullptr; | ExtraTags *et = nullptr; | ||||
| etit = uid_tags_map.find(node->getUniqueId().toAscii()); | etit = uid_tags_map.find(node->getUniqueId().toAscii()); | ||||
| bool has_connect = false; | bool use_connect = false; | ||||
| int connect_type = -1; | bool has_use_connect = false; | ||||
| if (etit != uid_tags_map.end()) { | if (etit != uid_tags_map.end()) { | ||||
| float tail[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; | float tail[3] = {FLT_MAX, FLT_MAX, FLT_MAX}; | ||||
| float roll = 0; | float roll = 0; | ||||
| std::string layers; | |||||
| et = etit->second; | et = etit->second; | ||||
| bool has_tail = false; | bool has_tail = false; | ||||
| has_tail |= et->setData("tip_x", &tail[0]); | has_tail |= et->setData("tip_x", &tail[0]); | ||||
| has_tail |= et->setData("tip_y", &tail[1]); | has_tail |= et->setData("tip_y", &tail[1]); | ||||
| has_tail |= et->setData("tip_z", &tail[2]); | has_tail |= et->setData("tip_z", &tail[2]); | ||||
| has_connect = et->setData("connect", &connect_type); | // Import roll and layer data from document, if present | ||||
| std::string layers = et->setData("layer", layers); | |||||
| bool has_roll = et->setData("roll", &roll); | bool has_roll = et->setData("roll", &roll); | ||||
| layers = et->setData("layer", layers); | |||||
| if (has_tail && !has_connect) { | |||||
| /* got a bone tail definition but no connect info -> bone is not connected */ | |||||
| has_connect = true; | |||||
| connect_type = 0; | |||||
| } | |||||
| be->set_bone_layers(layers, layer_labels); | be->set_bone_layers(layers, layer_labels); | ||||
| if (has_tail) { | if (has_tail) { | ||||
| be->set_tail(tail); | be->set_tail(tail); | ||||
| } | } | ||||
| if (has_roll) { | if (has_roll) { | ||||
| be->set_roll(roll); | be->set_roll(roll); | ||||
| } | } | ||||
| // Import use connect setting from document, if present | |||||
| use_connect = false; | |||||
| has_use_connect = et->setData("connect", &use_connect); | |||||
| // If there is tail information but no use_connect setting, force use_connect to be false. | |||||
| if (has_tail && !has_use_connect) { | |||||
| has_use_connect = true; | |||||
| use_connect = false; | |||||
| } | |||||
| } | } | ||||
| if (!has_connect && this->import_settings->auto_connect) { | // If no use_connect setting is supplied (either from the document or from having a tail) | ||||
| /* Auto connect only when parent has exactly one child. */ | // and the user requested auto-connection, set use_connect to true if this bone is the | ||||
| connect_type = sibcount == 1; | // only child of its parent. | ||||
| if (!has_use_connect && this->import_settings->auto_connect) { | |||||
| use_connect = true; | |||||
| } | } | ||||
| be->set_use_connect(connect_type); | be->set_use_connect(use_connect); | ||||
| be->set_leaf_bone(true); | be->set_leaf_bone(true); | ||||
| // Import scale inheritance setting from document, if present | |||||
| int scale_inherit_type = eBone_InheritScaleMode::BONE_INHERIT_SCALE_FULL; | |||||
| bool has_scale = et->setData("inherit_scale", &scale_inherit_type); | |||||
| if (has_scale) { | |||||
| be->set_inherit_scale((eBone_InheritScaleMode)scale_inherit_type); | |||||
| } | |||||
| // Import local location setting from document, if present | |||||
| bool use_local_location = false; | |||||
| bool has_local_location = et->setData("use_local_location", &use_local_location); | |||||
| if (has_local_location) { | |||||
| be->set_use_local_location(use_local_location); | |||||
| } | |||||
| return *be; | return *be; | ||||
| } | } | ||||
Just curious: Why is this code moved down from its previous location?