Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGaia Clary <gaia.clary@machinimatrix.org>2018-02-27 00:49:30 +0300
committerGaia Clary <gaia.clary@machinimatrix.org>2018-02-27 00:49:30 +0300
commitf228a08d027ef700344d35f1ba958249afa93222 (patch)
treefc6c60d89f911bcb0c5019e2e6e4243e49cba9af /source/blender/collada
parente94276d4033c72000942a49100e552e800d09e58 (diff)
parent7dd0e36dc4582e57a3f5235f384b5207882c923e (diff)
merge from master
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/AnimationExporter.cpp195
-rw-r--r--source/blender/collada/AnimationExporter.h9
-rw-r--r--source/blender/collada/ControllerExporter.cpp2
-rw-r--r--source/blender/collada/DocumentExporter.cpp28
-rw-r--r--source/blender/collada/DocumentExporter.h2
-rw-r--r--source/blender/collada/ExportSettings.h1
-rw-r--r--source/blender/collada/SceneExporter.cpp7
-rw-r--r--source/blender/collada/SceneExporter.h5
-rw-r--r--source/blender/collada/collada.cpp65
-rw-r--r--source/blender/collada/collada.h54
-rw-r--r--source/blender/collada/collada_utils.cpp189
-rw-r--r--source/blender/collada/collada_utils.h8
12 files changed, 420 insertions, 145 deletions
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index 24e5ecb8d10..a1497a0ab44 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -34,7 +34,7 @@ void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
}
}
-bool AnimationExporter::exportAnimations(const struct EvaluationContext *eval_ctx, Scene *sce)
+bool AnimationExporter::exportAnimations(EvaluationContext *eval_ctx, Scene *sce)
{
bool has_animations = hasAnimations(sce);
if (has_animations) {
@@ -50,7 +50,16 @@ bool AnimationExporter::exportAnimations(const struct EvaluationContext *eval_ct
return has_animations;
}
-
+bool AnimationExporter::is_flat_line(std::vector<float> &values, int channel_count)
+{
+ for (int i = 0; i < values.size(); i += channel_count) {
+ for (int j = 0; j < channel_count; j++) {
+ if (!bc_in_range(values[j], values[i+j], 0.000001))
+ return false;
+ }
+ }
+ return true;
+}
/*
* This function creates a complete LINEAR Collada <Animation> Entry with all needed
* <source>, <sampler>, and <channel> entries.
@@ -84,9 +93,11 @@ void AnimationExporter::create_sampled_animation(int channel_count,
std::string axis_name,
bool is_rot)
{
-
char anim_id[200];
+ if (is_flat_line(values, channel_count))
+ return;
+
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(), label.c_str(), axis_name.c_str());
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
@@ -98,8 +109,10 @@ void AnimationExporter::create_sampled_animation(int channel_count,
std::string output_id;
if (channel_count == 1)
output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, &values[0], values.size(), is_rot, anim_id, axis_name.c_str());
- else if(channel_count = 3)
+ else if (channel_count == 3)
output_id = create_xyz_source(&values[0], times.size(), anim_id);
+ else if (channel_count == 16)
+ output_id = create_4x4_source(times, values, anim_id);
std::string sampler_id = std::string(anim_id) + SAMPLER_ID_SUFFIX;
COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
@@ -136,26 +149,38 @@ void AnimationExporter::create_sampled_animation(int channel_count,
void AnimationExporter::export_keyframed_animation_set(Object *ob)
{
FCurve *fcu = (FCurve *)ob->adt->action->curves.first;
+ if (!fcu) {
+ return; /* object has no animation */
+ }
- char *transformName;
- while (fcu) {
- //for armature animations as objects
- if (ob->type == OB_ARMATURE)
- transformName = fcu->rna_path;
- else
- transformName = extract_transform_name(fcu->rna_path);
+ if (this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) {
- if (
- STREQ(transformName, "location") ||
- STREQ(transformName, "scale") ||
- (STREQ(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL) ||
- STREQ(transformName, "rotation_quaternion"))
- {
- create_keyframed_animation(ob, fcu, transformName, false);
- }
- fcu = fcu->next;
+ std::vector<float> ctimes;
+ std::vector<float[4][4]> values;
+ find_keyframes(ob, ctimes);
+ if (ctimes.size() > 0)
+ export_sampled_matrix_animation(ob, ctimes);
}
+ else {
+ char *transformName;
+ while (fcu) {
+ //for armature animations as objects
+ if (ob->type == OB_ARMATURE)
+ transformName = fcu->rna_path;
+ else
+ transformName = extract_transform_name(fcu->rna_path);
+ if (
+ STREQ(transformName, "location") ||
+ STREQ(transformName, "scale") ||
+ (STREQ(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL) ||
+ STREQ(transformName, "rotation_quaternion"))
+ {
+ create_keyframed_animation(ob, fcu, transformName, false);
+ }
+ fcu = fcu->next;
+ }
+ }
}
/*
@@ -172,19 +197,52 @@ void AnimationExporter::export_keyframed_animation_set(Object *ob)
*/
void AnimationExporter::export_sampled_animation_set(Object *ob)
{
+ std::vector<float>ctimes;
+ find_sampleframes(ob, ctimes);
+ if (ctimes.size() > 0) {
+ if (this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX)
+ export_sampled_matrix_animation(ob, ctimes);
+ else
+ export_sampled_transrotloc_animation(ob, ctimes);
+ }
+}
+
+void AnimationExporter::export_sampled_matrix_animation(Object *ob, std::vector<float> &ctimes)
+{
+ UnitConverter converter;
+
+ std::vector<float> values;
+
+ for (std::vector<float>::iterator ctime = ctimes.begin(); ctime != ctimes.end(); ++ctime) {
+ float fmat[4][4];
+ float outmat[4][4];
+
+ bc_update_scene(eval_ctx, scene, *ctime);
+ BKE_object_matrix_local_get(ob, fmat);
+ converter.mat4_to_dae(outmat, fmat);
+
+ if (this->export_settings->limit_precision)
+ bc_sanitize_mat(outmat, 6);
+
+ for (int i = 0; i < 4; i++)
+ for (int j = 0; j < 4; j++)
+ values.push_back(outmat[j][i]);
+ }
+
+ std::string ob_name = id_name(ob);
+
+ create_sampled_animation(16, ctimes, values, ob_name, "transform", "", false);
+}
+
+void AnimationExporter::export_sampled_transrotloc_animation(Object *ob, std::vector<float> &ctimes)
+{
static int LOC = 0;
static int EULX = 1;
static int EULY = 2;
static int EULZ = 3;
static int SCALE = 4;
- static int TIME = 5;
- if (this->export_settings->sampling_rate < 1)
- return; // to avoid infinite loop
-
- std::vector<float> baked_curves[6];
- std::vector<float> &ctimes = baked_curves[TIME];
- find_sampleframes(ob, ctimes);
+ std::vector<float> baked_curves[5];
for (std::vector<float>::iterator ctime = ctimes.begin(); ctime != ctimes.end(); ++ctime ) {
float fmat[4][4];
@@ -193,7 +251,7 @@ void AnimationExporter::export_sampled_animation_set(Object *ob)
float fsize[3];
float feul[3];
- evaluate_anim_with_constraints(ob, *ctime); // set object transforms to the frame
+ bc_update_scene(eval_ctx, scene, *ctime);
BKE_object_matrix_local_get(ob, fmat);
mat4_decompose(floc, fquat, fsize, fmat);
@@ -215,16 +273,16 @@ void AnimationExporter::export_sampled_animation_set(Object *ob)
std::string ob_name = id_name(ob);
- create_sampled_animation(3, baked_curves[TIME], baked_curves[SCALE], ob_name, "scale", "", false);
- create_sampled_animation(3, baked_curves[TIME], baked_curves[LOC], ob_name, "location", "", false);
+ create_sampled_animation(3, ctimes, baked_curves[SCALE], ob_name, "scale", "", false);
+ create_sampled_animation(3, ctimes, baked_curves[LOC], ob_name, "location", "", false);
/* Not sure how to export rotation as a 3channel animation,
* so separate into 3 single animations for now:
*/
- create_sampled_animation(1, baked_curves[TIME], baked_curves[EULX], ob_name, "rotation", "X", true);
- create_sampled_animation(1, baked_curves[TIME], baked_curves[EULY], ob_name, "rotation", "Y", true);
- create_sampled_animation(1, baked_curves[TIME], baked_curves[EULZ], ob_name, "rotation", "Z", true);
+ create_sampled_animation(1, ctimes, baked_curves[EULX], ob_name, "rotation", "X", true);
+ create_sampled_animation(1, ctimes, baked_curves[EULY], ob_name, "rotation", "Y", true);
+ create_sampled_animation(1, ctimes, baked_curves[EULZ], ob_name, "rotation", "Z", true);
fprintf(stdout, "Animation Export: Baked %zd frames for %s (sampling rate: %d)\n",
baked_curves[0].size(),
@@ -243,19 +301,19 @@ void AnimationExporter::operator()(Object *ob)
if (ob->adt && ob->adt->action) {
if (ob->type == OB_ARMATURE) {
+ /* Export skeletal animation (if any)*/
bArmature *arm = (bArmature *)ob->data;
for (Bone *bone = (Bone *)arm->bonebase.first; bone; bone = bone->next)
write_bone_animation_matrix(ob, bone);
}
+
+ /* Armatures can have object animation and skeletal animation*/
+ if (this->export_settings->sampling_rate < 1) {
+ export_keyframed_animation_set(ob);
+ }
else {
- if (this->export_settings->sampling_rate == -1) {
- export_keyframed_animation_set(ob);
- }
- else {
- export_sampled_animation_set(ob);
- }
+ export_sampled_animation_set(ob);
}
-
}
export_object_constraint_animation(ob);
@@ -1187,9 +1245,51 @@ std::string AnimationExporter::create_source_from_vector(COLLADASW::InputSemanti
return source_id;
}
+std::string AnimationExporter::create_4x4_source(std::vector<float> &ctimes, std::vector<float> &values , const std::string &anim_id)
+{
+ COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
+ std::string source_id = anim_id + get_semantic_suffix(semantic);
+
+ COLLADASW::Float4x4Source source(mSW);
+ source.setId(source_id);
+ source.setArrayId(source_id + ARRAY_ID_SUFFIX);
+ source.setAccessorCount(ctimes.size());
+ source.setAccessorStride(16);
+
+ COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
+ add_source_parameters(param, semantic, false, NULL, true);
+
+ source.prepareToAppendValues();
+
+ bPoseChannel *parchan = NULL;
+ bPoseChannel *pchan = NULL;
+
+
+ std::vector<float>::iterator it;
+
+ for (it = values.begin(); it != values.end(); it+=16) {
+ float mat[4][4];
+
+ bc_copy_m4_farray(mat, &*it);
+
+ UnitConverter converter;
+ double outmat[4][4];
+ converter.mat4_to_dae_double(outmat, mat);
+
+ if (this->export_settings->limit_precision)
+ bc_sanitize_mat(outmat, 6);
+
+ source.appendValues(outmat);
+ }
+
+ source.finish();
+ return source_id;
+}
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Object *ob, Bone *bone, const std::string &anim_id)
{
+ bool is_bone_animation = ob->type == OB_ARMATURE && bone;
+
COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
std::string source_id = anim_id + get_semantic_suffix(semantic);
@@ -1207,7 +1307,7 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj
bPoseChannel *parchan = NULL;
bPoseChannel *pchan = NULL;
- if (ob->type == OB_ARMATURE && bone) {
+ if (is_bone_animation) {
bPose *pose = ob->pose;
pchan = BKE_pose_channel_find_name(pose, bone->name);
if (!pchan)
@@ -1224,12 +1324,10 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj
float mat[4][4], ipar[4][4];
float frame = *it;
- float ctime = BKE_scene_frame_get_from_ctime(scene, *it);
- CFRA = BKE_scene_frame_get_from_ctime(scene, *it);
- //BKE_scene_graph_update_for_newframe(G.main->eval_ctx, depsgraph, G.main,scene);
- BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL);
-
- if (bone) {
+ float ctime = BKE_scene_frame_get_from_ctime(scene, frame);
+ bc_update_scene(eval_ctx, scene, ctime);
+ if (is_bone_animation) {
+
if (pchan->flag & POSE_CHAIN) {
enable_fcurves(ob->adt->action, NULL);
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL);
@@ -1269,9 +1367,6 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj
}
else {
- BKE_scene_frame_set(scene, ctime);
- Main *bmain = bc_get_main();
- BKE_animsys_evaluate_all_animation(bmain, scene, ctime);
copy_m4_m4(mat, ob->obmat);
}
diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h
index 3bb510e51d6..1e0f434ca13 100644
--- a/source/blender/collada/AnimationExporter.h
+++ b/source/blender/collada/AnimationExporter.h
@@ -85,7 +85,7 @@ class AnimationExporter: COLLADASW::LibraryAnimations
{
private:
Scene *scene;
- const struct EvaluationContext *eval_ctx;
+ EvaluationContext *eval_ctx;
COLLADASW::StreamWriter *sw;
public:
@@ -97,7 +97,7 @@ public:
this->sw = sw;
}
- bool exportAnimations(const struct EvaluationContext *eval_ctx, Scene *sce);
+ bool exportAnimations(EvaluationContext *eval_ctx, Scene *sce);
// called for each exported object
void operator() (Object *ob);
@@ -145,9 +145,12 @@ protected:
float* get_eul_source_for_quat(Object *ob );
+ bool is_flat_line(std::vector<float> &values, int channel_count);
void export_keyframed_animation_set(Object *ob);
void create_keyframed_animation(Object *ob, FCurve *fcu, char *transformName, bool is_param, Material *ma = NULL);
void export_sampled_animation_set(Object *ob);
+ void export_sampled_transrotloc_animation(Object *ob, std::vector<float> &ctimes);
+ void export_sampled_matrix_animation(Object *ob, std::vector<float> &ctimes);
void create_sampled_animation(int channel_count, std::vector<float> &times, std::vector<float> &values, std::string, std::string label, std::string axis_name, bool is_rot);
void evaluate_anim_with_constraints(Object *ob, float ctime);
@@ -162,7 +165,7 @@ protected:
std::string create_source_from_vector(COLLADASW::InputSemantic::Semantics semantic, std::vector<float> &fra, bool is_rot, const std::string& anim_id, const char *axis_name);
std::string create_xyz_source(float *v, int tot, const std::string& anim_id);
-
+ std::string create_4x4_source(std::vector<float> &times, std::vector<float> &values, const std::string& anim_id);
std::string create_4x4_source(std::vector<float> &frames, Object * ob_arm, Bone *bone, const std::string& anim_id);
std::string create_interpolation_source(FCurve *fcu, const std::string& anim_id, const char *axis_name, bool *has_tangents);
diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp
index f413651167c..ae99e6bafde 100644
--- a/source/blender/collada/ControllerExporter.cpp
+++ b/source/blender/collada/ControllerExporter.cpp
@@ -280,7 +280,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
}
if (oob_counter > 0) {
- fprintf(stderr, "Ignored %d Vertex weights which use index to non existing VGroup %lu.\n",
+ fprintf(stderr, "Ignored %d Vertex weights which use index to non existing VGroup %zu.\n",
oob_counter, joint_index_by_def_index.size());
}
}
diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp
index 1741312af5f..0e020c9011b 100644
--- a/source/blender/collada/DocumentExporter.cpp
+++ b/source/blender/collada/DocumentExporter.cpp
@@ -179,7 +179,7 @@ static COLLADABU::NativeString make_temp_filepath(const char *name, const char *
// COLLADA allows this through multiple <channel>s in <animation>.
// For this to work, we need to know objects that use a certain action.
-int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scene *sce)
+int DocumentExporter::exportCurrentScene(EvaluationContext *eval_ctx, Scene *sce)
{
PointerRNA sceneptr, unit_settings;
PropertyRNA *system; /* unused , *scale; */
@@ -300,29 +300,11 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen
SceneExporter se(writer, &arm_exporter, this->export_settings);
- // <library_animations>
- AnimationExporter ae(writer, this->export_settings);
-
-#if 0
- bool has_animations = ae.exportAnimations(eval_ctx, sce);
- /* The following code seems to be an obsolete workaround
- Comment out until it proofs correct that we no longer need it.
- */
- if (has_animations && this->export_settings->export_transformation_type == BC_TRANSFORMATION_TYPE_MATRIX) {
- // channels adressing <matrix> objects is not (yet) supported
- // So we force usage of <location>, <translation> and <scale>
- fprintf(stdout,
- "For animated Ojects we must use decomposed <matrix> elements,\n" \
- "Forcing usage of TransLocRot transformation type.");
- se.setExportTransformationType(BC_TRANSFORMATION_TYPE_TRANSROTLOC);
+ if (this->export_settings->include_animations) {
+ // <library_animations>
+ AnimationExporter ae(writer, this->export_settings);
+ ae.exportAnimations(eval_ctx, sce);
}
- else {
- se.setExportTransformationType(this->export_settings->export_transformation_type);
- }
-#else
- ae.exportAnimations(eval_ctx, sce);
- se.setExportTransformationType(this->export_settings->export_transformation_type);
-#endif
se.exportScene(eval_ctx, sce);
// <scene>
diff --git a/source/blender/collada/DocumentExporter.h b/source/blender/collada/DocumentExporter.h
index 895787c7bbc..b2d8214212c 100644
--- a/source/blender/collada/DocumentExporter.h
+++ b/source/blender/collada/DocumentExporter.h
@@ -39,7 +39,7 @@ class DocumentExporter
{
public:
DocumentExporter(const ExportSettings *export_settings);
- int exportCurrentScene(const struct EvaluationContext *eval_ctx, Scene *sce);
+ int exportCurrentScene(EvaluationContext *eval_ctx, Scene *sce);
void exportScenes(const char *filename);
private:
const ExportSettings *export_settings;
diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h
index 0483449e513..620ccedd544 100644
--- a/source/blender/collada/ExportSettings.h
+++ b/source/blender/collada/ExportSettings.h
@@ -40,6 +40,7 @@ public:
bool include_armatures;
bool include_shapekeys;
bool deform_bones_only;
+ bool include_animations;
int sampling_rate;
bool active_uv_only;
diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp
index c375c09d869..3a6386a8721 100644
--- a/source/blender/collada/SceneExporter.cpp
+++ b/source/blender/collada/SceneExporter.cpp
@@ -39,11 +39,6 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm,
{
}
-void SceneExporter::setExportTransformationType(BC_export_transformation_type transformation_type)
-{
- this->transformation_type = transformation_type;
-}
-
void SceneExporter::exportScene(const EvaluationContext *eval_ctx, Scene *sce)
{
// <library_visual_scenes> <visual_scene>
@@ -139,7 +134,7 @@ void SceneExporter::writeNodes(const EvaluationContext *eval_ctx, Object *ob, Sc
// for skinned mesh we write obmat in <bind_shape_matrix>
TransformWriter::add_node_transform_identity(colladaNode);
else {
- TransformWriter::add_node_transform_ob(colladaNode, ob, this->transformation_type);
+ TransformWriter::add_node_transform_ob(colladaNode, ob, this->export_settings->export_transformation_type);
}
// <instance_geometry>
diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h
index ded48983bd9..3e3c15b836f 100644
--- a/source/blender/collada/SceneExporter.h
+++ b/source/blender/collada/SceneExporter.h
@@ -96,12 +96,9 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter,
{
public:
SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings);
- void exportScene(const struct EvaluationContext *eval_ctx, Scene *sce);
- void setExportTransformationType(BC_export_transformation_type transformation_type);
+ void exportScene(const EvaluationContext *eval_ctx, Scene *sce);
private:
- BC_export_transformation_type transformation_type;
- // required for writeNodes() for bone-parented objects
friend class ArmatureExporter;
void exportHierarchy(const struct EvaluationContext *eval_ctx, Scene *sce);
void writeNodes(const struct EvaluationContext *eval_ctx, Object *ob, Scene *sce);
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index 286444882e4..04b828d35f9 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -32,6 +32,7 @@
#include "DocumentImporter.h"
#include "ExportSettings.h"
#include "ImportSettings.h"
+#include "collada.h"
extern "C"
{
@@ -68,38 +69,38 @@ int collada_import(bContext *C,
return 0;
}
-int collada_export(bContext *C,
- const char *filepath,
-
- int apply_modifiers,
- BC_export_mesh_type export_mesh_type,
-
- int selected,
- int include_children,
- int include_armatures,
- int include_shapekeys,
- int deform_bones_only,
- int sampling_rate,
-
- int active_uv_only,
- int include_material_textures,
- int use_texture_copies,
-
- int triangulate,
- int use_object_instantiation,
- int use_blender_profile,
- int sort_by_name,
- BC_export_transformation_type export_transformation_type,
- int open_sim,
- int limit_precision,
- int keep_bind_info)
+int collada_export(
+ EvaluationContext *eval_ctx,
+ Scene *sce,
+ const char *filepath,
+
+ int apply_modifiers,
+ BC_export_mesh_type export_mesh_type,
+
+ int selected,
+ int include_children,
+ int include_armatures,
+ int include_shapekeys,
+ int deform_bones_only,
+ int include_animations,
+ int sampling_rate,
+
+ int active_uv_only,
+ int include_material_textures,
+ int use_texture_copies,
+
+ int triangulate,
+ int use_object_instantiation,
+ int use_blender_profile,
+ int sort_by_name,
+ BC_export_transformation_type export_transformation_type,
+ int open_sim,
+ int limit_precision,
+ int keep_bind_info)
{
ExportSettings export_settings;
- EvaluationContext eval_ctx;
- CTX_data_eval_ctx(C, &eval_ctx);
- Scene *sce = CTX_data_scene(C);
- ViewLayer *view_layer = CTX_data_view_layer(C);
+ ViewLayer *view_layer = eval_ctx->view_layer;
export_settings.filepath = (char *)filepath;
@@ -110,7 +111,8 @@ int collada_export(bContext *C,
export_settings.include_armatures = include_armatures != 0;
export_settings.include_shapekeys = include_shapekeys != 0;
export_settings.deform_bones_only = deform_bones_only != 0;
- export_settings.sampling_rate = sampling_rate;
+ export_settings.include_animations = include_animations;
+ export_settings.sampling_rate = sampling_rate;
export_settings.active_uv_only = active_uv_only != 0;
export_settings.include_material_textures= include_material_textures != 0;
@@ -130,7 +132,6 @@ int collada_export(bContext *C,
if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
-
export_settings.export_set = BKE_object_relational_superset(view_layer, objectSet, (eObRelationTypes)includeFilter);
int export_count = BLI_linklist_count(export_settings.export_set);
@@ -149,7 +150,7 @@ int collada_export(bContext *C,
}
DocumentExporter exporter(&export_settings);
- int status = exporter.exportCurrentScene(&eval_ctx, sce);
+ int status = exporter.exportCurrentScene(eval_ctx, sce);
BLI_linklist_free(export_settings.export_set, NULL);
diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h
index 89853b8849f..47272255012 100644
--- a/source/blender/collada/collada.h
+++ b/source/blender/collada/collada.h
@@ -64,31 +64,35 @@ int collada_import(struct bContext *C,
int keep_bind_info);
-int collada_export(struct bContext *C,
- const char *filepath,
- int apply_modifiers,
- BC_export_mesh_type export_mesh_type,
-
- int selected,
- int include_children,
- int include_armatures,
- int include_shapekeys,
- int deform_bones_only,
- int sampling_rate,
-
- int active_uv_only,
- int include_material_textures,
- int use_texture_copies,
-
- int triangulate,
- int use_object_instantiation,
- int use_blender_profile,
- int sort_by_name,
- BC_export_transformation_type export_transformation_type,
-
- int open_sim,
- int limit_precision,
- int keep_bind_info);
+int collada_export(
+ EvaluationContext *eval_ctx,
+ Scene *sce,
+ const char *filepath,
+
+ int apply_modifiers,
+ BC_export_mesh_type export_mesh_type,
+
+ int selected,
+ int include_children,
+ int include_armatures,
+ int include_shapekeys,
+ int deform_bones_only,
+ int include_animations,
+ int sampling_rate,
+
+ int active_uv_only,
+ int include_material_textures,
+ int use_texture_copies,
+
+ int triangulate,
+ int use_object_instantiation,
+ int use_blender_profile,
+ int sort_by_name,
+ BC_export_transformation_type export_transformation_type,
+
+ int open_sim,
+ int limit_precision,
+ int keep_bind_info);
#ifdef __cplusplus
}
diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp
index 99eca373e4e..d30f8e82590 100644
--- a/source/blender/collada/collada_utils.cpp
+++ b/source/blender/collada/collada_utils.cpp
@@ -32,6 +32,8 @@
#include "COLLADAFWMeshPrimitive.h"
#include "COLLADAFWMeshVertexData.h"
+#include <set>
+
extern "C" {
#include "DNA_modifier_types.h"
#include "DNA_customdata_types.h"
@@ -152,6 +154,15 @@ EvaluationContext *bc_get_evaluation_context()
return bmain->eval_ctx;
}
+
+void bc_update_scene(EvaluationContext *eval_ctx, Scene *scene, float ctime)
+{
+ BKE_scene_frame_set(scene, ctime);
+ Main *bmain = bc_get_main();
+ EvaluationContext *ev_context = bc_get_evaluation_context();
+ BKE_scene_graph_update_for_newframe(eval_ctx, eval_ctx->depsgraph, bmain, scene, eval_ctx->view_layer);
+}
+
Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name)
{
Object *ob = BKE_object_add_only_object(G.main, type, name);
@@ -895,3 +906,181 @@ void bc_sanitize_mat(double mat[4][4], int precision)
mat[i][j] = double_round(mat[i][j], precision);
}
+void bc_copy_m4_farray(float r[4][4], float *a)
+{
+ for (int i = 0; i < 4; i++)
+ for (int j = 0; j < 4; j++)
+ r[i][j] = *a++;
+}
+
+void bc_copy_farray_m4(float *r, float a[4][4])
+{
+ for (int i = 0; i < 4; i++)
+ for (int j = 0; j < 4; j++)
+ *r++ = a[i][j];
+
+}
+
+/*
+ * Returns name of Active UV Layer or empty String if no active UV Layer defined
+ */
+std::string bc_get_active_uvlayer_name(Mesh *me)
+{
+ int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
+ if (num_layers) {
+ char *layer_name = bc_CustomData_get_active_layer_name(&me->fdata, CD_MTFACE);
+ if (layer_name) {
+ return std::string(layer_name);
+ }
+ }
+ return "";
+}
+
+/*
+* Returns name of Active UV Layer or empty String if no active UV Layer defined.
+* Assuming the Object is of type MESH
+*/
+std::string bc_get_active_uvlayer_name(Object *ob)
+{
+ Mesh *me = (Mesh *)ob->data;
+ return bc_get_active_uvlayer_name(me);
+}
+
+/*
+ * Returns UV Layer name or empty string if layer index is out of range
+ */
+std::string bc_get_uvlayer_name(Mesh *me, int layer)
+{
+ int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
+ if (num_layers && layer < num_layers) {
+ char *layer_name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, layer);
+ if (layer_name) {
+ return std::string(layer_name);
+ }
+ }
+ return "";
+}
+
+#if 0
+/**********************************************************************
+*
+* Return the list of Mesh objects with assigned UVtextures and Images
+* Note: We need to create artificaial materials for each of them
+*
+***********************************************************************/
+std::set<Object *> bc_getUVTexturedObjects(Scene *sce, bool all_uv_layers)
+{
+ std::set <Object *> UVObjects;
+ Base *base = (Base *)sce->base.first;
+
+ while (base) {
+ Object *ob = base->object;
+ bool has_uvimage = false;
+ if (ob->type == OB_MESH) {
+ Mesh *me = (Mesh *)ob->data;
+ int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
+
+ for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) {
+ if (all_uv_layers || active_uv_layer == i)
+ {
+ if (me->pdata.layers[i].type == CD_MTEXPOLY) {
+ MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
+ MPoly *mpoly = me->mpoly;
+ for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
+
+ Image *ima = txface->tpage;
+ if (ima != NULL) {
+ has_uvimage = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (has_uvimage) {
+ UVObjects.insert(ob);
+ }
+ }
+ base = base->next;
+ }
+ return UVObjects;
+}
+
+/**********************************************************************
+*
+* Return the list of UV Texture images from all exported Mesh Items
+* Note: We need to create one artificial material for each Image.
+*
+***********************************************************************/
+std::set<Image *> bc_getUVImages(Scene *sce, bool all_uv_layers)
+{
+ std::set <Image *> UVImages;
+ Base *base = (Base *)sce->base.first;
+
+ while (base) {
+ Object *ob = base->object;
+ bool has_uvimage = false;
+ if (ob->type == OB_MESH) {
+ Mesh *me = (Mesh *)ob->data;
+ int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
+
+ for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) {
+ if (all_uv_layers || active_uv_layer == i)
+ {
+ if (me->pdata.layers[i].type == CD_MTEXPOLY) {
+ MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
+ MPoly *mpoly = me->mpoly;
+ for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
+
+ Image *ima = txface->tpage;
+ if (ima != NULL) {
+ if (UVImages.find(ima) == UVImages.end())
+ UVImages.insert(ima);
+ }
+ }
+ }
+ }
+ }
+ }
+ base = base->next;
+ }
+ return UVImages;
+}
+
+/**********************************************************************
+*
+* Return the list of UV Texture images for the given Object
+* Note: We need to create one artificial material for each Image.
+*
+***********************************************************************/
+std::set<Image *> bc_getUVImages(Object *ob, bool all_uv_layers)
+{
+ std::set <Image *> UVImages;
+
+ bool has_uvimage = false;
+ if (ob->type == OB_MESH) {
+ Mesh *me = (Mesh *)ob->data;
+ int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
+
+ for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) {
+ if (all_uv_layers || active_uv_layer == i)
+ {
+ if (me->pdata.layers[i].type == CD_MTEXPOLY) {
+ MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
+ MPoly *mpoly = me->mpoly;
+ for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
+
+ Image *ima = txface->tpage;
+ if (ima != NULL) {
+ if (UVImages.find(ima) == UVImages.end())
+ UVImages.insert(ima);
+ }
+ }
+ }
+ }
+ }
+ }
+ return UVImages;
+}
+#endif
diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h
index 43fcdf66dce..cdc7b99722d 100644
--- a/source/blender/collada/collada_utils.h
+++ b/source/blender/collada/collada_utils.h
@@ -67,6 +67,7 @@ typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureA
extern Scene *bc_get_scene(bContext *C);
extern Main *bc_get_main();
extern EvaluationContext *bc_get_evaluation_context();
+extern void bc_update_scene(EvaluationContext *eval_ctx, Scene *scene, float ctime);
extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index);
extern int bc_test_parent_loop(Object *par, Object *ob);
@@ -104,6 +105,13 @@ extern bool bc_is_leaf_bone(Bone *bone);
extern EditBone *bc_get_edit_bone(bArmature * armature, char *name);
extern int bc_set_layer(int bitfield, int layer, bool enable);
extern int bc_set_layer(int bitfield, int layer);
+
+inline bool bc_in_range(float a, float b, float range) {
+ return abs(a - b) < range;
+}
+void bc_copy_m4_farray(float r[4][4], float *a);
+void bc_copy_farray_m4(float *r, float a[4][4]);
+
extern void bc_sanitize_mat(float mat[4][4], int precision);
extern void bc_sanitize_mat(double mat[4][4], int precision);