-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fixes #2470 Added timer #2471
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
Fixes #2470 Added timer #2471
Conversation
src/utils/index.js
Outdated
|
|
||
| var warn = debug('utils:warn'); | ||
|
|
||
| module.exports.Timer = require('./timer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could keep this alphabetical
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, I didn't noticed O:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use THREE.Clock?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmarcos this was my first try, but the current implementation it's quite ugly (https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js) you need to call getElapsedTime() and getDelta() but you'll get different values as it will call performance.now() again. Or you call getDelta() and then access elapsedTime that doesn't seems very coherent.
Also it works with seconds instead of ms, so we need to multiply everything by 1000.
I would better stick for now with our implementation and probably open a PR in three.js but I guess it's widely used so it will break many things if we change the implementation a lot.
|
|
||
| this.animationFrameID = effect.requestAnimationFrame(this.render); | ||
| effect.render(this.object3D, this.camera); | ||
| this.time = time; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd keep the time property on the scene.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Umm do you want it even if it's accesible with this.timer.ellapsedTime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's documented, might be being used. And if browsers ever fix the behavior, it's possible we might revert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good point
src/core/scene/a-scene.js
Outdated
| var effect = this.effect; | ||
| var timeDelta = time - this.time; | ||
| this.timer.update(); | ||
| var time = this.timer.elapsedTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need intermediate vars, only used once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/utils/timer.js
Outdated
| this.running = true; | ||
| }, | ||
|
|
||
| update: function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unit tests
b2c95c1 to
9ed44ce
Compare
|
r+ from me |
|
Test added, I'm using right now |
|
Thanks! |
|
waiting for tests |
Introducing a timer to fix the problems with the
requestAnimationFrame