minor wm render optimiz

This commit is contained in:
Darsu 2025-01-31 07:19:04 +07:00
parent 05ce80d82d
commit 0c252b5f6f
3 changed files with 95 additions and 91 deletions

View File

@ -39,7 +39,7 @@ function SWEP:DrawCustomModel(wm, custompos, customang)
mdl = self.WModel
lod = self:ShouldLOD()
if mdl and mdl[1]:IsValid() then
if lod == 0 and mdl and mdl[1]:IsValid() then
mdl[1]:SetMaterial(self:GetProcessedValue("Material", true))
for ind = 0, 31 do
@ -71,11 +71,11 @@ function SWEP:DrawCustomModel(wm, custompos, customang)
end
end
local onground = wm and !IsValid(owner)
local hidebones = self:GetHiddenBones(wm)
if lod < 2 then
local onground = wm and !IsValid(owner)
local hidebones = self:GetHiddenBones(wm)
for _, model in ipairs(mdl or {}) do
if model.IsAnimationProxy then continue end
local slottbl = model.slottbl

View File

@ -1,4 +1,5 @@
SWEP.ModelVersion = 0
local v0, a0 = Vector(0, 0, 0), Angle(0, 0, 0)
function SWEP:GetAttachmentPos(slottbl, wm, idle, nomodeloffset, custompos, customang, dupli)
dupli = dupli or 0
@ -63,10 +64,10 @@ function SWEP:GetAttachmentPos(slottbl, wm, idle, nomodeloffset, custompos, cust
atttbl = self:GetFinalAttTable(slottbl)
end
local icon_offset = slottbl.Icon_Offset or Vector()
local icon_offset = slottbl.Icon_Offset or v0
local offset_pos = slottbl.Pos or Vector(0, 0, 0)
local offset_ang = slottbl.Ang or Angle(0, 0, 0)
local offset_pos = slottbl.Pos or v0
local offset_ang = slottbl.Ang or a0
local bpos, bang
if dupli > 0 then
@ -79,7 +80,7 @@ function SWEP:GetAttachmentPos(slottbl, wm, idle, nomodeloffset, custompos, cust
if parentmdl and bone then
local boneindex = parentmdl:LookupBone(bone)
if !boneindex then return vector_origin, angle_zero, vector_origin end
if !boneindex then return v0, a0, v0 end
if parentmdl == self:GetOwner() then
parentmdl:SetupBones()
@ -92,7 +93,7 @@ function SWEP:GetAttachmentPos(slottbl, wm, idle, nomodeloffset, custompos, cust
end
elseif custompos then
bpos = custompos
bang = customang or Angle(0, 0, 0)
bang = customang or a0
end
if slottbl.OriginalAddress then
@ -130,7 +131,7 @@ function SWEP:GetAttachmentPos(slottbl, wm, idle, nomodeloffset, custompos, cust
apos = apos + aang:Up() * offset_pos.z
if !nomodeloffset then
offset_ang = offset_ang + (atttbl.ModelAngleOffset or angle_zero)
offset_ang = offset_ang + (atttbl.ModelAngleOffset or a0)
end
aang:Set(bang)
@ -144,7 +145,7 @@ function SWEP:GetAttachmentPos(slottbl, wm, idle, nomodeloffset, custompos, cust
aang:RotateAroundAxis(up, offset_ang.y)
if !nomodeloffset then
local moffset = (atttbl.ModelOffset or Vector(0, 0, 0)) * (slottbl.Scale or 1)
local moffset = (atttbl.ModelOffset or v0) * (slottbl.Scale or 1)
if wm then
moffset = moffset * (self.WorldModelOffset.Scale or 1)
end

View File

@ -4,9 +4,10 @@ local v1 = Vector(1, 1, 1)
function SWEP:DoBodygroups(wm, cm)
if cm then wm = true end
local owner = self:GetOwner()
local isnpc = owner:IsNPC() or self:ShouldLOD() > 0
if !wm and !IsValid(owner) then return end
if !wm and owner:IsNPC() then return end
if !wm and !IsValid(owner) or isnpc then return end
local dbg = self.DefaultBodygroups
@ -26,10 +27,6 @@ function SWEP:DoBodygroups(wm, cm)
mdl:SetSkin(self.DefaultSkin)
mdl:SetBodyGroups(dbg or "")
for i = 0, mdl:GetBoneCount() do
mdl:ManipulateBoneScale(i, v1)
end
local eles = self:GetAttachmentElements()
for _, ele in ipairs(eles) do
@ -44,92 +41,98 @@ function SWEP:DoBodygroups(wm, cm)
end
end
local bbg = self.BulletBodygroups
if bbg then
local amt = self:Clip1()
if self:GetReloading() then
amt = self:GetLoadedRounds()
if !isnpc then
for i = 0, mdl:GetBoneCount() do
mdl:ManipulateBoneScale(i, v1)
end
for c, bgs in ipairs(bbg or {}) do
if !isnumber(c) then continue end
if amt < c then
mdl:SetBodygroup(bgs[1], bgs[2])
break
end
end
end
local bbg = self.BulletBodygroups
local stbg = self.SoundTableBodygroups
if stbg then
for i, k in pairs(stbg) do
mdl:SetBodygroup(i, k)
end
end
if bbg and !isnpc then
local amt = self:Clip1()
if CLIENT then
for i = 0, mdl:GetNumPoseParameters() - 1 do
mdl:SetPoseParameter(i, 0)
local ii = mdl:GetPoseParameterName(i)
if self.SoundTablePoseParams[ii] then
mdl:SetPoseParameter(i, self.SoundTablePoseParams[ii])
end
end
end
local hidebones = self:GetHiddenBones(wm)
for bone, a in pairs(hidebones or {}) do
if !a then continue end
local boneid = isnumber(bone) and bone or mdl:LookupBone(bone)
if !boneid then continue end
mdl:ManipulateBoneScale(boneid, v0)
end
local bulletbones = self:GetProcessedValue("BulletBones", true)
if bulletbones then
for i, bone in ipairs(bulletbones or {}) do
local bones = bone
if !istable(bones) then
bones = {bone}
if self:GetReloading() then
amt = self:GetLoadedRounds()
end
local loaded = self:GetLoadedRounds() - (self.BulletBonesSub1 and 1 or 0)
if self:GetProcessedValue("BottomlessClip", true) then loaded = self:Ammo1() end
for _, bone2 in ipairs(bones) do
local boneid = isnumber(bone2) and bone2 or mdl:LookupBone(bone2)
if !boneid then continue end
if i > loaded and !clear then
mdl:ManipulateBoneScale(boneid, v0)
for c, bgs in ipairs(bbg or {}) do
if !isnumber(c) then continue end
if amt < c then
mdl:SetBodygroup(bgs[1], bgs[2])
break
end
end
end
end
local stripperbones = self:GetProcessedValue("StripperClipBones", true)
if stripperbones then
for i, bone in ipairs(stripperbones or {}) do
local bones = bone
if !istable(bones) then
bones = {bone}
local stbg = self.SoundTableBodygroups
if stbg and !isnpc then
for i, k in pairs(stbg) do
mdl:SetBodygroup(i, k)
end
end
for _, bone2 in ipairs(bones) do
local boneid = isnumber(bone2) and bone2 or mdl:LookupBone(bone2)
if CLIENT then
for i = 0, mdl:GetNumPoseParameters() - 1 do
mdl:SetPoseParameter(i, 0)
local ii = mdl:GetPoseParameterName(i)
if !boneid then continue end
if self.SoundTablePoseParams[ii] then
mdl:SetPoseParameter(i, self.SoundTablePoseParams[ii])
end
end
end
if i > self:GetLoadingIntoClip() and !clear then
mdl:ManipulateBoneScale(boneid, v0)
local hidebones = self:GetHiddenBones(wm)
for bone, a in pairs(hidebones or {}) do
if !a then continue end
local boneid = isnumber(bone) and bone or mdl:LookupBone(bone)
if !boneid then continue end
mdl:ManipulateBoneScale(boneid, v0)
end
local bulletbones = self:GetProcessedValue("BulletBones", true)
if bulletbones then
for i, bone in ipairs(bulletbones or {}) do
local bones = bone
if !istable(bones) then
bones = {bone}
end
local loaded = self:GetLoadedRounds() - (self.BulletBonesSub1 and 1 or 0)
if self:GetProcessedValue("BottomlessClip", true) then loaded = self:Ammo1() end
for _, bone2 in ipairs(bones) do
local boneid = isnumber(bone2) and bone2 or mdl:LookupBone(bone2)
if !boneid then continue end
if i > loaded and !clear then
mdl:ManipulateBoneScale(boneid, v0)
end
end
end
end
local stripperbones = self:GetProcessedValue("StripperClipBones", true)
if stripperbones then
for i, bone in ipairs(stripperbones or {}) do
local bones = bone
if !istable(bones) then
bones = {bone}
end
for _, bone2 in ipairs(bones) do
local boneid = isnumber(bone2) and bone2 or mdl:LookupBone(bone2)
if !boneid then continue end
if i > self:GetLoadingIntoClip() and !clear then
mdl:ManipulateBoneScale(boneid, v0)
end
end
end
end
@ -143,7 +146,7 @@ function SWEP:DoBodygroups(wm, cm)
self:RunHook("Hook_ModifyBodygroups", {model = mdl, elements = self:GetElements()})
if CLIENT then
if CLIENT and !isnpc then
local pptables = self:GetReloadPoseParameterTable(wm)
for pp, ppv in pairs(pptables or {}) do