76 lines
2.6 KiB
GDScript
76 lines
2.6 KiB
GDScript
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")
|
|
|
|
func get_billiard() -> Billiard:
|
|
return get_parent()
|
|
|
|
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)
|
|
|
|
func walk_meshes_post_order(parent: Node, f: Callable):
|
|
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)
|
|
var layer0: BaseMaterial3D = original_mat.duplicate()
|
|
var layer1: ShaderMaterial = preload("control_target_overlay.material").duplicate()
|
|
# Non-occlused
|
|
var layer2: BaseMaterial3D = original_mat.duplicate()
|
|
layer0.next_pass = layer1
|
|
layer1.next_pass = layer2
|
|
|
|
layer0.render_priority = 10
|
|
layer1.render_priority = 20
|
|
layer2.render_priority = 30
|
|
|
|
layer0.no_depth_test = true
|
|
layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_HASH
|
|
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)
|
|
var layer2: StandardMaterial3D = mat.next_pass.next_pass
|
|
layer2.transparency = BaseMaterial3D.TRANSPARENCY_DISABLED
|
|
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_OPAQUE_ONLY
|
|
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)
|
|
|