Skip to content

Commit 0e6b679

Browse files
committed
limb spacing
1 parent 0e876c3 commit 0e6b679

11 files changed

Lines changed: 125 additions & 4 deletions

Content/Documentation/ScriptingAPI-Documentation.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,10 @@ Describes a Collider object.
15281528
- SetRagdollHeadSize(float value) -- Control the overall size of the ragdoll head (default: 1)
15291529
- GetRagdollFatness() : float
15301530
- GetRagdollHeadSize() : float
1531+
- SetArmSpacing(float value) -- dynamically modify arm spacing after animation (negative: pull together, positive: push apart)
1532+
- GetArmSpacing() : float
1533+
- SetLegSpacing(float value) -- dynamically modify leg spacing after animation (negative: pull together, positive: push apart)
1534+
- GetLegSpacing() : float
15311535

15321536
```lua
15331537
[outer] HumanoidBone = {
@@ -1542,11 +1546,11 @@ Describes a Collider object.
15421546
Jaw = 8,
15431547
LeftUpperLeg = 9, -- included in ragdoll
15441548
LeftLowerLeg = 10, -- included in ragdoll
1545-
LeftFoot = 11,
1549+
LeftFoot = 11, -- included in ragdoll
15461550
LeftToes = 12,
15471551
RightUpperLeg = 13, -- included in ragdoll
15481552
RightLowerLeg = 14, -- included in ragdoll
1549-
RightFoot = 15,
1553+
RightFoot = 15, -- included in ragdoll
15501554
RightToes = 16,
15511555
LeftShoulder = 17,
15521556
LeftUpperArm = 18, -- included in ragdoll

Editor/HumanoidWindow.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,20 @@ void HumanoidWindow::Create(EditorComponent* _editor)
149149
}));
150150
AddWidget(&ragdollHeadSizeSlider);
151151

152+
armSpacingSlider.Create(-1, 1, 0, 100, "Arm spacing: ");
153+
armSpacingSlider.SetTooltip("Adjust distance between arms.");
154+
armSpacingSlider.OnSlide(forEachSelected([](auto humanoid, auto args) {
155+
humanoid->arm_spacing = args.fValue;
156+
}));
157+
AddWidget(&armSpacingSlider);
158+
159+
legSpacingSlider.Create(-1, 1, 0, 100, "Leg spacing: ");
160+
legSpacingSlider.SetTooltip("Adjust distance between legs.");
161+
legSpacingSlider.OnSlide(forEachSelected([](auto humanoid, auto args) {
162+
humanoid->leg_spacing = args.fValue;
163+
}));
164+
AddWidget(&legSpacingSlider);
165+
152166
boneList.Create("Bones: ");
153167
boneList.OnSelect([&](wi::gui::EventArgs args) {
154168

@@ -314,6 +328,8 @@ void HumanoidWindow::SetEntity(Entity entity)
314328
eyeRotSpeedSlider.SetValue(humanoid->eye_rotation_speed);
315329
ragdollFatnessSlider.SetValue(humanoid->ragdoll_fatness);
316330
ragdollHeadSizeSlider.SetValue(humanoid->ragdoll_headsize);
331+
armSpacingSlider.SetValue(humanoid->arm_spacing);
332+
legSpacingSlider.SetValue(humanoid->leg_spacing);
317333

318334
Entity bone = humanoid->bones[size_t(HumanoidComponent::HumanoidBone::Head)];
319335
const TransformComponent* transform = scene.transforms.GetComponent(bone);
@@ -597,6 +613,8 @@ void HumanoidWindow::ResizeLayout()
597613
layout.add(headSizeSlider);
598614
layout.add(ragdollFatnessSlider);
599615
layout.add(ragdollHeadSizeSlider);
616+
layout.add(armSpacingSlider);
617+
layout.add(legSpacingSlider);
600618

601619
layout.jump();
602620

Editor/HumanoidWindow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class HumanoidWindow : public wi::gui::Window
2828
wi::gui::Slider headSizeSlider;
2929
wi::gui::Slider ragdollFatnessSlider;
3030
wi::gui::Slider ragdollHeadSizeSlider;
31+
wi::gui::Slider armSpacingSlider;
32+
wi::gui::Slider legSpacingSlider;
3133
wi::gui::TreeList boneList;
3234

3335
void ResizeLayout() override;

WickedEngine/wiScene.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3490,6 +3490,8 @@ namespace wi::scene
34903490
}
34913491
});
34923492

3493+
wi::jobsystem::Wait(ctx); // sync needed when there is IK on character arm/leg, and also arm/leg spacing!
3494+
34933495
wi::jobsystem::Dispatch(ctx, (uint32_t)humanoids.GetCount(), 1, [this, &recompute_hierarchy](wi::jobsystem::JobArgs args) {
34943496
Entity humanoidEntity = humanoids.GetEntity(args.jobIndex);
34953497
HumanoidComponent& humanoid = humanoids[args.jobIndex];
@@ -3614,6 +3616,35 @@ namespace wi::scene
36143616

36153617
}
36163618
}
3619+
3620+
if (humanoid.arm_spacing != 0.0f)
3621+
{
3622+
recompute_hierarchy.store(true);
3623+
size_t left_arm = transforms.GetIndex(humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::LeftUpperArm]);
3624+
size_t right_arm = transforms.GetIndex(humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::RightUpperArm]);
3625+
if (left_arm != ~0ull)
3626+
{
3627+
transforms_temp[left_arm].Rotate(XMQuaternionRotationNormal(FORWARD, -humanoid.arm_spacing * XM_PIDIV4));
3628+
}
3629+
if (right_arm != ~0ull)
3630+
{
3631+
transforms_temp[right_arm].Rotate(XMQuaternionRotationNormal(FORWARD, humanoid.arm_spacing * XM_PIDIV4));
3632+
}
3633+
}
3634+
if (humanoid.leg_spacing != 0.0f)
3635+
{
3636+
recompute_hierarchy.store(true);
3637+
size_t left_leg = transforms.GetIndex(humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::LeftUpperLeg]);
3638+
size_t right_leg = transforms.GetIndex(humanoid.bones[(size_t)HumanoidComponent::HumanoidBone::RightUpperLeg]);
3639+
if (left_leg != ~0ull)
3640+
{
3641+
transforms_temp[left_leg].Rotate(XMQuaternionRotationNormal(FORWARD, -humanoid.leg_spacing * XM_PIDIV4));
3642+
}
3643+
if (right_leg != ~0ull)
3644+
{
3645+
transforms_temp[right_leg].Rotate(XMQuaternionRotationNormal(FORWARD, humanoid.leg_spacing * XM_PIDIV4));
3646+
}
3647+
}
36173648
});
36183649

36193650
wi::jobsystem::Wait(ctx);

WickedEngine/wiScene.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ namespace wi::scene
5656
wi::ecs::ComponentManager<ColliderComponent>& colliders = componentLibrary.Register<ColliderComponent>("wi::scene::Scene::colliders", 2); // version = 2
5757
wi::ecs::ComponentManager<ScriptComponent>& scripts = componentLibrary.Register<ScriptComponent>("wi::scene::Scene::scripts");
5858
wi::ecs::ComponentManager<ExpressionComponent>& expressions = componentLibrary.Register<ExpressionComponent>("wi::scene::Scene::expressions");
59-
wi::ecs::ComponentManager<HumanoidComponent>& humanoids = componentLibrary.Register<HumanoidComponent>("wi::scene::Scene::humanoids", 2); // version = 2
59+
wi::ecs::ComponentManager<HumanoidComponent>& humanoids = componentLibrary.Register<HumanoidComponent>("wi::scene::Scene::humanoids", 3); // version = 3
6060
wi::ecs::ComponentManager<wi::terrain::Terrain>& terrains = componentLibrary.Register<wi::terrain::Terrain>("wi::scene::Scene::terrains", 5); // version = 5
6161
wi::ecs::ComponentManager<wi::Sprite>& sprites = componentLibrary.Register<wi::Sprite>("wi::scene::Scene::sprites", 2); // version = 2
6262
wi::ecs::ComponentManager<wi::SpriteFont>& fonts = componentLibrary.Register<wi::SpriteFont>("wi::scene::Scene::fonts");

WickedEngine/wiScene_BindLua.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7506,6 +7506,10 @@ Luna<HumanoidComponent_BindLua>::FunctionType HumanoidComponent_BindLua::methods
75067506
lunamethod(HumanoidComponent_BindLua, SetRagdollHeadSize),
75077507
lunamethod(HumanoidComponent_BindLua, GetRagdollFatness),
75087508
lunamethod(HumanoidComponent_BindLua, GetRagdollHeadSize),
7509+
lunamethod(HumanoidComponent_BindLua, SetArmSpacing),
7510+
lunamethod(HumanoidComponent_BindLua, GetArmSpacing),
7511+
lunamethod(HumanoidComponent_BindLua, SetLegSpacing),
7512+
lunamethod(HumanoidComponent_BindLua, GetLegSpacing),
75097513
{ NULL, NULL }
75107514
};
75117515
Luna<HumanoidComponent_BindLua>::PropertyType HumanoidComponent_BindLua::properties[] = {
@@ -7643,6 +7647,42 @@ int HumanoidComponent_BindLua::GetRagdollHeadSize(lua_State* L)
76437647
wi::lua::SSetFloat(L, component->ragdoll_headsize);
76447648
return 1;
76457649
}
7650+
int HumanoidComponent_BindLua::SetArmSpacing(lua_State* L)
7651+
{
7652+
int argc = wi::lua::SGetArgCount(L);
7653+
if (argc > 0)
7654+
{
7655+
component->arm_spacing = wi::lua::SGetFloat(L, 1);
7656+
}
7657+
else
7658+
{
7659+
wi::lua::SError(L, "SetArmSpacing(float value) not enough arguments!");
7660+
}
7661+
return 0;
7662+
}
7663+
int HumanoidComponent_BindLua::GetArmSpacing(lua_State* L)
7664+
{
7665+
wi::lua::SSetFloat(L, component->arm_spacing);
7666+
return 1;
7667+
}
7668+
int HumanoidComponent_BindLua::SetLegSpacing(lua_State* L)
7669+
{
7670+
int argc = wi::lua::SGetArgCount(L);
7671+
if (argc > 0)
7672+
{
7673+
component->leg_spacing = wi::lua::SGetFloat(L, 1);
7674+
}
7675+
else
7676+
{
7677+
wi::lua::SError(L, "SetLegSpacing(float value) not enough arguments!");
7678+
}
7679+
return 0;
7680+
}
7681+
int HumanoidComponent_BindLua::GetLegSpacing(lua_State* L)
7682+
{
7683+
wi::lua::SSetFloat(L, component->leg_spacing);
7684+
return 1;
7685+
}
76467686

76477687

76487688

WickedEngine/wiScene_BindLua.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,6 +1870,10 @@ namespace wi::lua::scene
18701870
int SetRagdollHeadSize(lua_State* L);
18711871
int GetRagdollFatness(lua_State* L);
18721872
int GetRagdollHeadSize(lua_State* L);
1873+
int SetArmSpacing(lua_State* L);
1874+
int GetArmSpacing(lua_State* L);
1875+
int SetLegSpacing(lua_State* L);
1876+
int GetLegSpacing(lua_State* L);
18731877
};
18741878

18751879
class DecalComponent_BindLua

WickedEngine/wiScene_Components.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ namespace wi::scene
174174

175175
XMStoreFloat4(&rotation_local, quat);
176176
}
177+
void TransformComponent::RotateRollPitchYaw(const XMVECTOR& value)
178+
{
179+
XMFLOAT3 v;
180+
XMStoreFloat3(&v, value);
181+
RotateRollPitchYaw(v);
182+
}
177183
void TransformComponent::Rotate(const XMFLOAT4& quaternion)
178184
{
179185
SetDirty();

WickedEngine/wiScene_Components.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ namespace wi::scene
9595
void Translate(const XMFLOAT3& value);
9696
void Translate(const XMVECTOR& value);
9797
void RotateRollPitchYaw(const XMFLOAT3& value);
98+
void RotateRollPitchYaw(const XMVECTOR& value);
9899
void Rotate(const XMFLOAT4& quaternion);
99100
void Rotate(const XMVECTOR& quaternion);
100101
void Scale(const XMFLOAT3& value);
@@ -2297,6 +2298,9 @@ namespace wi::scene
22972298

22982299
wi::ecs::Entity lookAtEntity = wi::ecs::INVALID_ENTITY; // lookAt can be fixed to specific entity
22992300

2301+
float arm_spacing = 0;
2302+
float leg_spacing = 0;
2303+
23002304
// Non-serialized attributes:
23012305
XMFLOAT3 lookAt = {}; // lookAt target pos, can be set by user
23022306
XMFLOAT4 lookAtDeltaRotationState_Head = XMFLOAT4(0, 0, 0, 1);

WickedEngine/wiScene_Serializers.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,6 +2401,12 @@ namespace wi::scene
24012401
{
24022402
SerializeEntity(archive, lookAtEntity, seri);
24032403
}
2404+
2405+
if (seri.GetVersion() >= 3)
2406+
{
2407+
archive >> arm_spacing;
2408+
archive >> leg_spacing;
2409+
}
24042410
}
24052411
else
24062412
{
@@ -2426,6 +2432,12 @@ namespace wi::scene
24262432
{
24272433
SerializeEntity(archive, lookAtEntity, seri);
24282434
}
2435+
2436+
if (seri.GetVersion() >= 3)
2437+
{
2438+
archive << arm_spacing;
2439+
archive << leg_spacing;
2440+
}
24292441
}
24302442
}
24312443
void MetadataComponent::Serialize(wi::Archive& archive, EntitySerializer& seri)

0 commit comments

Comments
 (0)