-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Marc Rousavy <[email protected]>
- Loading branch information
Showing
12 changed files
with
288 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// Created by Hanno Gödecke on 29.02.24. | ||
// | ||
|
||
#include "AnimatorWrapper.h" | ||
|
||
namespace margelo { | ||
void AnimatorWrapper::loadHybridMethods() { | ||
registerHybridMethod("applyAnimation", &AnimatorWrapper::applyAnimation, this); | ||
registerHybridMethod("updateBoneMatrices", &AnimatorWrapper::updateBoneMatrices, this); | ||
registerHybridMethod("applyCrossFade", &AnimatorWrapper::applyCrossFade, this); | ||
registerHybridMethod("resetBoneMatrices", &AnimatorWrapper::resetBoneMatrices, this); | ||
registerHybridMethod("getAnimationCount", &AnimatorWrapper::getAnimationCount, this); | ||
registerHybridMethod("getAnimationDuration", &AnimatorWrapper::getAnimationDuration, this); | ||
registerHybridMethod("getAnimationName", &AnimatorWrapper::getAnimationName, this); | ||
} | ||
|
||
Animator* AnimatorWrapper::getAnimator() { | ||
FilamentInstance* instance = _asset->getInstance(); | ||
if (instance == nullptr) { | ||
[[unlikely]]; | ||
throw std::runtime_error("Filament Asset does not contain a valid FilamentInstance!"); | ||
} | ||
return instance->getAnimator(); | ||
} | ||
|
||
void AnimatorWrapper::applyAnimation(int animationIndex, double time) { | ||
Animator* animator = getAnimator(); | ||
animator->applyAnimation(animationIndex, time); | ||
} | ||
|
||
void AnimatorWrapper::updateBoneMatrices() { | ||
Animator* animator = getAnimator(); | ||
animator->updateBoneMatrices(); | ||
} | ||
|
||
void AnimatorWrapper::applyCrossFade(int previousAnimationIndex, double previousAnimationTime, double alpha) { | ||
Animator* animator = getAnimator(); | ||
animator->applyCrossFade(previousAnimationIndex, previousAnimationTime, alpha); | ||
} | ||
|
||
void AnimatorWrapper::resetBoneMatrices() { | ||
Animator* animator = getAnimator(); | ||
animator->resetBoneMatrices(); | ||
} | ||
|
||
int AnimatorWrapper::getAnimationCount() { | ||
Animator* animator = getAnimator(); | ||
return animator->getAnimationCount(); | ||
} | ||
|
||
double AnimatorWrapper::getAnimationDuration(int animationIndex) { | ||
Animator* animator = getAnimator(); | ||
return animator->getAnimationDuration(animationIndex); | ||
} | ||
|
||
std::string AnimatorWrapper::getAnimationName(int animationIndex) { | ||
Animator* animator = getAnimator(); | ||
return animator->getAnimationName(animationIndex); | ||
} | ||
} // namespace margelo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Created by Hanno Gödecke on 29.02.24. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "jsi/HybridObject.h" | ||
#include <gltfio/Animator.h> | ||
|
||
namespace margelo { | ||
|
||
using namespace filament::gltfio; | ||
|
||
class AnimatorWrapper : public HybridObject { | ||
public: | ||
explicit AnimatorWrapper(const std::shared_ptr<FilamentAsset>& asset) : HybridObject("AnimatorWrapper"), _asset(std::move(asset)) {} | ||
|
||
void loadHybridMethods() override; | ||
|
||
private: | ||
void applyAnimation(int animationIndex, double time); | ||
void applyCrossFade(int previousAnimationIndex, double previousAnimationTime, double alpha); | ||
void updateBoneMatrices(); | ||
void resetBoneMatrices(); | ||
int getAnimationCount(); | ||
double getAnimationDuration(int animationIndex); | ||
std::string getAnimationName(int animationIndex); | ||
|
||
Animator* getAnimator(); | ||
|
||
private: | ||
std::shared_ptr<FilamentAsset> _asset; | ||
}; | ||
|
||
} // namespace margelo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.