Allow specifying filename (#1)

* Allow specifying filename

* Update README
This commit is contained in:
Alex 2019-07-22 10:18:03 -07:00 committed by random-geek
parent 4c337a39e4
commit b598a0c5d5
3 changed files with 22 additions and 7 deletions

View File

@ -8,7 +8,7 @@ This mod is still in the "alpha" phase; as such, many types of nodes are not yet
## Usage
Use `/mesh1` and `/mesh2` to set the corners of the area you want exported, then use `/meshport` to export the mesh. The saved `.obj` and `.mtl` files will be located in the `meshport` folder of the world directory, within a subfolder.
Use `/mesh1` and `/mesh2` to set the corners of the area you want exported, then use `/meshport [filename]` to export the mesh (filename is optional). The saved `.obj` and `.mtl` files will be located in the `meshport` folder of the world directory, within a subfolder.
### Importing into Blender

View File

@ -132,7 +132,7 @@ function meshport.create_node(idx, area, content, param2, playerName)
return faces
end
function meshport.create_mesh(playerName, p1, p2)
function meshport.create_mesh(playerName, p1, p2, filename)
meshport.print(playerName, "info", "Generating mesh...")
p1, p2 = vector.sort(p1, p2)
local vm = minetest.get_voxel_manip()
@ -163,13 +163,21 @@ function meshport.create_mesh(playerName, p1, p2)
end
end
filename = filename or os.date("%Y-%m-%d_%H-%M-%S")
-- Create path for exported mesh.
local path = string.format("%s%smeshport%s%s_%s",
minetest.get_worldpath(), DIR_DELIM, DIR_DELIM, playerName, os.date("%Y-%m-%d_%H-%M-%S"))
minetest.get_worldpath(), DIR_DELIM, DIR_DELIM, playerName, filename)
if file_exists(path) then
meshport.print(playerName, "error", "File already exists.")
return
end
minetest.mkdir(path)
mesh:write_obj(path)
mesh:write_mtl(path, playerName)
meshport.print(playerName, "info", "Finished.")
meshport.print(playerName, "info", "Finished. Saved to " .. path)
end

View File

@ -53,8 +53,8 @@ for i = 1, 2 do
end
minetest.register_chatcommand("meshport", {
params = "",
description = "Save a mesh of the selected area.",
params = "[filename]",
description = "Save a mesh of the selected area (filename optional).",
privs = {meshport = true},
func = function(name, param)
@ -63,6 +63,13 @@ minetest.register_chatcommand("meshport", {
return
end
meshport.create_mesh(name, meshport.p1[name], meshport.p2[name])
if param:find("[^%w-_]") then
meshport.print(name, "error", "Invalid name supplied. Please use valid characters ([A-Z][a-z][0-9][-_]).")
return
elseif param == "" then
param = nil
end
meshport.create_mesh(name, meshport.p1[name], meshport.p2[name], param)
end,
})