Browse Source

Use minetestmapper binary when possible

master
poikilos 8 years ago
committed by Jacob Gustafson
parent
commit
71152430af
  1. 2
      minetestmapper-expertmm.py
  2. 43
      singleimage.py

2
minetestmapper-expertmm.py

@ -403,6 +403,8 @@ if os.path.exists(path + "sectors"):
if len(xlist) == 0 or len(zlist) == 0: if len(xlist) == 0 or len(zlist) == 0:
print("Data does not exist at this location.") print("Data does not exist at this location.")
print("xlist: "+str(xlist))
print("zlist: "+str(zlist))
sys.exit(1) sys.exit(1)
# Get rid of doubles # Get rid of doubles

43
singleimage.py

@ -9,22 +9,26 @@ from PIL import Image
class ChunkymapOfflineRenderer: class ChunkymapOfflineRenderer:
minetestmapper_numpy_path = None #minetestmapper_numpy_path = None
minetestmapper_custom_path = None #minetestmapper_custom_path = None
minetestmapper_py_path = None #minetestmapper_py_path = None
backend_string = None #minetestmapper_bin_path = None
world_path = None #backend_string = None
world_name = None #world_path = None
boundary_x_min = None #world_name = None
boundary_x_max = None #boundary_x_min = None
boundary_z_min = None #boundary_x_max = None
boundary_z_max = None #boundary_z_min = None
#boundary_z_max = None
#mtm_bin_enable = None
#mtm_bin_dir_path = None
def __init__(self): def __init__(self):
self.boundary_x_min = -4096 #formerly -10000 self.boundary_x_min = -4096 #formerly -10000
self.boundary_x_max = 4096 #formerly 10000 self.boundary_x_max = 4096 #formerly 10000
self.boundary_z_min = -4096 #formerly -10000 self.boundary_z_min = -4096 #formerly -10000
self.boundary_z_max = 4096 #formerly 10000 self.boundary_z_max = 4096 #formerly 10000
self.mtm_bin_enable = False # set below automatically if present
#NOTE: 6144*2 = 12288 #NOTE: 6144*2 = 12288
#NOTE: a 16464x16384 or 12288x12288 image fails to load in browser, but 6112x6592 works #NOTE: a 16464x16384 or 12288x12288 image fails to load in browser, but 6112x6592 works
@ -34,7 +38,10 @@ class ChunkymapOfflineRenderer:
self.minetestmapper_numpy_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "minetestmapper-numpy.py") self.minetestmapper_numpy_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "minetestmapper-numpy.py")
self.minetestmapper_custom_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "minetestmapper-expertmm.py") self.minetestmapper_custom_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "minetestmapper-expertmm.py")
self.minetestmapper_py_path = self.minetestmapper_numpy_path self.minetestmapper_py_path = self.minetestmapper_numpy_path
self.mtm_bin_dir_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)),".."),"minetestmapper")
self.minetestmapper_bin_path = os.path.join(self.mtm_bin_dir_path,"minetestmapper")
if os.path.isfile(self.minetestmapper_bin_path):
self.mtm_bin_enable = True
#region useful if version of minetestmapper.py from expertmm fork of minetest is used #region useful if version of minetestmapper.py from expertmm fork of minetest is used
#profile_path = None #profile_path = None
#if 'USERPROFILE' in os.environ: #if 'USERPROFILE' in os.environ:
@ -68,7 +75,7 @@ class ChunkymapOfflineRenderer:
#endregion the following is also in singleimage.py #endregion the following is also in singleimage.py
def RenderSingleImage(self): def RenderSingleImage(self):
dest_colors_path = os.path.join(self.mtm_bin_dir_path,"colors.txt")
genresults_folder_path = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), "chunkymap-genresults"), self.world_name) genresults_folder_path = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), "chunkymap-genresults"), self.world_name)
if not os.path.isdir(genresults_folder_path): if not os.path.isdir(genresults_folder_path):
os.makedirs(genresults_folder_path) os.makedirs(genresults_folder_path)
@ -102,20 +109,30 @@ class ChunkymapOfflineRenderer:
if os_name!="windows": if os_name!="windows":
squote = "'" squote = "'"
io_string = " --input \""+self.world_path+"\" --output \""+tmp_png_path+"\"" io_string = " --input \""+self.world_path+"\" --output \""+tmp_png_path+"\""
if "numpy" in self.minetestmapper_py_path: if (not self.mtm_bin_enable) and ("numpy" in self.minetestmapper_py_path):
limit_param = region_param limit_param = region_param
io_string = " \""+self.world_path+"\" \""+tmp_png_path+"\"" io_string = " \""+self.world_path+"\" \""+tmp_png_path+"\""
#geometry_param = " --region " + str(min_x) + " " + str(max_x) + " " + str(min_z) + " " + str(max_z) #geometry_param = " --region " + str(min_x) + " " + str(max_x) + " " + str(min_z) + " " + str(max_z)
#print("Using numpy style parameters.") #print("Using numpy style parameters.")
#print(" since using "+self.minetestmapper_py_path) #print(" since using "+self.minetestmapper_py_path)
#print() #print()
if self.mtm_bin_enable:
cmd_no_out_string = self.minetestmapper_bin_path+" --colors "+dest_colors_path+" --bgcolor "+squote+FLAG_EMPTY_HEXCOLOR+squote+io_string+limit_param
else:
cmd_no_out_string = python_exe_path+" "+self.minetestmapper_py_path+" --bgcolor "+squote+FLAG_EMPTY_HEXCOLOR+squote+io_string+limit_param cmd_no_out_string = python_exe_path+" "+self.minetestmapper_py_path+" --bgcolor "+squote+FLAG_EMPTY_HEXCOLOR+squote+io_string+limit_param
cmd_string = cmd_no_out_string + cmd_suffix cmd_string = cmd_no_out_string + cmd_suffix
print("") print("")
print("") print("")
print("Running") print("Running")
print(" "+cmd_string) print(" "+cmd_string)
if self.mtm_bin_enable:
if os.path.isfile(self.colors_path) and not os.path.isfile(dest_colors_path):
print("Copying...'"+self.colors_path+"' to '"+dest_colors_path+"'")
shutil.copyfile(self.colors_path,dest_colors_path)
print(" mapper_path: " + self.minetestmapper_bin_path)
else:
print(" mapper_path: " + self.minetestmapper_py_path) print(" mapper_path: " + self.minetestmapper_py_path)
print(" colors_path: "+self.colors_path)
print(" backend: " + self.backend_string) print(" backend: " + self.backend_string)
print(" # (this may take a while...)") print(" # (this may take a while...)")
if os.path.isfile(tmp_png_path): if os.path.isfile(tmp_png_path):

Loading…
Cancel
Save