9#include "COLLADASWBaseInputElement.h"
10#include "COLLADASWInstanceController.h"
11#include "COLLADASWPrimitves.h"
12#include "COLLADASWSource.h"
39 std::stringstream collection_stream;
40 std::stringstream visible_stream;
42 collection_stream << bcoll->name <<
"\n";
45 visible_stream << bcoll->name <<
"\n";
49 std::string collection_names = collection_stream.str();
50 if (collection_names.length() > 1) {
51 collection_names.pop_back();
52 node.addExtraTechniqueParameter(
"blender",
"collections", collection_names);
55 std::string visible_names = visible_stream.str();
56 if (visible_names.length() > 1) {
57 visible_names.pop_back();
58 node.addExtraTechniqueParameter(
"blender",
"visible_collections", visible_names);
62 node.addExtraTechniqueParameter(
70 std::vector<Object *> &child_objects)
76 bool is_edited = armature->
edbo !=
nullptr;
83 add_bone_node(bone, ob_arm, se, child_objects);
91void ArmatureExporter::write_bone_URLs(COLLADASW::InstanceController &ins,
95 if (
bc_is_root_bone(bone, this->export_settings.get_deform_bones_only())) {
97 ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, joint_id));
101 write_bone_URLs(ins, ob_arm, child);
111 const std::string &controller_id = get_controller_id(ob_arm, ob);
113 COLLADASW::InstanceController ins(mSW);
114 ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id));
117 if (mesh->deform_verts().is_empty()) {
123 write_bone_URLs(ins, ob_arm, bone);
127 ins.getBindMaterial(), ob, this->export_settings.get_active_uv_only());
134void ArmatureExporter::operator()(
Object *ob)
139bool ArmatureExporter::already_written(
Object *ob_arm)
141 return std::find(written_armatures.begin(), written_armatures.end(), ob_arm) !=
142 written_armatures.end();
145void ArmatureExporter::wrote(
Object *ob_arm)
147 written_armatures.push_back(ob_arm);
150void ArmatureExporter::find_objects_using_armature(
Object *ob_arm,
151 std::vector<Object *> &objects,
156 Base *base = (
Base *)sce->base.first;
158 Object *ob = base->object;
160 if (ob->
type ==
OB_MESH && get_assigned_armature(ob) == ob_arm) {
161 objects.push_back(ob);
169void ArmatureExporter::add_bone_node(
Bone *bone,
172 std::vector<Object *> &child_objects)
174 if (can_export(bone)) {
176 std::string node_name = std::string(bone->
name);
179 COLLADASW::Node
node(mSW);
181 node.setType(COLLADASW::Node::JOINT);
182 node.setNodeId(node_id);
183 node.setNodeName(node_name);
184 node.setNodeSid(node_sid);
186 if (this->export_settings.get_use_blender_profile()) {
187 if (!is_export_root(bone)) {
189 node.addExtraTechniqueParameter(
"blender",
"connect",
true);
193 std::string collection_names =
"";
195 collection_names += std::string(bcoll_ref->bcoll->name) +
"\n";
197 if (collection_names.length() > 1) {
198 collection_names.pop_back();
199 node.addExtraTechniqueParameter(
"blender",
"", collection_names,
"",
"collections");
204 if (ebone && ebone->
roll != 0) {
205 node.addExtraTechniqueParameter(
"blender",
"roll", ebone->
roll);
209 const BCMatrix &global_transform = this->export_settings.get_global_transform();
210 if (this->export_settings.get_apply_global_orientation()) {
218 node.addExtraTechniqueParameter(
"blender",
"tip_x", tail[0] - head[0]);
219 node.addExtraTechniqueParameter(
"blender",
"tip_y", tail[1] - head[1]);
220 node.addExtraTechniqueParameter(
"blender",
"tip_z", tail[2] - head[2]);
226 add_bone_transform(ob_arm, bone, node);
229 std::vector<Object *>::iterator iter = child_objects.begin();
231 while (iter != child_objects.end()) {
234 float backup_parinv[4][4];
249 if (export_settings.get_open_sim()) {
254 temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
261 iter = child_objects.erase(iter);
269 add_bone_node(child, ob_arm, se, child_objects);
275 add_bone_node(child, ob_arm, se, child_objects);
280bool ArmatureExporter::is_export_root(
Bone *bone)
284 if (can_export(entry)) {
289 return can_export(bone);
292void ArmatureExporter::add_bone_transform(
Object *ob_arm,
Bone *bone, COLLADASW::Node &node)
297 float bone_rest_mat[4][4];
298 float parent_rest_mat[4][4];
308 if (is_export_root(bone)) {
312 Matrix parent_inverse;
322 if (export_settings.get_open_sim()) {
328 workmat[3][0] = workmat[3][1] = workmat[3][2] = 0.0f;
333 if (!is_export_root(bone)) {
335 workmat[3][0] = workmat[3][1] = workmat[3][2] = 0.0f;
342 if (this->export_settings.get_limit_precision()) {
349std::string ArmatureExporter::get_controller_id(
Object *ob_arm,
Object *ob)
352 SKIN_CONTROLLER_ID_SUFFIX;
Blender kernel action and pose functionality.
#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])
@ BONE_COLLECTION_VISIBLE
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)
bool bc_get_property_matrix(Bone *bone, std::string key, float mat[4][4])
bool bc_is_leaf_bone(Bone *bone)
EditBone * bc_get_edit_bone(bArmature *armature, char *name)
constexpr int LIMITTED_PRECISION
struct BoneCollection * active_collection
char active_collection_name[64]
struct bArmature_Runtime runtime