123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import { FBXLoader } from "../loaders/FBXLoader.js";
- class XRHandOculusMeshModel {
- constructor( handModel, controller, handedness, options ) {
- this.controller = controller;
- this.handModel = handModel;
- this.bones = [];
- var loader = new FBXLoader();
- const low = options && options.model === "lowpoly" ? "_low" : "";
- loader.load( `/examples/models/fbx/OculusHand_${handedness === "right" ? "R" : "L"}${low}.fbx`, object => {
- this.handModel.add( object );
- // Hack because of the scale of the skinnedmesh
- object.scale.setScalar( 0.01 );
- object.getObjectByProperty( "type", "SkinnedMesh" ).frustumCulled = false;
- const bonesMapping = [
- 'b_%_wrist', // XRHand.WRIST,
- 'b_%_thumb1', // XRHand.THUMB_METACARPAL,
- 'b_%_thumb2', // XRHand.THUMB_PHALANX_PROXIMAL,
- 'b_%_thumb3', // XRHand.THUMB_PHALANX_DISTAL,
- 'b_%_thumb_null', // XRHand.THUMB_PHALANX_TIP,
- null, //'b_%_index1', // XRHand.INDEX_METACARPAL,
- 'b_%_index1', // XRHand.INDEX_PHALANX_PROXIMAL,
- 'b_%_index2', // XRHand.INDEX_PHALANX_INTERMEDIATE,
- 'b_%_index3', // XRHand.INDEX_PHALANX_DISTAL,
- 'b_%_index_null', // XRHand.INDEX_PHALANX_TIP,
- null, //'b_%_middle1', // XRHand.MIDDLE_METACARPAL,
- 'b_%_middle1', // XRHand.MIDDLE_PHALANX_PROXIMAL,
- 'b_%_middle2', // XRHand.MIDDLE_PHALANX_INTERMEDIATE,
- 'b_%_middle3', // XRHand.MIDDLE_PHALANX_DISTAL,
- 'b_%_middlenull', // XRHand.MIDDLE_PHALANX_TIP,
- null, //'b_%_ring1', // XRHand.RING_METACARPAL,
- 'b_%_ring1', // XRHand.RING_PHALANX_PROXIMAL,
- 'b_%_ring2', // XRHand.RING_PHALANX_INTERMEDIATE,
- 'b_%_ring3', // XRHand.RING_PHALANX_DISTAL,
- 'b_%_ring_inull', // XRHand.RING_PHALANX_TIP,
- 'b_%_pinky0', // XRHand.LITTLE_METACARPAL,
- 'b_%_pinky1', // XRHand.LITTLE_PHALANX_PROXIMAL,
- 'b_%_pinky2', // XRHand.LITTLE_PHALANX_INTERMEDIATE,
- 'b_%_pinky3', // XRHand.LITTLE_PHALANX_DISTAL,
- 'b_%_pinkynull', // XRHand.LITTLE_PHALANX_TIP
- ];
- bonesMapping.forEach( boneName => {
- if ( boneName ) {
- const bone = object.getObjectByName( boneName.replace( "%", handedness === "right" ? "r" : "l" ) );
- this.bones.push( bone );
- } else {
- this.bones.push( null );
- }
- } );
- } );
- }
- updateMesh() {
- // XR Joints
- const XRJoints = this.controller.joints;
- for ( var i = 0; i < this.bones.length; i ++ ) {
- const bone = this.bones[ i ];
- const XRJoint = XRJoints[ i ];
- if ( XRJoint ) {
- if ( XRJoint.visible ) {
- let position = XRJoint.position;
- if ( bone ) {
- bone.position.copy( position.clone().multiplyScalar( 100 ) );
- bone.quaternion.copy( XRJoint.quaternion );
- // bone.scale.setScalar( XRJoint.jointRadius || defaultRadius );
- }
- }
- }
- }
- }
- }
- export { XRHandOculusMeshModel };
|