Skip to content
Merged
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
15 changes: 15 additions & 0 deletions Resources/Engine/Lua/Components/SkinnedMeshRenderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ function SkinnedMeshRenderer:GetBoneLocalRotation(boneIndex) end
---@return Vector3|nil
function SkinnedMeshRenderer:GetBoneLocalScale(boneIndex) end

--- Returns the current bone global position in skeleton/model space, excluding the owning actor's world transform, or nil
---@param boneIndex integer
---@return Vector3|nil
function SkinnedMeshRenderer:GetBoneGlobalPosition(boneIndex) end

--- Returns the current bone global rotation in skeleton/model space, excluding the owning actor's world transform, or nil
---@param boneIndex integer
---@return Quaternion|nil
function SkinnedMeshRenderer:GetBoneGlobalRotation(boneIndex) end

--- Returns the current bone global scale in skeleton/model space, excluding the owning actor's world transform, or nil
---@param boneIndex integer
---@return Vector3|nil
function SkinnedMeshRenderer:GetBoneGlobalScale(boneIndex) end

--- Sets local bone position
---@param boneIndex integer
---@param position Vector3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@ namespace OvCore::ECS::Components
*/
std::optional<OvMaths::FVector3> GetBoneLocalScale(uint32_t p_boneIndex) const;

/**
* Returns the current bone global position in skeleton/model space, excluding the owning actor's world transform
* @param p_boneIndex
* @return The bone global position, or std::nullopt if the bone index is invalid
*/
std::optional<OvMaths::FVector3> GetBoneGlobalPosition(uint32_t p_boneIndex) const;

/**
* Returns the current bone global rotation in skeleton/model space, excluding the owning actor's world transform
* @param p_boneIndex
* @return The bone global rotation, or std::nullopt if the bone index is invalid
*/
std::optional<OvMaths::FQuaternion> GetBoneGlobalRotation(uint32_t p_boneIndex) const;

/**
* Returns the current bone global scale in skeleton/model space, excluding the owning actor's world transform
* @param p_boneIndex
* @return The bone global scale, or std::nullopt if the bone index is invalid
*/
std::optional<OvMaths::FVector3> GetBoneGlobalScale(uint32_t p_boneIndex) const;

/**
* Sets the local bone position
* @param p_boneIndex
Expand Down
59 changes: 52 additions & 7 deletions Sources/OvCore/src/OvCore/ECS/Components/CSkinnedMeshRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ namespace
return interpolate(prev, next, next.time - prev.time);
}

void DecomposeLocalTransform(
void DecomposeTransform(
const OvMaths::FMatrix4& p_matrix,
OvMaths::FVector3& p_position,
OvMaths::FQuaternion& p_rotation,
Expand Down Expand Up @@ -571,7 +571,7 @@ std::optional<OvMaths::FVector3> OvCore::ECS::Components::CSkinnedMeshRenderer::
OvMaths::FVector3 position;
OvMaths::FQuaternion rotation;
OvMaths::FVector3 scale;
DecomposeLocalTransform(m_localPose[*nodeIndex], position, rotation, scale);
DecomposeTransform(m_localPose[*nodeIndex], position, rotation, scale);
return position;
}

Expand All @@ -586,7 +586,7 @@ std::optional<OvMaths::FQuaternion> OvCore::ECS::Components::CSkinnedMeshRendere
OvMaths::FVector3 position;
OvMaths::FQuaternion rotation;
OvMaths::FVector3 scale;
DecomposeLocalTransform(m_localPose[*nodeIndex], position, rotation, scale);
DecomposeTransform(m_localPose[*nodeIndex], position, rotation, scale);
return rotation;
}

Expand All @@ -601,7 +601,52 @@ std::optional<OvMaths::FVector3> OvCore::ECS::Components::CSkinnedMeshRenderer::
OvMaths::FVector3 position;
OvMaths::FQuaternion rotation;
OvMaths::FVector3 scale;
DecomposeLocalTransform(m_localPose[*nodeIndex], position, rotation, scale);
DecomposeTransform(m_localPose[*nodeIndex], position, rotation, scale);
return scale;
}

std::optional<OvMaths::FVector3> OvCore::ECS::Components::CSkinnedMeshRenderer::GetBoneGlobalPosition(uint32_t p_boneIndex) const
{
const auto nodeIndex = GetNodeIndexFromBoneIndex(p_boneIndex);
if (!nodeIndex.has_value() || *nodeIndex >= m_globalPose.size())
{
return std::nullopt;
}

OvMaths::FVector3 position;
OvMaths::FQuaternion rotation;
OvMaths::FVector3 scale;
DecomposeTransform(m_globalPose[*nodeIndex], position, rotation, scale);
return position;
}

std::optional<OvMaths::FQuaternion> OvCore::ECS::Components::CSkinnedMeshRenderer::GetBoneGlobalRotation(uint32_t p_boneIndex) const
{
const auto nodeIndex = GetNodeIndexFromBoneIndex(p_boneIndex);
if (!nodeIndex.has_value() || *nodeIndex >= m_globalPose.size())
{
return std::nullopt;
}

OvMaths::FVector3 position;
OvMaths::FQuaternion rotation;
OvMaths::FVector3 scale;
DecomposeTransform(m_globalPose[*nodeIndex], position, rotation, scale);
return rotation;
}

std::optional<OvMaths::FVector3> OvCore::ECS::Components::CSkinnedMeshRenderer::GetBoneGlobalScale(uint32_t p_boneIndex) const
{
const auto nodeIndex = GetNodeIndexFromBoneIndex(p_boneIndex);
if (!nodeIndex.has_value() || *nodeIndex >= m_globalPose.size())
{
return std::nullopt;
}

OvMaths::FVector3 position;
OvMaths::FQuaternion rotation;
OvMaths::FVector3 scale;
DecomposeTransform(m_globalPose[*nodeIndex], position, rotation, scale);
return scale;
}

Expand All @@ -616,7 +661,7 @@ bool OvCore::ECS::Components::CSkinnedMeshRenderer::SetBoneLocalPosition(uint32_
OvMaths::FVector3 currentPosition;
OvMaths::FQuaternion currentRotation;
OvMaths::FVector3 currentScale;
DecomposeLocalTransform(m_localPose[*nodeIndex], currentPosition, currentRotation, currentScale);
DecomposeTransform(m_localPose[*nodeIndex], currentPosition, currentRotation, currentScale);

const OvMaths::FTransform transform(p_position, currentRotation, currentScale);
m_localPose[*nodeIndex] = transform.GetLocalMatrix();
Expand All @@ -636,7 +681,7 @@ bool OvCore::ECS::Components::CSkinnedMeshRenderer::SetBoneLocalRotation(uint32_
OvMaths::FVector3 currentPosition;
OvMaths::FQuaternion currentRotation;
OvMaths::FVector3 currentScale;
DecomposeLocalTransform(m_localPose[*nodeIndex], currentPosition, currentRotation, currentScale);
DecomposeTransform(m_localPose[*nodeIndex], currentPosition, currentRotation, currentScale);

const OvMaths::FTransform transform(currentPosition, p_rotation, currentScale);
m_localPose[*nodeIndex] = transform.GetLocalMatrix();
Expand All @@ -656,7 +701,7 @@ bool OvCore::ECS::Components::CSkinnedMeshRenderer::SetBoneLocalScale(uint32_t p
OvMaths::FVector3 currentPosition;
OvMaths::FQuaternion currentRotation;
OvMaths::FVector3 currentScale;
DecomposeLocalTransform(m_localPose[*nodeIndex], currentPosition, currentRotation, currentScale);
DecomposeTransform(m_localPose[*nodeIndex], currentPosition, currentRotation, currentScale);

const OvMaths::FTransform transform(currentPosition, currentRotation, p_scale);
m_localPose[*nodeIndex] = transform.GetLocalMatrix();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ void BindLuaComponents(sol::state& p_luaState)
"GetBoneLocalPosition", &CSkinnedMeshRenderer::GetBoneLocalPosition,
"GetBoneLocalRotation", &CSkinnedMeshRenderer::GetBoneLocalRotation,
"GetBoneLocalScale", &CSkinnedMeshRenderer::GetBoneLocalScale,
"GetBoneGlobalPosition", &CSkinnedMeshRenderer::GetBoneGlobalPosition,
"GetBoneGlobalRotation", &CSkinnedMeshRenderer::GetBoneGlobalRotation,
"GetBoneGlobalScale", &CSkinnedMeshRenderer::GetBoneGlobalScale,
"SetBoneLocalPosition", &CSkinnedMeshRenderer::SetBoneLocalPosition,
"SetBoneLocalRotation", &CSkinnedMeshRenderer::SetBoneLocalRotation,
"SetBoneLocalScale", &CSkinnedMeshRenderer::SetBoneLocalScale
Expand Down