// parent_mat is armature-space void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm) { std::string node_id = get_joint_id(bone, ob_arm); std::string node_name = std::string(bone->name); std::string node_sid = get_joint_sid(bone, ob_arm); COLLADASW::Node node(mSW); node.setType(COLLADASW::Node::JOINT); node.setNodeId(node_id); node.setNodeName(node_name); node.setNodeSid(node_sid); /*if ( bone->childbase.first == NULL || BLI_countlist(&(bone->childbase))>=2) add_blender_leaf_bone( bone, ob_arm , node ); else{*/ node.start(); add_bone_transform(ob_arm, bone, node); for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) { add_bone_node(child, ob_arm); } node.end(); //} }
// write bone nodes void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce) { // write bone nodes bArmature *arm = (bArmature*)ob_arm->data; for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) { // start from root bones if (!bone->parent) add_bone_node(bone, ob_arm); } }
void ArmatureExporter::add_blender_leaf_bone(Bone *bone, Object *ob_arm, COLLADASW::Node& node) { node.start(); add_bone_transform(ob_arm, bone, node); node.addExtraTechniqueParameter("blender", "tip_x", bone->tail[0] ); node.addExtraTechniqueParameter("blender", "tip_y", bone->tail[1] ); node.addExtraTechniqueParameter("blender", "tip_z", bone->tail[2] ); for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) { add_bone_node(child, ob_arm); } node.end(); }
// write bone nodes void ArmatureExporter::add_armature_bones(Object *ob_arm, ViewLayer *view_layer, SceneExporter *se, std::vector<Object *> &child_objects) { // write bone nodes bArmature *armature = (bArmature *)ob_arm->data; bool is_edited = armature->edbo != NULL; if (!is_edited) { ED_armature_to_edit(armature); } for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) { add_bone_node(bone, ob_arm, se, child_objects); } if (!is_edited) { ED_armature_edit_free(armature); } }
// parent_mat is armature-space void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, SceneExporter *se, std::vector<Object *> &child_objects) { if (can_export(bone)) { 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.get_use_blender_profile()) { if (!is_export_root(bone)) { 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)) { Vector head, tail; const BCMatrix &global_transform = this->export_settings.get_global_transform(); if (this->export_settings.get_apply_global_orientation()) { bc_add_global_transform(head, bone->arm_head, global_transform); bc_add_global_transform(tail, bone->arm_tail, global_transform); } else { copy_v3_v3(head, bone->arm_head); copy_v3_v3(tail, bone->arm_tail); } node.addExtraTechniqueParameter("blender", "tip_x", tail[0] - head[0]); node.addExtraTechniqueParameter("blender", "tip_y", tail[1] - head[1]); node.addExtraTechniqueParameter("blender", "tip_z", tail[2] - head[2]); } } node.start(); add_bone_transform(ob_arm, bone, node); // Write nodes of childobjects, remove written objects from list std::vector<Object *>::iterator iter = child_objects.begin(); while (iter != child_objects.end()) { Object *ob = *iter; if (ob->partype == PARBONE && STREQ(ob->parsubstr, bone->name)) { float backup_parinv[4][4]; copy_m4_m4(backup_parinv, ob->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. ob->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.get_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(ob->parentinv, temp, ob->parentinv); } se->writeNode(ob); copy_m4_m4(ob->parentinv, backup_parinv); iter = child_objects.erase(iter); } else iter++; } 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); } } }