Skip to content

Commit 123c8a2

Browse files
authored
Fixed clip planes lagging behind when parented to a bone on a model part (#1391)
Resolves last reported problem on issue #1341
1 parent c7d7c70 commit 123c8a2

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

lua/pac3/core/client/parts/bone.lua

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,12 @@ function PART:GetBonePosition()
290290
if not self.bone_index then return ent:GetPos(), ent:GetAngles() end
291291

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

295-
local pos = m:GetTranslation()
296-
local ang = m:GetAngles()
297-
298-
return pos, ang
294+
if m then
295+
return m:GetTranslation(), m:GetAngles()
296+
else
297+
return ent:GetPos(), ent:GetAngles()
298+
end
299299
end
300300

301301
function PART:GetBoneMatrix()
@@ -306,12 +306,15 @@ BUILDER:Register()
306306

307307
pac.AddHook("OnEntityCreated", "hide_mesh_no_crash", function(ent)
308308
local ply = ent:GetRagdollOwner()
309+
309310
if ply:IsPlayer() and ply.pac_inf_scale then
310311
for i = 0, ply:GetBoneCount() - 1 do
311312
local scale = ply:GetManipulateBoneScale(i)
313+
312314
if scale == inf_scale then
313-
scale = Vector(0,0,0)
315+
scale = vector_origin
314316
end
317+
315318
ply:ManipulateBoneScale(i, scale)
316319
end
317320
end

lua/pac3/core/client/parts/clip.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ do
4040
function PART:PreOnDraw()
4141
bclip = render_EnableClipping(true)
4242

43+
-- this fixes clip planes lagging behind when parented to a bone on a model part
44+
local owner = self:GetParentOwner()
45+
if owner:IsValid() and not owner.pac_clip_bonessetup and owner.PACPart then
46+
-- in case there are multiple clips on one model part, only the first one needs to call SetupBones
47+
self.pac_clip_owner = owner
48+
owner.pac_clip_bonessetup = true
49+
50+
pac.SetupBones(owner)
51+
end
52+
4353
local pos, ang = LocalToWorld(self.Position + self.PositionOffset, self:CalcAngles(self.Angles + self.AngleOffset), self:GetBonePosition())
4454
local normal = ang:Forward()
4555

@@ -49,6 +59,11 @@ do
4959
local render_PopCustomClipPlane = render.PopCustomClipPlane
5060

5161
function PART:PostOnDraw()
62+
if self.pac_clip_owner then
63+
self.pac_clip_owner.pac_clip_bonessetup = nil
64+
self.pac_clip_owner = nil
65+
end
66+
5267
render_PopCustomClipPlane()
5368

5469
render_EnableClipping(bclip)

0 commit comments

Comments
 (0)