Ortho4XP-like approach to generate water masks. I may roll this back if it does not work.

This commit is contained in:
Marcus Str. 2024-11-29 17:24:32 +01:00
parent 10d00169fe
commit 642b42de1e
2 changed files with 25 additions and 25 deletions

View File

@ -459,17 +459,27 @@ class mstr_layergen:
# Create a water mask we need to remove from the DDS later # Create a water mask we need to remove from the DDS later
if (self._tag == "natural" and self._value == "water") or (self._tag == "water" and self._value == "lake") or (self._tag == "water" and self._value == "pond") or (self._tag == "water" and self._value == "river") or (self._tag == "leisure" and self._value == "swimming_pool"): if (self._tag == "natural" and self._value == "water") or (self._tag == "water" and self._value == "lake") or (self._tag == "water" and self._value == "pond") or (self._tag == "water" and self._value == "river") or (self._tag == "leisure" and self._value == "swimming_pool"):
mstr_msg("layergen", "Generating inland water mask") mstr_msg("layergen", "Generating inland water mask")
inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,0)) water_file = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._lat_number) + "_" + str(self._lng_number) + "_water.png"
inl_mask = None
if os.path.isfile(water_file):
inl_mask = Image.open(water_file)
else:
inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (255,255,255,255))
lyr_pix = layer_comp.load() lyr_pix = layer_comp.load()
inl_pix = inl_mask.load() inl_pix = inl_mask.load()
for y in range(self._imgsize): for y in range(self._imgsize):
for x in range(self._imgsize): for x in range(self._imgsize):
l = lyr_pix[x,y] l = lyr_pix[x,y]
if l[3] > 65: if l[3] > 50:
b = 255 - l[3] clr = 255-l[3]
inl_pix[x,y] = (255,0,255,255) c = (clr,clr,clr,255)
inl_pix[x,y] = c
inl_mask.save(water_file)
#if l[3] > 65:
# b = 255 - l[3]
# inl_pix[x,y] = (255,0,255,255)
#inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png") #inl_mask.save(mstr_datafolder + "_cache/" + str(self._latitude) + "-" + str(self._lat_number) + "_" + str(self._longitude) + "-" + str(self._lng_number) + "_" + self._tag + "-" + self._value + "_layer_mask.png")
layer_comp = inl_mask #layer_comp = inl_mask
mstr_msg("layergen", "Inland water mask generated and saved") mstr_msg("layergen", "Inland water mask generated and saved")
# Return the completed image # Return the completed image

View File

@ -154,6 +154,8 @@ class mstr_xp_scenery:
cnt_x = cur_lat + (self._vstep/2) cnt_x = cur_lat + (self._vstep/2)
cnt_y = cur_lng + (mstr_zl_18/2) cnt_y = cur_lng + (mstr_zl_18/2)
ddsf_water = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + "_water.png"
terstr = "" terstr = ""
terstr = terstr + "A\r\n" terstr = terstr + "A\r\n"
terstr = terstr + "800\r\n" terstr = terstr + "800\r\n"
@ -164,6 +166,9 @@ class mstr_xp_scenery:
if mstr_xp_scn_normalmaps == True: if mstr_xp_scn_normalmaps == True:
terstr = terstr + "NORMAL_TEX 1.0 ../../normals/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".png\r\n" terstr = terstr + "NORMAL_TEX 1.0 ../../normals/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".png\r\n"
if os.path.isfile(ddsf_water) == True:
terstr = terstr + "BORDER_TEX ../../orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + "_water.png\r\n"
terfln = mstr_datafolder + "z_orthographic/terrain/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".ter" terfln = mstr_datafolder + "z_orthographic/terrain/" + self._latlngfld + "/" + str(lat)+"_"+str(lng)+".ter"
with open(terfln, 'w') as textfile: with open(terfln, 'w') as textfile:
@ -211,7 +216,7 @@ class mstr_xp_scenery:
dsf_str = dsf_str + "PROPERTY sim/east " + str((int(self._lng) + 1)) + "\r\n" dsf_str = dsf_str + "PROPERTY sim/east " + str((int(self._lng) + 1)) + "\r\n"
dsf_str = dsf_str + "PROPERTY sim/south " + str(int(self._lat)) + "\r\n" dsf_str = dsf_str + "PROPERTY sim/south " + str(int(self._lat)) + "\r\n"
dsf_str = dsf_str + "PROPERTY sim/north " + str((int(self._lat) + 1)) + "\r\n" dsf_str = dsf_str + "PROPERTY sim/north " + str((int(self._lat) + 1)) + "\r\n"
dsf_str = dsf_str + "PROPERTY sim/require_object 6/0\r\n" dsf_str = dsf_str + "PROPERTY sim/require_object 0/6\r\n"
dsf_str = dsf_str + "PROPERTY planet earth\r\n" dsf_str = dsf_str + "PROPERTY planet earth\r\n"
dsf_str = dsf_str + "PROPERTY sim/creation_agent Orthographic\r\n" dsf_str = dsf_str + "PROPERTY sim/creation_agent Orthographic\r\n"
#dsf_str = dsf_str + "TERRAIN_DEF terrain_Water\r\n" #dsf_str = dsf_str + "TERRAIN_DEF terrain_Water\r\n"
@ -226,21 +231,12 @@ class mstr_xp_scenery:
for lng in range(1, self._mlng+1): for lng in range(1, self._mlng+1):
# Write the line only if an ortho exists of course. # Write the line only if an ortho exists of course.
ddsf = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".dds" ddsf = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".dds"
ddsf_water = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + "_water.png"
if os.path.isfile(ddsf) == True: if os.path.isfile(ddsf) == True:
dsfstr = "TERRAIN_DEF terrain/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".ter\r\n" dsfstr = "TERRAIN_DEF terrain/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".ter\r\n"
# Let's check if this tile needs water beneath # Let's check if this tile needs water beneath
needs_water = False if os.path.isfile(ddsf_water) == True:
thistile = Image.open(ddsf)
tile_pix = thistile.load()
for y in range(thistile.height):
for x in range(thistile.width):
clr = tile_pix[x,y]
if clr[3] == 0:
needs_water = True
break
if needs_water == True:
dsfstr = dsfstr + "TERRAIN_DEF terrain_Water\r\n" dsfstr = dsfstr + "TERRAIN_DEF terrain_Water\r\n"
with open(meshtxt, 'a') as textfile: with open(meshtxt, 'a') as textfile:
@ -323,6 +319,7 @@ class mstr_xp_scenery:
#ddsf = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/1_1.dds" #ddsf = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/1_1.dds"
ddsf = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".dds" ddsf = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".dds"
ddsf_water = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + "_water.png"
if os.path.isfile(ddsf) == True: if os.path.isfile(ddsf) == True:
scangrid = self.find_height_scan_start_end_points([ self._lat+((lat-1)*self._vstep), self._lng+((lng-1)*mstr_zl_18) ]) scangrid = self.find_height_scan_start_end_points([ self._lat+((lat-1)*self._vstep), self._lng+((lng-1)*mstr_zl_18) ])
@ -430,14 +427,7 @@ class mstr_xp_scenery:
# Let's check if this tile needs water beneath # Let's check if this tile needs water beneath
needs_water = False needs_water = False
thistile = Image.open(ddsf) if os.path.isfile(ddsf_water) == True: needs_water = True
tile_pix = thistile.load()
for y in range(thistile.height):
for x in range(thistile.width):
clr = tile_pix[x,y]
if clr[3] == 0:
needs_water = True
break
if needs_water == True: if needs_water == True: