three.js: Clock (start, getDelta) broken in Node.js r74, 'performance.now' not defined
The functionality of THREE.Clock broke in release r74 when attempting to run in Node.js (installed via npm package ‘three’). Functions like .start() & .getDelta() complain about ReferenceError: performance is not defined (as in performance.now()).
I might be missing something, but it would seem the changes in 71ddb80818c504028a0cd1dd4c61de0edaa237a8 removed the polyfill for performance.now necessary to run THREE (Clock) in Node; as far as I can tell, Node.js doesn’t have a global performance implemented.
I am not sure if/how much issues #7787, or #7800 are involved.
Running w/ r74 (current broken state):
$ node
> var THREE = require('three');
undefined
> var myclock = new THREE.Clock();
undefined
> myclock.start()
ReferenceError: performance is not defined
at THREE.Clock.start (/data/users/rlinsalata/workspaces/js_ws/node_playground/node_modules/three/three.js:7911:20)
at repl:1:10
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
at ReadStream.EventEmitter.emit (events.js:98:17)
> myclock.getDelta()
ReferenceError: performance is not defined
at THREE.Clock.start (/data/users/rlinsalata/workspaces/js_ws/node_playground/node_modules/three/three.js:7911:20)
at THREE.Clock.getDelta (/data/users/rlinsalata/workspaces/js_ws/node_playground/node_modules/three/three.js:7938:9)
at repl:1:10
at REPLServer.self.eval (repl.js:110:21)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
at Interface._line (readline.js:531:8)
at Interface._ttyWrite (readline.js:760:14)
at ReadStream.onkeypress (readline.js:99:10)
> THREE.REVISION
'74'
Running w/ r73 (old working state):
$ node
> var THREE = require('three');
> THREE.REVISION
'73'
> var myclock = new THREE.Clock();
> myclock.start()
> myclock.getDelta()
20.876
> myclock.getDelta()
1.437
> myclock.getDelta()
4.405
Version Info: Three version r74 npm package ‘three’ three@0.74 Node v5.2.0 Ubuntu 14.04
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (8 by maintainers)
+1
THREE.Clockdoesn’t work on iOS 8 (Chrome and Safari).For me, not working on iOS8 based devices. I have added this r73 polyfill and works again:
@Mugen87 I made a pull request #10732. Check please
@mrdoob I think we should implement @sasha240100 suggestion with a respective comment.
We use
performanceonly in these two lines in the entirethree.jscore:https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js#L23 https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js#L57
@Mugen87
( performance || Date ).now()results to error in node.( typeof performance === 'undefined' ? Date : performance ).now()works. https://github.com/mrdoob/three.js/blob/master/src/core/Clock.js#L23