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)
|
|
|
|
var layer0 = original_mat.duplicate()
|
|
|
|
var layer1 = preload("control_target_overlay.material").duplicate()
|
|
|
|
# Non-occlused
|
|
|
|
var layer2 = original_mat.duplicate()
|
|
|
|
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
|
|
|
|
layer0.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA_DEPTH_PRE_PASS
|
|
|
|
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
|
|
|
|
mesh.set_surface_override_material(i, layer2)
|
|
|
|
layer2.transparency = BaseMaterial3D.TRANSPARENCY_DISABLED
|
|
|
|
layer2.depth_draw_mode = BaseMaterial3D.DEPTH_DRAW_OPAQUE_ONLY
|