Merge pull request #18 from eriwyn:eriwyn/issue6

Eriwyn/issue6
pull/22/head
eriwyn 3 years ago committed by GitHub
commit c1f6ab3e27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      LICENSE.md
  2. 12
      project.godot
  3. 6
      ui/map/map.gd
  4. 4
      utils/camera/CamBase.tscn
  5. 11
      utils/camera/CameraController.gd
  6. 156
      utils/camera/outline.gd
  7. 134
      utils/camera/post_process_outlines.shader
  8. 18
      utils/camera/post_process_outlines_material.tres
  9. 11
      utils/terrain/Terrain.gd
  10. 43
      world/World.gd
  11. 48
      world/World3d.gd
  12. 48
      world/game.gd
  13. 32
      world/game.tscn
  14. BIN
      world/world.material
  15. 2
      world/world.tres

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2021 João Marinheiro
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -9,11 +9,16 @@
config_version=4
_global_script_classes=[ {
"base": "Camera",
"base": "CameraOutline",
"class": "CameraController",
"language": "GDScript",
"path": "res://utils/camera/CameraController.gd"
}, {
"base": "Camera",
"class": "CameraOutline",
"language": "GDScript",
"path": "res://utils/camera/outline.gd"
}, {
"base": "Reference",
"class": "Delaunator",
"language": "GDScript",
@ -31,6 +36,7 @@ _global_script_classes=[ {
} ]
_global_script_class_icons={
"CameraController": "",
"CameraOutline": "",
"Delaunator": "",
"PoissonDiscSampling": "",
"Terrain": ""
@ -46,6 +52,10 @@ config/icon="res://icon.png"
Global="*res://utils/Global.gd"
[editor_plugins]
enabled=PoolStringArray( )
[gui]
common/drop_mouse_on_gui_input_disabled=true

@ -10,11 +10,11 @@ func heightmap():
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, Color("#89cfa5")) # green
colors.add_point(0.0, Color("#89cfa5")) # green
colors.add_point(-0.999, Color("#5e4fa2")) # blue
var color = colors.interpolate(min(triangle.get_data("elevation"), 0.999))
var color = colors.interpolate(min(triangle.get_elevation()+0.001, 0.999))
if triangle.get_data("ocean"):
var factor = pow((triangle.get_data("elevation")+1), 10) / 5.0
var factor = pow((triangle.get_elevation()+1), 10) / 5.0
color = Color("#5e4fa2") + Color(factor, factor, factor, 0.0)
if triangle.polygon().size() > 2:
draw_polygon(triangle.polygon(), PoolColorArray([color]))

@ -15,10 +15,6 @@ size = 20.0
near = 0.01
far = 8192.0
script = ExtResource( 3 )
movement_speed = 70.017
min_zoom = 51.0
zoom_sensibility = 2.818
rotation_sensibility = 1.0
[node name="Node" type="Node" parent="Camera"]
script = ExtResource( 4 )

@ -1,4 +1,4 @@
extends Camera
extends CameraOutline
class_name CameraController
signal camera_moved(new_location)
@ -8,7 +8,7 @@ enum CAMERA_ACTIONS{
ROTATING_VIEW,
}
export(float,1,100) var movement_speed = 30
export(float,1,100) var movement_speed = 48
export(float,0.01,0.99) var movement_damping = 0.74
export(float,0.01, 3.1415) var max_rotation = 1.2
export(float,0.01, 3.1415) var min_rotation = 0.5
@ -18,13 +18,14 @@ export(float,0.01, 3.1415) var min_rotation = 0.5
export(float, 0.0,1.0) var edge_size = 0.0
#EDIT HERE--->**,***<--- ZOOM MIN AND MAX LIMITS
export(float, 10,100) var min_zoom = 25
export(float, 10,100) var min_zoom = 10
export(float, 10,100) var max_zoom = 100
export(float, 1,3) var zoom_sensibility = 2.5
export(float, 1,3) var zoom_sensibility = 1.4
export(float, 1,3) var rotation_sensibility = 2.3
export(float, 1.0, 10.0) var height = 5.0
var pitch : float
var yaw : float
var current_action = CAMERA_ACTIONS.MOVING
@ -78,7 +79,7 @@ func move(_velocity : Vector2):
y_offset = result.position.y
else:
y_offset = 0
global_transform.origin.y = max(5 + y_offset * 1.3, 10)
global_transform.origin.y = max(15 + y_offset * 1.3, 10)
emit_signal("camera_moved", global_transform.origin)

@ -0,0 +1,156 @@
tool
extends Camera
class_name CameraOutline
var screen_mesh : MeshInstance;
var global_post_process_material : ShaderMaterial = preload("post_process_outlines_material.tres");
var instance_post_process_material : ShaderMaterial = global_post_process_material.duplicate();
#Size of color outlines
export (float) var color_outline_scale = 0.0 setget set_color_scale, get_color_scale
#Size of depth outlines
export (float) var depth_outline_scale = 2.0 setget set_depth_scale, get_depth_scale
#Controls sensitivity to depth changes (lower values mean more outlines, but more artifacts too)
export (float,0,10) var depth_threshold = 0.1 setget set_depth_thres, get_depth_thres
#Multiplier for depth values
export (float) var depth_multiplier = 99999.0 setget set_depth_multiplier, get_depth_multiplier
#General threshold for values to be considered as edges
export (float,0,1) var edge_threshold = 0.332 setget set_edge_threshold, get_edge_threshold
#Max edge alpha, lower values means edges blend more with background
export (float,0,1) var max_edge_alpha = 0.791 setget set_max_edge_alpha, get_max_edge_alpha
#General multiplier for edge alpha value, higher values mean harder edges
export (float) var edge_alpha_multiplier = 3.0 setget set_alpha_multiplier, get_alpha_multiplier
#Outlines color
export (Color) var edge_color = Color(0.4,0.4,0.4,1) setget set_edge_color, get_edge_color
#Sets depth edges to use the laplace operator instead of sobel
export (Texture) var background_tex setget set_bg_tex, get_bg_tex
#Sets depth edges to use the laplace operator instead of sobel
export (bool) var depth_use_laplace = true setget set_depth_use_laplace, get_depth_use_laplace
#Sets color edges to use the laplace operator instead of sobel
export (bool) var color_use_laplace = false setget set_color_use_laplace, get_color_use_laplace
#Sets shader to use render the BG behind the edges
export (bool) var use_bg_texture = false setget set_use_bg_texture, get_use_bg_texture
func set_color_scale(value):
color_outline_scale = value;
instance_post_process_material.set_shader_param("color_outline_scale", value);
func get_color_scale():
return color_outline_scale;
func set_depth_scale(value):
depth_outline_scale = value;
instance_post_process_material.set_shader_param("depth_outline_scale", value);
func get_depth_scale():
return depth_outline_scale;
func set_depth_thres(value):
depth_threshold = value;
instance_post_process_material.set_shader_param("depth_threshold", value);
func get_depth_thres():
return depth_threshold;
func set_depth_multiplier(value):
depth_multiplier = value;
instance_post_process_material.set_shader_param("depth_multiplier", value);
func get_depth_multiplier():
return depth_multiplier;
func set_edge_threshold(value):
edge_threshold = value;
instance_post_process_material.set_shader_param("edge_threshold", value);
func get_edge_threshold():
return edge_threshold;
func set_max_edge_alpha(value):
max_edge_alpha = value;
instance_post_process_material.set_shader_param("max_edge_alpha", value);
func get_max_edge_alpha():
return max_edge_alpha;
func set_alpha_multiplier(value):
edge_alpha_multiplier = value;
instance_post_process_material.set_shader_param("edge_alpha_multiplier", value);
func get_alpha_multiplier():
return edge_alpha_multiplier;
func set_edge_color(value):
edge_color = value;
instance_post_process_material.set_shader_param("edge_color", value);
func get_edge_color():
return edge_color;
func set_bg_tex(value):
background_tex = value;
instance_post_process_material.set_shader_param("bgTex", value);
func get_bg_tex():
return background_tex;
func set_depth_use_laplace(value):
depth_use_laplace = value;
instance_post_process_material.set_shader_param("depth_use_laplace", value);
func get_depth_use_laplace():
return depth_use_laplace;
func set_color_use_laplace(value):
color_use_laplace = value;
instance_post_process_material.set_shader_param("color_use_laplace", value);
func get_color_use_laplace():
return color_use_laplace;
func set_use_bg_texture(value):
use_bg_texture = value;
instance_post_process_material.set_shader_param("use_bg_texture", value);
func get_use_bg_texture():
return use_bg_texture;
func _ready():
screen_mesh = MeshInstance.new();
var quad : QuadMesh = QuadMesh.new();
quad.size = Vector2(2,2);
screen_mesh.mesh = quad;
screen_mesh.material_override = instance_post_process_material;
screen_mesh.extra_cull_margin = 16000;
add_child(screen_mesh);
set_color_scale(color_outline_scale)
set_depth_scale(depth_outline_scale)
set_alpha_multiplier(edge_alpha_multiplier)
set_depth_thres(depth_threshold)
set_depth_multiplier(depth_multiplier)
set_edge_threshold(edge_threshold)
set_max_edge_alpha(max_edge_alpha)
set_edge_color(edge_color)
set_bg_tex(background_tex)
set_use_bg_texture(use_bg_texture)
set_depth_use_laplace(depth_use_laplace)
set_color_use_laplace(color_use_laplace)
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

@ -0,0 +1,134 @@
shader_type spatial;
render_mode depth_draw_never, depth_test_disable, unshaded;
uniform float color_outline_scale = 2.0; // Size of color outlines
uniform float depth_outline_scale = 2.0; // Size of depth outlines
uniform float depth_threshold : hint_range(0,10) = 2.5; // Controls sensitivity to depth changes (lower values mean more outlines, but more artifacts too)
uniform float depth_multiplier = 1000.0; // Multiplier for depth values
uniform float edge_threshold : hint_range(0,1) = 0.04; // General threshold for values to be considered as edges
uniform float max_edge_alpha : hint_range(0,1) = 0.8; // Max edge alpha, lower values means edges blend more with background
uniform float edge_alpha_multiplier = 3.0; // General multiplier for edge alpha value, higher values mean harder edges
uniform vec4 edge_color : hint_color = vec4(0,0,0,1); // Outlines color
uniform sampler2D bgTex : hint_albedo; // BG texture
uniform bool depth_use_laplace = true; // Sets depth edges to use the laplace operator instead of sobel
uniform bool color_use_laplace = false; // Sets color edges to use the laplace operator instead of sobel
uniform bool use_bg_texture = false; // Sets shader to use render the BG behind the edges
varying mat4 CAMERA;
void vertex() {
POSITION = vec4(VERTEX, 1.0);
CAMERA = CAMERA_MATRIX;
}
float getDepthVal(sampler2D depthTex, vec2 depthUV, mat4 invProjMat) {
float depth = texture(depthTex, depthUV).r;
return depth;
}
void fragment() {
float halfScaleFloor_c = floor(color_outline_scale * 0.5);
float halfScaleCeil_c = ceil(color_outline_scale * 0.5);
float halfScaleFloor_d = floor(depth_outline_scale * 0.5);
float halfScaleCeil_d = ceil(depth_outline_scale * 0.5);
vec2 texelSize = vec2(1.0/VIEWPORT_SIZE.x, 1.0/VIEWPORT_SIZE.y);
vec2 bottomLeftUV_c = SCREEN_UV - vec2(texelSize.x, texelSize.y) * halfScaleFloor_c;
vec2 topRightUV_c = SCREEN_UV + vec2(texelSize.x, texelSize.y) * halfScaleCeil_c;
vec2 topUV_c = SCREEN_UV + vec2(0.0, texelSize.y * halfScaleCeil_c);
vec2 bottomUV_c = SCREEN_UV + vec2(0.0, -texelSize.y * halfScaleFloor_c);
vec2 rightUV_c = SCREEN_UV + vec2(texelSize.x * halfScaleCeil_c, 0.0);
vec2 leftUV_c = SCREEN_UV + vec2(-texelSize.x * halfScaleFloor_c, 0.0);
vec2 bottomRightUV_c = SCREEN_UV + vec2(texelSize.x * halfScaleCeil_c, -texelSize.y * halfScaleFloor_c);
vec2 topLeftUV_c = SCREEN_UV + vec2(-texelSize.x * halfScaleFloor_c, texelSize.y * halfScaleCeil_c);
vec2 centerUV_c = SCREEN_UV;
vec2 bottomLeftUV_d = SCREEN_UV - vec2(texelSize.x, texelSize.y) * halfScaleFloor_d;
vec2 topRightUV_d = SCREEN_UV + vec2(texelSize.x, texelSize.y) * halfScaleCeil_d;
vec2 topUV_d = SCREEN_UV + vec2(0.0, texelSize.y * halfScaleCeil_d);
vec2 bottomUV_d = SCREEN_UV + vec2(0.0, -texelSize.y * halfScaleFloor_d);
vec2 rightUV_d = SCREEN_UV + vec2(texelSize.x * halfScaleCeil_d, 0.0);
vec2 leftUV_d = SCREEN_UV + vec2(-texelSize.x * halfScaleFloor_d, 0.0);
vec2 bottomRightUV_d = SCREEN_UV + vec2(texelSize.x * halfScaleCeil_d, -texelSize.y * halfScaleFloor_d);
vec2 topLeftUV_d = SCREEN_UV + vec2(-texelSize.x * halfScaleFloor_d, texelSize.y * halfScaleCeil_d);
vec2 centerUV_d = SCREEN_UV;
float d0 = getDepthVal(DEPTH_TEXTURE, topLeftUV_d, INV_PROJECTION_MATRIX);
float d1 = getDepthVal(DEPTH_TEXTURE, topUV_d, INV_PROJECTION_MATRIX);
float d2 = getDepthVal(DEPTH_TEXTURE, topRightUV_d, INV_PROJECTION_MATRIX);
float d3 = getDepthVal(DEPTH_TEXTURE, leftUV_d, INV_PROJECTION_MATRIX);
float d4 = getDepthVal(DEPTH_TEXTURE, centerUV_d, INV_PROJECTION_MATRIX);
float d5 = getDepthVal(DEPTH_TEXTURE, rightUV_d, INV_PROJECTION_MATRIX);
float d6 = getDepthVal(DEPTH_TEXTURE, bottomLeftUV_d, INV_PROJECTION_MATRIX);
float d7 = getDepthVal(DEPTH_TEXTURE, bottomUV_d, INV_PROJECTION_MATRIX);
float d8 = getDepthVal(DEPTH_TEXTURE, bottomRightUV_d, INV_PROJECTION_MATRIX);
float edgeDepth = 0.0;
if (depth_use_laplace) {
edgeDepth = (8.0 * d4 - (d0+d1+d2+d3+d5+d6+d7+d8)) * depth_multiplier;
}
else {
float d_sobel_edge_h = (d2 + (2.0*d5) + d8 - (d0 + (2.0*d3) + d6)) / 4.0;
float d_sobel_edge_v = (d0 + (2.0*d1) + d2 - (d6 + (2.0*d7) + d8)) / 4.0;
edgeDepth = sqrt((d_sobel_edge_h * d_sobel_edge_h) + (d_sobel_edge_v * d_sobel_edge_v)) * depth_multiplier;
}
float depthThreshold = depth_threshold * d0;
edgeDepth = smoothstep(depthThreshold-depthThreshold/5.0, depthThreshold, edgeDepth);
float edgeVal = edgeDepth;
vec4 n0 = texture(SCREEN_TEXTURE, topLeftUV_c);
vec4 n1 = texture(SCREEN_TEXTURE, topUV_c);
vec4 n2 = texture(SCREEN_TEXTURE, topRightUV_c);
vec4 n3 = texture(SCREEN_TEXTURE, leftUV_c);
vec4 n4 = texture(SCREEN_TEXTURE, centerUV_c);
vec4 n5 = texture(SCREEN_TEXTURE, rightUV_c);
vec4 n6 = texture(SCREEN_TEXTURE, bottomLeftUV_c);
vec4 n7 = texture(SCREEN_TEXTURE, bottomUV_c);
vec4 n8 = texture(SCREEN_TEXTURE, bottomRightUV_c);
float color_edge;
if (color_use_laplace) {
vec4 laplace_edge = (8.0 * n4 - (n0+n1+n2+n3+n5+n6+n7+n8));
color_edge = laplace_edge.r;
color_edge += laplace_edge.g;
color_edge += laplace_edge.b;
color_edge /= 3.0;
}
else {
vec4 sobel_edge_h = (n2 + (2.0*n5) + n8 - (n0 + (2.0*n3) + n6)) / 4.0;
vec4 sobel_edge_v = (n0 + (2.0*n1) + n2 - (n6 + (2.0*n7) + n8)) / 4.0;
vec4 sobel = sqrt((sobel_edge_h * sobel_edge_h) + (sobel_edge_v * sobel_edge_v));
color_edge = sobel.r;
color_edge += sobel.g;
color_edge += sobel.b;
color_edge /= 3.0;
}
edgeVal = max(edgeVal, color_edge);
if (edgeVal > edge_threshold) {
if (use_bg_texture) {
ALBEDO = edge_color.rgb * texture(bgTex, SCREEN_UV).rgb;
}
else {
ALBEDO = edge_color.rgb;
ALPHA = min(max_edge_alpha,edgeVal * edge_alpha_multiplier);
}
}
else {
if (use_bg_texture) {
ALBEDO = texture(bgTex, SCREEN_UV).rgb;
}
else {
ALPHA = 0.0;
}
}
}

@ -0,0 +1,18 @@
[gd_resource type="ShaderMaterial" load_steps=2 format=2]
[ext_resource path="res://utils/camera/post_process_outlines.shader" type="Shader" id=1]
[resource]
resource_local_to_scene = true
shader = ExtResource( 1 )
shader_param/color_outline_scale = 1.0
shader_param/depth_outline_scale = 1.0
shader_param/depth_threshold = 1.0
shader_param/depth_multiplier = 10000.0
shader_param/edge_threshold = 0.1
shader_param/max_edge_alpha = 0.8
shader_param/edge_alpha_multiplier = 3.0
shader_param/edge_color = Color( 0, 0, 0, 1 )
shader_param/depth_use_laplace = true
shader_param/color_use_laplace = false
shader_param/use_bg_texture = false

@ -63,6 +63,7 @@ class Triangle:
var list_points = []
for edge in edges():
list_points.append(Point.new(_terrain._triangles[edge._idx], _terrain))
list_points.invert()
return list_points
func triangles_adjacent():
@ -81,6 +82,13 @@ class Triangle:
var points = points()
return (points[0].point3d() + points[1].point3d() + points[2].point3d()) / 3.0
func set_elevation(elevation:float):
for point in points():
point.set_elevation(elevation)
func get_elevation():
return center3d().y
func polygon():
var polygon = []
for point in points():
@ -246,6 +254,9 @@ class Edge:
func triangle():
return Triangle.new(floor(_idx / 3), _terrain)
func opposite_triangle():
return opposite().triangle()
func start():
return Point.new(_terrain._triangles[_idx], _terrain)

@ -1,43 +0,0 @@
extends Spatial
var terrain
func _ready():
pass
func draw_world():
# for i in range(0, 1, 1):
# print(i)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.add_smooth_group(true)
for triangle in terrain.get_triangles():
for point in triangle.points():
var factor = Vector3(1, 24*5, 1)
# if point.get_data("river") and i == 0:
# factor.y -= 0
# if i == 1:
# factor.y -= 2.0
st.add_vertex(point.point3d() * factor)
st.generate_normals()
# st.generate_tangents()
st.index()
# Commit to a mesh.
var mesh = st.commit()
var mi = MeshInstance.new()
mi.mesh = mesh
var material = load("res://world/world.material")
mi.set_surface_material(0, material)
mi.create_trimesh_collision()
mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON
print(mi)
add_child(mi)
func _on_Game_world_loaded(game_terrain):
terrain = game_terrain
draw_world()

@ -0,0 +1,48 @@
extends Spatial
var terrain
func _ready():
pass
func draw_world():
# for i in range(0, 1, 1):
# print(i)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
# st.add_smooth_group(true)
for triangle in terrain.get_triangles():
var factor = Vector3(1, 12*10, 1)
for edge in triangle.edges():
if triangle.get_elevation() > edge.opposite_triangle().get_elevation():
st.add_vertex(Vector3(edge.start().point3d().x, triangle.get_elevation(), edge.start().point3d().z) * factor)
st.add_vertex(Vector3(edge.end().point3d().x, triangle.get_elevation(), edge.end().point3d().z) * factor)
st.add_vertex(Vector3(edge.start().point3d().x, edge.opposite_triangle().get_elevation(), edge.start().point3d().z) * factor)
st.add_vertex(Vector3(edge.end().point3d().x, triangle.get_elevation(), edge.end().point3d().z) * factor)
st.add_vertex(Vector3(edge.end().point3d().x, edge.opposite_triangle().get_elevation(), edge.end().point3d().z) * factor)
st.add_vertex(Vector3(edge.start().point3d().x, edge.opposite_triangle().get_elevation(), edge.start().point3d().z) * factor)
for point in triangle.points():
st.add_vertex(Vector3(point.point3d().x, triangle.get_elevation(), point.point3d().z) * factor)
st.generate_normals()
# st.generate_tangents()
st.index()
# Commit to a mesh.
var mesh = st.commit()
var mi = MeshInstance.new()
mi.mesh = mesh
var material = load("res://world/world.material")
mi.set_surface_material(0, material)
mi.create_trimesh_collision()
mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON
print(mi)
add_child(mi)
func _on_Game_world_loaded(game_terrain):
terrain = game_terrain
draw_world()

@ -8,7 +8,7 @@ export(int) var spacing = 20
export(int, 1, 9) var octaves = 5
export(int, 1, 30) var wavelength = 8
export(int) var border_width = 200
export(int) var terraces = 24
export(int) var terraces = 10
export(int) var terrace_height = 5
export(float) var mountain_height = 6.0 / 24.0
export(int) var river_proba = 200
@ -22,9 +22,8 @@ func _ready():
rng.randomize()
noise.seed = rng.randi()
noise.octaves = octaves
# terrain = Terrain.new(width,height,spacing,false)
var terrain_name="bonjour"
var terrain_name="bonjour90"
terrain = Terrain.new()
print(terrain.list())
@ -44,26 +43,26 @@ func _ready():
Global.print_debug("Pas de palais ..., pas de palais.")
func init_data():
for point in terrain.get_points():
point.set_elevation(point_find_elevation(point.point2d()))
point.set_data("water", point_is_water(point))
point.set_data("mountain", point_is_mountain(point))
# for point in terrain.get_points():
# point.set_elevation(point_find_elevation(point.point2d()))
# point.set_data("water", point_is_water(point))
# point.set_data("mountain", point_is_mountain(point))
# point.set_data("river", point_is_river(point))
fill_oceans()
# fill_oceans()
for point in terrain.get_points():
if point.get_data("water") and not point.get_data("ocean"):
point.set_elevation(0.1)
point.set_data("water", false)
point.set_data("coast", point_is_coast(point))
if point.get_data("river"):
set_river_path(point)
# for point in terrain.get_points():
# if point.get_data("water") and not point.get_data("ocean"):
# point.set_elevation(0.1)
# point.set_data("water", false)
# point.set_data("coast", point_is_coast(point))
# if point.get_data("river"):
# set_river_path(point)
for triangle in terrain.get_triangles():
triangle.set_data("elevation", triangle_find_elevation(triangle))
triangle.set_elevation(find_elevation(triangle.center2d()))
# triangle.set_data("elevation", triangle_find_elevation(triangle))
triangle.set_data("water", triangle_is_water(triangle))
triangle.set_data("ocean", false)
# TODO #1 : Get triangles around point
for point in triangle.points():
if point.get_data("ocean"):
triangle.set_data("ocean", true)
@ -120,7 +119,7 @@ func set_river_path(point):
# Point
func point_find_elevation(point):
func find_elevation(point):
var border = border_width + rng.randf_range(-20.0, 20.0)
var elevation = noise.get_noise_2d(point.x / wavelength, point.y / wavelength)
@ -178,7 +177,7 @@ func triangle_find_elevation(triangle):
return elevation
func triangle_is_water(triangle):
if triangle.get_data("elevation") <= 0:
if triangle.get_elevation() < 0:
return true
return false
@ -202,14 +201,5 @@ func add_trees():
var num = rng.randi_range(0, 5)
if num == 1:
var tree = treescene.instance()
tree.translation = Vector3(point.point3d() * Vector3(1, 24*5, 1))
tree.translation = Vector3(point.point3d() * Vector3(1, 12*10, 1))
add_child(tree)
# for point in points.size():
# if points_data[i].elevation > 0:
# var num = rng.randi_range(0, 20)
# if num == 2:
# var tree = treescene.instance()
# tree.translation = Vector3(points[i].x, points_data[i].elevation * terrace_height, points[i].y)
# add_child(tree)

@ -3,7 +3,7 @@
[ext_resource path="res://ui/ui.tscn" type="PackedScene" id=1]
[ext_resource path="res://world/game.gd" type="Script" id=2]
[ext_resource path="res://world/default_env.tres" type="Environment" id=3]
[ext_resource path="res://world/World.gd" type="Script" id=4]
[ext_resource path="res://world/World3d.gd" type="Script" id=4]
[ext_resource path="res://utils/camera/CamBase.tscn" type="PackedScene" id=5]
[sub_resource type="PlaneMesh" id=1]
@ -24,36 +24,34 @@ scale = Vector2( 0.25, 0.25 )
scale = Vector2( 4, 4 )
z_index = 3
[node name="World" type="Spatial" parent="."]
[node name="World3d" type="Spatial" parent="."]
script = ExtResource( 4 )
[node name="Water" type="MeshInstance" parent="World"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1000, -0.1, 1000 )
[node name="Water" type="MeshInstance" parent="World3d"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1000, -0.5, 1000 )
mesh = SubResource( 1 )
material/0 = SubResource( 2 )
[node name="WorldEnvironment" type="WorldEnvironment" parent="World"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="World3d"]
environment = ExtResource( 3 )
[node name="CamBase" parent="World" instance=ExtResource( 5 )]
[node name="CamBase" parent="World3d" instance=ExtResource( 5 )]
[node name="Camera" parent="World/CamBase" index="0"]
transform = Transform( 1, 0, 0, 0, 0.910272, -0.41401, 0, 0.41401, 0.910272, 0, -1.90735e-06, 6.618 )
movement_speed = 48.076
min_zoom = 10.0
[node name="Camera" parent="World3d/CamBase" index="0"]
transform = Transform( 1, 0, 0, 0, 0.659983, -0.75128, 0, 0.75128, 0.659983, 0, -1.90735e-06, 6.618 )
fov = 55.0
zoom_sensibility = 1.436
rotation_sensibility = 3.0
[node name="DirectionalLight" type="DirectionalLight" parent="World"]
transform = Transform( 1, 0, 0, 0, 0.512597, 0.858629, 0, -0.858629, 0.512597, 0, 1.41623, 0 )
[node name="DirectionalLight" type="DirectionalLight" parent="World3d"]
transform = Transform( 0.971628, 0.168947, -0.16552, 0, 0.699825, 0.714314, 0.236516, -0.694047, 0.67997, 0, 1.41623, 14.8745 )
light_energy = 0.1
shadow_enabled = true
[connection signal="world_loaded" from="." to="UI/Map" method="_on_Game_world_loaded"]
[connection signal="world_loaded" from="." to="World" method="_on_Game_world_loaded"]
[connection signal="map_clicked" from="UI/Map" to="World/CamBase/Camera" method="_on_Map_map_clicked"]
[connection signal="camera_moved" from="World/CamBase/Camera" to="UI/Map/Cursor" method="_on_Camera_camera_moved"]
[connection signal="world_loaded" from="." to="World3d" method="_on_Game_world_loaded"]
[connection signal="map_clicked" from="UI/Map" to="World3d/CamBase/Camera" method="_on_Map_map_clicked"]
[connection signal="camera_moved" from="World3d/CamBase/Camera" to="UI/Map/Cursor" method="_on_Camera_camera_moved"]
[editable path="UI"]
[editable path="UI/Map"]
[editable path="World/CamBase"]
[editable path="World3d/CamBase"]

Binary file not shown.

@ -1,4 +1,4 @@
[gd_resource type="SpatialMaterial" format=2]
[resource]
albedo_color = Color( 0.109804, 0.305882, 0.0745098, 1 )
albedo_color = Color( 0.125, 0.5, 0.275, 1 )

Loading…
Cancel
Save