44 lines
1.1 KiB
GDScript
44 lines
1.1 KiB
GDScript
class_name Backdrop3D extends MeshInstance3D
|
|
|
|
const DISTANCE = 655.0
|
|
|
|
@export var interactive := false
|
|
|
|
func _ready() -> void:
|
|
get_viewport().size_changed.connect(_adjust_size)
|
|
_adjust_size()
|
|
_follow_camera()
|
|
|
|
func _adjust_size() -> void:
|
|
mesh.size = get_viewport().get_visible_rect().size
|
|
|
|
func _process(_delta: float) -> void:
|
|
_follow_camera()
|
|
|
|
func _follow_camera() -> void:
|
|
global_transform = FX.get_camera().global_transform
|
|
transform = transform.rotated(
|
|
basis.x, PI/2.0
|
|
).translated(
|
|
-DISTANCE*basis.z
|
|
)
|
|
|
|
func _get_embedded_viewport() -> Viewport:
|
|
var mat := mesh.surface_get_material(0)
|
|
var texture: Texture2D = null
|
|
if mat is ShaderMaterial:
|
|
texture = mat.get_shader_parameter(&'image')
|
|
elif mat is BaseMaterial3D:
|
|
texture = mat.albedo_texture
|
|
if texture is ViewportTexture:
|
|
return get_tree().current_scene.get_node(texture.viewport_path)
|
|
else:
|
|
return null
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if interactive:
|
|
var viewport := _get_embedded_viewport()
|
|
if viewport:
|
|
viewport.push_input(event)
|
|
get_viewport().set_input_as_handled()
|