hurrmmm/godot/control_scheme/is_targetable.gd

76 lines
2.6 KiB
GDScript3
Raw Normal View History

2023-11-11 13:08:24 -07:00
extends Node3D
class_name Targetable
@export var attached_to: Node3D = owner
static func is_targetable(node: Node3D) -> Targetable:
return node.get_node_or_null("is_targetable")
2023-11-11 17:24:52 -07:00
func get_billiard() -> Billiard:
return get_parent()
2023-11-11 13:08:24 -07:00
func make_target():
walk_meshes_post_order(self.get_parent(), change_all_materials)
func unmake_target():
walk_meshes_post_order(self.get_parent(), unchange_all_materials)
2023-11-11 14:47:07 -07:00
func walk_meshes_post_order(parent: Node, f: Callable):
2023-11-11 13:08:24 -07:00
for child in parent.get_children():
walk_meshes_post_order(child, f)
if parent is MeshInstance3D:
f.call(parent)
func change_all_materials(mesh: MeshInstance3D):
for i in range(mesh.get_surface_override_material_count()):
var original_mat: BaseMaterial3D = mesh.get_active_material(i)
2023-11-12 13:52:55 -07:00
var layer0: BaseMaterial3D = original_mat.duplicate()
var layer1: ShaderMaterial = preload("control_target_overlay.material").duplicate()
2023-11-11 13:08:24 -07:00
# Non-occlused
2023-11-12 13:52:55 -07:00
var layer2: BaseMaterial3D = original_mat.duplicate()
2023-11-11 13:08:24 -07:00
layer0.next_pass = layer1
layer1.next_pass = layer2
2023-11-11 14:56:43 -07:00
layer0.render_priority = 10
layer1.render_priority = 20
layer2.render_priority = 30
2023-11-11 13:08:24 -07:00
layer0.no_depth_test = true
2023-11-12 01:42:51 -07:00
layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_HASH
2023-11-11 13:08:24 -07:00
layer0.grow = true
layer0.grow_amount = -0.001
layer0.albedo_color = layer0.albedo_color.darkened(0.5)
layer2.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_ALWAYS
mesh.set_surface_override_material(i, layer0)
func unchange_all_materials(mesh: MeshInstance3D):
for i in range(mesh.get_surface_override_material_count()):
var mat := mesh.get_active_material(i)
2023-11-11 20:45:57 -07:00
var layer2: StandardMaterial3D = mat.next_pass.next_pass
layer2.transparency = BaseMaterial3D.TRANSPARENCY_DISABLED
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_OPAQUE_ONLY
2023-11-12 13:52:55 -07:00
layer2.emission_enabled = false
layer2.emission = Color(1.0, 1.0, 1.0)
mesh.set_surface_override_material(i, layer2.duplicate())
func set_strobe(color: float):
walk_meshes_post_order(self.get_parent(), set_mesh_strobe.bind(color))
func set_mesh_strobe(mesh: MeshInstance3D, color: float):
for i in range(mesh.get_surface_override_material_count()):
var mat := mesh.get_active_material(i)
var layer0: BaseMaterial3D = mat
var layer1: ShaderMaterial = mat.next_pass
var layer2: BaseMaterial3D = mat.next_pass.next_pass
layer0.emission_enabled = true
layer2.emission_enabled = true
layer0.emission_energy_multiplier = color
layer2.emission_energy_multiplier = color
layer0.emission = Color(1.0, 0.0, 0.0)
layer2.emission = Color(1.0, 0.0, 0.0)