2
0

WebXRHandController.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import {
  2. Object3D
  3. } from "../../../build/three.module.js";
  4. import {
  5. XRHandSpheresModel
  6. } from "./XRHandSpheresModel.js";
  7. import {
  8. XRHandOculusMeshModel
  9. } from "./XRHandOculusMeshModel.js";
  10. function XRHandModel( controller ) {
  11. Object3D.call( this );
  12. this.controller = controller;
  13. this.motionController = null;
  14. this.envMap = null;
  15. this.mesh = null;
  16. }
  17. XRHandModel.prototype = Object.assign( Object.create( Object3D.prototype ), {
  18. constructor: XRHandModel,
  19. updateMatrixWorld: function ( force ) {
  20. Object3D.prototype.updateMatrixWorld.call( this, force );
  21. if ( this.motionController ) {
  22. this.motionController.updateMesh();
  23. }
  24. },
  25. } );
  26. var XRHandModelFactory = ( function () {
  27. function XRHandModelFactory() {}
  28. XRHandModelFactory.prototype = {
  29. constructor: XRHandModelFactory,
  30. createHandModel: function ( controller, profile ) {
  31. const handModel = new XRHandModel( controller );
  32. let scene = null;
  33. controller.addEventListener( 'connected', ( event ) => {
  34. const xrInputSource = event.data;
  35. if ( xrInputSource.hand && ! handModel.motionController ) {
  36. handModel.visible = true;
  37. handModel.xrInputSource = xrInputSource;
  38. // @todo Detect profile if not provided
  39. if ( profile === "spheres" ) {
  40. handModel.motionController = new XRHandSpheresModel( controller, xrInputSource.handedness );
  41. } else {
  42. handModel.motionController = new XRHandOculusMeshModel( controller, xrInputSource.handedness );
  43. }
  44. }
  45. } );
  46. controller.addEventListener( 'disconnected', () => {
  47. // handModel.motionController = null;
  48. // handModel.remove( scene );
  49. // scene = null;
  50. } );
  51. return handModel;
  52. }
  53. };
  54. return XRHandModelFactory;
  55. } )();
  56. export { XRHandModelFactory };