three-stdlib 2.8.2 → 2.8.6
Sign up to get free protection for your applications and to get access to all the features.
- package/{BufferGeometryUtils-582025b8.js → BufferGeometryUtils-1a7a235c.js} +2 -1
- package/{BufferGeometryUtils-9eb5c2e7.js → BufferGeometryUtils-971dfde3.js} +0 -0
- package/animation/MMDAnimationHelper.d.ts +17 -17
- package/animation/MMDPhysics.d.ts +3 -3
- package/csm/CSM.d.ts +47 -22
- package/csm/CSMHelper.d.ts +20 -7
- package/effects/OutlineEffect.d.ts +4 -4
- package/effects/OutlineEffect.js +8 -2
- package/exporters/GLTFExporter.js +5 -10
- package/geometries/ConvexGeometry.d.ts +1 -1
- package/geometries/ParametricGeometries.d.ts +4 -2
- package/helpers/RectAreaLightHelper.d.ts +3 -3
- package/index.cjs.js +1 -1
- package/index.d.ts +9 -4
- package/index.js +9 -4
- package/libs/MotionControllers.cjs.js +1 -0
- package/libs/MotionControllers.js +403 -0
- package/loaders/AssimpLoader.js +39 -10
- package/loaders/ColladaLoader.js +22 -5
- package/loaders/EXRLoader.js +5 -1
- package/loaders/FBXLoader.js +10 -2
- package/loaders/GLTFLoader.cjs.js +1 -1
- package/loaders/GLTFLoader.d.ts +44 -20
- package/loaders/GLTFLoader.js +0 -1
- package/loaders/LDrawLoader.d.ts +6 -0
- package/loaders/MTLLoader.d.ts +18 -18
- package/loaders/RGBMLoader.d.ts +10 -10
- package/loaders/RGBMLoader.js +253 -178
- package/loaders/SVGLoader.d.ts +5 -3
- package/loaders/SVGLoader.js +10 -5
- package/loaders/lwo/IFFParser.js +4 -1
- package/math/OBB.d.ts +1 -1
- package/misc/GPUComputationRenderer.d.ts +8 -6
- package/misc/MD2CharacterComplex.js +9 -2
- package/misc/Volume.d.ts +2 -0
- package/modifiers/CurveModifier.cjs.js +1 -1
- package/modifiers/CurveModifier.js +1 -1
- package/modifiers/EdgeSplitModifier.cjs.js +1 -1
- package/modifiers/SimplifyModifier.cjs.js +1 -1
- package/nodes/inputs/ColorNode.d.ts +2 -2
- package/nodes/inputs/TextureNode.d.ts +3 -2
- package/nodes/materials/StandardNodeMaterial.d.ts +1 -1
- package/nodes/materials/nodes/StandardNode.d.ts +1 -0
- package/nodes/utils/ColorSpaceNode.d.ts +1 -1
- package/nodes/utils/JoinNode.d.ts +1 -0
- package/objects/MarchingCubes.d.ts +12 -4
- package/objects/Reflector.d.ts +4 -2
- package/objects/ReflectorForSSRPass.d.ts +6 -6
- package/objects/Refractor.d.ts +4 -2
- package/objects/Water.d.ts +4 -3
- package/objects/Water2.d.ts +12 -3
- package/package.json +2 -3
- package/postprocessing/ClearPass.d.ts +3 -3
- package/postprocessing/SAOPass.d.ts +3 -2
- package/postprocessing/SSAARenderPass.d.ts +3 -3
- package/postprocessing/SSAOPass.d.ts +3 -2
- package/postprocessing/SSRPass.d.ts +14 -17
- package/postprocessing/TAARenderPass.d.ts +2 -2
- package/renderers/CSS2DRenderer.d.ts +5 -1
- package/renderers/CSS3DRenderer.d.ts +5 -1
- package/renderers/webgpu/WebGPUTextures.js +62 -41
- package/shaders/SSRShader.d.ts +1 -2
- package/utils/BufferGeometryUtils.cjs.js +1 -1
- package/utils/BufferGeometryUtils.js +2 -1
- package/utils/LDrawUtils.cjs.js +1 -1
- package/utils/LDrawUtils.d.ts +5 -0
- package/utils/LDrawUtils.js +1 -1
- package/utils/RoughnessMipmapper.js +5 -1
- package/utils/SceneUtils.d.ts +10 -12
- package/utils/ShadowMapViewer.js +4 -1
- package/webxr/OculusHandModel.cjs.js +1 -0
- package/webxr/OculusHandModel.d.ts +19 -0
- package/webxr/OculusHandModel.js +72 -0
- package/webxr/OculusHandPointerModel.cjs.js +1 -0
- package/webxr/OculusHandPointerModel.d.ts +63 -0
- package/webxr/OculusHandPointerModel.js +248 -0
- package/webxr/Text2D.cjs.js +1 -0
- package/webxr/Text2D.d.ts +3 -0
- package/webxr/Text2D.js +32 -0
- package/webxr/VRButton.cjs.js +1 -1
- package/webxr/VRButton.js +17 -1
- package/webxr/XRControllerModelFactory.cjs.js +1 -1
- package/webxr/XRControllerModelFactory.js +65 -66
- package/webxr/XREstimatedLight.cjs.js +1 -1
- package/webxr/XREstimatedLight.js +1 -0
- package/webxr/XRHandMeshModel.cjs.js +1 -0
- package/webxr/XRHandMeshModel.d.ts +11 -0
- package/webxr/XRHandMeshModel.js +55 -0
- package/webxr/XRHandModelFactory.cjs.js +1 -1
- package/webxr/XRHandModelFactory.d.ts +3 -3
- package/webxr/XRHandModelFactory.js +47 -50
- package/webxr/XRHandPrimitiveModel.cjs.js +1 -1
- package/webxr/XRHandPrimitiveModel.d.ts +1 -1
- package/webxr/XRHandPrimitiveModel.js +31 -41
- package/csm/Frustum.d.ts +0 -16
- package/csm/Shader.d.ts +0 -6
- package/loaders/XLoader.d.ts +0 -19
- package/shaders/FresnelShader.d.ts +0 -13
- package/shaders/ParallaxShader.d.ts +0 -20
- package/utils/RoughnessMipmapper.d.ts +0 -7
- package/webxr/XRHandOculusMeshModel.cjs.js +0 -1
- package/webxr/XRHandOculusMeshModel.d.ts +0 -23
- package/webxr/XRHandOculusMeshModel.js +0 -89
package/webxr/Text2D.js
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
import * as THREE from 'three';
|
2
|
+
|
3
|
+
function createText(message, height) {
|
4
|
+
const canvas = document.createElement('canvas');
|
5
|
+
const context = canvas.getContext('2d');
|
6
|
+
let metrics = null;
|
7
|
+
const textHeight = 100;
|
8
|
+
context.font = 'normal ' + textHeight + 'px Arial';
|
9
|
+
metrics = context.measureText(message);
|
10
|
+
const textWidth = metrics.width;
|
11
|
+
canvas.width = textWidth;
|
12
|
+
canvas.height = textHeight;
|
13
|
+
context.font = 'normal ' + textHeight + 'px Arial';
|
14
|
+
context.textAlign = 'center';
|
15
|
+
context.textBaseline = 'middle';
|
16
|
+
context.fillStyle = '#ffffff';
|
17
|
+
context.fillText(message, textWidth / 2, textHeight / 2);
|
18
|
+
const texture = new THREE.Texture(canvas);
|
19
|
+
texture.needsUpdate = true; //var spriteAlignment = new THREE.Vector2(0,0) ;
|
20
|
+
|
21
|
+
const material = new THREE.MeshBasicMaterial({
|
22
|
+
color: 0xffffff,
|
23
|
+
side: THREE.DoubleSide,
|
24
|
+
map: texture,
|
25
|
+
transparent: true
|
26
|
+
});
|
27
|
+
const geometry = new THREE.PlaneGeometry(height * textWidth / textHeight, height);
|
28
|
+
const plane = new THREE.Mesh(geometry, material);
|
29
|
+
return plane;
|
30
|
+
}
|
31
|
+
|
32
|
+
export { createText };
|
package/webxr/VRButton.cjs.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});
|
1
|
+
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("@babel/runtime/helpers/defineProperty"));class n{static createButton(e,t){t&&console.error('THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.');const o=document.createElement("button");function s(){o.style.display="",o.style.cursor="auto",o.style.left="calc(50% - 75px)",o.style.width="150px",o.onmouseenter=null,o.onmouseleave=null,o.onclick=null,o.textContent="VR NOT SUPPORTED"}function r(e){e.style.position="absolute",e.style.bottom="20px",e.style.padding="12px 6px",e.style.border="1px solid #fff",e.style.borderRadius="4px",e.style.background="rgba(0,0,0,0.1)",e.style.color="#fff",e.style.font="normal 13px sans-serif",e.style.textAlign="center",e.style.opacity="0.5",e.style.outline="none",e.style.zIndex="999"}if("xr"in navigator)return o.id="VRButton",o.style.display="none",r(o),navigator.xr.isSessionSupported("immersive-vr").then((function(t){t?function(){let t=null;async function n(n){n.addEventListener("end",s),await e.xr.setSession(n),o.textContent="EXIT VR",t=n}function s(){t.removeEventListener("end",s),o.textContent="ENTER VR",t=null}o.style.display="",o.style.cursor="pointer",o.style.left="calc(50% - 50px)",o.style.width="100px",o.textContent="ENTER VR",o.onmouseenter=function(){o.style.opacity="1.0"},o.onmouseleave=function(){o.style.opacity="0.5"},o.onclick=function(){if(null===t){const e={optionalFeatures:["local-floor","bounded-floor","hand-tracking","layers"]};navigator.xr.requestSession("immersive-vr",e).then(n)}else t.end()}}():s(),t&&n.xrSessionIsGranted&&o.click()})),o;{const e=document.createElement("a");return!1===window.isSecureContext?(e.href=document.location.href.replace(/^http:/,"https:"),e.innerHTML="WEBXR NEEDS HTTPS"):(e.href="https://immersiveweb.dev/",e.innerHTML="WEBXR NOT AVAILABLE"),e.style.left="calc(50% - 90px)",e.style.width="180px",e.style.textDecoration="none",r(e),e}}static registerSessionGrantedListener(){"xr"in navigator&&navigator.xr.addEventListener("sessiongranted",(()=>{n.xrSessionIsGranted=!0}))}}t.default(n,"xrSessionIsGranted",!1),exports.VRButton=n;
|
package/webxr/VRButton.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
2
|
+
|
1
3
|
class VRButton {
|
2
4
|
static createButton(renderer, options) {
|
3
5
|
if (options) {
|
@@ -50,7 +52,7 @@ class VRButton {
|
|
50
52
|
// ('local' is always available for immersive sessions and doesn't need to
|
51
53
|
// be requested separately.)
|
52
54
|
const sessionInit = {
|
53
|
-
optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking']
|
55
|
+
optionalFeatures: ['local-floor', 'bounded-floor', 'hand-tracking', 'layers']
|
54
56
|
};
|
55
57
|
navigator.xr.requestSession('immersive-vr', sessionInit).then(onSessionStarted);
|
56
58
|
} else {
|
@@ -95,6 +97,10 @@ class VRButton {
|
|
95
97
|
stylizeElement(button);
|
96
98
|
navigator.xr.isSessionSupported('immersive-vr').then(function (supported) {
|
97
99
|
supported ? showEnterVR() : showWebXRNotFound();
|
100
|
+
|
101
|
+
if (supported && VRButton.xrSessionIsGranted) {
|
102
|
+
button.click();
|
103
|
+
}
|
98
104
|
});
|
99
105
|
return button;
|
100
106
|
} else {
|
@@ -116,6 +122,16 @@ class VRButton {
|
|
116
122
|
}
|
117
123
|
}
|
118
124
|
|
125
|
+
static registerSessionGrantedListener() {
|
126
|
+
if ('xr' in navigator) {
|
127
|
+
navigator.xr.addEventListener('sessiongranted', () => {
|
128
|
+
VRButton.xrSessionIsGranted = true;
|
129
|
+
});
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
119
133
|
}
|
120
134
|
|
135
|
+
_defineProperty(VRButton, "xrSessionIsGranted", false);
|
136
|
+
|
121
137
|
export { VRButton };
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),o=require("../loaders/GLTFLoader.cjs.js"),t=require("../libs/MotionControllers.cjs.js");class n extends e.Object3D{constructor(){super(),this.motionController=null,this.envMap=null}setEnvironmentMap(e){return this.envMap==e||(this.envMap=e,this.traverse((e=>{e.isMesh&&(e.material.envMap=this.envMap,e.material.needsUpdate=!0)}))),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:n,maxNode:r,value:s,valueNodeProperty:a}=e;o&&(a===t.MotionControllerConstants.VisualResponseProperty.VISIBILITY?o.visible=s:a===t.MotionControllerConstants.VisualResponseProperty.TRANSFORM&&(o.quaternion.slerpQuaternions(n.quaternion,r.quaternion,s),o.position.lerpVectors(n.position,r.position,s)))}))})))}}function r(o,n){!function(o,n){Object.values(o.components).forEach((o=>{const{type:r,touchPointNodeName:s,visualResponses:a}=o;if(r===t.MotionControllerConstants.ComponentType.TOUCHPAD)if(o.touchPointNode=n.getObjectByName(s),o.touchPointNode){const t=new e.SphereGeometry(.001),n=new e.MeshBasicMaterial({color:255}),r=new e.Mesh(t,n);o.touchPointNode.add(r)}else console.warn(`Could not find touch dot, ${o.touchPointNodeName}, in touchpad component ${o.id}`);Object.values(a).forEach((e=>{const{valueNodeName:o,minNodeName:r,maxNodeName:s,valueNodeProperty:a}=e;if(a===t.MotionControllerConstants.VisualResponseProperty.TRANSFORM){if(e.minNode=n.getObjectByName(r),e.maxNode=n.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=n.getObjectByName(o),e.valueNode||console.warn(`Could not find ${o} in the model`)}))}))}(o.motionController,n),o.envMap&&n.traverse((e=>{e.isMesh&&(e.material.envMap=o.envMap,e.material.needsUpdate=!0)})),o.add(n)}exports.XRControllerModelFactory=class{constructor(e=null){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 o.GLTFLoader)}createControllerModel(e){const o=new n;let s=null;return e.addEventListener("connected",(e=>{const n=e.data;"tracked-pointer"===n.targetRayMode&&n.gamepad&&t.fetchProfile(n,this.path,"generic-trigger").then((({profile:e,assetPath:a})=>{o.motionController=new t.MotionController(n,e,a);const l=this._assetCache[o.motionController.assetUrl];if(l)s=l.scene.clone(),r(o,s);else{if(!this.gltfLoader)throw new Error("GLTFLoader not set.");this.gltfLoader.setPath(""),this.gltfLoader.load(o.motionController.assetUrl,(e=>{this._assetCache[o.motionController.assetUrl]=e,s=e.scene.clone(),r(o,s)}),null,(()=>{throw new Error(`Asset ${o.motionController.assetUrl} missing or malformed.`)}))}})).catch((e=>{console.warn(e)}))})),e.addEventListener("disconnected",(()=>{o.motionController=null,o.remove(s),s=null})),o}};
|
@@ -1,19 +1,18 @@
|
|
1
|
-
import { Object3D,
|
1
|
+
import { Object3D, SphereGeometry, MeshBasicMaterial, Mesh } from 'three';
|
2
2
|
import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
3
|
-
import {
|
3
|
+
import { fetchProfile, MotionController, MotionControllerConstants } from '../libs/MotionControllers.js';
|
4
4
|
|
5
5
|
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles';
|
6
6
|
const DEFAULT_PROFILE = 'generic-trigger';
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
class XRControllerModel extends Object3D {
|
9
|
+
constructor() {
|
10
|
+
super();
|
11
|
+
this.motionController = null;
|
12
|
+
this.envMap = null;
|
13
|
+
}
|
13
14
|
|
14
|
-
|
15
|
-
constructor: XRControllerModel,
|
16
|
-
setEnvironmentMap: function (envMap) {
|
15
|
+
setEnvironmentMap(envMap) {
|
17
16
|
if (this.envMap == envMap) {
|
18
17
|
return this;
|
19
18
|
}
|
@@ -26,14 +25,15 @@ XRControllerModel.prototype = Object.assign(Object.create(Object3D.prototype), {
|
|
26
25
|
}
|
27
26
|
});
|
28
27
|
return this;
|
29
|
-
}
|
30
|
-
|
28
|
+
}
|
31
29
|
/**
|
32
30
|
* Polls data from the XRInputSource and updates the model's components to match
|
33
31
|
* the real world data
|
34
32
|
*/
|
35
|
-
|
36
|
-
|
33
|
+
|
34
|
+
|
35
|
+
updateMatrixWorld(force) {
|
36
|
+
super.updateMatrixWorld(force);
|
37
37
|
if (!this.motionController) return; // Cause the MotionController to poll the Gamepad for data
|
38
38
|
|
39
39
|
this.motionController.updateFromGamepad(); // Update the 3D model to reflect the button, thumbstick, and touchpad state
|
@@ -52,22 +52,24 @@ XRControllerModel.prototype = Object.assign(Object.create(Object3D.prototype), {
|
|
52
52
|
|
53
53
|
if (!valueNode) return; // Calculate the new properties based on the weight supplied
|
54
54
|
|
55
|
-
if (valueNodeProperty ===
|
55
|
+
if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.VISIBILITY) {
|
56
56
|
valueNode.visible = value;
|
57
|
-
} else if (valueNodeProperty ===
|
58
|
-
|
57
|
+
} else if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM) {
|
58
|
+
valueNode.quaternion.slerpQuaternions(minNode.quaternion, maxNode.quaternion, value);
|
59
59
|
valueNode.position.lerpVectors(minNode.position, maxNode.position, value);
|
60
60
|
}
|
61
61
|
});
|
62
62
|
});
|
63
63
|
}
|
64
|
-
|
64
|
+
|
65
|
+
}
|
65
66
|
/**
|
66
67
|
* Walks the model's tree to find the nodes needed to animate the components and
|
67
68
|
* saves them to the motionContoller components for use in the frame loop. When
|
68
69
|
* touchpads are found, attaches a touch dot to them.
|
69
70
|
*/
|
70
71
|
|
72
|
+
|
71
73
|
function findNodes(motionController, scene) {
|
72
74
|
// Loop through the components and find the nodes needed for each components' visual responses
|
73
75
|
Object.values(motionController.components).forEach(component => {
|
@@ -77,7 +79,7 @@ function findNodes(motionController, scene) {
|
|
77
79
|
visualResponses
|
78
80
|
} = component;
|
79
81
|
|
80
|
-
if (type ===
|
82
|
+
if (type === MotionControllerConstants.ComponentType.TOUCHPAD) {
|
81
83
|
component.touchPointNode = scene.getObjectByName(touchPointNodeName);
|
82
84
|
|
83
85
|
if (component.touchPointNode) {
|
@@ -102,7 +104,7 @@ function findNodes(motionController, scene) {
|
|
102
104
|
valueNodeProperty
|
103
105
|
} = visualResponse; // If animating a transform, find the two nodes to be interpolated between.
|
104
106
|
|
105
|
-
if (valueNodeProperty ===
|
107
|
+
if (valueNodeProperty === MotionControllerConstants.VisualResponseProperty.TRANSFORM) {
|
106
108
|
visualResponse.minNode = scene.getObjectByName(minNodeName);
|
107
109
|
visualResponse.maxNode = scene.getObjectByName(maxNodeName); // If the extents cannot be found, skip this animation
|
108
110
|
|
@@ -144,8 +146,8 @@ function addAssetSceneToControllerModel(controllerModel, scene) {
|
|
144
146
|
controllerModel.add(scene);
|
145
147
|
}
|
146
148
|
|
147
|
-
|
148
|
-
|
149
|
+
class XRControllerModelFactory {
|
150
|
+
constructor(gltfLoader = null) {
|
149
151
|
this.gltfLoader = gltfLoader;
|
150
152
|
this.path = DEFAULT_PROFILES_PATH;
|
151
153
|
this._assetCache = {}; // If a GLTFLoader wasn't supplied to the constructor create a new one.
|
@@ -155,51 +157,48 @@ var XRControllerModelFactory = function () {
|
|
155
157
|
}
|
156
158
|
}
|
157
159
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
if (!this.gltfLoader) {
|
178
|
-
throw new Error('GLTFLoader not set.');
|
179
|
-
}
|
180
|
-
|
181
|
-
this.gltfLoader.setPath('');
|
182
|
-
this.gltfLoader.load(controllerModel.motionController.assetUrl, asset => {
|
183
|
-
this._assetCache[controllerModel.motionController.assetUrl] = asset;
|
184
|
-
scene = asset.scene.clone();
|
185
|
-
addAssetSceneToControllerModel(controllerModel, scene);
|
186
|
-
}, null, () => {
|
187
|
-
throw new Error(`Asset ${controllerModel.motionController.assetUrl} missing or malformed.`);
|
188
|
-
});
|
160
|
+
createControllerModel(controller) {
|
161
|
+
const controllerModel = new XRControllerModel();
|
162
|
+
let scene = null;
|
163
|
+
controller.addEventListener('connected', event => {
|
164
|
+
const xrInputSource = event.data;
|
165
|
+
if (xrInputSource.targetRayMode !== 'tracked-pointer' || !xrInputSource.gamepad) return;
|
166
|
+
fetchProfile(xrInputSource, this.path, DEFAULT_PROFILE).then(({
|
167
|
+
profile,
|
168
|
+
assetPath
|
169
|
+
}) => {
|
170
|
+
controllerModel.motionController = new MotionController(xrInputSource, profile, assetPath);
|
171
|
+
const cachedAsset = this._assetCache[controllerModel.motionController.assetUrl];
|
172
|
+
|
173
|
+
if (cachedAsset) {
|
174
|
+
scene = cachedAsset.scene.clone();
|
175
|
+
addAssetSceneToControllerModel(controllerModel, scene);
|
176
|
+
} else {
|
177
|
+
if (!this.gltfLoader) {
|
178
|
+
throw new Error('GLTFLoader not set.');
|
189
179
|
}
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
180
|
+
|
181
|
+
this.gltfLoader.setPath('');
|
182
|
+
this.gltfLoader.load(controllerModel.motionController.assetUrl, asset => {
|
183
|
+
this._assetCache[controllerModel.motionController.assetUrl] = asset;
|
184
|
+
scene = asset.scene.clone();
|
185
|
+
addAssetSceneToControllerModel(controllerModel, scene);
|
186
|
+
}, null, () => {
|
187
|
+
throw new Error(`Asset ${controllerModel.motionController.assetUrl} missing or malformed.`);
|
188
|
+
});
|
189
|
+
}
|
190
|
+
}).catch(err => {
|
191
|
+
console.warn(err);
|
198
192
|
});
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
193
|
+
});
|
194
|
+
controller.addEventListener('disconnected', () => {
|
195
|
+
controllerModel.motionController = null;
|
196
|
+
controllerModel.remove(scene);
|
197
|
+
scene = null;
|
198
|
+
});
|
199
|
+
return controllerModel;
|
200
|
+
}
|
201
|
+
|
202
|
+
}
|
204
203
|
|
205
204
|
export { XRControllerModelFactory };
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class i{constructor(i,e,n,s,r){this.xrLight=i,this.renderer=e,this.lightProbe=n,this.xrWebGLBinding=null,this.estimationStartCallback=r,this.frameCallback=this.onXRFrame.bind(this);const h=e.xr.getSession();if(s&&"XRWebGLBinding"in window){const n=new t.WebGLCubeRenderTarget(16);i.environment=n.texture;const s=e.getContext();switch(h.preferredReflectionFormat){case"srgba8":s.getExtension("EXT_sRGB");break;case"rgba16f":s.getExtension("OES_texture_half_float")}this.xrWebGLBinding=new XRWebGLBinding(h,s),this.lightProbe.addEventListener("reflectionchange",(()=>{this.updateReflection()}))}h.requestAnimationFrame(this.frameCallback)}updateReflection(){const t=this.renderer.properties.get(this.xrLight.environment);if(t){const i=this.xrWebGLBinding.getReflectionCubeMap(this.lightProbe);i&&(t.__webglTexture=i)}}onXRFrame(t,i){if(!this.xrLight)return;i.session.requestAnimationFrame(this.frameCallback);const e=i.getLightEstimate(this.lightProbe);if(e){this.xrLight.lightProbe.sh.fromArray(e.sphericalHarmonicsCoefficients),this.xrLight.lightProbe.intensity=1;const t=Math.max(1,Math.max(e.primaryLightIntensity.x,Math.max(e.primaryLightIntensity.y,e.primaryLightIntensity.z)));this.xrLight.directionalLight.color.setRGB(e.primaryLightIntensity.x/t,e.primaryLightIntensity.y/t,e.primaryLightIntensity.z/t),this.xrLight.directionalLight.intensity=t,this.xrLight.directionalLight.position.copy(e.primaryLightDirection),this.estimationStartCallback&&(this.estimationStartCallback(),this.estimationStartCallback=null)}}dispose(){this.xrLight=null,this.renderer=null,this.lightProbe=null,this.xrWebGLBinding=null}}class e extends t.Group{constructor(e,n=!0){super(),this.lightProbe=new t.LightProbe,this.lightProbe.intensity=0,this.add(this.lightProbe),this.directionalLight=new t.DirectionalLight,this.directionalLight.intensity=0,this.add(this.directionalLight),this.environment=null;let s=null,r=!1;e.xr.addEventListener("sessionstart",(()=>{const t=e.xr.getSession();"requestLightProbe"in t&&t.requestLightProbe({reflectionFormat:t.preferredReflectionFormat}).then((t=>{s=new i(this,e,t,n,(()=>{r=!0,this.dispatchEvent({type:"estimationstart"})}))}))})),e.xr.addEventListener("sessionend",(()=>{s&&(s.dispose(),s=null),r&&this.dispatchEvent({type:"estimationend"})})),this.dispose=()=>{s&&(s.dispose(),s=null),this.remove(this.lightProbe),this.lightProbe=null,this.remove(this.directionalLight),this.directionalLight=null,this.environment=null}}}exports.XREstimatedLight=e;
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class i{constructor(i,e,n,s,r){this.xrLight=i,this.renderer=e,this.lightProbe=n,this.xrWebGLBinding=null,this.estimationStartCallback=r,this.frameCallback=this.onXRFrame.bind(this);const h=e.xr.getSession();if(s&&"XRWebGLBinding"in window){const n=new t.WebGLCubeRenderTarget(16);i.environment=n.texture;const s=e.getContext();switch(h.preferredReflectionFormat){case"srgba8":s.getExtension("EXT_sRGB");break;case"rgba16f":s.getExtension("OES_texture_half_float")}this.xrWebGLBinding=new XRWebGLBinding(h,s),this.lightProbe.addEventListener("reflectionchange",(()=>{this.updateReflection()}))}h.requestAnimationFrame(this.frameCallback)}updateReflection(){const t=this.renderer.properties.get(this.xrLight.environment);if(t){const i=this.xrWebGLBinding.getReflectionCubeMap(this.lightProbe);i&&(t.__webglTexture=i,this.xrLight.environment.needsPMREMUpdate=!0)}}onXRFrame(t,i){if(!this.xrLight)return;i.session.requestAnimationFrame(this.frameCallback);const e=i.getLightEstimate(this.lightProbe);if(e){this.xrLight.lightProbe.sh.fromArray(e.sphericalHarmonicsCoefficients),this.xrLight.lightProbe.intensity=1;const t=Math.max(1,Math.max(e.primaryLightIntensity.x,Math.max(e.primaryLightIntensity.y,e.primaryLightIntensity.z)));this.xrLight.directionalLight.color.setRGB(e.primaryLightIntensity.x/t,e.primaryLightIntensity.y/t,e.primaryLightIntensity.z/t),this.xrLight.directionalLight.intensity=t,this.xrLight.directionalLight.position.copy(e.primaryLightDirection),this.estimationStartCallback&&(this.estimationStartCallback(),this.estimationStartCallback=null)}}dispose(){this.xrLight=null,this.renderer=null,this.lightProbe=null,this.xrWebGLBinding=null}}class e extends t.Group{constructor(e,n=!0){super(),this.lightProbe=new t.LightProbe,this.lightProbe.intensity=0,this.add(this.lightProbe),this.directionalLight=new t.DirectionalLight,this.directionalLight.intensity=0,this.add(this.directionalLight),this.environment=null;let s=null,r=!1;e.xr.addEventListener("sessionstart",(()=>{const t=e.xr.getSession();"requestLightProbe"in t&&t.requestLightProbe({reflectionFormat:t.preferredReflectionFormat}).then((t=>{s=new i(this,e,t,n,(()=>{r=!0,this.dispatchEvent({type:"estimationstart"})}))}))})),e.xr.addEventListener("sessionend",(()=>{s&&(s.dispose(),s=null),r&&this.dispatchEvent({type:"estimationend"})})),this.dispose=()=>{s&&(s.dispose(),s=null),this.remove(this.lightProbe),this.lightProbe=null,this.remove(this.directionalLight),this.directionalLight=null,this.environment=null}}}exports.XREstimatedLight=e;
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../loaders/GLTFLoader.cjs.js");require("three");exports.XRHandMeshModel=class{constructor(i,n,a,t){this.controller=n,this.handModel=i,this.bones=[];const r=new e.GLTFLoader;r.setPath(a||"https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/"),r.load(`${t}.glb`,(e=>{const i=e.scene.children[0];this.handModel.add(i);const n=i.getObjectByProperty("type","SkinnedMesh");n.frustumCulled=!1,n.castShadow=!0,n.receiveShadow=!0;["wrist","thumb-metacarpal","thumb-phalanx-proximal","thumb-phalanx-distal","thumb-tip","index-finger-metacarpal","index-finger-phalanx-proximal","index-finger-phalanx-intermediate","index-finger-phalanx-distal","index-finger-tip","middle-finger-metacarpal","middle-finger-phalanx-proximal","middle-finger-phalanx-intermediate","middle-finger-phalanx-distal","middle-finger-tip","ring-finger-metacarpal","ring-finger-phalanx-proximal","ring-finger-phalanx-intermediate","ring-finger-phalanx-distal","ring-finger-tip","pinky-finger-metacarpal","pinky-finger-phalanx-proximal","pinky-finger-phalanx-intermediate","pinky-finger-phalanx-distal","pinky-finger-tip"].forEach((e=>{const n=i.getObjectByName(e);void 0!==n?n.jointName=e:console.warn(`Couldn't find ${e} in ${t} hand mesh`),this.bones.push(n)}))}))}updateMesh(){const e=this.controller.joints;for(let i=0;i<this.bones.length;i++){const n=this.bones[i];if(n){const i=e[n.jointName];if(i.visible){const e=i.position;n.position.copy(e),n.quaternion.copy(i.quaternion)}}}}};
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Object3D } from 'three';
|
2
|
+
|
3
|
+
export class XRHandMeshModel {
|
4
|
+
controller: Object3D;
|
5
|
+
handModel: Object3D;
|
6
|
+
bones: Object3D[];
|
7
|
+
|
8
|
+
constructor(handModel: Object3D, controller: Object3D, path: string, handedness: string);
|
9
|
+
|
10
|
+
updateMesh(): void;
|
11
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { GLTFLoader } from '../loaders/GLTFLoader.js';
|
2
|
+
|
3
|
+
const DEFAULT_HAND_PROFILE_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles/generic-hand/';
|
4
|
+
|
5
|
+
class XRHandMeshModel {
|
6
|
+
constructor(handModel, controller, path, handedness) {
|
7
|
+
this.controller = controller;
|
8
|
+
this.handModel = handModel;
|
9
|
+
this.bones = [];
|
10
|
+
const loader = new GLTFLoader();
|
11
|
+
loader.setPath(path || DEFAULT_HAND_PROFILE_PATH);
|
12
|
+
loader.load(`${handedness}.glb`, gltf => {
|
13
|
+
const object = gltf.scene.children[0];
|
14
|
+
this.handModel.add(object);
|
15
|
+
const mesh = object.getObjectByProperty('type', 'SkinnedMesh');
|
16
|
+
mesh.frustumCulled = false;
|
17
|
+
mesh.castShadow = true;
|
18
|
+
mesh.receiveShadow = true;
|
19
|
+
const joints = ['wrist', 'thumb-metacarpal', 'thumb-phalanx-proximal', 'thumb-phalanx-distal', 'thumb-tip', 'index-finger-metacarpal', 'index-finger-phalanx-proximal', 'index-finger-phalanx-intermediate', 'index-finger-phalanx-distal', 'index-finger-tip', 'middle-finger-metacarpal', 'middle-finger-phalanx-proximal', 'middle-finger-phalanx-intermediate', 'middle-finger-phalanx-distal', 'middle-finger-tip', 'ring-finger-metacarpal', 'ring-finger-phalanx-proximal', 'ring-finger-phalanx-intermediate', 'ring-finger-phalanx-distal', 'ring-finger-tip', 'pinky-finger-metacarpal', 'pinky-finger-phalanx-proximal', 'pinky-finger-phalanx-intermediate', 'pinky-finger-phalanx-distal', 'pinky-finger-tip'];
|
20
|
+
joints.forEach(jointName => {
|
21
|
+
const bone = object.getObjectByName(jointName);
|
22
|
+
|
23
|
+
if (bone !== undefined) {
|
24
|
+
bone.jointName = jointName;
|
25
|
+
} else {
|
26
|
+
console.warn(`Couldn't find ${jointName} in ${handedness} hand mesh`);
|
27
|
+
}
|
28
|
+
|
29
|
+
this.bones.push(bone);
|
30
|
+
});
|
31
|
+
});
|
32
|
+
}
|
33
|
+
|
34
|
+
updateMesh() {
|
35
|
+
// XR Joints
|
36
|
+
const XRJoints = this.controller.joints;
|
37
|
+
|
38
|
+
for (let i = 0; i < this.bones.length; i++) {
|
39
|
+
const bone = this.bones[i];
|
40
|
+
|
41
|
+
if (bone) {
|
42
|
+
const XRJoint = XRJoints[bone.jointName];
|
43
|
+
|
44
|
+
if (XRJoint.visible) {
|
45
|
+
const position = XRJoint.position;
|
46
|
+
bone.position.copy(position);
|
47
|
+
bone.quaternion.copy(XRJoint.quaternion); // bone.scale.setScalar( XRJoint.jointRadius || defaultRadius );
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
}
|
54
|
+
|
55
|
+
export { XRHandMeshModel };
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./XRHandPrimitiveModel.cjs.js"),
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./XRHandPrimitiveModel.cjs.js"),r=require("./XRHandMeshModel.cjs.js");require("../loaders/GLTFLoader.cjs.js");class o extends e.Object3D{constructor(e){super(),this.controller=e,this.motionController=null,this.envMap=null,this.mesh=null}updateMatrixWorld(e){super.updateMatrixWorld(e),this.motionController&&this.motionController.updateMesh()}}exports.XRHandModelFactory=class{constructor(){this.path=null}setPath(e){return this.path=e,this}createHandModel(e,n){const s=new o(e);return e.addEventListener("connected",(o=>{const i=o.data;i.hand&&!s.motionController&&(s.xrInputSource=i,void 0===n||"spheres"===n?s.motionController=new t.XRHandPrimitiveModel(s,e,this.path,i.handedness,{primitive:"sphere"}):"boxes"===n?s.motionController=new t.XRHandPrimitiveModel(s,e,this.path,i.handedness,{primitive:"box"}):"mesh"===n&&(s.motionController=new r.XRHandMeshModel(s,e,this.path,i.handedness)))})),e.addEventListener("disconnected",(()=>{})),s}};
|
@@ -1,14 +1,14 @@
|
|
1
1
|
import { Group, Object3D } from 'three';
|
2
2
|
|
3
3
|
import { XRHandPrimitiveModel, XRHandPrimitiveModelOptions } from './XRHandPrimitiveModel';
|
4
|
-
import {
|
4
|
+
import { XRHandMeshModel } from './XRHandMeshModel';
|
5
5
|
|
6
6
|
export type XRHandModelHandedness = 'left' | 'right';
|
7
7
|
|
8
8
|
export class XRHandModel extends Object3D {
|
9
9
|
constructor();
|
10
10
|
|
11
|
-
motionController: XRHandPrimitiveModel |
|
11
|
+
motionController: XRHandPrimitiveModel | XRHandMeshModel;
|
12
12
|
}
|
13
13
|
|
14
14
|
export class XRHandModelFactory {
|
@@ -20,6 +20,6 @@ export class XRHandModelFactory {
|
|
20
20
|
createHandModel(
|
21
21
|
controller: Group,
|
22
22
|
profile?: 'spheres' | 'boxes' | 'oculus',
|
23
|
-
options?: XRHandPrimitiveModelOptions
|
23
|
+
options?: XRHandPrimitiveModelOptions,
|
24
24
|
): XRHandModel;
|
25
25
|
}
|
@@ -1,67 +1,64 @@
|
|
1
1
|
import { Object3D } from 'three';
|
2
2
|
import { XRHandPrimitiveModel } from './XRHandPrimitiveModel.js';
|
3
|
-
import {
|
3
|
+
import { XRHandMeshModel } from './XRHandMeshModel.js';
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
class XRHandModel extends Object3D {
|
6
|
+
constructor(controller) {
|
7
|
+
super();
|
8
|
+
this.controller = controller;
|
9
|
+
this.motionController = null;
|
10
|
+
this.envMap = null;
|
11
|
+
this.mesh = null;
|
12
|
+
}
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
updateMatrixWorld: function (force) {
|
16
|
-
Object3D.prototype.updateMatrixWorld.call(this, force);
|
14
|
+
updateMatrixWorld(force) {
|
15
|
+
super.updateMatrixWorld(force);
|
17
16
|
|
18
17
|
if (this.motionController) {
|
19
18
|
this.motionController.updateMesh();
|
20
19
|
}
|
21
20
|
}
|
22
|
-
});
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
}
|
23
|
+
|
24
|
+
class XRHandModelFactory {
|
25
|
+
constructor() {
|
26
|
+
this.path = null;
|
27
|
+
}
|
28
|
+
|
29
|
+
setPath(path) {
|
30
|
+
this.path = path;
|
31
|
+
return this;
|
27
32
|
}
|
28
33
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
return this;
|
34
|
-
},
|
35
|
-
createHandModel: function (controller, profile, options) {
|
36
|
-
const handModel = new XRHandModel(controller);
|
37
|
-
controller.addEventListener('connected', event => {
|
38
|
-
const xrInputSource = event.data;
|
34
|
+
createHandModel(controller, profile) {
|
35
|
+
const handModel = new XRHandModel(controller);
|
36
|
+
controller.addEventListener('connected', event => {
|
37
|
+
const xrInputSource = event.data;
|
39
38
|
|
40
|
-
|
41
|
-
|
42
|
-
handModel.xrInputSource = xrInputSource; // @todo Detect profile if not provided
|
39
|
+
if (xrInputSource.hand && !handModel.motionController) {
|
40
|
+
handModel.xrInputSource = xrInputSource; // @todo Detect profile if not provided
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
42
|
+
if (profile === undefined || profile === 'spheres') {
|
43
|
+
handModel.motionController = new XRHandPrimitiveModel(handModel, controller, this.path, xrInputSource.handedness, {
|
44
|
+
primitive: 'sphere'
|
45
|
+
});
|
46
|
+
} else if (profile === 'boxes') {
|
47
|
+
handModel.motionController = new XRHandPrimitiveModel(handModel, controller, this.path, xrInputSource.handedness, {
|
48
|
+
primitive: 'box'
|
49
|
+
});
|
50
|
+
} else if (profile === 'mesh') {
|
51
|
+
handModel.motionController = new XRHandMeshModel(handModel, controller, this.path, xrInputSource.handedness);
|
55
52
|
}
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
}
|
64
|
-
|
65
|
-
}
|
53
|
+
}
|
54
|
+
});
|
55
|
+
controller.addEventListener('disconnected', () => {// handModel.motionController = null;
|
56
|
+
// handModel.remove( scene );
|
57
|
+
// scene = null;
|
58
|
+
});
|
59
|
+
return handModel;
|
60
|
+
}
|
61
|
+
|
62
|
+
}
|
66
63
|
|
67
64
|
export { XRHandModelFactory };
|
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");exports.XRHandPrimitiveModel=class{constructor(i,n,a,r
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");const i=new e.Matrix4,n=new e.Vector3;exports.XRHandPrimitiveModel=class{constructor(i,n,a,t,r){let s;this.controller=n,this.handModel=i,this.envMap=null,r&&r.primitive&&"sphere"!==r.primitive?"box"===r.primitive&&(s=new e.BoxGeometry(1,1,1)):s=new e.SphereGeometry(1,10,10);const h=new e.MeshStandardMaterial;this.handMesh=new e.InstancedMesh(s,h,30),this.handMesh.instanceMatrix.setUsage(e.DynamicDrawUsage),this.handMesh.castShadow=!0,this.handMesh.receiveShadow=!0,this.handModel.add(this.handMesh),this.joints=["wrist","thumb-metacarpal","thumb-phalanx-proximal","thumb-phalanx-distal","thumb-tip","index-finger-metacarpal","index-finger-phalanx-proximal","index-finger-phalanx-intermediate","index-finger-phalanx-distal","index-finger-tip","middle-finger-metacarpal","middle-finger-phalanx-proximal","middle-finger-phalanx-intermediate","middle-finger-phalanx-distal","middle-finger-tip","ring-finger-metacarpal","ring-finger-phalanx-proximal","ring-finger-phalanx-intermediate","ring-finger-phalanx-distal","ring-finger-tip","pinky-finger-metacarpal","pinky-finger-phalanx-proximal","pinky-finger-phalanx-intermediate","pinky-finger-phalanx-distal","pinky-finger-tip"]}updateMesh(){const e=this.controller.joints;let a=0;for(let t=0;t<this.joints.length;t++){const r=e[this.joints[t]];r.visible&&(n.setScalar(r.jointRadius||.008),i.compose(r.position,r.quaternion,n),this.handMesh.setMatrixAt(t,i),a++)}this.handMesh.count=a,this.handMesh.instanceMatrix.needsUpdate=!0}};
|
@@ -3,7 +3,7 @@ import { Group, Texture } from 'three';
|
|
3
3
|
import { XRHandModel, XRHandModelHandedness } from './XRHandModelFactory';
|
4
4
|
|
5
5
|
export interface XRHandPrimitiveModelOptions {
|
6
|
-
primitive?: 'sphere' | 'box';
|
6
|
+
primitive?: 'sphere' | 'box' | undefined;
|
7
7
|
}
|
8
8
|
|
9
9
|
export class XRHandPrimitiveModel {
|