@iwsdk/xr-input 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +138 -0
  2. package/dist/gamepad/generated-profiles.d.ts.map +1 -1
  3. package/dist/gamepad/generated-profiles.js +9998 -12843
  4. package/dist/gamepad/generated-profiles.js.map +1 -1
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +4 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/node_modules/.pnpm/super-three@0.181.0/node_modules/super-three/src/math/MathUtils.js.map +1 -0
  10. package/dist/pointer/cursor-visual.d.ts +34 -0
  11. package/dist/pointer/cursor-visual.d.ts.map +1 -0
  12. package/dist/pointer/cursor-visual.js +110 -0
  13. package/dist/pointer/cursor-visual.js.map +1 -0
  14. package/dist/pointer/multi-pointer.d.ts +137 -12
  15. package/dist/pointer/multi-pointer.d.ts.map +1 -1
  16. package/dist/pointer/multi-pointer.js +481 -107
  17. package/dist/pointer/multi-pointer.js.map +1 -1
  18. package/dist/pointer/ray-pointer.d.ts +5 -5
  19. package/dist/pointer/ray-pointer.d.ts.map +1 -1
  20. package/dist/pointer/ray-pointer.js +11 -84
  21. package/dist/pointer/ray-pointer.js.map +1 -1
  22. package/dist/pointer/touch-pointer.d.ts +42 -0
  23. package/dist/pointer/touch-pointer.d.ts.map +1 -0
  24. package/dist/pointer/touch-pointer.js +51 -0
  25. package/dist/pointer/touch-pointer.js.map +1 -0
  26. package/dist/rig/xr-origin.d.ts +10 -0
  27. package/dist/rig/xr-origin.d.ts.map +1 -1
  28. package/dist/rig/xr-origin.js +11 -1
  29. package/dist/rig/xr-origin.js.map +1 -1
  30. package/dist/version.d.ts +1 -1
  31. package/dist/visual/adapter/hand-visual-adapter.d.ts +5 -0
  32. package/dist/visual/adapter/hand-visual-adapter.d.ts.map +1 -1
  33. package/dist/visual/adapter/hand-visual-adapter.js +7 -0
  34. package/dist/visual/adapter/hand-visual-adapter.js.map +1 -1
  35. package/dist/visual/impl/animated-controller-hand.js +1 -1
  36. package/dist/visual/utils/flex-batched-mesh.d.ts.map +1 -1
  37. package/dist/visual/utils/flex-batched-mesh.js +10 -5
  38. package/dist/visual/utils/flex-batched-mesh.js.map +1 -1
  39. package/dist/visual/utils/simple-batched-mesh.d.ts +47 -0
  40. package/dist/visual/utils/simple-batched-mesh.d.ts.map +1 -0
  41. package/dist/visual/utils/simple-batched-mesh.js +389 -0
  42. package/dist/visual/utils/simple-batched-mesh.js.map +1 -0
  43. package/dist/xr-input-manager.d.ts +5 -0
  44. package/dist/xr-input-manager.d.ts.map +1 -1
  45. package/dist/xr-input-manager.js +24 -0
  46. package/dist/xr-input-manager.js.map +1 -1
  47. package/package.json +1 -1
  48. package/dist/node_modules/.pnpm/super-three@0.177.0/node_modules/super-three/src/math/MathUtils.js.map +0 -1
  49. /package/dist/node_modules/.pnpm/{super-three@0.177.0 → super-three@0.181.0}/node_modules/super-three/src/math/MathUtils.js +0 -0
package/dist/index.d.ts CHANGED
@@ -16,5 +16,8 @@ export * from './visual/utils/flex-batched-mesh.js';
16
16
  export * from './rig/xr-origin.js';
17
17
  export * from './xr-input-manager.js';
18
18
  export * from './pointer/grab-pointer.js';
19
+ export * from './pointer/touch-pointer.js';
20
+ export * from './pointer/ray-pointer.js';
19
21
  export * from './pointer/multi-pointer.js';
22
+ export * from './pointer/cursor-visual.js';
20
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AAGxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAG1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,yCAAyC,CAAC;AAGxD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,sCAAsC,CAAC;AACrD,cAAc,2CAA2C,CAAC;AAG1D,cAAc,yCAAyC,CAAC;AACxD,cAAc,gCAAgC,CAAC;AAG/C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,oBAAoB,CAAC;AAGnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
package/dist/index.js CHANGED
@@ -10,5 +10,8 @@ export { FlexBatchedMesh } from './visual/utils/flex-batched-mesh.js';
10
10
  export { XROrigin } from './rig/xr-origin.js';
11
11
  export { DefaultXRAssetLoader, XRInputDeviceType, XRInputManager } from './xr-input-manager.js';
12
12
  export { GrabPointer } from './pointer/grab-pointer.js';
13
- export { MultiPointer } from './pointer/multi-pointer.js';
13
+ export { TOUCH_DEFAULTS, TouchPointer } from './pointer/touch-pointer.js';
14
+ export { RayDisplayMode, RayPointer } from './pointer/ray-pointer.js';
15
+ export { InteractorState, MultiPointer } from './pointer/multi-pointer.js';
16
+ export { CursorVisual } from './pointer/cursor-visual.js';
14
17
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MathUtils.js","sources":["../../../../../../../../../../node_modules/.pnpm/super-three@0.181.0/node_modules/super-three/src/math/MathUtils.js"],"sourcesContent":["import { warn } from '../utils.js';\n\nconst _lut = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff' ];\n\nlet _seed = 1234567;\n\n\nconst DEG2RAD = Math.PI / 180;\nconst RAD2DEG = 180 / Math.PI;\n\n/**\n * Generate a [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier)\n * (universally unique identifier).\n *\n * @return {string} The UUID.\n */\nfunction generateUUID() {\n\n\t// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136\n\n\tconst d0 = Math.random() * 0xffffffff | 0;\n\tconst d1 = Math.random() * 0xffffffff | 0;\n\tconst d2 = Math.random() * 0xffffffff | 0;\n\tconst d3 = Math.random() * 0xffffffff | 0;\n\tconst uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +\n\t\t\t_lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +\n\t\t\t_lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +\n\t\t\t_lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];\n\n\t// .toLowerCase() here flattens concatenated strings to save heap memory space.\n\treturn uuid.toLowerCase();\n\n}\n\n/**\n * Clamps the given value between min and max.\n *\n * @param {number} value - The value to clamp.\n * @param {number} min - The min value.\n * @param {number} max - The max value.\n * @return {number} The clamped value.\n */\nfunction clamp( value, min, max ) {\n\n\treturn Math.max( min, Math.min( max, value ) );\n\n}\n\n/**\n * Computes the Euclidean modulo of the given parameters that\n * is `( ( n % m ) + m ) % m`.\n *\n * @param {number} n - The first parameter.\n * @param {number} m - The second parameter.\n * @return {number} The Euclidean modulo.\n */\nfunction euclideanModulo( n, m ) {\n\n\t// https://en.wikipedia.org/wiki/Modulo_operation\n\n\treturn ( ( n % m ) + m ) % m;\n\n}\n\n/**\n * Performs a linear mapping from range `<a1, a2>` to range `<b1, b2>`\n * for the given value.\n *\n * @param {number} x - The value to be mapped.\n * @param {number} a1 - Minimum value for range A.\n * @param {number} a2 - Maximum value for range A.\n * @param {number} b1 - Minimum value for range B.\n * @param {number} b2 - Maximum value for range B.\n * @return {number} The mapped value.\n */\nfunction mapLinear( x, a1, a2, b1, b2 ) {\n\n\treturn b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );\n\n}\n\n/**\n * Returns the percentage in the closed interval `[0, 1]` of the given value\n * between the start and end point.\n *\n * @param {number} x - The start point\n * @param {number} y - The end point.\n * @param {number} value - A value between start and end.\n * @return {number} The interpolation factor.\n */\nfunction inverseLerp( x, y, value ) {\n\n\t// https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/\n\n\tif ( x !== y ) {\n\n\t\treturn ( value - x ) / ( y - x );\n\n\t} else {\n\n\t\treturn 0;\n\n\t}\n\n}\n\n/**\n * Returns a value linearly interpolated from two known points based on the given interval -\n * `t = 0` will return `x` and `t = 1` will return `y`.\n *\n * @param {number} x - The start point\n * @param {number} y - The end point.\n * @param {number} t - The interpolation factor in the closed interval `[0, 1]`.\n * @return {number} The interpolated value.\n */\nfunction lerp( x, y, t ) {\n\n\treturn ( 1 - t ) * x + t * y;\n\n}\n\n/**\n * Smoothly interpolate a number from `x` to `y` in a spring-like manner using a delta\n * time to maintain frame rate independent movement. For details, see\n * [Frame rate independent damping using lerp](http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/).\n *\n * @param {number} x - The current point.\n * @param {number} y - The target point.\n * @param {number} lambda - A higher lambda value will make the movement more sudden,\n * and a lower value will make the movement more gradual.\n * @param {number} dt - Delta time in seconds.\n * @return {number} The interpolated value.\n */\nfunction damp( x, y, lambda, dt ) {\n\n\treturn lerp( x, y, 1 - Math.exp( - lambda * dt ) );\n\n}\n\n/**\n * Returns a value that alternates between `0` and the given `length` parameter.\n *\n * @param {number} x - The value to pingpong.\n * @param {number} [length=1] - The positive value the function will pingpong to.\n * @return {number} The alternated value.\n */\nfunction pingpong( x, length = 1 ) {\n\n\t// https://www.desmos.com/calculator/vcsjnyz7x4\n\n\treturn length - Math.abs( euclideanModulo( x, length * 2 ) - length );\n\n}\n\n/**\n * Returns a value in the range `[0,1]` that represents the percentage that `x` has\n * moved between `min` and `max`, but smoothed or slowed down the closer `x` is to\n * the `min` and `max`.\n *\n * See [Smoothstep](http://en.wikipedia.org/wiki/Smoothstep) for more details.\n *\n * @param {number} x - The value to evaluate based on its position between min and max.\n * @param {number} min - The min value. Any x value below min will be `0`.\n * @param {number} max - The max value. Any x value above max will be `1`.\n * @return {number} The alternated value.\n */\nfunction smoothstep( x, min, max ) {\n\n\tif ( x <= min ) return 0;\n\tif ( x >= max ) return 1;\n\n\tx = ( x - min ) / ( max - min );\n\n\treturn x * x * ( 3 - 2 * x );\n\n}\n\n/**\n * A [variation on smoothstep](https://en.wikipedia.org/wiki/Smoothstep#Variations)\n * that has zero 1st and 2nd order derivatives at x=0 and x=1.\n *\n * @param {number} x - The value to evaluate based on its position between min and max.\n * @param {number} min - The min value. Any x value below min will be `0`.\n * @param {number} max - The max value. Any x value above max will be `1`.\n * @return {number} The alternated value.\n */\nfunction smootherstep( x, min, max ) {\n\n\tif ( x <= min ) return 0;\n\tif ( x >= max ) return 1;\n\n\tx = ( x - min ) / ( max - min );\n\n\treturn x * x * x * ( x * ( x * 6 - 15 ) + 10 );\n\n}\n\n/**\n * Returns a random integer from `<low, high>` interval.\n *\n * @param {number} low - The lower value boundary.\n * @param {number} high - The upper value boundary\n * @return {number} A random integer.\n */\nfunction randInt( low, high ) {\n\n\treturn low + Math.floor( Math.random() * ( high - low + 1 ) );\n\n}\n\n/**\n * Returns a random float from `<low, high>` interval.\n *\n * @param {number} low - The lower value boundary.\n * @param {number} high - The upper value boundary\n * @return {number} A random float.\n */\nfunction randFloat( low, high ) {\n\n\treturn low + Math.random() * ( high - low );\n\n}\n\n/**\n * Returns a random integer from `<-range/2, range/2>` interval.\n *\n * @param {number} range - Defines the value range.\n * @return {number} A random float.\n */\nfunction randFloatSpread( range ) {\n\n\treturn range * ( 0.5 - Math.random() );\n\n}\n\n/**\n * Returns a deterministic pseudo-random float in the interval `[0, 1]`.\n *\n * @param {number} [s] - The integer seed.\n * @return {number} A random float.\n */\nfunction seededRandom( s ) {\n\n\tif ( s !== undefined ) _seed = s;\n\n\t// Mulberry32 generator\n\n\tlet t = _seed += 0x6D2B79F5;\n\n\tt = Math.imul( t ^ t >>> 15, t | 1 );\n\n\tt ^= t + Math.imul( t ^ t >>> 7, t | 61 );\n\n\treturn ( ( t ^ t >>> 14 ) >>> 0 ) / 4294967296;\n\n}\n\n/**\n * Converts degrees to radians.\n *\n * @param {number} degrees - A value in degrees.\n * @return {number} The converted value in radians.\n */\nfunction degToRad( degrees ) {\n\n\treturn degrees * DEG2RAD;\n\n}\n\n/**\n * Converts radians to degrees.\n *\n * @param {number} radians - A value in radians.\n * @return {number} The converted value in degrees.\n */\nfunction radToDeg( radians ) {\n\n\treturn radians * RAD2DEG;\n\n}\n\n/**\n * Returns `true` if the given number is a power of two.\n *\n * @param {number} value - The value to check.\n * @return {boolean} Whether the given number is a power of two or not.\n */\nfunction isPowerOfTwo( value ) {\n\n\treturn ( value & ( value - 1 ) ) === 0 && value !== 0;\n\n}\n\n/**\n * Returns the smallest power of two that is greater than or equal to the given number.\n *\n * @param {number} value - The value to find a POT for.\n * @return {number} The smallest power of two that is greater than or equal to the given number.\n */\nfunction ceilPowerOfTwo( value ) {\n\n\treturn Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );\n\n}\n\n/**\n * Returns the largest power of two that is less than or equal to the given number.\n *\n * @param {number} value - The value to find a POT for.\n * @return {number} The largest power of two that is less than or equal to the given number.\n */\nfunction floorPowerOfTwo( value ) {\n\n\treturn Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );\n\n}\n\n/**\n * Sets the given quaternion from the [Intrinsic Proper Euler Angles](https://en.wikipedia.org/wiki/Euler_angles)\n * defined by the given angles and order.\n *\n * Rotations are applied to the axes in the order specified by order:\n * rotation by angle `a` is applied first, then by angle `b`, then by angle `c`.\n *\n * @param {Quaternion} q - The quaternion to set.\n * @param {number} a - The rotation applied to the first axis, in radians.\n * @param {number} b - The rotation applied to the second axis, in radians.\n * @param {number} c - The rotation applied to the third axis, in radians.\n * @param {('XYX'|'XZX'|'YXY'|'YZY'|'ZXZ'|'ZYZ')} order - A string specifying the axes order.\n */\nfunction setQuaternionFromProperEuler( q, a, b, c, order ) {\n\n\tconst cos = Math.cos;\n\tconst sin = Math.sin;\n\n\tconst c2 = cos( b / 2 );\n\tconst s2 = sin( b / 2 );\n\n\tconst c13 = cos( ( a + c ) / 2 );\n\tconst s13 = sin( ( a + c ) / 2 );\n\n\tconst c1_3 = cos( ( a - c ) / 2 );\n\tconst s1_3 = sin( ( a - c ) / 2 );\n\n\tconst c3_1 = cos( ( c - a ) / 2 );\n\tconst s3_1 = sin( ( c - a ) / 2 );\n\n\tswitch ( order ) {\n\n\t\tcase 'XYX':\n\t\t\tq.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'YZY':\n\t\t\tq.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'ZXZ':\n\t\t\tq.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'XZX':\n\t\t\tq.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'YXY':\n\t\t\tq.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );\n\t\t\tbreak;\n\n\t\tcase 'ZYZ':\n\t\t\tq.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );\n\t\t\tbreak;\n\n\t\tdefault:\n\t\t\twarn( 'MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );\n\n\t}\n\n}\n\n/**\n * Denormalizes the given value according to the given typed array.\n *\n * @param {number} value - The value to denormalize.\n * @param {TypedArray} array - The typed array that defines the data type of the value.\n * @return {number} The denormalize (float) value in the range `[0,1]`.\n */\nfunction denormalize( value, array ) {\n\n\tswitch ( array.constructor ) {\n\n\t\tcase Float32Array:\n\n\t\t\treturn value;\n\n\t\tcase Uint32Array:\n\n\t\t\treturn value / 4294967295.0;\n\n\t\tcase Uint16Array:\n\n\t\t\treturn value / 65535.0;\n\n\t\tcase Uint8Array:\n\n\t\t\treturn value / 255.0;\n\n\t\tcase Int32Array:\n\n\t\t\treturn Math.max( value / 2147483647.0, - 1.0 );\n\n\t\tcase Int16Array:\n\n\t\t\treturn Math.max( value / 32767.0, - 1.0 );\n\n\t\tcase Int8Array:\n\n\t\t\treturn Math.max( value / 127.0, - 1.0 );\n\n\t\tdefault:\n\n\t\t\tthrow new Error( 'Invalid component type.' );\n\n\t}\n\n}\n\n/**\n * Normalizes the given value according to the given typed array.\n *\n * @param {number} value - The float value in the range `[0,1]` to normalize.\n * @param {TypedArray} array - The typed array that defines the data type of the value.\n * @return {number} The normalize value.\n */\nfunction normalize( value, array ) {\n\n\tswitch ( array.constructor ) {\n\n\t\tcase Float32Array:\n\n\t\t\treturn value;\n\n\t\tcase Uint32Array:\n\n\t\t\treturn Math.round( value * 4294967295.0 );\n\n\t\tcase Uint16Array:\n\n\t\t\treturn Math.round( value * 65535.0 );\n\n\t\tcase Uint8Array:\n\n\t\t\treturn Math.round( value * 255.0 );\n\n\t\tcase Int32Array:\n\n\t\t\treturn Math.round( value * 2147483647.0 );\n\n\t\tcase Int16Array:\n\n\t\t\treturn Math.round( value * 32767.0 );\n\n\t\tcase Int8Array:\n\n\t\t\treturn Math.round( value * 127.0 );\n\n\t\tdefault:\n\n\t\t\tthrow new Error( 'Invalid component type.' );\n\n\t}\n\n}\n\n/**\n * @class\n * @classdesc A collection of math utility functions.\n * @hideconstructor\n */\nconst MathUtils = {\n\tDEG2RAD: DEG2RAD,\n\tRAD2DEG: RAD2DEG,\n\t/**\n\t * Generate a [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier)\n\t * (universally unique identifier).\n\t *\n\t * @static\n\t * @method\n\t * @return {string} The UUID.\n\t */\n\tgenerateUUID: generateUUID,\n\t/**\n\t * Clamps the given value between min and max.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} value - The value to clamp.\n\t * @param {number} min - The min value.\n\t * @param {number} max - The max value.\n\t * @return {number} The clamped value.\n\t */\n\tclamp: clamp,\n\t/**\n\t * Computes the Euclidean modulo of the given parameters that\n\t * is `( ( n % m ) + m ) % m`.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} n - The first parameter.\n\t * @param {number} m - The second parameter.\n\t * @return {number} The Euclidean modulo.\n\t */\n\teuclideanModulo: euclideanModulo,\n\t/**\n\t * Performs a linear mapping from range `<a1, a2>` to range `<b1, b2>`\n\t * for the given value.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The value to be mapped.\n\t * @param {number} a1 - Minimum value for range A.\n\t * @param {number} a2 - Maximum value for range A.\n\t * @param {number} b1 - Minimum value for range B.\n\t * @param {number} b2 - Maximum value for range B.\n\t * @return {number} The mapped value.\n\t */\n\tmapLinear: mapLinear,\n\t/**\n\t * Returns the percentage in the closed interval `[0, 1]` of the given value\n\t * between the start and end point.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The start point\n\t * @param {number} y - The end point.\n\t * @param {number} value - A value between start and end.\n\t * @return {number} The interpolation factor.\n\t */\n\tinverseLerp: inverseLerp,\n\t/**\n\t * Returns a value linearly interpolated from two known points based on the given interval -\n\t * `t = 0` will return `x` and `t = 1` will return `y`.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The start point\n\t * @param {number} y - The end point.\n\t * @param {number} t - The interpolation factor in the closed interval `[0, 1]`.\n\t * @return {number} The interpolated value.\n\t */\n\tlerp: lerp,\n\t/**\n\t * Smoothly interpolate a number from `x` to `y` in a spring-like manner using a delta\n\t * time to maintain frame rate independent movement. For details, see\n\t * [Frame rate independent damping using lerp](http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/).\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The current point.\n\t * @param {number} y - The target point.\n\t * @param {number} lambda - A higher lambda value will make the movement more sudden,\n\t * and a lower value will make the movement more gradual.\n\t * @param {number} dt - Delta time in seconds.\n\t * @return {number} The interpolated value.\n\t */\n\tdamp: damp,\n\t/**\n\t * Returns a value that alternates between `0` and the given `length` parameter.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The value to pingpong.\n\t * @param {number} [length=1] - The positive value the function will pingpong to.\n\t * @return {number} The alternated value.\n\t */\n\tpingpong: pingpong,\n\t/**\n\t * Returns a value in the range `[0,1]` that represents the percentage that `x` has\n\t * moved between `min` and `max`, but smoothed or slowed down the closer `x` is to\n\t * the `min` and `max`.\n\t *\n\t * See [Smoothstep](http://en.wikipedia.org/wiki/Smoothstep) for more details.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The value to evaluate based on its position between min and max.\n\t * @param {number} min - The min value. Any x value below min will be `0`.\n\t * @param {number} max - The max value. Any x value above max will be `1`.\n\t * @return {number} The alternated value.\n\t */\n\tsmoothstep: smoothstep,\n\t/**\n\t * A [variation on smoothstep](https://en.wikipedia.org/wiki/Smoothstep#Variations)\n\t * that has zero 1st and 2nd order derivatives at x=0 and x=1.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} x - The value to evaluate based on its position between min and max.\n\t * @param {number} min - The min value. Any x value below min will be `0`.\n\t * @param {number} max - The max value. Any x value above max will be `1`.\n\t * @return {number} The alternated value.\n\t */\n\tsmootherstep: smootherstep,\n\t/**\n\t * Returns a random integer from `<low, high>` interval.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} low - The lower value boundary.\n\t * @param {number} high - The upper value boundary\n\t * @return {number} A random integer.\n\t */\n\trandInt: randInt,\n\t/**\n\t * Returns a random float from `<low, high>` interval.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} low - The lower value boundary.\n\t * @param {number} high - The upper value boundary\n\t * @return {number} A random float.\n\t */\n\trandFloat: randFloat,\n\t/**\n\t * Returns a random integer from `<-range/2, range/2>` interval.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} range - Defines the value range.\n\t * @return {number} A random float.\n\t */\n\trandFloatSpread: randFloatSpread,\n\t/**\n\t * Returns a deterministic pseudo-random float in the interval `[0, 1]`.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} [s] - The integer seed.\n\t * @return {number} A random float.\n\t */\n\tseededRandom: seededRandom,\n\t/**\n\t * Converts degrees to radians.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} degrees - A value in degrees.\n\t * @return {number} The converted value in radians.\n\t */\n\tdegToRad: degToRad,\n\t/**\n\t * Converts radians to degrees.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} radians - A value in radians.\n\t * @return {number} The converted value in degrees.\n\t */\n\tradToDeg: radToDeg,\n\t/**\n\t * Returns `true` if the given number is a power of two.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} value - The value to check.\n\t * @return {boolean} Whether the given number is a power of two or not.\n\t */\n\tisPowerOfTwo: isPowerOfTwo,\n\t/**\n\t * Returns the smallest power of two that is greater than or equal to the given number.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} value - The value to find a POT for.\n\t * @return {number} The smallest power of two that is greater than or equal to the given number.\n\t */\n\tceilPowerOfTwo: ceilPowerOfTwo,\n\t/**\n\t * Returns the largest power of two that is less than or equal to the given number.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} value - The value to find a POT for.\n\t * @return {number} The largest power of two that is less than or equal to the given number.\n\t */\n\tfloorPowerOfTwo: floorPowerOfTwo,\n\t/**\n\t * Sets the given quaternion from the [Intrinsic Proper Euler Angles](https://en.wikipedia.org/wiki/Euler_angles)\n\t * defined by the given angles and order.\n\t *\n\t * Rotations are applied to the axes in the order specified by order:\n\t * rotation by angle `a` is applied first, then by angle `b`, then by angle `c`.\n\t *\n\t * @static\n\t * @method\n\t * @param {Quaternion} q - The quaternion to set.\n\t * @param {number} a - The rotation applied to the first axis, in radians.\n\t * @param {number} b - The rotation applied to the second axis, in radians.\n\t * @param {number} c - The rotation applied to the third axis, in radians.\n\t * @param {('XYX'|'XZX'|'YXY'|'YZY'|'ZXZ'|'ZYZ')} order - A string specifying the axes order.\n\t */\n\tsetQuaternionFromProperEuler: setQuaternionFromProperEuler,\n\t/**\n\t * Normalizes the given value according to the given typed array.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} value - The float value in the range `[0,1]` to normalize.\n\t * @param {TypedArray} array - The typed array that defines the data type of the value.\n\t * @return {number} The normalize value.\n\t */\n\tnormalize: normalize,\n\t/**\n\t * Denormalizes the given value according to the given typed array.\n\t *\n\t * @static\n\t * @method\n\t * @param {number} value - The value to denormalize.\n\t * @param {TypedArray} array - The typed array that defines the data type of the value.\n\t * @return {number} The denormalize (float) value in the range `[0,1]`.\n\t */\n\tdenormalize: denormalize\n};\n\nexport {\n\tDEG2RAD,\n\tRAD2DEG,\n\tgenerateUUID,\n\tclamp,\n\teuclideanModulo,\n\tmapLinear,\n\tinverseLerp,\n\tlerp,\n\tdamp,\n\tpingpong,\n\tsmoothstep,\n\tsmootherstep,\n\trandInt,\n\trandFloat,\n\trandFloatSpread,\n\tseededRandom,\n\tdegToRad,\n\tradToDeg,\n\tisPowerOfTwo,\n\tceilPowerOfTwo,\n\tfloorPowerOfTwo,\n\tsetQuaternionFromProperEuler,\n\tnormalize,\n\tdenormalize,\n\tMathUtils\n};\n"],"names":[],"mappings":"AA0GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG;;AAEzB,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC;;AAE7B;;;;","x_google_ignoreList":[0]}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { Intersection } from '@pmndrs/pointer-events';
8
+ import type { XROrigin } from '../rig/xr-origin.js';
9
+ /**
10
+ * Shared cursor visual that can be updated from any pointer's intersection.
11
+ * Renders as a circle mesh positioned at the intersection point, oriented to the surface normal.
12
+ *
13
+ * @category Pointer
14
+ */
15
+ export declare class CursorVisual {
16
+ private xrOrigin;
17
+ private cursor;
18
+ private zOffset;
19
+ private focusAlpha;
20
+ constructor(xrOrigin: XROrigin, pointerIndex: number);
21
+ /**
22
+ * Update cursor position and orientation from an intersection.
23
+ */
24
+ updateFromIntersection(intersection: Intersection, delta: number, focused: boolean): void;
25
+ /**
26
+ * Set cursor visibility.
27
+ */
28
+ setVisible(visible: boolean): void;
29
+ /**
30
+ * Dispose of cursor resources.
31
+ */
32
+ dispose(): void;
33
+ }
34
+ //# sourceMappingURL=cursor-visual.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor-visual.d.ts","sourceRoot":"","sources":["../../src/pointer/cursor-visual.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAW3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AA6BpD;;;;;GAKG;AACH,qBAAa,YAAY;IAMrB,OAAO,CAAC,QAAQ;IALlB,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAK;gBAGb,QAAQ,EAAE,QAAQ,EAC1B,YAAY,EAAE,MAAM;IAetB;;OAEG;IACH,sBAAsB,CACpB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,GACf,IAAI;IA0CP;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAIlC;;OAEG;IACH,OAAO,IAAI,IAAI;CAKhB"}
@@ -0,0 +1,110 @@
1
+ import { CanvasTexture, Vector3, Quaternion, Matrix3, Mesh, CircleGeometry, MeshBasicMaterial } from 'three';
2
+ import { lerp } from '../node_modules/.pnpm/super-three@0.181.0/node_modules/super-three/src/math/MathUtils.js';
3
+
4
+ /**
5
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+ // Create shared cursor texture
11
+ const cursorRes = 512;
12
+ const canvas = document.createElement('canvas');
13
+ canvas.width = cursorRes;
14
+ canvas.height = cursorRes;
15
+ const ctx = canvas.getContext('2d');
16
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
17
+ ctx.fillStyle = 'white';
18
+ ctx.beginPath();
19
+ ctx.arc(cursorRes / 2, cursorRes / 2, (cursorRes / 16) * 7, 0, Math.PI * 2);
20
+ ctx.fill();
21
+ ctx.strokeStyle = 'gray';
22
+ ctx.lineWidth = 3;
23
+ ctx.beginPath();
24
+ ctx.arc(cursorRes / 2, cursorRes / 2, (cursorRes / 16) * 7, 0, Math.PI * 2);
25
+ ctx.stroke();
26
+ const cursorTexture = new CanvasTexture(canvas);
27
+ const ZAxis = new Vector3(0, 0, 1);
28
+ const offsetHelper = new Vector3();
29
+ const cursorPosition = new Vector3();
30
+ const quaternionHelper = new Quaternion();
31
+ const scratchNormal = new Vector3();
32
+ const scratchNormalMatrix = new Matrix3();
33
+ let cursorCount = 0;
34
+ /**
35
+ * Shared cursor visual that can be updated from any pointer's intersection.
36
+ * Renders as a circle mesh positioned at the intersection point, oriented to the surface normal.
37
+ *
38
+ * @category Pointer
39
+ */
40
+ class CursorVisual {
41
+ constructor(xrOrigin, pointerIndex) {
42
+ this.xrOrigin = xrOrigin;
43
+ this.focusAlpha = 0;
44
+ this.cursor = new Mesh(new CircleGeometry(0.008), new MeshBasicMaterial({
45
+ map: cursorTexture,
46
+ transparent: true,
47
+ }));
48
+ this.cursor.renderOrder = Infinity;
49
+ this.cursor.userData.attached = true;
50
+ this.zOffset = 0.004 + (pointerIndex + cursorCount++) * 0.001;
51
+ xrOrigin.add(this.cursor);
52
+ }
53
+ /**
54
+ * Update cursor position and orientation from an intersection.
55
+ */
56
+ updateFromIntersection(intersection, delta, focused) {
57
+ var _a, _b;
58
+ cursorPosition.copy(intersection.pointOnFace);
59
+ this.focusAlpha = lerp(this.focusAlpha, focused ? 1 : 0, 30 * delta);
60
+ const cursorScale = (Math.max(0, intersection.distance - 0.3) + 1) *
61
+ lerp(1, 0.8, this.focusAlpha);
62
+ this.cursor.material.opacity = lerp(0.7, 1, this.focusAlpha);
63
+ this.cursor.scale.setScalar(cursorScale);
64
+ const normal = (_a = intersection.normal) !== null && _a !== void 0 ? _a : (_b = intersection.face) === null || _b === void 0 ? void 0 : _b.normal;
65
+ if (normal != null) {
66
+ // Convert local-space normal to world-space using normal matrix to handle non-uniform scales
67
+ scratchNormal.copy(normal);
68
+ scratchNormalMatrix.getNormalMatrix(intersection.object.matrixWorld);
69
+ scratchNormal.applyNormalMatrix(scratchNormalMatrix).normalize();
70
+ // Build world-space orientation from +Z to world normal
71
+ this.cursor.quaternion.setFromUnitVectors(ZAxis, scratchNormal);
72
+ // Convert world orientation to xrOrigin local space
73
+ quaternionHelper.copy(this.xrOrigin.quaternion).invert();
74
+ this.cursor.quaternion.multiply(quaternionHelper);
75
+ // Offset slightly along the oriented normal to avoid z-fighting
76
+ offsetHelper.set(0, 0, this.zOffset);
77
+ offsetHelper.applyQuaternion(this.cursor.quaternion);
78
+ cursorPosition.add(offsetHelper);
79
+ }
80
+ else if (intersection.pointerQuaternion) {
81
+ // Fallback: align cursor with pointer direction when no surface normal is available
82
+ this.cursor.quaternion.copy(intersection.pointerQuaternion);
83
+ quaternionHelper.copy(this.xrOrigin.quaternion).invert();
84
+ this.cursor.quaternion.multiply(quaternionHelper);
85
+ offsetHelper.set(0, 0, this.zOffset);
86
+ offsetHelper.applyQuaternion(this.cursor.quaternion);
87
+ cursorPosition.add(offsetHelper);
88
+ }
89
+ this.xrOrigin.worldToLocal(cursorPosition);
90
+ this.cursor.position.copy(cursorPosition);
91
+ this.cursor.updateMatrix();
92
+ }
93
+ /**
94
+ * Set cursor visibility.
95
+ */
96
+ setVisible(visible) {
97
+ this.cursor.visible = visible;
98
+ }
99
+ /**
100
+ * Dispose of cursor resources.
101
+ */
102
+ dispose() {
103
+ this.cursor.geometry.dispose();
104
+ this.cursor.material.dispose();
105
+ this.cursor.removeFromParent();
106
+ }
107
+ }
108
+
109
+ export { CursorVisual };
110
+ //# sourceMappingURL=cursor-visual.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor-visual.js","sources":["../../src/pointer/cursor-visual.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAAA;;;;;AAKG;AAeH;AACA,MAAM,SAAS,GAAG,GAAG;AACrB,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC;AAC/C,MAAM,CAAC,KAAK,GAAG,SAAS;AACxB,MAAM,CAAC,MAAM,GAAG,SAAS;AACzB,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAE;AACpC,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;AA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M,CAAC,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC;AACzC,QAAA,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE;IAC5B;AAEA;;AAEG;AACH,IAAA,UAAU,CAAC,OAAgB,EAAA;AACzB,QAAA,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,OAAO;IAC/B;AAEA;;AAEG;IACH,OAAO,GAAA;AACL,QAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE;AAC9B,QAAA,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE;IAChC;AACD;;;;"}
@@ -4,42 +4,167 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
+ import { Pointer } from '@pmndrs/pointer-events';
7
8
  import type { Object3D, PerspectiveCamera } from 'three';
8
9
  import type { XROrigin } from '../rig/xr-origin.js';
9
- export type PointerKind = 'ray' | 'grab' | 'custom';
10
+ export type PointerKind = 'ray' | 'grab' | 'touch';
11
+ /**
12
+ * Interactor state machine states
13
+ */
14
+ export declare enum InteractorState {
15
+ /** Pointer not registered or not enabled */
16
+ DISABLED = "disabled",
17
+ /** Pointer enabled, no candidate */
18
+ NORMAL = "normal",
19
+ /** Pointer has candidate, hovering over object */
20
+ HOVER = "hover",
21
+ /** Pointer actively selecting object */
22
+ SELECT = "select"
23
+ }
24
+ /**
25
+ * MultiPointer orchestrates multiple pointer types using priority-based selection.
26
+ *
27
+ * @remarks
28
+ * - Priority order: Touch > Grab > Ray
29
+ * - Uses state machine: DISABLED ↔ NORMAL ↔ HOVER ↔ SELECT
30
+ * - Selection lock: Once a pointer starts selecting, it stays locked until release
31
+ * - Hysteresis: Touch pointer uses separate enter/exit thresholds to prevent flickering
32
+ *
33
+ * @category Pointer
34
+ */
10
35
  export declare class MultiPointer {
11
36
  private readonly handedness;
12
37
  private readonly scene;
13
38
  private readonly camera;
14
39
  private readonly xrOrigin;
15
- private readonly combined;
16
- private readonly registered;
17
- private ray?;
18
- private grab?;
19
- private defaultKind;
40
+ private ray;
41
+ private grab;
42
+ private touch;
43
+ private cursorVisual;
44
+ /** Current active pointer kind (winner of priority selection) */
45
+ private activeKind;
46
+ /** State for each pointer type */
47
+ private pointerStates;
48
+ /** Hysteresis tracking: whether touch is currently in hover state */
49
+ private touchHoverActive;
50
+ /** Cached scene reference with type-specific descendants */
51
+ private sceneWithDescendants;
52
+ /** Reusable native event object to avoid per-frame allocations */
53
+ private readonly nativeEvent;
54
+ /** Reusable policy object for ray rendering */
55
+ private readonly rayPolicy;
56
+ /** Reusable event object for pointer down/up with button */
57
+ private readonly buttonEvent;
20
58
  constructor(handedness: 'left' | 'right', scene: Object3D, camera: PerspectiveCamera, xrOrigin: XROrigin);
59
+ /**
60
+ * Main update loop - implements priority-based pointer selection
61
+ */
21
62
  update(connected: boolean, delta: number, time: number, input?: {
22
63
  selectStart?: boolean;
23
64
  selectEnd?: boolean;
24
65
  squeezeStart?: boolean;
25
66
  squeezeEnd?: boolean;
26
67
  }): void;
68
+ /**
69
+ * Update enabled state for all registered pointers
70
+ */
71
+ private updatePointerEnabled;
72
+ /**
73
+ * Update enabled state for a single pointer (avoids array allocation)
74
+ */
75
+ private updateSinglePointerEnabled;
76
+ /**
77
+ * Compute intersections for all enabled pointers using type-specific descendant arrays.
78
+ * Swaps scene.interactableDescendants per pointer type for optimized traversal.
79
+ */
80
+ private computeAllIntersections;
81
+ /**
82
+ * Move a single pointer using its type-specific descendants.
83
+ * Used when selection is locked to avoid unnecessary traversal.
84
+ */
85
+ private movePointerWithDescendants;
86
+ /**
87
+ * Pick active pointer by priority - first with valid candidate wins
88
+ */
89
+ private pickActiveByPriority;
90
+ /**
91
+ * Check if a pointer has a valid candidate (intersection)
92
+ */
93
+ private hasValidCandidate;
94
+ /**
95
+ * Switch active pointer to a new kind
96
+ */
97
+ private switchActivePointer;
98
+ /**
99
+ * Process lifecycle transitions based on input
100
+ */
101
+ private processLifecycle;
102
+ /**
103
+ * Process touch pointer lifecycle - auto-selects based on distance
104
+ */
105
+ private processTouchLifecycle;
106
+ /**
107
+ * Process button-based pointer lifecycle (ray/grab)
108
+ */
109
+ private processButtonLifecycle;
110
+ /**
111
+ * Get the policy for ray visual rendering
112
+ */
27
113
  getPolicyForRay(): {
28
114
  forceHideRay: boolean;
29
- forceHideCursor: boolean;
30
115
  };
116
+ /**
117
+ * Check if ray is busy (has intersection)
118
+ */
31
119
  getRayBusy(): boolean;
120
+ /**
121
+ * Toggle a sub-pointer on/off
122
+ */
123
+ toggleSubPointer(kind: PointerKind, enabled: boolean): boolean;
124
+ /**
125
+ * Get the registration state of a sub-pointer
126
+ */
127
+ getSubPointerState(kind: PointerKind): {
128
+ registered: boolean;
129
+ };
130
+ /**
131
+ * Get the currently active pointer kind
132
+ */
133
+ getActiveKind(): PointerKind | null;
134
+ /**
135
+ * Get the currently active pointer
136
+ */
137
+ getActivePointer(): Pointer | null;
138
+ /**
139
+ * Get a specific pointer by kind
140
+ */
141
+ getPointer(kind: PointerKind): Pointer;
142
+ /**
143
+ * Route a down event to a specific pointer target.
144
+ * Used by grab-system for hand pinch gestures.
145
+ */
32
146
  routeDown(kind: 'select' | 'squeeze' | 'custom', target: 'ray' | 'grab' | 'active', nativeEvent: {
33
147
  timeStamp: number;
34
148
  }): void;
149
+ /**
150
+ * Route an up event to a specific pointer target.
151
+ * Used by grab-system for hand pinch gestures.
152
+ */
35
153
  routeUp(kind: 'select' | 'squeeze' | 'custom', target: 'ray' | 'grab' | 'active', nativeEvent: {
36
154
  timeStamp: number;
37
155
  }): void;
156
+ /**
157
+ * Pick pointer by target type.
158
+ */
38
159
  private pickTarget;
39
- toggleSubPointer(kind: PointerKind, enabled: boolean): boolean;
40
- getSubPointerState(kind: PointerKind): {
41
- registered: boolean;
42
- };
43
- setDefault(kind: PointerKind): void;
160
+ /**
161
+ * Get the entry for a pointer kind
162
+ */
163
+ private getEntry;
164
+ /**
165
+ * Dispose of all pointer resources.
166
+ * Call this when the MultiPointer is no longer needed.
167
+ */
168
+ dispose(): void;
44
169
  }
45
170
  //# sourceMappingURL=multi-pointer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"multi-pointer.d.ts","sourceRoot":"","sources":["../../src/pointer/multi-pointer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AACzD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAIpD,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;AAQpD,qBAAa,YAAY;IAkBrB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IApB3B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,GAAG,CAAC,CAKV;IACF,OAAO,CAAC,IAAI,CAAC,CAKX;IACF,OAAO,CAAC,WAAW,CAAsB;gBAGtB,UAAU,EAAE,MAAM,GAAG,OAAO,EAC5B,KAAK,EAAE,QAAQ,EACf,MAAM,EAAE,iBAAiB,EACzB,QAAQ,EAAE,QAAQ;IAWrC,MAAM,CACJ,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE;QACN,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,UAAU,CAAC,EAAE,OAAO,CAAC;KACtB;IAkCH,eAAe;;;;IAef,UAAU,IAAI,OAA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