Skip to content

Commit

Permalink
"AttachToNode" component can now use any other GameObject, not only a…
Browse files Browse the repository at this point in the history
… parent of the Component's GameObject
  • Loading branch information
Benualdo committed Sep 28, 2024
1 parent d1303b7 commit 2944115
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
16 changes: 10 additions & 6 deletions data/Prefabs/GJ.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<Property type="String" name="m_name" value="GJ"/>
<Property type="Uint32" name="m_uid" flags="" value="3525072167"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Opened|Selected"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Opened"/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="Float4" name="m_color" flags="Color" x="1" y="1" z="1" w="1"/>
<Property type="Float4x4" name="m_local" flags="Flatten" Ix="1" Iy="0" Iz="0" Iw="0" Jx="0" Jy="1" Jz="0" Jw="0" Kx="0" Ky="0" Kz="1" Kw="0" Tx="0" Ty="0" Tz="0" Tw="1"/>
Expand Down Expand Up @@ -143,7 +143,7 @@
<Property type="Object" name="m_sounds">
<Object class="SoundResourceList">
<Property type="String" name="m_name" flags="NotVisible" value=""/>
<Property type="Uint32" name="m_uid" flags="" value="0"/>
<Property type="Uint32" name="m_uid" flags="" value="127572953"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="ResourceVector" name="m_resources" flags="Resource"/>
Expand Down Expand Up @@ -191,7 +191,7 @@
<Property type="String" name="m_name" value="GJ_RightHand"/>
<Property type="Uint32" name="m_uid" flags="" value="2507986118"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Selected"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="Float4" name="m_color" flags="Color" x="1" y="1" z="1" w="1"/>
<Property type="Float4x4" name="m_local" flags="Flatten" Ix="-0.9999823" Iy="-0.0040099621" Iz="-0.0044074561" Iw="0" Jx="0.0039848005" Jy="0.099920698" Jz="-0.99498779" Jw="0" Kx="0.0044302288" Ky="-0.99498785" Kz="-0.099902965" Kw="0" Tx="-0.95762956" Ty="-0.012848332" Tz="1.2753206" Tw="1"/>
Expand Down Expand Up @@ -245,7 +245,9 @@
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Opened"/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="String" name="m_NodeName" value="Jg_ R Finger21"/>
<Property type="Bool" name="m_useTarget" flags="NotVisible" value="true"/>
<Property type="ObjectHandle" name="m_target" flags="Optional" value="3525072167"/>
<Property type="String" name="m_boneName" value="Jg_ R Finger21"/>
</Object>
</Property>
<Property type="ObjectPtrVector" name="m_children" flags="NotVisible"/>
Expand All @@ -254,7 +256,7 @@
<Property type="String" name="m_name" value="GJ_LeftHand"/>
<Property type="Uint32" name="m_uid" flags="" value="1563062627"/>
<Property type="Uint32" name="m_originalUID" flags="" value="2507986118"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Selected"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="Float4" name="m_color" flags="Color" x="1" y="1" z="1" w="1"/>
<Property type="Float4x4" name="m_local" flags="Flatten" Ix="0.99998224" Iy="-0.0040074023" Iz="-0.0044101356" Iw="0" Jx="-0.0039877649" Jy="0.099920601" Jz="-0.99498773" Jw="0" Kx="0.0044280384" Ky="0.99498743" Kz="0.099902824" Kw="0" Tx="0.95761532" Ty="-0.012845897" Tz="1.2753178" Tw="1"/>
Expand Down Expand Up @@ -308,7 +310,9 @@
<Property type="Uint32" name="m_originalUID" flags="" value="3645143640"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value="Opened"/>
<Property type="EnumFlagsU32" name="m_flags" flags="Bitfield" value="Enabled"/>
<Property type="String" name="m_NodeName" value="Jg_ L Finger21"/>
<Property type="Bool" name="m_useTarget" flags="NotVisible" value="true"/>
<Property type="ObjectHandle" name="m_target" flags="Optional" value="3525072167"/>
<Property type="String" name="m_boneName" value="Jg_ L Finger21"/>
</Object>
</Property>
<Property type="ObjectPtrVector" name="m_children" flags="NotVisible"/>
Expand Down
9 changes: 8 additions & 1 deletion data/Worlds/Game.world
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@
</Object>
<Object class="PrefabResource">
<Property type="String" name="m_name" flags="NotVisible" value=""/>
<Property type="Uint32" name="m_uid" flags="" value="0"/>
<Property type="Uint32" name="m_uid" flags="" value="3147124227"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="String" name="m_resourcePath" flags="NotVisible" value="data/Prefabs/Bat.prefab"/>
</Object>
<Object class="PrefabResource">
<Property type="String" name="m_name" flags="NotVisible" value=""/>
<Property type="Uint32" name="m_uid" flags="" value="0"/>
<Property type="Uint32" name="m_originalUID" flags="" value="0"/>
<Property type="EnumFlagsU32" name="m_objectFlags" flags="" value=""/>
<Property type="String" name="m_resourcePath" flags="NotVisible" value="data/Prefabs/GJ.prefab"/>
</Object>
</Property>
</Object>
</Root>
45 changes: 36 additions & 9 deletions src/engine/Component/Animation/AttachToNodeComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ namespace vg::engine
{
super::registerProperties(_desc);

registerProperty(AttachToNodeComponent, m_NodeName, "Node");
registerOptionalProperty(AttachToNodeComponent, m_useTarget, m_target, "Target");
setPropertyDescription(AttachToNodeComponent, m_target, "Use to specify another GameObject to look for skeleton. Otherwise the first skeleton found in parents will be used.");

registerProperty(AttachToNodeComponent, m_boneName, "Bone");
setPropertyDescription(AttachToNodeComponent, m_boneName, "The bone to follow. Bone names can be found under \"MeshComponent>Skeleton>Nodes\".");

return true;
}
Expand Down Expand Up @@ -80,7 +84,7 @@ namespace vg::engine
{
super::SetPropertyValue(_prop, _previousValue, _newValue);

if (&m_NodeName == _previousValue)
if (&m_boneName == _previousValue)
updateCache();
}

Expand All @@ -89,21 +93,44 @@ namespace vg::engine
{
clearCache();

if (const GameObject * go = getGameObject())
const GameObject * gameObject = nullptr;
const renderer::ISkeleton * skeleton = nullptr;

if (m_useTarget)
{
if (const MeshComponent * mc = go->GetComponentInParentsT<MeshComponent>())
if (const GameObject * go = m_target.get<GameObject>())
{
if (const renderer::IMeshInstance * mi = mc->getMeshInstance())
if (const MeshComponent * mc = go->GetComponentT<MeshComponent>())
{
if (const renderer::ISkeleton * sk = mi->GetSkeleton())
if (const renderer::IMeshInstance * mi = mc->getMeshInstance())
{
m_skeleton = sk;
m_nodeIndex = sk->FindNodeIndex(m_NodeName);
return true;
if (const renderer::ISkeleton * sk = mi->GetSkeleton())
skeleton = sk;
}
}
}
}
else
{
if (const GameObject * go = getGameObject())
{
if (const MeshComponent * mc = go->GetComponentInParentsT<MeshComponent>())
{
if (const renderer::IMeshInstance * mi = mc->getMeshInstance())
{
if (const renderer::ISkeleton * sk = mi->GetSkeleton())
skeleton = sk;
}
}
}
}

if (nullptr != skeleton)
{
m_skeleton = skeleton;
m_nodeIndex = skeleton->FindNodeIndex(m_boneName);
return true;
}

return false;
}
Expand Down
5 changes: 4 additions & 1 deletion src/engine/Component/Animation/AttachToNodeComponent.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "core/Component/Component.h"
#include "core/Object/ObjectHandle.h"

namespace vg::renderer
{
Expand Down Expand Up @@ -30,7 +31,9 @@ namespace vg::engine
void clearCache ();

private:
core::string m_NodeName;
bool m_useTarget = false;
core::ObjectHandle m_target;
core::string m_boneName;
const renderer::ISkeleton * m_skeleton;
renderer::NodeIndex m_nodeIndex;
};
Expand Down

0 comments on commit 2944115

Please sign in to comment.