# Z-Order 5
("aeroway", "taxiway", 42),
("aeroway", "runway", 80),
+ ("building", "detached", "building", "common"),
("building", "church", "building", "common"),
("building", "hotel", "building", "industrial"),
("building", "farm", "building", "industrial"),
("building", "industrial", "building", "industrial"),
("building", "house", "building", "house"),
("building", "terrace", "building", "industrial"),
+ ("building", "hangar", "building", "industrial"),
+ ("building", "school", "building", "common"),
("building", "yes", "building", "common")
]
# Z-Order 5
("aeroway", "taxiway", 12),
("aeroway", "runway", 12),
+ ("building", "detached", 1),
("building", "church", 1),
("building", "hotel", 1),
("building", "farm", 1),
("building", "industrial", 1),
("building", "house", 1),
("building", "terrace", 1),
+ ("building", "hangar", 1),
+ ("building", "school", 1),
("building", "yes", 1)
]
# There are some things we need to use sources for, and some things, we do not.
# We need to differentiate that.
- if (self._isline == False) or (self._is_completion == True):
+ if (self._isline == False and self._tag != "building") or (self._is_completion == True):
# Determine where we get the our source material from
root_folder = mstr_datafolder + "Textures\\"
for s in mstr_ortho_layers:
ptc = randrange(1, 14)
img = Image.open(mstr_datafolder + "Textures\\tile\\completion\\p" + str(ptc)+".png")
lx = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width )
- ly = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.width )
+ ly = randrange( int(layer.width/20), layer.width - (int(layer.width/20)) - img.height )
layer.alpha_composite( img, (lx, ly) )
- # Let's do something nice with buildings
- if self._tag == "building":
- osm_edge = osm_edge.filter(ImageFilter.GaussianBlur(radius=3))
- layer.alpha_composite(osm_edge)
-
-
# We now need to add the seamless border
layer.alpha_composite( brd_src )
mstr_msg("layergen", "Layer image completed")
# If we encounter one of these road-specific tags, we need to proceed differently.
- if self._isline == True:
+ if self._isline == True or self._tag == "building":
# We will need the mask in question
osm_mask = Image.open( mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + ".png" )
mask_pix = osm_mask.load()
edge_pix = osm_edge.load()
layer_comp_pix = layer_comp.load()
+
+ # Let's define some base color ranges for different types of buildings
+ bld_clr = [
+ ("detached", 190, 192, 195),
+ ("church", 134, 134, 136),
+ ("hotel", 153, 147, 138),
+ ("farm", 145, 124, 121),
+ ("semidetached_house", 167, 163, 152),
+ ("apartments", 129, 134, 127),
+ ("civic", 134, 134, 136),
+ ("garage", 101, 109, 111),
+ ("office", 139, 152, 156),
+ ("retail", 121, 122, 108),
+ ("industrial", 191, 192, 187),
+ ("house", 145, 124, 121),
+ ("terrace", 191, 192, 187),
+ ("hangar", 137, 162, 195),
+ ("school", 111, 117, 115),
+ ("yes", 152, 144, 141)
+ ]
+
+ # Find the color index to work with
+ cidx = 0
+ if self._tag == "building":
+ for c in bld_clr:
+ if c[0] == self._value:
+ break
+ cidx = cidx+1
+
for y in range(self._imgsize):
for x in range(self._imgsize):
if mask_pix[x, y][3] > 0:
t = a[3]-d
if t < 0: t = 0
layer_comp_pix[x, y] = ( mats[pick-1][0], mats[pick-1][1], mats[pick-1][2], t )
+
+ # A bit special here
if self._tag == "building":
- r = randrange(1, 20)
- if self._value == "yes":
- d = (116-r, 117-r,135-r)
- layer_comp_pix[x, y] = ( d[0], d[1], d[2], a[3] )
- if e[3] > 0:
- b = (96-r, 97-r, 115-r)
- layer_comp_pix[x, y] = ( b[0],b[1],b[2],e[3] )
-
- if self._value == "office" or self._value == "retail":
- d = (100-r, 100-r, 100-r)
- layer_comp_pix[x, y] = ( d[0], d[1], d[2], a[3] )
- if e[3] > 0:
- b = (80-r, 80-r, 80-r)
- layer_comp_pix[x, y] = ( b[0],b[1],b[2],e[3] )
-
- if self._value == "industrial":
- d = (166-r, 170-r, 175-r)
- layer_comp_pix[x, y] = ( d[0], d[1], d[2], a[3] )
- if e[3] > 0:
- b = (146-r, 150-r, 155-r)
- layer_comp_pix[x, y] = ( b[0],b[1],b[2],e[3] )
+ # Find a color range
+ d = randrange(1,21)
+ # Adjust this pixel
+ c = (bld_clr[cidx][1]-d, bld_clr[cidx][2]-d, bld_clr[cidx][3]-d, 255)
+ # Set pixel
+ layer_comp_pix[x, y] = c
if self._value == "track" or self._value == "path":
d = randrange(1,20)
b = 138 - d
layer_comp_pix[x, y] = ( r,g,b,a[3] )
+ # We will do some super magic here to let houses look more realistic
+ if self._tag == "building":
+ vls = [ "detached", "hotel", "farm", "semidetached_house", "apartments", "civic", "office", "retail", "industrial", "house", "school" ]
+ if self._value in vls:
+ # Generate a new image
+ details = Image.new("RGBA", (self._imgsize, self._imgsize))
+ details_pix = details.load()
+ layer_pix = layer_comp.load()
+ for y in range(self._imgsize-1):
+ for x in range(self._imgsize-1):
+ p = layer_pix[x,y]
+ if p[3] > 0:
+ shf_x = x+randrange(1, 21)
+ shf_y = y+randrange(1, 21)
+ shf_x2 = x-randrange(1, 21)
+ shf_y2 = y-randrange(1, 21)
+ if shf_x <= self._imgsize-1 and shf_x >= 0 and shf_y <= self._imgsize-1 and shf_y >= 0:
+ st = random.uniform(0.85, 1.0)
+ ca = 255 * st
+ aa = int(ca)
+ d = randrange(1,26)
+ d2 = randrange(1,26)
+ details_pix[shf_x, shf_y] = (187-d, 179-d, 176-d, aa)
+ details_pix[shf_x2, shf_y2] = (187-d2, 179-d2, 176-d2, aa)
+ # Merge the details BELOW the houses
+ details.alpha_composite(layer_comp)
+ layer_comp = details
+ # New edge
+ osm_edge = osm_mask.filter(ImageFilter.FIND_EDGES)
+ osm_edge = osm_edge.filter(ImageFilter.GaussianBlur(radius=1))
+ # Blur the image
+ layer_comp = layer_comp.filter(ImageFilter.GaussianBlur(radius=1))
+ osm_edge.alpha_composite(layer_comp)
+ layer_comp = osm_edge
+
+
+ # Add some random trees
+ div = int(self._imgsize/200)
+ for y in range(0, self._imgsize, div):
+ for x in range(0, self._imgsize, div):
+ if x > 0 and x < self._imgsize and y > 0 and y < self._imgsize:
+ p = mask_pix[x, y]
+ if p[3] != 0:
+ # We found something...
+ # Determine if we put something somewhere
+ placement = randrange(0, 5)
+ if placement == 1:
+ # Do some random shift away from this location
+ shf_x = randrange(x-11, x+11)
+ shf_y = randrange(y-11, y+11)
+ if shf_x > 0 and shf_x < self._imgsize and shf_y > 0 and shf_y < self._imgsize:
+ # Pick some file
+ pick = str(randrange(1, 11))
+ tree = Image.open(mstr_datafolder + "Textures\\building\\area\\p" + pick + ".png")
+ layer_comp.alpha_composite(tree, (shf_x, shf_y))
+ #layer_comp.paste(tree, (shf_x, shf_y))
+
+
mstr_msg("layergen", "Layer image generated")
# Building shadow
for y in range(self._imgsize-1):
for x in range(self._imgsize-1):
m = mask_pix[x,y]
- shf_x = x + mstr_shadow_shift
- if shf_x <= self._imgsize-1:
+ shf_x = x + randrange(1, mstr_shadow_shift)
+ shf_x2 = x + randrange(1, mstr_shadow_shift)
+ if shf_x <= self._imgsize-1 and shf_x >= 0 and shf_x2 <= self._imgsize-1 and shf_x2 >= 0:
a = mask_pix[x,y][3]
st = random.uniform(0.45, mstr_shadow_strength)
ca = a * st
aa = int(ca)
shadow_pix[shf_x, y] = (0,0,0,aa)
+ shadow_pix[shf_x2, y] = (0,0,0,aa)
shadow.save(mstr_datafolder + "_cache\\" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_shadow.png")
mstr_msg("layergen", "Shadow layer completed")