API Docs for: 2.7.3
Show:

Controls Class

Module: Input
Parent Module: Wanaplan

High-level controller for the 3D scene, that handles selection, dragging, and notifying events to 3D widgets. It is derived into a higher level of abstraction class : EditionComponent3D, but can still be used by another component.

Controls is the selection/dragging system on wanaplan, it wraps all Engine3D events into a high-level system. You provide a list of objects that can be selected and dragged. These objects have a hierarchy (parent - children), and an ancestor, called the root.

Dragging : A referent parent is always set, you can only drag object that are direct children of the referent parent, or direct children of the root.

Selection : You select objects by clicking on them. You can only select objects that are direct children of the referent parent, or direct children of the root.

Here is the list of all events you can set callbacks to, and the type of the argument provided to the callback :

  • before-dragstart (no argument)
  • before-dragging (BABYLON.Ray)
  • dragstart (BABYLON.PickingInfo)
  • dragging (BABYLON.PickingInfo)
  • dragend (BABYLON.PickingInfo)
  • mouseup (MouseEvent)
  • mousedown (MouseEvent)
  • mousemove (MouseEvent)
  • before-click (no argument)
  • click (BABYLON.PickingInfo)
  • double-click (BABYLON.PickingInfo)
  • select (BABYLON.PickingInfo)
  • deselect (BABYLON.PickingInfo)

Constructor

Controls

()

Methods

addDraggable

(
  • object
)

Adds an object to the list of handled objects.

Parameters:

  • object BABYLON.Mesh

    The object.

addUnremovableDraggable

(
  • object
)
deprecated private

Adds an object to the list of handled objects, that can't be removed. Do not use this

Parameters:

  • object BABYLON.Mesh

    The object.

clickSelection

(
  • event
)

Implements the behaviour "click = selection of top-level object"

Parameters:

constrains

(
  • [U]
  • [V]
)

Sets the constrains for the dragging. 3 cases :

  • No param is specified, no constraint on the dragging, the object is dragged on a sphere around the camera.
  • Only the param U is specified, the object is dragged along an axis, carried by the vector U.
  • Both params are specified, the object is dragged along a plane, directed by U and V.

Parameters:

  • [U] BABYLON.Vector3 optional

    First Vector.

  • [V] BABYLON.Vector3 optional

    Second Vector.

deselect

()

Deselects the object, even if no object has been selected.

dragLock

()

Unlocks the dragging capabilities.

dragLock

()

Locks the dragging capabilities.

dragSelection

(
  • event
)

Implements the behaviour "dragging of top-level object"

Parameters:

getDragged

() BABYLON.PickingInfo

Returns the dragged object as a picking information.

Returns:

BABYLON.PickingInfo:

The dragged object, as a picking information.

getLastPosition

()

Returns the last position of the dragged object.

getPointerCoordinates

(
  • event
)

Gets the correct values for the current pointer. Cross device.

Parameters:

  • event Event

    The JS event

getReferentParent

() BABYLON.Mesh

Returns the current referent parent, used to select or drag objects. See Controls wiki for more info.

Returns:

BABYLON.Mesh:

The current referent parent.

getReferentPlane

() BABYLON.Plane

Returns the current referent plane, on which the mouse is projected when dragging.

Returns:

BABYLON.Plane:

The current referent plane.

getRoot

() BABYLON.Mesh

Returns the current root, that is the top-level parent of all handled objects. NB : All objects that are not descendants of the root can't be handled by Controls.

Returns:

BABYLON.Mesh:

The current root.

getSelected

() BABYLON.PickingInfo

Returns the selected object, as picking information.

Returns:

BABYLON.PickingInfo:

The selected object, as picking information.

getSelectedObject

() BABYLON.Mesh

Returns the selected object. NB : This is equivalent to getSelected().pickedMesh.

Returns:

BABYLON.Mesh:

The selected object.

notify

(
  • event
  • data
)

Calls every callback registered for a specific event.

Parameters:

  • event Event

    The event.

  • data Object

    The data associated to this event.

off

(
  • event
  • handler
)
Controls

Removes a callback from a specific event.

Parameters:

Returns:

Controls:

this.

on

(
  • event
  • handler
  • insertFirst
)
Controls

Adds a callback to a specific event.

Parameters:

  • event Event

    The event.

  • handler Function

    The callback function.

  • insertFirst Boolean

    If true then insert function in first position of listeners.

Returns:

Controls:

this.

onClick

(
  • event
)

Triggered on event wnp.engine3D.click.

Parameters:

  • event Event

    The JS event.

onDoubleClick

(
  • event
)

Triggered on event wnp.engine3D.dblclick.collided.

Parameters:

  • event Event

    The JS event.

onDragEnd

(
  • event
)

Triggered on event wnp.engine3D.drag-end.

Parameters:

  • event Event

    The JS event.

onDragging

(
  • event
)

Triggered on event wnp.engine3D.dragging.

Parameters:

  • event Event

    The JS event.

onDragStart

(
  • event
)

Triggered on event wnp.engine3D.drag-start.

Parameters:

  • event Event

    The JS event.

onMouseDown

(
  • event
)

Triggered on event wnp.engine3D.mousedown.

Parameters:

  • event Event

    The JS event.

onMouseMove

(
  • event
)

Triggered on event wnp.engine3D.mouse-move.

Parameters:

  • event Event

    The JS event.

pickMeshUnderCursor

(
  • event
  • [ref]
)

Picks the mesh under the mouse pointer, and returns the top-level object as a pickingInfo

Parameters:

  • event MouseEvent

    The JS event

  • [ref] BABYLON.Mesh optional

    Optional parameter to override the referent parent.

refreshReferentPlane

()

Refresh the referent dragging plane, taking the constraints into account.

removeDraggable

(
  • object
)

Removes an object to the list of handled objects.

Parameters:

  • object BABYLON.Mesh

    The object.

resetDraggable

()

Empties the list of handled objects.

select

(
  • topLevelObjectPI
)

Selects an object, as a picking information.

Parameters:

  • topLevelObjectPI BABYLON.PickingInfo

    The new selected object, as a picking information.

selectObject

(
  • object
)

Selects an object. NB : A picking info is created, with a null distance and a null pickedPoint. NB 2 : The difference with setSelectedObject is that a select event is fired.

Parameters:

  • object BABYLON.Mesh

    The new selected object.

selectTopLevelObject

(
  • object
)

Selects the top-level object, relative to the referent parent, for the given object. NB : A picking info is created, with a null distance and a null pickedPoint.

Parameters:

  • object BABYLON.Mesh

    The object from which we have to find the top-level object.

setDragged

(
  • dragged
)

Forces the dragged object without having to click on it. NB : Warning, the parameter is a picking info !

Parameters:

  • dragged BABYLON.PickingInfo

    The new dragged object.

setReferentParent

(
  • parent
)

Sets the current referent parent, used to select or drag objects. See Controls wiki for more info.

Parameters:

  • parent BABYLON.Mesh

    The new referent parent.

setRoot

(
  • root
)

Sets the current root, that is the top-level parent of all handled objects. NB : All objects that are not descendants of the root can't be handled by Controls. NB 2 : The referent parent is also set to the new root, for consistency.

Parameters:

  • root BABYLON.Mesh

    The new root.

setScreenSize

(
  • width
  • height
)

Sets the canvas size.

Parameters:

setSelectedObject

(
  • object
)

Forces the selected object without having to click on it. NB : A picking info is created, with a null distance and a null pickedPoint. NB 2 : The difference with selectObject is that no select event is fired.

Parameters:

  • object BABYLON.Mesh

    The new selected object.

startListening

()

Starts the listening of Engine3D events.

stopListening

()

Stops the listening of Engine3D events.

Properties

_screenSizes

Object

Screen Sizes (width and height)

domElement

HTMLCanvasElement

The canvas.

listens

Boolean

Flag that indicates if the Controls are listening to the Engine3D events

move

Function

Move callback, called by Controls to move an object in the scene.

objects

BABYLON.Mesh

3D objects handled by the controls (selectable and draggable).

params

Object

Controls parameters.

scene

BABYLON.Scene

The 3D scene.

Events

wnp.request.disable-orbit-camera

Fired to disable the orbit camera.

wnp.request.enable-orbit-camera

Fired to enable the orbit camera.