So attempting to make a cleaning system similar to viscera cleanup detail/power wash sim though the difference from power wash sim is i want to utilize a mop you hold and then hit the 3D objects that have dirt on them to clean them. I've found some tutorials that do something close but it's on a 2D surface and fails when i map it on just a simple cube. I'm thinking how i go about calculating the UVs
The code i've been putting on my "dirty" object is this, but not sure this is correct
`extends MeshInstance3D
@export var dirt_mask_size: int = 1024 # Resolution of the dirt mask
var mask_image: Image
var dirt_mask: ImageTexture
func _ready():
Create a white mask (fully dirty)
mask_image = Image.new() # This should be created with the size of your dirt mask texture
mask_image = Image.create(dirt_mask_size, dirt_mask_size, false, Image.FORMAT_L8)
mask_image.fill(Color(1, 1, 1)) # White = Full Dirt
# Create texture from the mask
dirt_mask = ImageTexture.new()
dirt_mask = ImageTexture.create_from_image(mask_image)
#sets our dirt_mask from our shader to the dirt_mask we just made
var override_material: ShaderMaterial = get_surface_override_material(0)
override_material.set_shader_parameter('dirt_mask', dirt_mask)
#Called by the mop to remove dirt
func clean_surface(brush_position: Vector3, radius: int = 20):
print("Cleaning at position:", brush_position)
var local_pos = to_local(brush_position)
# Convert world position to UV space
var uv_x = int((local_pos.x ) * dirt_mask_size)
var uv_y = int((local_pos.y ) * dirt_mask_size)
for x in range(-radius, radius):
for y in range(-radius, radius):
var px = uv_x + x
var py = uv_y + y
if px >= 0 and px < dirt_mask_size and py >= 0 and py < dirt_mask_size:
mask_image.set_pixel(px, py, Color(0, 0, 0))
# Update dirt mask texture
dirt_mask.update(mask_image)
# Apply the updated mask
var mat: ShaderMaterial = get_surface_override_material(0)
if mat:
mat.set_shader_parameter("dirt_mask", dirt_mask)`