Skip to main content

InteractionComponent

Class

Enables invoking touch interactions with a BaseMeshVisual rendered to specific Camera.

  • Available on all platforms
Platform details: Snapchat, SPECS, Camera Kit Web, Camera Kit Mobile fully supported.

Platform details

  • Snapchat — Fully supported.

  • SPECS — Fully supported.

  • Camera Kit Web — Fully supported.

  • Camera Kit Mobile — Fully supported.

Since Lens Scripting v141

Index

Remarks

Sometimes touch events within lens may collide with Snapchat touch events. To avoid this use Touch Blocking.

Example

// Pass in a MeshVisual
// @input Component.BaseMeshVisual myMeshVisual

// Get a reference to the InteractionComponent
var interactionComponent = script.sceneObject.getComponent(InteractionComponent.getTypeName());

// Sets the MeshVisual to handle touches
interactionComponent.addMeshVisual(script.myMeshVisual);

// Allow certain touch types to be passed to Snapchat
interactionComponent.addTouchBlockingException("TouchTypeDoubleTap");
//@input Component.InteractionComponent interactionComponent

// Subscribe to the onTap event
var onTapEvent = script.interactionComponent.onTap.add(function(tapEventArgs){
print("onTap!");
});

// Unsubscribe from the onTap event
script.interactionComponent.onTap.remove(onTapEvent);

Extends

Properties

enabled

enabled: boolean

If disabled, the Component will stop enacting its behavior.

Default Value

true

Inherited from

Component.enabled


isBeingDestroyed

readonly isBeingDestroyed: boolean

Returns true if this Component is currently being destroyed. Becomes true as soon as destruction begins via Component#destroy or destruction of its owning SceneObject, before any OnDestroyEvent callbacks fire.

Since

Lens Scripting Version 364

Example

if (!script.isBeingDestroyed) {
// Component is still fully alive
}

Inherited from

Component.isBeingDestroyed


isEnabledInHierarchy

readonly isEnabledInHierarchy: boolean

Returns true if this Component, its SceneObject, and all of that SceneObjects parents are enabled.

Inherited from

Component.isEnabledInHierarchy


isFilteredByDepth

isFilteredByDepth: boolean

When enabled, interaction events will be invoked only on the"closest" object, where order is defined by distance from camera and camera render order.

Since

Lens Scripting Version 195

Default Value

true

isFocused

readonly isFocused: boolean

Returns whether the user is currently gazing at the object on wearable devices, and when the user is touching on mobile devices.

Since

Lens Scripting Version 148


isSelected

readonly isSelected: boolean

Returns whether the user is currently selecting and gazing at an object on wearable devices, or touching it on mobile devices.

Since

Lens Scripting Version 148


onDoubleTap

readonly onDoubleTap: event1<DoubleTapEventArgs, void>

Triggered when the user double taps on the screen.

Since

Lens Scripting Version 193


onFocusEnd

readonly onFocusEnd: event1<FocusEndEventArgs, void>

On mobile devices, this is triggered when the user releases their touch. On wearable devices, this is triggered when the user looks away from the current object.

Since

Lens Scripting Version 148


onFocusStart

readonly onFocusStart: event1<FocusStartEventArgs, void>

On mobile devices, this is triggered when the user starts touching. On wearable devices, this is triggered when the user gazes on the current object.

Since

Lens Scripting Version 148


onHover

readonly onHover: event1<HoverEventArgs, void>

Gets called when hover events are passed to the lens.

Since

Lens Scripting Version 324


onHoverEnd

readonly onHoverEnd: event1<HoverEndEventArgs, void>

Gets called when hover events are finished.

Since

Lens Scripting Version 324


onHoverStart

readonly onHoverStart: event1<HoverStartEventArgs, void>

Gets called when hover event is initially triggered.

Since

Lens Scripting Version 324


onLongPressEnd

readonly onLongPressEnd: event1<LongPressEndEventArgs, void>

Triggered when the user ends a tap and hold.

Since

Lens Scripting Version 327


onLongPressStart

readonly onLongPressStart: event1<LongPressStartEventArgs, void>

Triggered when the user begins to tap and hold.

Since

Lens Scripting Version 327


onPanEnd

readonly onPanEnd: event1<PanEndEventArgs, void>

Triggered when the pan ends.

Since

Lens Scripting Version 327


onPanMove

readonly onPanMove: event1<PanMoveEventArgs, void>

Triggered when the user is panning.

Since

Lens Scripting Version 327


onPanStart

readonly onPanStart: event1<PanStartEventArgs, void>

Triggered when the user starts to pan across the screen.

Since

Lens Scripting Version 327


onPinchEnd

readonly onPinchEnd: event1<PinchEndEventArgs, void>

Triggered when the user ends the pinch.

Since

Lens Scripting Version 327


onPinchMove

readonly onPinchMove: event1<PinchMoveEventArgs, void>

Triggered when the user is pinching the screen.

Since

Lens Scripting Version 327


onPinchStart

readonly onPinchStart: event1<PinchStartEventArgs, void>

Triggered when the user pinches the screen.

Since

Lens Scripting Version 327


onScroll

readonly onScroll: event1<ScrollEventArgs, void>

Gets called when user scrolls on screen.

Since

Lens Scripting Version 141


onScrollEnd

readonly onScrollEnd: event1<ScrollEndEventArgs, void>

Gets called when scroll ends.

Since

Lens Scripting Version 141


onScrollStart

readonly onScrollStart: event1<ScrollStartEventArgs, void>

Gets called when scroll begins.

Since

Lens Scripting Version 141


onSelectEnd

readonly onSelectEnd: event1<SelectEndEventArgs, void>

On mobile devices, this is triggered when the user releases their touch. On wearable devices, this is triggered when the user stops touching the current object.

Since

Lens Scripting Version 148


onSelectStart

readonly onSelectStart: event1<SelectStartEventArgs, void>

On mobile devices, this is triggered when the user starts touching the current object. On wearable devices, this is triggered when the user touches the touchpad while focusing on an object.

Since

Lens Scripting Version 148


onTap

readonly onTap: event1<TapEventArgs, void>

Triggered when the user taps on the screen.

Since

Lens Scripting Version 148


onTouchEnd

readonly onTouchEnd: event1<TouchEndEventArgs, void>

Triggered when a touch event ends.

Since

Lens Scripting Version 148


onTouchMove

readonly onTouchMove: event1<TouchMoveEventArgs, void>

Triggered when a touch position on the screen is moved.

Since

Lens Scripting Version 148


onTouchStart

readonly onTouchStart: event1<TouchStartEventArgs, void>

Triggered when a touch event starts--either on the screen or on a touchpad. On wearables with touchpad, the coordinate returned are based on the touchpad and not the screen.

Since

Lens Scripting Version 148


onTriggerPrimary

readonly onTriggerPrimary: event1<TriggerPrimaryEventArgs, void>

Gets called when the user triggers the primary input on their device. For example touch on touch screens.

Since

Lens Scripting Version 148


sceneObject

readonly sceneObject: SceneObject

The SceneObject this component is on.

Inherited from

Component.sceneObject


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Component.uniqueIdentifier

Methods

addMeshVisual()

addMeshVisual(meshVisual): void

Adds a MeshVisual as a target for interaction detection.

Parameters

ParameterType
meshVisualBaseMeshVisual

Returns

void

Since

Lens Scripting Version 141


addTouchBlockingException()

addTouchBlockingException(exception): void

Adds a touch type that this component will ignore.

Parameters

ParameterType
exceptionstring

Returns

void

Since

Lens Scripting Version 141


destroy()

destroy(): void

Destroys the component.

Returns

void

Inherited from

Component.destroy


getMinimumTouchSize()

getMinimumTouchSize(): number

Returns the minimum bounding box size used for detecting touches. Value range is from [0-1], relative to screen width.

Returns

number

Since

Lens Scripting Version 141


getSceneObject()

getSceneObject(): SceneObject

Returns the SceneObject the component is attached to.

Returns

SceneObject

Inherited from

Component.getSceneObject


getTransform()

getTransform(): Transform

Returns the Transform this component is attached to.

Returns

Transform

Inherited from

Component.getTransform


getTypeName()

static getTypeName(): TypeName<InteractionComponent>

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

TypeName<InteractionComponent>

Since

Lens Scripting Version 141

Overrides

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Component.getTypeName


isOfType()

isOfType(type): boolean

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

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Component.isOfType


isSame()

isSame(other): boolean

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

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Component.isSame


removeMeshVisual()

removeMeshVisual(meshVisual): void

Removes a MeshVisual as a target for interaction detection.

Parameters

ParameterType
meshVisualBaseMeshVisual

Returns

void

Since

Lens Scripting Version 141


setCamera()

setCamera(camera): void

Sets the camera that will be used for interaction detection.

Parameters

ParameterType
cameraCamera

Returns

void

Since

Lens Scripting Version 141


setMinimumTouchSize()

setMinimumTouchSize(value): void

Sets the minimum bounding box size used for detecting touches. Value range is from [0-1], relative to screen width.

Parameters

ParameterType
valuenumber

Returns

void

Since

Lens Scripting Version 141

See also