]> marstr Code Repo - orthographic/commitdiff
Ortho4XP-like approach to generate water masks. I may roll this back if it does not...
authorMarcus Str. <marcus@marstr.online>
Fri, 29 Nov 2024 16:24:32 +0000 (17:24 +0100)
committerMarcus Str. <marcus@marstr.online>
Fri, 29 Nov 2024 16:24:32 +0000 (17:24 +0100)
layergen.py
xp_scenery.py

index 5b04f371b9a467c51d7e53852cfddfdd1fecd219..b699dfa42abfefffeecd0346e4272e5af34a5989 100644 (file)
@@ -459,17 +459,27 @@ class mstr_layergen:
             # Create a water mask we need to remove from the DDS later\r
             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"):\r
                 mstr_msg("layergen", "Generating inland water mask")\r
-                inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (0,0,0,0))\r
+                water_file = mstr_datafolder + "z_orthographic/orthos/" + self._latlngfld + "/" + str(self._lat_number) + "_" + str(self._lng_number) + "_water.png"\r
+                inl_mask = None\r
+                if os.path.isfile(water_file):\r
+                    inl_mask = Image.open(water_file)\r
+                else:\r
+                    inl_mask = Image.new("RGBA", (self._imgsize, self._imgsize), (255,255,255,255))\r
                 lyr_pix = layer_comp.load()\r
                 inl_pix = inl_mask.load()\r
                 for y in range(self._imgsize):\r
                     for x in range(self._imgsize):\r
                         l = lyr_pix[x,y]\r
-                        if l[3] > 65:\r
-                            b = 255 - l[3]\r
-                            inl_pix[x,y] = (255,0,255,255)\r
+                        if l[3] > 50:\r
+                            clr = 255-l[3]\r
+                            c = (clr,clr,clr,255)\r
+                            inl_pix[x,y] = c\r
+                inl_mask.save(water_file)\r
+                        #if l[3] > 65:\r
+                        #    b = 255 - l[3]\r
+                        #    inl_pix[x,y] = (255,0,255,255)\r
                 #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")\r
-                layer_comp = inl_mask\r
+                #layer_comp = inl_mask\r
                 mstr_msg("layergen", "Inland water mask generated and saved")\r
 \r
             # Return the completed image\r
index 720591fa29cfc658e2fe2749dd0f9eaff139a185..b87cc754e3429cfbb051ee05b6e460b83b0fd584 100644 (file)
@@ -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: