mirror of
https://github.com/Sevii77/proper_clipping.git
synced 2025-03-04 03:13:04 -05:00
physicize tool, closes #9
This commit is contained in:
parent
ce03d75420
commit
996fabbc1b
60
lua/weapons/gmod_tool/stools/proper_clipping_physicize.lua
Normal file
60
lua/weapons/gmod_tool/stools/proper_clipping_physicize.lua
Normal file
@ -0,0 +1,60 @@
|
||||
TOOL.Category = "Construction"
|
||||
TOOL.Name = "#Tool.proper_clipping_physicize.name"
|
||||
|
||||
if CLIENT then
|
||||
language.Add("Tool.proper_clipping_physicize.name", "Proper Clipping Physicize")
|
||||
language.Add("Tool.proper_clipping_physicize.desc", "Convert non-physics clips to physics")
|
||||
|
||||
language.Add("Tool.proper_clipping_physicize.left", "Convert")
|
||||
|
||||
TOOL.Information = {
|
||||
{stage = 0, name = "left"}
|
||||
}
|
||||
end
|
||||
|
||||
function TOOL:LeftClick(tr)
|
||||
local ent = tr.Entity
|
||||
if not ent.Clipped then return end
|
||||
if CLIENT then return true end
|
||||
|
||||
local owner = self:GetOwner()
|
||||
local valid, left = ProperClipping.CanAddPhysicsClip(ent, owner)
|
||||
|
||||
if not valid then
|
||||
owner:ChatPrint("Entity cannot be physically clipped")
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local norms, dists, insides, physicss = {}, {}, {}, {}
|
||||
local i = 1
|
||||
for _, clip in ipairs(ent.ClipData) do
|
||||
if not clip.physics then
|
||||
left = left - 1
|
||||
|
||||
if left < 0 then
|
||||
owner:ChatPrint("Max physics clips per entity reached (max " .. ProperClipping.MaxPhysicsClips() .. ") converted " .. (i - 1) .. " clips")
|
||||
|
||||
break
|
||||
end
|
||||
|
||||
norms[i] = clip.norm
|
||||
dists[i] = clip.dist
|
||||
insides[i] = clip.inside
|
||||
physicss[i] = true
|
||||
i = i + 1
|
||||
end
|
||||
end
|
||||
|
||||
if #norms > 0 then
|
||||
for i = 1, #norms do
|
||||
ProperClipping.RemoveClip(ent, select(2, ProperClipping.ClipExists(ent, norms[i], dists[i])))
|
||||
end
|
||||
|
||||
ProperClipping.AddClip(ent, norms, dists, insides, physicss)
|
||||
end
|
||||
|
||||
owner:ChatPrint("Converted " .. (i - 1) .. " clips")
|
||||
|
||||
return true
|
||||
end
|
Loading…
Reference in New Issue
Block a user