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

WIP: OrbitControls: added support for zoom to cursor #17145

Closed
wants to merge 4 commits into from

Conversation

WestLangley
Copy link
Collaborator

@WestLangley WestLangley commented Aug 1, 2019

As suggested in #16961 (comment).

I think this should be the default for MapControls. I'm not sure if it makes as much sense for OrbitControls, but it can be toggled on.

This is a WIP. Feedback welcome.

<EDIT - live link removed>

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 1, 2019

Hint: Consider to use draft PRs if your code is really WIP.

Copy link
Contributor

@sciecode sciecode left a comment

Choose a reason for hiding this comment

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

The behavior looks great 👍
Just pointing out some places where a division by zero is possible and you didn't clearly state with comments.

examples/jsm/controls/OrbitControls.js Outdated Show resolved Hide resolved
examples/jsm/controls/OrbitControls.js Outdated Show resolved Hide resolved
examples/jsm/controls/OrbitControls.js Outdated Show resolved Hide resolved
@EliasHasle
Copy link
Contributor

EliasHasle commented Aug 8, 2019

The desired behavior is confirmed with touchpad pinch-to-zoom on Chrome for Windows. Does it work on touch screens too?

I think I agree that disabling panning should also disable this feature. Also that zoom to (through?) cursor should be default for MapControls and not for OrbitControls.

@looeee
Copy link
Collaborator

looeee commented Aug 15, 2019

The updated example looks great 👍

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 9, 2019

@WestLangley This change is great! But what about the concerns of @sciecode here #17145 (comment)?

Apart from that, I think it's okay to remove the WIP label and updating the docs/TS instead. Would be nice to have this feature in context of MapControls.

@Mugen87 Mugen87 mentioned this pull request Dec 19, 2019
@WestLangley
Copy link
Collaborator Author

I now have a version that supports touch, too. I'll get back to this soon...

@mrdoob mrdoob added this to the rXXX milestone Dec 19, 2019
@Peque
Copy link
Contributor

Peque commented Jan 29, 2020

@WestLangley Friendly ping. 😇

I too think this would be a great default for MapControls.

@duhaime
Copy link
Contributor

duhaime commented Mar 6, 2020

@Peque check out the PR, he exports MapControls and OrbitControls!

@Peque
Copy link
Contributor

Peque commented Mar 6, 2020

@duhaime Not sure what you mean... 😅 😊

@duhaime
Copy link
Contributor

duhaime commented Mar 7, 2020

Haha, no worries, I just meant that this PR includes a zoom to cursor implementation for the Map controls. The OrbitControls here exports both OrbitControls and MapControls objects.

Did you see @WestLangley's MapControls demo with zoom to cursor? That might be the easiest way to see the zoom to cursor in action...

@Peque
Copy link
Contributor

Peque commented Mar 7, 2020

@duhaime Thanks. With my comment I just wanted to upvote this MR and ask @WestLangley if they were planning to work on this to get it merged. 😊

@Peque
Copy link
Contributor

Peque commented Mar 7, 2020

In particular, I wanted to upvote for MapControls to zoom to cursor by default, which I think is what most people would expect nowadays (matching OpenStreetMaps, Google Maps, Bing Maps...).

@Peque
Copy link
Contributor

Peque commented May 9, 2020

@WestLangley I tried your code here and found one issue, in case you are still interested in this. 😇

The problem occurs when using an OrtographicCamera and setting controls.maxPolarAngle = Math.PI / 2;. Then, if you go to a completely horizontal view (i.e.: polar angle is 90º) and zoom (out or it, it doesn't matter), it breaks. With break I mean you are unable to see the texture again.

@sciecode
Copy link
Contributor

sciecode commented May 9, 2020

@Peque there are comments informing of this limitation in the commit:

this.maxPolarAngle = Math.PI / 3; // must be less than pi/2 when zoomToCursor is true

@Peque
Copy link
Contributor

Peque commented May 9, 2020

@sciecode Do you know how to work-around that limitation?

@sciecode
Copy link
Contributor

sciecode commented May 9, 2020

@sciecode Do you know how to work-around that limitation?

From a design point of view there is no work-around, because we keep camera.up fixed and that's invaluable to many of other features, so we can't change that.

From a project stand point, you could simply make it so the "map" is not oriented facing up ( normal pointing to +Y ). Change the orientation to something else, for example... facing +Z.
This way, you avoid this limitation by working-around it and not against it.

@Peque
Copy link
Contributor

Peque commented May 9, 2020

@sciecode Thanks for your feedback! 😊

I have an application with the map facing +Z, but I seem to find the same issue. 😕 I do set camera.up.set(0, 0, 1); though.

@looeee
Copy link
Collaborator

looeee commented May 9, 2020

@Peque there are comments informing of this limitation in the commit:

this.maxPolarAngle = Math.PI / 3; // must be less than pi/2 when zoomToCursor is true|

We should note this in the docs as well.

@molzer
Copy link

molzer commented May 28, 2020

Thank you @WestLangley for this!

@promontis
Copy link

@WestLangley Is this something that is ready to be merged?

@JHB101
Copy link

JHB101 commented Feb 12, 2021

I for one am confused. Has this been added? Is it stable now?
The issue is still open and I don't remember the recent r125 release mentioning it being added.

@Mugen87
Copy link
Collaborator

Mugen87 commented Feb 12, 2021

When a PR is open then it is not yet merged. And that means the code is not yet added to the repo.

@JHB101
Copy link

JHB101 commented Feb 12, 2021

Well, I am forced to use your code by my current client because his people think its great. Sitting on your hands whilst a PR is open with just has a cryptic message at the bottom is not my idea of fun. So get snotty with me all you like, but you know you guys are starting to drop the ball on this, and then I am going to have to migrate this company back to the real thing. I would love to say I have never seen so much confusion in a code base, but unfortunately I have, so waddle on.

@molzer
Copy link

molzer commented Feb 12, 2021

I'm using this PR's code without problems since a few months even though it hasn't been merged yet – just do it this way?

@JHB101
Copy link

JHB101 commented Feb 12, 2021

@molzer

I am using it as is, and then my client reads somewhere (not here) that you can now zoom to cursor. Now he wants to know from me if I used ThreeJS at all, because he tested and his website does not zoom to cursor. He substantiates his claims by sighting some blog post that reports you must set some keyword to true. Little does he know that the keyword has already been removed again by the very people that are supposed to guard against such behavior.

The control js files in all their flavors, are not supposed to be part of the code base (its in examples), but it is treated as part of it in here, or is it part of it? I simply cannot tell anymore. It might help if the examples are moved to their own repo. Also there has been so many settings/keywords used in it that has been added and then removed again that I have lost count. These were added/removed at the whim of every person coming in here with a new suggestion/complaint. These keywords then start losing their meaning, because the word that describes the effect has been used and removed already.

My suggestion (for what it is worth) is make only one controls.js and make it part of the core. Then use settings/keywords to change it into map-/orbit-/camera-/whatever-/controls. Now using js (pseudo) pointers at the start of the file will send the request to the correct function (i.e. there will be no trackballcontrolls or orbitcontrols, but you could have either based on a setting like "Don't orbit all the way around the y axis or yAxisOrbitLimit=90"). If I remember correctly that is the difference between the two.

At the moment you are trying to mimic google maps in one file and a plane in another. This can all be one file. I saw in r120 someone made a cameracontrols.js in its own sub folder and I was hoping it was to merge all this, but here we go again with zoom to mouse and we all sit in limbo waiting to see if our next update is going to break this again.

@molzer

This comment has been minimized.

@JHB101

This comment has been minimized.

natarius added a commit to buildwithflux/three-orbitcontrols that referenced this pull request May 17, 2021
@timrutter
Copy link

timrutter commented Jun 23, 2021

is there any chance this can be merged? It pretty basic and commonly expected behaviour.

that said I've just tried using it locally and i have issues because my camera always looks along Z. The camera's position ends up as NaN. Any ideas why this might be?

@ammanvedi
Copy link

would be great to merge !

@metalim
Copy link

metalim commented Sep 10, 2021

Hey. So, what's preventing this from being merged? Should we just create a new PR?

@WestLangley
Copy link
Collaborator Author

Updated to the latest release... Support for touch in progress...

@WestLangley WestLangley deleted the dev_zoom_to_curson branch September 13, 2021 14:05
@WestLangley
Copy link
Collaborator Author

WestLangley commented Sep 13, 2021

I have come to the conclusion that this approach is not going to work.

(1) It only works when damping is enabled. That is not acceptable in my view.

(2) Touch is not supported. (My mobile devices do not support pointer events, so I am no longer able to test the code I wrote previously.)

To prevent further delay, I suggest someone else give this a try.

@WestLangley WestLangley removed this from the r??? milestone Sep 13, 2021
@PSausM
Copy link

PSausM commented Jan 17, 2022

It's best to not use orbit controls: Use camera controls
https://github.com/yomotsu/camera-controls
It's implemented there and they have a nice "fitToScreen" function as well.

@Akbar1909
Copy link

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.