diff --git a/Nuake/src/Resource/SkeletalAnimation.h b/Nuake/src/Resource/SkeletalAnimation.h index d5202d70..252e4ab3 100644 --- a/Nuake/src/Resource/SkeletalAnimation.h +++ b/Nuake/src/Resource/SkeletalAnimation.h @@ -145,6 +145,7 @@ namespace Nuake private: std::unordered_map m_Tracks; float m_CurrentTime; + float m_PreviousTime; float m_Duration; float m_TicksPerSecond; std::string m_Name; diff --git a/Nuake/src/Resource/SkinnedModel.cpp b/Nuake/src/Resource/SkinnedModel.cpp index f2c4ec60..9c3578fb 100644 --- a/Nuake/src/Resource/SkinnedModel.cpp +++ b/Nuake/src/Resource/SkinnedModel.cpp @@ -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 SkinnedModel::GetCurrentAnimation() { if (m_CurrentAnimation < m_NumAnimation) @@ -51,6 +61,17 @@ namespace Nuake return nullptr; } + Ref 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() diff --git a/Nuake/src/Resource/SkinnedModel.h b/Nuake/src/Resource/SkinnedModel.h index 70e30a52..c9c33541 100644 --- a/Nuake/src/Resource/SkinnedModel.h +++ b/Nuake/src/Resource/SkinnedModel.h @@ -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> m_Animations; @@ -39,7 +41,10 @@ namespace Nuake void SetAnimations(const std::vector> animations); void AddAnimation(Ref animation); + float GetCurrentBlendTime(); + void SetCurrentBlendTime(float time); Ref GetCurrentAnimation(); + Ref GetPreviousAnimation(); void PlayAnimation(uint32_t animationId); uint32_t GetCurrentAnimationIndex() const { return m_CurrentAnimation; } uint32_t GetAnimationsCount() const { return m_NumAnimation; } diff --git a/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp b/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp index e7cfd988..b0663133 100644 --- a/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp +++ b/Nuake/src/Scripting/NetModules/EngineNetAPI.cpp @@ -97,6 +97,16 @@ namespace Nuake { return ConvertHitsToArray(hits); } + Coral::Array ShapeCastSphere(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, float radius) + { + auto sphere = CreateRef(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 ShapeCastBox(float fromX, float fromY, float fromZ, float toX, float toY, float toZ, BoxInternal boxInternal) { auto capsule = CreateRef(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); }