Tree collisions and highlights
This commit is contained in:
parent
57602adddb
commit
7255cbdf64
17 changed files with 231 additions and 2251 deletions
89
Entities/Tree/scripts/tree.gd
Normal file
89
Entities/Tree/scripts/tree.gd
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
class_name TreeNode
|
||||
extends Node3D
|
||||
|
||||
@onready var area: Area3D = $InteractRange
|
||||
var mesh_instances: Array[MeshInstance3D] = []
|
||||
var original_materials: Array[Material] = []
|
||||
var outline_material: Material
|
||||
var base_circle: MeshInstance3D
|
||||
var circle_material: Material
|
||||
|
||||
func _ready():
|
||||
create_base_circle()
|
||||
# Find all MeshInstance3D nodes in the GLB
|
||||
find_all_mesh_instances(self)
|
||||
|
||||
setup_outline_material()
|
||||
area.body_entered.connect(_on_player_entered)
|
||||
area.body_exited.connect(_on_player_exited)
|
||||
|
||||
func setup_outline_material():
|
||||
if mesh_instances.is_empty():
|
||||
print("Warning: No MeshInstance3D found in GLB!")
|
||||
return
|
||||
|
||||
# Store original materials
|
||||
for mesh in mesh_instances:
|
||||
if mesh.get_surface_override_material(0):
|
||||
original_materials.append(mesh.get_surface_override_material(0))
|
||||
else:
|
||||
original_materials.append(mesh.get_surface_override_material(0))
|
||||
# Create outline material with your shader
|
||||
outline_material = ShaderMaterial.new()
|
||||
outline_material.shader = preload("res://outline.gdshader")
|
||||
outline_material.set_shader_parameter("color", Vector3(0.702, 0.557, 0.259))
|
||||
|
||||
func find_all_mesh_instances(node: Node):
|
||||
if node is MeshInstance3D:
|
||||
mesh_instances.append(node)
|
||||
|
||||
for child in node.get_children():
|
||||
find_all_mesh_instances(child)
|
||||
|
||||
func create_base_circle():
|
||||
base_circle = MeshInstance3D.new()
|
||||
add_child(base_circle)
|
||||
|
||||
# Create a flat cylinder for the circle
|
||||
var cylinder = CylinderMesh.new()
|
||||
cylinder.top_radius = 0.4 # Adjust size as needed
|
||||
cylinder.bottom_radius = 0.4
|
||||
cylinder.height = 0.02 # Very thin to make it look like a flat circle
|
||||
cylinder.rings = 1
|
||||
cylinder.radial_segments = 9 # More segments = smoother circle
|
||||
|
||||
base_circle.mesh = cylinder
|
||||
|
||||
# Create transparent material with outline
|
||||
circle_material = StandardMaterial3D.new()
|
||||
circle_material.flags_transparent = true
|
||||
circle_material.albedo_color = Color(1.0, 0.843, 0.0, 0.0) # Fully transparent gold
|
||||
|
||||
# Add rim lighting effect for outline appearance
|
||||
circle_material.rim_enabled = true
|
||||
circle_material.rim = 1.0
|
||||
circle_material.rim_tint = 1.0
|
||||
circle_material.rim_color = Color(1.0, 0.843, 0.0) # Gold rim
|
||||
|
||||
base_circle.material_override = circle_material
|
||||
|
||||
# Position at ground level
|
||||
base_circle.position.y = 0.01 # Slightly above ground to avoid z-fighting
|
||||
|
||||
# Start hidden
|
||||
base_circle.visible = false
|
||||
|
||||
func _on_player_entered(body: Node3D):
|
||||
if body.is_in_group("player"):
|
||||
base_circle.visible = true
|
||||
# Apply outline to all mesh instances
|
||||
for mesh in mesh_instances:
|
||||
mesh.material_overlay = outline_material
|
||||
|
||||
func _on_player_exited(body: Node3D):
|
||||
if body.is_in_group("player"):
|
||||
Log.pr('Out of range...')
|
||||
base_circle.visible = false
|
||||
# Remove outline from all mesh instances
|
||||
for mesh in mesh_instances:
|
||||
mesh.material_overlay = null
|
||||
Loading…
Add table
Add a link
Reference in a new issue