Controls Class
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
()
Item Index
Methods
- addDraggable
- addUnremovableDraggable deprecated
- clickSelection
- constrains
- deselect
- dragLock
- dragLock
- dragSelection
- getDragged
- getLastPosition
- getPointerCoordinates
- getReferentParent
- getReferentPlane
- getRoot
- getSelected
- getSelectedObject
- notify
- off
- on
- onClick
- onDoubleClick
- onDragEnd
- onDragging
- onDragStart
- onMouseDown
- onMouseMove
- pickMeshUnderCursor
- refreshReferentPlane
- removeDraggable
- resetDraggable
- select
- selectObject
- selectTopLevelObject
- setDragged
- setReferentParent
- setRoot
- setScreenSize
- setSelectedObject
- startListening
- stopListening
Properties
Methods
addDraggable
-
object
Adds an object to the list of handled objects.
Parameters:
-
object
BABYLON.MeshThe object.
addUnremovableDraggable
-
object
Adds an object to the list of handled objects, that can't be removed. Do not use this
Parameters:
-
object
BABYLON.MeshThe object.
clickSelection
-
event
Implements the behaviour "click = selection of top-level object"
Parameters:
-
event
MouseEventThe JS event
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 vectorU
. - Both params are specified, the object is dragged along a plane, directed by
U
andV
.
Parameters:
-
[U]
BABYLON.Vector3 optionalFirst Vector.
-
[V]
BABYLON.Vector3 optionalSecond 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:
-
event
MouseEventThe JS event
getDragged
()
BABYLON.PickingInfo
Returns the dragged object as a picking information.
Returns:
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
EventThe JS event
getReferentParent
()
BABYLON.Mesh
Returns the current referent parent, used to select or drag objects. See Controls
wiki for more info.
Returns:
The current referent parent.
getReferentPlane
()
BABYLON.Plane
Returns the current referent plane, on which the mouse is projected when dragging.
Returns:
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:
The current root.
getSelected
()
BABYLON.PickingInfo
Returns the selected object, as picking information.
Returns:
The selected object, as picking information.
getSelectedObject
()
BABYLON.Mesh
Returns the selected object. NB : This is equivalent to getSelected().pickedMesh.
Returns:
The selected object.
notify
-
event
-
data
Calls every callback registered for a specific event.
on
-
event
-
handler
-
insertFirst
Adds a callback to a specific event.
Parameters:
Returns:
this.
onDoubleClick
-
event
Triggered on event wnp.engine3D.dblclick.collided
.
Parameters:
-
event
EventThe JS event.
onDragging
-
event
Triggered on event wnp.engine3D.dragging
.
Parameters:
-
event
EventThe JS event.
onDragStart
-
event
Triggered on event wnp.engine3D.drag-start
.
Parameters:
-
event
EventThe JS event.
onMouseDown
-
event
Triggered on event wnp.engine3D.mousedown
.
Parameters:
-
event
EventThe JS event.
onMouseMove
-
event
Triggered on event wnp.engine3D.mouse-move
.
Parameters:
-
event
EventThe JS event.
pickMeshUnderCursor
-
event
-
[ref]
Picks the mesh under the mouse pointer, and returns the top-level object as a pickingInfo
Parameters:
-
event
MouseEventThe JS event
-
[ref]
BABYLON.Mesh optionalOptional 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.MeshThe object.
resetDraggable
()
Empties the list of handled objects.
select
-
topLevelObjectPI
Selects an object, as a picking information.
Parameters:
-
topLevelObjectPI
BABYLON.PickingInfoThe 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.MeshThe 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.MeshThe 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.PickingInfoThe 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.MeshThe 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.MeshThe new root.
setScreenSize
-
width
-
height
Sets the canvas size.
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.MeshThe new selected object.
startListening
()
Starts the listening of Engine3D
events.
stopListening
()
Stops the listening of Engine3D
events.
Properties
objects
BABYLON.Mesh
3D objects handled by the controls (selectable and draggable).
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.