Implement point cloud wand

This commit is contained in:
Starbeamrainbowlabs 2021-02-23 22:56:56 +00:00
parent f2aa87b396
commit 78572e453e
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
6 changed files with 111 additions and 1 deletions

View file

@ -40,3 +40,36 @@ function worldeditadditions.vector.floor(v)
-- Some vectors are 2d -- Some vectors are 2d
if v.z then v.z = math.floor(v.z) end if v.z then v.z = math.floor(v.z) end
end end
--- Determines if the target point is contained within the defined worldedit region.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to check.
-- @return boolean Whether the given target is contained within the defined worldedit region.
function worldeditadditions.vector.is_contained(pos1, pos2, target)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
return pos1.x >= target.x
and pos1.y >= target.y
and pos1.z >= target.z
and pos2.x <= target.x
and pos2.y <= target.y
and pos2.z <= target.z
end
--- Expands the defined region to include the given point.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to include.
function worldeditadditions.vector.expand_region(pos1, pos2, target)
local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
if target.x < pos1.x then pos1.x = target.x end
if target.y < pos1.y then pos1.y = target.y end
if target.z < pos1.z then pos1.z = target.z end
if target.x > pos2.x then pos2.x = target.x end
if target.y > pos2.y then pos2.y = target.y end
if target.z > pos2.z then pos2.z = target.z end
return pos1, pos2
end

View file

@ -1 +1 @@
{"modelVersion":2,"piskel":{"name":"worldedit_wand","description":"","fps":0,"height":16,"width":16,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAACWklEQVRIS82WXUhTYRjH/yd31ra2viQ5cxFRJlbUKre6CI2gm6AP2kV4FVSGXiZFfoSErCi76OOmQLqJERWkkMFuKqQsShIxvQrbyMK2yMztzNa2sz1xFkdW2fa+BwXP9ft/zu/3vO/zniP4BJCtAniVlNAeCAvQ8WSelJIQlJGekmFoAFcNqW4hWVYasdT6DJOxXQi2ylx5wb9JoNfvCFv2V8PT+ZwrrLpSt43SkRSK4mJWAEnA0Mgusc8XoEk5lm3bj0QaAw3buBiEpjI7OStWYai3D+XbV+Po4w9cBajDRtqm6RUY+VaJlJxGkfgURx5Vo/XlT2aG6YU3qyQKhcOwbHCh6WE/cwHlKqYF1O5f7DZxAWy9V0IJOYX0FCE5fh/Heg5y5f8AvV5TRcGBXqx3O1F/5y27RPtvCRXeZTeiP5TkglCz3p2mbA3e/D+QbXskikbGYSmrhPduH7OEdoxUEF6I3HuDNz8j4GmPk6QFUQhmK075hue1xH/hmvfaabFZRGb5Wpy91TNvJfKCXajdTeJEEIogoqXzvS4JaYkZ4Uiceya0uSiULwh147iLPo8GIDo24tztFwXX//0dVM+0CjHyNY7Lb9ivx9yZypdnAmqpcVOpIYYvE1F4/WNMmVyRM24TrVuhXyJfnhnm/KE1ZBEFfFQW4VrXEHNOE5krCS6Qk57N5DDKiCkZtD0Y5cqqInMhwQ3ReECikmIrxhQrrvgGufOzLcENoHayuXYHJULDKHcUo77jE3eN2ZTgfrl2pi8dttEyRUZdF/uf50yDfcL/XReD1oRfxpVUxz8/zhUAAAAASUVORK5CYII=\"}]}"]}} {"modelVersion":2,"piskel":{"name":"worldedit_wand","description":"","fps":0,"height":16,"width":16,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":4,\"chunks\":[{\"layout\":[[0],[1],[2],[3]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAAQCAYAAACm53kpAAACy0lEQVRYR92XXUhTYRzGn5M7083NMks2FxGmYp9Wal2ERhBE0Ad5EUIQfRh6mRT5ERJiX3bRx42BdBMjKkgpI28qLE3KEimlC5kbmugmms6d6dqX/ziLI1aa77sYjM71nv/7/H7vOe/ZEcwCSJ8JvPMZUGt1CAjjmnmZQoJNQnBKgqoUXDMMxbGkXaXGMt0bON27YKuSuPJKXSIi+4gbU9MBpKcmMs8QmjcJ9L6XsOVAPgoaWpmDsws36Sk46UeMRwwJgA9QlbFL2G+2klNyh8ZNe4PoKt3G3WHYIVFCggYulwfjTg82ZiYzzxDK04yUlbka3W0dyNi+Bide9DOH5dJUrydFRrgCLN+y4ZeCiBFf4dizfFS1f+fqYLFNULxWxb37cu/Zhe7kGcjucEC7PgflTzuZCwRuYlaAvPtXm+K4ALY+TCav5EdwiuAbe4STLYe48vKt/6V3FLFqEUP2MTidE+i5wi7xF9DbhXlk62rDutwslNz/zC6h9qcEGT7HqEan3ccFIWdrdsaFZvDmX7dbyGRcAa/Pjz5rf0jAYB27xD8gq/cYyDU5Bm1aNmoedDBLUB4DGYQXYu65y5t/8vwDydDHj+4VwpE4L+C5giwyLHFB0Ohw1twT9RJ+f3HxSFwQrmKfkRI0ImaWr8WFuy3/rYS/gl0u2k3iuA0BQURlQ19YEgxLNXBMerjPBOVciHR+Uai6Uzk0PGCFaNqAi/feLvr7+W5HGcIy6sH1j3yvt7kSIpVnAqoszKUUlRsj4y7UNA8xZeaKOJ8bR+krw5cQyTwzzKXDqaQVBXwNxONWYzdzThERSQiWf+8Lrc8FcqZgM5nUEtyBGVQ/HuDKyiWjUQI3RNlBAyUn6TAU0OGG+RN3PtokcAPIO1lRtIO89h5kmJJQUj/IPSOaJHCXV563a0f0lBiQUNzI/uU338F4unkirA6KxH/N/wCTFeDHmzMoJgAAAABJRU5ErkJggg==\"}]}"]}}

View file

@ -4,6 +4,8 @@ worldeditadditions.farwand = {
local modpath = minetest.get_modpath("worldeditadditions_farwand") local modpath = minetest.get_modpath("worldeditadditions_farwand")
dofile(modpath.."/lib/do_raycast.lua")
dofile(modpath.."/lib/farwand.lua") dofile(modpath.."/lib/farwand.lua")
dofile(modpath.."/lib/cloudwand.lua")
dofile(modpath.."/lib/chatcommand.lua") dofile(modpath.."/lib/chatcommand.lua")
dofile(modpath.."/lib/settings.lua") dofile(modpath.."/lib/settings.lua")

View file

@ -0,0 +1,58 @@
local function add_point(name, pos)
if pos ~= nil then
-- print("[set_pos1]", name, "("..pos.x..", "..pos.y..", "..pos.z..")")
if not worldedit.pos1[name] then worldedit.pos1[name] = vector.new(pos) end
if not worldedit.pos2[name] then worldedit.pos2[name] = vector.new(pos) end
worldedit.marker_update(name)
local volume_before = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
worldedit.pos1[name], worldedit.pos2[name] = worldeditadditions.vector.expand_region(worldedit.pos1[name], worldedit.pos2[name], pos)
local volume_after = worldedit.volume(worldedit.pos1[name], worldedit.pos2[name])
local volume_difference = volume_after - volume_before
worldedit.marker_update(name)
worldedit.player_notify(name, "Expanded region by "..volume_difference.." nodes")
else
worldedit.player_notify(name, "Error: Too far away (try raising your maxdist with //farwand maxdist <number>)")
-- print("[set_pos1]", name, "nil")
end
end
local function clear_points(name, pos)
worldedit.pos1[name] = nil
worldedit.pos2[name] = nil
worldedit.marker_update(name)
worldedit.set_pos[name] = nil
end
minetest.register_tool(":worldeditadditions:cloudwand", {
description = "WorldEditAdditions far-reaching point cloud wand",
inventory_image = "worldeditadditions_cloudwand.png",
on_place = function(itemstack, player, pointed_thing)
local name = player:get_player_name()
-- print("[farwand] on_place", name)
-- Right click when pointing at something
-- Pointed thing: https://rubenwardy.com/minetest_modding_book/lua_api.html#pointed_thing
clear_points(name)
end,
on_use = function(itemstack, player, pointed_thing)
local name = player:get_player_name()
-- print("[farwand] on_use", name)
local looking_pos, node_id = worldeditadditions.farwand.do_raycast(player)
add_point(name, looking_pos)
-- Left click when pointing at something or nothing
end,
on_secondary_use = function(itemstack, player, pointed_thing)
local name = player:get_player_name()
-- Right click when pointing at nothing
-- print("[farwand] on_secondary_use", name)
clear_points(name)
end
})

View file

@ -0,0 +1,17 @@
--- worldeditadditions.raycast() wrapper
function worldeditadditions.farwand.do_raycast(player)
if player == nil then return nil end
local player_name = player:get_player_name()
if worldeditadditions.farwand.player_data[player_name] == nil then
worldeditadditions.farwand.player_data[player_name] = { maxdist = 1000, skip_liquid = true }
end
local looking_pos, node_id = worldeditadditions.raycast(
player,
worldeditadditions.farwand.player_data[player_name].maxdist,
worldeditadditions.farwand.player_data[player_name].skip_liquid
)
return looking_pos, node_id
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B