It works!! ....but the output seems off when non 90° increments

...probably due to the wiping and rotation overlapping
This commit is contained in:
Starbeamrainbowlabs 2023-12-13 23:20:32 +00:00
parent 7d29453699
commit 27aa3a9c8f
Signed by: sbrl
GPG key ID: C1C6C0BB001E1725
2 changed files with 27 additions and 9 deletions

View file

@ -16,15 +16,20 @@ local function __compile_rotlist(rotlist)
--- 1: Construct a Vector3 to represent which axis we want to rotate on --- 1: Construct a Vector3 to represent which axis we want to rotate on
local rotval = Vector3.new(0, 0, 0) local rotval = Vector3.new(0, 0, 0)
-- Assume that if it's a table, it's a Vector3 instance -- Assume that if it's a table, it's a Vector3 instance
if type(rot) == "table" then rotval = rot:clone() end if type(rot) == "table" then
print("DEBUG:__compile_rotlist rot is talble, ROT", weac.inspect(rot))
if rot.axis:find("x", 1, true) then rotval.x = 1 rotval = rot.axis:clone()
elseif rot.axis:find("y", 1, true) then rotval.y = 1 else
elseif rot.axis:find("z", 1, true) then rotval.z = 1 end -- Otherwise, treat it as a string
if rot.axis:sub(1, 1) == "-" then if rot.axis:find("x", 1, true) then rotval.x = 1
rotval = rotval * -1 elseif rot.axis:find("y", 1, true) then rotval.y = 1
elseif rot.axis:find("z", 1, true) then rotval.z = 1 end
if rot.axis:sub(1, 1) == "-" then
rotval = rotval * -1
end
end end
--- 2: Rotate & apply amount of rotation to apply in radians --- 2: Rotate & apply amount of rotation to apply in radians
return rotval * rot.rad return rotval * rot.rad
end) end)
@ -53,6 +58,7 @@ function worldeditadditions.rotate(pos1, pos2, origin, rotlist)
-- First, rotate the defined region to find the target region -- First, rotate the defined region to find the target region
local pos1_rot, pos2_rot = pos1:clone(), pos2:clone() local pos1_rot, pos2_rot = pos1:clone(), pos2:clone()
for i, rot in ipairs(rotlist_c) do for i, rot in ipairs(rotlist_c) do
print("DEBUG origin", weac.inspect(origin), "pos1_rot", weac.inspect(pos1_rot), "pos2_rot", weac.inspect(pos2_rot), "rot", weac.inspect(rot))
pos1_rot = Vector3.rotate3d(origin, pos1_rot, rot) pos1_rot = Vector3.rotate3d(origin, pos1_rot, rot)
pos2_rot = Vector3.rotate3d(origin, pos2_rot, rot) pos2_rot = Vector3.rotate3d(origin, pos2_rot, rot)
end end
@ -81,7 +87,7 @@ function worldeditadditions.rotate(pos1, pos2, origin, rotlist)
local cpos_dest = cpos_src:clone() local cpos_dest = cpos_src:clone()
-- TODO: This is very inefficient. If we could use quaternions here to stack up the rotations, it would be much more efficient. -- TODO: This is very inefficient. If we could use quaternions here to stack up the rotations, it would be much more efficient.
for i, rot in ipairs(rotlist) do for i, rot in ipairs(rotlist_c) do
cpos_dest = Vector3.rotate3d(origin, cpos_dest, rot) cpos_dest = Vector3.rotate3d(origin, cpos_dest, rot)
end end

View file

@ -95,9 +95,21 @@ worldeditadditions_core.register_command("rotate+", {
func = function(name, origin, rotlist) func = function(name, origin, rotlist)
local start_time = wea_c.get_ms_time() local start_time = wea_c.get_ms_time()
------------------------------------------------- -------------------------------------------------
local pos_origin = wea_c.pos.get(name, origin)
local pos1, pos2 = wea_c.pos.get1(name), wea_c.pos.get2(name) local pos1, pos2 = wea_c.pos.get1(name), wea_c.pos.get2(name)
local pos_origin = nil
if type(origin) == "number" then
pos_origin = wea_c.pos.get(name, origin)
elseif type(origin) == "string" and origin == "__AUTO__" then
pos_origin = Vector3.mean(pos1, pos2)
end
if pos_origin == nil then
-- There's a very small chance that this could be a bug here if origin is (NOT type("number") and NOT type("string") and ~= "__AUTO__"), but this shouldn't happen because we constrain the output of the above parser. This means we can safely make this assumption here
return false, "Error: Failed to get origin point from position "..tostring(origin).." because it doesn't exist."
end
local success, stats = worldeditadditions.rotate( local success, stats = worldeditadditions.rotate(
pos1, pos2, pos1, pos2,