From 58681753e5f6edc8e5d12c602b2e4334328066f7 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 23 Feb 2026 05:31:02 -0800 Subject: [PATCH] Freeze gameobject M2 animations to prevent cycling Gameobject M2 instances (books, crates, chests) were continuously cycling their animations because M2Renderer unconditionally loops all sequences. Added setInstanceAnimationFrozen() and freeze all gameobject instances at creation time so they stay in their bind pose. --- include/rendering/m2_renderer.hpp | 1 + src/core/application.cpp | 3 +++ src/rendering/m2_renderer.cpp | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/include/rendering/m2_renderer.hpp b/include/rendering/m2_renderer.hpp index 6a5a08e2..265aeddc 100644 --- a/include/rendering/m2_renderer.hpp +++ b/include/rendering/m2_renderer.hpp @@ -266,6 +266,7 @@ public: void setInstancePosition(uint32_t instanceId, const glm::vec3& position); void setInstanceTransform(uint32_t instanceId, const glm::mat4& transform); + void setInstanceAnimationFrozen(uint32_t instanceId, bool frozen); void removeInstance(uint32_t instanceId); void removeInstances(const std::vector& instanceIds); void clear(); diff --git a/src/core/application.cpp b/src/core/application.cpp index feba2e76..f3e7d517 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -5730,6 +5730,9 @@ void Application::spawnOnlineGameObject(uint64_t guid, uint32_t entry, uint32_t return; } + // Freeze animation — gameobjects are static until interacted with + m2Renderer->setInstanceAnimationFrozen(instanceId, true); + gameObjectInstances_[guid] = {modelId, instanceId, false}; } diff --git a/src/rendering/m2_renderer.cpp b/src/rendering/m2_renderer.cpp index 0d28e9d2..773379fb 100644 --- a/src/rendering/m2_renderer.cpp +++ b/src/rendering/m2_renderer.cpp @@ -3074,6 +3074,16 @@ void M2Renderer::setInstancePosition(uint32_t instanceId, const glm::vec3& posit spatialIndexDirty_ = true; } +void M2Renderer::setInstanceAnimationFrozen(uint32_t instanceId, bool frozen) { + auto idxIt = instanceIndexById.find(instanceId); + if (idxIt == instanceIndexById.end()) return; + auto& inst = instances[idxIt->second]; + inst.animSpeed = frozen ? 0.0f : 1.0f; + if (frozen) { + inst.animTime = 0.0f; // Reset to bind pose + } +} + void M2Renderer::setInstanceTransform(uint32_t instanceId, const glm::mat4& transform) { auto idxIt = instanceIndexById.find(instanceId); if (idxIt == instanceIndexById.end()) return;