I want to make a mesh preview. I created a function that returns a texture for a button with TextureRect, but it returns a gdscript function state.
func render_thumbnail(_mesh, size, screen):
var new_viewport = viewport.instance()
new_viewport.size = screen
add_child(new_viewport)
var camera = new_viewport.find_node("Camera")
camera.size = size
if _mesh:
var mesh = new_viewport.find_node("Mesh")
mesh.set_mesh(_mesh)
var thumbnail = ImageTexture.new()
for a in 2: yield(get_tree(), "idle_frame")
var image = new_viewport.get_texture().get_data()
thumbnail.create_from_image(image)
new_viewport.queue_free()
return thumbnail
It seems to me that this is due to yield (), but I do not know how to fix this or how to replace it...