From fe10c4ef4ac29e2072ef535a11d555e3ed791514 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 16 Oct 2022 18:21:54 +0200 Subject: [PATCH] Refactored tile generation --- scenes/HexGrid3DTest.tscn | 13 +- scenes/HexTile3DPatch.tscn | 304 +++++++++++++++++++++++++++++++++++++ scenes/NoiseWorld.gd | 100 +++++++----- 3 files changed, 376 insertions(+), 41 deletions(-) create mode 100644 scenes/HexTile3DPatch.tscn diff --git a/scenes/HexGrid3DTest.tscn b/scenes/HexGrid3DTest.tscn index 04d144c..97c3bc2 100644 --- a/scenes/HexGrid3DTest.tscn +++ b/scenes/HexGrid3DTest.tscn @@ -120,7 +120,7 @@ map_data = PoolRealArray( 0 ) [sub_resource type="OpenSimplexNoise" id=11] octaves = 1 -period = 101.6 +period = 30.0 [sub_resource type="NoiseTexture" id=10] flags = 3 @@ -143,13 +143,14 @@ script = ExtResource( 2 ) [node name="World" type="Spatial" parent="."] script = ExtResource( 4 ) -world_size = 100 +world_size = 50 [node name="Scene" type="Spatial" parent="World"] [node name="Navigation" type="Spatial" parent="World"] [node name="Tiles" type="Spatial" parent="World"] +visible = false [node name="Highlight" type="MeshInstance" parent="World"] transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0.2, 0 ) @@ -158,14 +159,14 @@ mesh = SubResource( 7 ) material/0 = SubResource( 8 ) [node name="Water" type="MeshInstance" parent="World"] -transform = Transform( 50, 0, 0, 0, 50, 0, 0, 0, 50, 0, 0, 0 ) +transform = Transform( 25, 0, 0, 0, 25, 0, 0, 0, 25, 0, 0, 0 ) cast_shadow = 0 mesh = SubResource( 1 ) skeleton = NodePath("../..") material/0 = SubResource( 3 ) [node name="ClckArea" type="Area" parent="World"] -transform = Transform( 50, 0, 0, 0, 50, 0, 0, 0, 50, 0, 0, 0 ) +transform = Transform( 25, 0, 0, 0, 25, 0, 0, 0, 25, 0, 0, 0 ) [node name="CollisionShape" type="CollisionShape" parent="World/ClckArea"] transform = Transform( 2.5, 0, 0, 0, 1, 0, 0, 0, 2.5, 0, 0, 0 ) @@ -175,6 +176,8 @@ shape = SubResource( 6 ) visible = false texture = SubResource( 10 ) +[node name="PatchTiles" type="Spatial" parent="World"] + [node name="DirectionalLight" type="DirectionalLight" parent="."] transform = Transform( 0.83729, 0.174005, 0.518332, -0.54676, 0.266466, 0.793757, 0, -0.948008, 0.318248, 0, 8.03448, 0 ) shadow_enabled = true @@ -224,7 +227,7 @@ __meta__ = { script = ExtResource( 1 ) [node name="Camera" type="Camera" parent="Player"] -transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, -4.76837e-07, 6.70866, 3.34822 ) +transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, -4.76837e-07, 7.29903, 4.46831 ) current = true fov = 60.0 script = ExtResource( 3 ) diff --git a/scenes/HexTile3DPatch.tscn b/scenes/HexTile3DPatch.tscn new file mode 100644 index 0000000..a63e3ff --- /dev/null +++ b/scenes/HexTile3DPatch.tscn @@ -0,0 +1,304 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://scenes/HexTile3D.tscn" type="PackedScene" id=1] + +[node name="Spatial" type="Spatial"] + +[node name="HexTile3D1" parent="." instance=ExtResource( 1 )] + +[node name="HexTile3D2" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 0.866 ) + +[node name="HexTile3D3" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 1.732 ) + +[node name="HexTile3D4" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 2.598 ) + +[node name="HexTile3D5" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 3.464 ) + +[node name="HexTile3D8" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 4.33 ) + +[node name="HexTile3D6" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 5.196 ) + +[node name="HexTile3D7" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 6.062 ) + +[node name="HexTile3D9" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 6.928 ) + +[node name="HexTile3D10" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0, 0, 7.794 ) + +[node name="HexTile3D11" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 0.433 ) + +[node name="HexTile3D12" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 1.299 ) + +[node name="HexTile3D13" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 2.165 ) + +[node name="HexTile3D14" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 3.031 ) + +[node name="HexTile3D15" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 3.897 ) + +[node name="HexTile3D16" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 4.763 ) + +[node name="HexTile3D17" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 5.629 ) + +[node name="HexTile3D18" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 6.495 ) + +[node name="HexTile3D19" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 7.361 ) + +[node name="HexTile3D20" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 0.75, 0, 8.227 ) + +[node name="HexTile3D21" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 0 ) + +[node name="HexTile3D22" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 0.866 ) + +[node name="HexTile3D23" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 1.732 ) + +[node name="HexTile3D24" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 2.598 ) + +[node name="HexTile3D25" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 3.464 ) + +[node name="HexTile3D26" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 4.33 ) + +[node name="HexTile3D27" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 5.196 ) + +[node name="HexTile3D28" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 6.062 ) + +[node name="HexTile3D29" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 6.928 ) + +[node name="HexTile3D30" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 1.5, 0, 7.794 ) + +[node name="HexTile3D31" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 0.433 ) + +[node name="HexTile3D32" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 1.299 ) + +[node name="HexTile3D33" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 2.165 ) + +[node name="HexTile3D34" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 3.031 ) + +[node name="HexTile3D35" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 3.897 ) + +[node name="HexTile3D36" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 4.763 ) + +[node name="HexTile3D37" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 5.629 ) + +[node name="HexTile3D38" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 6.495 ) + +[node name="HexTile3D39" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 7.361 ) + +[node name="HexTile3D40" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 2.25, 0, 8.227 ) + +[node name="HexTile3D41" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 0 ) + +[node name="HexTile3D42" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 0.866 ) + +[node name="HexTile3D43" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 1.732 ) + +[node name="HexTile3D44" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 2.598 ) + +[node name="HexTile3D45" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 3.464 ) + +[node name="HexTile3D46" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 4.33 ) + +[node name="HexTile3D47" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 5.196 ) + +[node name="HexTile3D48" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 6.062 ) + +[node name="HexTile3D49" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 6.928 ) + +[node name="HexTile3D50" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3, 0, 7.794 ) + +[node name="HexTile3D51" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 0.433 ) + +[node name="HexTile3D52" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 1.299 ) + +[node name="HexTile3D53" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 2.165 ) + +[node name="HexTile3D54" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 3.031 ) + +[node name="HexTile3D55" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 3.897 ) + +[node name="HexTile3D56" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 4.763 ) + +[node name="HexTile3D57" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 5.629 ) + +[node name="HexTile3D58" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 6.495 ) + +[node name="HexTile3D59" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 7.361 ) + +[node name="HexTile3D60" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 3.75, 0, 8.227 ) + +[node name="HexTile3D61" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 0 ) + +[node name="HexTile3D62" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 0.866 ) + +[node name="HexTile3D63" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 1.732 ) + +[node name="HexTile3D64" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 2.598 ) + +[node name="HexTile3D65" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 3.464 ) + +[node name="HexTile3D66" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 4.33 ) + +[node name="HexTile3D67" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 5.196 ) + +[node name="HexTile3D68" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 6.062 ) + +[node name="HexTile3D69" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 6.928 ) + +[node name="HexTile3D70" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 4.5, 0, 7.794 ) + +[node name="HexTile3D71" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 0.433 ) + +[node name="HexTile3D72" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 1.299 ) + +[node name="HexTile3D73" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 2.165 ) + +[node name="HexTile3D74" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 3.031 ) + +[node name="HexTile3D75" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 3.897 ) + +[node name="HexTile3D76" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 4.763 ) + +[node name="HexTile3D77" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 5.629 ) + +[node name="HexTile3D78" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 6.495 ) + +[node name="HexTile3D79" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 7.361 ) + +[node name="HexTile3D80" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 5.25, 0, 8.227 ) + +[node name="HexTile3D81" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 0 ) + +[node name="HexTile3D82" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 0.866 ) + +[node name="HexTile3D83" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 1.732 ) + +[node name="HexTile3D84" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 2.598 ) + +[node name="HexTile3D85" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 3.464 ) + +[node name="HexTile3D86" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 4.33 ) + +[node name="HexTile3D87" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 5.196 ) + +[node name="HexTile3D88" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 6.062 ) + +[node name="HexTile3D89" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 6.928 ) + +[node name="HexTile3D90" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6, 0, 7.794 ) + +[node name="HexTile3D91" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 0.433 ) + +[node name="HexTile3D92" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 1.299 ) + +[node name="HexTile3D93" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 2.165 ) + +[node name="HexTile3D94" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 3.031 ) + +[node name="HexTile3D95" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 3.897 ) + +[node name="HexTile3D96" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 4.763 ) + +[node name="HexTile3D97" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 5.629 ) + +[node name="HexTile3D98" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 6.495 ) + +[node name="HexTile3D99" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 7.361 ) + +[node name="HexTile3D100" parent="." instance=ExtResource( 1 )] +transform = Transform( -1.62921e-07, 0, 1, 0, 1, 0, -1, 0, -1.62921e-07, 6.75, 0, 8.227 ) diff --git a/scenes/NoiseWorld.gd b/scenes/NoiseWorld.gd index 8506e35..c854847 100644 --- a/scenes/NoiseWorld.gd +++ b/scenes/NoiseWorld.gd @@ -4,7 +4,10 @@ extends Spatial var GameTile = load("res://utils/GameTile.gd") var HexCell = preload("res://addons/gdhexgrid/HexCell.gd") -onready var HexGrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() +onready var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() +onready var HexTile3D = preload("res://scenes/HexTile3D.tscn") +onready var HexTile3DPatch = preload("res://scenes/HexTile3DPatch.tscn") + var IslandGenerator = preload("res://utils/IslandGenerator.gd").new() onready var click_area = $ClckArea/CollisionShape onready var water = $Water @@ -16,15 +19,21 @@ var has_tiles_initialized = false var tile_map = {} var active_tile = null var island_count = 5 +var tick_tock_timer = 0 -export var world_size = 50 setget do_resize +export var world_size = 80 setget do_resize export var generate_flag: bool = false setget do_generate +func tick(): + tick_tock_timer = OS.get_ticks_msec() + +func tock(): + return OS.get_ticks_msec() - tick_tock_timer + func _ready(): assert(get_node("Tiles") != null) do_resize(world_size) - reset() generate() pass @@ -34,8 +43,6 @@ func _process(_delta): func do_generate(_flag): - reset() -# generate() generate_flag = false @@ -69,9 +76,18 @@ func reset(): func generate(): print ("generating world with size " + str(world_size)) + + tick() reset() + print ("Reset duration: " + str(tock() / 1000.0)) + + tick() generate_base_tiles() + print ("Generate tiles: " + str(tock() / 1000.0)) + + tick() apply_noise_as_height() + print ("Apply noise : " + str(tock() / 1000.0)) func apply_noise_as_height(): @@ -83,52 +99,64 @@ func apply_noise_as_height(): var vec1 = Vector2.ONE vec1 = vec1 * Vector2(0.5, 0.2) - for i in range (-world_size / 2, world_size / 2): - for j in range (-world_size / 2, world_size / 2): - var coord = Vector2(i,j) - var tile = tile_map[coord] - var tex_coord_normalized = (coord / world_size) * 0.5 + Vector2(0.5, 0.5) - var tex_coord = tex_coord_normalized * texture.get_size() + for coord in tile_map.keys(): + var tile = tile_map[coord] + var tex_coord_normalized = (coord / world_size) * 0.5 + Vector2(0.5, 0.5) + var tex_coord = tex_coord_normalized * texture.get_size() # -25 ... 25 -> 0 ... 1 # (coord / (size * 0.5)) * 0.5 + 0.5: -1 .. 1 - var noise_value = texture.get_data().get_pixelv(tex_coord) - tile.transform.origin.y = noise_value[0] * 5.0 - 3 + var noise_value = texture.get_data().get_pixelv(tex_coord)[0] - 0.5 +# if noise_value < 0.5: +# noise_value = noise_value * 1.5 +# else: +# noise_value = 1.0 + + if noise_value < 0.0: + tile.transform.origin.y = noise_value * 5 - 0.1 + else: + tile.transform.origin.y = noise_value * 1.0 + 0.4 + + if noise_value <= 0.1: + tile.set_tiletype(GameTile.TileType.Water) noise.unlock() func generate_base_tiles(): - for i in range (-world_size / 2, world_size / 2): - for j in range (-world_size / 2, world_size / 2): - var tile = GameTile.new() - tile.type = GameTile.TileType.Water - tile.offset_coords = Vector2(i,j) + var num_patch_tiles = world_size / 10 + var offset_z = 8.660254 + var offset_x = 7.5 + + for i in range (-num_patch_tiles / 2, num_patch_tiles / 2): + for j in range (-num_patch_tiles / 2, num_patch_tiles / 2): + var patch_tile = HexTile3DPatch.instance() + patch_tile.transform.origin = Vector3(i * offset_x, 0.0, j * offset_z) + add_child(patch_tile) - add_tile_for_hex(tile) + for child in patch_tile.get_children(): + var tile = GameTile.new() + tile.type = GameTile.TileType.Water + child.game_tile = tile + var tile_coord = hexgrid.get_hex_at(child.transform.origin).offset_coords + Vector2(i * 10, -j * 10) + tile_map[tile_coord] = child + -func add_tile_for_hex(game_tile): - var hexgrid = preload("res://addons/gdhexgrid/HexGrid.gd").new() - var HexTile3D = preload("res://scenes/HexTile3D.tscn") - var tile = HexTile3D.instance() - var pos = hexgrid.get_hex_center_from_offset(game_tile.offset_coords) - var height = -2.0 # if game_tile.type == GameTile.TileType.Sand else 0.1 + rand_range(0.0, 0.05) - - tiles.add_child(tile) - tile_map[game_tile.offset_coords] = tile - - tile.set_tiletype(game_tile.type) - tile.transform.origin = Vector3(pos.x, height, pos.y) - tile.game_tile = game_tile - - return tile +# for i in range (-world_size / 2, world_size / 2): +# for j in range (-world_size / 2, world_size / 2): +# var tile = GameTile.new() +# tile.type = GameTile.TileType.Water +# tile.offset_coords = Vector2(i,j) +# +# var game_tile = add_tile_for_hex(tile) +# print (str(i) + ", " + str(j) + ": " + str(game_tile.transform.origin)) func _on_ClckArea_input_event(_camera, _event, position, _normal, _shape_idx): - var hex_at_position = HexGrid.get_hex_at(position) + var hex_at_position = hexgrid.get_hex_at(position) var offset_coords = hex_at_position.offset_coords - var hex_center = HexGrid.get_hex_center_from_offset(offset_coords) + var hex_center = hexgrid.get_hex_center_from_offset(offset_coords) highlight.transform.origin = Vector3 (hex_center.x, 0.0, hex_center.y) var world_tile = null