Colours and practise dummy

This commit is contained in:
Twirpytherobot
2025-11-29 18:10:23 +00:00
parent ddc1522174
commit fab47fb1e0
11 changed files with 467 additions and 37 deletions
+43
View File
@@ -65,3 +65,46 @@ func play_attack(anim_name: String = "Attack_OneHand") -> void:
#push_warning("Animation '%s' not found, using Attack_OneHand" % anim_name)
animation_player.play("Attack_OneHand", -1, 1.0)
animation_player.animation_set_next("Attack_OneHand", "")
## Apply hue shift to all mesh instances in the character
func set_character_color(hue_shift: float) -> void:
# Find all MeshInstance3D children recursively
var mesh_instances = _find_mesh_instances(self)
for mesh in mesh_instances:
_apply_hue_to_mesh(mesh, hue_shift)
## Recursively find all MeshInstance3D nodes
func _find_mesh_instances(node: Node) -> Array[MeshInstance3D]:
var meshes: Array[MeshInstance3D] = []
if node is MeshInstance3D:
meshes.append(node)
for child in node.get_children():
meshes.append_array(_find_mesh_instances(child))
return meshes
## Apply hue shift to a mesh instance
func _apply_hue_to_mesh(mesh_instance: MeshInstance3D, hue_shift: float) -> void:
if not mesh_instance:
return
# Get or create material for each surface
for i in range(mesh_instance.get_surface_override_material_count()):
var material = mesh_instance.get_surface_override_material(i)
# If no override material, get the base material and duplicate it
if not material:
material = mesh_instance.mesh.surface_get_material(i)
if material:
material = material.duplicate()
mesh_instance.set_surface_override_material(i, material)
# Apply hue shift if it's a StandardMaterial3D
if material and material is StandardMaterial3D:
var std_mat = material as StandardMaterial3D
# Create a modulate color from hue
var color = Color.from_hsv(hue_shift, 0.6, 1.0)
std_mat.albedo_color = color