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 "image.h"
|
||||||
#include "model/draw.h"
|
#include "model/draw.h"
|
||||||
|
#include "model/frames.h"
|
||||||
#include "model/model.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
|
// 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;
|
int groupId = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RootBakeOptions
|
|
||||||
{
|
|
||||||
bool isRoundScale = false;
|
|
||||||
bool isRoundRotation = false;
|
|
||||||
bool isMatchRootInterpolation = false;
|
|
||||||
bool isUseRootPivot = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GridOptions
|
struct GridOptions
|
||||||
{
|
{
|
||||||
IVec2 start{};
|
IVec2 start{};
|
||||||
@@ -94,10 +87,9 @@ enum class FrameProperty
|
|||||||
#define X(property, tracks, ...) property,
|
#define X(property, tracks, ...) property,
|
||||||
FRAME_PROPERTIES(X)
|
FRAME_PROPERTIES(X)
|
||||||
#undef X
|
#undef X
|
||||||
COUNT
|
COUNT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
bool is_frame_property_valid(FrameProperty, ItemType);
|
bool is_frame_property_valid(FrameProperty, ItemType);
|
||||||
void frame_property_copy(Frame&, const Frame&, FrameProperty);
|
void frame_property_copy(Frame&, const Frame&, FrameProperty);
|
||||||
Uids frames_property_set(Model&, const std::set<Reference>&, FrameProperty, const Frame&);
|
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>&);
|
void frames_delete(Model&, const std::set<Reference>&);
|
||||||
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
|
Uids frames_duplicate(Model&, const std::set<Reference>&, Reference);
|
||||||
void frames_reverse(Model&, const std::set<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 frame_split(Model&, Reference, int);
|
||||||
Uids frames_split(Model&, const std::set<Reference>&, int);
|
Uids frames_split(Model&, const std::set<Reference>&, int);
|
||||||
Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
|
Uids frames_move(Model&, const std::set<Reference>&, Reference, int);
|
||||||
void frame_durations_set(Model&, const std::map<Reference, int>&);
|
void frame_durations_set(Model&, const std::map<Reference, int>&);
|
||||||
void trigger_at_frame_set(Model&, 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 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>>&);
|
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&);
|
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 = {};
|
Uids uids = {};
|
||||||
for (auto& [trackReference, indices] : frames_by_track_get(frames))
|
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;
|
continue;
|
||||||
auto duration = track->frames[index].duration;
|
auto duration = track->frames[index].duration;
|
||||||
auto count = duration <= FRAME_DURATION_MIN ? 1 : (int)std::ceil((float)duration / interval);
|
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));
|
uids.append_range(frames_uids_get(*track, index, count));
|
||||||
inserted += count - 1;
|
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
|
// 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.
|
// 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,
|
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);
|
auto byTrack = frames_by_track_get(rootFrames);
|
||||||
if (byTrack.size() != 1 || targets.empty())
|
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)
|
if (options.isMatchRootInterpolation)
|
||||||
for (int index = (int)track->frames.size() - 1; index >= 0; --index)
|
for (int index = (int)track->frames.size() - 1; index >= 0; --index)
|
||||||
if (is_spanned((int)frame_time_from_index_get(*track, 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)
|
for (int index = 0; index < (int)track->frames.size(); ++index)
|
||||||
{
|
{
|
||||||
auto start = (int)frame_time_from_index_get(*track, index);
|
auto start = (int)frame_time_from_index_get(*track, index);
|
||||||
if (is_spanned(start))
|
if (is_spanned(start))
|
||||||
frame_root_transform_apply(track->frames[index], frame_generate(root, (float)start),
|
frame_root_transform_apply(track->frames[index], frame_generate(root, (float)start), options);
|
||||||
options.isRoundScale, options.isRoundRotation, options.isUseRootPivot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+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.
|
// 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,
|
std::vector<Frame> frame_bake_split(const Frame& original, const Frame& next, int interval, BakeOptions options)
|
||||||
bool isRoundRotation)
|
|
||||||
{
|
{
|
||||||
auto total = std::max(original.duration, FRAME_DURATION_MIN);
|
auto total = std::max(original.duration, FRAME_DURATION_MIN);
|
||||||
interval = std::max(interval, 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));
|
frame_mix(baked, next, interpolation_factor(original.interpolation, (float)duration / total));
|
||||||
baked.duration = std::min(interval, total - duration);
|
baked.duration = std::min(interval, total - duration);
|
||||||
baked.interpolation = Interpolation::NONE;
|
baked.interpolation = Interpolation::NONE;
|
||||||
if (isRoundScale)
|
if (options.isRoundScale)
|
||||||
baked.scale = vec_round(baked.scale);
|
baked.scale = vec_round(baked.scale);
|
||||||
if (isRoundRotation)
|
if (options.isRoundRotation)
|
||||||
baked.rotation = std::round(baked.rotation);
|
baked.rotation = std::round(baked.rotation);
|
||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
@@ -44,11 +43,10 @@ Mat4 frame_parent_model_get(const Frame& frame)
|
|||||||
percent_to_unit(frame.skew));
|
percent_to_unit(frame.skew));
|
||||||
}
|
}
|
||||||
|
|
||||||
void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, bool isRoundScale, bool isRoundRotation,
|
void frame_root_transform_apply(Frame& frame, const Frame& rootFrame, BakeOptions options)
|
||||||
bool isUseRootPivot)
|
|
||||||
{
|
{
|
||||||
auto rootScale = percent_to_unit(rootFrame.scale);
|
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 offset = (frame.position - pivot) * rootScale;
|
||||||
auto angle = radians(rootFrame.rotation);
|
auto angle = radians(rootFrame.rotation);
|
||||||
auto cos = std::cos(angle);
|
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.tint *= rootFrame.tint;
|
||||||
frame.colorOffset += rootFrame.colorOffset;
|
frame.colorOffset += rootFrame.colorOffset;
|
||||||
|
|
||||||
if (isRoundScale)
|
if (options.isRoundScale)
|
||||||
frame.scale = vec_round(frame.scale);
|
frame.scale = vec_round(frame.scale);
|
||||||
if (isRoundRotation)
|
if (options.isRoundRotation)
|
||||||
frame.rotation = std::round(frame.rotation);
|
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)
|
for (int time = 0; time < length; ++time)
|
||||||
{
|
{
|
||||||
auto& frame = frames.emplace_back(frame_generate(track, (float)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.duration = FRAME_DURATION_MIN;
|
||||||
frame.interpolation = Interpolation::NONE;
|
frame.interpolation = Interpolation::NONE;
|
||||||
}
|
}
|
||||||
@@ -164,7 +162,7 @@ float frame_time_from_index_get(const Track& track, int index)
|
|||||||
return time;
|
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())
|
if (index < 0 || index >= (int)track.frames.size())
|
||||||
return;
|
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 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.erase(track.frames.begin() + index);
|
||||||
track.frames.insert(track.frames.begin() + index, baked.begin(), baked.end());
|
track.frames.insert(track.frames.begin() + index, baked.begin(), baked.end());
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-3
@@ -5,16 +5,25 @@
|
|||||||
|
|
||||||
#include "model/draw.h"
|
#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);
|
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&);
|
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);
|
Frame frame_generate(const Track&, float);
|
||||||
void track_group_root_bake(Track&, const Track&, int);
|
void track_group_root_bake(Track&, const Track&, int);
|
||||||
int frame_index_from_at_frame_get(const Track&, int);
|
int frame_index_from_at_frame_get(const Track&, int);
|
||||||
int frame_index_from_time_get(const Track&, float);
|
int frame_index_from_time_get(const Track&, float);
|
||||||
float frame_time_from_index_get(const Track&, int);
|
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_generate_from_grid(Track&, IVec2, IVec2, Vec2, int, int, int);
|
||||||
void frames_sort_by_at_frame(Track&);
|
void frames_sort_by_at_frame(Track&);
|
||||||
void frames_change(Track&, FrameChange, ItemType, ChangeType, const std::set<int>&, bool isAnimationLayer = false);
|
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;
|
return;
|
||||||
for (int index = (int)track.frames.size() - 1; index >= 0; --index)
|
for (int index = (int)track.frames.size() - 1; index >= 0; --index)
|
||||||
if (track.frames[index].interpolation != Interpolation::NONE)
|
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;
|
return animation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ void TimelineContext::frames_bake()
|
|||||||
return;
|
return;
|
||||||
edit_push(EDIT_BAKE_FRAMES, [=, interval = settings.bakeInterval, isRoundScale = settings.bakeIsRoundScale,
|
edit_push(EDIT_BAKE_FRAMES, [=, interval = settings.bakeInterval, isRoundScale = settings.bakeIsRoundScale,
|
||||||
isRoundRotation = settings.bakeIsRoundRotation](Model& model) {
|
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;
|
return;
|
||||||
auto targetItems = item_references_for_bake_into_other_frames_get(
|
auto targetItems = item_references_for_bake_into_other_frames_get(
|
||||||
document, *animation, bakeIntoOtherFramesTarget, isBakeIntoOtherFramesLayers, isBakeIntoOtherFramesNulls);
|
document, *animation, bakeIntoOtherFramesTarget, isBakeIntoOtherFramesLayers, isBakeIntoOtherFramesNulls);
|
||||||
RootBakeOptions options{settings.bakeIsRoundScale, settings.bakeIsRoundRotation,
|
BakeOptions options{settings.bakeIsRoundScale, settings.bakeIsRoundRotation, settings.bakeIsMatchRootInterpolation,
|
||||||
settings.bakeIsMatchRootInterpolation, settings.bakeIsUseRootPivot};
|
settings.bakeIsUseRootPivot};
|
||||||
edit_push(EDIT_BAKE_INTO_OTHER_FRAMES,
|
edit_push(EDIT_BAKE_INTO_OTHER_FRAMES,
|
||||||
[=](Model& model) { return root_bake_into(model, selectedRootFrames, targetItems, options); });
|
[=](Model& model) { return root_bake_into(model, selectedRootFrames, targetItems, options); });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ TEST_CASE("JSON documents read back as the editor's copy")
|
|||||||
// Unknown XML, element order, dangling references and repeated animation names are not kept.
|
// Unknown XML, element order, dangling references and repeated animation names are not kept.
|
||||||
auto isQuirky = fixture.filename() == "09_legacy_quirks.anm2" || fixture.filename() == "11_unknown.anm2";
|
auto isQuirky = fixture.filename() == "09_legacy_quirks.anm2" || fixture.filename() == "11_unknown.anm2";
|
||||||
if (!isQuirky)
|
if (!isQuirky)
|
||||||
CHECK(model_serialize(reloaded, SAVE_EDITOR) ==
|
CHECK(model_serialize(reloaded, SAVE_EDITOR) == model_serialize(model, SAVE_EDITOR));
|
||||||
model_serialize(model, SAVE_EDITOR));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -98,8 +98,8 @@ TEST_CASE("frames_change")
|
|||||||
TEST_CASE("frame_bake and frame_mix")
|
TEST_CASE("frame_bake and frame_mix")
|
||||||
{
|
{
|
||||||
auto model = fixture_load("07_special_interpolation.anm2");
|
auto model = fixture_load("07_special_interpolation.anm2");
|
||||||
frame_bake(layer_track_get(model, 0, 0), 0, 2, true, false);
|
frame_bake(layer_track_get(model, 0, 0), 0, 2, {.isRoundScale = true});
|
||||||
frame_bake(layer_track_get(model, 0, 0), 3, 1, false, true);
|
frame_bake(layer_track_get(model, 0, 0), 3, 1, {.isRoundRotation = true});
|
||||||
operation_check("frame_bake", model);
|
operation_check("frame_bake", model);
|
||||||
|
|
||||||
Frame from = {};
|
Frame from = {};
|
||||||
@@ -166,7 +166,10 @@ TEST_CASE("edit layer operations")
|
|||||||
},
|
},
|
||||||
0},
|
0},
|
||||||
{"frames_bake", "07_special_interpolation.anm2",
|
{"frames_bake", "07_special_interpolation.anm2",
|
||||||
[&](Model& anm2) { return frames_bake(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, 2, true, false); }, 5},
|
[&](Model& anm2) {
|
||||||
|
return frames_bake(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 0, 1}}, 2, {.isRoundScale = true});
|
||||||
|
},
|
||||||
|
5},
|
||||||
{"frame_split", "02_items.anm2", [&](Model& anm2) { return frame_split(anm2, {0, LAYER, 1, 0}, 2); }, 1},
|
{"frame_split", "02_items.anm2", [&](Model& anm2) { return frame_split(anm2, {0, LAYER, 1, 0}, 2); }, 1},
|
||||||
{"frames_move", "02_items.anm2",
|
{"frames_move", "02_items.anm2",
|
||||||
[&](Model& anm2) { return frames_move(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 1, 0}}, head, 2); }, 2},
|
[&](Model& anm2) { return frames_move(anm2, {{0, LAYER, 0, 0}, {0, LAYER, 1, 0}}, head, 2); }, 2},
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ static bool edit_random_apply(Model& anm2, std::mt19937& random)
|
|||||||
frames_reverse(anm2, {frame, other});
|
frames_reverse(anm2, {frame, other});
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
frames_bake(anm2, {frame}, 1, false, false);
|
frames_bake(anm2, {frame}, 1, {});
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
frame_split(anm2, frame, 1);
|
frame_split(anm2, frame, 1);
|
||||||
|
|||||||
Reference in new issue
Block a user