breadwinner/scenes/grabbable_base/grabbable_base.gd
Hellie-xd b8c233f21f autoloader fix and grabbable base added
title says all, and yeah
2026-08-05 01:31:20 +02:00

27 lines
905 B
GDScript

extends RigidBody3D
@onready var viewport = %SubViewport
@onready var mesh_instance = %GrabbableBaseMesh
func create_icon_from_mesh(target_mesh: Mesh) -> Texture2D:
# 1. Put the grabbable item's mesh into our hidden photo booth
mesh_instance.mesh = target_mesh
# 2. Tell the viewport it needs to render exactly one frame
viewport.render_target_update_mode = SubViewport.UPDATE_ONCE
# 3. Wait for the engine to finish drawing the frame
# (We wait two frames just to guarantee the 3D server has updated)
await get_tree().process_frame
await get_tree().process_frame
# 4. Grab the raw image data from the viewport
var img = viewport.get_texture().get_image()
# 5. Convert it into a permanent, standalone Texture2D
var final_texture = ImageTexture.create_from_image(img)
# Clear the mesh so the generator is clean for the next item
mesh_instance.mesh = null
return final_texture