Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions lua/pac3/editor/client/mctrl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,39 @@ function mctrl.RotationLines(pos, dir, dir2, r)
DrawLine(pr.x, pr.y, prb.x, prb.y)
end

function mctrl.ManualPaint(pos, ang, radius)
local forward, right, up = pace.mctrl.GetAxes(ang)
local radius = 2 * pace.mctrl.GetGizmoSize()
local origin = pace.mctrl.VecToScreen(pos)
local forward_point = pace.mctrl.VecToScreen(pos + forward * radius)
local right_point = pace.mctrl.VecToScreen(pos + right * radius)
local up_point = pace.mctrl.VecToScreen(pos + up * radius)

mctrl.nodraw = true
surface.SetDrawColor(255, 80, 80, 255)
mctrl.LineToBox(origin, forward_point)
mctrl.RotationLines(pos, forward, up, radius)

surface.SetDrawColor(80, 255, 80, 255)
mctrl.LineToBox(origin, right_point)
mctrl.RotationLines(pos, right, forward, radius)

surface.SetDrawColor(80, 80, 255, 255)
mctrl.LineToBox(origin, up_point)
mctrl.RotationLines(pos, up, right, radius)

surface.SetDrawColor(255, 200, 0, 255)
DrawCircleEx(origin.x, origin.y, 4, 32, 2)
end

function mctrl.HUDPaint()
mctrl.LastThinkCall = FrameNumber()
if pace.IsSelecting then return end
local target = mctrl.GetTarget()
if not target then return end
local pos, ang = mctrl.GetWorldPosition()
if not pos or not ang then return end
if mctrl.nodraw then return end --to allow overridden rendering
local forward, right, up = mctrl.GetAxes(ang)
local radius = mctrl.GetGizmoSize()
local origin = mctrl.VecToScreen(pos)
Expand Down
23 changes: 23 additions & 0 deletions lua/pac3/editor/client/parts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,29 @@ function pace.AddQuickSetupsToPartMenu(menu, obj)
substitutes:AddOption("interpolator", function()
pace.SubstituteBaseMovable(obj, "create_parent", "interpolated_multibone")
end):SetIcon("icon16/table_multiple.png")

--mirroring
local tooltip = "Axis is relative to parent bone\nThe output stays within that same bone\n\nIf you wish to mirror on flipped bones, it can work. I recommend using the bone 'switch sides' action first, and then double-check your axis to make sure you know what's the new bone's actual base angle."
local mirror_submenu1, pnlsubmenu = main:AddSubMenu("Mirror parts...") pnlsubmenu:SetImage("icon16/shape_flip_horizontal.png") pnlsubmenu:SetTooltip(tooltip)
mirror_submenu1:AddOption("x", function() pac.MirrorParts(pace.current_part, "x") end)
mirror_submenu1:AddOption("y", function() pac.MirrorParts(pace.current_part, "y") end)
mirror_submenu1:AddOption("z", function() pac.MirrorParts(pace.current_part, "z") end)
local mirror_submenu2, pnlsubmenu = main:AddSubMenu("Clone and Mirror parts...") pnlsubmenu:SetImage("icon16/shape_flip_horizontal.png") pnlsubmenu:SetTooltip(tooltip)
mirror_submenu2:AddOption("x", function() pac.MirrorParts(pace.current_part:Clone(), "x") end)
mirror_submenu2:AddOption("y", function() pac.MirrorParts(pace.current_part:Clone(), "y") end)
mirror_submenu2:AddOption("z", function() pac.MirrorParts(pace.current_part:Clone(), "z") end)
--override the gizmo to real coordinates used by mirror tool
pac.AddHook("HUDPaint", "mirror_tool_preview_bone_posang", function()
if not IsValid(menu) then
pace.mctrl.nodraw = false pac.RemoveHook("HUDPaint", "mirror_tool_preview_bone_posang") return
end
if pnlsubmenu1:IsHovered() or pnlsubmenu1:IsChildHovered() or pnlsubmenu2:IsHovered() or pnlsubmenu2:IsChildHovered() then
local pos, ang = pac.GetBonePosAng(pace.current_part:GetParentOwner(), pace.current_part.Bone)
pace.mctrl.ManualPaint(pos, ang, 2 * pace.mctrl.GetGizmoSize())
else
pace.mctrl.nodraw = false
end
end)
end

local function install_submaterial_options(menu)
Expand Down
67 changes: 67 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 @@ -863,3 +863,70 @@
end
end
end)

local function mirror_vector(vec, plane) -- plane must be normal vector
return vec - 2 * vec:Dot(plane) * plane
end

local function mirror_parts(part, plane)
if part.SetPosition then
part:SetPosition(mirror_vector(part:GetPosition(), plane))
part:SetPositionOffset(mirror_vector(part:GetPositionOffset(), plane))
end

if part.SetAngles then
local ang, angO = part:GetAngles(), part:GetAngleOffset()
local fwd, up, fwdO, upO = ang:Forward(), ang:Up(), angO:Forward(), angO:Up()

part:SetAngles(mirror_vector(fwd, plane):AngleEx(mirror_vector(up, plane)))
part:SetAngleOffset(mirror_vector(fwdO, plane):AngleEx(mirror_vector(upO, plane)))
end

if part.SetScale and part.ClassName ~= "faceposer" then
part:SetScale(mirror_vector(part:GetScale(), plane))
end

if part.SetInvert then
part:SetInvert(not part:GetInvert())
end

for _, part in ipairs(part:GetChildren()) do
mirror_parts(part, plane)
end
end

local axis_planes = {
["x"] = Vector(1, 0, 0),
["y"] = Vector(0, 1, 0),
["z"] = Vector(0, 0, 1)}

function pac.MirrorParts(part, plane)
if isstring(plane) then
plane = axis_planes[plane]
if not isvector(plane) then return end
end
mirror_parts(part, plane)
end


pace.AddTool(L"mirror this and children", function(part)
Derma_StringRequest(L"plane", L"input the plane to mirror across", "y", function(plane)
if plane and part:IsValid() then
local axis_plane = axis_planes[string.lower(plane)]
if axis_plane then
mirror_parts(part, axis_plane)
end
end
end)
end)

pace.AddTool(L"clone and mirror this and children", function(part)
Derma_StringRequest(L"plane", L"input the plane to mirror across", "y", function(plane)
if plane and part:IsValid() then
local axis_plane = axis_planes[string.lower(plane)]
if axis_plane then
mirror_parts(part:Clone(), axis_plane)
end
end
end)
end)
Loading