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: Add 3D cursor and limit to orbit camera target. #26558

Merged
merged 6 commits into from
Oct 18, 2023

Conversation

schwyzl
Copy link
Contributor

@schwyzl schwyzl commented Aug 9, 2023

Allows the user to limit the orbit controls target distance from a 3D cursor.

My use case is having models load far from the origin. I want to move the camera to the object, then limit it's distance from that object. This change allows me to limit the scale of the scene (and camera frustum) to achieve the highest quality rendering.

This contribution is funded by Axial3D

@Mugen87
Copy link
Collaborator

Mugen87 commented Aug 23, 2023

So this feature effectively limits panning operations, right?

Do you mind modifying the following templated by using your custom version of OrbitControls so the new feature can be tested?

https://jsfiddle.net/g3atw6k5/

@schwyzl
Copy link
Contributor Author

schwyzl commented Oct 17, 2023

@Mugen87 here is the updated fiddle: https://jsfiddle.net/oz0a69dn/22/

What you should see:

  • You should see an additional red sphere positioned at 20 units along the x axis.
  • The camera should be focussed on this sphere.
  • You shouldn't be able to move the target away from this sphere.

Code style clean up.
More clean up.
Move clamping further up.
@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 18, 2023

Users wanted to limit panning operations with OrbitControls multiple times in the past so I like the idea of having this as a feature in the class. Especially since it's already possible to limit orbiting and zooming/dollying.

The live example helped to understand the new code! I have just fixed the code style in OrbitControls and also move the clamping a few lines further up. Does it look good to you?

@Mugen87 Mugen87 added this to the r158 milestone Oct 18, 2023
@schwyzl
Copy link
Contributor Author

schwyzl commented Oct 18, 2023

Yep, looks good, thanks

@Mugen87 Mugen87 merged commit 2563342 into mrdoob:dev Oct 18, 2023
18 checks passed
@Mugen87 Mugen87 changed the title Add 3D cursor and limit to orbit camera target OrbitControls: Add 3D cursor and limit to orbit camera target. Oct 18, 2023
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.

2 participants