33 : export_settings(export_settings)
35 BCObjectSet::iterator it;
36 for (it = object_set.begin(); it != object_set.end(); ++it) {
44 BCAnimationObjectMap::iterator it;
45 for (it = objects.begin(); it != objects.end(); ++it) {
53 BlenderContext blender_context = export_settings.get_blender_context();
55 objects[ob] = animation;
57 initialize_keyframes(animation->
frame_set, ob);
58 initialize_curves(animation->
curve_map, ob);
65 initialize_curves(animation.
curve_map, ob);
75 sample_frames.clear();
77 if (sampling_rate < 1) {
81 float sfra = scene->
r.
sfra;
82 float efra = scene->
r.
efra;
85 for (frame_index = nearbyint(sfra); frame_index < efra; frame_index += sampling_rate) {
86 sample_frames.insert(frame_index);
89 if (frame_index >= efra && keyframe_at_end) {
90 sample_frames.insert(efra);
103 for (
int i = 0;
i < fcu->totvert; bezt++,
i++) {
104 int frame_index = nearbyint(bezt->
vec[1][0]);
105 frameset.insert(frame_index);
110void BCAnimationSampler::check_property_is_animated(
111 BCAnimation &animation,
float *ref,
float *val, std::string data_path,
int length)
113 for (
int array_index = 0; array_index <
length; array_index++) {
116 BCAnimationCurveMap::iterator it = animation.
curve_map.find(key);
124void BCAnimationSampler::update_animation_curves(
BCAnimation &animation,
129 BCAnimationCurveMap::iterator it;
131 BCAnimationCurve *curve = it->second;
141BCSample &BCAnimationSampler::sample_object(
Object *ob,
int frame_index,
bool for_opensim)
143 BCSample &ob_sample = sample_data.add(ob, frame_index);
145 if (export_settings.get_apply_global_orientation()) {
146 const BCMatrix &global_transform = export_settings.get_global_transform();
153 Bone *bone = pchan->bone;
166 BlenderContext blender_context = export_settings.get_blender_context();
167 int sampling_rate = export_settings.get_sampling_rate();
168 bool for_opensim = export_settings.get_open_sim();
169 bool keep_keyframes = export_settings.get_keep_keyframes();
176 int startframe = scene->
r.
sfra;
177 int endframe = scene->
r.
efra;
179 for (
int frame_index = startframe; frame_index <= endframe; frame_index++) {
181 bool is_scene_sample_frame =
false;
182 bool needs_update =
true;
183 if (scene_sample_frames.find(frame_index) != scene_sample_frames.end()) {
185 needs_update =
false;
186 is_scene_sample_frame =
true;
189 bool needs_sampling = is_scene_sample_frame || keep_keyframes ||
191 if (!needs_sampling) {
195 BCAnimationObjectMap::iterator obit;
196 for (obit = objects.begin(); obit != objects.end(); ++obit) {
200 if (is_scene_sample_frame || object_keyframes.find(frame_index) != object_keyframes.end()) {
204 needs_update =
false;
208 update_animation_curves(*animation,
sample, ob, frame_index);
216 std::set<Object *> &animated_objects)
219 ListBase targets = {
nullptr,
nullptr};
232 if (animated_objects.find(obtar) != animated_objects.end()) {
246 std::set<Object *> &candidates)
251 std::set<Object *>::iterator it;
252 for (it = candidates.begin(); it != candidates.end(); ++it) {
256 animated_objects.insert(cob);
257 candidates.erase(cob);
262 }
while (found_more && !candidates.empty());
274 animated_objects.clear();
275 std::set<Object *> candidates;
278 for (node = &export_set; node; node = node->
next) {
281 animated_objects.insert(cob);
286 candidates.insert(cob);
295 sample_data.get_frames(ob, frames);
300 sample_data.get_frames(ob, bone, frames);
305 sample_data.get_matrices(ob, bone, samples);
311 sample_data.get_matrices(ob, samples);
332 int array_index = curve.get_array_index();
333 const BC_animation_transform_type tm_type = curve.get_transform_type();
335 BCFrameSampleMap::iterator it;
336 for (it = samples.begin(); it != samples.end(); ++it) {
337 const int frame_index = nearbyint(it->first);
345 if (subindex == -1) {
346 good =
sample->get_value(tm_type, array_index, &val);
349 good =
sample->get_value(tm_type, array_index, &val, subindex);
357 curve.remove_unused_keyframes();
362void BCAnimationSampler::generate_transform(
Object *ob,
366 BCAnimationCurveMap::const_iterator it = curves.find(key);
367 if (it == curves.end()) {
368 curves[key] =
new BCAnimationCurve(key, ob);
372void BCAnimationSampler::generate_transforms(
Object *ob,
373 const std::string prep,
377 generate_transform(ob, BCCurveKey(type, prep +
"location", 0), curves);
378 generate_transform(ob, BCCurveKey(type, prep +
"location", 1), curves);
379 generate_transform(ob, BCCurveKey(type, prep +
"location", 2), curves);
380 generate_transform(ob, BCCurveKey(type, prep +
"rotation_euler", 0), curves);
381 generate_transform(ob, BCCurveKey(type, prep +
"rotation_euler", 1), curves);
382 generate_transform(ob, BCCurveKey(type, prep +
"rotation_euler", 2), curves);
383 generate_transform(ob, BCCurveKey(type, prep +
"scale", 0), curves);
384 generate_transform(ob, BCCurveKey(type, prep +
"scale", 1), curves);
385 generate_transform(ob, BCCurveKey(type, prep +
"scale", 2), curves);
390 std::string prep =
"pose.bones[\"" + std::string(bone->
name) +
"\"].";
394 generate_transforms(ob, child, curves);
398void BCAnimationSampler::initialize_keyframes(
BCFrameSet &frameset,
Object *ob)
405 for (
int a = 0; a < ob->
totcol; a++) {
425 BCCurveKey key(object_type, fcu->rna_path, fcu->array_index);
426 curves[key] =
new BCAnimationCurve(key, ob, fcu);
431 generate_transforms(ob,
EMPTY_STRING, object_type, curves);
435 generate_transforms(ob, root_bone, curves);
452 BCCurveKey key(object_type, fcu->rna_path, fcu->array_index);
453 curves[key] =
new BCAnimationCurve(key, ob, fcu);
458 for (
int a = 0; a < ob->
totcol; a++) {
465 BCCurveKey key(object_type, fcu->rna_path, fcu->array_index, a);
466 curves[key] =
new BCAnimationCurve(key, ob, fcu);
483 BCSampleMap::const_iterator it = sampleMap.find(ob);
484 if (it == sampleMap.end()) {
492 BCSampleMap::const_iterator it = sampleMap.find(ob);
493 if (it == sampleMap.end()) {
497 return &
sample->get_matrix();
502 BCSampleMap::const_iterator it = sampleMap.find(ob);
503 if (it == sampleMap.end()) {
514 return sampleMap.find(ob) != sampleMap.end();
528 return frame.
add(ob);
537 BCSampleFrameMap::iterator it = sample_frames.find(frame_index);
545 BCSampleFrameMap::const_iterator it;
546 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
547 frames.push_back(it->first);
549 return frames.size();
555 BCSampleFrameMap::const_iterator it;
556 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
559 frames.push_back(it->first);
562 return frames.size();
568 BCSampleFrameMap::const_iterator it;
569 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
572 frames.push_back(it->first);
575 return frames.size();
581 BCSampleFrameMap::const_iterator it;
582 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
586 samples[it->first] =
sample;
589 return samples.size();
595 BCSampleFrameMap::const_iterator it;
596 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
600 samples[it->first] = matrix;
603 return samples.size();
609 BCSampleFrameMap::const_iterator it;
610 for (it = sample_frames.begin(); it != sample_frames.end(); ++it) {
614 samples[it->first] =
sample;
617 return samples.size();
Functions for backward compatibility with the legacy Action API.
std::set< float > BCFrameSet
std::map< BCCurveKey, BCAnimationCurve * > BCAnimationCurveMap
std::vector< float > BCFrames
@ BC_ANIMATION_TYPE_MATERIAL
@ BC_ANIMATION_TYPE_LIGHT
@ BC_ANIMATION_TYPE_OBJECT
@ BC_ANIMATION_TYPE_CAMERA
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)
std::map< int, const BCMatrix * > BCMatrixSampleMap
std::map< int, const BCSample * > BCFrameSampleMap
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.
Material * BKE_object_material_get(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)
struct bPoseChannel bPoseChannel
struct bArmature bArmature
@ BC_ANIMATION_EXPORT_KEYS
@ BC_ANIMATION_EXPORT_SAMPLES
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
void add_value(float val, int frame)
bool add_value_from_matrix(const BCSample &sample, int frame)
bool is_keyframe(int frame)
bool is_transform_curve() const
bool add_value_from_rna(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)
BCAnimationCurveMap curve_map
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)
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)
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)
std::set< Object * > BCObjectSet
float length(VecOp< float, D >) RET
Vector< FCurve * > fcurves_for_assigned_action(AnimData *adt)
ListBase * constraint_active_list(Object *ob)