XRHandOculusMeshModel.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import { FBXLoader } from "../loaders/FBXLoader.js";
  2. class XRHandOculusMeshModel {
  3. constructor( handModel, controller, handedness, options ) {
  4. this.controller = controller;
  5. this.handModel = handModel;
  6. this.bones = [];
  7. var loader = new FBXLoader();
  8. const low = options && options.model === "lowpoly" ? "_low" : "";
  9. loader.load( `/examples/models/fbx/OculusHand_${handedness === "right" ? "R" : "L"}${low}.fbx`, object => {
  10. this.handModel.add( object );
  11. // Hack because of the scale of the skinnedmesh
  12. object.scale.setScalar( 0.01 );
  13. object.getObjectByProperty( "type", "SkinnedMesh" ).frustumCulled = false;
  14. const bonesMapping = [
  15. 'b_%_wrist', // XRHand.WRIST,
  16. 'b_%_thumb1', // XRHand.THUMB_METACARPAL,
  17. 'b_%_thumb2', // XRHand.THUMB_PHALANX_PROXIMAL,
  18. 'b_%_thumb3', // XRHand.THUMB_PHALANX_DISTAL,
  19. 'b_%_thumb_null', // XRHand.THUMB_PHALANX_TIP,
  20. null, //'b_%_index1', // XRHand.INDEX_METACARPAL,
  21. 'b_%_index1', // XRHand.INDEX_PHALANX_PROXIMAL,
  22. 'b_%_index2', // XRHand.INDEX_PHALANX_INTERMEDIATE,
  23. 'b_%_index3', // XRHand.INDEX_PHALANX_DISTAL,
  24. 'b_%_index_null', // XRHand.INDEX_PHALANX_TIP,
  25. null, //'b_%_middle1', // XRHand.MIDDLE_METACARPAL,
  26. 'b_%_middle1', // XRHand.MIDDLE_PHALANX_PROXIMAL,
  27. 'b_%_middle2', // XRHand.MIDDLE_PHALANX_INTERMEDIATE,
  28. 'b_%_middle3', // XRHand.MIDDLE_PHALANX_DISTAL,
  29. 'b_%_middlenull', // XRHand.MIDDLE_PHALANX_TIP,
  30. null, //'b_%_ring1', // XRHand.RING_METACARPAL,
  31. 'b_%_ring1', // XRHand.RING_PHALANX_PROXIMAL,
  32. 'b_%_ring2', // XRHand.RING_PHALANX_INTERMEDIATE,
  33. 'b_%_ring3', // XRHand.RING_PHALANX_DISTAL,
  34. 'b_%_ring_inull', // XRHand.RING_PHALANX_TIP,
  35. 'b_%_pinky0', // XRHand.LITTLE_METACARPAL,
  36. 'b_%_pinky1', // XRHand.LITTLE_PHALANX_PROXIMAL,
  37. 'b_%_pinky2', // XRHand.LITTLE_PHALANX_INTERMEDIATE,
  38. 'b_%_pinky3', // XRHand.LITTLE_PHALANX_DISTAL,
  39. 'b_%_pinkynull', // XRHand.LITTLE_PHALANX_TIP
  40. ];
  41. bonesMapping.forEach( boneName => {
  42. if ( boneName ) {
  43. const bone = object.getObjectByName( boneName.replace( "%", handedness === "right" ? "r" : "l" ) );
  44. this.bones.push( bone );
  45. } else {
  46. this.bones.push( null );
  47. }
  48. } );
  49. } );
  50. }
  51. updateMesh() {
  52. // XR Joints
  53. const XRJoints = this.controller.joints;
  54. for ( var i = 0; i < this.bones.length; i ++ ) {
  55. const bone = this.bones[ i ];
  56. const XRJoint = XRJoints[ i ];
  57. if ( XRJoint ) {
  58. if ( XRJoint.visible ) {
  59. let position = XRJoint.position;
  60. if ( bone ) {
  61. bone.position.copy( position.clone().multiplyScalar( 100 ) );
  62. bone.quaternion.copy( XRJoint.quaternion );
  63. // bone.scale.setScalar( XRJoint.jointRadius || defaultRadius );
  64. }
  65. }
  66. }
  67. }
  68. }
  69. }
  70. export { XRHandOculusMeshModel };