bool ArmatureExporter::add_instance_controller(Object *ob) { 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); COLLADASW::InstanceController ins(mSW); ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id)); 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); } InstanceWriter::add_material_bindings( ins.getBindMaterial(), ob, this->export_settings.get_active_uv_only()); ins.add(); return true; }
// ob should be of type OB_MESH // both args are required void ArmatureExporter::export_controller(Object* ob, Object *ob_arm) { // joint names // joint inverse bind matrices // vertex weights // input: // joint names: ob -> vertex group names // vertex group weights: me->dvert -> groups -> index, weight /* me->dvert: typedef struct MDeformVert { struct MDeformWeight *dw; int totweight; int flag; // flag only in use for weightpaint now } MDeformVert; typedef struct MDeformWeight { int def_nr; float weight; } MDeformWeight; */ Mesh *me = (Mesh*)ob->data; if (!me->dvert) return; std::string controller_name = id_name(ob_arm); std::string controller_id = get_controller_id(ob_arm, ob); openSkin(controller_id, controller_name, COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob))); add_bind_shape_mat(ob); std::string joints_source_id = add_joints_source(ob_arm, &ob->defbase, controller_id); std::string inv_bind_mat_source_id = add_inv_bind_mats_source(ob_arm, &ob->defbase, controller_id); std::string weights_source_id = add_weights_source(me, controller_id); add_joints_element(&ob->defbase, joints_source_id, inv_bind_mat_source_id); add_vertex_weights_element(weights_source_id, joints_source_id, me, ob_arm, &ob->defbase); closeSkin(); closeController(); }
void ArmatureExporter::add_instance_controller(Object *ob) { Object *ob_arm = get_assigned_armature(ob); bArmature *arm = (bArmature*)ob_arm->data; 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)); // write root bone URLs Bone *bone; for (bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) { if (!bone->parent) ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_joint_id(bone, ob_arm))); } InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob); ins.add(); }
void ControllerExporter::export_morph_controller(Object *ob, Key *key) { bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; me = bc_get_mesh_copy(scene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, this->export_settings->triangulate); std::string controller_name = id_name(ob) + "-morph"; std::string controller_id = get_controller_id(key, ob); openMorph(controller_id, controller_name, COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, use_instantiation))); std::string targets_id = add_morph_targets(key, ob); std::string morph_weights_id = add_morph_weights(key, ob); COLLADASW::TargetsElement targets(mSW); COLLADASW::InputList &input = targets.getInputList(); input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::MORPH_TARGET, // constant declared in COLLADASWInputList.h COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, targets_id))); input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::MORPH_WEIGHT, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id))); targets.add(); BKE_libblock_free_us(G.main, me); //support for animations //can also try the base element and param alternative add_weight_extras(key); closeMorph(); closeController(); }