reference: add hollow example to torus

This commit is contained in:
VorTechnix 2021-05-17 17:16:04 -07:00 committed by Starbeamrainbowlabs
parent 2b02f9ff2e
commit 0a44992676
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
2 changed files with 9 additions and 7 deletions

@ -11,7 +11,7 @@
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
local matrix = {x='yz', y='xz', z='xy'}
if type(axes) ~= "string" then axes = "xz" end
if #axes == 1 and axes.match('[xyz]') then axes = matrix[axes] end
if #axes == 1 and axes:match('[xyz]') then axes = matrix[axes] end
-- position = { x, y, z }
local total_radius = major_radius + minor_radius

@ -35,21 +35,23 @@ local function parse_params_torus(params_text)
if axes:find("[^xyz]") then
return false, "Error: The axes may only contain the letters x, y, and z."
end
if #axes ~= 2 then
return false, "Error: Exactly 2 axes must be specified. For example, 'xy' is valid, but 'xyy' is not (both of course without quotes)."
if #axes > 2 then
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
end
local hollow = parts[5]
if hollow == "false" then hollow = false end
-- Sort the axis names (this is important to ensure we can identify the direction properly)
if axes == "yx" then axes = "xy" end
if axes == "zx" then axes = "xz" end
if axes == "zy" then axes = "yz" end
return true, replace_node, major_radius, minor_radius, axes
return true, replace_node, major_radius, minor_radius, axes, hollow
end
worldedit.register_command("torus", {
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>]",
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>] [h[ollow]]",
description = "Creates a 3D torus with a major radius of <major_radius> and a minor radius of <minor_radius> at pos1, filled with <replace_node>, on axes <axes> (i.e. 2 axis names: xz, zy, etc).",
privs = { worldedit = true },
require_pos = 1,
@ -60,9 +62,9 @@ worldedit.register_command("torus", {
nodes_needed = function(name, target_node, major_radius, minor_radius)
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
end,
func = function(name, target_node, major_radius, minor_radius, axes)
func = function(name, target_node, major_radius, minor_radius, axes, hollow)
local start_time = worldeditadditions.get_ms_time()
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, false)
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, hollow)
local time_taken = worldeditadditions.get_ms_time() - start_time
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")