Fine-tuned tree generator in photogen
This commit is contained in:
parent
5f214308c4
commit
3de9058cc6
16
defines.py
16
defines.py
@ -252,14 +252,14 @@ mstr_mask_blur = [
|
|||||||
("amenity", "school", 1),
|
("amenity", "school", 1),
|
||||||
("highway", "pedestrian", 12),
|
("highway", "pedestrian", 12),
|
||||||
# Z-Order 4
|
# Z-Order 4
|
||||||
("highway", "motorway", 1),
|
("highway", "motorway", 0.5),
|
||||||
("highway", "primary", 1),
|
("highway", "primary", 0.5),
|
||||||
("highway", "secondary", 1),
|
("highway", "secondary", 0.5),
|
||||||
("highway", "tertiary", 1),
|
("highway", "tertiary", 0.5),
|
||||||
("highway", "unclassified", 1),
|
("highway", "unclassified", 0.5),
|
||||||
("highway", "living_street", 1),
|
("highway", "living_street", 0.5),
|
||||||
("highway", "residential", 1),
|
("highway", "residential", 0.5),
|
||||||
("highway", "service", 1),
|
("highway", "service", 0.5),
|
||||||
("highway", "footway", 2),
|
("highway", "footway", 2),
|
||||||
("highway", "track", 2),
|
("highway", "track", 2),
|
||||||
("highway", "path", 2),
|
("highway", "path", 2),
|
||||||
|
@ -567,18 +567,18 @@ class mstr_layergen:
|
|||||||
d = randrange(41, 61)
|
d = randrange(41, 61)
|
||||||
layer_comp_pix[x, y] = ( d,d,d,a[3] )
|
layer_comp_pix[x, y] = ( d,d,d,a[3] )
|
||||||
if self._tag == "highway" and self._value != "motorway":
|
if self._tag == "highway" and self._value != "motorway":
|
||||||
d = randrange(0, 6)
|
d = randrange(0, 31)
|
||||||
dr = 80+d
|
dr = 80+d
|
||||||
dg = 80+d
|
dg = 80+d
|
||||||
db = 85+d
|
db = 85+d
|
||||||
da = a[3]
|
da = 255
|
||||||
layer_comp_pix[x, y] = ( dr,dg,db,da )
|
layer_comp_pix[x, y] = ( dr,dg,db,da )
|
||||||
if self._tag == "highway" and self._value == "motorway":
|
if self._tag == "highway" and self._value == "motorway":
|
||||||
d = randrange(0, 46)
|
d = randrange(0, 46)
|
||||||
dr = 47+d
|
dr = 47+d
|
||||||
dg = 58+d
|
dg = 58+d
|
||||||
db = 60+d
|
db = 60+d
|
||||||
layer_comp_pix[x, y] = ( dr,dg,db,a[3] )
|
layer_comp_pix[x, y] = ( dr,dg,db,255 )
|
||||||
if self._tag == "highway" and (self._value == "footway" or self._value == "track" or self._value == "path"):
|
if self._tag == "highway" and (self._value == "footway" or self._value == "track" or self._value == "path"):
|
||||||
dr = randrange(158, 183)
|
dr = randrange(158, 183)
|
||||||
dg = randrange(143, 178)
|
dg = randrange(143, 178)
|
||||||
|
27
photogen.py
27
photogen.py
@ -225,6 +225,11 @@ class mstr_photogen:
|
|||||||
|
|
||||||
os.remove(mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._ty) + "_" + str(self._tx) + ".png")
|
os.remove(mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._ty) + "_" + str(self._tx) + ".png")
|
||||||
|
|
||||||
|
# Clear cache
|
||||||
|
cache = glob.glob(mstr_datafolder + "_cache/*" + str(self._lat) + "-" + str(self._ty) + "_" + str(self._lng) + "-" + str(self._tx) + "*.png")
|
||||||
|
for f in range(len(cache)):
|
||||||
|
os.remove(cache[f])
|
||||||
|
|
||||||
|
|
||||||
# Now generate the normal map for this ortho.
|
# Now generate the normal map for this ortho.
|
||||||
# But only if this is enabled.
|
# But only if this is enabled.
|
||||||
@ -252,7 +257,7 @@ class mstr_photogen:
|
|||||||
# Generates some random tree.
|
# Generates some random tree.
|
||||||
# We will now move away from using pre-made trees...
|
# We will now move away from using pre-made trees...
|
||||||
# they didn't look so great
|
# they didn't look so great
|
||||||
def generate_tree(self, bccolor=[(0,0,0)]):
|
def generate_tree(self, bccolor=None):
|
||||||
sx = randrange(18, 31)
|
sx = randrange(18, 31)
|
||||||
sy = randrange(18, 31)
|
sy = randrange(18, 31)
|
||||||
|
|
||||||
@ -272,7 +277,7 @@ class mstr_photogen:
|
|||||||
|
|
||||||
bc = []
|
bc = []
|
||||||
bcp = 0
|
bcp = 0
|
||||||
if bccolor[0] == 0:
|
if bccolor == None:
|
||||||
bc = [
|
bc = [
|
||||||
(36, 50, 52),
|
(36, 50, 52),
|
||||||
(30, 41, 39),
|
(30, 41, 39),
|
||||||
@ -302,6 +307,7 @@ class mstr_photogen:
|
|||||||
bcp = randrange(0, len(bc))
|
bcp = randrange(0, len(bc))
|
||||||
else:
|
else:
|
||||||
bc = bccolor
|
bc = bccolor
|
||||||
|
bcp = randrange(0, len(bc))
|
||||||
|
|
||||||
treedraw = ImageDraw.Draw(tree)
|
treedraw = ImageDraw.Draw(tree)
|
||||||
while ptsdrawn < treepts + 1:
|
while ptsdrawn < treepts + 1:
|
||||||
@ -361,25 +367,16 @@ class mstr_photogen:
|
|||||||
forest = curlyr
|
forest = curlyr
|
||||||
|
|
||||||
# Find the average color of the forest layer
|
# Find the average color of the forest layer
|
||||||
frstavg = [0,0,0]
|
frstclr = []
|
||||||
frstpix = None
|
frstpix = None
|
||||||
if forest != -1:
|
if forest != -1:
|
||||||
numusedpix = 0
|
|
||||||
frstpix = layers[forest].load()
|
frstpix = layers[forest].load()
|
||||||
avg=[0,0,0]
|
|
||||||
for y in range(0, self._imgsize):
|
for y in range(0, self._imgsize):
|
||||||
for x in range(0, self._imgsize):
|
for x in range(0, self._imgsize):
|
||||||
frs = frstpix[x,y]
|
frs = frstpix[x,y]
|
||||||
if frs[3] > 0:
|
if frs[3] > 0:
|
||||||
avg[0] = avg[0] + frs[0]
|
c = ( frs[0]-30, frs[1]-30, frs[2]-30 )
|
||||||
avg[1] = avg[1] + frs[1]
|
frstclr.append(c)
|
||||||
avg[2] = avg[2] + frs[2]
|
|
||||||
numusedpix = numusedpix + 1
|
|
||||||
|
|
||||||
# Calculate and set average
|
|
||||||
frstavg[0] = int(avg[0] / numusedpix)
|
|
||||||
frstavg[1] = int(avg[1] / numusedpix)
|
|
||||||
frstavg[2] = int(avg[2] / numusedpix)
|
|
||||||
|
|
||||||
|
|
||||||
# Walk through list of layers to decide where to add the trees
|
# Walk through list of layers to decide where to add the trees
|
||||||
@ -398,7 +395,7 @@ class mstr_photogen:
|
|||||||
lp = lyrmask[lx,ly]
|
lp = lyrmask[lx,ly]
|
||||||
wp = wtrpix[lx,ly]
|
wp = wtrpix[lx,ly]
|
||||||
if lp[3] == 255 and wp[3] == 0: # Exclude water bodies from tree placement
|
if lp[3] == 255 and wp[3] == 0: # Exclude water bodies from tree placement
|
||||||
tree = self.generate_tree(bccolor=[(frstavg[0], frstavg[1], frstavg[2])])
|
tree = self.generate_tree(frstclr)
|
||||||
trees.alpha_composite(tree, (lx, ly))
|
trees.alpha_composite(tree, (lx, ly))
|
||||||
|
|
||||||
tree_shadow = Image.new("RGBA", (self._imgsize, self._imgsize))
|
tree_shadow = Image.new("RGBA", (self._imgsize, self._imgsize))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user