Pass BakeOptions to every bake instead of rounding bools
RootBakeOptions moves into the model as BakeOptions, used by frame and track bakes and root transforms.
This commit is contained in:
1 parent
f9dcfb8d79
commit
1fc6b064ae
9 files changed
+44
-43
No files matched your search
+4
-12
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "image.h"
|
||||
#include "model/draw.h"
|
||||
#include "model/frames.h"
|
||||
#include "model/model.h"
|
||||
|
||||
// Document edits as plain functions of the model. Each returns the uids of the elements it created or changed that
|
||||
@@ -25,14 +26,6 @@ struct RowTarget
|
||||
int groupId = -1;
|
||||
};
|
||||
|
||||
struct RootBakeOptions
|
||||
{
|
||||
bool isRoundScale = false;
|
||||
bool isRoundRotation = false;
|
||||
bool isMatchRootInterpolation = false;
|
||||
bool isUseRootPivot = false;
|
||||
};
|
||||
|
||||
struct GridOptions
|
||||
{
|
||||
IVec2 start{};
|
||||
@@ -94,10 +87,9 @@ enum class FrameProperty
|
||||
#define X(property, tracks, ...) property,
|
||||
FRAME_PROPERTIES(X)
|
||||
#undef X
|
||||
COUNT
|
||||
COUNT
|
||||
};
|
||||
|
||||
|
||||
bool is_frame_property_valid(FrameProperty, ItemType);
|
||||
void frame_property_copy(Frame&, const Frame&, FrameProperty);
|
||||
Uids frames_property_set(Model&, const std::set<Reference>&, FrameProperty, const Frame&);
|
||||
@@ -108,14 +100,14 @@ Uids frame_insert(Model&, Reference, int);
|
||||
void frames_delete(Model&, const std::set<Reference>&);
|
||||
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
|
||||
void frames_reverse(Model&, const std::set<Reference>&);
|
||||
Uids frames_bake(Model&, const std::set<Reference>&, int, bool, bool);
|
||||
Uids frames_bake(Model&, const std::set<Reference>&, int, BakeOptions);
|
||||
Uids frame_split(Model&, Reference, int);
|
||||
Uids frames_split(Model&, const std::set<Reference>&, int);
|
||||
Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
|
||||
void frame_durations_set(Model&, const std::map<Reference, int>&);
|
||||
void trigger_at_frame_set(Model&, Reference, int);
|
||||
Uids frames_paste(Model&, Reference, const std::set<Reference>&, const std::string&, int, std::string*);
|
||||
Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, RootBakeOptions);
|
||||
Uids root_bake_into(Model&, const std::set<Reference>&, const std::set<Reference>&, BakeOptions);
|
||||
|
||||
void items_remove(Model&, int, const std::map<int, std::set<int>>&, const std::map<int, std::set<int>>&);
|
||||
Uids items_group(Model&, int, int, const std::set<int>&, const std::string&);
|
||||
|
||||
+5
-6
@@ -119,7 +119,7 @@ void frames_reverse(Model& model, const std::set<Reference>& frames)
|
||||
}
|
||||
}
|
||||
|
||||
Uids frames_bake(Model& model, const std::set<Reference>& frames, int interval, bool isRoundScale, bool isRoundRotation)
|
||||
Uids frames_bake(Model& model, const std::set<Reference>& frames, int interval, BakeOptions options)
|
||||
{
|
||||
Uids uids = {};
|
||||
for (auto& [trackReference, indices] : frames_by_track_get(frames))
|
||||
@@ -136,7 +136,7 @@ Uids frames_bake(Model& model, const std::set<Reference>& frames, int interval,
|
||||
continue;
|
||||
auto duration = track->frames[index].duration;
|
||||
auto count = duration <= FRAME_DURATION_MIN ? 1 : (int)std::ceil((float)duration / interval);
|
||||
frame_bake(*track, index, interval, isRoundScale, isRoundRotation);
|
||||
frame_bake(*track, index, interval, options);
|
||||
uids.append_range(frames_uids_get(*track, index, count));
|
||||
inserted += count - 1;
|
||||
}
|
||||
@@ -340,7 +340,7 @@ Uids frames_paste(Model& model, Reference reference, const std::set<Reference>&
|
||||
// Applies the selected root frames' transforms to the target tracks' frames under them, then resets those root
|
||||
// frames to a default frame spanning the same time.
|
||||
Uids root_bake_into(Model& model, const std::set<Reference>& rootFrames, const std::set<Reference>& targets,
|
||||
RootBakeOptions options)
|
||||
BakeOptions options)
|
||||
{
|
||||
auto byTrack = frames_by_track_get(rootFrames);
|
||||
if (byTrack.size() != 1 || targets.empty())
|
||||
@@ -373,14 +373,13 @@ Uids root_bake_into(Model& model, const std::set<Reference>& rootFrames, const s
|
||||
if (options.isMatchRootInterpolation)
|
||||
for (int index = (int)track->frames.size() - 1; index >= 0; --index)
|
||||
if (is_spanned((int)frame_time_from_index_get(*track, index)))
|
||||
frame_bake(*track, index, FRAME_DURATION_MIN, options.isRoundScale, options.isRoundRotation);
|
||||
frame_bake(*track, index, FRAME_DURATION_MIN, options);
|
||||
|
||||
for (int index = 0; index < (int)track->frames.size(); ++index)
|
||||
{
|
||||
auto start = (int)frame_time_from_index_get(*track, index);
|
||||
if (is_spanned(start))
|
||||
frame_root_transform_apply(track->frames[index], frame_generate(root, (float)start),
|
||||
options.isRoundScale, options.isRoundRotation, options.isUseRootPivot);
|
||||
frame_root_transform_apply(track->frames[index], frame_generate(root, (float)start), options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-12
@@ -18,8 +18,7 @@ void frame_mix(Frame& frame, const Frame& next, float amount)
|
||||
}
|
||||
|
||||
// Splits an interpolated frame into uninterpolated frames of at most `interval`. The first keeps the frame's uid.
|
||||
std::vector<Frame> frame_bake_split(const Frame& original, const Frame& next, int interval, bool isRoundScale,
|
||||
bool isRoundRotation)
|
||||
std::vector<Frame> frame_bake_split(const Frame& original, const Frame& next, int interval, BakeOptions options)
|
||||
{
|
||||
auto total = std::max(original.duration, FRAME_DURATION_MIN);
|
||||
interval = std::max(interval, FRAME_DURATION_MIN);
|
||||
@@ -30,9 +29,9 @@ std::vector<Frame> frame_bake_split(const Frame& original, const Frame& next, in
|
||||
frame_mix(baked, next, interpolation_factor(original.interpolation, (float)duration / total));
|
||||
baked.duration = std::min(interval, total - duration);
|
||||
baked.interpolation = Interpolation::NONE;
|
||||
if (isRoundScale)
|
||||
if (options.isRoundScale)
|
||||
baked.scale = vec_round(baked.scale);
|
||||
if (isRoundRotation)
|
||||
if (options.isRoundRotation)
|
||||
baked.rotation = std::round(baked.rotation);
|
||||
}
|
||||
return frames;
|
||||
@@ -44,11 +43,10 @@ Mat4 frame_parent_model_get(const Frame& frame)
|
||||
percent_to_unit(frame.skew));
|
||||
}
|
||||
|
||||
void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, bool isRoundScale, bool isRoundRotation,
|
||||
bool isUseRootPivot)
|
||||
void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, BakeOptions options)
|
||||
{
|
||||
auto rootScale = percent_to_unit(rootFrame.scale);
|
||||
auto pivot = isUseRootPivot ? rootFrame.position : Vec2();
|
||||
auto pivot = options.isUseRootPivot ? rootFrame.position : Vec2();
|
||||
auto offset = (frame.position - pivot) * rootScale;
|
||||
auto angle = radians(rootFrame.rotation);
|
||||
auto cos = std::cos(angle);
|
||||
@@ -60,9 +58,9 @@ void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, bool isRou
|
||||
frame.tint *= rootFrame.tint;
|
||||
frame.colorOffset += rootFrame.colorOffset;
|
||||
|
||||
if (isRoundScale)
|
||||
if (options.isRoundScale)
|
||||
frame.scale = vec_round(frame.scale);
|
||||
if (isRoundRotation)
|
||||
if (options.isRoundRotation)
|
||||
frame.rotation = std::round(frame.rotation);
|
||||
}
|
||||
|
||||
@@ -77,7 +75,7 @@ void track_group_root_bake(Track& track, const Track& root, int frameNum)
|
||||
for (int time = 0; time < length; ++time)
|
||||
{
|
||||
auto& frame = frames.emplace_back(frame_generate(track, (float)time));
|
||||
frame_root_transform_apply(frame, frame_generate(root, (float)time), false, false, false);
|
||||
frame_root_transform_apply(frame, frame_generate(root, (float)time));
|
||||
frame.duration = FRAME_DURATION_MIN;
|
||||
frame.interpolation = Interpolation::NONE;
|
||||
}
|
||||
@@ -164,7 +162,7 @@ float frame_time_from_index_get(const Track& track, int index)
|
||||
return time;
|
||||
}
|
||||
|
||||
void frame_bake(Track& track, int index, int interval, bool isRoundScale, bool isRoundRotation)
|
||||
void frame_bake(Track& track, int index, int interval, BakeOptions options)
|
||||
{
|
||||
if (index < 0 || index >= (int)track.frames.size())
|
||||
return;
|
||||
@@ -176,7 +174,7 @@ void frame_bake(Track& track, int index, int interval, bool isRoundScale, bool i
|
||||
}
|
||||
|
||||
auto next = index + 1 < (int)track.frames.size() ? track.frames[index + 1] : original;
|
||||
auto baked = frame_bake_split(original, next, interval, isRoundScale, isRoundRotation);
|
||||
auto baked = frame_bake_split(original, next, interval, options);
|
||||
track.frames.erase(track.frames.begin() + index);
|
||||
track.frames.insert(track.frames.begin() + index, baked.begin(), baked.end());
|
||||
}
|
||||
|
||||
+12
-3
@@ -5,16 +5,25 @@
|
||||
|
||||
#include "model/draw.h"
|
||||
|
||||
// How baking makes frames: whole scales and rotations, a root's easing kept, and turning around the root's position.
|
||||
struct BakeOptions
|
||||
{
|
||||
bool isRoundScale = false;
|
||||
bool isRoundRotation = false;
|
||||
bool isMatchRootInterpolation = false;
|
||||
bool isUseRootPivot = false;
|
||||
};
|
||||
|
||||
void frame_mix(Frame&, const Frame&, float);
|
||||
std::vector<Frame> frame_bake_split(const Frame&, const Frame&, int, bool, bool);
|
||||
std::vector<Frame> frame_bake_split(const Frame&, const Frame&, int, BakeOptions = {});
|
||||
Mat4 frame_parent_model_get(const Frame&);
|
||||
void frame_root_transform_apply(Frame&, const Frame&, bool, bool, bool);
|
||||
void frame_root_transform_apply(Frame&, const Frame&, BakeOptions = {});
|
||||
Frame frame_generate(const Track&, float);
|
||||
void track_group_root_bake(Track&, const Track&, int);
|
||||
int frame_index_from_at_frame_get(const Track&, int);
|
||||
int frame_index_from_time_get(const Track&, float);
|
||||
float frame_time_from_index_get(const Track&, int);
|
||||
void frame_bake(Track&, int, int, bool, bool);
|
||||
void frame_bake(Track&, int, int, BakeOptions = {});
|
||||
void frames_generate_from_grid(Track&, IVec2, IVec2, Vec2, int, int, int);
|
||||
void frames_sort_by_at_frame(Track&);
|
||||
void frames_change(Track&, FrameChange, ItemType, ChangeType, const std::set<int>&, bool isAnimationLayer = false);
|
||||
|
||||
+1
-1
@@ -1495,7 +1495,7 @@ static Animation animation_bake(const Writer& writer, Animation animation)
|
||||
return;
|
||||
for (int index = (int)track.frames.size() - 1; index >= 0; --index)
|
||||
if (track.frames[index].interpolation != Interpolation::NONE)
|
||||
frame_bake(track, index, FRAME_DURATION_MIN, false, false);
|
||||
frame_bake(track, index, FRAME_DURATION_MIN);
|
||||
});
|
||||
return animation;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,8 @@ void TimelineContext::frames_bake()
|
||||
return;
|
||||
edit_push(EDIT_BAKE_FRAMES, [=, interval = settings.bakeInterval, isRoundScale = settings.bakeIsRoundScale,
|
||||
isRoundRotation = settings.bakeIsRoundRotation](Model& model) {
|
||||
return ::frames_bake(model, selectedFrames, interval, isRoundScale, isRoundRotation);
|
||||
return ::frames_bake(model, selectedFrames, interval,
|
||||
{.isRoundScale = isRoundScale, .isRoundRotation = isRoundRotation});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -113,8 +114,8 @@ void TimelineContext::bake_into_other_frames()
|
||||
return;
|
||||
auto targetItems = item_references_for_bake_into_other_frames_get(
|
||||
document, *animation, bakeIntoOtherFramesTarget, isBakeIntoOtherFramesLayers, isBakeIntoOtherFramesNulls);
|
||||
RootBakeOptions options{settings.bakeIsRoundScale, settings.bakeIsRoundRotation,
|
||||
settings.bakeIsMatchRootInterpolation, settings.bakeIsUseRootPivot};
|
||||
BakeOptions options{settings.bakeIsRoundScale, settings.bakeIsRoundRotation, settings.bakeIsMatchRootInterpolation,
|
||||
settings.bakeIsUseRootPivot};
|
||||
edit_push(EDIT_BAKE_INTO_OTHER_FRAMES,
|
||||
[=](Model& model) { return root_bake_into(model, selectedRootFrames, targetItems, options); });
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user