From 0bd4924cfee789ad2b0d0ecd73e63a970295b70a Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 13 May 2023 09:29:54 +0200 Subject: [PATCH] WIP: fix for Colortexture and Heightmap mismatch --- materials/shader/HexToTexture.gdshader | 2 +- project.godot | 8 ++++---- scenes/Game.cs | 3 ++- scenes/StreamContainer.cs | 16 ++++++++++++++++ scenes/TileWorld.cs | 13 ++++--------- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/materials/shader/HexToTexture.gdshader b/materials/shader/HexToTexture.gdshader index cc8b655..4e9bd65 100644 --- a/materials/shader/HexToTexture.gdshader +++ b/materials/shader/HexToTexture.gdshader @@ -45,7 +45,7 @@ void vertex() { // Output:0 map_coord = origin.xz * 1. / float(TextureSize); - map_coord = axial_to_offset(axial_coords.xy) / float(TextureSize); + map_coord = axial_to_offset(axial_coords.xy) / float(TextureSize) - vec2(0.5); } void fragment() { diff --git a/project.godot b/project.godot index bd0be60..afb22bb 100644 --- a/project.godot +++ b/project.godot @@ -9,17 +9,17 @@ config_version=4 _global_script_classes=[ { -"base": "Node", +"base": "Reference", "class": "ClickableComponent", "language": "GDScript", "path": "res://components/ClickableComponent.gd" }, { -"base": "KinematicBody2D", +"base": "Reference", "class": "CollisionLine", "language": "GDScript", "path": "res://utils/CollisionLine.gd" }, { -"base": "Node", +"base": "Reference", "class": "ColorComponent", "language": "GDScript", "path": "res://components/ColorComponent.gd" @@ -54,7 +54,7 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://utils/SpringDamper.gd" }, { -"base": "Sprite", +"base": "Reference", "class": "TintedSpriteComponent", "language": "GDScript", "path": "res://components/TintedSpriteComponent.gd" diff --git a/scenes/Game.cs b/scenes/Game.cs index 6d1bb51..a86eeb8 100644 --- a/scenes/Game.cs +++ b/scenes/Game.cs @@ -253,6 +253,7 @@ public class Game : Spatial _tileMaterial.SetShaderParam("MapAlbedoTexture", new_world_texture); _tileMaterial.SetShaderParam("TextureSize", (int)_tileWorld.Colormap.GetSize().x); - _streamContainer.SetTileMaterial(_tileMaterial); + _streamContainer.OnWorldGenerated(); + //_streamContainer.SetTileMaterial(_tileMaterial); } } \ No newline at end of file diff --git a/scenes/StreamContainer.cs b/scenes/StreamContainer.cs index ebd5325..461ed30 100644 --- a/scenes/StreamContainer.cs +++ b/scenes/StreamContainer.cs @@ -235,4 +235,20 @@ public class StreamContainer : Spatial GD.Print("Hovered on Tile at " + tile.OffsetCoords); EmitSignal("TileHovered", tile); } + + public void OnWorldGenerated() + { + foreach (Spatial node in _activeTiles.GetChildren()) + { + HexTile3D tile = (HexTile3D)node; + if (tile == null) + { + continue; + } + + Transform tileTransform = tile.GlobalTransform; + tileTransform.origin.y = _tileWorld.GetHeightAtOffset(tile.OffsetCoords); + tile.GlobalTransform = tileTransform; + } + } } \ No newline at end of file diff --git a/scenes/TileWorld.cs b/scenes/TileWorld.cs index 5f9b4b2..0f575ef 100644 --- a/scenes/TileWorld.cs +++ b/scenes/TileWorld.cs @@ -14,7 +14,7 @@ public class TileWorld : Spatial delegate void WorldGenerated(); // public members - public Vector2 Size = new Vector2(100, 100); + public Vector2 Size = new Vector2(10, 10); public float HeightScale = 2; public Image Heightmap; public Image Colormap; @@ -45,7 +45,7 @@ public class TileWorld : Spatial public void Generate() { - GenerateSimpleMap(); + //GenerateSimpleMap(); // GenerateNoiseMap(); GenerateNoiseColorMap(); @@ -103,7 +103,7 @@ public class TileWorld : Spatial noise_generator.Lacunarity = 4; ImageTexture imageTexture = new ImageTexture(); - Heightmap.Unlock(); + //Heightmap.Unlock(); Heightmap = noise_generator.GetSeamlessImage((int)Size.x); imageTexture.CreateFromImage(Heightmap); imageTexture.Flags = 0; @@ -112,12 +112,7 @@ public class TileWorld : Spatial Heightmap.Lock(); } - - private void ApplyHeightMap() - { - - } - + public bool IsOffsetCoordValid(Vector2 offset_coord) { return ((int)Math.Clamp(offset_coord.x, -Size.x / 2, Size.x / 2 - 1) == (int)offset_coord.x