57 lines
1.8 KiB
GDScript
57 lines
1.8 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 = 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
|
|
|
|
layer0.render_priority = 10
|
|
layer1.render_priority = 20
|
|
layer2.render_priority = 30
|
|
|
|
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)
|
|
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
|