Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions lua/pac3/editor/client/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
end

function pace.AddTool(name, callback, ...)
for i,v in pairs(pace.Tools) do

Check warning on line 29 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma
if v.name == name then
table.remove(pace.Tools, i)
end
Expand All @@ -49,7 +49,7 @@
}

local model_prop_translate = {
Color = function(tbl, val) tbl.Color = Vector(val.r/255, val.g/255, val.b/255) end,

Check warning on line 52 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 52 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator

Check warning on line 52 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Whitespace style"

Style: Please put some whitespace before the operator
DoubleFace = function(tbl, val) tbl.NoCulling = val end,
Fullbright = function(tbl, val) tbl.NoLighting = val end,

Expand Down Expand Up @@ -84,7 +84,7 @@
bone = {
Bone = function(tbl, val)
if bones[tbl.UniqueID] and not bones[tbl.UniqueID][val] then
for k,v in pairs(bones[tbl.UniqueID]) do

Check warning on line 87 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma
if v.bone == 0 then
tbl.Bone = v.friendly
return
Expand Down Expand Up @@ -150,30 +150,30 @@
tbl.self.ClassName = new_classname

if old_classname == "model" then
if tbl.self.BlurLength and tbl.self.BlurLength > 0 then
table.insert(tbl.children, {
self = {
ClassName = "motion_blur",
UniqueID = pac.Hash(),
BlurLength = tbl.self.BlurLength,
BlurSpacing = tbl.self.BlurSpacing,
},
children = {},
})
end

Check warning on line 163 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end

if old_classname == "entity" then
if tbl.self.Weapon == true and tbl.self.HideEntity then
table.insert(parent.children, {
self = {
ClassName = "weapon",
UniqueID = pac.Hash(),
NoDraw = true
},
children = {},
})
end

Check warning on line 176 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end

for key in pairs(registered_parts[old_classname].StorableVars) do
Expand All @@ -191,7 +191,7 @@
elseif not registered_parts[new_classname].StorableVars[key] then
local msg = tbl.self.ClassName .. "." .. key
if not done[msg] then
pac.Message(Color(255,100,100), "cannot translate property ", msg)

Check warning on line 194 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma

Check warning on line 194 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma
done[msg] = true
end
end
Expand All @@ -200,16 +200,16 @@
end

if tbl.self.ClassName == "proxy" and tbl.self.VariableName == "Color" then
if isstring(tbl.self.Expression) and tbl.self.Expression ~= "" then
local r,g,b = unpack(tbl.self.Expression:Split(","))
r = tonumber(r)
g = tonumber(g)
b = tonumber(b)

if r and g and b then
tbl.self.Expression = (r/255)..","..(g/255)..","..(b/255)
end
end

Check warning on line 212 in lua/pac3/editor/client/tools.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end

if tbl.self.Model and tbl.self.Model:find("://", nil, true) and not tbl.self.Model:find(".zip", nil, true) then
Expand Down Expand Up @@ -930,3 +930,117 @@
end
end)
end)

local function radial_sym(part, axis, num, i)
local rotD = (360/num)*i

if part.SetPosition then
local pos, posO = part:GetPosition()
local x, y, z = pos:Unpack()
local xA, yA, zA = axis:Unpack()

local rotR = math.rad(rotD)
local s, c = math.sin(rotR), math.cos(rotR)

part:SetPosition(Vector(
(c+(xA^2)*(1-c))*x+(xA*yA*(1-c)-zA*s)*y+(xA*zA*(1-c)+yA*s)*z,
(yA*xA*(1-c)+zA*s)*x+(c+(yA^2)*(1-c))*y+(yA*zA*(1-c)-xA*s)*z,
(zA*xA*(1-c)-yA*s)*x+(zA*yA*(1-c)+xA*s)*y+(c+(zA^2)*(1-c))*z))
else -- if the part is a group, we should still make its children radially symmetric
for _, part in ipairs(part:GetChildren()) do
radial_sym(part, axis, num, i)
end
end

if part.SetAngles then
local ang = Angle(part:GetAngles()) -- cloning required, or else bad stuff happens

ang:RotateAroundAxis(axis, rotD)

part:SetAngles(ang)
end
end

pace.AddTool(L"radial symmetry", function(part)
Derma_StringRequest(L"axis & number", L"input the axis to mirror around and the degree of symmetry.\ncan accept arbitrary vectors, e.g. 1 1 0 4", "z 4", function(input)
if input and part:IsValid() then
local args = string.Split(input, " ")
local axis, num

if #args == 2 then
axis = axis_planes[string.lower(args[1])]
num = tonumber(args[2])
elseif #args == 4 then
axis = Vector(args[1].." "..args[2].." "..args[3])
if not axis:IsZero() then -- cannot work with zero vectors
axis:Normalize()
num = tonumber(args[4])
end
end

if axis and num and num >= 2 then -- try to avoid errors and weird situations
num = math.floor(num)
for i = 1, num-1 do
radial_sym(part:Clone(), axis, num, i)
end
end
end
end)
end)

local function radial_sym_offset(part, axis, num, i)
local rotD = (360/num)*i

if part.SetPositionOffset then
local pos, posO = part:GetPositionOffset()
local x, y, z = pos:Unpack()
local xA, yA, zA = axis:Unpack()

local rotR = math.rad(rotD)
local s, c = math.sin(rotR), math.cos(rotR)

part:SetPositionOffset(Vector(
(c+(xA^2)*(1-c))*x+(xA*yA*(1-c)-zA*s)*y+(xA*zA*(1-c)+yA*s)*z,
(yA*xA*(1-c)+zA*s)*x+(c+(yA^2)*(1-c))*y+(yA*zA*(1-c)-xA*s)*z,
(zA*xA*(1-c)-yA*s)*x+(zA*yA*(1-c)+xA*s)*y+(c+(zA^2)*(1-c))*z))
else -- if the part is a group, we should still make its children radially symmetric
for _, part in ipairs(part:GetChildren()) do
radial_sym_offset(part, axis, num, i)
end
end

if part.SetAngleOffset then
local ang = Angle(part:GetAngleOffset()) -- cloning required, or else bad stuff happens

ang:RotateAroundAxis(axis, rotD)

part:SetAngleOffset(ang)
end
end

pace.AddTool(L"radial symmetry offset", function(part)
Derma_StringRequest(L"axis & number", L"input the axis to mirror around and the degree of symmetry for position and angle offsets.\ncan accept arbitrary vectors, e.g. 1 1 0 4", "z 4", function(input)
if input and part:IsValid() then
local args = string.Split(input, " ")
local axis, num

if #args == 2 then
axis = axis_planes[string.lower(args[1])]
num = tonumber(args[2])
elseif #args == 4 then
axis = Vector(args[1].." "..args[2].." "..args[3])
if not axis:IsZero() then -- cannot work with zero vectors
axis:Normalize()
num = tonumber(args[4])
end
end

if axis and num and num >= 2 then -- try to avoid errors and weird situations
num = math.floor(num)
for i = 1, num-1 do
radial_sym_offset(part:Clone(), axis, num, i)
end
end
end
end)
end)
Loading