-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Added THREE.Timer. #17912
Added THREE.Timer. #17912
Conversation
I like it! Just a question, what is the expected use of |
Um, it's probably better to make
|
So in that case I agree on making |
I think |
In what situations would you want to use |
It's actually useful for testing and debugging if a timer can produce deterministic values. |
Okay, I've shorten the method names and variables. |
Nice. Is there a reason you've chosen to add a separate "update()" call? I.e. why not update the timer when "getDelta()" is called like the current Clock? |
Because many users complained about the fact that multiple calls of To avoid these design problems, the state of the timer is now explicitly updated by calling |
would you mind elaborate that how the Timer solves this "design flaw" of Clock #26806 (comment)? any help is appreciated. |
Updating the timer per frame before querying data is the intended usage. |
I've seen projects in the past copying this code or use an adapted version of it so I think it's better to provide an alternative to |
Just curious: why was this removed in d443665? 🤔 |
How about adding it to core now, with documentation? Then, deprecate If you don't want to do that now, how about adding the above comprehensive description to the header of |
I was unsure about this feature since the parameter has no effect when a fixed time delta is used. Besides, I couldn't decide how the parameter should play together with That said, not including a timestamp parameter in this PR does not mean we shouldn't support it. I just had the feeling this needs more discussion. A separate PR adding
That sounds good to me! |
Done! 46b6bb0 For |
Sorry for the huge delay dealing with this... 🙏 |
Hmmm... I'm not sure about the API for fixedTime. |
* Added THREE.Timer. * Timer: Make now() private. * Timer: Fix typo. * Timer: Shorten method and variable names. * Timer: Remove js and add d.ts file. * Timer: Transform to class. * Update webgl_morphtargets_sphere.html * Delete Timer.d.ts * Update webgl_morphtargets_sphere.html * Timer: Add optional timestamp parameter to update(). * Timer: Fix multiple instance usage. * Timer: Clean up.
Related #17679
This is a new alternative to
THREE.Clock
with a different API design and behavior. It should make it easier to implementthree.js
apps FPS independent which becomes more and more important with faster refresh rates.Background: Some time ago, I've realized on a 144 Hz gaming laptop that (at least in Chrome and Firefox) WebGL apps run with 144 FPS. Some
three.js
examples now look weird because they assume fix update steps (around 60 FPS). Since certain laptops already offer 240 Hz screens, I think we should reconsider how a time class works. The main differences ofTHREE.Timer
compared toTHREE.Clock
are:THREE.Timer
has an update method that updates its internal state..getDeltaTime()
and.getElapsedTime()
multiple times per simulation step without getting different values.Time
interface).THREE.Timer
is located inexamples/jsm/misc/
for now. I personally thinkTHREE.Timer
(or a similar class) should replaceTHREE.Clock
at some point since the class has some conceptual design flaws. The example webgl_morphtargets_sphere already usesTHREE.Timer
in order to replace the existing FPS workaround.The method names are quite descriptive now. If e.g.
getDelta()
is preferred overgetDeltaTime()
, I'm happy to shorten the names.