More blending code + ShapeCastSphere now works

This commit is contained in:
antopilo
2024-12-01 02:11:05 -05:00
parent 18eec6c570
commit a27039d7c5
4 changed files with 41 additions and 0 deletions

View File

@@ -145,6 +145,7 @@ namespace Nuake
private:
std::unordered_map<std::string, BoneTransformTrack> m_Tracks;
float m_CurrentTime;
float m_PreviousTime;
float m_Duration;
float m_TicksPerSecond;
std::string m_Name;

View File

@@ -40,6 +40,16 @@ namespace Nuake
m_Animations.push_back(std::move(animation));
}
void SkinnedModel::SetCurrentBlendTime(float blendTime)
{
m_TransitionBlendTime = std::max(blendTime, 0.0f);
}
float SkinnedModel::GetCurrentBlendTime()
{
return m_TransitionBlendTime;
}
Ref<Nuake::SkeletalAnimation> SkinnedModel::GetCurrentAnimation()
{
if (m_CurrentAnimation < m_NumAnimation)
@@ -51,6 +61,17 @@ namespace Nuake
return nullptr;
}
Ref<Nuake::SkeletalAnimation> SkinnedModel::GetPreviousAnimation()
{
if (m_PreviousAnimation < m_NumAnimation)
{
return m_Animations[m_PreviousAnimation];
}
Logger::Log("Cannot get animation if no animation exists", "skinned model", WARNING);
return nullptr;
}
void SkinnedModel::PlayAnimation(uint32_t animationId)
{
if (animationId >= m_NumAnimation)
@@ -61,7 +82,10 @@ namespace Nuake
GetCurrentAnimation()->SetCurrentTime(0.0f); // Reset previous animation
m_PreviousAnimation = m_CurrentAnimation;
m_CurrentAnimation = animationId;
m_TransitionBlendTime = 0.6f;
}
json SkinnedModel::Serialize()

View File

@@ -16,6 +16,8 @@ namespace Nuake
SkeletonNode m_SkeletonRoot;
uint32_t m_CurrentAnimation = 0;
uint32_t m_PreviousAnimation = 0;
float m_TransitionBlendTime = 0.0f;
uint32_t m_NumAnimation = 0;
std::vector<Ref<SkeletalAnimation>> m_Animations;
@@ -39,7 +41,10 @@ namespace Nuake
void SetAnimations(const std::vector<Ref<SkeletalAnimation>> animations);
void AddAnimation(Ref<SkeletalAnimation> animation);
float GetCurrentBlendTime();
void SetCurrentBlendTime(float time);
Ref<SkeletalAnimation> GetCurrentAnimation();
Ref<SkeletalAnimation> GetPreviousAnimation();
void PlayAnimation(uint32_t animationId);
uint32_t GetCurrentAnimationIndex() const { return m_CurrentAnimation; }
uint32_t GetAnimationsCount() const { return m_NumAnimation; }

View File

@@ -97,6 +97,16 @@ namespace Nuake {
return ConvertHitsToArray(hits);
}
Coral::Array<float> ShapeCastSphere(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, float radius)
{
auto sphere = CreateRef<Physics::Sphere>(radius);
const Vector3 from = { fromX, fromY, fromZ };
const Vector3 to = { toX, toY, toZ };
auto hits = PhysicsManager::Get().Shapecast(from, to, sphere);
return ConvertHitsToArray(hits);
}
Coral::Array<float> ShapeCastBox(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, BoxInternal boxInternal)
{
auto capsule = CreateRef<Physics::Box>(boxInternal.x, boxInternal.y, boxInternal.z);
@@ -143,6 +153,7 @@ namespace Nuake {
RegisterMethod("Debug.DrawShapeCylinderIcall", &DrawShapeCylinder);
RegisterMethod("Physic.RayCastIcall", &Raycast);
RegisterMethod("Physic.ShapeCastSphereIcall", &ShapeCastSphere);
RegisterMethod("Physic.ShapeCastCapsuleIcall", &ShapeCastCapsule);
RegisterMethod("Physic.ShapeCastBoxIcall", &ShapeCastBox);
}