33 static std::map<std::string, std::vector<std::string>> BC_COLLADA_AXIS_FROM_TYPE = {
34 {
"color", {
"R",
"G",
"B"}},
35 {
"specular_color", {
"R",
"G",
"B"}},
36 {
"diffuse_color", {
"R",
"G",
"B"}},
37 {
"alpha", {
"R",
"G",
"B"}},
38 {
"scale", {
"X",
"Y",
"Z"}},
39 {
"location", {
"X",
"Y",
"Z"}},
40 {
"rotation_euler", {
"X",
"Y",
"Z"}}};
42 std::map<std::string, std::vector<std::string>>::const_iterator it;
44 it = BC_COLLADA_AXIS_FROM_TYPE.find(channel_type);
45 if (it == BC_COLLADA_AXIS_FROM_TYPE.end()) {
49 const std::vector<std::string> &subchannel = it->second;
50 if (
id >= subchannel.size()) {
53 return subchannel[
id];
68 std::vector<std::string> anim_meta_entry;
70 anim_meta_entry.push_back(action_name);
85 Scene *sce = export_settings.get_scene();
87 LinkNode *export_set = this->export_settings.get_export_set();
89 int animation_count = 0;
94 animation_count = animated_subset.size();
102 BCObjectSet::iterator it;
103 for (it = animated_subset.begin(); it != animated_subset.end(); ++it) {
108 catch (std::invalid_argument &iae) {
109 fprintf(stderr,
"Animation export interrupted");
110 fprintf(stderr,
"Exception was: %s", iae.what());
120 if (this->export_settings->include_all_actions) {
126 return animation_count;
132 bool container_is_open =
false;
141 bool export_as_matrix = this->export_settings.get_animation_transformation_type() ==
144 if (export_as_matrix) {
153 #ifdef WITH_MORPH_ANIMATION
180 bool export_as_matrix)
183 bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
185 BCAnimationCurveMap::iterator it;
186 for (it = curves->begin(); it != curves->end(); ++it) {
188 std::string channel_type =
curve.get_channel_type();
189 if (channel_type ==
"rotation_quaternion") {
196 if (export_as_matrix &&
curve.is_transform_curve()) {
204 if (!keep_flat_curves && !
curve.is_animated()) {
221 bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
223 std::vector<float> frames;
225 if (!frames.empty()) {
228 if (keep_flat_curves || is_animated) {
231 std::string action_name = (action ==
nullptr) ? name +
"-action" :
id_name(action);
232 std::string channel_type =
"transform";
236 std::string target =
translate_id(name) +
'/' + channel_type;
240 id, name, target, frames, samples, global_rotation_type, ob->
parentinv);
247 bool is_export_root = this->export_settings.is_export_root(ob);
248 if (!is_export_root) {
252 bool apply_global_rotation = this->export_settings.get_apply_global_orientation();
262 bool keep_flat_curves = this->export_settings.get_keep_flat_curves();
264 std::vector<float> frames;
267 if (!frames.empty()) {
270 if (keep_flat_curves || is_animated) {
292 std::string channel_type =
curve.get_channel_type();
294 if (channel_type ==
"lens") {
303 curve.get_value_map(lens_values);
307 BCAnimationCurveMap::iterator cit = curves.find(sensor_key);
308 if (cit != curves.end()) {
309 sensor_curve = cit->second;
312 BCValueMap::const_iterator vit;
313 for (vit = lens_values.begin(); vit != lens_values.end(); ++vit) {
314 int frame = vit->first;
315 float lens_value = vit->second;
319 sensor_value = sensor_curve->
get_value(frame);
322 sensor_value = ((
Camera *)ob->
data)->sensor_x;
335 std::string channel_target =
curve.get_channel_target();
343 int channel_index =
curve.get_channel_index();
345 std::string channel_type =
curve.get_channel_type();
346 std::string axis =
get_axis_name(channel_type, channel_index);
348 std::string action_name;
350 action_name = (action) ?
id_name(action) :
"constraint_anim";
352 const std::string curve_name =
encode_xml(
curve.get_animation_name(ob));
353 std::string
id =
bc_get_action_id(action_name, curve_name, channel_target, axis,
".");
358 int material_index =
curve.get_subindex();
371 id, curve_name, collada_target, axis,
curve, global_rotation_type);
380 std::string bone_name(bone->
name);
387 id, name, target, frames, samples, global_rotation_type, ob->
parentinv);
414 std::string collada_target,
421 curve.get_frames(frames);
422 curve.get_values(values);
423 std::string channel_target =
curve.get_channel_target();
426 stdout,
"Export animation curve %s (%d control points)\n",
id.c_str(),
int(frames.size()));
427 openAnimation(
id, name);
434 source_type, COLLADASW::InputSemantic::OUTPUT, values,
id, axis);
436 bool has_tangents =
false;
437 std::string interpolation_id;
438 if (this->export_settings.get_keep_smooth_curves()) {
445 std::string intangent_id;
446 std::string outtangent_id;
449 COLLADASW::InputSemantic::IN_TANGENT,
curve,
id, axis);
451 COLLADASW::InputSemantic::OUT_TANGENT,
curve,
id, axis);
454 std::string sampler_id = std::string(
id) + SAMPLER_ID_SUFFIX;
456 COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
458 sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(
EMPTY_STRING, input_id));
459 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(
EMPTY_STRING, output_id));
460 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION,
464 sampler.addInput(COLLADASW::InputSemantic::IN_TANGENT,
466 sampler.addInput(COLLADASW::InputSemantic::OUT_TANGENT,
471 addChannel(COLLADABU::URI(
EMPTY_STRING, sampler_id), collada_target);
486 stdout,
"Export animation matrix %s (%d control points)\n",
id.c_str(),
int(frames.size()));
495 std::string sampler_id = std::string(
id) + SAMPLER_ID_SUFFIX;
496 COLLADASW::LibraryAnimations::Sampler sampler(sw, sampler_id);
498 sampler.addInput(COLLADASW::InputSemantic::INPUT, COLLADABU::URI(
EMPTY_STRING, input_id));
499 sampler.addInput(COLLADASW::InputSemantic::OUTPUT, COLLADABU::URI(
EMPTY_STRING, output_id));
500 sampler.addInput(COLLADASW::InputSemantic::INTERPOLATION,
506 addChannel(COLLADABU::URI(
EMPTY_STRING, sampler_id), target);
514 case COLLADASW::InputSemantic::INPUT:
515 return INPUT_SOURCE_ID_SUFFIX;
516 case COLLADASW::InputSemantic::OUTPUT:
517 return OUTPUT_SOURCE_ID_SUFFIX;
518 case COLLADASW::InputSemantic::INTERPOLATION:
519 return INTERPOLATION_SOURCE_ID_SUFFIX;
520 case COLLADASW::InputSemantic::IN_TANGENT:
521 return INTANGENT_SOURCE_ID_SUFFIX;
522 case COLLADASW::InputSemantic::OUT_TANGENT:
523 return OUTTANGENT_SOURCE_ID_SUFFIX;
531 COLLADASW::InputSemantic::Semantics semantic,
533 const std::string axis,
537 case COLLADASW::InputSemantic::INPUT:
538 param.push_back(
"TIME");
540 case COLLADASW::InputSemantic::OUTPUT:
542 param.push_back(
"ANGLE");
546 param.push_back(axis);
549 param.push_back(
"TRANSFORM");
553 param.push_back(
"X");
554 param.push_back(
"Y");
555 param.push_back(
"Z");
559 case COLLADASW::InputSemantic::IN_TANGENT:
560 case COLLADASW::InputSemantic::OUT_TANGENT:
561 param.push_back(
"X");
562 param.push_back(
"Y");
570 COLLADASW::InputSemantic::Semantics semantic,
572 const std::string &anim_id,
573 std::string axis_name)
575 Scene *
scene = this->export_settings.get_scene();
577 std::string channel =
curve.get_channel_target();
581 bool is_angle = (
bc_startswith(channel,
"rotation") || channel ==
"spot_size");
583 COLLADASW::FloatSourceF source(mSW);
584 source.setId(source_id);
585 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
586 source.setAccessorCount(
curve.sample_count());
587 source.setAccessorStride(2);
589 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
592 source.prepareToAppendValues();
595 int tangent = (semantic == COLLADASW::InputSemantic::IN_TANGENT) ? 0 : 2;
597 for (
int i = 0; i < fcu->
totvert; i++) {
600 float sampled_time = bezt.
vec[tangent][0];
601 float sampled_val = bezt.
vec[tangent][1];
604 sampled_val =
RAD2DEGF(sampled_val);
607 source.appendValues(
FRA2TIME(sampled_time));
608 source.appendValues(sampled_val);
616 COLLADASW::InputSemantic::Semantics semantic,
617 std::vector<float> &values,
618 const std::string &anim_id,
619 const std::string axis_name)
621 BlenderContext &blender_context = this->export_settings.get_blender_context();
626 int entry_count = values.size() /
stride;
629 COLLADASW::FloatSourceF source(mSW);
630 source.setId(source_id);
631 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
632 source.setAccessorCount(entry_count);
633 source.setAccessorStride(
stride);
635 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
638 source.prepareToAppendValues();
640 for (
int i = 0; i < entry_count; i++) {
641 float val = values[i];
642 switch (source_type) {
652 source.appendValues(val);
665 const std::string &anim_id,
669 COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
672 COLLADASW::Float4x4Source source(mSW);
673 source.setId(source_id);
674 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
675 source.setAccessorCount(samples.size());
676 source.setAccessorStride(16);
678 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
681 source.prepareToAppendValues();
683 BCMatrixSampleMap::iterator it;
685 int precision = (this->export_settings.get_limit_precision()) ? 6 : -1;
686 for (it = samples.begin(); it != samples.end(); it++) {
688 BCMatrix global_transform = this->export_settings.get_global_transform();
690 if (this->export_settings.get_apply_global_orientation()) {
691 sample.apply_transform(global_transform);
694 sample.add_transform(global_transform);
696 sample.get_matrix(daemat,
true, precision);
697 source.appendValues(daemat);
705 const std::string &anim_id,
706 const std::string axis,
709 std::string source_id = anim_id +
get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
711 COLLADASW::NameSource source(mSW);
712 source.setId(source_id);
713 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
714 source.setAccessorCount(
curve.sample_count());
715 source.setAccessorStride(1);
717 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
718 param.push_back(
"INTERPOLATION");
720 source.prepareToAppendValues();
722 *has_tangents =
false;
724 std::vector<float> frames;
725 curve.get_frames(frames);
727 for (
unsigned int i = 0; i <
curve.sample_count(); i++) {
728 float frame = frames[i];
729 int ipo =
curve.get_interpolation_type(frame);
731 source.appendValues(BEZIER_NAME);
732 *has_tangents =
true;
735 source.appendValues(STEP_NAME);
739 source.appendValues(LINEAR_NAME);
750 const std::string &anim_id)
752 std::string source_id = anim_id +
get_semantic_suffix(COLLADASW::InputSemantic::INTERPOLATION);
754 COLLADASW::NameSource source(mSW);
755 source.setId(source_id);
756 source.setArrayId(source_id + ARRAY_ID_SUFFIX);
757 source.setAccessorCount(tot);
758 source.setAccessorStride(1);
760 COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
761 param.push_back(
"INTERPOLATION");
763 source.prepareToAppendValues();
765 for (
int i = 0; i < tot; i++) {
766 source.appendValues(LINEAR_NAME);
782 static std::map<std::string, std::string> BC_CHANNEL_BLENDER_TO_COLLADA = {
783 {
"rotation",
"rotation"},
784 {
"rotation_euler",
"rotation"},
785 {
"rotation_quaternion",
"rotation"},
787 {
"location",
"location"},
790 {
"specular_color",
"specular"},
791 {
"diffuse_color",
"diffuse"},
792 {
"ior",
"index_of_refraction"},
793 {
"specular_hardness",
"specular_hardness"},
798 {
"fall_off_angle",
"falloff_angle"},
799 {
"spot_size",
"falloff_angle"},
800 {
"fall_off_exponent",
"falloff_exponent"},
801 {
"spot_blend",
"falloff_exponent"},
803 {
"blender/blender_dist",
"blender/blender_dist"},
805 {
"distance",
"blender/blender_dist"},
813 {
"ortho_scale",
"xmag"},
814 {
"clip_end",
"zfar"},
815 {
"clip_start",
"znear"}};
817 std::map<std::string, std::string>::iterator name_it = BC_CHANNEL_BLENDER_TO_COLLADA.find(
819 if (name_it == BC_CHANNEL_BLENDER_TO_COLLADA.end()) {
822 std::string tm_name = name_it->second;
831 const std::string axis_name)
833 std::string channel_target =
curve.get_channel_target();
834 std::string channel_type =
curve.get_channel_type();
837 bool is_angle =
curve.is_rotation_curve();
839 if (!tm_name.empty()) {
841 return tm_name + std::string(axis_name) +
".ANGLE";
843 if (!axis_name.empty()) {
844 return tm_name +
"." + std::string(axis_name);
853 #ifdef WITH_MORPH_ANIMATION
868 BC_animation_transform_type tm_type = get_transform_type(fcu->
rna_path);
870 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(const 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
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(const float frame)
void add_value(const float val, const int frame)
void get_object_frames(BCFrames &frames, Object *ob)
bool get_bone_samples(BCMatrixSampleMap &samples, Object *ob, Bone *bone)
static void get_animated_from_export_set(std::set< Object * > &animated_objects, LinkNode &export_set)
void get_bone_frames(BCFrames &frames, Object *ob, Bone *bone)
void sample_scene(BCExportSettings &export_settings, bool keyframe_at_end)
bool get_object_samples(BCMatrixSampleMap &samples, Object *ob)
BCAnimationCurveMap * get_curves(Object *ob)
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)
static void sample(SocketReader *reader, int x, int y, float color[4])