9#include "COLLADASWInstanceController.h"
31 std::stringstream collection_stream;
32 std::stringstream visible_stream;
34 collection_stream << bcoll->name <<
"\n";
37 visible_stream << bcoll->name <<
"\n";
41 std::string collection_names = collection_stream.str();
42 if (collection_names.length() > 1) {
43 collection_names.pop_back();
44 node.addExtraTechniqueParameter(
"blender",
"collections", collection_names);
47 std::string visible_names = visible_stream.str();
48 if (visible_names.length() > 1) {
49 visible_names.pop_back();
50 node.addExtraTechniqueParameter(
"blender",
"visible_collections", visible_names);
54 node.addExtraTechniqueParameter(
62 std::vector<Object *> &child_objects)
68 bool is_edited = armature->
edbo !=
nullptr;
75 add_bone_node(bone, ob_arm, se, child_objects);
83void ArmatureExporter::write_bone_URLs(COLLADASW::InstanceController &ins,
87 if (
bc_is_root_bone(bone, this->export_settings.get_deform_bones_only())) {
89 ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id));
93 write_bone_URLs(ins, ob_arm, child);
103 const std::string &controller_id = get_controller_id(ob_arm, ob);
105 COLLADASW::InstanceController ins(mSW);
106 ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id));
109 if (mesh->deform_verts().is_empty()) {
115 write_bone_URLs(ins, ob_arm, bone);
119 ins.getBindMaterial(), ob,
this->export_settings.get_active_uv_only());
126void ArmatureExporter::operator()(
Object *ob)
131bool ArmatureExporter::already_written(
Object *ob_arm)
133 return std::find(written_armatures.begin(), written_armatures.end(), ob_arm) !=
134 written_armatures.end();
137void ArmatureExporter::wrote(
Object *ob_arm)
139 written_armatures.push_back(ob_arm);
142void ArmatureExporter::find_objects_using_armature(
Object *ob_arm,
143 std::vector<Object *> &objects,
148 Base *base = (
Base *)sce->base.first;
150 Object *ob = base->object;
152 if (ob->
type ==
OB_MESH && get_assigned_armature(ob) == ob_arm) {
153 objects.push_back(ob);
161void ArmatureExporter::add_bone_node(
Bone *bone,
164 std::vector<Object *> &child_objects)
166 if (can_export(bone)) {
168 std::string node_name = std::string(bone->
name);
171 COLLADASW::Node node(mSW);
173 node.setType(COLLADASW::Node::JOINT);
174 node.setNodeId(node_id);
175 node.setNodeName(node_name);
176 node.setNodeSid(node_sid);
178 if (this->export_settings.get_use_blender_profile()) {
179 if (!is_export_root(bone)) {
181 node.addExtraTechniqueParameter(
"blender",
"connect",
true);
185 std::string collection_names;
187 collection_names += std::string(bcoll_ref->bcoll->name) +
"\n";
189 if (collection_names.length() > 1) {
190 collection_names.pop_back();
191 node.addExtraTechniqueParameter(
"blender",
"", collection_names,
"",
"collections");
196 if (ebone && ebone->
roll != 0) {
197 node.addExtraTechniqueParameter(
"blender",
"roll", ebone->
roll);
201 const BCMatrix &global_transform = this->export_settings.get_global_transform();
202 if (this->export_settings.get_apply_global_orientation()) {
210 node.addExtraTechniqueParameter(
"blender",
"tip_x", tail[0] - head[0]);
211 node.addExtraTechniqueParameter(
"blender",
"tip_y", tail[1] - head[1]);
212 node.addExtraTechniqueParameter(
"blender",
"tip_z", tail[2] - head[2]);
218 add_bone_transform(ob_arm, bone, node);
221 std::vector<Object *>::iterator iter = child_objects.begin();
223 while (iter != child_objects.end()) {
226 float backup_parinv[4][4];
241 if (export_settings.get_open_sim()) {
246 temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
253 iter = child_objects.erase(iter);
261 add_bone_node(child, ob_arm, se, child_objects);
267 add_bone_node(child, ob_arm, se, child_objects);
272bool ArmatureExporter::is_export_root(
Bone *bone)
276 if (can_export(entry)) {
281 return can_export(bone);
284void ArmatureExporter::add_bone_transform(
Object *ob_arm,
Bone *bone, COLLADASW::Node &node)
289 float bone_rest_mat[4][4];
290 float parent_rest_mat[4][4];
300 if (is_export_root(bone)) {
314 if (export_settings.get_open_sim()) {
320 workmat[3][0] = workmat[3][1] = workmat[3][2] = 0.0f;
325 if (!is_export_root(bone)) {
327 workmat[3][0] = workmat[3][1] = workmat[3][2] = 0.0f;
334 if (this->export_settings.get_limit_precision()) {
341std::string ArmatureExporter::get_controller_id(
Object *ob_arm,
Object *ob)
344 SKIN_CONTROLLER_ID_SUFFIX;
#define LISTBASE_FOREACH(type, var, list)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void copy_m4_m4(float m1[4][4], const float m2[4][4])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool invert_m4(float mat[4][4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
struct BoneCollectionReference BoneCollectionReference
@ BONE_COLLECTION_VISIBLE
struct bArmature bArmature
void ED_armature_edit_free(bArmature *arm)
void ED_armature_to_edit(bArmature *arm)
void add_bone_collections(Object *ob_arm, COLLADASW::Node &node)
bool add_instance_controller(Object *ob)
void add_armature_bones(Object *ob_arm, ViewLayer *view_layer, SceneExporter *se, std::vector< Object * > &child_objects)
static void sanitize(Matrix &matrix, int precision)
void add_material_bindings(COLLADASW::BindMaterial &bind_material, Object *ob, bool active_uv_only)
std::string get_joint_sid(Bone *bone)
std::string translate_id(const char *idString)
std::string id_name(void *id)
bool bc_is_root_bone(Bone *aBone, bool deform_bones_only)
void bc_add_global_transform(Matrix &to_mat, const Matrix &from_mat, const BCMatrix &global_transform, const bool invert)
Object * bc_get_assigned_armature(Object *ob)
void bc_create_restpose_mat(BCExportSettings &export_settings, Bone *bone, float to_mat[4][4], float from_mat[4][4], bool use_local_space)
EditBone * bc_get_edit_bone(bArmature *armature, const char *name)
bool bc_get_property_matrix(Bone *bone, const std::string &key, float mat[4][4])
bool bc_is_leaf_bone(Bone *bone)
constexpr int LIMITTED_PRECISION
struct BoneCollection * active_collection
char active_collection_name[64]
struct bArmature_Runtime runtime