From 8d014d69a9471c6fdc0fd99116c95fb08d0392fe Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 1 Feb 2023 00:11:14 +0000 Subject: [PATCH] Fix InteriorMap not hiding its multi-mesh instances when hidden --- interior/interior_map.gd | 29 ++++++++++++++++++++--------- map_editor.scn | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/interior/interior_map.gd b/interior/interior_map.gd index f3d9758..0d32504 100644 --- a/interior/interior_map.gd +++ b/interior/interior_map.gd @@ -41,9 +41,9 @@ class Chunk: ## func invalidate(interior_map: InteriorMap, coordinate: Vector2i) -> void: # TODO: Once this is all lowered into native code, look for ways to parallelize the loops. - for multimesh_instance in _multimesh_instances: - RenderingServer.free_rid(multimesh_instance._instance_rid) - RenderingServer.free_rid(multimesh_instance._multimesh_rid) + for multi_mesh_instance in _multimesh_instances: + RenderingServer.free_rid(multi_mesh_instance._instance_rid) + RenderingServer.free_rid(multi_mesh_instance._multimesh_rid) _multimesh_instances.clear() @@ -85,11 +85,11 @@ class Chunk: var global_transform := interior_map.global_transform for chunk_mesh in transforms_by_mesh: - var multimesh_instance := MultiMeshInstance.new( + var multi_mesh_instance := MultiMeshInstance.new( scenario_rid, chunk_mesh.get_rid(), transforms_by_mesh[chunk_mesh]) - multimesh_instance.set_offset(global_transform) - _multimesh_instances.append(multimesh_instance) + multi_mesh_instance.set_offset(global_transform) + _multimesh_instances.append(multi_mesh_instance) ## ## Sets the floor mesh in the chunk at the location relative [code]coordinatess[/code] to @@ -140,11 +140,17 @@ class MultiMeshInstance: RenderingServer.multimesh_instance_set_transform(_multimesh_rid, i, transforms[i]) ## - ## Sets the parent transform of all mesh instances under it to [code]offset[/code]. + ## Sets the transform of the instance to [code]offset[/code]. ## func set_offset(offset: Transform3D) -> void: RenderingServer.instance_set_transform(_instance_rid, offset) + ## + ## Sets the visibility of the instance to [code]is_visible[/code]. + ## + func set_visible(is_visible: bool) -> void: + RenderingServer.instance_set_visible(_instance_rid, is_visible) + var _chunks: Array[Chunk] = [] var _chunks_size := Vector2i.ZERO @@ -172,8 +178,13 @@ func _notification(what: int) -> void: match what: NOTIFICATION_TRANSFORM_CHANGED: for chunk in _chunks: - for multimesh_instance in chunk._multimesh_instances: - multimesh_instance.set_offset_transform(global_transform) + for multi_mesh_instance in chunk._multimesh_instances: + multi_mesh_instance.set_offset_transform(global_transform) + + NOTIFICATION_VISIBILITY_CHANGED: + for chunk in _chunks: + for multi_mesh_instance in chunk._multimesh_instances: + multi_mesh_instance.set_visible(visible) ## ## Clears the entirety of the tile grid to only contain tiles of instance [code]tile[/code] pointing diff --git a/map_editor.scn b/map_editor.scn index a2f3041..3540e8e 100644 --- a/map_editor.scn +++ b/map_editor.scn @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7fe7f05f0ecf9b18338fc90e47b3d25fb54d22e8ec15b610358228e203a80b10 -size 13275 +oid sha256:021482d14d5f8718d812861f27ffc883b19ae1561b78bd9589ecd8483019aff6 +size 13278