19 static std::map<std::string, std::vector<std::string>> BC_COLLADA_AXIS_FROM_TYPE = {
20 {
"color", {
"R",
"G",
"B"}},
21 {
"specular_color", {
"R",
"G",
"B"}},
22 {
"diffuse_color", {
"R",
"G",
"B"}},
23 {
"alpha", {
"R",
"G",
"B"}},
24 {
"scale", {
"X",
"Y",
"Z"}},
25 {
"location", {
"X",
"Y",
"Z"}},
26 {
"rotation_euler", {
"X",
"Y",
"Z"}}};
28 std::map<std::string, std::vector<std::string>>::const_iterator it;
30 it = BC_COLLADA_AXIS_FROM_TYPE.find(channel_type);
31 if (it == BC_COLLADA_AXIS_FROM_TYPE.end()) {
35 const std::vector<std::string> &subchannel = it->second;
36 if (
id >= subchannel.size()) {
39 return subchannel[
id];
54 std::vector<std::string> anim_meta_entry;
56 anim_meta_entry.push_back(action_name);
71 Scene *sce = export_settings.get_scene();
73 LinkNode *export_set = this->export_settings.get_export_set();
75 int animation_count = 0;
80 animation_count = animated_subset.size();
88 BCObjectSet::iterator it;
89 for (it = animated_subset.begin(); it != animated_subset.end(); ++it) {
94 catch (std::invalid_argument &iae) {
95 fprintf(stderr,
"Animation export interrupted");
96 fprintf(stderr,
"Exception was: %s", iae.what());
106 if (this->export_settings->include_all_actions) {
112 return animation_count;
117 bool container_is_open =
false;
126 bool export_as_matrix = this->export_settings.get_animation_transformation_type() ==
129 if (export_as_matrix) {
138 #ifdef WITH_MORPH_ANIMATION
155 bool export_as_matrix)
158 bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
160 BCAnimationCurveMap::iterator it;
163 std::string channel_type =
curve.get_channel_type();
164 if (channel_type ==
"rotation_quaternion") {
171 if (export_as_matrix &&
curve.is_transform_curve()) {
179 if (!keep_flat_curves && !
curve.is_animated()) {
196 bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
198 std::vector<float> frames;
199 sampler.get_object_frames(frames, ob);
200 if (!frames.empty()) {
202 bool is_animated =
sampler.get_object_samples(samples, ob);
203 if (keep_flat_curves || is_animated) {
206 std::string action_name = (action ==
nullptr) ? name +
"-action" :
id_name(action);
207 std::string channel_type =
"transform";
211 std::string target =
translate_id(name) +
'/' + channel_type;
215 id, name, target, frames, samples, global_rotation_type, ob->
parentinv);
222 bool is_export_root = this->export_settings.is_export_root(ob);
223 if (!is_export_root) {
227 bool apply_global_rotation = this->export_settings.get_apply_global_orientation();
236 bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
238 std::vector<float> frames;
239 sampler.get_bone_frames(frames, ob, bone);
241 if (!frames.empty()) {
243 bool is_animated =
sampler.get_bone_samples(samples, ob, bone);
244 if (keep_flat_curves || is_animated) {
258 std::string channel_type =
curve.get_channel_type();
260 if (channel_type ==
"lens") {
269 curve.get_value_map(lens_values);
273 BCAnimationCurveMap::iterator cit =
curves.find(sensor_key);
274 if (cit !=
curves.end()) {
275 sensor_curve = cit->second;
278 BCValueMap::const_iterator vit;
279 for (vit = lens_values.begin(); vit != lens_values.end(); ++vit) {
280 int frame = vit->first;
281 float lens_value = vit->second;
285 sensor_value = sensor_curve->
get_value(frame);
288 sensor_value = ((
Camera *)ob->
data)->sensor_x;
301 std::string channel_target =
curve.get_channel_target();
309 int channel_index =
curve.get_channel_index();
311 std::string channel_type =
curve.get_channel_type();
312 std::string axis =
get_axis_name(channel_type, channel_index);
314 std::string action_name;
316 action_name = (action) ?
id_name(action) :
"constraint_anim";
318 const std::string curve_name =
encode_xml(
curve.get_animation_name(ob));
319 std::string
id =
bc_get_action_id(action_name, curve_name, channel_target, axis,
".");
324 int material_index =
curve.get_subindex();
337 id, curve_name, collada_target, axis,
curve, global_rotation_type);
346 std::string bone_name(bone->
name);
353 id, name, target, frames, samples, global_rotation_type, ob->
parentinv);
380 std::string collada_target,
387 curve.get_frames(frames);
388 curve.get_values(values);
389 std::string channel_target =
curve.get_channel_target();
392 stdout,
"Export animation curve %s (%d control points)\n",
id.c_str(),
int(frames.size()));
393 openAnimation(
id, name);
400 source_type, COLLADASW::InputSemantic::OUTPUT, values,
id, axis);
402 bool has_tangents =
false;
403 std::string interpolation_id;
404 if (this->export_settings.get_keep_smooth_curves()) {
411 std::string intangent_id;
412 std::string outtangent_id;
415 COLLADASW::InputSemantic::IN_TANGENT,
curve,
id, axis);
417 COLLADASW::InputSemantic::OUT_TANGENT,
curve,
id, axis);
420 std::string sampler_id = std::string(
id) + SAMPLER_ID_SUFFIX;
422 COLLADASW::LibraryAnimations::Sampler
sampler(sw, sampler_id);
425 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(
EMPTY_STRING, output_id));
426 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION,
430 sampler.addInput(COLLADASW::InputSemantic::IN_TANGENT,
432 sampler.addInput(COLLADASW::InputSemantic::OUT_TANGENT,
437 addChannel(COLLADABU::URI(
EMPTY_STRING, sampler_id), collada_target);
452 stdout,
"Export animation matrix %s (%d control points)\n",
id.c_str(),
int(frames.size()));
461 std::string sampler_id = std::string(
id) + SAMPLER_ID_SUFFIX;
462 COLLADASW::LibraryAnimations::Sampler
sampler(sw, sampler_id);
465 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(
EMPTY_STRING, output_id));
466 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION,
472 addChannel(COLLADABU::URI(
EMPTY_STRING, sampler_id), target);
480 case COLLADASW::InputSemantic::INPUT:
481 return INPUT_SOURCE_ID_SUFFIX;
482 case COLLADASW::InputSemantic::OUTPUT:
483 return OUTPUT_SOURCE_ID_SUFFIX;
484 case COLLADASW::InputSemantic::INTERPOLATION:
485 return INTERPOLATION_SOURCE_ID_SUFFIX;
486 case COLLADASW::InputSemantic::IN_TANGENT:
487 return INTANGENT_SOURCE_ID_SUFFIX;
488 case COLLADASW::InputSemantic::OUT_TANGENT:
489 return OUTTANGENT_SOURCE_ID_SUFFIX;
497 COLLADASW::InputSemantic::Semantics semantic,
499 const std::string axis,
503 case COLLADASW::InputSemantic::INPUT:
504 param.push_back(
"TIME");
506 case COLLADASW::InputSemantic::OUTPUT:
508 param.push_back(
"ANGLE");
512 param.push_back(axis);
515 param.push_back(
"TRANSFORM");
519 param.push_back(
"X");
520 param.push_back(
"Y");
521 param.push_back(
"Z");
525 case COLLADASW::InputSemantic::IN_TANGENT:
526 case COLLADASW::InputSemantic::OUT_TANGENT:
527 param.push_back(
"X");
528 param.push_back(
"Y");
536 COLLADASW::InputSemantic::Semantics semantic,
538 const std::string &anim_id,
539 std::string axis_name)
541 Scene *
scene = this->export_settings.get_scene();
543 std::string channel =
curve.get_channel_target();
547 bool is_angle = (
bc_startswith(channel,
"rotation") || channel ==
"spot_size");
549 COLLADASW::FloatSourceF source(mSW);
550 source.setId(source_id);
551 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
552 source.setAccessorCount(
curve.sample_count());
553 source.setAccessorStride(2);
555 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
558 source.prepareToAppendValues();
561 int tangent = (semantic == COLLADASW::InputSemantic::IN_TANGENT) ? 0 : 2;
563 for (
int i = 0; i < fcu->
totvert; i++) {
566 float sampled_time = bezt.
vec[tangent][0];
567 float sampled_val = bezt.
vec[tangent][1];
570 sampled_val =
RAD2DEGF(sampled_val);
573 source.appendValues(
FRA2TIME(sampled_time));
574 source.appendValues(sampled_val);
582 COLLADASW::InputSemantic::Semantics semantic,
583 std::vector<float> &values,
584 const std::string &anim_id,
585 const std::string axis_name)
587 BlenderContext &blender_context = this->export_settings.get_blender_context();
592 int entry_count = values.size() /
stride;
595 COLLADASW::FloatSourceF source(mSW);
596 source.setId(source_id);
597 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
598 source.setAccessorCount(entry_count);
599 source.setAccessorStride(
stride);
601 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
604 source.prepareToAppendValues();
606 for (
int i = 0; i < entry_count; i++) {
607 float val = values[i];
608 switch (source_type) {
618 source.appendValues(val);
628 const std::string &anim_id,
632 COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
635 COLLADASW::Float4x4Source source(mSW);
636 source.setId(source_id);
637 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
638 source.setAccessorCount(samples.size());
639 source.setAccessorStride(16);
641 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
644 source.prepareToAppendValues();
646 BCMatrixSampleMap::iterator it;
648 int precision = (this->export_settings.get_limit_precision()) ? 6 : -1;
649 for (it = samples.begin(); it != samples.end(); it++) {
651 BCMatrix global_transform = this->export_settings.get_global_transform();
653 if (this->export_settings.get_apply_global_orientation()) {
654 sample.apply_transform(global_transform);
657 sample.add_transform(global_transform);
659 sample.get_matrix(daemat,
true, precision);
660 source.appendValues(daemat);
668 const std::string &anim_id,
669 const std::string axis,
672 std::string source_id = anim_id +
get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
674 COLLADASW::NameSource source(mSW);
675 source.setId(source_id);
676 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
677 source.setAccessorCount(
curve.sample_count());
678 source.setAccessorStride(1);
680 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
681 param.push_back(
"INTERPOLATION");
683 source.prepareToAppendValues();
685 *has_tangents =
false;
687 std::vector<float> frames;
688 curve.get_frames(frames);
690 for (
unsigned int i = 0; i <
curve.sample_count(); i++) {
691 float frame = frames[i];
692 int ipo =
curve.get_interpolation_type(frame);
694 source.appendValues(BEZIER_NAME);
695 *has_tangents =
true;
698 source.appendValues(STEP_NAME);
702 source.appendValues(LINEAR_NAME);
713 const std::string &anim_id)
715 std::string source_id = anim_id +
get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
717 COLLADASW::NameSource source(mSW);
718 source.setId(source_id);
719 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
720 source.setAccessorCount(tot);
721 source.setAccessorStride(1);
723 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
724 param.push_back(
"INTERPOLATION");
726 source.prepareToAppendValues();
728 for (
int i = 0; i < tot; i++) {
729 source.appendValues(LINEAR_NAME);
745 static std::map<std::string, std::string> BC_CHANNEL_BLENDER_TO_COLLADA = {
746 {
"rotation",
"rotation"},
747 {
"rotation_euler",
"rotation"},
748 {
"rotation_quaternion",
"rotation"},
750 {
"location",
"location"},
753 {
"specular_color",
"specular"},
754 {
"diffuse_color",
"diffuse"},
755 {
"ior",
"index_of_refraction"},
756 {
"specular_hardness",
"specular_hardness"},
761 {
"fall_off_angle",
"falloff_angle"},
762 {
"spot_size",
"falloff_angle"},
763 {
"fall_off_exponent",
"falloff_exponent"},
764 {
"spot_blend",
"falloff_exponent"},
766 {
"blender/blender_dist",
"blender/blender_dist"},
768 {
"distance",
"blender/blender_dist"},
776 {
"ortho_scale",
"xmag"},
777 {
"clip_end",
"zfar"},
778 {
"clip_start",
"znear"}};
780 std::map<std::string, std::string>::iterator name_it = BC_CHANNEL_BLENDER_TO_COLLADA.find(
782 if (name_it == BC_CHANNEL_BLENDER_TO_COLLADA.end()) {
785 std::string tm_name = name_it->second;
790 const std::string axis_name)
792 std::string channel_target =
curve.get_channel_target();
793 std::string channel_type =
curve.get_channel_type();
796 bool is_angle =
curve.is_rotation_curve();
798 if (!tm_name.empty()) {
800 return tm_name + std::string(axis_name) +
".ANGLE";
802 if (!axis_name.empty()) {
803 return tm_name +
"." + std::string(axis_name);
812 #ifdef WITH_MORPH_ANIMATION
827 BC_animation_transform_type tm_type = get_transform_type(fcu->
rna_path);
829 create_keyframed_animation(ob, fcu, tm_type,
true,
sampler);
@ BC_SOURCE_TYPE_TIMEFRAME
std::vector< float > BCValues
std::map< int, float > BCValueMap
@ BC_ANIMATION_TYPE_MATERIAL
@ BC_ANIMATION_TYPE_CAMERA
std::map< BCCurveKey, BCAnimationCurve * > BCAnimationCurveMap
std::vector< float > BCFrames
std::map< int, const BCMatrix * > BCMatrixSampleMap
struct Key * BKE_key_from_object(struct Object *ob)
struct Material * BKE_object_material_get(struct Object *ob, short act)
float focallength_to_fov(float focal_length, float sensor)
@ BC_TRANSFORMATION_TYPE_MATRIX
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
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 Bright Control the brightness and contrast of the input color Vector Map an input vectors to curves
SIMD_FORCE_INLINE btVector3 transform(const btVector3 &point) const
void exportAnimationClips(Scene *sce)
void export_collada_matrix_animation(std::string id, std::string name, std::string target, BCFrames &frames, BCMatrixSampleMap &samples, BC_global_rotation_type global_rotation_type, Matrix &parentinv)
std::string get_axis_name(std::string channel, int id)
std::string collada_interpolation_source(const BCAnimationCurve &curve, const std::string &anim_id, std::string axis_name, bool *has_tangents)
void add_source_parameters(COLLADASW::SourceBase::ParameterNameList ¶m, COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const std::string axis, bool transform)
void close_animation_container(bool has_container)
void openAnimationWithClip(std::string id, std::string name)
bool open_animation_container(bool has_container, Object *ob)
void export_collada_curve_animation(std::string id, std::string name, std::string target, std::string axis, BCAnimationCurve &curve, BC_global_rotation_type global_rotation_type)
void exportAnimation(Object *ob, BCAnimationSampler &sampler)
void export_matrix_animation(Object *ob, BCAnimationSampler &sampler)
void export_curve_animation_set(Object *ob, BCAnimationSampler &sampler, bool export_as_matrix)
bool is_bone_deform_group(Bone *bone)
void export_bone_animations_recursive(Object *ob_arm, Bone *bone, BCAnimationSampler &sampler)
void export_bone_animation(Object *ob, Bone *bone, BCFrames &frames, BCMatrixSampleMap &samples)
BCAnimationCurve * get_modified_export_curve(Object *ob, BCAnimationCurve &curve, BCAnimationCurveMap &curves)
void export_curve_animation(Object *ob, BCAnimationCurve &curve)
void export_morph_animation(Object *ob)
std::string get_collada_name(std::string channel_type) const
std::string collada_linear_interpolation_source(int tot, const std::string &anim_id)
std::string get_collada_sid(const BCAnimationCurve &curve, const std::string axis_name)
std::vector< std::vector< std::string > > anim_meta
std::string get_semantic_suffix(COLLADASW::InputSemantic::Semantics semantic)
std::string collada_tangent_from_curve(COLLADASW::InputSemantic::Semantics semantic, BCAnimationCurve &curve, const std::string &anim_id, const std::string axis_name)
std::string collada_source_from_values(BC_animation_source_type source_type, COLLADASW::InputSemantic::Semantics semantic, std::vector< float > &values, const std::string &anim_id, const std::string axis_name)
float get_value(float frame)
void add_value(float val, int frame)
static void get_animated_from_export_set(std::set< Object * > &animated_objects, LinkNode &export_set)
void sample_scene(BCExportSettings &export_settings, bool keyframe_at_end)
std::string translate_id(const char *idString)
std::string encode_xml(std::string xml)
std::string id_name(void *id)
bool bc_has_animations(Object *ob)
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)
std::set< Object * > BCObjectSet
bAction * bc_getSceneObjectAction(Object *ob)
bool bc_startswith(std::string const &value, std::string const &starting)
depth_tx sampler(1, ImageType::FLOAT_2D, "combined_tx") .sampler(2