|
26 | 26 | let controller1, controller2; |
27 | 27 | let controllerGrip1, controllerGrip2; |
28 | 28 |
|
29 | | - const currentHandModel = { |
30 | | - left: 0, |
31 | | - right: 0 |
32 | | - }; |
33 | | - |
34 | 29 | const handModels = { |
35 | 30 | left: null, |
36 | 31 | right: null |
|
108 | 103 | scene.add( controllerGrip1 ); |
109 | 104 |
|
110 | 105 | hand1 = renderer.xr.getHand( 0 ); |
| 106 | + hand1.userData.currentHandModel = 0; |
111 | 107 | scene.add( hand1 ); |
112 | 108 |
|
113 | 109 | handModels.left = [ |
114 | 110 | handModelFactory.createHandModel( hand1, "boxes" ), |
115 | 111 | 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" ) |
119 | 113 | ]; |
120 | 114 |
|
121 | | - handModels.left.forEach( model => { |
| 115 | + for ( let i = 0; i < 3; i ++ ) { |
122 | 116 |
|
123 | | - model.visible = false; |
| 117 | + const model = handModels.left[ i ]; |
| 118 | + model.visible = i == 0; |
124 | 119 | hand1.add( model ); |
125 | 120 |
|
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 | | - |
136 | 121 | } |
137 | 122 |
|
138 | | - hand1.addEventListener( 'pinchend', evt => { |
| 123 | + hand1.addEventListener( 'pinchend', function ( event ) { |
139 | 124 |
|
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; |
141 | 128 |
|
142 | 129 | } ); |
143 | 130 |
|
|
148 | 135 | scene.add( controllerGrip2 ); |
149 | 136 |
|
150 | 137 | hand2 = renderer.xr.getHand( 1 ); |
| 138 | + hand2.userData.currentHandModel = 0; |
151 | 139 | scene.add( hand2 ); |
152 | 140 |
|
153 | 141 | handModels.right = [ |
154 | 142 | handModelFactory.createHandModel( hand2, "boxes" ), |
155 | 143 | 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" ) |
159 | 145 | ]; |
160 | | - handModels.right.forEach( model => { |
161 | | - |
162 | | - model.visible = false; |
163 | | - hand2.add( model ); |
164 | 146 |
|
165 | | - } ); |
| 147 | + for ( let i = 0; i < 3; i ++ ) { |
166 | 148 |
|
167 | | - handModels.right[ currentHandModel.right ].visible = true; |
| 149 | + const model = handModels.right[ i ]; |
| 150 | + model.visible = i == 0; |
| 151 | + hand2.add( model ); |
168 | 152 |
|
169 | | - window.handModels = handModels; |
| 153 | + } |
170 | 154 |
|
171 | | - hand2.addEventListener( 'pinchend', evt => { |
| 155 | + hand2.addEventListener( 'pinchend', function ( evevent ) { |
172 | 156 |
|
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; |
174 | 160 |
|
175 | 161 | } ); |
176 | 162 |
|
177 | 163 | // |
178 | | - window.hands = [ hand1, hand2 ]; |
179 | 164 |
|
180 | 165 | const geometry = new THREE.BufferGeometry().setFromPoints( [ new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, - 1 ) ] ); |
181 | 166 |
|
|
0 commit comments