-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from Malcolmnixon/pickable-highlights
Enhanced pickable object highlighting
- Loading branch information
Showing
8 changed files
with
187 additions
and
27 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,38 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="StreamTexture" | ||
path.s3tc="res://.import/ring.png-34d9c9e9780f2732148a5b14fcac48dd.s3tc.stex" | ||
path.etc2="res://.import/ring.png-34d9c9e9780f2732148a5b14fcac48dd.etc2.stex" | ||
path.etc="res://.import/ring.png-34d9c9e9780f2732148a5b14fcac48dd.etc.stex" | ||
metadata={ | ||
"imported_formats": [ "s3tc", "etc2", "etc" ], | ||
"vram_texture": true | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/godot-xr-tools/images/ring.png" | ||
dest_files=[ "res://.import/ring.png-34d9c9e9780f2732148a5b14fcac48dd.s3tc.stex", "res://.import/ring.png-34d9c9e9780f2732148a5b14fcac48dd.etc2.stex", "res://.import/ring.png-34d9c9e9780f2732148a5b14fcac48dd.etc.stex" ] | ||
|
||
[params] | ||
|
||
compress/mode=2 | ||
compress/lossy_quality=0.7 | ||
compress/hdr_mode=0 | ||
compress/bptc_ldr=0 | ||
compress/normal_map=0 | ||
flags/repeat=0 | ||
flags/filter=true | ||
flags/mipmaps=true | ||
flags/anisotropic=false | ||
flags/srgb=1 | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/HDR_as_SRGB=false | ||
process/invert_color=false | ||
process/normal_map_invert_y=false | ||
stream=false | ||
size_limit=0 | ||
detect_3d=false | ||
svg/scale=1.0 |
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
51 changes: 51 additions & 0 deletions
51
addons/godot-xr-tools/objects/highlight/highlight_material.gd
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,51 @@ | ||
tool | ||
class_name XRTHighlightMaterial | ||
extends Node | ||
|
||
|
||
## Mesh to highlight | ||
export(NodePath) var highlight_mesh_instance | ||
|
||
## Material to set | ||
export(Resource) var highlight_material | ||
|
||
|
||
var _original_materials = Array() | ||
var _highlight_mesh_instance: MeshInstance | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
# Get the mesh to highlight | ||
_highlight_mesh_instance = get_node(highlight_mesh_instance) | ||
|
||
# Save the materials | ||
if _highlight_mesh_instance: | ||
# if we can find a node remember which materials are currently set on each surface | ||
for i in range(0, _highlight_mesh_instance.get_surface_material_count()): | ||
_original_materials.push_back(_highlight_mesh_instance.get_surface_material(i)) | ||
|
||
# Hook the highlight update | ||
get_parent().connect("highlight_updated", self, "_on_highlight_updated") | ||
|
||
|
||
# Called when the pickable highlight changes | ||
func _on_highlight_updated(pickable, enable: bool) -> void: | ||
# Set the materials | ||
if _highlight_mesh_instance: | ||
for i in range(0, _highlight_mesh_instance.get_surface_material_count()): | ||
if enable: | ||
_highlight_mesh_instance.set_surface_material(i, highlight_material) | ||
else: | ||
_highlight_mesh_instance.set_surface_material(i, _original_materials[i]) | ||
|
||
|
||
# This method verifies the node | ||
func _get_configuration_warning(): | ||
# Verify parent supports highlighting | ||
var parent := get_parent() | ||
if not parent or not parent.has_signal("highlight_updated"): | ||
return "Parent does not support highlighting" | ||
|
||
# No issues | ||
return "" |
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,29 @@ | ||
tool | ||
class_name XRTHighlightRing | ||
extends MeshInstance | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
# Turn off until requested | ||
if not Engine.editor_hint: | ||
visible = false | ||
|
||
# Hook the highlight update | ||
get_parent().connect("highlight_updated", self, "_on_highlight_updated") | ||
|
||
|
||
# Called when the pickable highlight changes | ||
func _on_highlight_updated(pickable, enable: bool) -> void: | ||
visible = enable | ||
|
||
|
||
# This method verifies the node | ||
func _get_configuration_warning(): | ||
# Verify parent supports highlighting | ||
var parent := get_parent() | ||
if not parent or not parent.has_signal("highlight_updated"): | ||
return "Parent does not support highlighting" | ||
|
||
# No issues | ||
return "" |
10 changes: 10 additions & 0 deletions
10
addons/godot-xr-tools/objects/highlight/highlight_ring.tres
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,10 @@ | ||
[gd_resource type="SpatialMaterial" load_steps=2 format=2] | ||
|
||
[ext_resource path="res://addons/godot-xr-tools/images/ring.png" type="Texture" id=1] | ||
|
||
[resource] | ||
flags_transparent = true | ||
flags_unshaded = true | ||
flags_no_depth_test = true | ||
params_billboard_mode = 1 | ||
albedo_texture = ExtResource( 1 ) |
12 changes: 12 additions & 0 deletions
12
addons/godot-xr-tools/objects/highlight/highlight_ring.tscn
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,12 @@ | ||
[gd_scene load_steps=4 format=2] | ||
|
||
[ext_resource path="res://addons/godot-xr-tools/objects/highlight/highlight_ring.gd" type="Script" id=1] | ||
[ext_resource path="res://addons/godot-xr-tools/objects/highlight/highlight_ring.tres" type="Material" id=2] | ||
|
||
[sub_resource type="QuadMesh" id=1] | ||
size = Vector2( 0.05, 0.05 ) | ||
|
||
[node name="XRTHighlightRing" type="MeshInstance"] | ||
mesh = SubResource( 1 ) | ||
material/0 = ExtResource( 2 ) | ||
script = ExtResource( 1 ) |
30 changes: 30 additions & 0 deletions
30
addons/godot-xr-tools/objects/highlight/highlight_visible.gd
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,30 @@ | ||
tool | ||
class_name XRTHighlightVisible | ||
extends Spatial | ||
|
||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
# Turn off until requested | ||
if not Engine.editor_hint: | ||
visible = false | ||
|
||
# Hook the highlight update | ||
get_parent().connect("highlight_updated", self, "_on_highlight_updated") | ||
|
||
|
||
# Called when the pickable highlight changes | ||
func _on_highlight_updated(pickable, enable: bool) -> void: | ||
visible = enable | ||
|
||
|
||
# This method verifies the node | ||
func _get_configuration_warning(): | ||
# Verify parent supports highlighting | ||
var parent := get_parent() | ||
if not parent or not parent.has_signal("highlight_updated"): | ||
return "Parent does not support highlighting" | ||
|
||
# No issues | ||
return "" |