def __map_Topography(self, planet, model, pts=[]): height_map = PNMImage() height_map_path = "{}/maps/{}".format(planet.path, planet.height_map) height_map.read(Filename(height_map_path)) _hu_size = height_map.getXSize() - 1 _hv_size = height_map.getYSize() - 1 radius = planet.radius bottom = radius + planet.height_min elev_range = planet.height_max - planet.height_min _has_sea = "sea_level" in planet.__dict__ if _has_sea: sea_level = planet.sea_level + planet.radius if not pts: pts = model.read("vertex") for pt in pts: u, v = self.__get_Pt_Uv(pt, _hu_size, _hv_size) height_val = height_map.getGray( u, v) ## watch when extending w colours. height = bottom + elev_range * height_val ratio = height / radius pt *= ratio # If planet has sea then raise vert to sea level. if _has_sea: len_pt = pt.length() if len_pt <= sea_level: ratio = sea_level / len_pt pt *= ratio model.modify("vertex", pts)
def __map_Topography(self, planet, model, pts=[]): height_map = PNMImage() height_map_path = "{}/maps/{}".format(planet.path, planet.height_map) height_map.read(Filename(height_map_path)) _hu_size = height_map.getXSize()-1 _hv_size = height_map.getYSize()-1 radius = planet.radius bottom = radius + planet.height_min elev_range = planet.height_max - planet.height_min _has_sea = "sea_level" in planet.__dict__ if _has_sea: sea_level = planet.sea_level + planet.radius if not pts: pts = model.read("vertex") for pt in pts: u, v = self.__get_Pt_Uv(pt, _hu_size, _hv_size) height_val = height_map.getGray(u, v) ## watch when extending w colours. height = bottom + elev_range*height_val ratio = height / radius pt *= ratio # If planet has sea then raise vert to sea level. if _has_sea: len_pt = pt.length() if len_pt <= sea_level: ratio = sea_level/len_pt pt *= ratio model.modify("vertex", pts)
def load_terrain_map(self): image = PNMImage() if image.read(self.get_terrain_file_name()): for y in range(self.patch.r_height): for x in range(self.patch.r_width): self.patch.set_height(x, y, image.getGray(x, y)) return True else: return False