-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: events #844
Open
andretchen0
wants to merge
17
commits into
main
Choose a base branch
from
refactor/events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
refactor: events #844
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* (fix) BREAKING - remove `event.intersects` – use `event.intersections` * (fix) BREAKING - remove `event.stopPropagating` – use `event.stopPropagation` * (fix) BREAKING – from TresCanvas, don't emit pointer/click events bubbled from Tres objects * (fix) BREAKING – `event.delta` is now reset to `0` following a `click`. * (fix) BREAKING – `pointerleave` handlers were sent previous intersections at `event.intersections`, now current intersections. * (fix) BREAKING – `@dblclick` now fires whenever the canvas `dblclick` is emitted. Any TresObject with an `@dblclick` handler will receive the event if it is under the pointer. (Previously objects not under the initial click did not receive the `@dblclick`.) * (fix) `event.pointer` is now defined – previously typed but was `undefined` in implementation. * (fix) `event.unprojectedPoint` is now properly calculated. Was previously left as `TODO`. * (fix) `event.eventObject` holds the object that registered the event handler. Was previously typed but `undefined` in implementation. * (fix) use Vue-style ("flatcase") event names, e.g. `@pointerdown`. Keep support for old-style ("kebab-case") event names, e.g. `@pointer-down`, and warn. Mixing both on the same object is not supported and may lead to handlers being overwritten. * (fix) `@pointer{leave,out}` was fired multiple times on a single "leave" – Issue #801 * (feat) BREAKING – `pointermissed` fires when the object that registered the handler is missed – previously only fired when ALL objects were missed * (feat) add filtering/sorting for intersections, prior to handling events. `:events={filter: (intersections) => ...}` * (feat) support Vue event modifiers – `stop, prevent, self, once`. (Tres cannot support `passive` and does not currently support `capture`.) * (feat) via `:events-target` prop, allow users to specify an HTML `addEventListener` target – allows Tres to respond to events, even if there's an overlay on the canvas. * (feat) via `:events-enabled` prop, allow `eventManager` to be enabled/disabled while Tres is running. * (feat) via `:events` prop, allow `eventManager` functions to be set/overwritten (non-reactive). * (feat) via `:events` prop, allow events system to be disabled completely: `<TresCanvas :events="null" />` (non-reactive) * (feat) `pointer{leave,out}` is triggered (if necessary) just prior to object removal. * (feat) `:blocking="true"` makes a subtree "solid"; objects behind objects in the subtree will not be "hit".
✅ Deploy Preview for tresjs-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
primitive :object
whenprimitive
is removedevent.intersects
– useevent.intersections
event.stopPropagating
– useevent.stopPropagation
event.delta
is now reset to0
following aclick
.pointerleave
handlers were sent previous intersections atevent.intersections
, now current intersections.@dblclick
now fires whenever the canvasdblclick
is emitted. Any TresObject with an@dblclick
handler will receive the event if it is under the pointer. (Previously objects not under the initial click did not receive the@dblclick
.)preventDefault
to Tres events. (Vue assumes it is present on events. If the user adds theprevent
event modifier andpreventDefault
is not present on the event, the browser will throw.)event.pointer
is now defined – previously typed but wasundefined
in implementation.event.unprojectedPoint
is now properly calculated. Was previously left asTODO
.event.eventObject
holds the object that registered the event handler. Was previously typed butundefined
in implementation.@pointerdown
; enables Vue event modifiers.@pointer-down
, and warn. Mixing both on the same object is not supported and may lead to handlers being overwritten. Vue event modifiers are not supported.pointer{enter,leave}
had the same implementation aspointer{over,out}
. Now has distinct behavior like in Vue/DOM. See description of DOM equivalents here: https://javascript.info/mousemove-mouseover-mouseout-mouseenter-mouseleave#events-mouseenter-and-mouseleavepointer{enter,leave}
were previously bubbled. Now they are not bubbled andevent.stopPropagation()
does not alter which objects receive the event. See description of DOM equivalents: https://javascript.info/mousemove-mouseover-mouseout-mouseenter-mouseleave#events-mouseenter-and-mouseleave Vue DOM example:https://play.vuejs.org/#eNqdU01vwjAM/StWLoCEWqHtxADtQxy2w4a2HXMpxStlbRIlToeE+t+XpMBgVOzjUtl+z8l7jrthN0pFlUU2ZCOT6lwRGCSrJlyM4qbgQpcQlqpICF0GMFrkFfgA4FrJXBBq9J8xZ6kURhYYFTLrdjwtAJ0eZ8f8ApMK2/gBOOXLqv14aamFbOlHbjDirCwHWyffvESGpHKnIIwnsAEM+UxLlWQJ5VJ0e1dQc3bSHPT/t9m7/FUv7Gwcmf5b63YC0DxRHIRDmgghCeYIvlfhAuaWwOuK3QUehm66xPQdtuPtjeLloNmK2A05LM7BsrA+I+Oob3kWrYwUbtE2nuyfp1R5gfpJeWmGsyEExGNJUciPh1AjbbG/q4ebW+ors/Y1zmYaDeoKOdtjlOgMqYGnL4+4dvEeLOXCFo59BnxGZ9N6jQ3t1oqFk33AC2rvSyU15SJ7NdM1oTA7U16oZ9aBz5n72+7OWP+SexFdhj4ualZ/Av43M5M=
@pointer{over,enter}
and other events were fired multiple times for a single action – Issuepointer-{leave,out}
fired multiple times on single "leave" #801left, right
– on@click
events. Supportleft, right, middle
on@pointer{up,down}
events. (Vue appears to silently convert@click.middle
to@pointerdown.middle
, but Tres is not notified of the change and will not call the associated handler.)prevent, self
. (Tres cannot supportpassive
and does not currently supportcapture
oronce
. Warning is logged on first unsupported event modifier, if!isProd
.)<TresCanvas @contextmenu.prevent />
. To disable it when clicking on a particular object, use e.g.<TresMesh @contextmenu.prevent />
or<TresMesh @contextmenu.prevent="myFn" />
pointermissed
fires when the object that registered the handler is missed – previously only fired when ALL objects were missedpointermissed
is always a "self" event (currentTarget === target
)pointerleave
d, all intersections are dropped andpointer{out,leave}
is called where appropriate.pointer{leave,out}
is triggered (if necessary) just prior to object removal.:events={filter: (intersections) => ...}
:events-target
prop, allow users to specify an HTMLaddEventListener
target – allows Tres to respond to events, even if there's an overlay on the canvas.:events-enabled
prop, alloweventManager
to be enabled/disabled while Tres is running.:events
prop, alloweventManager
functions to be set/overwritten (non-reactive).:events
prop, allow events system to be disabled completely:<TresCanvas :events="null" />
(non-reactive):blocking="true"
makes a subtree "solid"; objects behind objects in the subtree will not be "hit".@pointerdown="(e:ThreeEvent<PointerEvent>) => { e.target.setPointerCapture(e.pointerId) }"
captures the pointer –target
will receive pointer events even if it is not under the pointer, untilpointercancel
orpointerup
is heard.onLostpointercapture
fired when pointer capture is lost.context.eventManager
now creates its own raycaster(s) or no raycaster – depending on needs. It does not usecontext.raycaster
.currentTarget
to events (alias foreventObject
) – required for Vue event modifierself
.target
to events (alias forobject
) – required for Vue event modifierself
.useRaycaster
composable.useEventManager
composable.event.intersections
now includes ancestors of the hit objects that have events (like R3F).null
:eventObject, currentTarget
– as with DOM events, copy an event in its handler if it is needed at a later time.