From: Marcus Str. Date: Fri, 29 Nov 2024 16:24:32 +0000 (+0100) Subject: Ortho4XP-like approach to generate water masks. I may roll this back if it does not... X-Git-Url: https://marstr.online/code/gitweb.cgi?a=commitdiff_plain;h=642b42de1ed23eebc070033f652eecd7043c4067;p=orthographic Ortho4XP-like approach to generate water masks. I may roll this back if it does not work. --- diff --git a/layergen.py b/layergen.py index 5b04f37..b699dfa 100644 --- a/layergen.py +++ b/layergen.py @@ -459,17 +459,27 @@ class mstr_layergen: # 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"): 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() inl_pix = inl_mask.load() for y in range(self._imgsize): for x in range(self._imgsize): l = lyr_pix[x,y] - if l[3] > 65: - b = 255 - l[3] - inl_pix[x,y] = (255,0,255,255) + if l[3] > 50: + clr = 255-l[3] + 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") - layer_comp = inl_mask + #layer_comp = inl_mask mstr_msg("layergen", "Inland water mask generated and saved") # Return the completed image diff --git a/xp_scenery.py b/xp_scenery.py index 720591f..b87cc75 100644 --- a/xp_scenery.py +++ b/xp_scenery.py @@ -154,6 +154,8 @@ class mstr_xp_scenery: cnt_x = cur_lat + (self._vstep/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 + "A\r\n" terstr = terstr + "800\r\n" @@ -164,6 +166,9 @@ class mstr_xp_scenery: if mstr_xp_scn_normalmaps == True: 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" 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/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/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 sim/creation_agent Orthographic\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): # Write the line only if an ortho exists of course. 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: dsfstr = "TERRAIN_DEF terrain/" + self._latlngfld + "/" + str(lat) + "_" + str(lng) + ".ter\r\n" # Let's check if this tile needs water beneath - needs_water = False - 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: + if os.path.isfile(ddsf_water) == True: dsfstr = dsfstr + "TERRAIN_DEF terrain_Water\r\n" 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 + "/" + 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: 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 needs_water = False - 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 os.path.isfile(ddsf_water) == True: needs_water = True if needs_water == True: