mirror of
https://github.com/Uberi/Minetest-WorldEdit.git
synced 2024-12-04 21:33:43 +01:00
Dual-based cylinder
This commit is contained in:
parent
6ceb56c3dc
commit
bf8e2a8233
@ -175,23 +175,35 @@ Add dome centered at WorldEdit position 1 with radius `<radius>`, composed of `<
|
||||
//dome -12 glass
|
||||
//dome 17 mesecons:wire_00000000_off
|
||||
|
||||
### `//hollowcylinder x/y/z/? <length> <radius> <node>`
|
||||
### `//hollowcylinder x/y/z/? <length> <radius1> [radius2] <node>`
|
||||
|
||||
Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length `<length>` and radius `<radius>`, composed of `<node>`.
|
||||
Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length `<length>`, base radius `<radius1>` (and top radius `[radius2]`), composed of `<node>`.
|
||||
|
||||
Despite its name this command allows you to create cones (`radius2` = 0) as well as any shapes inbetween (0 < `radius2` < `radius1`).
|
||||
Swapping `radius1` and `radius2` will create the same object but upside-down.
|
||||
|
||||
//hollowcylinder x +5 8 Bronze Block
|
||||
//hollowcylinder y 28 10 glass
|
||||
//hollowcylinder z -12 3 mesecons:wire_00000000_off
|
||||
//hollowcylinder ? 2 4 default:stone
|
||||
|
||||
### `//cylinder x/y/z/? <length> <radius> <node>`
|
||||
//hollowcylinder y 10 10 0 walls:cobble
|
||||
//hollowcylinder x 6 0 5 Dirt
|
||||
//hollowcylinder z 20 10 20 default:desert_stone
|
||||
|
||||
Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length `<length>` and radius `<radius>`, composed of `<node>`.
|
||||
### `//cylinder x/y/z/? <length> <radius1> [radius2] <node>`
|
||||
|
||||
Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length `<length>`, base radius `<radius1>` (and top radius `[radius2]`), composed of `<node>`.
|
||||
Can also create shapes other than cylinders, e.g. cones (see documentation above).
|
||||
|
||||
//cylinder x +5 8 Bronze Block
|
||||
//cylinder y 28 10 glass
|
||||
//cylinder z -12 3 mesecons:wire_00000000_off
|
||||
//cylinder ? 2 4 default:stone
|
||||
|
||||
//cylinder y 10 10 0 walls:cobble
|
||||
//cylinder x 6 0 5 Dirt
|
||||
//cylinder z 20 10 20 default:desert_stone
|
||||
|
||||
### `//hollowpyramid x/y/z? <height> <node>`
|
||||
|
||||
@ -432,4 +444,4 @@ or vertically in the y axis `[v]`.
|
||||
Contracts the selection in all directions by `<amount>`. If specified, the selection can be contracted horizontally in the x and z axes `[h]`
|
||||
or vertically in the y axis `[v]`.
|
||||
|
||||
//outset v 5
|
||||
//outset v 5
|
||||
|
@ -127,9 +127,9 @@ Adds a dome centered at `pos` with radius `radius`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
### count = worldedit.cylinder(pos, axis, length, radius, node_name, hollow)
|
||||
### count = worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, hollow)
|
||||
|
||||
Adds a cylinder at `pos` along the `axis` axis ("x" or "y" or "z") with length `length` and radius `radius`, composed of `node_name`.
|
||||
Adds a cylinder-like at `pos` along the `axis` axis ("x" or "y" or "z") with length `length`, base radius `radius1` and top radius `radius2`, composed of `node_name`.
|
||||
|
||||
Returns the number of nodes added.
|
||||
|
||||
|
@ -92,49 +92,60 @@ end
|
||||
-- @param pos Position to center base of cylinder at.
|
||||
-- @param axis Axis ("x", "y", or "z")
|
||||
-- @param length Cylinder length.
|
||||
-- @param radius Cylinder radius.
|
||||
-- @param radius1 Cylinder base radius.
|
||||
-- @param radius2 Cylinder top radius.
|
||||
-- @param node_name Name of node to make cylinder of.
|
||||
-- @param hollow Whether the cylinder should be hollow.
|
||||
-- @return The number of nodes added.
|
||||
function worldedit.cylinder(pos, axis, length, radius, node_name, hollow)
|
||||
function worldedit.cylinder(pos, axis, length, radius1, radius2, node_name, hollow)
|
||||
local other1, other2 = worldedit.get_axis_others(axis)
|
||||
|
||||
-- Backwards compatibility
|
||||
if type(radius2) == "string" then
|
||||
hollow = node_name
|
||||
node_name = radius2
|
||||
radius2 = radius1 -- straight cylinder
|
||||
end
|
||||
|
||||
-- Handle negative lengths
|
||||
local current_pos = {x=pos.x, y=pos.y, z=pos.z}
|
||||
if length < 0 then
|
||||
length = -length
|
||||
current_pos[axis] = current_pos[axis] - length
|
||||
radius1, radius2 = radius2, radius1
|
||||
end
|
||||
|
||||
-- Set up voxel manipulator
|
||||
local manip, area = mh.init_axis_radius_length(current_pos, axis, radius, length)
|
||||
local manip, area = mh.init_axis_radius_length(current_pos, axis, math.max(radius1, radius2), length)
|
||||
local data = mh.get_empty_data(area)
|
||||
|
||||
-- Add cylinder
|
||||
-- Add desired shape (anything inbetween cylinder & cone)
|
||||
local node_id = minetest.get_content_id(node_name)
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
local stride = {x=1, y=area.ystride, z=area.zstride}
|
||||
local offset = {
|
||||
x = current_pos.x - area.MinEdge.x,
|
||||
y = current_pos.y - area.MinEdge.y,
|
||||
z = current_pos.z - area.MinEdge.z,
|
||||
}
|
||||
local min_slice, max_slice = offset[axis], offset[axis] + length - 1
|
||||
local count = 0
|
||||
for index2 = -radius, radius do
|
||||
-- Offset contributed by other axis 1 plus 1 to make it 1-indexed
|
||||
local new_index2 = (index2 + offset[other1]) * stride[other1] + 1
|
||||
for index3 = -radius, radius do
|
||||
local new_index3 = new_index2 + (index3 + offset[other2]) * stride[other2]
|
||||
local squared = index2 * index2 + index3 * index3
|
||||
if squared <= max_radius and (not hollow or squared >= min_radius) then
|
||||
-- Position is in cylinder
|
||||
-- Add column along axis
|
||||
for index1 = min_slice, max_slice do
|
||||
local vi = new_index3 + index1 * stride[axis]
|
||||
for i = 0, length - 1 do
|
||||
-- Calulate radius for this "height" in the cylinder
|
||||
local radius = radius1 + (radius2 - radius1) * (i - 1) / (length - 1)
|
||||
radius = math.floor(radius + 0.5) -- round
|
||||
local min_radius, max_radius = radius * (radius - 1), radius * (radius + 1)
|
||||
|
||||
for index2 = -radius, radius do
|
||||
-- Offset contributed by other axis 1 plus 1 to make it 1-indexed
|
||||
local new_index2 = (index2 + offset[other1]) * stride[other1] + 1
|
||||
for index3 = -radius, radius do
|
||||
local new_index3 = new_index2 + (index3 + offset[other2]) * stride[other2]
|
||||
local squared = index2 * index2 + index3 * index3
|
||||
if squared <= max_radius and (not hollow or squared >= min_radius) then
|
||||
-- Position is in cylinder, add node here
|
||||
local vi = new_index3 + (offset[axis] + i) * stride[axis]
|
||||
data[vi] = node_id
|
||||
count = count + 1
|
||||
end
|
||||
count = count + length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -538,46 +538,65 @@ local check_cylinder = function(name, param)
|
||||
worldedit.player_notify(name, "no position 1 selected")
|
||||
return nil
|
||||
end
|
||||
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
||||
-- two radii
|
||||
local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
||||
if found == nil then
|
||||
-- single radius
|
||||
found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
||||
radius2 = radius1
|
||||
end
|
||||
if found == nil then
|
||||
worldedit.player_notify(name, "invalid usage: " .. param)
|
||||
return nil
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
if not node then return nil end
|
||||
return math.ceil(math.pi * (tonumber(radius) ^ 2) * tonumber(length))
|
||||
local radius = math.max(tonumber(radius1), tonumber(radius2))
|
||||
return math.ceil(math.pi * (radius ^ 2) * tonumber(length))
|
||||
end
|
||||
|
||||
minetest.register_chatcommand("/hollowcylinder", {
|
||||
params = "x/y/z/? <length> <radius> <node>",
|
||||
description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
|
||||
params = "x/y/z/? <length> <radius1> [radius2] <node>",
|
||||
description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>, base radius <radius1> (and top radius [radius2]), composed of <node>",
|
||||
privs = {worldedit=true},
|
||||
func = safe_region(function(name, param)
|
||||
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
||||
-- two radii
|
||||
local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
||||
if found == nil then
|
||||
-- single radius
|
||||
found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
||||
radius2 = radius1
|
||||
end
|
||||
length = tonumber(length)
|
||||
if axis == "?" then
|
||||
axis, sign = worldedit.player_axis(name)
|
||||
length = length * sign
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node, true)
|
||||
local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node, true)
|
||||
worldedit.player_notify(name, count .. " nodes added")
|
||||
end, check_cylinder),
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("/cylinder", {
|
||||
params = "x/y/z/? <length> <radius> <node>",
|
||||
description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node>",
|
||||
params = "x/y/z/? <length> <radius1> [radius2] <node>",
|
||||
description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length>, base radius <radius1> (and top radius [radius2]), composed of <node>",
|
||||
privs = {worldedit=true},
|
||||
func = safe_region(function(name, param)
|
||||
local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
||||
-- two radii
|
||||
local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$")
|
||||
if found == nil then
|
||||
-- single radius
|
||||
found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$")
|
||||
radius2 = radius1
|
||||
end
|
||||
length = tonumber(length)
|
||||
if axis == "?" then
|
||||
axis, sign = worldedit.player_axis(name)
|
||||
length = length * sign
|
||||
end
|
||||
local node = get_node(name, nodename)
|
||||
local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node)
|
||||
local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node)
|
||||
worldedit.player_notify(name, count .. " nodes added")
|
||||
end, check_cylinder),
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user