Controls
Summary
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
Syntax
Controls
()
Summary
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
Syntax
addDraggable
-
object
Summary
Adds an object to the list of handled objects.
Parameters:
-
objectBABYLON.MeshThe object.
addUnremovableDraggable
Syntax
addUnremovableDraggable
-
object
Summary
Adds an object to the list of handled objects, that can't be removed. Do not use this
Parameters:
-
objectBABYLON.MeshThe object.
clickSelection
Syntax
clickSelection
-
event
Summary
Implements the behaviour "click = selection of top-level object"
Parameters:
-
eventMouseEventThe JS event
constrains
Syntax
constrains
-
[U] -
[V]
Summary
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
Uis 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
UandV.
Parameters:
-
[U]BABYLON.Vector3 optionalFirst Vector.
-
[V]BABYLON.Vector3 optionalSecond Vector.
deselect
Syntax
deselect
()
Summary
Deselects the object, even if no object has been selected.
dragLock
Syntax
dragLock
()
Summary
Unlocks the dragging capabilities.
dragLock
Syntax
dragLock
()
Summary
Locks the dragging capabilities.
dragSelection
Syntax
dragSelection
-
event
Summary
Implements the behaviour "dragging of top-level object"
Parameters:
-
eventMouseEventThe JS event
getDragged
Syntax
getDragged
()
BABYLON.PickingInfo
Summary
Returns the dragged object as a picking information.
Returns:
The dragged object, as a picking information.
getLastPosition
Syntax
getLastPosition
()
Summary
Returns the last position of the dragged object.
getPointerCoordinates
Syntax
getPointerCoordinates
-
event
Summary
Gets the correct values for the current pointer. Cross device.
Parameters:
-
eventEventThe JS event
getReferentParent
Syntax
getReferentParent
()
BABYLON.Mesh
Summary
Returns the current referent parent, used to select or drag objects. See Controls wiki for more info.
Returns:
The current referent parent.
getReferentPlane
Syntax
getReferentPlane
()
BABYLON.Plane
Summary
Returns the current referent plane, on which the mouse is projected when dragging.
Returns:
The current referent plane.
getRoot
Syntax
getRoot
()
BABYLON.Mesh
Summary
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
Syntax
getSelected
()
BABYLON.PickingInfo
Summary
Returns the selected object, as picking information.
Returns:
The selected object, as picking information.
getSelectedObject
Syntax
getSelectedObject
()
BABYLON.Mesh
Summary
Returns the selected object. NB : This is equivalent to getSelected().pickedMesh.
Returns:
The selected object.
notify
Syntax
notify
-
event -
data
Summary
Calls every callback registered for a specific event.
Parameters:
-
eventEventThe event.
-
dataObjectThe data associated to this event.
off
Syntax
Summary
Removes a callback from a specific event.
Parameters:
-
eventEventThe event.
-
handlerFunctionThe callback function.
Returns:
this.
onClick
Syntax
onClick
-
event
Summary
Triggered on event wnp.engine3D.click.
Parameters:
-
eventEventThe JS event.
onDoubleClick
Syntax
onDoubleClick
-
event
Summary
Triggered on event wnp.engine3D.dblclick.collided.
Parameters:
-
eventEventThe JS event.
onDragEnd
Syntax
onDragEnd
-
event
Summary
Triggered on event wnp.engine3D.drag-end.
Parameters:
-
eventEventThe JS event.
onDragging
Syntax
onDragging
-
event
Summary
Triggered on event wnp.engine3D.dragging.
Parameters:
-
eventEventThe JS event.
onDragStart
Syntax
onDragStart
-
event
Summary
Triggered on event wnp.engine3D.drag-start.
Parameters:
-
eventEventThe JS event.
onMouseDown
Syntax
onMouseDown
-
event
Summary
Triggered on event wnp.engine3D.mousedown.
Parameters:
-
eventEventThe JS event.
onMouseMove
Syntax
onMouseMove
-
event
Summary
Triggered on event wnp.engine3D.mouse-move.
Parameters:
-
eventEventThe JS event.
pickMeshUnderCursor
Syntax
pickMeshUnderCursor
-
event -
[ref]
Summary
Picks the mesh under the mouse pointer, and returns the top-level object as a pickingInfo
Parameters:
-
eventMouseEventThe JS event
-
[ref]BABYLON.Mesh optionalOptional parameter to override the referent parent.
refreshReferentPlane
Syntax
refreshReferentPlane
()
Summary
Refresh the referent dragging plane, taking the constraints into account.
removeDraggable
Syntax
removeDraggable
-
object
Summary
Removes an object to the list of handled objects.
Parameters:
-
objectBABYLON.MeshThe object.
resetDraggable
Syntax
resetDraggable
()
Summary
Empties the list of handled objects.
select
Syntax
select
-
topLevelObjectPI
Summary
Selects an object, as a picking information.
Parameters:
-
topLevelObjectPIBABYLON.PickingInfoThe new selected object, as a picking information.
selectObject
Syntax
selectObject
-
object
Summary
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:
-
objectBABYLON.MeshThe new selected object.
selectTopLevelObject
Syntax
selectTopLevelObject
-
object
Summary
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:
-
objectBABYLON.MeshThe object from which we have to find the top-level object.
setDragged
Syntax
setDragged
-
dragged
Summary
Forces the dragged object without having to click on it. NB : Warning, the parameter is a picking info !
Parameters:
-
draggedBABYLON.PickingInfoThe new dragged object.
setReferentParent
Syntax
setReferentParent
-
parent
Summary
Sets the current referent parent, used to select or drag objects. See Controls wiki for more info.
Parameters:
-
parentBABYLON.MeshThe new referent parent.
setRoot
Syntax
setRoot
-
root
Summary
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:
-
rootBABYLON.MeshThe new root.
setScreenSize
Syntax
setScreenSize
-
width -
height
Summary
Sets the canvas size.
setSelectedObject
Syntax
setSelectedObject
-
object
Summary
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:
-
objectBABYLON.MeshThe new selected object.
startListening
Syntax
startListening
()
Summary
Starts the listening of Engine3D events.
stopListening
Syntax
stopListening
()
Summary
Stops the listening of Engine3D events.
Properties
domElement
Syntax
domElement
HTMLCanvasElement
Summary
The canvas.
listens
Syntax
listens
Boolean
Summary
Flag that indicates if the Controls are listening to the Engine3D events
objects
Syntax
objects
BABYLON.Mesh
Summary
3D objects handled by the controls (selectable and draggable).
scene
Syntax
scene
BABYLON.Scene
Summary
The 3D scene.
Events
wnp.request.disable-orbit-camera
Syntax
wnp.request.disable-orbit-camera
Summary
Fired to disable the orbit camera.
wnp.request.enable-orbit-camera
Syntax
wnp.request.enable-orbit-camera
Summary
Fired to enable the orbit camera.