diff --git a/Resources/Engine/Lua/Components/SkinnedMeshRenderer.lua b/Resources/Engine/Lua/Components/SkinnedMeshRenderer.lua index 5790939df..ddf2b2013 100644 --- a/Resources/Engine/Lua/Components/SkinnedMeshRenderer.lua +++ b/Resources/Engine/Lua/Components/SkinnedMeshRenderer.lua @@ -55,9 +55,12 @@ function SkinnedMeshRenderer:SetTime(timeSeconds) end ---@return number function SkinnedMeshRenderer:GetTime() end ---- Sets an external model used as animation source, or nil to use the rendered model ----@param model Model|nil -function SkinnedMeshRenderer:SetAnimationSourceModel(model) end +--- Sets an external model used as animation source, either as a Model or as an asset path. +--- A path is loaded on first use and cached by the model manager. +--- Pass nil, or an empty path, to use the rendered model animations +---@overload fun(self: SkinnedMeshRenderer, model: Model|nil) +---@overload fun(self: SkinnedMeshRenderer, path: string) +function SkinnedMeshRenderer:SetAnimationSourceModel(...) end --- Returns the external animation source model, or nil when the rendered model is used ---@return Model|nil diff --git a/Sources/OvCore/include/OvCore/ECS/Components/CSkinnedMeshRenderer.h b/Sources/OvCore/include/OvCore/ECS/Components/CSkinnedMeshRenderer.h index 76a4dd883..4998280ff 100644 --- a/Sources/OvCore/include/OvCore/ECS/Components/CSkinnedMeshRenderer.h +++ b/Sources/OvCore/include/OvCore/ECS/Components/CSkinnedMeshRenderer.h @@ -126,6 +126,14 @@ namespace OvCore::ECS::Components */ void SetAnimationSourceModel(OvRendering::Resources::Model* p_model); + /** + * Sets the external model used as animation source, resolved from its asset path. + * The model is loaded on first use and kept by the model manager, so repeated calls with the + * same path are cheap. Pass an empty path to use the rendered model animations. + * @param p_path + */ + void SetAnimationSourceModel(const std::string& p_path); + /** * Returns the external animation source model, or nullptr when the rendered model is used */ diff --git a/Sources/OvCore/src/OvCore/ECS/Components/CSkinnedMeshRenderer.cpp b/Sources/OvCore/src/OvCore/ECS/Components/CSkinnedMeshRenderer.cpp index db3dfcced..edc2b54ee 100644 --- a/Sources/OvCore/src/OvCore/ECS/Components/CSkinnedMeshRenderer.cpp +++ b/Sources/OvCore/src/OvCore/ECS/Components/CSkinnedMeshRenderer.cpp @@ -15,8 +15,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -437,6 +439,25 @@ void OvCore::ECS::Components::CSkinnedMeshRenderer::SetAnimationSourceModel(OvRe RebuildRuntimeData(); } +void OvCore::ECS::Components::CSkinnedMeshRenderer::SetAnimationSourceModel(const std::string& p_path) +{ + if (p_path.empty()) + { + SetAnimationSourceModel(static_cast(nullptr)); + return; + } + + auto* model = OvCore::Global::ServiceLocator::Get().GetResource(p_path); + + if (!model) + { + OVLOG_WARNING("SkinnedMeshRenderer: Animation source model '" + p_path + "' could not be loaded."); + return; + } + + SetAnimationSourceModel(model); +} + OvRendering::Resources::Model* OvCore::ECS::Components::CSkinnedMeshRenderer::GetAnimationSourceModel() const { return m_animationSourceModel; diff --git a/Sources/OvCore/src/OvCore/Scripting/Lua/Bindings/LuaComponentsBindings.cpp b/Sources/OvCore/src/OvCore/Scripting/Lua/Bindings/LuaComponentsBindings.cpp index 816842ff6..5c3b7dd35 100644 --- a/Sources/OvCore/src/OvCore/Scripting/Lua/Bindings/LuaComponentsBindings.cpp +++ b/Sources/OvCore/src/OvCore/Scripting/Lua/Bindings/LuaComponentsBindings.cpp @@ -105,7 +105,10 @@ void BindLuaComponents(sol::state& p_luaState) "GetMeshBoundsScale", &CSkinnedMeshRenderer::GetMeshBoundsScale, "SetTime", &CSkinnedMeshRenderer::SetTime, "GetTime", &CSkinnedMeshRenderer::GetTime, - "SetAnimationSourceModel", &CSkinnedMeshRenderer::SetAnimationSourceModel, + "SetAnimationSourceModel", sol::overload( + sol::resolve(&CSkinnedMeshRenderer::SetAnimationSourceModel), + sol::resolve(&CSkinnedMeshRenderer::SetAnimationSourceModel) + ), "GetAnimationSourceModel", &CSkinnedMeshRenderer::GetAnimationSourceModel, "IsAnimationSourceCompatible", &CSkinnedMeshRenderer::IsAnimationSourceCompatible, "GetAnimationCount", &CSkinnedMeshRenderer::GetAnimationCount,