123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import {
- SphereGeometry,
- BoxGeometry,
- MeshStandardMaterial,
- Mesh,
- Group
- } from '../../../build/three.module.js';
- class XRHandPrimitiveModel {
- constructor( handModel, controller, path, handedness, options ) {
- this.controller = controller;
- this.handModel = handModel;
- this.envMap = null;
- this.handMesh = new Group();
- this.handModel.add( this.handMesh );
- if ( window.XRHand ) {
- let geometry;
- if ( ! options || ! options.primitive || options.primitive === 'sphere' ) {
- geometry = new SphereGeometry( 1, 10, 10 );
- } else if ( options.primitive === 'box' ) {
- geometry = new BoxGeometry( 1, 1, 1 );
- }
- const jointMaterial = new MeshStandardMaterial( { color: 0xffffff, roughness: 1, metalness: 0 } );
- const tipMaterial = new MeshStandardMaterial( { color: 0x999999, roughness: 1, metalness: 0 } );
- const tipIndexes = [
- window.XRHand.THUMB_PHALANX_TIP,
- window.XRHand.INDEX_PHALANX_TIP,
- window.XRHand.MIDDLE_PHALANX_TIP,
- window.XRHand.RING_PHALANX_TIP,
- window.XRHand.LITTLE_PHALANX_TIP
- ];
- for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
- var cube = new Mesh( geometry, tipIndexes.indexOf( i ) !== - 1 ? tipMaterial : jointMaterial );
- cube.castShadow = true;
- cube.receiveShadow = true;
- this.handMesh.add( cube );
- }
- }
- }
- updateMesh() {
- const defaultRadius = 0.008;
- const objects = this.handMesh.children;
- // XR Joints
- const XRJoints = this.controller.joints;
- for ( let i = 0; i < objects.length; i ++ ) {
- const jointMesh = objects[ i ];
- const XRJoint = XRJoints[ i ];
- if ( XRJoint.visible ) {
- jointMesh.position.copy( XRJoint.position );
- jointMesh.quaternion.copy( XRJoint.quaternion );
- jointMesh.scale.setScalar( XRJoint.jointRadius || defaultRadius );
- }
- jointMesh.visible = XRJoint.visible;
- }
- }
- }
- export { XRHandPrimitiveModel };
|