Skip to content

Commit

Permalink
XRHandPrimitiveModel: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Apr 23, 2021
1 parent c1d2e49 commit 8e50d5c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions examples/jsm/webxr/XRHandPrimitiveModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class XRHandPrimitiveModel {
this.envMap = null;

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

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

Expand All @@ -28,7 +27,10 @@ class XRHandPrimitiveModel {

}

this.handMesh = new InstancedMesh( geometry, jointMaterial, 30 );
const material = new MeshStandardMaterial();

this.handMesh = new InstancedMesh( geometry, material, 30 );
this.handMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage ); // will be updated every frame
this.handMesh.castShadow = true;
this.handMesh.receiveShadow = true;
this.handModel.add( this.handMesh );
Expand Down Expand Up @@ -61,38 +63,36 @@ class XRHandPrimitiveModel {
'pinky-finger-tip'
];

this.tempMat = new Matrix4(); this.tempVec = new Vector3( 1, 1, 1 );
this.tempMat = new Matrix4();
this.tempVec = new Vector3();

}

updateMesh() {

const defaultRadius = 0.008;
const joints = this.controller.joints;

// XR Joints
const XRJoints = this.controller.joints;
let count = 0;

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

const XRJoint = XRJoints[ this.joints[ i ] ];
const joint = joints[ this.joints[ i ] ];

if ( joint.visible ) {

if ( XRJoint.visible ) {
this.tempVec.setScalar( joint.jointRadius || defaultRadius );
this.tempMat.compose( joint.position, joint.quaternion, this.tempVec );
this.handMesh.setMatrixAt( i, this.tempMat );

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

}

}

this.handMesh.count = count;
if ( this.handMesh.instanceMatrix ) {

this.handMesh.instanceMatrix.needsUpdate = true;

}
this.handMesh.instanceMatrix.needsUpdate = true;

}

Expand Down

0 comments on commit 8e50d5c

Please sign in to comment.