Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Resources/Engine/Lua/Components/SkinnedMeshRenderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
21 changes: 21 additions & 0 deletions Sources/OvCore/src/OvCore/ECS/Components/CSkinnedMeshRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include <OvCore/ECS/Actor.h>
#include <OvCore/ECS/Components/CModelRenderer.h>
#include <OvCore/ECS/Components/CSkinnedMeshRenderer.h>
#include <OvCore/Global/ServiceLocator.h>
#include <OvCore/Helpers/GUIDrawer.h>
#include <OvCore/Helpers/Serializer.h>
#include <OvCore/ResourceManagement/ModelManager.h>
#include <OvDebug/Logger.h>
#include <OvMaths/FMatrix3.h>
#include <OvMaths/FTransform.h>
Expand Down Expand Up @@ -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<OvRendering::Resources::Model*>(nullptr));
return;
}

auto* model = OvCore::Global::ServiceLocator::Get<OvCore::ResourceManagement::ModelManager>().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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(OvRendering::Resources::Model*)>(&CSkinnedMeshRenderer::SetAnimationSourceModel),
sol::resolve<void(const std::string&)>(&CSkinnedMeshRenderer::SetAnimationSourceModel)
),
"GetAnimationSourceModel", &CSkinnedMeshRenderer::GetAnimationSourceModel,
"IsAnimationSourceCompatible", &CSkinnedMeshRenderer::IsAnimationSourceCompatible,
"GetAnimationCount", &CSkinnedMeshRenderer::GetAnimationCount,
Expand Down