parent
28779c4385
commit
3f0d6efa4b
@ -0,0 +1,35 @@ |
||||
[remap] |
||||
|
||||
importer="texture" |
||||
type="StreamTexture" |
||||
path="res://.import/map.png-9eea34967fae34f4388f4a32a16da936.stex" |
||||
metadata={ |
||||
"vram_texture": false |
||||
} |
||||
|
||||
[deps] |
||||
|
||||
source_file="res://map.png" |
||||
dest_files=[ "res://.import/map.png-9eea34967fae34f4388f4a32a16da936.stex" ] |
||||
|
||||
[params] |
||||
|
||||
compress/mode=0 |
||||
compress/lossy_quality=0.7 |
||||
compress/hdr_mode=0 |
||||
compress/bptc_ldr=0 |
||||
compress/normal_map=0 |
||||
flags/repeat=0 |
||||
flags/filter=true |
||||
flags/mipmaps=false |
||||
flags/anisotropic=false |
||||
flags/srgb=2 |
||||
process/fix_alpha_border=true |
||||
process/premult_alpha=false |
||||
process/HDR_as_SRGB=false |
||||
process/invert_color=false |
||||
process/normal_map_invert_y=false |
||||
stream=false |
||||
size_limit=0 |
||||
detect_3d=true |
||||
svg/scale=1.0 |
||||
@ -1,108 +1,18 @@ |
||||
extends Node2D |
||||
extends TextureRect |
||||
|
||||
signal map_clicked |
||||
|
||||
func heightmap(): |
||||
draw_rect(Rect2(Vector2(0, 0), Vector2(2048, 2048)), Color("#0e88bd")) |
||||
var coastline = PoolVector2Array() |
||||
|
||||
for center in Global.terrain.get_centers(): |
||||
if not center.get_data("ocean"): |
||||
var colors = Gradient.new() |
||||
colors.add_point(0.999, Color("#9e0142")) # red |
||||
colors.add_point(0.5, Color("#dc865d")) # orange |
||||
colors.add_point(0.25, Color("#fbf8b0")) # yellow |
||||
colors.add_point(0.0, Color("#89cfa5")) # green |
||||
colors.add_point(-0.999, Color("#5e4fa2")) # blue |
||||
var color = colors.interpolate(min(center.get_elevation() + 0.001, 0.999)) |
||||
# color = Color.green |
||||
if center.get_data("ocean"): |
||||
# var factor = pow((center.get_elevation()+1.001), 10) / 5.0 |
||||
color = Color("#5e4fa2") |
||||
# if center.get_data("coast"): |
||||
# color = Color.black |
||||
if center.polygon().size() > 2: |
||||
draw_polygon(center.polygon(), PoolColorArray([color])) |
||||
|
||||
if center.get_data("coast"): |
||||
for border in center.borders(): |
||||
if (border.end_center().get_data("ocean")): |
||||
coastline.append(border.line()[0]) |
||||
coastline.append(border.line()[1]) |
||||
|
||||
# for edge in Global.terrain.get_edges(): |
||||
# if edge.get_data("coast"): |
||||
|
||||
# if edge.get_data("river"): |
||||
# draw_line(edge.line()[0], edge.line()[1], Color.blue, 5.0) |
||||
draw_multiline(coastline, Color.black) |
||||
|
||||
func draw_triangles_edges(color=Color("#000000")): |
||||
for line in Global.terrain.get_edges_as_line(): |
||||
draw_line(line[0], line[1], color) |
||||
|
||||
func draw_voronoi_edges(color=Color("#000000")): |
||||
for line in Global.terrain.get_voronoi_edges_as_line(): |
||||
draw_line(line[0], line[1], color) |
||||
|
||||
func draw_voronoi_cells_old(): |
||||
var seen = [] |
||||
for edge_idx in Global.terrain.edges(): |
||||
var triangles = [] |
||||
var vertices = [] |
||||
var p = Global.terrain._triangles[Global.terrain.next_half_edge(edge_idx)] |
||||
if not seen.has(p): |
||||
seen.append(p) |
||||
var edges = Global.terrain.edges_around_point(edge_idx) |
||||
for edge_around_idx in edges: |
||||
triangles.append(Global.terrain.triangle_of_edge(edge_around_idx)) |
||||
for triangle in triangles: |
||||
vertices.append(Global.terrain.triangle_center(triangle)) |
||||
|
||||
if triangles.size() > 2: |
||||
var color = Color(randf(), randf(), randf(), 1) |
||||
var voronoi_cell = PoolVector2Array() |
||||
for vertice in vertices: |
||||
voronoi_cell.append(Vector2(vertice.x, vertice.z)) |
||||
draw_polygon(voronoi_cell, PoolColorArray([color])) |
||||
func draw_voronoi_cells(): |
||||
for polygon in Global.terrain.get_voronoi_cells_as_polygon(): |
||||
var color = Color(randf(), randf(), randf(), 1) |
||||
if polygon.size() > 2: |
||||
draw_polygon(polygon, PoolColorArray([color])) |
||||
|
||||
func draw_voronoi_cells_convex_hull(): |
||||
for point_idx in Global.terrain.points(): |
||||
var triangles = [] |
||||
var vertices = [] |
||||
var incoming = Global.terrain._points_to_half_edges.get(point_idx) |
||||
|
||||
if incoming == null: |
||||
triangles.append(0) |
||||
else: |
||||
var edges = Global.terrain.edges_around_point(incoming) |
||||
for edge_idx in edges: |
||||
triangles.append(Global.terrain.triangle_of_edge(edge_idx)) |
||||
|
||||
for triangle_idx in triangles: |
||||
vertices.append(Global.terrain.triangle_center(triangle_idx)) |
||||
|
||||
if triangles.size() > 2: |
||||
var color = Color(randf(), randf(), randf(), 1) |
||||
var voronoi_cell = PoolVector2Array() |
||||
for vertice in vertices: |
||||
voronoi_cell.append(Vector2(vertice[0], vertice[1])) |
||||
draw_polygon(voronoi_cell, PoolColorArray([color])) |
||||
|
||||
func _draw(): |
||||
heightmap() |
||||
# draw_voronoi_cells() |
||||
# draw_triangles_edges() |
||||
# draw_voronoi_cells_convex_hull() |
||||
# draw_voronoi_edges(Color("#ff0000")) |
||||
func _ready(): |
||||
var file_name = 'user://terrain/%s/map.png' % (Global.terrain_name) |
||||
var image = Image.new() |
||||
var err = image.load(file_name) |
||||
if err != OK: |
||||
print('Image load failed : %s' % (file_name)) |
||||
texture = ImageTexture.new() |
||||
texture.create_from_image(image, Image.FORMAT_RGBA8) |
||||
|
||||
func _process(_delta): |
||||
if Input.is_action_pressed("alt_command"): |
||||
var new_position = get_viewport().get_mouse_position() / scale |
||||
if new_position.x <= 2000 and new_position.y <= 2000: |
||||
var new_position = get_viewport().get_mouse_position() |
||||
if new_position.x <= 512 and new_position.y <= 512: |
||||
emit_signal("map_clicked", new_position) |
||||
|
||||
@ -0,0 +1,51 @@ |
||||
extends Reference |
||||
|
||||
# Build terrain from delaunay graph |
||||
class_name Map |
||||
|
||||
var image |
||||
var terrain |
||||
|
||||
# Called when the node enters the scene tree for the first time. |
||||
func _init(a_terrain): |
||||
self.terrain = a_terrain |
||||
a_terrain.set_data("map",self) |
||||
|
||||
func gen_map(): |
||||
Global.loadings["world_creation"].new_phase("Generation de la carte...", terrain._points.size()) |
||||
image = Image.new() |
||||
image.create(terrain._width,terrain._height,false,Image.FORMAT_RGBA8) |
||||
image.lock() |
||||
image.fill(Color('#5aa6ca')) |
||||
image.unlock() |
||||
var file_name = "user://terrain/%s/map.png" % (terrain.get_name()) |
||||
|
||||
for center in terrain.get_centers(): |
||||
if not center.get_data("water"): |
||||
var voronoi = center.get_data("voronoi") |
||||
var voronoi_bounding_box = center.get_data("voronoi_bounding_box") |
||||
# print_debug("Creat voronoi image") |
||||
var voronoi_image = Image.new() |
||||
voronoi_image.create(int(voronoi_bounding_box.size.x), int(voronoi_bounding_box.size.y),false,Image.FORMAT_RGBA8) |
||||
voronoi_image.lock() |
||||
for x in int(voronoi_bounding_box.size.x): |
||||
for y in int(voronoi_bounding_box.size.y): |
||||
var pixel = [] |
||||
pixel.append(Vector2(voronoi_bounding_box.position.x + x, voronoi_bounding_box.position.y + y)) |
||||
pixel.append(Vector2(voronoi_bounding_box.position.x + x + 1, voronoi_bounding_box.position.y + y)) |
||||
pixel.append(Vector2(voronoi_bounding_box.position.x + x + 1, voronoi_bounding_box.position.y + y + 1)) |
||||
pixel.append(Vector2(voronoi_bounding_box.position.x + x, voronoi_bounding_box.position.y + y + 1)) |
||||
var alpha = Global.pixel_area(voronoi, pixel) |
||||
# print_debug("Alpha : %f" % (alpha)) |
||||
var color |
||||
if center.get_data("coast"): |
||||
color = Color(0.708, 0.646, 0.138, alpha) |
||||
else: |
||||
color = Color(0.253, 0.621, 0.229, alpha) |
||||
voronoi_image.set_pixel(x,y,color) |
||||
image.lock() |
||||
image.blend_rect(voronoi_image,Rect2(0.0,0.0,voronoi_bounding_box.size.x,voronoi_bounding_box.size.y),voronoi_bounding_box.position) |
||||
image.unlock() |
||||
voronoi_image.unlock() |
||||
Global.loadings["world_creation"].increment_step() |
||||
image.save_png(file_name) |
||||
Loading…
Reference in new issue