diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index b3e9312..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,22 +0,0 @@ - -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. diff --git a/utils/world_generation/WorldGeneration.gd b/utils/world_generation/WorldGeneration.gd index d23bcc6..f00364b 100644 --- a/utils/world_generation/WorldGeneration.gd +++ b/utils/world_generation/WorldGeneration.gd @@ -4,13 +4,13 @@ class_name WorldGeneration export(int) var width = 2048 export(int) var height = 2048 -export(int) var spacing = 20 +export(int) var spacing = 40 export(int, 1, 9) var octaves = 5 export(int, 1, 30) var wavelength = 8 export(int) var border_width = 200 export(int) var terraces = 100 export(int) var terrace_height = 5 -export(float) var mountain_height = 6.0 / 24.0 +export(float) var mountain_height = 10.0 / 24.0 export(int) var river_proba = 200 var rng = RandomNumberGenerator.new() @@ -60,15 +60,23 @@ func init_data(): center.set_elevation(find_elevation(center.point2d())) if center.get_elevation() <= 0.0: center.set_data("water", true) + if center.get_elevation() >= mountain_height: + center.set_data("mountain", true) Global.loading.increment_step() fill_oceans() - remove_holes() + # remove_holes() for center in Global.terrain.get_centers(): center.set_data("coast", is_coast(center.to_point())) # if center.get_data("ocean"): # center.set_elevation(-1.0) + + center.set_data("material", "grass") + if center.get_data("mountain"): + center.set_data("material", "stone") + if center.get_data("coast"): + center.set_data("material", "sand") @@ -202,17 +210,6 @@ func edge_is_river(edge): return true return false -# func add_trees(): -# rng.randomize() -# var treescene = load("res://entities/environment/birchtree/birchtree.tscn") -# for triangle in Global.terrain.get_triangles(): -# if not triangle.get_data("water"): -# var num = rng.randi_range(0, 5) -# if num == 1: -# var tree = treescene.instance() -# tree.translation = Vector3(triangle.center3d() * Vector3(1, 12*10, 1)) -# add_child(tree) - @@ -231,7 +228,7 @@ func find_elevation(point): var nx = 2 * point.x / width - 1 var ny = 2 * point.y / height - 1 - var radius = range_lerp(elevation, -1, 1, 0.8, 1.0) + var radius = range_lerp(elevation, -1, 1, 0.8, 0.9) var distance = 1 - (1-pow(nx, 2)) * (1-pow(ny,2)) distance = sqrt(pow(nx, 2) + pow(ny, 2)) @@ -245,7 +242,7 @@ func find_elevation(point): elevation = min(elevation, 1) - elevation = round(elevation * terraces) / terraces + elevation = (elevation * terraces) / terraces return elevation @@ -283,12 +280,20 @@ func is_coast(point): func create_mesh(): + var file = File.new() + file.open("res://world/materials/materials.json", File.READ) + var materials = JSON.parse(file.get_as_text()).result + var st = SurfaceTool.new() st.begin(Mesh.PRIMITIVE_TRIANGLES) var factor = Vector3(1, 120, 1) for center in Global.terrain.get_centers(): if not center.get_data("water"): + var material_id = materials[center.get_data("material")] + var top_uv = Vector2(0, float(material_id) / (materials.size()-1)) + var border_uv = Vector2(1, float(material_id) / (materials.size()-1)) + for edge in center.borders(): if edge.end_center().get_elevation() < edge.start_center().get_elevation(): var top = edge.start_center().get_elevation() @@ -297,7 +302,7 @@ func create_mesh(): var bottom = edge.end_center().get_elevation() if edge.end_center().get_data("ocean"): bottom = 0.0 - + st.add_uv(border_uv) st.add_vertex(Vector3(edge.start_corner().point3d().x, bottom, edge.start_corner().point3d().z) * factor) st.add_vertex(Vector3(edge.end_corner().point3d().x, top, edge.end_corner().point3d().z) * factor) st.add_vertex(Vector3(edge.start_corner().point3d().x, top, edge.start_corner().point3d().z) * factor) @@ -305,7 +310,7 @@ func create_mesh(): st.add_vertex(Vector3(edge.start_corner().point3d().x, bottom, edge.start_corner().point3d().z) * factor) st.add_vertex(Vector3(edge.end_corner().point3d().x, bottom, edge.end_corner().point3d().z) * factor) st.add_vertex(Vector3(edge.end_corner().point3d().x, top, edge.end_corner().point3d().z) * factor) - + for corner_count in center.corners().size(): var current_corner = center.corners()[corner_count] var next_corner @@ -314,6 +319,7 @@ func create_mesh(): else: next_corner = center.corners()[0] + st.add_uv(Vector2(top_uv)) st.add_vertex(Vector3(current_corner.point2d().x, center.get_elevation(), current_corner.point2d().y) * factor) st.add_vertex(Vector3(next_corner.point2d().x, center.get_elevation(), next_corner.point2d().y) * factor) st.add_vertex(Vector3(center.point2d().x, center.get_elevation(), center.point2d().y) * factor) @@ -324,7 +330,7 @@ func create_mesh(): var mi = MeshInstance.new() mi.mesh = st.commit() - var material = load("res://world/world.material") + var material = load("res://world/materials/world.material") mi.set_surface_material(0, material) mi.create_trimesh_collision() mi.cast_shadow = GeometryInstance.SHADOW_CASTING_SETTING_ON diff --git a/world/World3d.gd b/world/World3d.gd index dc3c38b..62c90ef 100644 --- a/world/World3d.gd +++ b/world/World3d.gd @@ -1,5 +1,27 @@ extends Spatial +var rng = RandomNumberGenerator.new() + func _ready(): var mi = Global.terrain.get_data("mesh") add_child(mi) + add_trees() + +func add_trees(): + rng.randomize() + var treescene = load("res://entities/environment/birchtree/birchtree.tscn") + var poisson_disc_sampling: PoissonDiscSampling = PoissonDiscSampling.new() + + for center in Global.terrain.get_centers(): + if not center.get_data("water") and not center.get_data("coast") and not center.get_data("mountain"): + var num = rng.randi_range(0,10) + if num == 1: + var points2d = poisson_disc_sampling.generate_points(3, center.polygon(), 2) + for point in points2d: + # print(point) + var tree = treescene.instance() + var scaling = rng.randi_range(0.8, 1.2) + tree.scale = Vector3(scaling, scaling, scaling) + tree.rotate_y(rng.randi_range(0, 2*PI)) + tree.translation = Vector3(point.x, center.get_elevation() * 120, point.y) + add_child(tree) diff --git a/world/game.tscn b/world/game.tscn index 8236374..a05c5a7 100644 --- a/world/game.tscn +++ b/world/game.tscn @@ -1,7 +1,6 @@ -[gd_scene load_steps=12 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://ui/ui.tscn" type="PackedScene" id=1] -[ext_resource path="res://world/default_env.tres" type="Environment" id=3] [ext_resource path="res://world/World3d.gd" type="Script" id=4] [ext_resource path="res://utils/camera/CamBase.tscn" type="PackedScene" id=5] @@ -167,7 +166,6 @@ mesh = SubResource( 1 ) material/0 = SubResource( 3 ) [node name="WorldEnvironment" type="WorldEnvironment" parent="World3d"] -environment = ExtResource( 3 ) [node name="CamBase" parent="World3d" instance=ExtResource( 5 )] @@ -178,6 +176,7 @@ fov = 55.0 depth_threshold = 0.001 depth_multiplier = 999.0 zoom_sensibility = 1.436 +height = 6.596 [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 ) diff --git a/world/materials/colors.png b/world/materials/colors.png new file mode 100644 index 0000000..552593d Binary files /dev/null and b/world/materials/colors.png differ diff --git a/world/materials/colors.png.import b/world/materials/colors.png.import new file mode 100644 index 0000000..86543a5 --- /dev/null +++ b/world/materials/colors.png.import @@ -0,0 +1,35 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/colors.png-904d72771a067b8e29c211e8b0822e27.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://world/materials/colors.png" +dest_files=[ "res://.import/colors.png-904d72771a067b8e29c211e8b0822e27.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=false +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=false +svg/scale=1.0 diff --git a/world/materials/materials.json b/world/materials/materials.json new file mode 100644 index 0000000..fb6a7f9 --- /dev/null +++ b/world/materials/materials.json @@ -0,0 +1,5 @@ +{ + "grass": 0, + "stone": 1, + "sand": 2 +} diff --git a/world/materials/world.material b/world/materials/world.material new file mode 100644 index 0000000..c5148d2 Binary files /dev/null and b/world/materials/world.material differ diff --git a/world/world.material b/world/world.material deleted file mode 100644 index ae35355..0000000 Binary files a/world/world.material and /dev/null differ diff --git a/world/world.tres b/world/world.tres deleted file mode 100644 index ac212ee..0000000 --- a/world/world.tres +++ /dev/null @@ -1,4 +0,0 @@ -[gd_resource type="SpatialMaterial" format=2] - -[resource] -albedo_color = Color( 0.125, 0.5, 0.275, 1 )