editor › Globals › InteractionHandler
Class: InteractionHandler
This class handles a single interaction from start to finish, forwarding events to a Tool instance. One "interaction" is a sequence of events starting with pointerdown and ending with pointerup.
Hierarchy
- InteractionHandler
Index
Constructors
Properties
- activeToolMapping
- afterInputHandledEventEmitter
- baseToolInstance
- beforeInputHandledEventEmitter
- cancelToken
- consecutiveClickCount
- distanceTraveled
- editor
- eventQueue
- firstInputEvent
- interactableObjects
- interactionCancelEventEmitter
- isClick
- isReplaying
- lastInputEvent
- shouldCaptureEvent
- startTimeStamp
- state
- toolBuilder
- toolErrorEventEmitter
- toolInstance
- toolInstanceCancelable
- toolMappingChangeEventEmitter
- toolMappings
- toolUsageFinishEventEmitter
- toolUsageStartEventEmitter
- toolUserMessageEventEmitter
- toolUserProgressCancelEventEmitter
- toolUserProgressEventEmitter
- toolUserProgressFinishEventEmitter
Methods
- _callBeforeInteractionStart
- _callInteractionCallback
- _changeToolInstance
- _getInteractionData
- _getMappingResult
- _getNewToolInstance
- _getToolSpecificInteractionData
- _handleConsecutiveClick
- _handleContinueInputEvent
- _handleEvent
- _handleFailedToolInteraction
- _handleFinishInputEvent
- _handleStartInputEvent
- _isClick
- _isValidInteraction
- _onUserMessage
- _onUserProgress
- _onUserProgressCancel
- _onUserProgressFinish
- _prepareInteractionData
- _reset
- _updateDistanceTraveled
- cancel
- configureForConsecutiveClick
- getAfterInputHandledEventEmitter
- getBeforeInputHandledEventEmitter
- getInteractionCancelEventEmitter
- getIsClick
- getShouldCaptureEvent
- getToolErrorEventEmitter
- getToolInstance
- getToolMappingChangeEventEmitter
- getToolUsageFinishEventEmitter
- getToolUsageStartEventEmitter
- getToolUserMessageEventEmitter
- getToolUserProgressCancelEventEmitter
- getToolUserProgressEventEmitter
- getToolUserProgressFinishEventEmitter
- handleEvent
- isConsecutiveClick
- isMultipleInteractionsTool
- processQueue
- replay
- restart
- stop
Constructors
constructor
+ new InteractionHandler(editor: Editor, toolBuilder: ToolBuilder, interactableObjects: Object3D[]): InteractionHandler
Defined in src/input/InteractionHandler.ts:157
Parameters:
| Name | Type | Description |
|---|---|---|
editor |
Editor | - |
toolBuilder |
ToolBuilder | The preconfigured ToolBuilder instance, that can be used to build new tool instances. |
interactableObjects |
Object3D[] | All Object3Ds that this Interaction can interact with |
Returns: InteractionHandler
Properties
Private activeToolMapping
• activeToolMapping: AbstractInteractionMapping
Defined in src/input/InteractionHandler.ts:76
Private Readonly afterInputHandledEventEmitter
• afterInputHandledEventEmitter: EventEmitter‹void› = new EventEmitter
Defined in src/input/InteractionHandler.ts:116
Private baseToolInstance
• baseToolInstance: Tool
Defined in src/input/InteractionHandler.ts:73
Private Readonly beforeInputHandledEventEmitter
• beforeInputHandledEventEmitter: EventEmitter‹void› = new EventEmitter
Defined in src/input/InteractionHandler.ts:115
Private cancelToken
• cancelToken: CancelToken = new CancelToken()
Defined in src/input/InteractionHandler.ts:157
Private consecutiveClickCount
• consecutiveClickCount: number = 0
Defined in src/input/InteractionHandler.ts:78
Private distanceTraveled
• distanceTraveled: number = 0
Defined in src/input/InteractionHandler.ts:101
The total distance traveled by the input during this interaction. This is used to distinguish between drag and click interactions.
Private Readonly editor
• editor: Editor
Defined in src/input/InteractionHandler.ts:127
Private eventQueue
• eventQueue: RetainableQueue‹IInputEvent› = new RetainableQueue(RetentionPolicy.FirstAndLast)
Defined in src/input/InteractionHandler.ts:90
All events passed to this InteractionHandler will first be put into the queue. Then this queue will be processed. This easily allows restoring state (for replaying) and it allows deferring processing events until the startPromise is finished.
Private firstInputEvent
• firstInputEvent: IInputEvent
Defined in src/input/InteractionHandler.ts:83
Remember the first input event in order to be able to check for consecutive clicks.
Private Readonly interactableObjects
• interactableObjects: Object3D[]
Defined in src/input/InteractionHandler.ts:112
An array of THREE objects that will be considered for the interaction.
Private Readonly interactionCancelEventEmitter
• interactionCancelEventEmitter: EventEmitter‹InteractionHandler‹›› = new EventEmitter
Defined in src/input/InteractionHandler.ts:125
Private isClick
• isClick: boolean = false
Defined in src/input/InteractionHandler.ts:133
This is set to true, after an InteractionHandler finished its interaction and the interaction was determined to be a click. This is used to determine double clicks.
Private isReplaying
• isReplaying: boolean = false
Defined in src/input/InteractionHandler.ts:146
This is set to true, if we are replaying events. In that case, we must not call continue immediately after the start event.
Private lastInputEvent
• lastInputEvent: IInputEvent
Defined in src/input/InteractionHandler.ts:95
The most recent input event of this interaction, used to sum up distanceTraveled.
Private shouldCaptureEvent
• shouldCaptureEvent: boolean = false
Defined in src/input/InteractionHandler.ts:155
Stores whether the start event could be handled. If yes, the whole chain of events should be 'captured' by this interaction handler. This is needed to differentiate between pointer controls and tool interaction.
We could also return this on each interaction, but the startPromise (and thus the asynchronous processing of events) makes this a bit nasty. Thus, we made it explicit.
Private startTimeStamp
• startTimeStamp: DOMHighResTimeStamp
Defined in src/input/InteractionHandler.ts:135
Private state
• state: InteractionHandlerState = InteractionHandlerState.IDLE
Defined in src/input/InteractionHandler.ts:113
Private toolBuilder
• toolBuilder: ToolBuilder
Defined in src/input/InteractionHandler.ts:107
This ToolBuilder is used, whenever a new instance of the tool is required. see InteractionHandler.replay
Private Readonly toolErrorEventEmitter
• toolErrorEventEmitter: EventEmitter‹Error› = new EventEmitter
Defined in src/input/InteractionHandler.ts:119
Private toolInstance
• toolInstance: Tool
Defined in src/input/InteractionHandler.ts:71
Private toolInstanceCancelable
• toolInstanceCancelable: boolean = false
Defined in src/input/InteractionHandler.ts:140
Tracks whether the current tool instance may be canceled or not.
Private Readonly toolMappingChangeEventEmitter
• toolMappingChangeEventEmitter: EventEmitter‹void› = new EventEmitter
Defined in src/input/InteractionHandler.ts:124
Private toolMappings
• toolMappings: Array‹AbstractInteractionMapping‹IMapping›› = []
Defined in src/input/InteractionHandler.ts:75
Private Readonly toolUsageFinishEventEmitter
• toolUsageFinishEventEmitter: EventEmitter‹IToolUsageFinishEvent› = new EventEmitter
Defined in src/input/InteractionHandler.ts:118
Private Readonly toolUsageStartEventEmitter
• toolUsageStartEventEmitter: EventEmitter‹IToolUsageStartEvent› = new EventEmitter
Defined in src/input/InteractionHandler.ts:117
Private Readonly toolUserMessageEventEmitter
• toolUserMessageEventEmitter: EventEmitter‹string› = new EventEmitter
Defined in src/input/InteractionHandler.ts:120
Private Readonly toolUserProgressCancelEventEmitter
• toolUserProgressCancelEventEmitter: EventEmitter‹number› = new EventEmitter
Defined in src/input/InteractionHandler.ts:122
Private Readonly toolUserProgressEventEmitter
• toolUserProgressEventEmitter: EventEmitter‹IToolUserProgressEvent› = new EventEmitter
Defined in src/input/InteractionHandler.ts:121
Private Readonly toolUserProgressFinishEventEmitter
• toolUserProgressFinishEventEmitter: EventEmitter‹number› = new EventEmitter
Defined in src/input/InteractionHandler.ts:123
Methods
Private _callBeforeInteractionStart
▸ _callBeforeInteractionStart(physicalObject: PhysicalObject, tool: Tool): Promise‹Assembly[][]› | void
Defined in src/input/InteractionHandler.ts:747
Call any beforeInteractionCallbacks attached to components of the assembly of the interacted physicalObject.
Parameters:
| Name | Type | Description |
|---|---|---|
physicalObject |
PhysicalObject | at the users input |
tool |
Tool | the tool that is being used |
Returns: Promise‹Assembly[][]› | void
a promise that resolves when the before hook has been handled or undefined if no action was required
Private _callInteractionCallback
▸ _callInteractionCallback(interactionData: IInteractionData): boolean
Defined in src/input/InteractionHandler.ts:384
Calls interactionCallback() on the selected three node or one of its parents if the method exists
Parameters:
| Name | Type |
|---|---|
interactionData |
IInteractionData |
Returns: boolean
true iff an interaction callback was called
Private _changeToolInstance
▸ _changeToolInstance(previousInteractionHandler: InteractionHandler): void
Defined in src/input/InteractionHandler.ts:421
Changes this.toolInstance to the instance provided by the previous InteractionHandler.
Parameters:
| Name | Type |
|---|---|
previousInteractionHandler |
InteractionHandler |
Returns: void
Private _getInteractionData
▸ _getInteractionData(inputEvent: IInputEvent): IInteractionData
Defined in src/input/InteractionHandler.ts:414
Parameters:
| Name | Type |
|---|---|
inputEvent |
IInputEvent |
Returns: IInteractionData
Private _getMappingResult
▸ _getMappingResult(event: IInputEvent): IMapping | STOPPED
Defined in src/input/InteractionHandler.ts:694
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
the best mapping result of the supplied mappings or InteractionHandlerState.STOPPED if a mappingChange occurred and the event should not be continued processing.
Private _getNewToolInstance
▸ _getNewToolInstance(): Tool
Defined in src/input/InteractionHandler.ts:774
Returns: Tool
Private _getToolSpecificInteractionData
▸ _getToolSpecificInteractionData(inputEvent: IInputEvent): IInteractionData
Defined in src/input/InteractionHandler.ts:406
Parameters:
| Name | Type |
|---|---|
inputEvent |
IInputEvent |
Returns: IInteractionData
Private _handleConsecutiveClick
▸ _handleConsecutiveClick(event: IInputEvent, interactionData: IInteractionData, clickCount: number): void
Defined in src/input/InteractionHandler.ts:599
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
interactionData |
IInteractionData |
clickCount |
number |
Returns: void
Private _handleContinueInputEvent
▸ _handleContinueInputEvent(event: IInputEvent, interactionData: IInteractionData): void
Defined in src/input/InteractionHandler.ts:623
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
interactionData |
IInteractionData |
Returns: void
Private _handleEvent
▸ _handleEvent(inputEvent: IInputEvent, allowStartPromise: boolean, cancelToken: CancelToken): Promise‹void›
Defined in src/input/InteractionHandler.ts:432
Parameters:
| Name | Type |
|---|---|
inputEvent |
IInputEvent |
allowStartPromise |
boolean |
cancelToken |
CancelToken |
Returns: Promise‹void›
Private _handleFailedToolInteraction
▸ _handleFailedToolInteraction(error: Error): void
Defined in src/input/InteractionHandler.ts:794
Parameters:
| Name | Type |
|---|---|
error |
Error |
Returns: void
Private _handleFinishInputEvent
▸ _handleFinishInputEvent(event: IInputEvent, interactionData: IInteractionData): void
Defined in src/input/InteractionHandler.ts:639
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
interactionData |
IInteractionData |
Returns: void
Private _handleStartInputEvent
▸ _handleStartInputEvent(event: IInputEvent, interactionData: IInteractionData, allowStartPromise: boolean, cancelToken: CancelToken): void
Defined in src/input/InteractionHandler.ts:468
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
interactionData |
IInteractionData |
allowStartPromise |
boolean |
cancelToken |
CancelToken |
Returns: void
Private _isClick
▸ _isClick(): boolean
Defined in src/input/InteractionHandler.ts:770
Returns: boolean
Private _isValidInteraction
▸ _isValidInteraction(interactionData: IInteractionData): boolean
Defined in src/input/InteractionHandler.ts:724
Parameters:
| Name | Type |
|---|---|
interactionData |
IInteractionData |
Returns: boolean
Private _onUserMessage
▸ _onUserMessage(message: string): void
Defined in src/input/InteractionHandler.ts:364
Parameters:
| Name | Type |
|---|---|
message |
string |
Returns: void
Private _onUserProgress
▸ _onUserProgress(event: IToolUserProgressEvent): void
Defined in src/input/InteractionHandler.ts:368
Parameters:
| Name | Type |
|---|---|
event |
IToolUserProgressEvent |
Returns: void
Private _onUserProgressCancel
▸ _onUserProgressCancel(id: number): void
Defined in src/input/InteractionHandler.ts:376
Parameters:
| Name | Type |
|---|---|
id |
number |
Returns: void
Private _onUserProgressFinish
▸ _onUserProgressFinish(id: number): void
Defined in src/input/InteractionHandler.ts:372
Parameters:
| Name | Type |
|---|---|
id |
number |
Returns: void
Private _prepareInteractionData
▸ _prepareInteractionData(inputEvent: IInputEvent): IInteractionData
Defined in src/input/InteractionHandler.ts:398
Parameters:
| Name | Type |
|---|---|
inputEvent |
IInputEvent |
Returns: IInteractionData
Private _reset
▸ _reset(): void
Defined in src/input/InteractionHandler.ts:347
ToDo: Reset the "whole" state
Returns: void
Private _updateDistanceTraveled
▸ _updateDistanceTraveled(inputEvent: IInputEvent): void
Defined in src/input/InteractionHandler.ts:712
Parameters:
| Name | Type |
|---|---|
inputEvent |
IInputEvent |
Returns: void
cancel
▸ cancel(): void
Defined in src/input/InteractionHandler.ts:286
Cancels the tool interaction (tell the toolInstance about it to let it clean up).
Returns: void
configureForConsecutiveClick
▸ configureForConsecutiveClick(event: IInputEvent, previousInteractionHandler: InteractionHandler): void
Defined in src/input/InteractionHandler.ts:299
Configures this interactionHandler for a possible consecutive click with a tool from finishedInteractionHandlers.
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
previousInteractionHandler |
InteractionHandler |
Returns: void
getAfterInputHandledEventEmitter
▸ getAfterInputHandledEventEmitter(): IPublicEventEmitterInterface‹void›
Defined in src/input/InteractionHandler.ts:228
Returns: IPublicEventEmitterInterface‹void›
getBeforeInputHandledEventEmitter
▸ getBeforeInputHandledEventEmitter(): IPublicEventEmitterInterface‹void›
Defined in src/input/InteractionHandler.ts:224
Returns: IPublicEventEmitterInterface‹void›
getInteractionCancelEventEmitter
▸ getInteractionCancelEventEmitter(): IPublicEventEmitterInterface‹InteractionHandler›
Defined in src/input/InteractionHandler.ts:248
Returns: IPublicEventEmitterInterface‹InteractionHandler›
getIsClick
▸ getIsClick(): boolean
Defined in src/input/InteractionHandler.ts:216
Returns: boolean
getShouldCaptureEvent
▸ getShouldCaptureEvent(): boolean
Defined in src/input/InteractionHandler.ts:268
Returns: boolean
getToolErrorEventEmitter
▸ getToolErrorEventEmitter(): IPublicEventEmitterInterface‹Error›
Defined in src/input/InteractionHandler.ts:240
Returns: IPublicEventEmitterInterface‹Error›
getToolInstance
▸ getToolInstance(): Tool
Defined in src/input/InteractionHandler.ts:220
Returns: Tool
getToolMappingChangeEventEmitter
▸ getToolMappingChangeEventEmitter(): IPublicEventEmitterInterface‹void›
Defined in src/input/InteractionHandler.ts:244
Returns: IPublicEventEmitterInterface‹void›
getToolUsageFinishEventEmitter
▸ getToolUsageFinishEventEmitter(): IPublicEventEmitterInterface‹IToolUsageFinishEvent›
Defined in src/input/InteractionHandler.ts:236
Returns: IPublicEventEmitterInterface‹IToolUsageFinishEvent›
getToolUsageStartEventEmitter
▸ getToolUsageStartEventEmitter(): IPublicEventEmitterInterface‹IToolUsageStartEvent›
Defined in src/input/InteractionHandler.ts:232
Returns: IPublicEventEmitterInterface‹IToolUsageStartEvent›
getToolUserMessageEventEmitter
▸ getToolUserMessageEventEmitter(): IPublicEventEmitterInterface‹string›
Defined in src/input/InteractionHandler.ts:252
Returns: IPublicEventEmitterInterface‹string›
getToolUserProgressCancelEventEmitter
▸ getToolUserProgressCancelEventEmitter(): IPublicEventEmitterInterface‹number›
Defined in src/input/InteractionHandler.ts:260
Returns: IPublicEventEmitterInterface‹number›
getToolUserProgressEventEmitter
▸ getToolUserProgressEventEmitter(): IPublicEventEmitterInterface‹IToolUserProgressEvent›
Defined in src/input/InteractionHandler.ts:256
Returns: IPublicEventEmitterInterface‹IToolUserProgressEvent›
getToolUserProgressFinishEventEmitter
▸ getToolUserProgressFinishEventEmitter(): IPublicEventEmitterInterface‹number›
Defined in src/input/InteractionHandler.ts:264
Returns: IPublicEventEmitterInterface‹number›
handleEvent
▸ handleEvent(event: IInputEvent): void
Defined in src/input/InteractionHandler.ts:179
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
Returns: void
isConsecutiveClick
▸ isConsecutiveClick(event: IInputEvent, otherInteractionHandler: InteractionHandler): boolean
Defined in src/input/InteractionHandler.ts:326
Consecutive Clicks are clicks followed by a quick mouse down, where the mouse did not move far The time between the second mouse down (↓) and the corresponding mouse up (↑) does not matter. This is similar to how Windows implements double click. Other window managers do it differently, but this is already known to most users and also simplifies implementation. This is a double click ↓-↑-↓-↑ This is also a double click, the rest of the interaction is discarded. ↓-↑-↓------↑ This is not a double click ↓-↑-----↓-↑
Parameters:
| Name | Type |
|---|---|
event |
IInputEvent |
otherInteractionHandler |
InteractionHandler |
Returns: boolean
If the current inputEvent together with the otherInteractionHandler are form consecutive click.
isMultipleInteractionsTool
▸ isMultipleInteractionsTool(): boolean
Defined in src/input/InteractionHandler.ts:188
Returns: boolean
processQueue
▸ processQueue(): void
Defined in src/input/InteractionHandler.ts:276
Starts processing queued events. This is called internally, whenever a new event comes in. Needs to be called manually for double click handlers.
Returns: void
replay
▸ replay(): void
Defined in src/input/InteractionHandler.ts:170
Returns: void
restart
▸ restart(): void
Defined in src/input/InteractionHandler.ts:206
Restart a stopped interaction (e.g. in case of a multipleInteractionsTool). The handler is not reset.
Returns: void
stop
▸ stop(): void
Defined in src/input/InteractionHandler.ts:195
Stops any event processing. This should only happen after an interaction finished/was canceled.
Returns: void