2022-09-18 21:58:33 +00:00
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
2021-02-07 23:39:09 +00:00
2021-02-18 00:30:24 +00:00
--- Scales the defined region by the given scale factor in the given anchors.
2021-02-07 23:39:09 +00:00
-- Scale factor vectors containing both scale up and scale down operations are
-- split into 2 different scale operations automatically.
2021-02-18 02:18:34 +00:00
-- Scale up operations are always performed before scale down operations to
-- preserve detail. If performance is important, you should split the scale
-- operations up manually!
2021-02-07 23:39:09 +00:00
-- @param pos1 Vector Position 1 of the defined region,
-- @param pos2 Vector Position 2 of the defined region.
-- @param scale Vector The scale factor - as a vector - by which to scale (values between -1 and 1 are considered a scale down operation).
2021-02-18 02:18:34 +00:00
-- @param anchor Vector The anchor to scale in - as a vector. e.g. { x = -1, y = 1, z = -1 } would mean scale in the negative x, positive y, and negative z directions.
2021-02-07 23:39:09 +00:00
-- @return boolean, string|table Whether the operation was successful or not. If not, then an error messagea as a string is also passed. If it was, then a statistics object is returned instead.
2021-02-18 00:30:24 +00:00
function worldeditadditions . scale ( pos1 , pos2 , scale , anchor )
2022-09-18 21:58:33 +00:00
pos1 , pos2 = Vector3.sort ( pos1 , pos2 )
2021-02-18 02:18:34 +00:00
2021-02-07 23:39:09 +00:00
if scale.x == 0 or scale.y == 0 or scale.z == 0 then
return false , " A component of the scale factoro was 0. "
end
2022-09-18 21:58:33 +00:00
local scale_down = Vector3.new ( 1 , 1 , 1 )
local scale_up = Vector3.new ( 1 , 1 , 1 )
2021-02-07 23:39:09 +00:00
if scale.x > - 1 and scale.x < 1 then scale_down.x = scale.x end
if scale.y > - 1 and scale.y < 1 then scale_down.y = scale.y end
if scale.z > - 1 and scale.z < 1 then scale_down.z = scale.z end
if scale.x > 1 or scale.x < - 1 then scale_up.x = scale.x end
if scale.y > 1 or scale.y < - 1 then scale_up.y = scale.y end
if scale.z > 1 or scale.z < - 1 then scale_up.z = scale.z end
local stats_total = { updated = 0 , operations = 0 }
local success , stats
if scale_up.x ~= 1 or scale_up.y ~= 1 or scale_up.z ~= 1 then
2021-02-18 00:30:24 +00:00
success , stats = worldeditadditions.scale_up ( pos1 , pos2 , scale_up , anchor )
2021-02-07 23:39:09 +00:00
if not success then return success , stats end
stats_total.updated = stats.updated
stats_total.operations = stats_total.operations + 1
stats_total.scale_down = stats.scale
2021-02-18 02:18:34 +00:00
pos1 = stats.pos1
pos2 = stats.pos2
2021-02-07 23:39:09 +00:00
end
if scale_down.x ~= 1 or scale_down.y ~= 1 or scale_down.z ~= 1 then
2021-02-18 00:30:24 +00:00
success , stats = worldeditadditions.scale_down ( pos1 , pos2 , scale_down , anchor )
2021-02-07 23:39:09 +00:00
if not success then return success , stats end
stats_total.updated = stats_total.updated + stats.updated
stats_total.operations = stats_total.operations + 1
2021-02-18 02:18:34 +00:00
pos1 = stats.pos1
pos2 = stats.pos2
2021-02-07 23:39:09 +00:00
end
2022-09-18 21:58:33 +00:00
pos1 , pos2 = Vector3.sort ( pos1 , pos2 )
2021-02-18 02:33:26 +00:00
2021-02-18 02:18:34 +00:00
stats_total.pos1 = pos1
stats_total.pos2 = pos2
2021-02-07 23:39:09 +00:00
return true , stats_total
end