Allow specifying filename (#1)
* Allow specifying filename * Update README
This commit is contained in:
parent
4c337a39e4
commit
b598a0c5d5
@ -8,7 +8,7 @@ This mod is still in the "alpha" phase; as such, many types of nodes are not yet
|
|||||||
|
|
||||||
## Usage
|
## 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
|
### Importing into Blender
|
||||||
|
|
||||||
|
14
export.lua
14
export.lua
@ -132,7 +132,7 @@ function meshport.create_node(idx, area, content, param2, playerName)
|
|||||||
return faces
|
return faces
|
||||||
end
|
end
|
||||||
|
|
||||||
function meshport.create_mesh(playerName, p1, p2)
|
function meshport.create_mesh(playerName, p1, p2, filename)
|
||||||
meshport.print(playerName, "info", "Generating mesh...")
|
meshport.print(playerName, "info", "Generating mesh...")
|
||||||
p1, p2 = vector.sort(p1, p2)
|
p1, p2 = vector.sort(p1, p2)
|
||||||
local vm = minetest.get_voxel_manip()
|
local vm = minetest.get_voxel_manip()
|
||||||
@ -163,13 +163,21 @@ function meshport.create_mesh(playerName, p1, p2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
filename = filename or os.date("%Y-%m-%d_%H-%M-%S")
|
||||||
|
|
||||||
-- Create path for exported mesh.
|
-- Create path for exported mesh.
|
||||||
local path = string.format("%s%smeshport%s%s_%s",
|
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)
|
minetest.mkdir(path)
|
||||||
|
|
||||||
mesh:write_obj(path)
|
mesh:write_obj(path)
|
||||||
mesh:write_mtl(path, playerName)
|
mesh:write_mtl(path, playerName)
|
||||||
|
|
||||||
meshport.print(playerName, "info", "Finished.")
|
meshport.print(playerName, "info", "Finished. Saved to " .. path)
|
||||||
end
|
end
|
||||||
|
13
init.lua
13
init.lua
@ -53,8 +53,8 @@ for i = 1, 2 do
|
|||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_chatcommand("meshport", {
|
minetest.register_chatcommand("meshport", {
|
||||||
params = "",
|
params = "[filename]",
|
||||||
description = "Save a mesh of the selected area.",
|
description = "Save a mesh of the selected area (filename optional).",
|
||||||
privs = {meshport = true},
|
privs = {meshport = true},
|
||||||
|
|
||||||
func = function(name, param)
|
func = function(name, param)
|
||||||
@ -63,6 +63,13 @@ minetest.register_chatcommand("meshport", {
|
|||||||
return
|
return
|
||||||
end
|
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,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user