three-stdlib 2.8.1 → 2.8.5
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 -2
- 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/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
@@ -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 {
|
@@ -1,62 +1,52 @@
|
|
1
|
-
import {
|
1
|
+
import { Matrix4, Vector3, SphereGeometry, BoxGeometry, MeshStandardMaterial, InstancedMesh, DynamicDrawUsage } from 'three';
|
2
|
+
|
3
|
+
const _matrix = new Matrix4();
|
4
|
+
|
5
|
+
const _vector = new Vector3();
|
2
6
|
|
3
7
|
class XRHandPrimitiveModel {
|
4
8
|
constructor(handModel, controller, path, handedness, options) {
|
5
9
|
this.controller = controller;
|
6
10
|
this.handModel = handModel;
|
7
11
|
this.envMap = null;
|
8
|
-
|
9
|
-
this.handModel.add(this.handMesh);
|
12
|
+
let geometry;
|
10
13
|
|
11
|
-
if (
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
} else if (options.primitive === 'box') {
|
17
|
-
geometry = new BoxGeometry(1, 1, 1);
|
18
|
-
}
|
14
|
+
if (!options || !options.primitive || options.primitive === 'sphere') {
|
15
|
+
geometry = new SphereGeometry(1, 10, 10);
|
16
|
+
} else if (options.primitive === 'box') {
|
17
|
+
geometry = new BoxGeometry(1, 1, 1);
|
18
|
+
}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
metalness: 0
|
24
|
-
});
|
25
|
-
const tipMaterial = new MeshStandardMaterial({
|
26
|
-
color: 0x999999,
|
27
|
-
roughness: 1,
|
28
|
-
metalness: 0
|
29
|
-
});
|
30
|
-
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
|
+
const material = new MeshStandardMaterial();
|
21
|
+
this.handMesh = new InstancedMesh(geometry, material, 30);
|
22
|
+
this.handMesh.instanceMatrix.setUsage(DynamicDrawUsage); // will be updated every frame
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
cube.jointName = jointName;
|
37
|
-
this.handMesh.add(cube);
|
38
|
-
}
|
39
|
-
}
|
24
|
+
this.handMesh.castShadow = true;
|
25
|
+
this.handMesh.receiveShadow = true;
|
26
|
+
this.handModel.add(this.handMesh);
|
27
|
+
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'];
|
40
28
|
}
|
41
29
|
|
42
30
|
updateMesh() {
|
43
31
|
const defaultRadius = 0.008;
|
44
|
-
const
|
32
|
+
const joints = this.controller.joints;
|
33
|
+
let count = 0;
|
45
34
|
|
46
|
-
|
35
|
+
for (let i = 0; i < this.joints.length; i++) {
|
36
|
+
const joint = joints[this.joints[i]];
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
const XRJoint = XRJoints[jointMesh.jointName];
|
38
|
+
if (joint.visible) {
|
39
|
+
_vector.setScalar(joint.jointRadius || defaultRadius);
|
51
40
|
|
52
|
-
|
53
|
-
jointMesh.position.copy(XRJoint.position);
|
54
|
-
jointMesh.quaternion.copy(XRJoint.quaternion);
|
55
|
-
jointMesh.scale.setScalar(XRJoint.jointRadius || defaultRadius);
|
56
|
-
}
|
41
|
+
_matrix.compose(joint.position, joint.quaternion, _vector);
|
57
42
|
|
58
|
-
|
43
|
+
this.handMesh.setMatrixAt(i, _matrix);
|
44
|
+
count++;
|
45
|
+
}
|
59
46
|
}
|
47
|
+
|
48
|
+
this.handMesh.count = count;
|
49
|
+
this.handMesh.instanceMatrix.needsUpdate = true;
|
60
50
|
}
|
61
51
|
|
62
52
|
}
|
package/csm/Frustum.d.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
export default class Frustum {
|
2
|
-
constructor(data: any);
|
3
|
-
vertices: {
|
4
|
-
near: any[];
|
5
|
-
far: any[];
|
6
|
-
};
|
7
|
-
setFromProjectionMatrix(
|
8
|
-
projectionMatrix: any,
|
9
|
-
maxFar: any,
|
10
|
-
): {
|
11
|
-
near: any[];
|
12
|
-
far: any[];
|
13
|
-
};
|
14
|
-
split(breaks: any, target: any): void;
|
15
|
-
toSpace(cameraMatrix: any, target: any): void;
|
16
|
-
}
|
package/csm/Shader.d.ts
DELETED
package/loaders/XLoader.d.ts
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
import { Mesh, Loader, LoadingManager } from 'three';
|
2
|
-
|
3
|
-
export interface XResult {
|
4
|
-
animations: object[];
|
5
|
-
models: Mesh[];
|
6
|
-
}
|
7
|
-
|
8
|
-
export class XLoader extends Loader {
|
9
|
-
constructor(manager?: LoadingManager);
|
10
|
-
|
11
|
-
load(
|
12
|
-
url: string,
|
13
|
-
onLoad: (object: XResult) => void,
|
14
|
-
onProgress?: (event: ProgressEvent) => void,
|
15
|
-
onError?: (event: ErrorEvent) => void,
|
16
|
-
): void;
|
17
|
-
loadAsync(url: string, onProgress?: (event: ProgressEvent) => void): Promise<XResult>;
|
18
|
-
parse(data: ArrayBuffer | string, onLoad: (object: object) => void): object;
|
19
|
-
}
|
@@ -1,13 +0,0 @@
|
|
1
|
-
import { Uniform } from 'three';
|
2
|
-
|
3
|
-
export const FresnelShader: {
|
4
|
-
uniforms: {
|
5
|
-
mRefractionRatio: Uniform;
|
6
|
-
mFresnelBias: Uniform;
|
7
|
-
mFresnelPower: Uniform;
|
8
|
-
mFresnelScale: Uniform;
|
9
|
-
tCube: Uniform;
|
10
|
-
};
|
11
|
-
vertexShader: string;
|
12
|
-
fragmentShader: string;
|
13
|
-
};
|