https://github.com/looeee/three.time
Drop in replacement for the three.js clock available as an NPM module. Fixes several issues with the existing clock.
https://github.com/looeee/three.time
3d-graphics stopwatch threejs webgl webgl2
Last synced: 2 months ago
JSON representation
Drop in replacement for the three.js clock available as an NPM module. Fixes several issues with the existing clock.
- Host: GitHub
- URL: https://github.com/looeee/three.time
- Owner: looeee
- License: mit
- Created: 2018-06-21T08:52:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-12T04:36:47.000Z (over 2 years ago)
- Last Synced: 2024-05-02T05:31:55.540Z (about 1 year ago)
- Topics: 3d-graphics, stopwatch, threejs, webgl, webgl2
- Language: JavaScript
- Homepage:
- Size: 6.96 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Three-time module by [Discover three.js](https://discoverthreejs.com/)
Replacement for THREE.CLock with some extra features and cleaner syntax. The main extra feature is that you can set the Timescale, allowing for slow motion effects in your animations.
Note that there is nothing actually related to three.js in the code, so you can use this in any application that needs a simple timer function.
## Installation
`npm install three-time`
## Usage
```js
import Time from 'three-time';const time = new Time();
// start timer, or continue if paused
// unlike THREE.Clock, there is no autostart so you always need to call this
time.start();// pause timer
time.pause();// stop and reset timer, doesn't reset timescale
time.stop();// set timescale, values above 1 speed up time, values below 1 slow down time
time.timeScale = 1;// total running time of const totalScaledTimeSinceStart = time.totalTime();, taking into account timescale changes
const totalScaledTimeSinceStart = time.totalTime();// total real world time since timer was started
const totalRealTimeSinceStart = time.totalTime();// current value of Performance.now with fallback to Date.now
const now = time.now;// A typical three.js animation loop:
function animate() {requestAnimationFrame( animate );
// time since last time delta was called, taking into account time scale
const delta = time.delta;// OR
// real world time since last time delta was called, ignoring time scale
const unscaledDelta = time.unscaledDelta;// NB delta and scaledDelta are not independent, don't call both in the same frame
animation.update( delta );
}
```All code is MIT licensed and free to use, modify, or distribute in any way that you wish. Have fun!