From 7d376dab7f0a12fd141ad4a1d8d7052c325b79bc Mon Sep 17 00:00:00 2001 From: Ryan <20880060+Earu@users.noreply.github.com> Date: Mon, 26 Oct 2026 02:10:12 +0400 Subject: [PATCH] only draw relevant parts in opaque and translucent passes --- lua/pac3/core/client/base_part.lua | 77 ++++++++++++++++++++++++++++++ lua/pac3/core/client/part_pool.lua | 6 ++- 2 files changed, 81 insertions(+), 2 deletions(-) diff --git a/lua/pac3/core/client/base_part.lua b/lua/pac3/core/client/base_part.lua index 00149498a..fe6d815fb 100644 --- a/lua/pac3/core/client/base_part.lua +++ b/lua/pac3/core/client/base_part.lua @@ -487,6 +487,83 @@ do -- scene graph end end + do + local function filter_list(source, keep) + local out = {} + + for i = 1, #source do + local part = source[i] + + if keep(part) then + out[#out + 1] = part + end + end + + return out + end + + local function can_draw(part) + if not part.Draw then return false end + + if not part.OnDraw then + local drawable = pac.GetTemplate("base_drawable") + if drawable and part.Draw == drawable.PART.Draw then return false end + end + + return true + end + + local function can_build_bones(part) + return part.BuildBonePositions ~= PART.BuildBonePositions or part.OnBuildBonePositions ~= PART.OnBuildBonePositions + end + + function PART:GetDrawableChildrenList() + local source = self:GetChildrenList() + + if self.drawable_children_source ~= source then + self.drawable_children_source = source + self.drawable_children_list = filter_list(source, can_draw) + end + + return self.drawable_children_list + end + + function PART:GetBoneBuilderChildrenList() + local source = self:GetChildrenList() + + if self.bone_builder_children_source ~= source then + self.bone_builder_children_source = source + self.bone_builder_children_list = filter_list(source, can_build_bones) + end + + return self.bone_builder_children_list + end + + function PART:CallRecursiveDraw(draw_type) + if self.Draw then + self:Draw(draw_type) + end + + local list = self:GetDrawableChildrenList() + + for i = 1, #list do + list[i]:Draw(draw_type) + end + end + + function PART:CallRecursiveBuildBonePositions() + if self.BuildBonePositions then + self:BuildBonePositions() + end + + local list = self:GetBoneBuilderChildrenList() + + for i = 1, #list do + list[i]:BuildBonePositions() + end + end + end + function PART:CallRecursiveOnClassName(class_name, func, a,b,c) assert(c == nil, "EXTEND ME") if self[func] and self.ClassName == class_name then diff --git a/lua/pac3/core/client/part_pool.lua b/lua/pac3/core/client/part_pool.lua index ddbda93b3..dd4a29489 100644 --- a/lua/pac3/core/client/part_pool.lua +++ b/lua/pac3/core/client/part_pool.lua @@ -75,7 +75,7 @@ do for key, part in next, parts do if part:IsValid() then if not part:HasParent() then - part:CallRecursive("BuildBonePositions") + part:CallRecursiveBuildBonePositions() end else parts[key] = nil @@ -101,7 +101,7 @@ do part.OwnerName ~= "viewmodel" and part.OwnerName ~= "hands" and type ~= "viewmodel" and type ~= "hands" then if not part:IsDrawHidden() then - part:CallRecursive("Draw", type) + part:CallRecursiveDraw(type) end end end @@ -459,6 +459,8 @@ function pac.UpdatePartsWithMetatable(META) part[k] = v end end + + part:InvalidateChildrenList() end end end