Godot Version
4.2
Question
- Hi all. I’m stuck in a point where I’m trying to procedurally generate a texture via gdscript (godot 4.2), but I keep getting pink textures. Here are the main parts of the code:
@export var texture_dimensions: Vector2 = Vector2(100, 100)
…code that generates hexagons (works)
…apply textures:
func generate_voronoi_texture(polygon: Polygon2D):
var voronoi_texture = Image.new()
voronoi_texture.create(int(texture_dimensions.x), int(texture_dimensions.y), false, Image.FORMAT_RGBA8)
print ("texture dimensions: ", texture_dimensions)var points: Array[Vector2] = [] var new_voronoi_regions = randomize_in_range(voronoi_regions, region_min_bias, region_max_bias) for i in range(new_voronoi_regions): points.append(Vector2(randi_range(0, int(texture_dimensions.x)), randi_range(0, int(texture_dimensions.y)))) for i in range(int(texture_dimensions.x)): for j in range(int(texture_dimensions.y)): var nearest_point_index = 0 var nearest_distance = INF for k in range(points.size()): var distance = points[k].distance_to(Vector2(i, j)) if distance < nearest_distance: nearest_distance = distance nearest_point_index = k var color = Color.from_hsv(nearest_point_index / float(new_voronoi_regions), 1, 1) voronoi_texture.set_pixel(i, j, color) voronoi_texture.generate_mipmaps() var texture = ImageTexture.new() texture.create_from_image(voronoi_texture) polygon.texture = texture
==> result, textures are pink (edited)