From 27aa3a9c8f518d11642357872a94f8ccbcee482e Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 13 Dec 2023 23:20:32 +0000 Subject: [PATCH] =?UTF-8?q?It=20works!!=20....but=20the=20output=20seems?= =?UTF-8?q?=20off=20when=20non=2090=C2=B0=20increments=20...probably=20due?= =?UTF-8?q?=20to=20the=20wiping=20and=20rotation=20overlapping?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldeditadditions/lib/rotate.lua | 22 ++++++++++++------- .../commands/rotate.lua | 14 +++++++++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/worldeditadditions/lib/rotate.lua b/worldeditadditions/lib/rotate.lua index af0c877..f73293d 100644 --- a/worldeditadditions/lib/rotate.lua +++ b/worldeditadditions/lib/rotate.lua @@ -16,15 +16,20 @@ local function __compile_rotlist(rotlist) --- 1: Construct a Vector3 to represent which axis we want to rotate on local rotval = Vector3.new(0, 0, 0) -- Assume that if it's a table, it's a Vector3 instance - if type(rot) == "table" then rotval = rot:clone() end - - if rot.axis:find("x", 1, true) then rotval.x = 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 + if type(rot) == "table" then + print("DEBUG:__compile_rotlist rot is talble, ROT", weac.inspect(rot)) + rotval = rot.axis:clone() + else + -- Otherwise, treat it as a string + if rot.axis:find("x", 1, true) then rotval.x = 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 + --- 2: Rotate & apply amount of rotation to apply in radians return rotval * rot.rad end) @@ -53,6 +58,7 @@ function worldeditadditions.rotate(pos1, pos2, origin, rotlist) -- First, rotate the defined region to find the target region local pos1_rot, pos2_rot = pos1:clone(), pos2:clone() 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) pos2_rot = Vector3.rotate3d(origin, pos2_rot, rot) end @@ -81,7 +87,7 @@ function worldeditadditions.rotate(pos1, pos2, origin, rotlist) 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. - for i, rot in ipairs(rotlist) do + for i, rot in ipairs(rotlist_c) do cpos_dest = Vector3.rotate3d(origin, cpos_dest, rot) end diff --git a/worldeditadditions_commands/commands/rotate.lua b/worldeditadditions_commands/commands/rotate.lua index 8e40e79..4eb6136 100644 --- a/worldeditadditions_commands/commands/rotate.lua +++ b/worldeditadditions_commands/commands/rotate.lua @@ -95,9 +95,21 @@ worldeditadditions_core.register_command("rotate+", { func = function(name, origin, rotlist) 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 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( pos1, pos2,