Skip to content

Commit

Permalink
- Animation fixes and improvements
Browse files Browse the repository at this point in the history
- Update packages
  • Loading branch information
edunad committed May 12, 2024
1 parent 84e44c3 commit 86f6fbd
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ if(NOT WIN32 AND RAWRBOX_USE_WAYLAND)
CPMAddPackage("gl:wayland/weston@12.0.3")
endif()

CPMAddPackage("gh:stephenberry/glaze@2.6.0")
CPMAddPackage("gh:stephenberry/glaze@2.6.1")

# ---
if(RAWRBOX_BUILD_RAWRBOX_NETWORK OR RAWRBOX_BUILD_RAWRBOX_ASSIMP)
Expand Down
4 changes: 2 additions & 2 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion cmake/catch2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if(RAWRBOX_BUILD_TESTING)
GITHUB_REPOSITORY
catchorg/Catch2
VERSION
3.5.4
3.6.0
OPTIONS
"CATCH_INSTALL_DOCS OFF"
"CATCH_INSTALL_EXTRAS ON")
Expand Down
6 changes: 3 additions & 3 deletions package-lock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CPMDeclarePackage(magic_enum
)
# glaze
CPMDeclarePackage(glaze
VERSION 2.6.0
VERSION 2.6.1
GITHUB_REPOSITORY stephenberry/glaze
SYSTEM YES
EXCLUDE_FROM_ALL YES
Expand All @@ -38,7 +38,7 @@ CPMDeclarePackage(zlib
# Catch2
CPMDeclarePackage(Catch2
NAME Catch2
VERSION 3.5.4
VERSION 3.6.0
GITHUB_REPOSITORY catchorg/Catch2
OPTIONS
"CATCH_INSTALL_DOCS OFF"
Expand Down Expand Up @@ -77,7 +77,7 @@ CPMDeclarePackage(cpptrace
# luau
CPMDeclarePackage(luau
NAME luau
GIT_TAG 0.624
GIT_TAG 0.625
GITHUB_REPOSITORY luau-lang/luau
OPTIONS
"LUAU_BUILD_CLI OFF"
Expand Down
2 changes: 1 addition & 1 deletion rawrbox.render/include/rawrbox/render/models/animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ namespace rawrbox {
std::function<void()> onComplete = nullptr;

PlayingAnimationData() = default;
PlayingAnimationData(std::string _name, bool _loop, float _speed, float _time, rawrbox::Animation& _data, std::function<void()> complete = nullptr) : name(std::move(_name)), loop(_loop), speed(_speed), time(_time), data(&_data), onComplete(std::move(complete)){};
PlayingAnimationData(std::string _name, bool _loop, float _speed, rawrbox::Animation& _data, std::function<void()> complete = nullptr) : name(std::move(_name)), loop(_loop), speed(_speed), time(_speed <= 0.F ? _data.duration : 0.F), data(&_data), onComplete(std::move(complete)){};
};
} // namespace rawrbox
22 changes: 7 additions & 15 deletions rawrbox.render/include/rawrbox/render/models/model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,19 @@ namespace rawrbox {
float newTime = it->second.time + timeToAdd;
float totalDur = it->second.data->duration;

// Check if the animation has reached the end or the beginning (for negative speed)
bool animationEnded = (it->second.speed >= 0 && newTime >= totalDur) || (it->second.speed < 0 && newTime <= 0);

bool animationEnded = it->second.speed >= 0 ? newTime >= totalDur : newTime <= 0;
if (animationEnded) {
if (it->second.loop) {
newTime = std::fmod(newTime, totalDur);
if (newTime <= 0) newTime += totalDur;
} else {
auto onCompleteCallback = it->second.onComplete;
it = this->_playingAnimations.erase(it);
auto onCompleteCallback = it->second.onComplete;

if (!it->second.loop) {
it = this->_playingAnimations.erase(it);
if (onCompleteCallback != nullptr) onCompleteCallback();

continue;
}

this->onAnimationComplete(it->second.name);
newTime = it->second.speed >= 0 ? 0 : totalDur;
if (onCompleteCallback != nullptr) onCompleteCallback();
}

it->second.time = newTime;
Expand Down Expand Up @@ -181,10 +178,6 @@ namespace rawrbox {
// --------------

public:
// ANIMATION ---
rawrbox::Event<std::string> onAnimationComplete = {};
// ------------

Model(size_t vertices = 0, size_t indices = 0) : rawrbox::ModelBase<M>(vertices, indices){};
Model(const Model&) = delete;
Model(Model&&) = delete;
Expand Down Expand Up @@ -297,7 +290,6 @@ namespace rawrbox {
name,
loop,
speed,
0.0F,
iter->second,
onComplete};

Expand Down
2 changes: 1 addition & 1 deletion rawrbox.scripting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CPMAddPackage(
GITHUB_REPOSITORY
luau-lang/luau
GIT_TAG
0.624
0.625
OPTIONS
"LUAU_BUILD_CLI OFF"
"LUAU_BUILD_TESTS OFF"
Expand Down
12 changes: 6 additions & 6 deletions samples/009-assimp/src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ namespace assimp {

void Game::testANIM() {
this->_model8->playAnimation("TEST.UP", false, 1.F, true, [this]() {
this->_model8->playAnimation("TEST.LEFT", false, 1.F, true, [this]() {
this->_model8->playAnimation("TEST.LEFT", false, -1.F, true, [this]() {
this->_model8->playAnimation("TEST.BACK", false, 1.F, true, [this]() {
fmt::print("loop anim test \n");
this->testANIM();
Expand Down Expand Up @@ -104,7 +104,6 @@ namespace assimp {
this->_model3->playAnimation("Scene", true, 1.F);
this->_model3->setPos({1, 0, 0});
this->_model3->upload();
this->_model3->onAnimationComplete += [](std::string anim) { fmt::print("Anim '{}' completed\n", anim); };

this->_model4->load(*mdl2);
this->_model4->playAnimation("Scene", true, -1.F);
Expand All @@ -115,7 +114,7 @@ namespace assimp {
this->_model5->load(*mdl3);
this->_model5->playAnimation("MewAction", true, 0.8F);
this->_model5->playAnimation("MewAction.001", true, 0.5F);
this->_model5->setPos({0, 0, 2.5F});
this->_model5->setPos({-2.F, 0, 2.5F});
this->_model5->setScale({0.25F, 0.25F, 0.25F});
this->_model5->upload();

Expand All @@ -136,8 +135,8 @@ namespace assimp {

// ANIM TEST ---
auto* mdl6 = rawrbox::RESOURCES::getFile<rawrbox::ResourceAssimp>("./assets/models/anim_test.glb")->get();

this->_model8->setPos({7, 1.1F, 2.F});
this->_model8->setScale({0.25F, 0.25F, 0.25F});
this->_model8->setPos({2.F, 0.F, 2.5F});
this->_model8->load(*mdl6);
this->_model8->upload();
// ---------
Expand All @@ -146,9 +145,10 @@ namespace assimp {
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "TEXTURES + LIGHT", {-6.F, 3.0F, 0});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "TEXTURES", {6.F, 3.0F, 0});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "SINGLE ARMATURE +\nVERTEX ANIMATION", {0.F, 2.F, 0});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "TWO ARMATURES +\nTWO ANIMATIONS", {0.F, 1.F, 2.5F});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "TWO ARMATURES +\nTWO ANIMATIONS", {-2.25F, 0.5F, 2.5F});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "VERTEX ANIMATIONS", {-1.F, 1.8F, -3.5F});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "EMBEDDED TEXTURES +\nBLEND SHAPES", {1.F, 1.8F, -3.5F});
this->_text->addText(*rawrbox::DEBUG_FONT_REGULAR, "ANIMATION EVENT", {1.5F, 1.F, 2.5F});
this->_text->upload();
// ------

Expand Down

0 comments on commit 86f6fbd

Please sign in to comment.