Skip to content
Open
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
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
pac.SetPoseParameter(ply, 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 self.OverrideBodygroups 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("OverrideBodygroups", true, {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 off 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()
24 changes: 22 additions & 2 deletions 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("UseRange", false, {description="Limits the output range of the Pose Parameter to be within the legal ranges defined by the model"})
BUILDER:EndStorableVars()

function PART:GetNiceName()
Expand Down Expand Up @@ -49,19 +50,38 @@ 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.UseRange then
num = self.Range
else
-- backwards compatibility; reverts the math in the new setter
-- old calculation

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

num = pac.ToPoseParameterRange(
ent,
data.name,
num
)
end

ent.pac_pose_params = ent.pac_pose_params or {}
ent.pac_pose_params[self.UniqueID] = ent.pac_pose_params[self.UniqueID] or {}

ent.pac_pose_params[self.UniqueID].key = data.name
ent.pac_pose_params[self.UniqueID].val = num

ent:SetPoseParameter(data.name, num)
pac.SetPoseParameter(ent, data.name, num)
end
end
end

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

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

Expand Down
Loading