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

OrbitControls: Set certain event listeners to non-passive #19782

Closed

Conversation

WestLangley
Copy link
Collaborator

@WestLangley WestLangley commented Jul 3, 2020

... similar to the suggestion by @unphased in #10373 (comment).

It does seem to prevent the following warning in Chrome:

[Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. Consider marking event handler as 'passive' to make the page more responsive.

ref: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

@unphased
Copy link
Contributor

unphased commented Jul 3, 2020

Nice :)

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 3, 2020

It does seem to prevent the following warning in Chrome:

How can I trigger this warning? I don't see it in the production link right now.

@unphased
Copy link
Contributor

unphased commented Jul 3, 2020

It does seem to prevent the following warning in Chrome:

How can I trigger this warning? I don't see it in the production link right now.

What's your chrome version? (Ellipsis menu, Help, About) Mine is Version 83.0.4103.116 (Official Build) (64-bit).

Also you must refresh the page after opening it. console does not show these messages if you open it after pageload.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 3, 2020

Um, I still don't see it 🤔 . I'm using Chrome 83.0.4103.116 on macOS.

@unphased
Copy link
Contributor

unphased commented Jul 3, 2020

I observe it on my macOS as well. Perhaps check if you have console filters activated.

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 3, 2020

I have not changed the default settings. It looks like so:

image

@unphased
Copy link
Contributor

unphased commented Jul 3, 2020

Yeah... looks like it is a debug-level warning and only shows if you set all levels... just to the right of your screenshot i guess itll say "3 hidden". Hey thanks for the screenshot, I'm gonna go check out the three.js dev tools!

@Mugen87
Copy link
Collaborator

Mugen87 commented Jul 3, 2020

Okay, they only appear if you ensure Verbose is checked.

image

Copy link
Contributor

@trusktr trusktr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to allow event options to be passed in, which would override (merge with) the default options.

@trusktr
Copy link
Contributor

trusktr commented Jul 3, 2020

Also, how does orbit controls work if rendering more than one scene or camera within the same WebGL context? For this reason, it may be also good to allow the DOM element to be optionally passed in, to give more optional control (f.e. cover the canvas with elements to handle events for different portions of the canvas).

@@ -1125,11 +1125,11 @@ THREE.OrbitControls = function ( object, domElement ) {
scope.domElement.addEventListener( 'contextmenu', onContextMenu, false );

scope.domElement.addEventListener( 'mousedown', onMouseDown, false );
scope.domElement.addEventListener( 'wheel', onMouseWheel, false );
scope.domElement.addEventListener( 'wheel', onMouseWheel, { capture: false, passive: false } );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find on the internets if capture is false by default...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, useCapture (the third parameter) is supposed to be false by default, but Firefox used to error a decade ago if it was not specified.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See this spec, but the relevant section is non-normative.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

capture (a boolean, initially false)

I guess I can remove it from the options object then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since non-normative means the specifications in that section are recommendations, not requirements, I think it would be best if we specify the value we want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was reading a different section than you were.

When set to true, options’s capture prevents callback from being invoked when the event’s eventPhase attribute value is BUBBLING_PHASE. When false (or not present), ...

Copy link
Owner

@mrdoob mrdoob Sep 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess it should just be this?

scope.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );

PS: I realised I didn't explain the useCapture issue property. Firefox used to crash because the third parameter was not passed.

@unphased
Copy link
Contributor

unphased commented Jul 4, 2020

Also, how does orbit controls work if rendering more than one scene or camera within the same WebGL context? For this reason, it may be also good to allow the DOM element to be optionally passed in

I think this is already the case. That’s what scope.domElement is in the controls code.

@WestLangley WestLangley added this to the r119 milestone Jul 7, 2020
@WestLangley
Copy link
Collaborator Author

This is easily reverted. Let's try it early in the dev cycle so we can get feedback.

@mrdoob mrdoob modified the milestones: r119, r120 Jul 29, 2020
@mrdoob mrdoob modified the milestones: r120, r121 Aug 25, 2020
@WestLangley
Copy link
Collaborator Author

This PR eliminates the Chrome warnings if there is no DAT.GUI -- but not if there is one...

@mrdoob
Copy link
Owner

mrdoob commented Sep 3, 2020

Hmmm... I can't see any warnings on Chrome 84.0.4147.135...

https://threejs.org/examples/misc_controls_orbit.html

Took a screenshot after scrolling on the view:

Screen Shot 2020-09-03 at 9 35 07 AM

@WestLangley
Copy link
Collaborator Author

Try #19782 (comment).

@mrdoob
Copy link
Owner

mrdoob commented Sep 3, 2020

@WestLangley Yeah! As you can see in the screenshot I have all levels selected. Including verbose.

@mrdoob
Copy link
Owner

mrdoob commented Sep 3, 2020

Oh wait, I can reproduce it from the examples page:

https://threejs.org/examples/#misc_controls_orbit

@WestLangley
Copy link
Collaborator Author

When the console sidebar is visible in Chrome 85, 'verbose' appears to be hardwired, and the warnings appear.

My current workaround to avoid the warnings is to hide the console sidebar and toggle-off 'verbose'.

@mrdoob mrdoob modified the milestones: r121, r122 Sep 29, 2020
@mrdoob mrdoob removed this from the r122 milestone Oct 28, 2020
@mrdoob mrdoob added this to the r123 milestone Oct 28, 2020
@mrdoob mrdoob modified the milestones: r123, r124 Nov 25, 2020
@mrdoob mrdoob modified the milestones: r124, r125 Dec 24, 2020
@mrdoob mrdoob modified the milestones: r125, r126 Jan 27, 2021
@WestLangley
Copy link
Collaborator Author

It doesn't appear there is interest in this, so closing...

@WestLangley WestLangley closed this Feb 1, 2021
@WestLangley WestLangley removed this from the r126 milestone Feb 2, 2021
@WestLangley WestLangley deleted the dev_orbit_controls_passive branch February 3, 2021 20:56
@bananu7
Copy link

bananu7 commented Mar 3, 2021

Um, this is pretty weird. I found this page looking for PRs that would fix the [Violation] warnings that are pretty annoying, only to find that this has been... dropped? I mean, it's a trivial change, what's preventing this from being merged in?

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.

6 participants