three-stdlib 2.21.0 → 2.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1 -1
- package/misc/Timer.cjs.js +1 -0
- package/misc/Timer.d.ts +26 -0
- package/misc/Timer.js +120 -0
- package/package.json +1 -1
- package/renderers/CSS2DRenderer.js +4 -1
- package/webxr/XRControllerModelFactory.cjs.js +1 -1
- package/webxr/XRControllerModelFactory.js +13 -5
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var i=e(require("@babel/runtime/helpers/defineProperty"));function t(){!1===document.hidden&&this.reset()}exports.Timer=class{constructor(){i.default(this,"_previousTime",void 0),i.default(this,"_currentTime",void 0),i.default(this,"_delta",void 0),i.default(this,"_elapsed",void 0),i.default(this,"_timescale",void 0),i.default(this,"_useFixedDelta",void 0),i.default(this,"_fixedDelta",void 0),i.default(this,"_usePageVisibilityAPI",void 0),i.default(this,"_pageVisibilityHandler",void 0),this._previousTime=0,this._currentTime=0,this._delta=0,this._elapsed=0,this._timescale=1,this._useFixedDelta=!1,this._fixedDelta=16.67,this._usePageVisibilityAPI="undefined"!=typeof document&&void 0!==document.hidden}connect(){return this._usePageVisibilityAPI&&(this._pageVisibilityHandler=t.bind(this),document.addEventListener("visibilitychange",this._pageVisibilityHandler,!1)),this}dispose(){return this._usePageVisibilityAPI&&this._pageVisibilityHandler&&document.removeEventListener("visibilitychange",this._pageVisibilityHandler),this}disableFixedDelta(){return this._useFixedDelta=!1,this}enableFixedDelta(){return this._useFixedDelta=!0,this}getDelta(){return this._delta/1e3}getElapsed(){return this._elapsed/1e3}getFixedDelta(){return this._fixedDelta/1e3}getTimescale(){return this._timescale}reset(){return this._currentTime=this._now(),this}setFixedDelta(e){return this._fixedDelta=1e3*e,this}setTimescale(e){return this._timescale=e,this}update(){return!0===this._useFixedDelta?this._delta=this._fixedDelta:(this._previousTime=this._currentTime,this._currentTime=this._now(),this._delta=this._currentTime-this._previousTime),this._delta*=this._timescale,this._elapsed+=this._delta,this}_now(){return("undefined"==typeof performance?Date:performance).now()}};
|
package/misc/Timer.d.ts
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
declare class Timer {
|
2
|
+
private _previousTime;
|
3
|
+
private _currentTime;
|
4
|
+
private _delta;
|
5
|
+
private _elapsed;
|
6
|
+
private _timescale;
|
7
|
+
private _useFixedDelta;
|
8
|
+
private _fixedDelta;
|
9
|
+
private _usePageVisibilityAPI;
|
10
|
+
private _pageVisibilityHandler;
|
11
|
+
constructor();
|
12
|
+
connect(): this;
|
13
|
+
dispose(): this;
|
14
|
+
disableFixedDelta(): this;
|
15
|
+
enableFixedDelta(): this;
|
16
|
+
getDelta(): number;
|
17
|
+
getElapsed(): number;
|
18
|
+
getFixedDelta(): number;
|
19
|
+
getTimescale(): number;
|
20
|
+
reset(): this;
|
21
|
+
setFixedDelta(fixedDelta: number): this;
|
22
|
+
setTimescale(timescale: number): this;
|
23
|
+
update(): this;
|
24
|
+
private _now;
|
25
|
+
}
|
26
|
+
export { Timer };
|
package/misc/Timer.js
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
|
+
|
3
|
+
class Timer {
|
4
|
+
constructor() {
|
5
|
+
_defineProperty(this, "_previousTime", void 0);
|
6
|
+
|
7
|
+
_defineProperty(this, "_currentTime", void 0);
|
8
|
+
|
9
|
+
_defineProperty(this, "_delta", void 0);
|
10
|
+
|
11
|
+
_defineProperty(this, "_elapsed", void 0);
|
12
|
+
|
13
|
+
_defineProperty(this, "_timescale", void 0);
|
14
|
+
|
15
|
+
_defineProperty(this, "_useFixedDelta", void 0);
|
16
|
+
|
17
|
+
_defineProperty(this, "_fixedDelta", void 0);
|
18
|
+
|
19
|
+
_defineProperty(this, "_usePageVisibilityAPI", void 0);
|
20
|
+
|
21
|
+
_defineProperty(this, "_pageVisibilityHandler", void 0);
|
22
|
+
|
23
|
+
this._previousTime = 0;
|
24
|
+
this._currentTime = 0;
|
25
|
+
this._delta = 0;
|
26
|
+
this._elapsed = 0;
|
27
|
+
this._timescale = 1;
|
28
|
+
this._useFixedDelta = false;
|
29
|
+
this._fixedDelta = 16.67; // ms, corresponds to approx. 60 FPS
|
30
|
+
|
31
|
+
this._usePageVisibilityAPI = typeof document !== 'undefined' && document.hidden !== undefined;
|
32
|
+
} // https://github.com/mrdoob/three.js/issues/20575
|
33
|
+
// use Page Visibility API to avoid large time delta values
|
34
|
+
|
35
|
+
|
36
|
+
connect() {
|
37
|
+
if (this._usePageVisibilityAPI) {
|
38
|
+
this._pageVisibilityHandler = handleVisibilityChange.bind(this);
|
39
|
+
document.addEventListener('visibilitychange', this._pageVisibilityHandler, false);
|
40
|
+
}
|
41
|
+
|
42
|
+
return this;
|
43
|
+
}
|
44
|
+
|
45
|
+
dispose() {
|
46
|
+
if (this._usePageVisibilityAPI && this._pageVisibilityHandler) {
|
47
|
+
document.removeEventListener('visibilitychange', this._pageVisibilityHandler);
|
48
|
+
}
|
49
|
+
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
|
53
|
+
disableFixedDelta() {
|
54
|
+
this._useFixedDelta = false;
|
55
|
+
return this;
|
56
|
+
}
|
57
|
+
|
58
|
+
enableFixedDelta() {
|
59
|
+
this._useFixedDelta = true;
|
60
|
+
return this;
|
61
|
+
}
|
62
|
+
|
63
|
+
getDelta() {
|
64
|
+
return this._delta / 1000;
|
65
|
+
}
|
66
|
+
|
67
|
+
getElapsed() {
|
68
|
+
return this._elapsed / 1000;
|
69
|
+
}
|
70
|
+
|
71
|
+
getFixedDelta() {
|
72
|
+
return this._fixedDelta / 1000;
|
73
|
+
}
|
74
|
+
|
75
|
+
getTimescale() {
|
76
|
+
return this._timescale;
|
77
|
+
}
|
78
|
+
|
79
|
+
reset() {
|
80
|
+
this._currentTime = this._now();
|
81
|
+
return this;
|
82
|
+
}
|
83
|
+
|
84
|
+
setFixedDelta(fixedDelta) {
|
85
|
+
this._fixedDelta = fixedDelta * 1000;
|
86
|
+
return this;
|
87
|
+
}
|
88
|
+
|
89
|
+
setTimescale(timescale) {
|
90
|
+
this._timescale = timescale;
|
91
|
+
return this;
|
92
|
+
}
|
93
|
+
|
94
|
+
update() {
|
95
|
+
if (this._useFixedDelta === true) {
|
96
|
+
this._delta = this._fixedDelta;
|
97
|
+
} else {
|
98
|
+
this._previousTime = this._currentTime;
|
99
|
+
this._currentTime = this._now();
|
100
|
+
this._delta = this._currentTime - this._previousTime;
|
101
|
+
}
|
102
|
+
|
103
|
+
this._delta *= this._timescale;
|
104
|
+
this._elapsed += this._delta; // _elapsed is the accumulation of all previous deltas
|
105
|
+
|
106
|
+
return this;
|
107
|
+
} // private
|
108
|
+
|
109
|
+
|
110
|
+
_now() {
|
111
|
+
return (typeof performance === 'undefined' ? Date : performance).now();
|
112
|
+
}
|
113
|
+
|
114
|
+
}
|
115
|
+
|
116
|
+
function handleVisibilityChange() {
|
117
|
+
if (document.hidden === false) this.reset();
|
118
|
+
}
|
119
|
+
|
120
|
+
export { Timer };
|
package/package.json
CHANGED
@@ -59,7 +59,10 @@ class CSS2DRenderer {
|
|
59
59
|
|
60
60
|
this.render = function (scene, camera) {
|
61
61
|
if (scene.matrixWorldAutoUpdate === true || scene.autoUpdate === true) scene.updateMatrixWorld();
|
62
|
-
|
62
|
+
|
63
|
+
if (camera.parent === null && (camera.matrixWorldAutoUpdate == null || camera.matrixWorldAutoUpdate === true)) {
|
64
|
+
camera.updateMatrixWorld();
|
65
|
+
}
|
63
66
|
|
64
67
|
_viewMatrix.copy(camera.matrixWorldInverse);
|
65
68
|
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),o=require("three"),t=require("../loaders/GLTFLoader.cjs.js"),n=require("../libs/MotionControllers.cjs.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e);const a=(e,t)=>{t.traverse((t=>{t instanceof o.Mesh&&"envMap"in t.material&&(t.material.envMap=e,t.material.needsUpdate=!0)}))};class
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/defineProperty"),o=require("three"),t=require("../loaders/GLTFLoader.cjs.js"),n=require("../libs/MotionControllers.cjs.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=r(e);const a=(e,t)=>{t.traverse((t=>{t instanceof o.Mesh&&"envMap"in t.material&&(t.material.envMap=e,t.material.needsUpdate=!0)}))};class i extends o.Object3D{constructor(){super(),s.default(this,"envMap",void 0),s.default(this,"motionController",void 0),this.motionController=null,this.envMap=null}setEnvironmentMap(e){return this.envMap==e||(this.envMap=e,a(this.envMap,this)),this}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&(this.motionController.updateFromGamepad(),Object.values(this.motionController.components).forEach((e=>{Object.values(e.visualResponses).forEach((e=>{const{valueNode:o,minNode:t,maxNode:r,value:s,valueNodeProperty:a}=e;o&&(a===n.MotionControllerConstants.VisualResponseProperty.VISIBILITY&&"boolean"==typeof s?o.visible=s:a===n.MotionControllerConstants.VisualResponseProperty.TRANSFORM&&t&&r&&"number"==typeof s&&(o.quaternion.slerpQuaternions(t.quaternion,r.quaternion,s),o.position.lerpVectors(t.position,r.position,s)))}))})))}}function l(e,t){!function(e,t){Object.values(e.components).forEach((e=>{const{type:r,touchPointNodeName:s,visualResponses:a}=e;if(r===n.MotionControllerConstants.ComponentType.TOUCHPAD&&s)if(e.touchPointNode=t.getObjectByName(s),e.touchPointNode){const t=new o.SphereGeometry(.001),n=new o.MeshBasicMaterial({color:255}),r=new o.Mesh(t,n);e.touchPointNode.add(r)}else console.warn(`Could not find touch dot, ${e.touchPointNodeName}, in touchpad component ${e.id}`);Object.values(a).forEach((e=>{const{valueNodeName:o,minNodeName:r,maxNodeName:s,valueNodeProperty:a}=e;if(a===n.MotionControllerConstants.VisualResponseProperty.TRANSFORM&&r&&s){if(e.minNode=t.getObjectByName(r),e.maxNode=t.getObjectByName(s),!e.minNode)return void console.warn(`Could not find ${r} in the model`);if(!e.maxNode)return void console.warn(`Could not find ${s} in the model`)}e.valueNode=t.getObjectByName(o),e.valueNode||console.warn(`Could not find ${o} in the model`)}))}))}(e.motionController,t),e.envMap&&a(e.envMap,t),e.add(t)}exports.XRControllerModelFactory=class{constructor(e=null){s.default(this,"gltfLoader",void 0),s.default(this,"path",void 0),s.default(this,"_assetCache",void 0),this.gltfLoader=e,this.path="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",this._assetCache={},this.gltfLoader||(this.gltfLoader=new t.GLTFLoader)}createControllerModel(e){const o=new i;let t=null;const r=e=>{const r=e.data;"tracked-pointer"===r.targetRayMode&&r.gamepad&&n.fetchProfile(r,this.path,"generic-trigger").then((({profile:e,assetPath:s})=>{if(!s)throw new Error("no asset path");o.motionController=new n.MotionController(r,e,s);const a=o.motionController.assetUrl,i=this._assetCache[a];if(i)t=i.scene.clone(),l(o,t);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(o.motionController.assetUrl,(e=>{o.motionController?(this._assetCache[a]=e,t=e.scene.clone(),l(o,t)):console.warn("motionController gone while gltf load, bailing...")}),null,(()=>{throw new Error(`Asset ${a} missing or malformed.`)}))}})).catch((e=>{console.warn(e)}))};e.addEventListener("connected",r);const s=()=>{e.removeEventListener("connected",r),e.removeEventListener("disconnected",s),o.motionController=null,t&&o.remove(t),t=null};return e.addEventListener("disconnected",s),o}};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
2
|
import { Object3D, Mesh, SphereGeometry, MeshBasicMaterial } from 'three';
|
3
3
|
import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
4
|
-
import { fetchProfile, MotionController
|
4
|
+
import { MotionControllerConstants, fetchProfile, MotionController } from '../libs/MotionControllers.js';
|
5
5
|
|
6
6
|
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles';
|
7
7
|
const DEFAULT_PROFILE = 'generic-trigger';
|
@@ -171,7 +171,8 @@ class XRControllerModelFactory {
|
|
171
171
|
createControllerModel(controller) {
|
172
172
|
const controllerModel = new XRControllerModel();
|
173
173
|
let scene = null;
|
174
|
-
|
174
|
+
|
175
|
+
const onConnected = event => {
|
175
176
|
const xrInputSource = event.data;
|
176
177
|
if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad) return;
|
177
178
|
fetchProfile(xrInputSource, this.path, DEFAULT_PROFILE).then(({
|
@@ -211,8 +212,13 @@ class XRControllerModelFactory {
|
|
211
212
|
}).catch(err => {
|
212
213
|
console.warn(err);
|
213
214
|
});
|
214
|
-
}
|
215
|
-
|
215
|
+
};
|
216
|
+
|
217
|
+
controller.addEventListener('connected', onConnected);
|
218
|
+
|
219
|
+
const onDisconnected = () => {
|
220
|
+
controller.removeEventListener('connected', onConnected);
|
221
|
+
controller.removeEventListener('disconnected', onDisconnected);
|
216
222
|
controllerModel.motionController = null;
|
217
223
|
|
218
224
|
if (scene) {
|
@@ -220,7 +226,9 @@ class XRControllerModelFactory {
|
|
220
226
|
}
|
221
227
|
|
222
228
|
scene = null;
|
223
|
-
}
|
229
|
+
};
|
230
|
+
|
231
|
+
controller.addEventListener('disconnected', onDisconnected);
|
224
232
|
return controllerModel;
|
225
233
|
}
|
226
234
|
|