Additional inverted / mononode modes for matrix import

master
entuland 2018-06-10 04:17:58 +02:00
parent c4852e5d0e
commit b584e60166
2 changed files with 56 additions and 14 deletions

View File

@ -114,7 +114,7 @@ Three separate privileges are available:
- `wesh_place` limits the ability to place created meshes in the world
- `wesh_delete` limits the ability to delete meshes from disk
- `wesh_import` limits the ability to import builds from `.obj.matrix.dat` files
- `wesh_vacuum` limits the ability to destroy all nodes in the canvas range
- `wesh_fill` limits the ability to fill the canvas with arbitrary nodes (including air)
All of those privileges are granted to `singleplayer` by default.
@ -150,7 +150,15 @@ When importing a matrix file it must match the size of the canvas you're current
You can combine different matrices together by importing them into the same canvas in sequence.
You can also completely erase the canvas space using the "Vacuum Canvas" button, which will set all nodes to "air"
You can select three different modes to import the matrices:
- Both `Invert` and `Mononode` unchecked: the matrix will be built normally according to the original colors
- `Invert`: the negative version of the matrix will be filled with whatever node you enter in the textarea
- `Mononode`: uses the entered nodename to import the matrix instead of the original colors
`Mononode` can be checked or unchecked in `Invert` mode, it makes no difference.
You can also completely fill the canvas space using the `Fill/Empty Canvas` button with whatever node, including air.
Finally, matrices can be accessed and rebuilt immediately, without the need for restarting the world. This means that you can use this feature to blueprint something and rebuild it with wool blocks right away as many times as you want, then go to "Manage meshes" and delete such temporary capture to avoid adding any new meshes to your library.

View File

@ -553,7 +553,7 @@ wesh.forms.import_matrix = smartfs.create("wesh.forms.import_matrix", function(s
local stored_matrices = wesh.filter_non_matrix(wesh.get_stored_files())
local temp_matrices = wesh.filter_non_matrix(wesh.get_temp_files())
local matrices_list = state:listbox(0.5, 0.5, 7, 6.5, "matrices_list")
local matrices_list = state:listbox(0.5, 0.5, 7, 5, "matrices_list")
for _, matrix_filename in pairs(stored_matrices) do
matrices_list:addItem(matrix_filename)
@ -563,6 +563,12 @@ wesh.forms.import_matrix = smartfs.create("wesh.forms.import_matrix", function(s
matrices_list:addItem(matrix_filename)
end
local negative_check = state:checkbox(0.5, 6.2, "negative_check", "Invert")
local mononode_check = state:checkbox(2.3, 6.2, "mononode_check", "Mononode")
local nodename_field = state:field(4.5, 6.5, 3.5, 1, "nodename", "'modname:nodename' or 'air'")
nodename_field:setCloseOnEnter(false)
nodename_field:setText("air")
local import_button = state:button(0.5, 7.2, 3, 1, "import", "Import selected")
import_button:onClick(function()
local full_matrix_filename = false
@ -580,21 +586,26 @@ wesh.forms.import_matrix = smartfs.create("wesh.forms.import_matrix", function(s
break
end
end
wesh.import_matrix(full_matrix_filename, state.player)
local negative = negative_check:getValue()
local mononode = mononode_check:getValue()
local nodename = nodename_field:getText()
if wesh.import_matrix(full_matrix_filename, state.player, negative, mononode, nodename) then
minetest.after(0, function()
minetest.close_formspec(state.player, "wesh.forms.import_matrix")
end)
end
end)
import_button:setClose(true)
local done_button = state:button(4, 7.2, 2, 1, "done", "Done")
done_button:setClose(true)
local close_button = state:button(5.5, 7.2, 2, 1, "close", "Close")
close_button:setClose(true)
end)
wesh.forms.fill_canvas = smartfs.create("wesh.forms.fill_canvas", function(state)
state:size(6, 4)
local nodename_field = state:field(0.5, 0.5, 5, 1, "nodename", "Fill with 'modname:nodename'")
nodename_field:setText("air")
local nodename_field = state:field(0.5, 0.5, 5, 1, "nodename", "'modname:nodename' or 'air'")
nodename_field:setCloseOnEnter(false)
nodename_field:setText("air")
local confirm_vacuum = state:button(0.5, 2, 4, 1, "confirm_vacuum", "Fill canvas")
confirm_vacuum:onClick(function()
@ -1005,8 +1016,21 @@ function wesh.get_content_id(nodename)
return wesh.content_ids[nodename]
end
function wesh.import_matrix(full_matrix_filename, playername)
if not full_matrix_filename then return end
function wesh.import_matrix(full_matrix_filename, playername, negative, mononode, nodename)
if not full_matrix_filename then
wesh.notify(playername, "Please select a matrix to import")
return false
end
local nodename_id = wesh.get_content_id(nodename)
local invalid_nodename = (nodename_id == minetest.CONTENT_IGNORE) or (nodename_id == minetest.CONTENT_UNKNOWN)
if invalid_nodename and (negative or mononode) then
wesh.notify(playername, "Unknown nodename: '" .. nodename .. "'")
return false
end
local file = io.open(full_matrix_filename, "rb")
if not file then
wesh.notify(playername, "Unable to open file " .. full_matrix_filename)
@ -1051,11 +1075,21 @@ function wesh.import_matrix(full_matrix_filename, playername)
for y = 1, #matrix[x] do
for z = 1, #matrix[x][y] do
local color = matrix[x][y][z]
if color ~= "air" then
local final_id = false
if negative then
if color == "air" then
final_id = nodename_id
end
elseif color ~= "air" then
final_id = mononode and nodename_id or wesh.get_content_id("wool:" .. color)
end
if final_id then
local rel_pos = { x = x, y = y, z = z }
local abs_pos = wesh.make_absolute(rel_pos, canvas)
local vi = a:index(abs_pos.x, abs_pos.y, abs_pos.z)
data[vi] = wesh.get_content_id("wool:" .. color)
data[vi] = final_id
end
end
end