2
0

XRHandOculusMeshModel.js 2.6 KB

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