ShadowEditor/web/src/polyfills.js
2020-05-01 09:07:57 +08:00

51 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

window.URL = window.URL || window.webkitURL;
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder;
Number.prototype.format = function () {
return this.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
};
String.prototype.format = function () {
var str = this;
for (var i = 0; i < arguments.length; i++) {
str = str.replace('{' + i + '}', arguments[i]);
}
return str;
};
// 在一个渲染循环中getDelta和getElapsedTime只能调用一次否则会导致动画异常。
// 这里改成可以调用多次避免产生各种奇怪的bug。
THREE.Clock.prototype._getDelta = function () {
var diff = 0;
if (this.autoStart && !this.running) {
this.start();
return 0;
}
if (this.running) {
var newTime = (typeof performance === 'undefined' ? Date : performance).now();
diff = (newTime - this.oldTime) / 1000;
this.oldTime = newTime;
this.elapsedTime += diff;
}
this.deltaTime = diff;
return diff;
};
THREE.Clock.prototype.getDelta = function () {
return this.deltaTime ? this.deltaTime : 0;
};
THREE.Clock.prototype.getElapsedTime = function () {
return this.elapsedTime;
};