Options
All
  • Public
  • Public/Protected
  • All
Menu

The interaction manager deals with mouse, touch and pointer events. Any DisplayObject can be interactive if its interactive parameter is set to true This manager also supports multitouch.

reference to pixi.js impl

example

import { Scene, PerspectiveCamera, WebGLRenderer, Mesh, BoxGeometry, MeshBasicMaterial } from 'three'; import { Interaction } from 'three.interaction'; const renderer = new WebGLRenderer({ canvas: canvasElement }); const scenevis = new Scene(); const camera = new PerspectiveCamera(60, width / height, 0.1, 100);

const interaction = new Interaction(renderer, scenevis, camera); // then you can bind every interaction event with any mesh which you had add into scenevis before const cube = new Mesh( new BoxGeometry(1, 1, 1), new MeshBasicMaterial({ color: 0xffffff }), ); scenevis.add(cube); cube.on('touchstart', ev => { console.log(ev); });

cube.on(PointerEvents.POINTER_DOWN, ev => { console.log(ev); });

cube.on('pointerdown', ev => { console.log(ev); }); // and so on ...

// you can also listen on parent-node or any display-tree node, // source event will bubble up along with display-tree. // you can stop the bubble-up by invoke ev.stopPropagation function. scenevis.on('touchstart', ev => { console.log(ev); })

Hierarchy

Index

Constructors

constructor

  • new Interaction(renderer: Renderer, scene: Scene, camera: Camera, options?: { autoAttach?: boolean; autoPreventDefault?: boolean; interactionFrequency?: number }): Interaction

Properties

autoPreventDefault

autoPreventDefault: boolean

Should default browser actions automatically be prevented. Does not apply to pointer events for backwards compatibility preventDefault on pointer events stops mouse events from firing Thus, for every pointer event, there will always be either a mouse of touch event alongside it.

member

{boolean}

default

false

camera

camera: Camera

The renderer this interaction manager works for.

member

{Camera}

currentCursorMode

currentCursorMode: string

The mode of the cursor that is being used. The value of this is a key from the cursorStyles dictionary.

member

{string}

cursorStyles

cursorStyles: { default: string; pointer: string }

Dictionary of how different cursor modes are handled. Strings are handled as CSS cursor values, objects are handled as dictionaries of CSS values for interactionDOMElement, and functions are called instead of changing the CSS. Default CSS cursor values are provided for 'default' and 'pointer' modes.

member

{Object.<string, (string|Function|Object.<string, string>)>}

Type declaration

  • default: string
  • pointer: string

didMove

didMove: boolean

eventData

eventData: InteractionEvent

An event data object to handle all the event tracking/dispatching

member

{object}

interactionFrequency

interactionFrequency: number

Frequency in milliseconds that the mousemove, moveover & mouseout interaction events will be checked.

member

{number}

default

10

mouse

mouse: InteractionData

The mouse data

member

{InteractionData}

moveWhenInside

moveWhenInside: boolean

This property determines if mousemove and touchmove events are fired only when the cursor is over the object. Setting to true will make things work more in line with how the DOM verison works. Setting to false can make things easier for things like dragging It is currently set to false as this is how three.js used to work.

member

{boolean}

default

true

renderer

renderer: Renderer

The renderer this interaction manager works for.

member

{WebGLRenderer}

scene

scene: Scene

The renderer this interaction manager works for.

member

{Scene}

Readonly supportsPointerEvents

supportsPointerEvents: boolean

Does the device support pointer events https://www.w3.org/Submission/pointer-events/

readonly
member

{boolean}

Readonly supportsTouchEvents

supportsTouchEvents: boolean

Does the device support touch events https://www.w3.org/TR/touch-events/

readonly
member

{boolean}

Private ticker

ticker: any

a ticker

member

{Ticker}

Methods

addEventListener

  • addEventListener(type: string, listener: (event: Event) => void): void
  • Adds a listener to an event type.

    Parameters

    • type: string

      The type of event to listen to.

    • listener: (event: Event) => void

      The function that gets called when the event is fired.

        • (event: Event): void
        • Parameters

          • event: Event

          Returns void

    Returns void

destroy

  • destroy(): void

dispatchEvent

  • dispatchEvent(event: { type: string }): void
  • Fire an event type.

    Parameters

    • event: { type: string }
      • [attachment: string]: any
      • type: string

    Returns void

hasEventListener

  • hasEventListener(type: string, listener: (event: Event) => void): boolean
  • Checks if listener is added to an event type.

    Parameters

    • type: string

      The type of event to listen to.

    • listener: (event: Event) => void

      The function that gets called when the event is fired.

        • (event: Event): void
        • Parameters

          • event: Event

          Returns void

    Returns boolean

hitTest

  • hitTest(globalPoint: { x: number; y: number }, root?: Object3D): Object3D

mapPositionToPoint

  • mapPositionToPoint(point: { x: number; y: number }, x: number, y: number): void
  • Maps x and y coords from a DOM object and maps them correctly to the three.js view. The resulting value is stored in the point. This takes into account the fact that the DOM element could be scaled and positioned anywhere on the screen.

    Parameters

    • point: { x: number; y: number }

      the point that the result will be stored in

      • x: number
      • y: number
    • x: number

      the x coord of the position to map

    • y: number

      the y coord of the position to map

    Returns void

removeEventListener

  • removeEventListener(type: string, listener: (event: Event) => void): void
  • Removes a listener from an event type.

    Parameters

    • type: string

      The type of the listener that gets removed.

    • listener: (event: Event) => void

      The listener function that gets removed.

        • (event: Event): void
        • Parameters

          • event: Event

          Returns void

    Returns void

setCursorMode

  • setCursorMode(mode: string): void

setObjectsToRaycast

  • setObjectsToRaycast(objects: any): void

setTargetElement

  • setTargetElement(element: HTMLCanvasElement): void

update

  • update(__namedParameters: { snippet: number }): void

Generated using TypeDoc