Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed clip planes lagging behind when parented to a bone on a model part #1391

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
15 changes: 9 additions & 6 deletions lua/pac3/core/client/parts/bone.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
local NULL = NULL

Check warning on line 1 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: NULL
local pairs = pairs
local Matrix = Matrix
local vector_origin = vector_origin
Expand All @@ -12,13 +12,13 @@
local BUILDER, PART = pac.PartTemplate("base_movable")

PART.FriendlyName = "bone"
PART.ClassName = "bone3"

Check warning on line 15 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
PART.Groups = {'entity', 'model'}

Check warning on line 16 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
PART.Icon = 'icon16/connect.png'

Check warning on line 17 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
PART.is_bone_part = true

BUILDER:StartStorableVars()
BUILDER:SetPropertyGroup("generic")

Check warning on line 21 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
BUILDER:PropertyOrder("Name")
BUILDER:PropertyOrder("Hide")
BUILDER:PropertyOrder("ParentName")
Expand All @@ -36,7 +36,7 @@
BUILDER:PropertyOrder("Angles")
BUILDER:PropertyOrder("EyeAngles")
BUILDER:GetSet("Size", 1, {editor_sensitivity = 0.25})
BUILDER:GetSet("Scale", Vector(1,1,1), {editor_sensitivity = 0.25})

Check warning on line 39 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma

Check warning on line 39 in lua/pac3/core/client/parts/bone.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma
BUILDER:PropertyOrder("PositionOffset")
BUILDER:PropertyOrder("AngleOffset")

Expand Down Expand Up @@ -290,12 +290,12 @@
if not self.bone_index then return ent:GetPos(), ent:GetAngles() end

local m = ent:GetBoneMatrix(self.bone_index)
if not m then return ent:GetPos(), ent:GetAngles() end

local pos = m:GetTranslation()
local ang = m:GetAngles()

return pos, ang
if m then
return m:GetTranslation(), m:GetAngles()
else
return ent:GetPos(), ent:GetAngles()
end
end

function PART:GetBoneMatrix()
Expand All @@ -306,12 +306,15 @@

pac.AddHook("OnEntityCreated", "hide_mesh_no_crash", function(ent)
local ply = ent:GetRagdollOwner()

if ply:IsPlayer() and ply.pac_inf_scale then
for i = 0, ply:GetBoneCount() - 1 do
local scale = ply:GetManipulateBoneScale(i)

if scale == inf_scale then
scale = Vector(0,0,0)
scale = vector_origin
end

ply:ManipulateBoneScale(i, scale)
end
end
Expand Down
15 changes: 15 additions & 0 deletions lua/pac3/core/client/parts/clip.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
local render_EnableClipping = render.EnableClipping
local render_PushCustomClipPlane = render.PushCustomClipPlane
local LocalToWorld = LocalToWorld
local IsEntity = IsEntity

Check warning on line 4 in lua/pac3/core/client/parts/clip.lua

View workflow job for this annotation

GitHub Actions / lint

"Unused variable"

Unused variable: IsEntity

local BUILDER, PART = pac.PartTemplate("base_drawable")

PART.FriendlyName = "clip"
PART.ClassName = "clip2"

Check warning on line 9 in lua/pac3/core/client/parts/clip.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
PART.Groups = {'model', 'modifiers'}

Check warning on line 10 in lua/pac3/core/client/parts/clip.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'single quoted strings' and 'double quoted strings'
PART.Icon = 'icon16/cut.png'

function PART:OnParent(part)
Expand Down Expand Up @@ -40,6 +40,16 @@
function PART:PreOnDraw()
bclip = render_EnableClipping(true)

-- this fixes clip planes lagging behind when parented to a bone on a model part
local owner = self:GetParentOwner()
if owner:IsValid() and not owner.pac_clip_bonessetup and owner.PACPart then
-- in case there are multiple clips on one model part, only the first one needs to call SetupBones
self.pac_clip_owner = owner
owner.pac_clip_bonessetup = true

pac.SetupBones(owner)
end

local pos, ang = LocalToWorld(self.Position + self.PositionOffset, self:CalcAngles(self.Angles + self.AngleOffset), self:GetBonePosition())
local normal = ang:Forward()

Expand All @@ -49,6 +59,11 @@
local render_PopCustomClipPlane = render.PopCustomClipPlane

function PART:PostOnDraw()
if self.pac_clip_owner then
self.pac_clip_owner.pac_clip_bonessetup = nil
self.pac_clip_owner = nil
end

render_PopCustomClipPlane()

render_EnableClipping(bclip)
Expand Down
Loading