extends RefCounted const ALTERNATE_TEXTURES := [ preload("res://assets/blocks/ice/textures/top_albedo_diagonal.png"), preload("res://assets/blocks/ice/textures/top_albedo_forked.png"), ] const TOP_MATERIAL := "Storybook / ice top" static var overrides: Dictionary[Texture2D, StandardMaterial3D] = {} static func apply(visual: Node3D, location: Vector3) -> void: # X/Z grid neighbors differ by one or two steps in the three-pattern cycle. var pattern := posmod(roundi(location.x) + 2 * roundi(location.z), 3) if pattern == 0: return var texture: Texture2D = ALTERNATE_TEXTURES[pattern - 1] for node in visual.find_children("*", "MeshInstance3D", true, false): var mesh_view := node as MeshInstance3D for index in range(mesh_view.mesh.get_surface_count()): var source := mesh_view.mesh.surface_get_material(index) as StandardMaterial3D if source != null and source.resource_name == TOP_MATERIAL: if not overrides.has(texture): var material := source.duplicate() as StandardMaterial3D material.albedo_texture = texture overrides[texture] = material mesh_view.set_surface_override_material(index, overrides[texture]) return