Skip to content

Commit 8e50d5c

Browse files
committed
XRHandPrimitiveModel: Clean up
1 parent c1d2e49 commit 8e50d5c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

examples/jsm/webxr/XRHandPrimitiveModel.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class XRHandPrimitiveModel {
1616
this.envMap = null;
1717

1818
let geometry;
19-
const jointMaterial = new MeshStandardMaterial( { color: 0xffffff, roughness: 1, metalness: 0 } );
2019

2120
if ( ! options || ! options.primitive || options.primitive === 'sphere' ) {
2221

@@ -28,7 +27,10 @@ class XRHandPrimitiveModel {
2827

2928
}
3029

31-
this.handMesh = new InstancedMesh( geometry, jointMaterial, 30 );
30+
const material = new MeshStandardMaterial();
31+
32+
this.handMesh = new InstancedMesh( geometry, material, 30 );
33+
this.handMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage ); // will be updated every frame
3234
this.handMesh.castShadow = true;
3335
this.handMesh.receiveShadow = true;
3436
this.handModel.add( this.handMesh );
@@ -61,38 +63,36 @@ class XRHandPrimitiveModel {
6163
'pinky-finger-tip'
6264
];
6365

64-
this.tempMat = new Matrix4(); this.tempVec = new Vector3( 1, 1, 1 );
66+
this.tempMat = new Matrix4();
67+
this.tempVec = new Vector3();
6568

6669
}
6770

6871
updateMesh() {
6972

7073
const defaultRadius = 0.008;
74+
const joints = this.controller.joints;
7175

72-
// XR Joints
73-
const XRJoints = this.controller.joints;
7476
let count = 0;
7577

7678
for ( let i = 0; i < this.joints.length; i ++ ) {
7779

78-
const XRJoint = XRJoints[ this.joints[ i ] ];
80+
const joint = joints[ this.joints[ i ] ];
81+
82+
if ( joint.visible ) {
7983

80-
if ( XRJoint.visible ) {
84+
this.tempVec.setScalar( joint.jointRadius || defaultRadius );
85+
this.tempMat.compose( joint.position, joint.quaternion, this.tempVec );
86+
this.handMesh.setMatrixAt( i, this.tempMat );
8187

82-
this.handMesh.setMatrixAt( i, this.tempMat.compose( XRJoint.position, XRJoint.quaternion,
83-
this.tempVec.set( 1, 1, 1 ).multiplyScalar( XRJoint.jointRadius || defaultRadius ) ) );
8488
count ++;
8589

8690
}
8791

8892
}
8993

9094
this.handMesh.count = count;
91-
if ( this.handMesh.instanceMatrix ) {
92-
93-
this.handMesh.instanceMatrix.needsUpdate = true;
94-
95-
}
95+
this.handMesh.instanceMatrix.needsUpdate = true;
9696

9797
}
9898

0 commit comments

Comments
 (0)