Skip to content

Commit c2feb28

Browse files
committed
Fix hiding/showing of bones, show arm bones on death/unarmed state
1 parent 3cf2b43 commit c2feb28

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/Layers/xrRender_R2/r2.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Layers/xrRender/SkeletonCustom.h"
99
#include "Layers/xrRender/dxWallMarkArray.h"
1010
#include "Layers/xrRender/dxUIShader.h"
11+
#include "xrEngine/xr_object.h"
1112

1213
#if defined(USE_DX11)
1314
#include "Layers/xrRenderDX11/3DFluid/dx113DFluidManager.h"

src/xrGame/Actor.cpp

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -465,17 +465,14 @@ void CActor::Load(LPCSTR section)
465465
// initialize bones for first person body
466466
m_firstPersonBodyBonesToHide =
467467
{
468-
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_head"), true},
469-
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_neck"), true },
468+
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_head"), true },
470469
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_l_clavicle"), true },
471470
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_r_clavicle"), true },
472471
};
473472

474473
m_firstPersonBodyBonesToIgnoreAnims =
475474
{
476-
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_spine"), true },
477-
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_spine1"), true },
478-
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_spine2"), true },
475+
{ Visual()->dcast_PKinematics()->LL_BoneID("bip01_head"), false},
479476
};
480477
}
481478

@@ -1563,19 +1560,49 @@ void CActor::RenderFirstPersonBody(u32 context_id, IRenderable* root)
15631560
GEnv.Render->add_Visual(context_id, root, m_firstPersonBody, m_firstPersonBodyXform);
15641561
m_firstPersonBody->getVisData().hom_frame = Device.dwFrame;
15651562

1566-
// Copy transforms from actual body visual, excluding bones we don't want to animate
1563+
PIItem pItem = inventory().ActiveItem();
1564+
bool noItemEquipped = 0 == pItem;
1565+
1566+
// On death or unarmed, show arms
1567+
if (!g_Alive() || noItemEquipped)
1568+
{
1569+
m_firstPersonBodyBonesToHide[m_firstPersonBody->dcast_PKinematics()->LL_BoneID("bip01_l_clavicle")] = false;
1570+
m_firstPersonBodyBonesToHide[m_firstPersonBody->dcast_PKinematics()->LL_BoneID("bip01_r_clavicle")] = false;
1571+
1572+
for (auto [boneId, vis] : m_firstPersonBodyBonesToIgnoreAnims)
1573+
{
1574+
m_firstPersonBodyBonesToIgnoreAnims[boneId] = false;
1575+
}
1576+
}
1577+
else
1578+
{
1579+
m_firstPersonBodyBonesToHide[m_firstPersonBody->dcast_PKinematics()->LL_BoneID("bip01_l_clavicle")] = true;
1580+
m_firstPersonBodyBonesToHide[m_firstPersonBody->dcast_PKinematics()->LL_BoneID("bip01_r_clavicle")] = true;
1581+
1582+
for (auto [boneId, vis] : m_firstPersonBodyBonesToIgnoreAnims)
1583+
{
1584+
m_firstPersonBodyBonesToIgnoreAnims[boneId] = true;
1585+
}
1586+
}
1587+
1588+
// Copy transforms from actual body visual, excluding hidden bones and bones we don't want to animate
15671589
const u16 bones_count = kinematics->LL_BoneCount();
15681590
for (u16 i = 0; i < bones_count; ++i)
15691591
{
1570-
if (m_firstPersonBodyBonesToIgnoreAnims[i])
1592+
if (m_firstPersonBodyBonesToIgnoreAnims.find(i) != m_firstPersonBodyBonesToIgnoreAnims.end() && m_firstPersonBodyBonesToIgnoreAnims[i])
1593+
continue;
1594+
if (m_firstPersonBodyBonesToHide.find(i) != m_firstPersonBodyBonesToHide.end() && m_firstPersonBodyBonesToHide[i])
15711595
continue;
15721596

1597+
kinematics->LL_GetTransform(i).set(realBodyK->LL_GetTransform(i));
15731598
kinematics->LL_GetTransform_R(i).set(realBodyK->LL_GetTransform_R(i));
15741599
}
15751600

1576-
// Hide bones
1577-
for (auto [boneId, vis] : m_firstPersonBodyBonesToHide)
1578-
kinematics->LL_SetBoneVisible(boneId, !vis, true);
1601+
// Hide/show bones AFTER copying transforms so we update all child bones properly
1602+
for (auto [boneId, hide] : m_firstPersonBodyBonesToHide)
1603+
{
1604+
kinematics->LL_SetBoneVisible(boneId, hide ? FALSE : TRUE, TRUE);
1605+
}
15791606

15801607
// Update camera position
15811608
m_firstPersonCameraXform.set(m_firstPersonBodyXform);

0 commit comments

Comments
 (0)