10#include "COLLADABUPlatform.h"
12#include "COLLADAFWGeometry.h"
13#include "COLLADAFWMeshPrimitive.h"
14#include "COLLADAFWMeshVertexData.h"
15#include "COLLADAFWNode.h"
80 if (index >=
array.getValuesCount()) {
84 if (
array.getType() == COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT) {
85 return array.getFloatValues()->getData()[index];
88 return array.getDoubleValues()->getData()[index];
112 if (cti ==
nullptr) {
137 const bool xmirror =
false;
138 const bool keep_transform =
false;
140 if (par && is_parent_space) {
142 par->object_to_world().ptr(),
143 ob->object_to_world().ptr());
147 nullptr, C, scene, ob, par, partype, xmirror, keep_transform,
nullptr);
153 std::vector<bAction *> actions;
162 actions.push_back(act);
167 actions.push_back(action);
175 std::string channel_type,
176 std::string axis_name,
177 std::string axis_separator)
179 std::string result = action_name +
"_" + channel_type;
180 if (ob_name.length() > 0) {
181 result = ob_name +
"_" +
result;
183 if (axis_name.length() > 0) {
184 result += axis_separator + axis_name;
191 Main *bmain = blender_context.get_main();
192 Scene *scene = blender_context.get_scene();
193 Depsgraph *
depsgraph = blender_context.get_depsgraph();
223 if (!node_extra_tags) {
228 std::vector<std::string> collection_names = node_extra_tags->
dataSplitString(
"collections");
229 std::vector<std::string> visible_names = node_extra_tags->
dataSplitString(
"visible_collections");
230 std::set<std::string> visible_names_set(visible_names.begin(), visible_names.end());
231 for (
const std::string &name : collection_names) {
233 if (visible_names_set.find(name) == visible_names_set.end()) {
241 std::string active_name;
242 active_name = node_extra_tags->
setData(
"active_collection", active_name);
262 bool apply_modifiers,
265 const Mesh *tmpmesh =
nullptr;
266 if (apply_modifiers) {
268 switch (export_mesh_type) {
270 dm = mesh_create_derived_view(
depsgraph, scene, ob, &mask);
274 dm = mesh_create_derived_render(
depsgraph, scene, ob, &mask);
279 Depsgraph *
depsgraph = blender_context.get_depsgraph();
323 for (node = export_set;
node; node = node->
next) {
326 if (ob->
type == obtype && ob->
data) {
339 for (node = export_set; node->
next && !sorted; node = node->
next) {
344 for (current = export_set; current->
next; current = current->
next) {
348 if (strcmp(a->id.name,
b->id.name) > 0) {
350 current->next->link = a;
359 if (deform_bones_only) {
360 Bone *root =
nullptr;
368 return (aBone == root);
389 const std::string &pattern,
390 const std::string &replacement)
393 while ((
pos = data.find(pattern,
pos)) != std::string::npos) {
394 data.replace(
pos, pattern.length(), replacement);
395 pos += replacement.length();
402 if (scale_to_scene) {
404 ob->
runtime->object_to_world.ptr(), bc_unit.
get_scale(), ob->object_to_world().ptr());
415 for (
Object *ob : *objects_done) {
416 if (ob->parent ==
nullptr) {
422void bc_decompose(
float mat[4][4],
float *loc,
float eul[3],
float quat[4],
float *size)
446 float mat_from[4][4];
460 bool use_beauty =
false;
461 bool tag_only =
false;
470 bm_from_me_params.calc_vert_normal =
true;
493 if (
STREQ(name, eBone->name)) {
507 int bit = 1u << layer;
521 std::string key = armature->
id.
name;
523 if (result ==
nullptr) {
525 extended_bone_maps[key] =
result;
532 std::map<std::string, BoneExtensionMap *>::iterator map_it;
533 for (map_it = extended_bone_maps.begin(); map_it != extended_bone_maps.end(); ++map_it) {
535 for (
auto &extended_bone : *extended_bones) {
536 delete extended_bone.second;
538 extended_bones->clear();
539 delete extended_bones;
551 this->chain_length = 0;
552 this->is_leaf =
false;
553 this->tail[0] = 0.0f;
554 this->tail[1] = 0.5f;
555 this->tail[2] = 0.0f;
556 this->use_connect = -1;
559 this->has_custom_tail =
false;
560 this->has_custom_roll =
false;
580 chain_length = aLength;
596 this->has_custom_roll =
true;
601 return this->has_custom_roll;
611 this->tail[0] = vec[0];
612 this->tail[1] = vec[1];
613 this->tail[2] = vec[2];
614 this->has_custom_tail =
true;
619 return this->has_custom_tail;
629 if (s.empty() || (!isdigit(s[0]) && (s[0] !=
'-') && (s[0] !=
'+'))) {
634 strtol(s.c_str(), &p, 10);
641 this->bone_collections = bone_collections;
645 return this->bone_collections;
650 this->use_connect = use_connect;
655 return this->use_connect;
661 if (idgroup ==
nullptr) {
663 ebone->
prop = idgroup;
681 if (ebone->
prop ==
nullptr) {
701 switch (property->type) {
724 if (property && property->type ==
IDP_ARRAY && property->len == 16) {
726 for (
int i = 0; i < 4; i++) {
727 for (
int j = 0; j < 4; j++) {
728 mat[i][j] =
array[4 * i + j];
758 if (adt ==
nullptr) {
767 SNPRINTF(prefix,
"pose.bones[\"%s\"]", bone_name_esc);
772 if (
STREQLEN(fcu->rna_path, prefix, strlen(prefix))) {
773 fcu->flag &= ~FCURVE_DISABLED;
780 fcu->flag &= ~FCURVE_DISABLED;
814 temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
821 temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;
832 static float MIN_DISTANCE = 0.00001;
834 if (values.size() < 2) {
838 BCMatrixSampleMap::iterator it;
840 for (it = values.begin(); it != values.end(); ++it) {
841 const BCMatrix *matrix = it->second;
843 if (refmat ==
nullptr) {
848 if (!matrix->in_range(*refmat, MIN_DISTANCE)) {
866 for (
int a = 0; a < ob->
totcol; a++) {
888 for (node = export_set;
node; node = node->
next) {
900 const Matrix &from_mat,
909 const Vector &from_vec,
950 float from_mat[4][4],
951 bool use_local_space)
956 static const float V0[3] = {0, 0, 0};
958 if (!
has_custom_props(bone, export_settings.get_keep_bind_info(),
"restpose_loc") &&
959 !
has_custom_props(bone, export_settings.get_keep_bind_info(),
"restpose_rot") &&
960 !
has_custom_props(bone, export_settings.get_keep_bind_info(),
"restpose_scale"))
970 if (export_settings.get_keep_bind_info()) {
973 if (use_local_space && bone->
parent) {
986 if (export_settings.get_keep_bind_info()) {
998 if (export_settings.get_keep_bind_info()) {
1007 for (
int i = 0; i < 3; i++) {
1016 for (
int i = 0; i < 3; i++) {
1023 for (
int i = 0; i < 4; i++) {
1024 for (
int j = 0; j < 4; j++) {
1032 for (
int i = 0; i < 4; i++) {
1033 for (
int j = 0; j < 4; j++) {
1041 for (
int i = 0; i < 4; i++) {
1042 for (
int j = 0; j < 4; j++) {
1050 for (
int i = 0; i < 4; i++) {
1051 for (
int j = 0; j < 4; j++) {
1059 for (
int i = 0; i < 4; i++) {
1060 for (
int j = 0; j < 4; j++) {
1076 return std::string(layer_name);
1098 if (num_layers && layer < num_layers) {
1102 return std::string(layer_name);
1112 nullptr, &ma->
id,
"Shader Nodetree",
"ShaderNodeTree");
1123 if (
label.length() > 0) {
1135 return bc_add_node(C, ntree, node_type, locx, locy,
"");
1150 std::map<std::string, bNode *> nmap;
1152 nmap[
"main"] =
bc_add_node(C, ntree, SH_NODE_BSDF_PRINCIPLED, -300, 300);
1153 nmap[
"emission"] =
bc_add_node(C, ntree, SH_NODE_EMISSION, -300, 500,
"emission");
1154 nmap[
"add"] =
bc_add_node(C, ntree, SH_NODE_ADD_SHADER, 100, 400);
1155 nmap[
"transparent"] =
bc_add_node(C, ntree, SH_NODE_BSDF_TRANSPARENT, 100, 200);
1156 nmap[
"mix"] =
bc_add_node(C, ntree, SH_NODE_MIX_SHADER, 400, 300,
"transparency");
1158 nmap[
"out"]->flag &= ~NODE_SELECT;
1167 bc_make_group(C, ntree, nmap);
1169 nmap[
"main"] =
bc_add_node(C, ntree, SH_NODE_BSDF_PRINCIPLED, 0, 300);
1178 Color default_color = {ma->
r, ma->
g, ma->
b, 1.0};
1189 Color default_color = {0, 0, 0, 1};
1195 double emission_strength = 0.0;
1197 if (emission_strength == 0.0) {
1204 COLLADASW::Color
col = cot.getColor();
1205 double final_color[3] = {
col.getRed(),
col.getGreen(),
col.getBlue()};
1209 double max_color = fmax(fmax(final_color[0], final_color[1]), final_color[2]);
1210 if (max_color > 1.0) {
1214 cot.getColor().set(final_color[0], final_color[1], final_color[2],
col.getAlpha());
1221 Color default_color = {0, 0, 0, 1.0};
1227 Color default_color = {0, 0, 0, 1.0};
1233 Color default_color = {0, 0, 0, 1.0};
1239 double alpha = ma->
a;
1269 double reflectivity = ma->
spec;
1274 return reflectivity;
1290 Color &default_color,
1300 return bc_get_cot(default_color, with_alpha);
1308 if (node->typeinfo->type == SH_NODE_BSDF_PRINCIPLED) {
1316COLLADASW::ColorOrTexture
bc_get_cot(
float r,
float g,
float b,
float a)
1318 COLLADASW::Color
color(r, g,
b, a);
1319 COLLADASW::ColorOrTexture cot(color);
1326 COLLADASW::ColorOrTexture cot(color);
Functions and classes to work with Actions.
Functions for backward compatibility with the legacy Action API.
C++ functions to deal with Armature collections (i.e. the successor of bone layers).
void ANIM_bonecoll_hide(bArmature *armature, BoneCollection *bcoll)
void ANIM_armature_bonecoll_active_name_set(bArmature *armature, const char *name)
void ANIM_bonecoll_show(bArmature *armature, BoneCollection *bcoll)
BoneCollection * ANIM_armature_bonecoll_new(bArmature *armature, const char *name, int parent_index=-1)
std::map< int, const BCMatrix * > BCMatrixSampleMap
Blender kernel action and pose functionality.
bPoseChannel * BKE_pose_channel_find_name(const bPose *pose, const char *name)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
const bConstraintTypeInfo * BKE_constraint_typeinfo_get(struct bConstraint *con)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_active_layer_index(const CustomData *data, eCustomDataType type)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Key * BKE_key_from_object(Object *ob)
LayerCollection * BKE_layer_collection_get_active(ViewLayer *view_layer)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
void BKE_view_layer_base_select_and_set_active(ViewLayer *view_layer, Base *selbase)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
void BKE_mesh_tessface_ensure(Mesh *mesh)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
#define SH_NODE_OUTPUT_MATERIAL
General operations, lookup, etc. for blender objects.
void BKE_object_apply_mat4(Object *ob, const float mat[4][4], bool use_compat, bool use_parent)
void * BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name) ATTR_NONNULL(1)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
void BKE_scene_frame_set(Scene *scene, float frame)
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
double double_round(double x, int ndigits)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void loc_eulO_size_to_mat4(float R[4][4], const float loc[3], const float eul[3], const float size[3], short order)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
bool invert_m4(float mat[4][4])
void mat4_to_size(float size[3], const float M[4][4])
void mat4_to_eul(float eul[3], const float mat[4][4])
void quat_to_mat4(float m[4][4], const float q[4])
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
void mat4_to_quat(float q[4], const float mat[4][4])
MINLINE void mul_v3db_db(double r[3], double f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define STRNCPY(dst, src)
#define SNPRINTF(dst, format,...)
size_t BLI_str_escape(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define STREQLEN(a, b, n)
typedef double(DMatrix)[4][4]
void DEG_id_tag_update(ID *id, unsigned int flags)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ MOD_TRIANGULATE_QUAD_SHORTEDGE
Object is a sort of wrapper for general info.
void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
Read Guarded memory(de)allocation.
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
ATTR_WARN_UNUSED_RESULT BMesh * bm
const BMAllocTemplate bm_mesh_allocsize_default
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
BMesh * BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params)
BMesh Make Mesh.
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams *params)
void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void BM_mesh_triangulate(BMesh *bm, const int quad_method, const int ngon_method, const int min_vertices, const bool tag_only, BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out)
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
void add_transform(Matrix &to, const Matrix &transform, const Matrix &from, bool inverted=false)
void get_matrix(DMatrix &matrix, bool transposed=false, int precision=-1) const
void apply_transform(Matrix &to, const Matrix &transform, const Matrix &from, bool inverse=false)
void set_use_connect(int use_connect)
void set_roll(float roll)
const std::vector< std::string > & get_bone_collections()
void set_name(char *aName)
void set_bone_collections(std::vector< std::string > bone_collections)
void set_tail(const float vec[])
void set_leaf_bone(bool state)
BoneExtended(EditBone *aBone)
void set_chain_length(int aLength)
BoneExtensionMap & getExtensionMap(bArmature *armature)
float(& get_rotation())[4]
std::string translate_id(const char *idString)
Object * bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name)
COLLADASW::ColorOrTexture bc_get_specular(Material *ma)
COLLADASW::ColorOrTexture bc_get_ambient(Material *ma)
bool bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
void bc_copy_farray_m4(float *r, float a[4][4])
bool bc_is_root_bone(Bone *aBone, bool deform_bones_only)
double bc_get_alpha(Material *ma)
COLLADASW::ColorOrTexture bc_get_cot_from_shader(bNode *shader, std::string nodeid, Color &default_color, bool with_alpha)
float bc_get_property(Bone *bone, std::string key, float def)
void bc_add_global_transform(Matrix &to_mat, const Matrix &from_mat, const BCMatrix &global_transform, const bool invert)
bNode * bc_get_master_shader(Material *ma)
void bc_sanitize_v3(float v[3], int precision)
std::vector< bAction * > bc_getSceneActions(const bContext *C, Object *ob, bool all_actions)
COLLADASW::ColorOrTexture bc_get_cot(float r, float g, float b, float a)
IDProperty * bc_get_IDProperty(Bone *bone, std::string key)
bool bc_has_animations(Object *ob)
void bc_apply_global_transform(Matrix &to_mat, const BCMatrix &global_transform, const bool invert)
COLLADASW::ColorOrTexture bc_get_emission(Material *ma)
COLLADASW::ColorOrTexture bc_get_reflective(Material *ma)
static bool has_custom_props(Bone *bone, bool enabled, std::string key)
static std::string bc_get_uvlayer_name(Mesh *mesh, int layer)
bool isInteger(const std::string &s)
void bc_rotate_from_reference_quat(float quat_to[4], float quat_from[4], float mat_to[4][4])
double bc_get_reflectivity(Material *ma)
static void bc_add_armature_collections(COLLADAFW::Node *node, ExtraTags *node_extra_tags, bArmature *arm)
void bc_copy_m4d_v44(double(&r)[4][4], std::vector< std::vector< double > > &a)
void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene)
void bc_get_property_vector(Bone *bone, std::string key, float val[3], const float def[3])
Object * bc_get_assigned_armature(Object *ob)
void bc_add_default_shader(bContext *C, Material *ma)
Object * bc_add_armature(COLLADAFW::Node *node, ExtraTags *node_extra_tags, Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name)
static void bc_node_add_link(bNodeTree *ntree, bNode *from_node, int from_index, bNode *to_node, int to_index)
void bc_set_IDPropertyMatrix(EditBone *ebone, const char *key, float mat[4][4])
bool bc_is_animated(BCMatrixSampleMap &values)
void bc_triangulate_mesh(Mesh *mesh)
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_float_from_shader(bNode *shader, double &val, std::string nodeid)
int bc_get_active_UVLayer(Object *ob)
static std::string bc_get_active_uvlayer_name(Mesh *mesh)
void bc_bubble_sort_by_Object_name(LinkNode *export_set)
bool bc_validateConstraints(bConstraint *con)
Mesh * bc_get_mesh_copy(BlenderContext &blender_context, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
std::string bc_url_encode(std::string data)
double bc_get_shininess(Material *ma)
bool bc_get_property_matrix(Bone *bone, std::string key, float mat[4][4])
COLLADASW::ColorOrTexture bc_get_base_color(Material *ma)
static bNodeTree * prepare_material_nodetree(Material *ma)
double bc_get_ior(Material *ma)
static bNode * bc_add_node(bContext *C, bNodeTree *ntree, int node_type, int locx, int locy, std::string label)
int bc_set_layer(int bitfield, int layer)
void bc_copy_v44_m4d(std::vector< std::vector< double > > &r, double(&a)[4][4])
void bc_update_scene(BlenderContext &blender_context, float ctime)
std::string bc_replace_string(std::string data, const std::string &pattern, const std::string &replacement)
bool bc_bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim)
void bc_enable_fcurves(AnimData *adt, char *bone_name)
float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray &array, uint index)
void bc_copy_darray_m4d(double *r, double a[4][4])
void bc_decompose(float mat[4][4], float *loc, float eul[3], float quat[4], float *size)
void bc_copy_m4_farray(float r[4][4], float *a)
bool bc_has_object_type(LinkNode *export_set, short obtype)
std::string bc_get_action_id(std::string action_name, std::string ob_name, std::string channel_type, std::string axis_name, std::string axis_separator)
bool bc_is_leaf_bone(Bone *bone)
int bc_test_parent_loop(Object *par, Object *ob)
EditBone * bc_get_edit_bone(bArmature *armature, char *name)
const char * bc_CustomData_get_active_layer_name(const CustomData *data, eCustomDataType type)
AnimData * bc_getSceneLightAnimData(Object *ob)
AnimData * bc_getSceneCameraAnimData(Object *ob)
const char * bc_CustomData_get_layer_name(const CustomData *data, eCustomDataType type, int n)
void bc_set_IDProperty(EditBone *ebone, const char *key, float value)
bAction * bc_getSceneObjectAction(Object *ob)
AnimData * bc_getSceneMaterialAnimData(Material *ma)
std::map< std::string, BoneExtended * > BoneExtensionMap
local_group_size(16, 16) .push_constant(Type b
const Depsgraph * depsgraph
draw_view in_light_buf[] float
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Vector< FCurve * > fcurves_for_assigned_action(AnimData *adt)
bool assigned_action_has_keyframes(AnimData *adt)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRefNull prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
bNode * node_add_static_node(const bContext *C, bNodeTree *ntree, int type)
bNodeLink * node_add_link(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, bNode *tonode, bNodeSocket *tosock)
bNodeTree * node_tree_add_tree_embedded(Main *bmain, ID *owner_id, const char *name, const char *idname)
bNodeSocket * node_find_socket(bNode *node, eNodeSocketInOut in_out, StringRef identifier)
bool parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *const ob, Object *const par, int partype, bool xmirror, bool keep_transform, const int vert_par[3])
struct Collection * collection
struct bNodeTree * nodetree
ObjectRuntimeHandle * runtime
void(* evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets)
struct bPoseChannel * parent
ccl_device_inline int mod(int x, int m)