autoloader fix and grabbable base added

title says all, and yeah
This commit is contained in:
Hellie-xd 2026-08-05 01:31:20 +02:00
parent 3367698d10
commit b8c233f21f
3 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,27 @@
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

View file

@ -0,0 +1 @@
uid://cg6uae2pbr7eq

View file

@ -0,0 +1,32 @@
[gd_scene format=3 uid="uid://csj6ipagcwmeu"]
[ext_resource type="Script" uid="uid://cg6uae2pbr7eq" path="res://scenes/grabbable_base/grabbable_base.gd" id="1_rs3u4"]
[sub_resource type="BoxShape3D" id="BoxShape3D_1r4x2"]
[sub_resource type="PrismMesh" id="PrismMesh_60a4j"]
[node name="GrabbableBase" type="RigidBody3D" unique_id=1244645162]
script = ExtResource("1_rs3u4")
[node name="SubViewport" type="SubViewport" parent="." unique_id=174206665]
unique_name_in_owner = true
transparent_bg = true
size = Vector2i(128, 128)
render_target_update_mode = 1
[node name="Camera3D" type="Camera3D" parent="SubViewport" unique_id=1760830344]
transform = Transform3D(0.7071068, -0.5, 0.5, 0, 0.7071068, 0.70710677, -0.7071068, -0.5, 0.5, 1, 1, 1)
current = true
fov = 73.3
near = 0.106
[node name="GrabbableBaseCollider" type="CollisionShape3D" parent="." unique_id=5194036]
shape = SubResource("BoxShape3D_1r4x2")
[node name="GrabbableBaseMesh" type="MeshInstance3D" parent="." unique_id=191136965]
unique_name_in_owner = true
mesh = SubResource("PrismMesh_60a4j")
[node name="AreaLight3D" type="AreaLight3D" parent="." unique_id=283063489]
transform = Transform3D(0.74197584, -0.40812987, 0.53188515, 0, 0.7933533, 0.6087614, -0.6704266, -0.45168626, 0.588649, 0.8652531, 0.7732402, 0.9565933)