-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoxelmap.py
235 lines (215 loc) · 8.33 KB
/
foxelmap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/usr/bin/python
import sys, getopt
import numpy_render
import atlas_gen
import stitch
import os
import math
import merger
try:
os.makedirs('out/z0')
except:
pass
# Features:
# Different rendering output modes: terrain, elevation and landmass (configurable sea level y)
# Time of day (plus end,nether and gamma)
# Render Biomes with Bedrock Colors
# Issues:
# Block states are partially supported (no waterlogging)
# Not pixel accurate to real Voxel Map (unsure if it ever will be) [very close now]
# Biome tints are currently hard-coded (using values from minecraft wiki)
# No mod support (sorry)
# No resource pack support
# Block slopes breaks across region edges
# Different toggles for terrain/slope/water not yet avaliable
# Only supports/tested with the overworld dimension
# Add better help/documentation
# Send a single variable for atlases and modes
def main(argv):
intro = "FoxelMap 0.1 | back from hiatus \n foxelmap.py -x \"x1,x2\" -z \"z1,z2\""
calculate_atlas = False
generate_atlas = False
bounds_x = None
bounds_z = None
render_all = False
stitch_tiles = False
config = {}
config['y_shading'] = True
mode = "terrain"
world = ["world"]
time_of_day = "day"
bedrock = False
zoom = 0
version = 19
try:
opts, args = getopt.getopt(argv,"ham:w:c:t:v:",
["all","stitch","radius=","mode=","world=","light=","bedrock","help","cx=","cz=","zoom=","heightslice=","layer=","noyshading","atlas","atlasgen"]
)
except getopt.GetoptError:
print(intro)
sys.exit(2)
for opt,arg in opts:
if opt in ('-h','--help'):
print (intro)
print("")
print("\t -v <version> - the minecraft version to render (17/18/19)")
print("")
print("\t --world <path> - the path to the tiles to be rendered")
print("")
print("\t-a --all - renders all tiles")
print("\t-t \"x,z\" - region x")
print("\t--tx \"x1,x2\" - region x")
print("\t--tz \"z1,z2\" - region z")
print("\t-c \"x,z\" - tile at x,z ingame coords")
print("\t--cx \"x1,x2\" - tiles from x1 to x2 ingame coords")
print("\t--cz \"z1,z2\" - tiles from z1 to z2 ingame coords")
print("\t--radius <value> - expands the tile area selected")
print("")
print("\t--mode <terrain|height|land|light|biome|none>")
print("\t--light <day|night|nether|end|gamma>")
print("\t--bedrock - use bedrock edition biome colors")
print("\t--heightslice <slice> - thickness of layers in height mode")
print("\t--layer <layer> | choose a single voxelmap layer to render")
print("\t--noyshading - disables height shading in terrain mode")
print("")
print("\t--zoom z")
print("\t--stitch - produces a single image file with all tiles")
print("")
print("\t--atlas - uses the minecraft assets folder to calculate block colors")
print("\t--atlasgen - generates an atlas and exports it to palettes/atlas/")
print("\n")
sys.exit()
elif opt in ('-v'):
version = int(arg)
elif opt in ("--radius"):
if bounds_x == None: bounds_x = [0,0]
if bounds_z == None: bounds_z = [0,0]
bounds_x = [bounds_x[0] -int(arg),bounds_x[1] + int(arg)]
bounds_z = [bounds_z[0] -int(arg),bounds_z[1] + int(arg)]
elif opt in ("--atlas"):
calculate_atlas = True
elif opt in ("--atlasgen"):
generate_atlas = True
elif opt in ("-a","--all"):
render_all = True
elif opt in ("--stitch"):
stitch_tiles = True
elif opt in ("-m","--mode"):
if arg in ("terrain","land","biome","light","height","none"):
mode = arg
elif opt in ("-w","--world"):
world = arg.split(",")
elif opt in ("--light"):
time_of_day = arg
#---
# Area Selection
#---
elif opt in ("-c"):
split = arg.split(",")
cx = math.floor(int(split[0])/256)
cz = math.floor(int(split[1])/256)
bounds_x = [cx,cx]
bounds_z = [cz,cz]
elif opt in ("--cx"):
split = arg.split(",")
cx1 = math.floor(int(split[0])/256)
cx2 = math.floor(int(split[1])/256)
bounds_x = [cx1,cx2]
bounds_x.sort()
elif opt in ("--cz"):
split = arg.split(",")
cz1 = math.floor(int(split[0])/256)
cz2 = math.floor(int(split[1])/256)
bounds_z = [cz1,cz2]
bounds_z.sort()
elif opt in ("-t"):
split = arg.split(",")
cx = math.floor(int(split[0])/256)
cz = math.floor(int(split[1])/256)
bounds_x = [int(split[0]),int(split[0])]
bounds_z = [int(split[1]),int(split[1])]
elif opt in ("--tx"):
render_all = False
split = arg.split(",")
if len(split) == 1:
bounds_x = [int(arg),int(arg)]
if len(split) == 2:
bounds_x = [int(split[0]),int(split[1])]
bounds_x.sort()
elif opt in ("--tz"):
render_all = False
split = arg.split(",")
if len(split) == 1:
bounds_z = [int(arg),int(arg)]
if len(split) == 2:
bounds_z = [int(split[0]),int(split[1])]
bounds_z.sort()
elif opt in ("--bedrock"):
bedrock = True
elif opt in ("--zoom"):
zoom = int(arg)
elif opt in ("--heightslice"):
config['cut'] = int(arg)
elif opt in ('--layer'):
config['render_layer'] = int(arg)
elif opt in ('--noyshading'):
config['y_shading'] = False
print(world)
#if (bounds_x == None or bounds_z == None) and render_all == False:
# print("ERROR: Invalid Map Bounds")
# sys.exit(1)
if (world == ""):
print("ERROR: No World Provided")
sys.exit(1)
print(bounds_x,bounds_z)
atlas = None
light_atlas = None
biome_atlas = atlas_gen.get_biome_atlas(v=version)
if generate_atlas:
atlas_gen.calculate_atlas(v=16)
atlas_gen.calculate_atlas(v=17)
atlas_gen.calculate_atlas(v=18)
atlas_gen.calculate_atlas(v=19)
if mode == "terrain":
if calculate_atlas:
atlas = atlas_gen.get_atlas(be=bedrock,v=version)
else:
atlas = atlas_gen.load_atlas(be=bedrock,v=version)
atlas_gen.tints = biome_atlas
if mode in ("terrain","light"):
light_atlas = atlas_gen.get_light_atlas(time_of_day)
print("bounds is",bounds_x,bounds_z)
for w in world:
print("printing tiles for {}".format(w))
if len(world) == 1:
out = ""
else:
out = "{}/".format(w)
try:
#print(out)
os.makedirs("out/"+out+"/z0/")
except:
pass
if bounds_x != None and bounds_z != None:
for x in range(bounds_x[0],bounds_x[1]+1):
for y in range(bounds_z[0],bounds_z[1]+1):
if mode != "none":
numpy_render.make_tile(w,atlas,light_atlas,biome_atlas,"{},{}.zip".format(x,y),mode,out,config)
if render_all:
if mode != "none":
for voxelfile in os.listdir(w):
if voxelfile.endswith('.zip'):
numpy_render.make_tile(w,atlas,light_atlas,biome_atlas,voxelfile,mode,out,config)
#numpy_render.make_all_tiles(w,atlas,light_atlas,biome_atlas,mode,out)
if len(world) > 1:
# do merge code here
merger.merge(world)
if zoom > 0:
stitch.zoom_stitch(zoom,render_all,bounds_x,bounds_z)
pass
if stitch_tiles:
print("stitching")
stitch.stitch(zoom,render_all,bounds_x,bounds_z)
print("Done!")
if __name__ == "__main__":
main(sys.argv[1:])