rolling-6
parent
b52276a397
commit
295feccade
|
@ -3,8 +3,7 @@ function set_os_execute(os_exec)
|
|||
os_execute = os_exec
|
||||
set_os_execute = nil
|
||||
end
|
||||
local conf = config
|
||||
local defaults = conf.defaults
|
||||
local defaults = config.defaults
|
||||
|
||||
minetest.register_privilege("protection_bypass", {
|
||||
description = "Can bypass protection",
|
||||
|
@ -18,7 +17,7 @@ minetest.register_privilege("voxelizer", {
|
|||
give_to_singleplayer = true
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox", {
|
||||
cmdlib.register_chatcommand("vox", {
|
||||
description = "Voxelizer",
|
||||
privs = {voxelizer = true},
|
||||
func = function(sendername, params)
|
||||
|
@ -55,12 +54,12 @@ end
|
|||
|
||||
function register_setting_command(commandname, values, settingname)
|
||||
settingname = settingname or commandname
|
||||
local root = number_ext.round(math.sqrt(#values))
|
||||
local root = modlib.number.round(math.sqrt(#values))
|
||||
local display_vals = {}
|
||||
for index, val in ipairs(values) do
|
||||
table.insert(display_vals, index..". "..val)
|
||||
end
|
||||
cmd_ext.register_chatcommand("vox "..commandname, {
|
||||
cmdlib.register_chatcommand("vox "..commandname, {
|
||||
description = "Get and list or set player-specific setting "..settingname,
|
||||
params = "[index]",
|
||||
func = function(sendername, params)
|
||||
|
@ -89,13 +88,13 @@ end
|
|||
|
||||
function register_file_command(commandname, settingname)
|
||||
settingname = settingname or commandname
|
||||
cmd_ext.register_chatcommand("vox "..commandname, {
|
||||
cmdlib.register_chatcommand("vox "..commandname, {
|
||||
description = "Get or set player-specific file "..settingname,
|
||||
params = "[filename]",
|
||||
func = function(sendername, params)
|
||||
if params.filename then
|
||||
local path = get_media(params.filename)
|
||||
if not file_ext.exists(path) then return false, "File doesn't exist" end
|
||||
if not modlib.file.exists(path) then return false, "File doesn't exist" end
|
||||
set_setting(sendername, settingname, params.filename)
|
||||
return true, string.format('File "%s" was set to "%s"', settingname, params.filename)
|
||||
end
|
||||
|
@ -130,7 +129,7 @@ register_file_command("texture")
|
|||
register_file_command("nodemap")
|
||||
|
||||
function register_bool_setting_command(name)
|
||||
cmd_ext.register_chatcommand("vox "..name, {
|
||||
cmdlib.register_chatcommand("vox "..name, {
|
||||
description = "Check whether "..name.." is enabled",
|
||||
func = function(sendername)
|
||||
local enabled = get_setting_int(sendername, name) == 1
|
||||
|
@ -138,7 +137,7 @@ function register_bool_setting_command(name)
|
|||
end
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox "..name.." enable", {
|
||||
cmdlib.register_chatcommand("vox "..name.." enable", {
|
||||
description = "Enable "..name,
|
||||
privs = {protection_bypass = true},
|
||||
func = function(sendername)
|
||||
|
@ -147,7 +146,7 @@ function register_bool_setting_command(name)
|
|||
end
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox "..name.." disable", {
|
||||
cmdlib.register_chatcommand("vox "..name.." disable", {
|
||||
description = "Disable "..name,
|
||||
privs = {protection_bypass = true},
|
||||
func = function(sendername)
|
||||
|
@ -161,8 +160,8 @@ register_bool_setting_command("protection_bypass")
|
|||
|
||||
register_bool_setting_command("alpha_weighing")
|
||||
|
||||
local max_precision = conf.max_precision
|
||||
cmd_ext.register_chatcommand("vox precision", {
|
||||
local max_precision = config.max_precision
|
||||
cmdlib.register_chatcommand("vox precision", {
|
||||
description = "Set/get current precision",
|
||||
params = "[number]",
|
||||
func = function(sendername, params)
|
||||
|
@ -178,7 +177,7 @@ cmd_ext.register_chatcommand("vox precision", {
|
|||
end
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox min_density", {
|
||||
cmdlib.register_chatcommand("vox min_density", {
|
||||
description = "Set/get minimum density",
|
||||
params = "[number]",
|
||||
func = function(sendername, params)
|
||||
|
@ -220,11 +219,11 @@ local function place(sendername, additional)
|
|||
color_choosing = color_choosing[setting_int("color_choosing")],
|
||||
merge_mode = merge_mode[setting_int("placement")],
|
||||
}
|
||||
table_ext.add_all(params, additional)
|
||||
modlib.table.add_all(params, additional)
|
||||
return place_obj(params)
|
||||
end
|
||||
|
||||
cmd_ext.register_chatcommand("vox place", {
|
||||
cmdlib.register_chatcommand("vox place", {
|
||||
description = "Place model at position with given size. Missing coordinates will be replaced by player coordinates.",
|
||||
params = "[scale] {position}",
|
||||
func = function(sendername, params)
|
||||
|
@ -240,7 +239,7 @@ cmd_ext.register_chatcommand("vox place", {
|
|||
end
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox 1", {
|
||||
cmdlib.register_chatcommand("vox 1", {
|
||||
description = "Set first corner position of model to be placed. Missing coordinates will be replaced by player coordinates.",
|
||||
params = "{position}",
|
||||
func = function(sendername, params)
|
||||
|
@ -272,7 +271,7 @@ cmd_ext.register_chatcommand("vox 1", {
|
|||
end
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox 2", {
|
||||
cmdlib.register_chatcommand("vox 2", {
|
||||
description = "Set second corner position of model & place it. Missing coordinates will be replaced by player coordinates.",
|
||||
params = "{position}",
|
||||
func = function(sendername, params)
|
||||
|
@ -289,7 +288,7 @@ cmd_ext.register_chatcommand("vox 2", {
|
|||
end
|
||||
})
|
||||
|
||||
cmd_ext.register_chatcommand("vox reset", {
|
||||
cmdlib.register_chatcommand("vox reset", {
|
||||
description = "Reset settings",
|
||||
func = function(sendername)
|
||||
for setting, _ in pairs(defaults) do
|
||||
|
@ -299,7 +298,7 @@ cmd_ext.register_chatcommand("vox reset", {
|
|||
end
|
||||
})
|
||||
|
||||
if conf.download then
|
||||
if config.download then
|
||||
minetest.register_privilege("voxelizer:download", {
|
||||
description = "Can download files from the internet using the voxelizer mod",
|
||||
give_to_admin = true,
|
||||
|
@ -315,7 +314,7 @@ if conf.download then
|
|||
"Malformed URL"
|
||||
}
|
||||
|
||||
cmd_ext.register_chatcommand("vox download", {
|
||||
cmdlib.register_chatcommand("vox download", {
|
||||
description = "Download a file from the internet",
|
||||
params = "<url> [filename]",
|
||||
privs = {["voxelizer:download"]=true},
|
||||
|
|
2
conf.lua
2
conf.lua
|
@ -48,7 +48,7 @@ local conf_spec = {
|
|||
},
|
||||
}
|
||||
|
||||
config=conf.import("voxelizer", conf_spec)
|
||||
config=modlib.conf.import("voxelizer", conf_spec)
|
||||
local mediapath = minetest.get_modpath("voxelizer").."/media/"
|
||||
local fallback_defaults = {texture = mediapath.."character.png", model = mediapath.."character.obj", nodemap = mediapath.."colors.txt"}
|
||||
for key, alt in pairs(fallback_defaults) do
|
||||
|
|
20
init.lua
20
init.lua
|
@ -2,19 +2,19 @@ voxelizer={}
|
|||
minetest.mkdir(minetest.get_worldpath().."/media") -- Create media dir
|
||||
local os_execute = os.execute or (minetest.request_insecure_environment() or
|
||||
error("Please add voxelizer to the trusted mods in settings, or disable it. See the Readme for details.")).os.execute
|
||||
extend_mod("voxelizer", "conf") -- Load JSON configuration stored in worldpath
|
||||
extend_mod("voxelizer", "vector") -- Own vector lib, operating on lists
|
||||
extend_mod("voxelizer", "closest_color") -- Closest color finder, uses linear search / k-d tree depending on number of colors
|
||||
extend_mod("voxelizer", "texture_reader") -- Texture reader, reads textures, uses Java program
|
||||
modlib.mod.extend("voxelizer", "conf") -- Load JSON configuration stored in worldpath
|
||||
modlib.mod.extend("voxelizer", "vector") -- Own vector lib, operating on lists
|
||||
modlib.mod.extend("voxelizer", "closest_color") -- Closest color finder, uses linear search / k-d tree depending on number of colors
|
||||
modlib.mod.extend("voxelizer", "texture_reader") -- Texture reader, reads textures, uses Java program
|
||||
voxelizer.set_os_execute(os_execute) -- Passing insecure os.execute while keeping it local
|
||||
extend_mod("voxelizer", "dithering") -- Error diffusion dithering
|
||||
extend_mod("voxelizer", "obj_reader") -- OBJ reader, reads simple OBJ models
|
||||
extend_mod("voxelizer", "node_map_reader") -- Node map reader, reads minetestmapper-colors.txt like files
|
||||
extend_mod("voxelizer", "main") -- Main : Actual API for placing of models using VoxelManip
|
||||
extend_mod("voxelizer", "chatcommands") -- Chatcommands for making use of the API
|
||||
modlib.mod.extend("voxelizer", "dithering") -- Error diffusion dithering
|
||||
modlib.mod.extend("voxelizer", "obj_reader") -- OBJ reader, reads simple OBJ models
|
||||
modlib.mod.extend("voxelizer", "node_map_reader") -- Node map reader, reads minetestmapper-colors.txt like files
|
||||
modlib.mod.extend("voxelizer", "main") -- Main : Actual API for placing of models using VoxelManip
|
||||
modlib.mod.extend("voxelizer", "chatcommands") -- Chatcommands for making use of the API
|
||||
voxelizer.set_os_execute(os_execute) -- Passing insecure os.execute while keeping it local
|
||||
|
||||
-- Tests : Only uncomment if you actually want to test something !
|
||||
--[[minetest.register_on_mods_loaded(function()
|
||||
extend_mod("voxelizer", "test")
|
||||
modlib.mod.extend("voxelizer", "test")
|
||||
end)]]
|
12
main.lua
12
main.lua
|
@ -35,20 +35,20 @@ function place_obj(params)
|
|||
local path_to_obj, path_to_texture, path_to_nodemap, pos1, pos2, scale = params.model, params.texture, params.nodemap, params.pos1, params.pos2, params.scale
|
||||
local steps = params.precision or steps
|
||||
local min_amount = (params.min_amount or min_amount) * 255 * steps * steps
|
||||
local obj_content = file_ext.read(path_to_obj)
|
||||
local obj_content = modlib.file.read(path_to_obj)
|
||||
if not obj_content then
|
||||
return ("OBJ doesn't exist."):format(path_to_obj)
|
||||
end
|
||||
if not file_ext.exists(path_to_texture) then
|
||||
if not modlib.file.exists(path_to_texture) then
|
||||
return ("Texture doesn't exist."):format(path_to_texture)
|
||||
end
|
||||
local nodemap_content=file_ext.read(path_to_nodemap)
|
||||
local nodemap_content=modlib.file.read(path_to_nodemap)
|
||||
if not nodemap_content then
|
||||
return ("Nodemap doesn't exist."):format(path_to_nodemap)
|
||||
end
|
||||
local nodemap = read_node_map(nodemap_content)
|
||||
local colors = table_ext.keys(nodemap)
|
||||
table_ext.map(colors, rgb_number_to_table)
|
||||
local colors = modlib.table.keys(nodemap)
|
||||
modlib.table.map(colors, rgb_number_to_table)
|
||||
local closest_color_finder = closest_color_finder(colors)
|
||||
local texture = read_texture(path_to_texture)
|
||||
if params.dithering then
|
||||
|
@ -95,7 +95,7 @@ function place_obj(params)
|
|||
return res
|
||||
end
|
||||
end
|
||||
table_ext.map(vertexes, transform) -- Transforming the vertices to MT space
|
||||
modlib.table.map(vertexes, transform) -- Transforming the vertices to MT space
|
||||
area = get_voxel_area(transform(min), transform(max), vm)
|
||||
|
||||
data = vm:get_data()
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
-- Reads a node map in a similar format as minetestmapper.txt
|
||||
function read_node_map(minetestmapper_content)
|
||||
local lines=string_ext.split_without_limit(minetestmapper_content, "\n")
|
||||
local lines=modlib.text.split_without_limit(minetestmapper_content, "\n")
|
||||
local iterator, _, index=ipairs(lines)
|
||||
local color_to_cid={}
|
||||
|
||||
--Process lines
|
||||
index, line=iterator(lines, index)
|
||||
while line do
|
||||
parts=string_ext.split(line, " ",5)
|
||||
parts=modlib.text.split(line, " ",5)
|
||||
if #parts >= 4 then
|
||||
local c_id=tonumber(parts[1], 16)
|
||||
if not c_id then c_id=minetest.get_content_id(parts[1]) end
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
-- TODO add support for colors
|
||||
function read_obj(obj_content, triangle_consumer_factory)
|
||||
print(obj_content)
|
||||
local lines=string_ext.split_without_limit(obj_content, "\n")
|
||||
local lines=modlib.text.split_without_limit(obj_content, "\n")
|
||||
local iterator, _, index=ipairs(lines)
|
||||
|
||||
::next_object::
|
||||
|
@ -11,8 +11,8 @@ function read_obj(obj_content, triangle_consumer_factory)
|
|||
local counter=1
|
||||
index, line=iterator(lines, index)
|
||||
repeat
|
||||
if string_ext.starts_with(line, "v ") then
|
||||
local parts=string_ext.split(line:sub(3), " ", 4) -- x, y, z, unneeded
|
||||
if modlib.text.starts_with(line, "v ") then
|
||||
local parts=modlib.text.split(line:sub(3), " ", 4) -- x, y, z, unneeded
|
||||
local x, y, z = tonumber(parts[1]), tonumber(parts[2]), tonumber(parts[3])
|
||||
if x and y and z then
|
||||
vertices[counter] = {x,y,z}
|
||||
|
@ -20,14 +20,14 @@ function read_obj(obj_content, triangle_consumer_factory)
|
|||
counter = counter + 1
|
||||
end
|
||||
index, line=iterator(lines, index)
|
||||
until string_ext.starts_with(line, "vt ")
|
||||
until modlib.text.starts_with(line, "vt ")
|
||||
|
||||
--UVs
|
||||
local uvs={}
|
||||
counter=1
|
||||
repeat
|
||||
if string_ext.starts_with(line, "vt ") then
|
||||
local parts=string_ext.split(line:sub(4), " ", 3)
|
||||
if modlib.text.starts_with(line, "vt ") then
|
||||
local parts=modlib.text.split(line:sub(4), " ", 3)
|
||||
local x, y = tonumber(parts[1]), tonumber(parts[2])
|
||||
if x and y then
|
||||
uvs[counter] = {x, y}
|
||||
|
@ -35,17 +35,17 @@ function read_obj(obj_content, triangle_consumer_factory)
|
|||
counter = counter + 1
|
||||
end
|
||||
index, line=iterator(lines, index)
|
||||
until string_ext.starts_with(line, "f ")
|
||||
until modlib.text.starts_with(line, "f ")
|
||||
|
||||
local triangle_consumer=triangle_consumer_factory(vertices)
|
||||
--Faces (need to be triangles), polygons are ignored
|
||||
repeat
|
||||
if string_ext.starts_with(line, "f ") then --Face
|
||||
local parts=string_ext.split(line:sub(3), " ", 4)
|
||||
if modlib.text.starts_with(line, "f ") then --Face
|
||||
local parts=modlib.text.split(line:sub(3), " ", 4)
|
||||
local verts={}
|
||||
local texs={}
|
||||
for i=1, 3 do
|
||||
local indices = string_ext.split(parts[i], "/", 3)
|
||||
local indices = modlib.text.split(parts[i], "/", 3)
|
||||
local vert, uv = tonumber(indices[1]), tonumber(indices[2])
|
||||
verts[i] = vertices[vert]
|
||||
texs[i] = uvs[uv]
|
||||
|
@ -53,7 +53,7 @@ function read_obj(obj_content, triangle_consumer_factory)
|
|||
end
|
||||
triangle_consumer(verts, texs)
|
||||
::invalid::
|
||||
elseif string_ext.starts_with(line, "o ") then
|
||||
elseif modlib.text.starts_with(line, "o ") then
|
||||
goto next_object
|
||||
end
|
||||
index, line=iterator(lines, index)
|
||||
|
|
2
test.lua
2
test.lua
|
@ -59,7 +59,7 @@ test_texture_reader()
|
|||
|
||||
local function test_nodemap_reader()
|
||||
print("Nodemap Reader Test : ")
|
||||
local color_to_cid = read_node_map(file_ext.read("/usr/share/games/minetest/minetestmapper-colors.txt"))
|
||||
local color_to_cid = read_node_map(modlib.file.read("/usr/share/games/minetest/minetestmapper-colors.txt"))
|
||||
for c, cid in pairs(color_to_cid) do
|
||||
print(string.format("%x", c).." -> "..minetest.get_name_from_content_id(cid))
|
||||
end
|
||||
|
|
|
@ -55,9 +55,9 @@ end
|
|||
|
||||
function bilinear_filtering(texture, pos_uv)
|
||||
local x = pos_uv[1]*texture.width
|
||||
local x_line = number_ext.round(x)
|
||||
local x_line = modlib.number.round(x)
|
||||
local y = (1-pos_uv[2])*texture.height
|
||||
local y_line = number_ext.round(y)
|
||||
local y_line = modlib.number.round(y)
|
||||
|
||||
local affected, affected_alpha = 0, 0
|
||||
local avg_alpha = 0
|
||||
|
|
|
@ -82,7 +82,7 @@ end
|
|||
vector.to_string = function(v)
|
||||
local c = {}
|
||||
for i=1, #v do
|
||||
c[i] = number_ext.round(v[i], 100)
|
||||
c[i] = modlib.number.round(v[i], 100)
|
||||
end
|
||||
return table.concat(c, ", ")
|
||||
end
|
Loading…
Reference in New Issue