Skip to content

Commit

Permalink
Added option to only show laser pointer on collision. Modified pointe…
Browse files Browse the repository at this point in the history
…r demo to show collision-laser and collision-target.

Added ability to truncate the laser length to the collision point.

Updated versions file with laser pointer options.

Modified settings of left pointer to show different styles (collision-only, show-target).
  • Loading branch information
Malcolmnixon committed Oct 26, 2022
1 parent 9ce09a5 commit d9b1ee6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Improvements to our 2D in 3D viewport
- Use value based grip input with threshold
- Improved pointer demo supporting left hand with switching
- Enhanced pointer laser visibility options for colliding with targets.

# 3.0.0
- Included demo project with test scenes to evaluate features
Expand Down
51 changes: 45 additions & 6 deletions addons/godot-xr-tools/functions/function_pointer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,27 @@ extends Spatial
##


## Enumeration of laser show modes
enum LaserShow {
HIDE = 0, ## Hide laser
SHOW = 1, ## Show laser
COLLIDE = 2, ## Only show laser on collision
}

## Enumeration of laser length modes
enum LaserLength {
FULL = 0, ## Full length
COLLIDE = 1 ## Draw to collision
}

## Pointer enabled property
export var enabled : bool = true setget set_enabled

## Show laser property
export var show_laser : bool = true setget set_show_laser
export (LaserShow) var show_laser : int = LaserShow.SHOW setget set_show_laser

## Laser length property
export (LaserLength) var laser_length : int = LaserLength.FULL

## Show laser target
export var show_target : bool = false
Expand Down Expand Up @@ -145,9 +161,21 @@ func _process(_delta):
elif new_target.has_method("pointer_moved"):
new_target.pointer_moved(last_collided_at, new_at)

if last_target and show_target:
$Target.global_transform.origin = last_collided_at
$Target.visible = true
if last_target:
# Show target if configured
if show_target:
$Target.global_transform.origin = new_at
$Target.visible = true

# Show laser if set to show-on-collide
if show_laser == LaserShow.COLLIDE:
$Laser.visible = true

# Adjust laser length if set to collide-length
if laser_length == LaserLength.COLLIDE:
var collide_len : float = new_at.distance_to(global_transform.origin)
$Laser.mesh.size.z = collide_len
$Laser.translation.z = collide_len * -0.5

# remember our new position
last_collided_at = new_at
Expand All @@ -159,8 +187,19 @@ func _process(_delta):
last_target.pointer_exited()

last_target = null

# Ensure target is hidden
$Target.visible = false

# Hide laser if set to show-on-collide
if show_laser == LaserShow.COLLIDE:
$Laser.visible = false

# Restore laser length if set to collide-length
if laser_length == LaserLength.COLLIDE:
$Laser.mesh.size.z = distance
$Laser.translation.z = distance * -0.5


# Set pointer enabled property
func set_enabled(p_enabled : bool) -> void:
Expand All @@ -172,7 +211,7 @@ func set_enabled(p_enabled : bool) -> void:


# Set show-laser property
func set_show_laser(p_show : bool) -> void:
func set_show_laser(p_show : int) -> void:
show_laser = p_show
if is_inside_tree():
_update_show_laser()
Expand Down Expand Up @@ -221,7 +260,7 @@ func _update_set_enabled() -> void:

# Pointer show-laser update handler
func _update_show_laser() -> void:
$Laser.visible = enabled and show_laser
$Laser.visible = enabled and show_laser == LaserShow.SHOW


# Pointer Y offset update handler
Expand Down
4 changes: 4 additions & 0 deletions scenes/pointer_demo/pointer_demo.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ strafe = true

[node name="FunctionPointer" parent="ARVROrigin/LeftHand" index="2" instance=ExtResource( 5 )]
enabled = false
show_laser = 2
laser_length = 1
show_target = true

[node name="RightHand" parent="ARVROrigin/RightHand" index="0" instance=ExtResource( 10 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.03, -0.05, 0.15 )
Expand All @@ -44,6 +47,7 @@ strafe = false
smooth_rotation = true

[node name="FunctionPointer" parent="ARVROrigin/RightHand" index="3" instance=ExtResource( 5 )]
laser_length = 1

[node name="PlayerBody" parent="ARVROrigin" index="3" instance=ExtResource( 8 )]

Expand Down

0 comments on commit d9b1ee6

Please sign in to comment.