From df071af39c2a6c9e488e7ee3cdb571c40af23a51 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 13 Feb 2022 15:52:19 +0100 Subject: [PATCH] Now the dungeon teleporters switch between 2 materials for hover / normal states. This way only the hovered one will light up, instead of all. Also reworked them to use mesh data resources. --- .../dungeon/simple_dungeon_teleporter.tres | 5 ++++ .../simple_dungeon_back_teleporter.tscn | 22 ++++++++---------- .../dungeon/simple_dungeon_teleporter.tscn | 23 ++++++++----------- ...dungeon_teleporter_highlight_material.tres | 9 ++++++++ .../simple_dungeon_teleporter_material.tres | 9 ++++++++ .../teleporters/dung_back_teleporter.gd | 16 ++++++------- .../dungeons/teleporters/dung_teleporter.gd | 17 +++++++------- 7 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 game/models/teleporters/dungeon/simple_dungeon_teleporter.tres create mode 100644 game/props/teleporters/dungeon/simple_dungeon_teleporter_highlight_material.tres create mode 100644 game/props/teleporters/dungeon/simple_dungeon_teleporter_material.tres diff --git a/game/models/teleporters/dungeon/simple_dungeon_teleporter.tres b/game/models/teleporters/dungeon/simple_dungeon_teleporter.tres new file mode 100644 index 00000000..a9e5b36c --- /dev/null +++ b/game/models/teleporters/dungeon/simple_dungeon_teleporter.tres @@ -0,0 +1,5 @@ +[gd_resource type="MeshDataResource" format=2] + +[resource] +array = [ PoolVector3Array( -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, 0.5, -0.5, -0.5, 0.5, -0.5, -0.5, -0.5, 0.5, -0.5, -0.5, 0.5, -0.5, 0.5 ), PoolVector3Array( 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0 ), null, null, PoolVector2Array( 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1 ), null, null, null, PoolIntArray( 0, 1, 2, 2, 3, 0, 4, 6, 5, 4, 7, 6, 8, 9, 10, 10, 11, 8, 12, 14, 13, 12, 15, 14, 16, 17, 18, 18, 19, 16, 20, 22, 21, 20, 23, 22 ) ] +aabb = AABB( -0.5, -0.5, -0.5, 1, 1, 1 ) diff --git a/game/props/teleporters/dungeon/simple_dungeon_back_teleporter.tscn b/game/props/teleporters/dungeon/simple_dungeon_back_teleporter.tscn index cc5bb37f..77a9bdea 100644 --- a/game/props/teleporters/dungeon/simple_dungeon_back_teleporter.tscn +++ b/game/props/teleporters/dungeon/simple_dungeon_back_teleporter.tscn @@ -1,25 +1,23 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://scripts/dungeons/teleporters/dung_back_teleporter.gd" type="Script" id=1] [ext_resource path="res://textures/bricks/test_brick_albedo.png" type="Texture" id=2] - -[sub_resource type="CubeMesh" id=1] -size = Vector3( 1, 1, 1 ) - -[sub_resource type="SpatialMaterial" id=2] -flags_vertex_lighting = true -albedo_color = Color( 0.494118, 0.494118, 0.494118, 1 ) -albedo_texture = ExtResource( 2 ) +[ext_resource path="res://props/teleporters/dungeon/simple_dungeon_teleporter_material.tres" type="Material" id=3] +[ext_resource path="res://props/teleporters/dungeon/simple_dungeon_teleporter_highlight_material.tres" type="Material" id=4] +[ext_resource path="res://models/teleporters/dungeon/simple_dungeon_teleporter.tres" type="MeshDataResource" id=5] [sub_resource type="BoxShape" id=3] extents = Vector3( 0.5, 0.5, 0.5 ) [node name="DungeonBackTeleporter" type="StaticBody"] script = ExtResource( 1 ) +default_material = ExtResource( 3 ) +hover_material = ExtResource( 4 ) -[node name="MeshInstance" type="MeshInstance" parent="."] -mesh = SubResource( 1 ) -material/0 = SubResource( 2 ) +[node name="MeshDataInstance" type="MeshDataInstance" parent="."] +mesh_data = ExtResource( 5 ) +texture = ExtResource( 2 ) +material = ExtResource( 3 ) [node name="CollisionShape" type="CollisionShape" parent="."] shape = SubResource( 3 ) diff --git a/game/props/teleporters/dungeon/simple_dungeon_teleporter.tscn b/game/props/teleporters/dungeon/simple_dungeon_teleporter.tscn index dead92bb..4ef1dde5 100644 --- a/game/props/teleporters/dungeon/simple_dungeon_teleporter.tscn +++ b/game/props/teleporters/dungeon/simple_dungeon_teleporter.tscn @@ -1,28 +1,25 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://scripts/dungeons/teleporters/dung_teleporter.gd" type="Script" id=1] [ext_resource path="res://props/teleporters/dungeon/simple_dungeon_back_teleporter.tscn" type="PackedScene" id=2] +[ext_resource path="res://models/teleporters/dungeon/simple_dungeon_teleporter.tres" type="MeshDataResource" id=3] [ext_resource path="res://textures/bricks/test_brick_albedo.png" type="Texture" id=4] - -[sub_resource type="CubeMesh" id=1] -size = Vector3( 1, 1, 1 ) - -[sub_resource type="SpatialMaterial" id=2] -flags_vertex_lighting = true -albedo_color = Color( 0.494118, 0.494118, 0.494118, 1 ) -albedo_texture = ExtResource( 4 ) +[ext_resource path="res://props/teleporters/dungeon/simple_dungeon_teleporter_material.tres" type="Material" id=5] +[ext_resource path="res://props/teleporters/dungeon/simple_dungeon_teleporter_highlight_material.tres" type="Material" id=6] [sub_resource type="BoxShape" id=3] extents = Vector3( 0.5, 0.5, 0.5 ) [node name="DungeonTeleporter" type="StaticBody"] script = ExtResource( 1 ) -default_albedo = Color( 0.521569, 0.521569, 0.521569, 1 ) +default_material = ExtResource( 5 ) +hover_material = ExtResource( 6 ) dungeon_back_teleporter = ExtResource( 2 ) -[node name="MeshInstance" type="MeshInstance" parent="."] -mesh = SubResource( 1 ) -material/0 = SubResource( 2 ) +[node name="MeshDataInstance" type="MeshDataInstance" parent="."] +mesh_data = ExtResource( 3 ) +texture = ExtResource( 4 ) +material = ExtResource( 5 ) [node name="CollisionShape" type="CollisionShape" parent="."] shape = SubResource( 3 ) diff --git a/game/props/teleporters/dungeon/simple_dungeon_teleporter_highlight_material.tres b/game/props/teleporters/dungeon/simple_dungeon_teleporter_highlight_material.tres new file mode 100644 index 00000000..77182988 --- /dev/null +++ b/game/props/teleporters/dungeon/simple_dungeon_teleporter_highlight_material.tres @@ -0,0 +1,9 @@ +[gd_resource type="ShaderMaterial" load_steps=3 format=2] + +[ext_resource path="res://shaders/5_standard_shader_nouv2.tres" type="Shader" id=1] +[ext_resource path="res://textures/bricks/test_brick_albedo.png" type="Texture" id=2] + +[resource] +shader = ExtResource( 1 ) +shader_param/albedo = Color( 0.65098, 0.65098, 0.65098, 1 ) +shader_param/texture_albedo = ExtResource( 2 ) diff --git a/game/props/teleporters/dungeon/simple_dungeon_teleporter_material.tres b/game/props/teleporters/dungeon/simple_dungeon_teleporter_material.tres new file mode 100644 index 00000000..c71791b4 --- /dev/null +++ b/game/props/teleporters/dungeon/simple_dungeon_teleporter_material.tres @@ -0,0 +1,9 @@ +[gd_resource type="ShaderMaterial" load_steps=3 format=2] + +[ext_resource path="res://shaders/5_standard_shader_nouv2.tres" type="Shader" id=1] +[ext_resource path="res://textures/bricks/test_brick_albedo.png" type="Texture" id=2] + +[resource] +shader = ExtResource( 1 ) +shader_param/albedo = Color( 0.521569, 0.521569, 0.521569, 1 ) +shader_param/texture_albedo = ExtResource( 2 ) diff --git a/game/scripts/dungeons/teleporters/dung_back_teleporter.gd b/game/scripts/dungeons/teleporters/dung_back_teleporter.gd index 927f507d..e7c8d6ba 100644 --- a/game/scripts/dungeons/teleporters/dung_back_teleporter.gd +++ b/game/scripts/dungeons/teleporters/dung_back_teleporter.gd @@ -1,7 +1,7 @@ extends StaticBody -export(Color) var default_albedo : Color = Color(0.494118, 0.494118, 0.494118) -export(Color) var hover_albedo : Color = Color(0.65098, 0.65098, 0.65098) +export(Material) var default_material : Material = null +export(Material) var hover_material : Material = null export(float) var use_range : float = 5 var _dungeon : Spatial = null @@ -17,20 +17,20 @@ func _ready(): connect("mouse_entered", self, "on_mouse_entered") connect("mouse_exited", self, "on_mouse_exited") - var mat = $MeshInstance.get_surface_material(0) - mat.albedo_color = default_albedo + if default_material: + $MeshDataInstance.material = default_material func on_mouse_entered(): - var mat = $MeshInstance.get_surface_material(0) - mat.albedo_color = hover_albedo + if hover_material: + $MeshDataInstance.material = hover_material Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND) _mouse_hover = true func on_mouse_exited(): - var mat = $MeshInstance.get_surface_material(0) - mat.albedo_color = default_albedo + if default_material: + $MeshDataInstance.material = default_material Input.set_default_cursor_shape(Input.CURSOR_ARROW) diff --git a/game/scripts/dungeons/teleporters/dung_teleporter.gd b/game/scripts/dungeons/teleporters/dung_teleporter.gd index 2618acd6..ddadf1b5 100644 --- a/game/scripts/dungeons/teleporters/dung_teleporter.gd +++ b/game/scripts/dungeons/teleporters/dung_teleporter.gd @@ -1,7 +1,8 @@ extends StaticBody -export(Color) var default_albedo : Color = Color(0.494118, 0.494118, 0.494118) -export(Color) var hover_albedo : Color = Color(0.65098, 0.65098, 0.65098) +export(Material) var default_material : Material = null +export(Material) var hover_material : Material = null + export(float) var use_range : float = 5 export(PackedScene) var dungeon : PackedScene @@ -29,20 +30,20 @@ func _ready(): connect("mouse_entered", self, "on_mouse_entered") connect("mouse_exited", self, "on_mouse_exited") - var mat = $MeshInstance.get_surface_material(0) - mat.albedo_color = default_albedo + if default_material: + $MeshDataInstance.material = default_material func on_mouse_entered(): - var mat = $MeshInstance.get_surface_material(0) - mat.albedo_color = hover_albedo + if hover_material: + $MeshDataInstance.material = hover_material Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND) _mouse_hover = true func on_mouse_exited(): - var mat = $MeshInstance.get_surface_material(0) - mat.albedo_color = default_albedo + if default_material: + $MeshDataInstance.material = default_material Input.set_default_cursor_shape(Input.CURSOR_ARROW)