Skip to content
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
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

refactor: events #844

wants to merge 17 commits into from

Conversation

andretchen0
Copy link
Contributor

@andretchen0 andretchen0 commented Sep 28, 2024

  • (fix) remove JSX event handlers from primitive :object when primitive is removed
  • (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) Added preventDefault to Tres events. (Vue assumes it is present on events. If the user adds the prevent event modifier and preventDefault is not present on the event, the browser will throw.)
  • (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; enables Vue event modifiers.
  • (fix) 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. Vue event modifiers are not supported.
  • (feat) BREAKING – pointer{enter,leave} had the same implementation as pointer{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-mouseleave
  • (fix) BREAKING – pointer{enter,leave} were previously bubbled. Now they are not bubbled and event.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=
  • (fix) @pointer{over,enter} and other events were fired multiple times for a single action – Issue pointer-{leave,out} fired multiple times on single "leave" #801
  • (fix) support Vue event modifiers – left, right – on @click events. Support left, 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.)
  • (fix) support Vue event modifiers – prevent, self. (Tres cannot support passive and does not currently support capture or once. Warning is logged on first unsupported event modifier, if !isProd.)
  • (fix) The OS context menu now appears by default when right-clicking. To disable the context menu for the entire canvas, use <TresCanvas @contextmenu.prevent />. To disable it when clicking on a particular object, use e.g. <TresMesh @contextmenu.prevent /> or <TresMesh @contextmenu.prevent="myFn" />
  • (feat) BREAKING – pointermissed fires when the object that registered the handler is missed – previously only fired when ALL objects were missed
  • (feat) BREAKING – pointermissed is always a "self" event (currentTarget === target)
  • (feat) BREAKING – when Tres' domElement is pointerleaved, all intersections are dropped and pointer{out,leave} is called where appropriate.
  • (feat) pointer{leave,out} is triggered (if necessary) just prior to object removal.
  • (feat) add filtering/sorting for intersections, prior to handling events. :events={filter: (intersections) => ...}
  • (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) :blocking="true" makes a subtree "solid"; objects behind objects in the subtree will not be "hit".
  • (feat) @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, until pointercancel or pointerup is heard.
  • (feat) onLostpointercapture fired when pointer capture is lost.
  • (perf) meshes without events on self/ancestors are no longer hit-tested by default.
  • (refactor) context.eventManager now creates its own raycaster(s) or no raycaster – depending on needs. It does not use context.raycaster.
  • (refactor) add field currentTarget to events (alias for eventObject) – required for Vue event modifier self.
  • (refactor) add field target to events (alias for object) – required for Vue event modifier self.
  • (refactor) BREAKING – remove the useRaycaster composable.
  • (refactor) BREAKING – remove the useEventManager composable.
  • (refactor) BREAKING – in addition to objects hit by raycaster rays, event.intersections now includes ancestors of the hit objects that have events (like R3F).
  • (fix) after event is used, these fields are set to null: eventObject, currentTarget – as with DOM events, copy an event in its handler if it is needed at a later time.

* (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".
Copy link

netlify bot commented Sep 28, 2024

Deploy Preview for tresjs-docs ready!

Name Link
🔨 Latest commit 799ad72
🔍 Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/66f8147b2c06d90008198732
😎 Deploy Preview https://deploy-preview-844--tresjs-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@andretchen0 andretchen0 changed the title refactor/events refactor: events Sep 28, 2024
@andretchen0 andretchen0 marked this pull request as ready for review September 28, 2024 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant