Skip to content
6 changes: 3 additions & 3 deletions lua/pac3/core/client/bones.lua
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,14 @@ do -- bone manipulation for boneanimlib
for id, time in pairs(ent.pac_touching_flexes) do

if not reset_scale then
ent:SetFlexScale(1)
ent:SetFlexScale(1)
reset_scale = true
end

if time < pac.RealTime then
ent:SetFlexWeight(id, 0)
pac.SetFlexWeight(ent, id, 0)
else
if ent:GetFlexWeight(id) == 0 then
if pac.GetFlexWeight(ent, id) == 0 then
ent.pac_touching_flexes[id] = nil
end
end
Expand Down
6 changes: 4 additions & 2 deletions lua/pac3/core/client/hooks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ do
local tbl = ply.pac_pose_params

if tbl then
for _, data in pairs(tbl) do
ply:SetPoseParameter(data.key, data.val)
for i, data in pairs(tbl) do
if ply:LookupPoseParameter(data.key) ~= -1 then
ply:SetPoseParameter(data.key, data.val)
end
end
end
end
Expand Down
26 changes: 24 additions & 2 deletions lua/pac3/core/client/parts/faceposer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ BUILDER:StartStorableVars()
local i = tonumber(key:match("faceposer_flex(%d+)"))
if i then
local name = ent:GetFlexName(i)

if name then
weight = tonumber(weight) or 0

if part.UseRange then
weight = pac.ToFlexRange(ent, i, weight)
end

preset[name] = tonumber(weight)
end
end
Expand All @@ -49,6 +56,8 @@ BUILDER:StartStorableVars()
end})
:GetSet("FlexWeights", "", {hidden = true})
:GetSet("Scale", 1)
:GetSet("UseRange", false, {description="When enabled, the ranges defined in its Flex Controller will be used as opposed to the legacy global [0, 1] range"})
:GetSet("Clamped", false, {description="Limits the output range of the Flex to be within the legal ranges defined by its Flex Controller"})
:GetSet("Additive", false)
:EndStorableVars()

Expand Down Expand Up @@ -165,10 +174,23 @@ function PART:UpdateFlex()
for name, weight in pairs(self:GetWeightMap()) do
local id = ent:GetFlexIDByName(name)
if id then
if not self.UseRange then
weight = pac.ToFlexRange( ent, id, weight )
end

if self.Additive then
weight = ent:GetFlexWeight(id) + weight
weight = pac.GetFlexWeight(ent, id) + weight
end
ent:SetFlexWeight(id, weight)

if self.Clamped then
weight = math.Clamp(
weight,
ent:GetFlexBounds(id)
)
end

pac.SetFlexWeight(ent, id, weight)

ent.pac_touching_flexes[id] = pac.RealTime + 0.1
end
end
Expand Down
49 changes: 43 additions & 6 deletions lua/pac3/core/client/parts/flex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ BUILDER:StartStorableVars()
})

BUILDER:GetSet("Weight", 0)
BUILDER:GetSet("Additive", false)
BUILDER:GetSet("Additive", false)
BUILDER:GetSet("UseRange", false, {description="When enabled, the ranges defined in its Flex Controller will be used as opposed to the legacy global [0, 1] range"})
BUILDER:GetSet("Clamped", false, {description="Limits the output range of the Flex to be within the legal ranges defined by its Flex Controller"})
BUILDER:GetSet("RootOwner", false, { hide_in_editor = true })
BUILDER:EndStorableVars()

Expand All @@ -41,14 +43,49 @@ function PART:GetFlexID()
return flex and flex.i, ent
end

function PART:OnHide()
local id, ent = self:GetFlexID()
if not id then return end
ent.pac_touching_flexes = ent.pac_touching_flexes or {}
ent.pac_touching_flexes[id] = nil
pac.SetFlexWeight(ent, id, 0) -- added reset!
end

function PART:OnRemove()
local id, ent = self:GetFlexID()
if not id then return end
ent.pac_touching_flexes = ent.pac_touching_flexes or {}
ent.pac_touching_flexes[id] = nil
pac.SetFlexWeight(ent, id, 0) -- added reset!
end

function PART:OnBuildBonePositions()
local id, ent = self:GetFlexID()
if not id then return end
local weight = self.Weight
if self.Additive then
weight = weight + ent:GetFlexWeight(id)
end
ent:SetFlexWeight(id, weight)

local weight

if self.UseRange then
weight = self.Weight
else
-- backwards compatibility
weight = pac.ToFlexRange( ent, id, self.Weight )
end

if self.Additive then
weight = weight + pac.GetFlexWeight(ent, id)
end

-- added clamping to prevent explosion, particularly when using additive flexes
if self.Clamped then
weight = math.Clamp(
weight,
ent:GetFlexBounds(id)
)
end

pac.SetFlexWeight(ent, id, weight)

ent.pac_touching_flexes = ent.pac_touching_flexes or {}
ent.pac_touching_flexes[id] = pac.RealTime + 0.1
end
Expand Down
2 changes: 1 addition & 1 deletion lua/pac3/core/client/parts/model.lua
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ function PART:PreEntityDraw(ent, pos, ang)
end
end

if self.draw_bodygroups then
if self.draw_bodygroups and not self.IgnoreBodygroups then
for _, v in ipairs(self.draw_bodygroups) do
ent:SetBodygroup(v[1], v[2])
end
Expand Down
4 changes: 3 additions & 1 deletion lua/pac3/core/client/parts/model/entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ BUILDER:StartStorableVars()
:PropertyOrder("Name")
:PropertyOrder("Hide")
:PropertyOrder("ParentName")
:GetSet("IgnoreBodygroups", false, {description = "This part can change your rendered bodygroups. But there are now console commands to change your bodygroups, flexes and poseparams to save up on proxy costs and such.\nYou'll need this setting turned on to stop the entity from overwriting your bodygroups...\n\nRead up more in the console:\npac_override_bodygroup\npac_override_flexweights\npac_override_poseparameter"})

:SetPropertyGroup("appearance")
:GetSet("NoDraw", false)
:GetSet("DrawShadow", true)
Expand Down Expand Up @@ -277,4 +279,4 @@ function PART:OnThink()
end
end

BUILDER:Register()
BUILDER:Register()
13 changes: 12 additions & 1 deletion lua/pac3/core/client/parts/poseparameter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PART.Icon = 'icon16/disconnect.png'
BUILDER:StartStorableVars()
BUILDER:GetSet("PoseParameter", "", {enums = function(part) return part:GetPoseParameterList() end})
BUILDER:GetSet("Range", 0)
BUILDER:GetSet("RawRange", false, {description="Passes the raw value of Range to SetPoseParameter instead of remapping.\nFor example with head_yaw, a range of [-1,1] would then need to use [-75,75]"})
BUILDER:EndStorableVars()

function PART:GetNiceName()
Expand Down Expand Up @@ -49,7 +50,13 @@ function PART:UpdateParams()
local data = self.pose_params[self.PoseParameter]

if data then
local num = Lerp((self.Range + 1) / 2, data.range[1] or 0, data.range[2] or 1)
local num

if self.RawRange then
num = self.Range
else
num = Lerp((self.Range + 1) / 2, data.range[1] or 0, data.range[2] or 1)
end

ent.pac_pose_params = ent.pac_pose_params or {}
ent.pac_pose_params[self.UniqueID] = ent.pac_pose_params[self.UniqueID] or {}
Expand All @@ -62,6 +69,10 @@ function PART:UpdateParams()
end
end

function PART:OnBuildBonePositions()
self:UpdateParams()
end

function PART:OnHide()
local ent = self:GetOwner()

Expand Down
1 change: 1 addition & 0 deletions lua/pac3/core/shared/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include("http.lua")
include("movement.lua")
include("entity_mutator.lua")
include("hash.lua")
include("model_utils.lua")

pac.StringStream = include("pac3/libraries/string_stream.lua")

Expand Down
Loading