Preparing search index...

    Class SpecsInteractionModule

    Entry point for the SPECS Interaction System.

    Register a SceneObject as an Interactable to add its colliders to the interaction scene, or as an InteractionPlane to define a zone that triggers near-field targeting logic. Registered Interactable colliders drive the system's spatial queries and cursor positioning. Run ray casts, sphere casts, and overlap probes against those colliders. Read activeInteractors for the interactors present now, subscribe to onInteractorAdded and onInteractorRemoved for later changes, and read each interactor's targeting ray. The cursor is rendered for you: use the Interactor to set its visual state, lock it to a position or plane, hide it, or lock its field while an interaction is in progress.

    Lens Scripting Version 375

    const interaction = require('LensStudio:SpecsInteractionModule');
    function onInteractor(interactor) {
    const ray = interactor.getTargetingRay();
    if (ray) {
    print("interactor " + interactor.id + " aiming from " + ray.origin);
    }
    }
    interaction.activeInteractors.forEach(onInteractor);
    interaction.onInteractorAdded.add(onInteractor);

    Hierarchy (View Summary)

    • Asset
      • SpecsInteractionModule
    Index

    Properties

    activeInteractors: SpecsInteractionModule.Interactor[]

    The interactors currently available. Use this to handle interactors that already exist when your script starts, then subscribe to SpecsInteractionModule#onInteractorAdded for later arrivals. Read this and subscribe in the same synchronous block so an interactor that connects in between is not missed. Each entry provides getTargetingRay, getCursor, and the lock APIs while it is live.

    Lens Scripting Version 375

    const interaction = require('LensStudio:SpecsInteractionModule');
    function onInteractor(interactor) {
    print("interactor " + interactor.id);
    }
    interaction.activeInteractors.forEach(onInteractor);
    interaction.onInteractorAdded.add(onInteractor);
    name: string

    The name of the Asset in Lens Studio.

    ""
    
    onInteractorAdded: event1<SpecsInteractionModule.Interactor, void>

    Fires when an interactor becomes available (a hand starts tracking, a controller connects). Only future arrivals are delivered. Interactors already present when you subscribe are not replayed. To handle those, read SpecsInteractionModule#activeInteractors once before subscribing.

    The handler receives the SpecsInteractionModule.Interactor. Retain it to read and control that interactor while it is live.

    Lens Scripting Version 375

    const interaction = require('LensStudio:SpecsInteractionModule');
    interaction.onInteractorAdded.add(function (interactor) {
    print("interactor added: " + interactor.id);
    });
    onInteractorRemoved: event1<SpecsInteractionModule.Interactor, void>

    Fires when an interactor is removed: it disconnects, or interaction is disabled for it. This is not the same as losing tracking (a hand going out of view, for example), which only flips SpecsInteractionModule.Interactor#isTracked and does not fire this event. The delivered SpecsInteractionModule.Interactor has isValid === false; use it only to identify which interactor was removed and tear down any state keyed on its id.

    Lens Scripting Version 375

    interaction.onInteractorRemoved.add(function (interactor) {
    print("removed interactor " + interactor.id);
    });
    uniqueIdentifier: string

    Lens Scripting Version 176

    Methods

    • Creates an edge-triggered box overlap probe that follows sceneObject, tracking its world position and rotation (uniform scale only). The probe reports colliders entering or leaving the oriented box through its onOverlapEnter and onOverlapExit events, each fired at most once per frame with a batch of that frame's changes. Subscribe immediately after creating the probe, since colliders that enter before you subscribe are not replayed.

      enterHalfExtents/exitHalfExtents (cm) give per-axis hysteresis. A collider enters at enterHalfExtents and leaves at exitHalfExtents, which should be >= enterHalfExtents per axis. Equal values disable hysteresis.

      queryMask matches colliders whose layerMask shares a layer with it; pass LayerSet.all() to match every supported layer. Only layers 0-63 are supported.

      options (SpecsInteractionModule.OverlapProbeOptions, optional) configures the probe, e.g. per-member distance tracking via trackDistances.

      Store the returned probe: it runs only while you hold a reference to it, and dropping your last one collects the probe along with its handlers. Call its destroy() to stop a probe you still hold and get a final OverlapProbe#onOverlapExit for whatever is inside.

      Parameters

      Returns BoxOverlapProbe

      Lens Scripting Version 375

      const half = new vec3(5, 5, 5);
      const queryMask = LayerSet.all();
      const probe = interaction.createBoxOverlapProbe(script.getSceneObject(), half, half, queryMask);
    • Creates an edge-triggered sphere overlap probe that follows sceneObject, tracking its world position. The probe reports colliders entering or leaving the sphere through its onOverlapEnter and onOverlapExit events, each fired at most once per frame with a batch of that frame's changes. Subscribe immediately after creating the probe, since colliders that enter before you subscribe are not replayed.

      enterRadius/exitRadius (cm) give hysteresis. A collider enters at enterRadius and leaves at exitRadius, which should be >= enterRadius. Equal values disable hysteresis.

      queryMask matches colliders whose layerMask shares a layer with it; pass LayerSet.all() to match every supported layer. Only layers 0-63 are supported.

      options (SpecsInteractionModule.OverlapProbeOptions, optional) configures the probe, e.g. per-member distance tracking via trackDistances.

      Store the returned probe: it runs only while you hold a reference to it, and dropping your last one collects the probe along with its handlers. Call its destroy() to stop a probe you still hold and get a final OverlapProbe#onOverlapExit for whatever is inside.

      Parameters

      Returns SphereOverlapProbe

      Lens Scripting Version 375

      const queryMask = LayerSet.all();
      const probe = interaction.createSphereOverlapProbe(script.getSceneObject(), 5, 6, queryMask);
      probe.onOverlapEnter.add(function (args) {
      print(args.enteredOverlaps.length + " entered");
      });
    • Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

      Returns string

      Lens Scripting Version 375

    • Returns the name of this object's type.

      Returns string

    • Returns true if the object matches or derives from the passed in type.

      Parameters

      • type: string

      Returns boolean

    • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

      Parameters

      Returns boolean

    • Returns (via callback) the nearest intersection across all registered colliders whose layerMask shares a layer with queryMask. Pass LayerSet.all() to match every supported layer. Only layers 0-63 are supported. start and end are in world space, in centimeters. A hit on an Interactable with SpecsInteractionModule.TargetingPriority.High wins over a nearer Normal-priority hit; within the same priority, the nearest hit wins. If there is no hit, the callback is called with a null hit argument. Ray casts are performed after Update, prior to LateUpdate.

      A cast can be blocked by a collider from another Lens, which is not returned as a hit.

      Parameters

      Returns void

      Lens Scripting Version 375

      const queryMask = LayerSet.all();
      interaction.rayCast(rayStart, rayEnd, queryMask, function (hit) {
      if (hit && hit.collider) {
      print("hit " + hit.collider.getSceneObject().name);
      }
      });
    • Returns (via callback) all intersections across all registered colliders whose layerMask shares a layer with queryMask. Pass LayerSet.all() to match every supported layer. Only layers 0-63 are supported. start and end are in world space, in centimeters. The callback receives an array of hits ordered by targeting priority first (Interactables with SpecsInteractionModule.TargetingPriority.High before Normal-priority ones), then by distance, nearest to farthest, within each priority. If there were no hits, the array length is 0. Ray casts are performed after Update, prior to LateUpdate.

      A cast can be blocked by a collider from another Lens, which is not returned as a hit.

      Parameters

      Returns void

      Lens Scripting Version 375

      const queryMask = LayerSet.all();
      interaction.rayCastAll(rayStart, rayEnd, queryMask, function (hits) {
      print(hits.length + " hits");
      });
    • Registers a SceneObject with a set of ColliderComponents as an Interactable. The colliders become interaction targets: they are targetable by interactors (driving the cursor per the options' targetingMode and targetingVisual) and are hit by SpecsInteractionModule's casts and overlap probes.

      Colliders do not have to be on interactableSceneObject. Each is hit-tested where it sits in the world, following its own SceneObject rather than interactableSceneObject. Disabling interactableSceneObject suspends hit-testing for all of its colliders, re-enabling resumes, and destroying it drops the registration. An individual collider that is disabled or destroyed drops out of hit-testing while the registration lives on, and re-enabling it restores it.

      Registering again for the same SceneObject replaces the previous registration, so call this whenever the colliders or options change.

      options (SpecsInteractionModule.InteractableOptions, optional) configures the Interactable, e.g. its targetingMode or layerMask; omitting it uses the defaults.

      Parameters

      Returns void

      Lens Scripting Version 375

      interaction.registerInteractable(script.getSceneObject(), [collider]);
      
    • Registers a SceneObject as an InteractionPlane, a zone that triggers near-field targeting logic for hand interactors. Add one to dense 2D UI, such as a menu of closely packed buttons, to stabilize targeting between neighbors. The options size its interaction zones and set the targeting visual shown while an interactor targets it.

      Registering again for the same SceneObject replaces the previous registration, so call this whenever the options change.

      Parameters

      Returns void

      Lens Scripting Version 375

      interaction.registerInteractionPlane(script.getSceneObject(), new SpecsInteractionModule.InteractionPlaneOptions());
      
    • Returns (via callback) the nearest intersection while sweeping a sphere from start to end across all registered colliders whose layerMask shares a layer with queryMask. Pass LayerSet.all() to match every supported layer. Only layers 0-63 are supported. radius is in centimeters; start and end are in world space, in centimeters. A hit on an Interactable with SpecsInteractionModule.TargetingPriority.High wins over a nearer Normal-priority hit; within the same priority, the nearest hit wins. If there is no hit, the callback is called with a null hit argument. Sphere casts are performed after Update, prior to LateUpdate.

      A cast can be blocked by a collider from another Lens, which is not returned as a hit.

      Parameters

      Returns void

      Lens Scripting Version 375

      const queryMask = LayerSet.all();
      interaction.sphereCast(2, rayStart, rayEnd, queryMask, function (hit) {
      if (hit) {
      print("nearest hit at " + hit.position);
      }
      });
    • Returns (via callback) all intersections while sweeping a sphere from start to end across all registered colliders whose layerMask shares a layer with queryMask. Pass LayerSet.all() to match every supported layer. Only layers 0-63 are supported. radius is in centimeters; start and end are in world space, in centimeters. The callback receives an array of hits ordered by targeting priority first (Interactables with SpecsInteractionModule.TargetingPriority.High before Normal-priority ones), then by distance, nearest to farthest, within each priority. If there were no hits, the array length is 0. Sphere casts are performed after Update, prior to LateUpdate.

      A cast can be blocked by a collider from another Lens, which is not returned as a hit.

      Parameters

      Returns void

      Lens Scripting Version 375

      const queryMask = LayerSet.all();
      interaction.sphereCastAll(2, rayStart, rayEnd, queryMask, function (hits) {
      print(hits.length + " hits");
      });
    • Unregisters an Interactable. Its colliders are no longer targetable by interactors or hit by SpecsInteractionModule's casts and overlap probes.

      Parameters

      Returns void

      Lens Scripting Version 375

      interaction.unregisterInteractable(script.getSceneObject());
      
    • Unregisters an InteractionPlane, removing its near-field targeting zone from SpecsInteractionModule.

      Parameters

      Returns void

      Lens Scripting Version 375

      interaction.unregisterInteractionPlane(script.getSceneObject());