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

[FEATURE] Make transitions thenable #206

Closed
looeee opened this issue Aug 21, 2021 · 7 comments
Closed

[FEATURE] Make transitions thenable #206

looeee opened this issue Aug 21, 2021 · 7 comments

Comments

@looeee
Copy link
Contributor

looeee commented Aug 21, 2021

Is your feature request related to a problem? Please describe.

  1. I need to disable parts of the interface while the camera is animating, e.g. using controls.rotateTo.
disableUI();
await controls.rotateAzimuthTo(Math.PI/4, true);
enableUI();
  1. I would like to chain animations e.g:
await controls.dollyTo(5, true);
await controls.rotateAzimuthTo(Math.PI/4, true);
await controls.dollyTo(2, true);
// ... etc.

Describe alternatives you've considered

I've tried doing this using the event listeners wake and sleep however the problem is:
a) it's hard to distinguish an animation from a user interaction
b) due to damping sleep fires far too late

@yomotsu
Copy link
Owner

yomotsu commented Aug 21, 2021

Hi @looeee,
I'm happy to have your comment, the author of the book, as well as a frequent contributor of three.js!

If you'd like to control a CameraControls instance as tweens, you could combine a tween library,

e.g.
https://yomotsu.github.io/camera-controls/examples/easing.html


  • CameraControls relies on a damping animation, as you understand, and not time-based animations(like tween).
  • Because, damping animation can combine multiple input dynamically, unlike time-based fixed animation.
  • Although, CameraControls can be applied to time-based fixed animation as well.
  • (But damping animation must be ignored during fixed animations.)
  • To apply the fixed animation, use a Tween library such as tween.js, GSAP, or whatever.

What do you think...?

@looeee
Copy link
Contributor Author

looeee commented Aug 22, 2021

I'm happy to have your comment

😊 Thank you for this awesome library.

If you'd like to control a CameraControls instance as tweens, you could combine a tween library,

Yeah for sure, I'm using Popmotion at the moment. Actually it was GSAP's new version that inspired me to make this request, their tweens return promises now which makes writing animations much cleaner. No more onComplete everywhere.

Because, damping animation can combine multiple input dynamically, unlike time-based fixed animation.

Yeah, this is the difficult one for knowing when an animation has completed. I explored the code a bit more since I made this issue and I see why it would be a bit hard to implement.

The problem is sleep firing too late because of damping - usually it fire a number of seconds after it "looks" like the camera has stopped.

If sleep fired earlier I can just just wrap the even listener in a promise and get the behavior I want, so here's a simpler version of this feature request: can we get a way to make sleep fire sooner? Possibly adding a controls.sleepEpsilon property would work, then once the movement has become less than sleepEpsilon in a single frame, sleep will fire (but damping movement should still continue to zero).

Another alternative would be a completely new event that fires before sleep but when the movement is less than some epsilon in a single frame.

@yomotsu
Copy link
Owner

yomotsu commented Aug 22, 2021

The problem is sleep firing too late

Yeah, actually I think so...
sleep events may not fit UI controls.

Possibly adding a controls.sleepEpsilon property would work, then once the movement has become less than sleepEpsilon in a single frame, sleep will fire (but damping movement should still continue to zero).

Another alternative would be a completely new event that fires before sleep but when the movement is less than some epsilon in a single frame.

Both sound good!
How about adding a new event with the epsilon parameter? Like REM-sleep (the name REM is kinda joking and we should figure out a better name though, I guess)

@looeee
Copy link
Contributor Author

looeee commented Aug 23, 2021

Haha love it 😄

Maybe rest? So the camera comes to rest, then goes to sleep.

@yomotsu
Copy link
Owner

yomotsu commented Aug 23, 2021

Make sense!
Let's add rest event and restThreshold for the epsilon.

Are you interested in contributing to the code? or maybe next?
If you don't have time, I can do it at this time.

@looeee
Copy link
Contributor Author

looeee commented Aug 23, 2021

I can do it if you don't mind waiting for a few days :)

@yomotsu
Copy link
Owner

yomotsu commented Aug 23, 2021

Cool!
If you have any questions, feel free to ask me.

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

No branches or pull requests

2 participants