mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-26 09:03:01 +00:00
Bugfix/torus: fix hollow implementation; improve clarity
This commit is contained in:
parent
45d5f74d0a
commit
639c2061ef
2 changed files with 24 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
--- Overlap command. Places a specified node on top of
|
--- Generates torus shapes.
|
||||||
-- @module worldeditadditions.overlay
|
-- @module worldeditadditions.torus
|
||||||
|
|
||||||
--- Generates a torus shape at the given position with the given parameters.
|
--- Generates a torus shape at the given position with the given parameters.
|
||||||
-- @param position Vector The position at which to generate the torus.
|
-- @param position Vector The position at which to generate the torus.
|
||||||
|
@ -57,8 +57,8 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
|
||||||
-- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2)
|
-- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2)
|
||||||
-- Where:
|
-- Where:
|
||||||
-- (x, y, z) is the point
|
-- (x, y, z) is the point
|
||||||
-- a is the major radius (centre to centre of circle)
|
-- a is the major radius (centre of the ring to the centre of the torus)
|
||||||
-- b is the minor radius (radius of circle)
|
-- b is the minor radius (radius of the ring)
|
||||||
local comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+minor_radius_sq))
|
local comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+minor_radius_sq))
|
||||||
local test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-sq.z)
|
local test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-sq.z)
|
||||||
|
|
||||||
|
|
|
@ -39,8 +39,10 @@ local function parse_params_torus(params_text)
|
||||||
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
|
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
|
||||||
end
|
end
|
||||||
|
|
||||||
local hollow = parts[5]
|
local hollow = false
|
||||||
if hollow == "false" then hollow = false end
|
if parts[5] == "hollow" or parts[5] == "h" then
|
||||||
|
hollow = true
|
||||||
|
end
|
||||||
|
|
||||||
-- Sort the axis names (this is important to ensure we can identify the direction properly)
|
-- Sort the axis names (this is important to ensure we can identify the direction properly)
|
||||||
if axes == "yx" then axes = "xy" end
|
if axes == "yx" then axes = "xy" end
|
||||||
|
@ -51,7 +53,7 @@ local function parse_params_torus(params_text)
|
||||||
end
|
end
|
||||||
|
|
||||||
worldedit.register_command("torus", {
|
worldedit.register_command("torus", {
|
||||||
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>] [h[ollow]]",
|
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).",
|
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 },
|
privs = { worldedit = true },
|
||||||
require_pos = 1,
|
require_pos = 1,
|
||||||
|
@ -64,7 +66,13 @@ worldedit.register_command("torus", {
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, major_radius, minor_radius, axes, hollow)
|
func = function(name, target_node, major_radius, minor_radius, axes, hollow)
|
||||||
local start_time = worldeditadditions.get_ms_time()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, hollow)
|
local replaced = worldeditadditions.torus(
|
||||||
|
worldedit.pos1[name],
|
||||||
|
major_radius, minor_radius,
|
||||||
|
target_node,
|
||||||
|
axes,
|
||||||
|
hollow
|
||||||
|
)
|
||||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
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")
|
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
|
@ -85,9 +93,15 @@ worldedit.register_command("hollowtorus", {
|
||||||
nodes_needed = function(name, target_node, major_radius, minor_radius, axes)
|
nodes_needed = function(name, target_node, major_radius, minor_radius, axes)
|
||||||
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
|
||||||
end,
|
end,
|
||||||
func = function(name, target_node, major_radius, minor_radius)
|
func = function(name, target_node, major_radius, minor_radius, axes)
|
||||||
local start_time = worldeditadditions.get_ms_time()
|
local start_time = worldeditadditions.get_ms_time()
|
||||||
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, true)
|
local replaced = worldeditadditions.torus(
|
||||||
|
worldedit.pos1[name],
|
||||||
|
major_radius, minor_radius,
|
||||||
|
target_node,
|
||||||
|
axes,
|
||||||
|
true -- hollow
|
||||||
|
)
|
||||||
local time_taken = worldeditadditions.get_ms_time() - start_time
|
local time_taken = worldeditadditions.get_ms_time() - start_time
|
||||||
|
|
||||||
minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
|
||||||
|
|
Loading…
Reference in a new issue