Skip to content

Commit 571347f

Browse files
committed
Fixed code WebXR Hands code.
1 parent 2c9b143 commit 571347f

File tree

6 files changed

+23
-43
lines changed

6 files changed

+23
-43
lines changed

examples/jsm/webxr/OculusHandModel.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { Object3D, Sphere, Box3 } from '../../../build/three.module.js';
2-
import { fetchProfile } from '../libs/motion-controllers.module.js';
32
import { XRHandMeshModel } from './XRHandMeshModel.js';
43

5-
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/[email protected]/dist/profiles';
6-
const DEFAULT_PROFILE = 'generic-hand';
7-
84
const TOUCH_RADIUS = 0.01;
95
const POINTING_JOINT = 'index-finger-tip';
106

@@ -23,23 +19,13 @@ class OculusHandModel extends Object3D {
2319
controller.addEventListener( 'connected', ( event ) => {
2420

2521
const xrInputSource = event.data;
22+
2623
if ( xrInputSource.hand && ! this.motionController ) {
2724

2825
this.visible = true;
2926
this.xrInputSource = xrInputSource;
30-
fetchProfile( xrInputSource, DEFAULT_PROFILES_PATH, DEFAULT_PROFILE ).then( ( { profile, assetPath } ) => {
31-
32-
this.motionController = new XRHandMeshModel(
33-
this,
34-
controller,
35-
assetPath
36-
);
37-
38-
} ).catch( ( err ) => {
39-
40-
console.warn( err );
4127

42-
} );
28+
this.motionController = new XRHandMeshModel( this, controller, this.path, xrInputSource.handedness );
4329

4430
}
4531

examples/jsm/webxr/XRHandMeshModel.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { GLTFLoader } from '../loaders/GLTFLoader.js';
22

3+
const DEFAULT_HAND_PROFILE_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/[email protected]/dist/profiles/generic-hand/';
4+
35
class XRHandMeshModel {
46

5-
constructor( handModel, controller, assetUrl ) {
7+
constructor( handModel, controller, path, handedness ) {
68

79
this.controller = controller;
810
this.handModel = handModel;
911

1012
this.bones = [];
11-
const loader = new GLTFLoader();
1213

13-
loader.setPath( '' );
14-
loader.load( assetUrl, gltf => {
14+
const loader = new GLTFLoader();
15+
loader.setPath( path || DEFAULT_HAND_PROFILE_PATH );
16+
loader.load( `${handedness}.glb`, gltf => {
1517

1618
const object = gltf.scene.children[ 0 ];
1719
this.handModel.add( object );
@@ -21,6 +23,8 @@ class XRHandMeshModel {
2123
mesh.castShadow = true;
2224
mesh.receiveShadow = true;
2325

26+
mesh.material.side = 0; // Workaround: force FrontSide
27+
2428
const joints = [
2529
'wrist',
2630
'thumb-metacarpal',
@@ -52,6 +56,7 @@ class XRHandMeshModel {
5256
joints.forEach( jointName => {
5357

5458
const bone = object.getObjectByName( jointName );
59+
5560
if ( bone !== undefined ) {
5661

5762
bone.jointName = jointName;
@@ -74,15 +79,19 @@ class XRHandMeshModel {
7479

7580
// XR Joints
7681
const XRJoints = this.controller.joints;
82+
7783
for ( let i = 0; i < this.bones.length; i ++ ) {
7884

7985
const bone = this.bones[ i ];
86+
8087
if ( bone ) {
8188

8289
const XRJoint = XRJoints[ bone.jointName ];
90+
8391
if ( XRJoint.visible ) {
8492

8593
const position = XRJoint.position;
94+
8695
if ( bone ) {
8796

8897
bone.position.copy( position );

examples/jsm/webxr/XRHandModelFactory.js

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ import {
1010
XRHandMeshModel
1111
} from './XRHandMeshModel.js';
1212

13-
import {
14-
fetchProfile
15-
} from '../libs/motion-controllers.module.js';
16-
17-
const DEFAULT_PROFILES_PATH = 'https://cdn.jsdelivr.net/npm/@webxr-input-profiles/[email protected]/dist/profiles';
18-
const DEFAULT_PROFILE = 'generic-hand';
19-
2013
class XRHandModel extends Object3D {
2114

2215
constructor( controller ) {
@@ -49,18 +42,19 @@ class XRHandModelFactory {
4942

5043
constructor() {
5144

52-
this.path = '';
45+
this.path = null;
5346

5447
}
5548

5649
setPath( path ) {
5750

5851
this.path = path;
52+
5953
return this;
6054

6155
}
6256

63-
createHandModel( controller, profile, options ) {
57+
createHandModel( controller, profile ) {
6458

6559
const handModel = new XRHandModel( controller );
6660

@@ -70,7 +64,6 @@ class XRHandModelFactory {
7064

7165
if ( xrInputSource.hand && ! handModel.motionController ) {
7266

73-
handModel.visible = true;
7467
handModel.xrInputSource = xrInputSource;
7568

7669
// @todo Detect profile if not provided
@@ -82,17 +75,9 @@ class XRHandModelFactory {
8275

8376
handModel.motionController = new XRHandPrimitiveModel( handModel, controller, this.path, xrInputSource.handedness, { primitive: 'box' } );
8477

85-
} else if ( profile === 'oculus' ) {
86-
87-
fetchProfile( xrInputSource, DEFAULT_PROFILES_PATH, DEFAULT_PROFILE ).then( ( { profile, assetPath } ) => {
88-
89-
handModel.motionController = new XRHandMeshModel( handModel, controller, assetPath );
90-
91-
} ).catch( ( err ) => {
92-
93-
console.warn( err );
78+
} else if ( profile === 'mesh' ) {
9479

95-
} );
80+
handModel.motionController = new XRHandMeshModel( handModel, controller, this.path, xrInputSource.handedness );
9681

9782
}
9883

examples/webxr_vr_handinput.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
scene.add( controller2 );
8888

8989
const controllerModelFactory = new XRControllerModelFactory();
90-
const handModelFactory = new XRHandModelFactory().setPath( "./models/gltf/" );
90+
const handModelFactory = new XRHandModelFactory();
9191

9292
// Hand 1
9393
controllerGrip1 = renderer.xr.getControllerGrip( 0 );

examples/webxr_vr_handinput_cubes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
scene.add( controller2 );
101101

102102
const controllerModelFactory = new XRControllerModelFactory();
103-
const handModelFactory = new XRHandModelFactory().setPath( "./models/gltf/" );
103+
const handModelFactory = new XRHandModelFactory();
104104

105105
// Hand 1
106106
controllerGrip1 = renderer.xr.getControllerGrip( 0 );

examples/webxr_vr_handinput_profiles.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
scene.add( controller2 );
100100

101101
const controllerModelFactory = new XRControllerModelFactory();
102-
const handModelFactory = new XRHandModelFactory().setPath( "./models/gltf/" );
102+
const handModelFactory = new XRHandModelFactory();
103103

104104
// Hand 1
105105

0 commit comments

Comments
 (0)