-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added node to create visual hints on interactable objects
- Loading branch information
1 parent
c8688a1
commit 69efa21
Showing
3 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@icon("res://components/interaction/3D/visuals/visual_hint_3d.svg") | ||
class_name VisualHint3D extends Node3D | ||
|
||
|
||
@export var interactable: Interactable3D | ||
@export_category("Image") | ||
@export var image_hint: Sprite3D | ||
@export var image_hint_texture: CompressedTexture2D | ||
@export var image_hint_focus_texture: CompressedTexture2D | ||
## The distance in meters at which the visual runway can be seen | ||
@export var image_hint_visible_distance: float = 3.0 | ||
@export var image_billboard_mode: BaseMaterial3D.BillboardMode = BaseMaterial3D.BillboardMode.BILLBOARD_FIXED_Y | ||
@export_category("Text") | ||
@export var text_hint: Label3D | ||
## The distance in meters at which the text runway can be seen | ||
@export var text_hint_visible_distance: float = 3.0 | ||
@export var text_billboard_mode: BaseMaterial3D.BillboardMode = BaseMaterial3D.BillboardMode.BILLBOARD_FIXED_Y | ||
|
||
|
||
func _ready() -> void: | ||
if image_hint == null: | ||
image_hint = NodeTraversal.first_node_of_type(self, Sprite3D.new()) | ||
|
||
if text_hint == null: | ||
text_hint = NodeTraversal.first_node_of_type(self, Label3D.new()) | ||
|
||
assert(image_hint != null or text_hint != null, "VisualHint3D: This node needs at least one Sprite3D or Label3D to work as expected") | ||
|
||
if interactable == null: | ||
interactable = NodeTraversal.first_node_of_custom_class(self, Interactable3D) | ||
|
||
assert(interactable != null, "VisualHint3D: This node needs at least one Interactable3D so that it can be interactive") | ||
|
||
image_hint.texture = image_hint_texture | ||
|
||
interactable.focused.connect(on_focused_interactable) | ||
interactable.unfocused.connect(on_unfocused_interactable) | ||
|
||
_setup_image_hint() | ||
_setup_text_hint() | ||
|
||
|
||
func _setup_image_hint() -> void: | ||
if image_hint != null: | ||
image_hint.texture = image_hint_texture | ||
image_hint.billboard = image_billboard_mode | ||
image_hint.render_priority = 2 | ||
image_hint.transparent = true | ||
image_hint.no_depth_test = true | ||
image_hint.visibility_range_end = image_hint_visible_distance | ||
|
||
|
||
func _setup_text_hint() -> void: | ||
if text_hint != null: | ||
text_hint.billboard = text_billboard_mode | ||
text_hint.render_priority = 2 | ||
text_hint.visibility_range_end = text_hint_visible_distance | ||
|
||
|
||
func display_image_hint() -> void: | ||
if image_hint != null and image_hint_focus_texture != null: | ||
image_hint.texture = image_hint_focus_texture | ||
|
||
|
||
func hide_image_hint() -> void: | ||
if image_hint != null and image_hint_texture != null: | ||
image_hint.texture = image_hint_texture | ||
|
||
|
||
func display_text_hint() -> void: | ||
if text_hint != null: | ||
text_hint.show() | ||
|
||
|
||
func hide_text_hint() -> void: | ||
if text_hint != null: | ||
text_hint.hide() | ||
|
||
|
||
func on_focused_interactable() -> void: | ||
display_image_hint() | ||
display_text_hint() | ||
|
||
|
||
func on_unfocused_interactable() -> void: | ||
hide_image_hint() | ||
hide_text_hint() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
components/interaction/3D/visuals/visual_hint_3d.svg.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://cvwua0fthdsy4" | ||
path="res://.godot/imported/visual_hint_3d.svg-850eda13390f74cde2848ca803be685c.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://components/interaction/3D/visuals/visual_hint_3d.svg" | ||
dest_files=["res://.godot/imported/visual_hint_3d.svg-850eda13390f74cde2848ca803be685c.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 | ||
svg/scale=1.0 | ||
editor/scale_with_editor_scale=false | ||
editor/convert_colors_with_editor_theme=false |