three-stdlib 2.20.4 → 2.21.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.cjs.js +1 -1
- package/index.d.ts +1 -0
- package/libs/MotionControllers.cjs.js +1 -1
- package/libs/MotionControllers.d.ts +132 -0
- package/libs/MotionControllers.js +65 -13
- package/package.json +1 -1
- package/renderers/CSS2DRenderer.cjs.js +1 -1
- package/renderers/CSS2DRenderer.js +124 -99
- package/webxr/XRControllerModelFactory.cjs.js +1 -1
- package/webxr/XRControllerModelFactory.d.ts +12 -12
- package/webxr/XRControllerModelFactory.js +46 -21
@@ -1,13 +1,28 @@
|
|
1
|
-
import
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
|
+
import { Object3D, Mesh, SphereGeometry, MeshBasicMaterial } from 'three';
|
2
3
|
import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
3
4
|
import { fetchProfile, MotionController, MotionControllerConstants } from '../libs/MotionControllers.js';
|
4
5
|
|
5
6
|
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles';
|
6
7
|
const DEFAULT_PROFILE = 'generic-trigger';
|
7
8
|
|
9
|
+
const applyEnvironmentMap = (envMap, obj) => {
|
10
|
+
obj.traverse(child => {
|
11
|
+
if (child instanceof Mesh && 'envMap' in child.material) {
|
12
|
+
child.material.envMap = envMap;
|
13
|
+
child.material.needsUpdate = true;
|
14
|
+
}
|
15
|
+
});
|
16
|
+
};
|
17
|
+
|
8
18
|
class XRControllerModel extends Object3D {
|
9
19
|
constructor() {
|
10
20
|
super();
|
21
|
+
|
22
|
+
_defineProperty(this, "envMap", void 0);
|
23
|
+
|
24
|
+
_defineProperty(this, "motionController", void 0);
|
25
|
+
|
11
26
|
this.motionController = null;
|
12
27
|
this.envMap = null;
|
13
28
|
}
|
@@ -18,12 +33,7 @@ class XRControllerModel extends Object3D {
|
|
18
33
|
}
|
19
34
|
|
20
35
|
this.envMap = envMap;
|
21
|
-
this.
|
22
|
-
if (child.isMesh) {
|
23
|
-
child.material.envMap = this.envMap;
|
24
|
-
child.material.needsUpdate = true;
|
25
|
-
}
|
26
|
-
});
|
36
|
+
applyEnvironmentMap(this.envMap, this);
|
27
37
|
return this;
|
28
38
|
}
|
29
39
|
/**
|
@@ -52,9 +62,9 @@ class XRControllerModel extends Object3D {
|
|
52
62
|
|
53
63
|
if (!valueNode) return; // Calculate the new properties based on the weight supplied
|
54
64
|
|
55
|
-
if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.VISIBILITY) {
|
65
|
+
if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.VISIBILITY && typeof value === 'boolean') {
|
56
66
|
valueNode.visible = value;
|
57
|
-
} else if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM) {
|
67
|
+
} else if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM && minNode && maxNode && typeof value === 'number') {
|
58
68
|
valueNode.quaternion.slerpQuaternions(minNode.quaternion, maxNode.quaternion, value);
|
59
69
|
valueNode.position.lerpVectors(minNode.position, maxNode.position, value);
|
60
70
|
}
|
@@ -79,7 +89,7 @@ function findNodes(motionController, scene) {
|
|
79
89
|
visualResponses
|
80
90
|
} = component;
|
81
91
|
|
82
|
-
if (type === MotionControllerConstants.ComponentType.TOUCHPAD) {
|
92
|
+
if (type === MotionControllerConstants.ComponentType.TOUCHPAD && touchPointNodeName) {
|
83
93
|
component.touchPointNode = scene.getObjectByName(touchPointNodeName);
|
84
94
|
|
85
95
|
if (component.touchPointNode) {
|
@@ -104,7 +114,7 @@ function findNodes(motionController, scene) {
|
|
104
114
|
valueNodeProperty
|
105
115
|
} = visualResponse; // If animating a transform, find the two nodes to be interpolated between.
|
106
116
|
|
107
|
-
if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM) {
|
117
|
+
if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM && minNodeName && maxNodeName) {
|
108
118
|
visualResponse.minNode = scene.getObjectByName(minNodeName);
|
109
119
|
visualResponse.maxNode = scene.getObjectByName(maxNodeName); // If the extents cannot be found, skip this animation
|
110
120
|
|
@@ -134,12 +144,7 @@ function addAssetSceneToControllerModel(controllerModel, scene) {
|
|
134
144
|
findNodes(controllerModel.motionController, scene); // Apply any environment map that the mesh already has set.
|
135
145
|
|
136
146
|
if (controllerModel.envMap) {
|
137
|
-
|
138
|
-
if (child.isMesh) {
|
139
|
-
child.material.envMap = controllerModel.envMap;
|
140
|
-
child.material.needsUpdate = true;
|
141
|
-
}
|
142
|
-
});
|
147
|
+
applyEnvironmentMap(controllerModel.envMap, scene);
|
143
148
|
} // Add the glTF scene to the controllerModel.
|
144
149
|
|
145
150
|
|
@@ -148,6 +153,12 @@ function addAssetSceneToControllerModel(controllerModel, scene) {
|
|
148
153
|
|
149
154
|
class XRControllerModelFactory {
|
150
155
|
constructor(gltfLoader = null) {
|
156
|
+
_defineProperty(this, "gltfLoader", void 0);
|
157
|
+
|
158
|
+
_defineProperty(this, "path", void 0);
|
159
|
+
|
160
|
+
_defineProperty(this, "_assetCache", void 0);
|
161
|
+
|
151
162
|
this.gltfLoader = gltfLoader;
|
152
163
|
this.path = DEFAULT_PROFILES_PATH;
|
153
164
|
this._assetCache = {}; // If a GLTFLoader wasn't supplied to the constructor create a new one.
|
@@ -167,8 +178,13 @@ class XRControllerModelFactory {
|
|
167
178
|
profile,
|
168
179
|
assetPath
|
169
180
|
}) => {
|
181
|
+
if (!assetPath) {
|
182
|
+
throw new Error('no asset path');
|
183
|
+
}
|
184
|
+
|
170
185
|
controllerModel.motionController = new MotionController(xrInputSource, profile, assetPath);
|
171
|
-
const
|
186
|
+
const assetUrl = controllerModel.motionController.assetUrl;
|
187
|
+
const cachedAsset = this._assetCache[assetUrl];
|
172
188
|
|
173
189
|
if (cachedAsset) {
|
174
190
|
scene = cachedAsset.scene.clone();
|
@@ -180,11 +196,16 @@ class XRControllerModelFactory {
|
|
180
196
|
|
181
197
|
this.gltfLoader.setPath('');
|
182
198
|
this.gltfLoader.load(controllerModel.motionController.assetUrl, asset => {
|
183
|
-
|
199
|
+
if (!controllerModel.motionController) {
|
200
|
+
console.warn('motionController gone while gltf load, bailing...');
|
201
|
+
return;
|
202
|
+
}
|
203
|
+
|
204
|
+
this._assetCache[assetUrl] = asset;
|
184
205
|
scene = asset.scene.clone();
|
185
206
|
addAssetSceneToControllerModel(controllerModel, scene);
|
186
207
|
}, null, () => {
|
187
|
-
throw new Error(`Asset ${
|
208
|
+
throw new Error(`Asset ${assetUrl} missing or malformed.`);
|
188
209
|
});
|
189
210
|
}
|
190
211
|
}).catch(err => {
|
@@ -193,7 +214,11 @@ class XRControllerModelFactory {
|
|
193
214
|
});
|
194
215
|
controller.addEventListener('disconnected', () => {
|
195
216
|
controllerModel.motionController = null;
|
196
|
-
|
217
|
+
|
218
|
+
if (scene) {
|
219
|
+
controllerModel.remove(scene);
|
220
|
+
}
|
221
|
+
|
197
222
|
scene = null;
|
198
223
|
});
|
199
224
|
return controllerModel;
|