2023-03-21 22:06:45 +00:00
|
|
|
extends Area3D
|
|
|
|
|
|
2023-07-19 11:49:48 +00:00
|
|
|
@export var billboard = true
|
2023-04-22 13:11:10 +00:00
|
|
|
@onready var sprite: Sprite3D = $UiSprite
|
|
|
|
|
@onready var viewport: SubViewport = $UiSprite/SubViewport
|
2025-03-23 13:32:24 +00:00
|
|
|
|
|
|
|
|
|
2023-07-11 08:57:19 +00:00
|
|
|
func _process(_delta):
|
2024-09-15 09:30:31 +00:00
|
|
|
if billboard:
|
|
|
|
|
var camera = get_viewport().get_camera_3d()
|
|
|
|
|
|
|
|
|
|
var up = (camera.global_position - global_position)
|
|
|
|
|
up = up.cross(Vector3.UP).cross(up)
|
|
|
|
|
|
|
|
|
|
look_at(global_position - (camera.global_position - global_position), up)
|
2023-03-21 22:06:45 +00:00
|
|
|
|
2025-03-23 13:32:24 +00:00
|
|
|
func _input(event: InputEvent) -> void:
|
|
|
|
|
if event is InputEventAction:
|
|
|
|
|
print(event.action)
|
|
|
|
|
|
|
|
|
|
#func _unhandled_input(event):
|
|
|
|
|
# viewport.push_input(event)
|
2023-03-21 22:06:45 +00:00
|
|
|
|
|
|
|
|
func _on_input_event(_camera: Camera3D, event: InputEvent, pos: Vector3, _normal: Vector3, _shape_idx: int):
|
2024-09-15 09:30:31 +00:00
|
|
|
if not State.focus_locked:
|
|
|
|
|
# Position of the event in Sprite3D local coordinates.
|
|
|
|
|
var texture_3d_position = sprite.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) / sprite.pixel_size - sprite.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)
|
|
|
|
|
viewport.push_input(e)
|
2023-03-21 22:06:45 +00:00
|
|
|
|
|
|
|
|
func _on_button_pressed():
|
2024-09-15 09:30:31 +00:00
|
|
|
print("Button pressed")
|
2023-03-21 22:06:45 +00:00
|
|
|
|
|
|
|
|
func _on_line_edit_text_submitted(new_text):
|
2024-09-15 09:30:31 +00:00
|
|
|
print("Text submitted: ", new_text)
|