From 2031a8b9d2bf568f538cc9223713f50c77bac897 Mon Sep 17 00:00:00 2001 From: nokoe Date: Thu, 26 Sep 2024 19:38:58 +0200 Subject: floor as one mesh --- client/map/map.gd | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'client/map/map.gd') diff --git a/client/map/map.gd b/client/map/map.gd index ce3c6dfa..40451c57 100644 --- a/client/map/map.gd +++ b/client/map/map.gd @@ -21,6 +21,8 @@ extends Node3D var tile_by_pos: Dictionary = {} var autobake = false var currently_baked = false +var floor_mesher := FloorMesher.new() +var floor_node := MeshInstance3D.new() func get_tile_name(pos: Vector2i): var e = tile_by_pos.get(str(pos)) @@ -32,11 +34,10 @@ func get_tile_instance(pos: Vector2i) -> Tile: else: return null func set_tile(pos: Vector2i, name_: String, neighbors: Array = [null,null,null,null]) -> Tile: - var tile = TileFactory.produce(name_, str(pos), neighbors) + var tile = TileFactory.produce(name_, pos, neighbors, floor_mesher) add_child(tile) tile.position = Vector3(pos.x, 0, pos.y) tile_by_pos[str(pos)] = [pos, name_, tile, neighbors] - if autobake: voxelgi_timer.start(1) return tile func clear_tile(pos: Vector2i): @@ -47,12 +48,16 @@ func clear_tile(pos: Vector2i): tile.name += "_queued_free" tile.queue_free() -@onready var voxelgi_timer: Timer = $Timer @onready var voxelgi: VoxelGI = $VoxelGI func _ready(): - voxelgi_timer.connect("timeout", gi_bake) Settings.hook_changed("graphics.gi", false, apply_gi_setting) + floor_node.material_override = preload("res://map/tiles/floor_material.tres") + add_child(floor_node) + +func flush() -> void: + floor_node.mesh = floor_mesher.flush() + gi_bake() func apply_gi_setting(state): if state == "voxelgi" and not currently_baked: @@ -61,7 +66,6 @@ func apply_gi_setting(state): currently_baked = false voxelgi.data = null - func gi_bake(): if Global.get_setting("graphics.gi") != "voxelgi": return print("Map: Rebaking VoxelGI") -- cgit v1.2.3-70-g09d2