User Tools

Site Tools


dragengine:modules:dragonscript:behavior_vrhandlaserpointer

ECBehaviorVRHandLaserPointer

Behavior element behavior adding VR Hand Controller Laser Pointer support to actor.

VR Hand Controllers often use a laser pointer type interaction.

This behavior adds a particle emitter representing the laser pointer. The behavior attaches itself to a ECBehaviorVRHandPointAt. The enable casting of the particle emitter is linked to the enabled state of ECBehaviorVRHandPointAt.

Named controllers can be used to set typically laserpointer parameters at runtime if the named controllers exist. The following named controllers are supported:

  • length: Length of unobstructed beam in meters.
  • intensity: Intensity of beam.
  • red: Red color component of beam.
  • green: Green color component of beam.
  • blue: Blue color component of beam.

Additional named controllers can be added if required. The default particle emitter used is /shareddata/particles/laserpointer/laserpointer.depemit. This particle emitter defines the controller ranges like this:

  • length: Between 0m to 10m.
  • intensity: Between 0 to 1. The beam skin uses camera adapted intensity hence 1 represents full bright intensits compared to camera upper intensity.
  • red, green, blue: All betwen 0 to 1.

The default particle emitter is set to use custom collision response. This behavior implements the response to make the beam stop at the first hit obstacle. The collision filter from ECBehaviorVRHandPointAt is copied to the particle emitter to ensure the results are comparable.

The particle emitter is aligned with the test direction.

Instance Counts

This behavior can be added twice to an element to add support for left and right hand controller. Use the behavior identifier to tell them apart.

Element Class Properties

Element class properties have the prefix vrHandLaserPointer. or vrHandLaserPointer(id). if id is not empty.

particleEmitter.*

This behavior adds a child ECBehaviorParticleEmitter to the element class to show the laser pointer in the game world. The child behavior has the identifier “vrHandLaserPointer” or “vrHandLaserPointer(id)”. The child behavior has the element class property prefix “vrHandLaserPointer.particleEmitter.” or “vrHandLaserPointer(id).particleEmitter.”.

Hence to set for example the particle emitter of the right hand use the element class property “vrHandLaserPointer(right).particleEmitter.path”

controllerLength

Name of particle emitter controller to update with laserpointer length or empty string if not used.

  • Full name: “vrHandLaserPointer.controllerLength” or “vrHandLaserPointer(id).controllerLength”
  • Type: string
  • Default Value: “length”
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerLength'>length</string>

controllerIntensity

Name of particle emitter controller to update with laserpointer intensity or empty string if not used.

  • Full name: “vrHandLaserPointer.controllerIntensity” or “vrHandLaserPointer(id).controllerIntensity”
  • Type: string
  • Default Value: “intensity”
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerIntensity'>intensity</string>

controllerRed

Name of particle emitter controller to update with laserpointer red color component or empty string if not used.

  • Full name: “vrHandLaserPointer.controllerRed” or “vrHandLaserPointer(id).controllerRed”
  • Type: string
  • Default Value: “red”
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerRed'>red</string>

controllerGreen

Name of particle emitter controller to update with laserpointer green color component or empty string if not used.

  • Full name: “vrHandLaserPointer.controllerGreen” or “vrHandLaserPointer(id).controllerGreen”
  • Type: string
  • Default Value: “green”
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerGreen'>green</string>

controllerBlue

Name of particle emitter controller to update with laserpointer blue color component or empty string if not used.

  • Full name: “vrHandLaserPointer.controllerBlue” or “vrHandLaserPointer(id).controllerBlue”
  • Type: string
  • Default Value: “blue”
  • Example (*.deeclass):
    <string name='vrHandLaserPointer(right).controllerBlue'>blue</string>

length

Length in meters of laser pointer.

  • Full name: “vrHandLaserPointer.length” or “vrHandLaserPointer(id).length”
  • Type: float
  • Restrictions: Greater than or equal to 0
  • Default Value: 10
  • Example (*.deeclass):
    <float name='vrHandLaserPointer(right).length'>15</float>

intensity

Intensity of laser pointer. The actual intensity used depends on the particle emitter. Usually particle emitters use camera adapted intensity which maps an intensity of 1 to the camera upper intensity.

  • Full name: “vrHandLaserPointer.intensity” or “vrHandLaserPointer(id).intensity”
  • Type: float
  • Restrictions: Greater than or equal to 0
  • Default Value: 0.4
  • Example (*.deeclass):
    <float name='vrHandLaserPointer(right).intensity'>0.8</float>

color

Color of laser pointer.

  • Full name: “vrHandLaserPointer.color” or “vrHandLaserPointer(id).color”
  • Type: color
  • Default Value: (0, 1, 1)
  • Example (*.deeclass):
    <color name='vrHandLaserPointer(right).color' r='1' g='1' b='0'/>

Required Behaviors

Optional Behaviors

This behavior does not support optional behaviors.

Persistency

Saves these parameters:

  • Length
  • Intensity
  • Color

API Documentation

ECBehaviorVRHandLaserPointer.

Since DragonScript Module Version 1.7

Use Cases

  • Show a laser pointer in VR to visualize what objects the player interacts with.

Element Class Example

The following example creates an element class with laser pointer support.

class MyElement extends BehaviorElementClass
   public var ECBehaviorVRPlayspace vrPlayspace
   public var ECBehaviorVRHand vrHandRight
   public var ECBehaviorVRHand vrHandLeft
   public var ECBehaviorVRHandPointAt vrRightHandPointAt
   public var ECBehaviorVRHandPointAt vrLeftHandPointAt
   public var ECBehaviorVRHandLaserPointer vrRightHandLaserPointer
   public var ECBehaviorVRHandLaserPointer vrLeftHandLaserPointer
   
   public func new()
      // Create playspace
      vrPlayspace = ECBehaviorVRPlayspace.new(this)
      
      // Create hand controllers. The InputDeviceType indicates what device type
      // to monitor. vrRightHand and vrLeftHand can exist only once
      vrHandRight = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrRightHand, "right")
      vrHandLeft = ECBehaviorVRHand.new(this, vrPlayspace, InputDeviceType.vrLeftHand, "left")
      
      // Create point at behavior for each hand. By default the test direction
      // is along the controller Z axis. For common controllers this points
      // along the handle direction which is like holding a sword or similar
      vrRightHandPointAt = ECBehaviorVRHandPointAt.new(this, vrRightHand, "right")
      vrLeftHandPointAt = ECBehaviorVRHandPointAt.new(this, vrLeftHand, "left")
      
      // If you have a ECBehaviorCollider in your element class it is a good idea
      // to ignore this collider. This avoids the point hitting the player body
      // or hands.
      
      // vrRightHandPointAt.setIgnoreCollider(collider)
      // vrLeftHandPointAt.setIgnoreCollider(collider)
      
      // Add laser pointers. These are disabled by default. Enable them in
      // actor actions for example when the player touches the track pad
      // on his controller or whenever a specific actor action activates
      vrRightHandLaserPointer = ECBehaviorVRHandLaserPointer.new(this, vrRightHandPointAt, "right")
      vrLeftHandLaserPointer = ECBehaviorVRHandLaserPointer.new(this, vrLeftHandPointAt, "left")
  end
end

The BaseVRActorClass provides full VR support including ECBehaviorVRHandLaserPointer for both hands.

Live Examples

You could leave a comment if you were logged in.
dragengine/modules/dragonscript/behavior_vrhandlaserpointer.txt · Last modified: 2024/03/14 16:51 by dragonlord