Skip to content

Commit

Permalink
Allow specifying filename (#1)
Browse files Browse the repository at this point in the history
* Allow specifying filename

* Update README
  • Loading branch information
GreenXenith authored and random-geek committed Jul 22, 2019
1 parent 4c337a3 commit b598a0c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions export.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
13 changes: 10 additions & 3 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
})

0 comments on commit b598a0c

Please sign in to comment.