37 : export_settings(export_settings)
39 BCObjectSet::iterator it;
40 for (it = object_set.begin(); it != object_set.end(); ++it) {
48 BCAnimationObjectMap::iterator it;
49 for (it = objects.begin(); it != objects.end(); ++it) {
57 BlenderContext blender_context = export_settings.get_blender_context();
59 objects[ob] = animation;
61 initialize_keyframes(animation->frame_set, ob);
62 initialize_curves(animation->curve_map, ob);
68 if (animation.curve_map.empty()) {
69 initialize_curves(animation.curve_map, ob);
71 return &animation.curve_map;
79 sample_frames.clear();
81 if (sampling_rate < 1) {
85 float sfra = scene->r.sfra;
86 float efra = scene->r.efra;
89 for (frame_index = nearbyint(sfra); frame_index < efra; frame_index += sampling_rate) {
90 sample_frames.insert(frame_index);
93 if (frame_index >= efra && keyframe_at_end) {
94 sample_frames.insert(efra);
107 for (
int i = 0; i < fcu->totvert; bezt++, i++) {
108 int frame_index = nearbyint(bezt->
vec[1][0]);
109 frameset.insert(frame_index);
114void BCAnimationSampler::check_property_is_animated(
115 BCAnimation &animation,
float *ref,
float *val, std::string data_path,
int length)
117 for (
int array_index = 0; array_index <
length; array_index++) {
118 if (!
bc_in_range(ref[length], val[length], 0.00001)) {
120 BCAnimationCurveMap::iterator it = animation.curve_map.find(key);
121 if (it == animation.curve_map.end()) {
122 animation.curve_map[key] =
new BCAnimationCurve(key, animation.get_reference());
128void BCAnimationSampler::update_animation_curves(
BCAnimation &animation,
133 BCAnimationCurveMap::iterator it;
134 for (it = animation.curve_map.begin(); it != animation.curve_map.end(); ++it) {
136 if (curve->is_transform_curve()) {
140 curve->add_value_from_rna(frame);
145BCSample &BCAnimationSampler::sample_object(
Object *ob,
int frame_index,
bool for_opensim)
147 BCSample &ob_sample = sample_data.
add(ob, frame_index);
149 if (export_settings.get_apply_global_orientation()) {
150 const BCMatrix &global_transform = export_settings.get_global_transform();
157 Bone *bone = pchan->bone;
170 BlenderContext blender_context = export_settings.get_blender_context();
171 int sampling_rate = export_settings.get_sampling_rate();
172 bool for_opensim = export_settings.get_open_sim();
173 bool keep_keyframes = export_settings.get_keep_keyframes();
176 Scene *scene = blender_context.get_scene();
180 int startframe = scene->r.sfra;
181 int endframe = scene->r.efra;
183 for (
int frame_index = startframe; frame_index <= endframe; frame_index++) {
185 bool is_scene_sample_frame =
false;
186 bool needs_update =
true;
187 if (scene_sample_frames.find(frame_index) != scene_sample_frames.end()) {
189 needs_update =
false;
190 is_scene_sample_frame =
true;
193 bool needs_sampling = is_scene_sample_frame || keep_keyframes ||
195 if (!needs_sampling) {
199 BCAnimationObjectMap::iterator obit;
200 for (obit = objects.begin(); obit != objects.end(); ++obit) {
204 if (is_scene_sample_frame || object_keyframes.find(frame_index) != object_keyframes.end()) {
208 needs_update =
false;
212 update_animation_curves(*animation,
sample, ob, frame_index);
220 std::set<Object *> &animated_objects)
223 ListBase targets = {
nullptr,
nullptr};
236 if (animated_objects.find(obtar) != animated_objects.end()) {
250 std::set<Object *> &candidates)
255 std::set<Object *>::iterator it;
256 for (it = candidates.begin(); it != candidates.end(); ++it) {
260 animated_objects.insert(cob);
261 candidates.erase(cob);
266 }
while (found_more && !candidates.empty());
278 animated_objects.clear();
279 std::set<Object *> candidates;
282 for (node = &export_set;
node; node = node->
next) {
285 animated_objects.insert(cob);
290 candidates.insert(cob);
336 int array_index = curve.get_array_index();
337 const BC_animation_transform_type tm_type = curve.get_transform_type();
339 BCFrameSampleMap::iterator it;
340 for (it = samples.begin(); it != samples.end(); ++it) {
341 const int frame_index = nearbyint(it->first);
347 int subindex = curve.get_subindex();
349 if (subindex == -1) {
353 good =
sample->get_value(tm_type, array_index, &val, subindex);
357 curve.add_value(val, frame_index);
361 curve.remove_unused_keyframes();
366void BCAnimationSampler::generate_transform(
Object *ob,
370 BCAnimationCurveMap::const_iterator it = curves.find(key);
371 if (it == curves.end()) {
376void BCAnimationSampler::generate_transforms(
Object *ob,
377 const std::string prep,
381 generate_transform(ob,
BCCurveKey(type, prep +
"location", 0), curves);
382 generate_transform(ob,
BCCurveKey(type, prep +
"location", 1), curves);
383 generate_transform(ob,
BCCurveKey(type, prep +
"location", 2), curves);
384 generate_transform(ob,
BCCurveKey(type, prep +
"rotation_euler", 0), curves);
385 generate_transform(ob,
BCCurveKey(type, prep +
"rotation_euler", 1), curves);
386 generate_transform(ob,
BCCurveKey(type, prep +
"rotation_euler", 2), curves);
387 generate_transform(ob,
BCCurveKey(type, prep +
"scale", 0), curves);
388 generate_transform(ob,
BCCurveKey(type, prep +
"scale", 1), curves);
389 generate_transform(ob,
BCCurveKey(type, prep +
"scale", 2), curves);
394 std::string prep =
"pose.bones[\"" + std::string(bone->
name) +
"\"].";
398 generate_transforms(ob, child, curves);
402void BCAnimationSampler::initialize_keyframes(
BCFrameSet &frameset,
Object *ob)
409 for (
int a = 0; a < ob->
totcol; a++) {
429 BCCurveKey key(object_type, fcu->rna_path, fcu->array_index);
435 generate_transforms(ob,
EMPTY_STRING, object_type, curves);
439 generate_transforms(ob, root_bone, curves);
456 BCCurveKey key(object_type, fcu->rna_path, fcu->array_index);
462 for (
int a = 0; a < ob->
totcol; a++) {
469 BCCurveKey key(object_type, fcu->rna_path, fcu->array_index, a);
487 BCSampleMap::const_iterator it = sampleMap.find(ob);
488 if (it == sampleMap.end()) {
496 BCSampleMap::const_iterator it = sampleMap.find(ob);
497 if (it == sampleMap.end()) {
506 BCSampleMap::const_iterator it = sampleMap.find(ob);
507 if (it == sampleMap.end()) {
518 return sampleMap.find(ob) != sampleMap.end();
532 return frame.
add(ob);
541 BCSampleFrameMap::iterator it = sample_frames.find(frame_index);
542 BCSampleFrame *frame = (it == sample_frames.end()) ?
nullptr : &it->second;
549 BCSampleFrameMap::const_iterator it;
550 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
551 frames.push_back(it->first);
553 return frames.size();
559 BCSampleFrameMap::const_iterator it;
560 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
563 frames.push_back(it->first);
566 return frames.size();
572 BCSampleFrameMap::const_iterator it;
573 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
576 frames.push_back(it->first);
579 return frames.size();
585 BCSampleFrameMap::const_iterator it;
586 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
590 samples[it->first] =
sample;
593 return samples.size();
599 BCSampleFrameMap::const_iterator it;
600 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
604 samples[it->first] = matrix;
607 return samples.size();
613 BCSampleFrameMap::const_iterator it;
614 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
618 samples[it->first] =
sample;
621 return samples.size();
Functions for backward compatibility with the legacy Action API.
@ BC_ANIMATION_TYPE_MATERIAL
@ BC_ANIMATION_TYPE_LIGHT
@ BC_ANIMATION_TYPE_OBJECT
@ BC_ANIMATION_TYPE_CAMERA
std::map< BCCurveKey, BCAnimationCurve * > BCAnimationCurveMap
std::vector< float > BCFrames
std::set< float > BCFrameSet
static BCAnimationCurveMap BCEmptyAnimationCurves
static void add_keyframes_from(AnimData *adt, BCFrameSet &frameset)
static bool is_object_keyframe(Object *ob, int frame_index)
static void get_sample_frames(BCFrameSet &sample_frames, int sampling_rate, bool keyframe_at_end, Scene *scene)
static std::string EMPTY_STRING
std::map< int, const BCSample * > BCFrameSampleMap
std::map< int, const BCMatrix * > BCMatrixSampleMap
Blender kernel action and pose functionality.
void BKE_constraint_targets_flush(struct bConstraint *con, struct ListBase *targets, bool no_copy)
int BKE_constraint_targets_get(struct bConstraint *con, struct ListBase *r_targets)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
#define LISTBASE_FOREACH(type, var, list)
bool bool BLI_str_quoted_substr(const char *__restrict str, const char *__restrict prefix, char *result, size_t result_maxncpy)
@ BC_ANIMATION_EXPORT_KEYS
@ BC_ANIMATION_EXPORT_SAMPLES
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
bool add_value_from_matrix(const BCSample &sample, int frame)
void get_object_frames(BCFrames &frames, Object *ob)
static void find_depending_animated(std::set< Object * > &animated_objects, std::set< Object * > &candidates)
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)
BCAnimationSampler(BCExportSettings &export_settings, BCObjectSet &object_set)
void add_object(Object *ob)
void sample_scene(BCExportSettings &export_settings, bool keyframe_at_end)
static bool is_animated_by_constraint(Object *ob, ListBase *conlist, std::set< Object * > &animated_objects)
bool get_object_samples(BCMatrixSampleMap &samples, Object *ob)
BCAnimationCurveMap * get_curves(Object *ob)
void get_matrix(DMatrix &matrix, bool transposed=false, int precision=-1) const
BCSample & add(Object *ob, int frame_index)
int get_frames(std::vector< int > &frames) const
BCSampleFrame * get_frame(int frame_index)
int get_samples(Object *ob, BCFrameSampleMap &samples) const
int get_matrices(Object *ob, BCMatrixSampleMap &samples) const
const BCMatrix * get_sample_matrix(Object *ob) const
bool has_sample_for(Object *ob) const
const BCSample * get_sample(Object *ob) const
BCSample & add(Object *ob)
bool get_value(std::string channel_target, int array_index, float *val) const
const BCMatrix & get_matrix() const
void add_bone_matrix(Bone *bone, Matrix &mat)
bool bc_has_animations(Object *ob)
bool bc_is_animated(BCMatrixSampleMap &values)
bool bc_validateConstraints(bConstraint *con)
void bc_update_scene(BlenderContext &blender_context, float ctime)
bool bc_bone_matrix_local_get(Object *ob, Bone *bone, Matrix &mat, bool for_opensim)
std::set< Object * > BCObjectSet
AnimData * bc_getSceneLightAnimData(Object *ob)
AnimData * bc_getSceneCameraAnimData(Object *ob)
bool bc_in_range(float a, float b, float range)
AnimData * bc_getSceneMaterialAnimData(Material *ma)
Vector< FCurve * > fcurves_for_assigned_action(AnimData *adt)
ListBase * constraint_active_list(Object *ob)