From 4e8eb09f166fa73c1c2390f570fa3e978b765cf0 Mon Sep 17 00:00:00 2001 From: TW1STaL1CKY Date: Sat, 15 Feb 2025 16:55:09 +0000 Subject: [PATCH 1/2] Fixed clip planes lagging behind when parented to a bone on a model part Resolves last reported problem on issue #1341 --- lua/pac3/core/client/parts/bone.lua | 15 +++++++++------ lua/pac3/core/client/parts/clip.lua | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lua/pac3/core/client/parts/bone.lua b/lua/pac3/core/client/parts/bone.lua index e3414b447..29526e574 100644 --- a/lua/pac3/core/client/parts/bone.lua +++ b/lua/pac3/core/client/parts/bone.lua @@ -290,12 +290,12 @@ function PART:GetBonePosition() 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() @@ -306,12 +306,15 @@ BUILDER:Register() 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 diff --git a/lua/pac3/core/client/parts/clip.lua b/lua/pac3/core/client/parts/clip.lua index 7b40e4f0a..08d09d3a9 100644 --- a/lua/pac3/core/client/parts/clip.lua +++ b/lua/pac3/core/client/parts/clip.lua @@ -40,6 +40,12 @@ do 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 owner.PACPart then + pac.SetupBones(owner) + end + local pos, ang = LocalToWorld(self.Position + self.PositionOffset, self:CalcAngles(self.Angles + self.AngleOffset), self:GetBonePosition()) local normal = ang:Forward() From 4d8e6d8c99939b50f7ebe7037689838c46dfd09f Mon Sep 17 00:00:00 2001 From: TW1STaL1CKY Date: Sun, 16 Feb 2025 20:40:57 +0000 Subject: [PATCH 2/2] Prevent multiple clip parts calling SetupBones on the same model --- lua/pac3/core/client/parts/clip.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/pac3/core/client/parts/clip.lua b/lua/pac3/core/client/parts/clip.lua index 08d09d3a9..7dda463a2 100644 --- a/lua/pac3/core/client/parts/clip.lua +++ b/lua/pac3/core/client/parts/clip.lua @@ -42,7 +42,11 @@ do -- this fixes clip planes lagging behind when parented to a bone on a model part local owner = self:GetParentOwner() - if owner:IsValid() and owner.PACPart then + 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 @@ -55,6 +59,11 @@ do 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)