Skip to content

Commit 9b22261

Browse files
committed
Examples: Simplified webxr_vr_handinput_profiles.
1 parent 571347f commit 9b22261

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

examples/webxr_vr_handinput_profiles.html

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@
2626
let controller1, controller2;
2727
let controllerGrip1, controllerGrip2;
2828

29-
const currentHandModel = {
30-
left: 0,
31-
right: 0
32-
};
33-
3429
const handModels = {
3530
left: null,
3631
right: null
@@ -108,36 +103,28 @@
108103
scene.add( controllerGrip1 );
109104

110105
hand1 = renderer.xr.getHand( 0 );
106+
hand1.userData.currentHandModel = 0;
111107
scene.add( hand1 );
112108

113109
handModels.left = [
114110
handModelFactory.createHandModel( hand1, "boxes" ),
115111
handModelFactory.createHandModel( hand1, "spheres" ),
116-
// low poly option disabled until low poly hands model is fixed
117-
// handModelFactory.createHandModel( hand1, "oculus", { model: "lowpoly" } ),
118-
handModelFactory.createHandModel( hand1, "oculus" )
112+
handModelFactory.createHandModel( hand1, "mesh" )
119113
];
120114

121-
handModels.left.forEach( model => {
115+
for ( let i = 0; i < 3; i ++ ) {
122116

123-
model.visible = false;
117+
const model = handModels.left[ i ];
118+
model.visible = i == 0;
124119
hand1.add( model );
125120

126-
} );
127-
128-
handModels.left[ currentHandModel.left ].visible = true;
129-
130-
function cycleHandModel( hand ) {
131-
132-
handModels[ hand ][ currentHandModel[ hand ] ].visible = false;
133-
currentHandModel[ hand ] = ( currentHandModel[ hand ] + 1 ) % handModels[ hand ].length;
134-
handModels[ hand ][ currentHandModel[ hand ] ].visible = true;
135-
136121
}
137122

138-
hand1.addEventListener( 'pinchend', evt => {
123+
hand1.addEventListener( 'pinchend', function ( event ) {
139124

140-
cycleHandModel( evt.handedness );
125+
handModels.left[ this.userData.currentHandModel ].visible = false;
126+
this.userData.currentHandModel = ( this.userData.currentHandModel + 1 ) % 3;
127+
handModels.left[ this.userData.currentHandModel ].visible = true;
141128

142129
} );
143130

@@ -148,34 +135,32 @@
148135
scene.add( controllerGrip2 );
149136

150137
hand2 = renderer.xr.getHand( 1 );
138+
hand2.userData.currentHandModel = 0;
151139
scene.add( hand2 );
152140

153141
handModels.right = [
154142
handModelFactory.createHandModel( hand2, "boxes" ),
155143
handModelFactory.createHandModel( hand2, "spheres" ),
156-
// low poly option disabled until low poly hands model is fixed
157-
// handModelFactory.createHandModel( hand2, "oculus", { model: "lowpoly" } ),
158-
handModelFactory.createHandModel( hand2, "oculus" )
144+
handModelFactory.createHandModel( hand2, "mesh" )
159145
];
160-
handModels.right.forEach( model => {
161-
162-
model.visible = false;
163-
hand2.add( model );
164146

165-
} );
147+
for ( let i = 0; i < 3; i ++ ) {
166148

167-
handModels.right[ currentHandModel.right ].visible = true;
149+
const model = handModels.right[ i ];
150+
model.visible = i == 0;
151+
hand2.add( model );
168152

169-
window.handModels = handModels;
153+
}
170154

171-
hand2.addEventListener( 'pinchend', evt => {
155+
hand2.addEventListener( 'pinchend', function ( evevent ) {
172156

173-
cycleHandModel( evt.handedness );
157+
handModels.right[ this.userData.currentHandModel ].visible = false;
158+
this.userData.currentHandModel = ( this.userData.currentHandModel + 1 ) % 3;
159+
handModels.right[ this.userData.currentHandModel ].visible = true;
174160

175161
} );
176162

177163
//
178-
window.hands = [ hand1, hand2 ];
179164

180165
const geometry = new THREE.BufferGeometry().setFromPoints( [ new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, - 1 ) ] );
181166

0 commit comments

Comments
 (0)