Commit ed0d8453 authored by Florian Oetke's avatar Florian Oetke
Browse files

integrated rotation-test model for DualQuaternion blending

parent a38a7d8d
......@@ -18,9 +18,6 @@ build_gcc:
- cmake -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=../bin -DCMAKE_BUILD_TYPE=Release -DMIRRAGE_EXPORT_EXECUTABLE=ON ..
- cmake --build . --target src/install
- cmake --build . --target test
- wget -N https://github.com/lowkey42/mirrage/releases/download/v0.2/model_data.tar.xz || true
- cd bin/bin
- tar xf ../../model_data.tar.xz
artifacts:
paths:
- build/bin
......
......@@ -89,6 +89,12 @@ namespace mirrage {
chest.get<renderer::Animation_comp>().process([](auto& anim) { anim.animation("close"_strid); });
auto rotation_test = _meta_system.entities().emplace("rotation_test");
rotation_test.get<Transform_comp>().process([](auto& transform) {
transform.position = {-4, 0, -0.5f};
});
_camera = _meta_system.entities().emplace("camera");
......
......@@ -41,9 +41,9 @@ namespace mirrage::renderer {
Animation_comp(ecs::Entity_handle owner, ecs::Entity_manager& em) : Component(owner, em) {}
/// play preloaded; for small or frequently used animations
void animation(util::Str_id, bool loop = true);
void animation(util::Str_id, bool loop = true, bool preserve_state = false);
/// load + play; for large one-time animations
void animation(asset::Ptr<Animation>, bool loop = true);
void animation(asset::Ptr<Animation>, bool loop = true, bool preserve_state = false);
auto animation() { return _current_animation; }
auto animation_id() const { return _current_animation_id; }
......
......@@ -4,10 +4,18 @@ namespace mirrage::renderer {
void load_component(ecs::Deserializer& state, Animation_comp& a)
{
auto skeleton = std::string();
auto preload = std::unordered_map<std::string, std::string>();
state.read_virtual(sf2::vmember("skeleton", skeleton), sf2::vmember("animations", preload));
auto skeleton = std::string();
auto preload = std::unordered_map<std::string, std::string>();
auto default_animation = a._current_animation_id.get_or(""_strid).str();
state.read_virtual(sf2::vmember("skeleton", skeleton),
sf2::vmember("animations", preload),
sf2::vmember("default_animation", default_animation),
sf2::vmember("time", a._time),
sf2::vmember("speed", a._speed),
sf2::vmember("reversed", a._reversed),
sf2::vmember("paused", a._paused),
sf2::vmember("default_looped", a._looped));
a._skeleton_id = skeleton;
a._skeleton = state.assets.load<Skeleton>(skeleton);
......@@ -16,6 +24,8 @@ namespace mirrage::renderer {
for(auto&& [key, aid] : preload) {
a._preloaded_animations.emplace(util::Str_id(key), state.assets.load<Animation>(aid));
}
a.animation(util::Str_id(default_animation), a._looped, true);
}
void save_component(ecs::Serializer& state, const Animation_comp& a)
{
......@@ -24,32 +34,42 @@ namespace mirrage::renderer {
preload.emplace(key.str(), anim.aid().str());
}
auto default_animation = a._current_animation_id.get_or(""_strid).str();
state.write_virtual(sf2::vmember("skeleton", a._skeleton_id.str()),
sf2::vmember("animations", preload));
sf2::vmember("animations", preload),
sf2::vmember("default_animation", default_animation),
sf2::vmember("time", a._time),
sf2::vmember("speed", a._speed),
sf2::vmember("reversed", a._reversed),
sf2::vmember("paused", a._paused),
sf2::vmember("default_looped", a._looped));
}
void Animation_comp::animation(util::Str_id id, bool loop)
void Animation_comp::animation(util::Str_id id, bool loop, bool preserve_state)
{
if(auto anim = util::find_maybe(_preloaded_animations, id); anim.is_some()) {
_current_animation_id = id;
animation(anim.get_or_throw(), loop);
animation(anim.get_or_throw(), loop, preserve_state);
} else if(_current_animation) {
animation(asset::Ptr<Animation>{});
animation(asset::Ptr<Animation>{}, preserve_state);
}
}
void Animation_comp::animation(asset::Ptr<Animation> anim, bool loop)
void Animation_comp::animation(asset::Ptr<Animation> anim, bool loop, bool preserve_state)
{
_looped = loop;
if(anim) {
if(anim != _current_animation) {
_current_animation = anim;
_time = 0.f;
_speed = 1.f;
_reversed = false;
_paused = false;
_animation_keys.clear();
if(!preserve_state) {
_time = 0.f;
_speed = 1.f;
_reversed = false;
_paused = false;
_animation_keys.clear();
}
}
} else if(_current_animation) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment