44 lines
1.5 KiB
GDScript3
44 lines
1.5 KiB
GDScript3
|
|
extends Area3D
|
||
|
|
|
||
|
|
|
||
|
|
@onready var s: Sprite3D = $Sprite3D
|
||
|
|
@onready var v: SubViewport = $Sprite3D/SubViewport
|
||
|
|
|
||
|
|
func _process(delta):
|
||
|
|
var camera = get_viewport().get_camera_3d()
|
||
|
|
# Look in the same direction as the camera
|
||
|
|
var look = camera.to_global(Vector3(0, 0, -100)) - camera.global_transform.origin
|
||
|
|
look = position + look
|
||
|
|
|
||
|
|
look = Vector3(look.x, 0, look.z)
|
||
|
|
|
||
|
|
look_at(look, Vector3.UP)
|
||
|
|
|
||
|
|
func _unhandled_input(event):
|
||
|
|
if event is InputEventMouse:
|
||
|
|
# Handled via _on_input_event.
|
||
|
|
return
|
||
|
|
v.push_input(event)
|
||
|
|
|
||
|
|
func _on_input_event(_camera: Camera3D, event: InputEvent, pos: Vector3, _normal: Vector3, _shape_idx: int):
|
||
|
|
# Position of the event in Sprite3D local coordinates.
|
||
|
|
var texture_3d_position = s.get_global_transform().affine_inverse() * pos
|
||
|
|
#if !is_zero_approx(texture_3d_position.z):
|
||
|
|
# # Discard event because event didn't happen on the side of the Sprite3D.
|
||
|
|
# return
|
||
|
|
# Position of the event relative to the texture.
|
||
|
|
var texture_position: Vector2 = Vector2(texture_3d_position.x, -texture_3d_position.y) / s.pixel_size - s.get_item_rect().position
|
||
|
|
# Send mouse event.
|
||
|
|
var e: InputEvent = event.duplicate()
|
||
|
|
if e is InputEventMouse:
|
||
|
|
e.set_position(texture_position)
|
||
|
|
e.set_global_position(texture_position)
|
||
|
|
v.push_input(e)
|
||
|
|
|
||
|
|
func _on_button_pressed():
|
||
|
|
print("Button pressed")
|
||
|
|
|
||
|
|
|
||
|
|
func _on_line_edit_text_submitted(new_text):
|
||
|
|
print("Text submitted: ", new_text)
|