@react-three/drei 9.83.9 → 9.84.0

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 (255) hide show
  1. package/README.md +70 -2
  2. package/core/AccumulativeShadows.d.ts +3 -3
  3. package/core/AccumulativeShadows.js +30 -36
  4. package/core/AdaptiveDpr.js +4 -4
  5. package/core/ArcballControls.d.ts +1 -1
  6. package/core/ArcballControls.js +0 -1
  7. package/core/AsciiRenderer.d.ts +3 -3
  8. package/core/AsciiRenderer.js +12 -6
  9. package/core/BBAnchor.cjs.js +1 -1
  10. package/core/BBAnchor.d.ts +2 -2
  11. package/core/BBAnchor.js +5 -5
  12. package/core/Backdrop.d.ts +2 -2
  13. package/core/Backdrop.js +0 -3
  14. package/core/Billboard.d.ts +1 -1
  15. package/core/Billboard.js +6 -3
  16. package/core/Bounds.d.ts +5 -5
  17. package/core/Bounds.js +5 -32
  18. package/core/CameraControls.d.ts +2 -2
  19. package/core/CameraControls.js +0 -3
  20. package/core/CameraShake.js +0 -4
  21. package/core/CatmullRomLine.d.ts +1 -1
  22. package/core/CatmullRomLine.js +0 -2
  23. package/core/Caustics.d.ts +1 -1
  24. package/core/Caustics.js +31 -32
  25. package/core/Center.d.ts +2 -2
  26. package/core/Center.js +2 -1
  27. package/core/Clone.d.ts +1 -1
  28. package/core/Clone.js +10 -13
  29. package/core/Cloud.cjs.js +1 -1
  30. package/core/Cloud.d.ts +2 -2
  31. package/core/Cloud.js +1 -2
  32. package/core/ComputedAttribute.d.ts +2 -2
  33. package/core/ComputedAttribute.js +0 -1
  34. package/core/ContactShadows.d.ts +1 -1
  35. package/core/ContactShadows.js +6 -7
  36. package/core/CubeCamera.cjs.js +1 -1
  37. package/core/CubeCamera.d.ts +2 -2
  38. package/core/CubeCamera.js +1 -1
  39. package/core/CubicBezierLine.d.ts +1 -1
  40. package/core/CurveModifier.d.ts +1 -1
  41. package/core/CurveModifier.js +2 -4
  42. package/core/Decal.d.ts +1 -1
  43. package/core/Decal.js +8 -15
  44. package/core/Detailed.d.ts +1 -1
  45. package/core/Detailed.js +0 -1
  46. package/core/DeviceOrientationControls.d.ts +1 -1
  47. package/core/DeviceOrientationControls.js +3 -4
  48. package/core/Edges.d.ts +1 -1
  49. package/core/Edges.js +0 -2
  50. package/core/Effects.d.ts +1 -1
  51. package/core/Effects.js +5 -7
  52. package/core/Environment.d.ts +3 -3
  53. package/core/Environment.js +6 -12
  54. package/core/Example.d.ts +3 -3
  55. package/core/Example.js +2 -1
  56. package/core/FaceControls.cjs.js +1 -1
  57. package/core/FaceControls.d.ts +5 -5
  58. package/core/FaceControls.js +42 -39
  59. package/core/FaceLandmarker.d.ts +3 -2
  60. package/core/FaceLandmarker.js +1 -1
  61. package/core/Facemesh.d.ts +6 -6
  62. package/core/Facemesh.js +47 -53
  63. package/core/FirstPersonControls.d.ts +1 -1
  64. package/core/Float.d.ts +1 -1
  65. package/core/Float.js +0 -1
  66. package/core/FlyControls.d.ts +1 -1
  67. package/core/FlyControls.js +1 -2
  68. package/core/GizmoHelper.cjs.js +1 -1
  69. package/core/GizmoHelper.d.ts +2 -2
  70. package/core/GizmoHelper.js +18 -19
  71. package/core/GizmoViewcube.d.ts +3 -3
  72. package/core/GizmoViewcube.js +0 -14
  73. package/core/GizmoViewport.d.ts +3 -3
  74. package/core/GizmoViewport.js +0 -7
  75. package/core/Gltf.d.ts +1 -1
  76. package/core/GradientTexture.d.ts +3 -3
  77. package/core/GradientTexture.js +2 -5
  78. package/core/Grid.d.ts +2 -2
  79. package/core/Grid.js +2 -6
  80. package/core/Hud.d.ts +2 -2
  81. package/core/Hud.js +6 -9
  82. package/core/Image.d.ts +2 -2
  83. package/core/Image.js +4 -6
  84. package/core/Instances.d.ts +6 -6
  85. package/core/Instances.js +20 -35
  86. package/core/Lightformer.d.ts +1 -1
  87. package/core/Lightformer.js +4 -2
  88. package/core/Line.d.ts +1 -1
  89. package/core/Line.js +0 -3
  90. package/core/MapControls.d.ts +1 -1
  91. package/core/MapControls.js +0 -2
  92. package/core/MarchingCubes.d.ts +3 -3
  93. package/core/Mask.d.ts +1 -1
  94. package/core/MeshDistortMaterial.d.ts +2 -2
  95. package/core/MeshDistortMaterial.js +0 -9
  96. package/core/MeshPortalMaterial.d.ts +4 -4
  97. package/core/MeshPortalMaterial.js +22 -61
  98. package/core/MeshReflectorMaterial.d.ts +1 -1
  99. package/core/MeshReflectorMaterial.js +12 -14
  100. package/core/MeshRefractionMaterial.cjs.js +1 -1
  101. package/core/MeshRefractionMaterial.d.ts +3 -3
  102. package/core/MeshRefractionMaterial.js +9 -14
  103. package/core/MeshTransmissionMaterial.d.ts +2 -2
  104. package/core/MeshTransmissionMaterial.js +32 -33
  105. package/core/MeshWobbleMaterial.d.ts +2 -2
  106. package/core/MeshWobbleMaterial.js +0 -7
  107. package/core/MotionPathControls.cjs.js +1 -0
  108. package/core/MotionPathControls.d.ts +15 -0
  109. package/core/MotionPathControls.js +114 -0
  110. package/core/OrbitControls.d.ts +2 -2
  111. package/core/OrbitControls.js +0 -4
  112. package/core/OrthographicCamera.d.ts +1 -1
  113. package/core/OrthographicCamera.js +2 -3
  114. package/core/Outlines.cjs.js +1 -1
  115. package/core/Outlines.d.ts +3 -3
  116. package/core/Outlines.js +2 -7
  117. package/core/PerformanceMonitor.d.ts +4 -4
  118. package/core/PerformanceMonitor.js +8 -12
  119. package/core/PerspectiveCamera.d.ts +1 -1
  120. package/core/PerspectiveCamera.js +2 -3
  121. package/core/PointMaterial.d.ts +1 -1
  122. package/core/PointMaterial.js +0 -2
  123. package/core/PointerLockControls.d.ts +1 -1
  124. package/core/PointerLockControls.js +4 -6
  125. package/core/Points.d.ts +2 -2
  126. package/core/Points.js +6 -23
  127. package/core/PositionalAudio.d.ts +1 -1
  128. package/core/PositionalAudio.js +0 -5
  129. package/core/Preload.d.ts +1 -1
  130. package/core/Preload.js +8 -9
  131. package/core/QuadraticBezierLine.d.ts +2 -2
  132. package/core/QuadraticBezierLine.js +0 -2
  133. package/core/Reflector.d.ts +1 -1
  134. package/core/Reflector.js +11 -12
  135. package/core/RenderTexture.d.ts +1 -1
  136. package/core/RenderTexture.js +9 -11
  137. package/core/Resize.d.ts +2 -2
  138. package/core/RoundedBox.cjs.js +1 -1
  139. package/core/RoundedBox.d.ts +1 -1
  140. package/core/RoundedBox.js +1 -3
  141. package/core/Sampler.d.ts +5 -5
  142. package/core/Sampler.js +0 -10
  143. package/core/ScreenQuad.d.ts +1 -1
  144. package/core/ScreenQuad.js +0 -1
  145. package/core/ScreenSpace.d.ts +1 -1
  146. package/core/Segments.d.ts +2 -2
  147. package/core/Segments.js +0 -6
  148. package/core/Shadow.d.ts +1 -1
  149. package/core/Sky.d.ts +1 -1
  150. package/core/Sparkles.js +0 -10
  151. package/core/SpotLight.d.ts +2 -2
  152. package/core/SpotLight.js +3 -10
  153. package/core/SpriteAnimator.d.ts +1 -1
  154. package/core/SpriteAnimator.js +16 -34
  155. package/core/Stage.d.ts +4 -4
  156. package/core/Stage.js +2 -4
  157. package/core/Stars.d.ts +1 -1
  158. package/core/Stars.js +2 -11
  159. package/core/Stats.d.ts +1 -1
  160. package/core/Stats.js +2 -2
  161. package/core/StatsGl.d.ts +1 -1
  162. package/core/StatsGl.js +4 -3
  163. package/core/Svg.js +0 -2
  164. package/core/Text.d.ts +1 -1
  165. package/core/Text3D.d.ts +1 -1
  166. package/core/Text3D.js +1 -3
  167. package/core/TrackballControls.d.ts +1 -1
  168. package/core/TrackballControls.js +0 -1
  169. package/core/Trail.d.ts +3 -3
  170. package/core/Trail.js +6 -17
  171. package/core/TransformControls.d.ts +1 -1
  172. package/core/TransformControls.js +3 -9
  173. package/core/Wireframe.d.ts +1 -1
  174. package/core/Wireframe.js +0 -28
  175. package/core/index.cjs.js +1 -1
  176. package/core/index.d.ts +1 -0
  177. package/core/index.js +1 -0
  178. package/core/meshBounds.js +4 -14
  179. package/core/shaderMaterial.js +10 -9
  180. package/core/shapes.d.ts +2 -2
  181. package/core/shapes.js +3 -6
  182. package/core/softShadows.d.ts +1 -1
  183. package/core/softShadows.js +1 -4
  184. package/core/useAnimations.d.ts +1 -1
  185. package/core/useAnimations.js +2 -4
  186. package/core/useBVH.d.ts +1 -1
  187. package/core/useBVH.js +3 -4
  188. package/core/useBoxProjectedEnv.js +15 -22
  189. package/core/useCamera.js +0 -1
  190. package/core/useContextBridge.js +1 -2
  191. package/core/useCubeCamera.d.ts +1 -1
  192. package/core/useCubeTexture.d.ts +1 -1
  193. package/core/useCubeTexture.js +4 -3
  194. package/core/useEnvironment.cjs.js +1 -1
  195. package/core/useEnvironment.d.ts +2 -2
  196. package/core/useEnvironment.js +9 -11
  197. package/core/useFBO.d.ts +1 -1
  198. package/core/useFBO.js +3 -12
  199. package/core/useFBX.js +0 -2
  200. package/core/useFont.d.ts +2 -2
  201. package/core/useFont.js +0 -4
  202. package/core/useGLTF.d.ts +2 -2
  203. package/core/useGLTF.js +0 -8
  204. package/core/useHelper.d.ts +3 -3
  205. package/core/useHelper.js +2 -5
  206. package/core/useIntersect.js +5 -8
  207. package/core/useKTX2.js +3 -5
  208. package/core/useMatcapTexture.js +0 -6
  209. package/core/useNormalTexture.d.ts +1 -1
  210. package/core/useProgress.d.ts +1 -1
  211. package/core/useProgress.js +0 -5
  212. package/core/useTexture.js +4 -6
  213. package/core/useTrailTexture.d.ts +1 -1
  214. package/core/useTrailTexture.js +10 -21
  215. package/helpers/environment-assets.d.ts +1 -1
  216. package/helpers/ts-utils.d.ts +2 -2
  217. package/helpers/useEffectfulState.d.ts +1 -1
  218. package/helpers/useEffectfulState.js +0 -1
  219. package/index.cjs.js +1 -1
  220. package/index.js +1 -0
  221. package/materials/BlurPass.js +2 -5
  222. package/materials/ConvolutionMaterial.js +0 -3
  223. package/materials/MeshReflectorMaterial.d.ts +1 -1
  224. package/materials/MeshReflectorMaterial.js +0 -34
  225. package/materials/MeshRefractionMaterial.js +2 -6
  226. package/materials/SpotLightMaterial.js +2 -7
  227. package/materials/WireframeMaterial.js +7 -25
  228. package/native/index.cjs.js +1 -1
  229. package/native/index.js +1 -0
  230. package/package.json +2 -2
  231. package/react-three-drei-0.0.0-semantic-release.tgz +0 -0
  232. package/web/CycleRaycast.d.ts +1 -1
  233. package/web/CycleRaycast.js +20 -24
  234. package/web/Html.d.ts +2 -2
  235. package/web/Html.js +6 -50
  236. package/web/KeyboardControls.d.ts +10 -10
  237. package/web/KeyboardControls.js +9 -6
  238. package/web/Loader.d.ts +2 -2
  239. package/web/Loader.js +8 -5
  240. package/web/PresentationControls.d.ts +2 -2
  241. package/web/PresentationControls.js +2 -1
  242. package/web/ScrollControls.d.ts +4 -4
  243. package/web/ScrollControls.js +5 -16
  244. package/web/Select.d.ts +3 -3
  245. package/web/Select.js +6 -17
  246. package/web/View.d.ts +5 -5
  247. package/web/View.js +7 -20
  248. package/web/index.cjs.js +1 -1
  249. package/web/index.js +1 -0
  250. package/web/pivotControls/AxisArrow.js +6 -15
  251. package/web/pivotControls/AxisRotator.js +8 -23
  252. package/web/pivotControls/PlaneSlider.js +6 -16
  253. package/web/pivotControls/context.d.ts +2 -2
  254. package/web/pivotControls/index.d.ts +1 -1
  255. package/web/pivotControls/index.js +2 -9
@@ -10,19 +10,19 @@ import { Facemesh } from './Facemesh.js';
10
10
  import { useFaceLandmarker } from './FaceLandmarker.js';
11
11
 
12
12
  // useVideoTexture 1st arg `src` type
13
+
13
14
  function mean(v1, v2) {
14
15
  return v1.clone().add(v2).multiplyScalar(0.5);
15
16
  }
16
-
17
17
  function localToLocal(objSrc, v, objDst) {
18
18
  // see: https://discourse.threejs.org/t/object3d-localtolocal/51564
19
19
  const v_world = objSrc.localToWorld(v);
20
20
  return objDst.worldToLocal(v_world);
21
- } //
21
+ }
22
+
23
+ //
22
24
  //
23
25
  //
24
-
25
-
26
26
  const FaceControlsContext = /*#__PURE__*/createContext({});
27
27
  const FaceControls = /*#__PURE__*/forwardRef(({
28
28
  camera,
@@ -43,14 +43,15 @@ const FaceControls = /*#__PURE__*/forwardRef(({
43
43
  makeDefault
44
44
  }, fref) => {
45
45
  var _faces$facialTransfor, _faces$faceBlendshape;
46
-
47
46
  const scene = useThree(state => state.scene);
48
47
  const defaultCamera = useThree(state => state.camera);
49
48
  const set = useThree(state => state.set);
50
49
  const get = useThree(state => state.get);
51
50
  const explCamera = camera || defaultCamera;
52
51
  const webcamApiRef = useRef(null);
53
- const facemeshApiRef = useRef(null); //
52
+ const facemeshApiRef = useRef(null);
53
+
54
+ //
54
55
  // computeTarget()
55
56
  //
56
57
  // Compute `target` position and rotation for the camera (according to <Facemesh>)
@@ -68,48 +69,49 @@ const FaceControls = /*#__PURE__*/forwardRef(({
68
69
  // same parent as the camera
69
70
  target.parent = explCamera.parent;
70
71
  const facemeshApi = facemeshApiRef.current;
71
-
72
72
  if (facemeshApi) {
73
73
  const {
74
74
  outerRef,
75
75
  eyeRightRef,
76
76
  eyeLeftRef
77
77
  } = facemeshApi;
78
-
79
78
  if (eyeRightRef.current && eyeLeftRef.current) {
80
79
  // 1. 👀
80
+
81
81
  const {
82
82
  irisDirRef: irisRightDirRef
83
83
  } = eyeRightRef.current;
84
84
  const {
85
85
  irisDirRef: irisLeftDirRef
86
86
  } = eyeLeftRef.current;
87
-
88
87
  if (irisRightDirRef.current && irisLeftDirRef.current && outerRef.current) {
89
88
  //
90
89
  // position: mean of irisRightDirPos,irisLeftDirPos
91
90
  //
92
91
  irisRightDirPos.copy(localToLocal(irisRightDirRef.current, new THREE.Vector3(0, 0, 0), outerRef.current));
93
92
  irisLeftDirPos.copy(localToLocal(irisLeftDirRef.current, new THREE.Vector3(0, 0, 0), outerRef.current));
94
- target.position.copy(localToLocal(outerRef.current, mean(irisRightDirPos, irisLeftDirPos), explCamera.parent || scene)); //
93
+ target.position.copy(localToLocal(outerRef.current, mean(irisRightDirPos, irisLeftDirPos), explCamera.parent || scene));
94
+
95
+ //
95
96
  // lookAt: mean of irisRightLookAt,irisLeftLookAt
96
97
  //
97
-
98
98
  irisRightLookAt.copy(localToLocal(irisRightDirRef.current, new THREE.Vector3(0, 0, 1), outerRef.current));
99
99
  irisLeftLookAt.copy(localToLocal(irisLeftDirRef.current, new THREE.Vector3(0, 0, 1), outerRef.current));
100
100
  target.lookAt(outerRef.current.localToWorld(mean(irisRightLookAt, irisLeftLookAt)));
101
101
  }
102
102
  } else {
103
103
  // 2. 👤
104
+
104
105
  if (outerRef.current) {
105
106
  target.position.copy(localToLocal(outerRef.current, new THREE.Vector3(0, 0, 0), explCamera.parent || scene));
106
107
  target.lookAt(outerRef.current.localToWorld(new THREE.Vector3(0, 0, 1)));
107
108
  }
108
109
  }
109
110
  }
110
-
111
111
  return target;
112
- }, [explCamera, irisLeftDirPos, irisLeftLookAt, irisRightDirPos, irisRightLookAt, scene, target]); //
112
+ }, [explCamera, irisLeftDirPos, irisLeftLookAt, irisRightDirPos, irisRightLookAt, scene, target]);
113
+
114
+ //
113
115
  // update()
114
116
  //
115
117
  // Updating the camera `current` position and rotation, following `target`
@@ -119,9 +121,7 @@ const FaceControls = /*#__PURE__*/forwardRef(({
119
121
  const update = useCallback(function (delta, target) {
120
122
  if (explCamera) {
121
123
  var _target;
122
-
123
124
  (_target = target) !== null && _target !== void 0 ? _target : target = computeTarget();
124
-
125
125
  if (smoothTime > 0) {
126
126
  // damping current
127
127
  const eps = 1e-9;
@@ -132,11 +132,12 @@ const FaceControls = /*#__PURE__*/forwardRef(({
132
132
  current.position.copy(target.position);
133
133
  current.rotation.copy(target.rotation);
134
134
  }
135
-
136
135
  explCamera.position.copy(current.position);
137
136
  explCamera.rotation.copy(current.rotation);
138
137
  }
139
- }, [explCamera, computeTarget, smoothTime, current.position, current.rotation]); //
138
+ }, [explCamera, computeTarget, smoothTime, current.position, current.rotation]);
139
+
140
+ //
140
141
  // detect()
141
142
  //
142
143
 
@@ -150,8 +151,9 @@ const FaceControls = /*#__PURE__*/forwardRef(({
150
151
  if (!manualUpdate) {
151
152
  update(delta);
152
153
  }
153
- }); // Ref API
154
+ });
154
155
 
156
+ // Ref API
155
157
  const api = useMemo(() => Object.assign(Object.create(THREE.EventDispatcher.prototype), {
156
158
  detect,
157
159
  computeTarget,
@@ -160,17 +162,17 @@ const FaceControls = /*#__PURE__*/forwardRef(({
160
162
  webcamApiRef,
161
163
  // shorthands
162
164
  play: () => {
163
- var _webcamApiRef$current, _webcamApiRef$current2;
164
-
165
- (_webcamApiRef$current = webcamApiRef.current) == null ? void 0 : (_webcamApiRef$current2 = _webcamApiRef$current.videoTextureApiRef.current) == null ? void 0 : _webcamApiRef$current2.texture.source.data.play();
165
+ var _webcamApiRef$current;
166
+ (_webcamApiRef$current = webcamApiRef.current) == null || (_webcamApiRef$current = _webcamApiRef$current.videoTextureApiRef.current) == null || _webcamApiRef$current.texture.source.data.play();
166
167
  },
167
168
  pause: () => {
168
- var _webcamApiRef$current3, _webcamApiRef$current4;
169
-
170
- (_webcamApiRef$current3 = webcamApiRef.current) == null ? void 0 : (_webcamApiRef$current4 = _webcamApiRef$current3.videoTextureApiRef.current) == null ? void 0 : _webcamApiRef$current4.texture.source.data.pause();
169
+ var _webcamApiRef$current2;
170
+ (_webcamApiRef$current2 = webcamApiRef.current) == null || (_webcamApiRef$current2 = _webcamApiRef$current2.videoTextureApiRef.current) == null || _webcamApiRef$current2.texture.source.data.pause();
171
171
  }
172
172
  }), [detect, computeTarget, update]);
173
- useImperativeHandle(fref, () => api, [api]); //
173
+ useImperativeHandle(fref, () => api, [api]);
174
+
175
+ //
174
176
  // events callbacks
175
177
  //
176
178
 
@@ -179,13 +181,13 @@ const FaceControls = /*#__PURE__*/forwardRef(({
179
181
  if (!manualDetect) detect(e.texture.source.data, e.time);
180
182
  if (onVideoFrame) onVideoFrame(e);
181
183
  };
182
-
183
184
  api.addEventListener('videoFrame', onVideoFrameCb);
184
185
  return () => {
185
186
  api.removeEventListener('videoFrame', onVideoFrameCb);
186
187
  };
187
- }, [api, detect, faceLandmarker, manualDetect, onVideoFrame]); // `controls` global state
188
+ }, [api, detect, faceLandmarker, manualDetect, onVideoFrame]);
188
189
 
190
+ // `controls` global state
189
191
  useEffect(() => {
190
192
  if (makeDefault) {
191
193
  const old = get().controls;
@@ -198,8 +200,8 @@ const FaceControls = /*#__PURE__*/forwardRef(({
198
200
  }
199
201
  }, [makeDefault, api, get, set]);
200
202
  const points = faces == null ? void 0 : faces.faceLandmarks[0];
201
- const facialTransformationMatrix = faces == null ? void 0 : (_faces$facialTransfor = faces.facialTransformationMatrixes) == null ? void 0 : _faces$facialTransfor[0];
202
- const faceBlendshapes = faces == null ? void 0 : (_faces$faceBlendshape = faces.faceBlendshapes) == null ? void 0 : _faces$faceBlendshape[0];
203
+ const facialTransformationMatrix = faces == null || (_faces$facialTransfor = faces.facialTransformationMatrixes) == null ? void 0 : _faces$facialTransfor[0];
204
+ const faceBlendshapes = faces == null || (_faces$faceBlendshape = faces.faceBlendshapes) == null ? void 0 : _faces$faceBlendshape[0];
203
205
  return /*#__PURE__*/React.createElement(FaceControlsContext.Provider, {
204
206
  value: api
205
207
  }, webcam && /*#__PURE__*/React.createElement(Suspense, {
@@ -226,10 +228,11 @@ const FaceControls = /*#__PURE__*/forwardRef(({
226
228
  side: THREE.DoubleSide
227
229
  })));
228
230
  });
229
- const useFaceControls = () => useContext(FaceControlsContext); //
231
+ const useFaceControls = () => useContext(FaceControlsContext);
232
+
233
+ //
230
234
  // Webcam
231
235
  //
232
-
233
236
  const Webcam = /*#__PURE__*/forwardRef(({
234
237
  videoTextureSrc,
235
238
  autostart = true
@@ -250,11 +253,12 @@ const Webcam = /*#__PURE__*/forwardRef(({
250
253
  stream
251
254
  });
252
255
  return () => {
253
- stream == null ? void 0 : stream.getTracks().forEach(track => track.stop());
256
+ stream == null || stream.getTracks().forEach(track => track.stop());
254
257
  clear([videoTextureSrc]);
255
258
  };
256
- }, [stream, faceControls, videoTextureSrc]); // ref-api
259
+ }, [stream, faceControls, videoTextureSrc]);
257
260
 
261
+ // ref-api
258
262
  const api = useMemo(() => ({
259
263
  videoTextureApiRef
260
264
  }), []);
@@ -266,10 +270,11 @@ const Webcam = /*#__PURE__*/forwardRef(({
266
270
  src: videoTextureSrc || stream,
267
271
  start: autostart
268
272
  }));
269
- }); //
273
+ });
274
+
275
+ //
270
276
  // VideoTexture
271
277
  //
272
-
273
278
  const VideoTexture = /*#__PURE__*/forwardRef(({
274
279
  src,
275
280
  start
@@ -286,27 +291,25 @@ const VideoTexture = /*#__PURE__*/forwardRef(({
286
291
  time
287
292
  });
288
293
  }, [texture, faceControls]);
289
- useVideoFrame(video, onVideoFrame); // ref-api
294
+ useVideoFrame(video, onVideoFrame);
290
295
 
296
+ // ref-api
291
297
  const api = useMemo(() => ({
292
298
  texture
293
299
  }), [texture]);
294
300
  useImperativeHandle(fref, () => api, [api]);
295
301
  return /*#__PURE__*/React.createElement(React.Fragment, null);
296
302
  });
297
-
298
303
  const useVideoFrame = (video, f) => {
299
304
  // https://web.dev/requestvideoframecallback-rvfc/
300
305
  // https://www.remotion.dev/docs/video-manipulation
301
306
  useEffect(() => {
302
307
  if (!video || !video.requestVideoFrameCallback) return;
303
308
  let handle;
304
-
305
309
  function callback(...args) {
306
310
  f(...args);
307
311
  handle = video.requestVideoFrameCallback(callback);
308
312
  }
309
-
310
313
  video.requestVideoFrameCallback(callback);
311
314
  return () => video.cancelVideoFrameCallback(handle);
312
315
  }, [video, f]);
@@ -1,6 +1,7 @@
1
+ import * as React from 'react';
1
2
  import { ReactNode } from 'react';
2
3
  import { FaceLandmarker as FaceLandmarkerImpl, FaceLandmarkerOptions } from '@mediapipe/tasks-vision';
3
- declare type FaceLandmarkerProps = {
4
+ type FaceLandmarkerProps = {
4
5
  basePath?: string;
5
6
  options?: FaceLandmarkerOptions;
6
7
  children?: ReactNode;
@@ -9,6 +10,6 @@ export declare const FaceLandmarkerDefaults: {
9
10
  basePath: string;
10
11
  options: FaceLandmarkerOptions;
11
12
  };
12
- export declare function FaceLandmarker({ basePath, options, children, }: FaceLandmarkerProps): JSX.Element;
13
+ export declare function FaceLandmarker({ basePath, options, children, }: FaceLandmarkerProps): React.JSX.Element;
13
14
  export declare function useFaceLandmarker(): FaceLandmarkerImpl | undefined;
14
15
  export {};
@@ -28,7 +28,7 @@ function FaceLandmarker({
28
28
  }, [basePath, opts]);
29
29
  useEffect(() => {
30
30
  return () => {
31
- faceLandmarker == null ? void 0 : faceLandmarker.close();
31
+ faceLandmarker == null || faceLandmarker.close();
32
32
  clear([basePath, opts]);
33
33
  };
34
34
  }, [faceLandmarker, basePath, opts]);
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import * as THREE from 'three';
3
- export declare type MediaPipeFaceMesh = typeof FacemeshDatas.SAMPLE_FACE;
4
- export declare type MediaPipePoints = typeof FacemeshDatas.SAMPLE_FACE.keypoints | typeof FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.faceLandmarks[0];
5
- export declare type FacemeshProps = {
3
+ export type MediaPipeFaceMesh = typeof FacemeshDatas.SAMPLE_FACE;
4
+ export type MediaPipePoints = typeof FacemeshDatas.SAMPLE_FACE.keypoints | typeof FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.faceLandmarks[0];
5
+ export type FacemeshProps = {
6
6
  points?: MediaPipePoints;
7
7
  face?: MediaPipeFaceMesh;
8
8
  width?: number;
@@ -18,7 +18,7 @@ export declare type FacemeshProps = {
18
18
  eyesAsOrigin?: boolean;
19
19
  debug?: boolean;
20
20
  } & Omit<JSX.IntrinsicElements['group'], 'ref'>;
21
- export declare type FacemeshApi = {
21
+ export type FacemeshApi = {
22
22
  meshRef: React.RefObject<THREE.Mesh>;
23
23
  outerRef: React.RefObject<THREE.Group>;
24
24
  eyeRightRef: React.RefObject<FacemeshEyeApi>;
@@ -73,11 +73,11 @@ export declare const Facemesh: React.ForwardRefExoticComponent<{
73
73
  eyesAsOrigin?: boolean | undefined;
74
74
  debug?: boolean | undefined;
75
75
  } & Omit<import("@react-three/fiber").GroupProps, "ref"> & React.RefAttributes<FacemeshApi>>;
76
- export declare type FacemeshEyeProps = {
76
+ export type FacemeshEyeProps = {
77
77
  side: 'left' | 'right';
78
78
  debug?: boolean;
79
79
  };
80
- export declare type FacemeshEyeApi = {
80
+ export type FacemeshEyeApi = {
81
81
  eyeMeshRef: React.RefObject<THREE.Group>;
82
82
  irisDirRef: React.RefObject<THREE.Group>;
83
83
  _computeSphere: (faceGeometry: THREE.BufferGeometry) => THREE.Sphere;
package/core/Facemesh.js CHANGED
@@ -5,7 +5,6 @@ import { Line } from './Line.js';
5
5
 
6
6
  /* eslint react-hooks/exhaustive-deps: 1 */
7
7
  const defaultLookAt = new THREE.Vector3(0, 0, -1);
8
-
9
8
  const normal = function () {
10
9
  const a = new THREE.Vector3();
11
10
  const b = new THREE.Vector3();
@@ -21,11 +20,9 @@ const normal = function () {
21
20
  return v.crossVectors(ac, ab).normalize();
22
21
  };
23
22
  }();
24
-
25
23
  function mean(v1, v2) {
26
24
  return v1.clone().add(v2).multiplyScalar(0.5);
27
25
  }
28
-
29
26
  const Facemesh = /*#__PURE__*/React.forwardRef(({
30
27
  points = FacemeshDatas.SAMPLE_FACELANDMARKER_RESULT.faceLandmarks[0],
31
28
  face,
@@ -45,12 +42,10 @@ const Facemesh = /*#__PURE__*/React.forwardRef(({
45
42
  ...props
46
43
  }, fref) => {
47
44
  var _meshRef$current3;
48
-
49
45
  if (face) {
50
46
  points = face.keypoints;
51
47
  console.warn('Facemesh `face` prop is deprecated: use `points` instead');
52
48
  }
53
-
54
49
  const offsetRef = React.useRef(null);
55
50
  const scaleRef = React.useRef(null);
56
51
  const originRef = React.useRef(null);
@@ -67,17 +62,17 @@ const Facemesh = /*#__PURE__*/React.forwardRef(({
67
62
  } = useThree();
68
63
  React.useEffect(() => {
69
64
  var _meshRef$current;
70
-
71
- (_meshRef$current = meshRef.current) == null ? void 0 : _meshRef$current.geometry.setIndex(FacemeshDatas.TRIANGULATION);
65
+ (_meshRef$current = meshRef.current) == null || _meshRef$current.geometry.setIndex(FacemeshDatas.TRIANGULATION);
72
66
  }, []);
73
67
  const [bboxSize] = React.useState(() => new THREE.Vector3());
74
68
  React.useEffect(() => {
75
69
  var _meshRef$current2, _outerRef$current;
76
-
77
70
  const faceGeometry = (_meshRef$current2 = meshRef.current) == null ? void 0 : _meshRef$current2.geometry;
78
71
  if (!faceGeometry) return;
79
72
  faceGeometry.setFromPoints(points);
80
- faceGeometry.setDrawRange(0, FacemeshDatas.TRIANGULATION.length); //
73
+ faceGeometry.setDrawRange(0, FacemeshDatas.TRIANGULATION.length);
74
+
75
+ //
81
76
  // A. compute sightDir vector
82
77
  //
83
78
  // - either from `facialTransformationMatrix` if available
@@ -87,42 +82,44 @@ const Facemesh = /*#__PURE__*/React.forwardRef(({
87
82
  if (facialTransformationMatrix) {
88
83
  // from facialTransformationMatrix
89
84
  transform.matrix.fromArray(facialTransformationMatrix.data);
90
- transform.matrix.decompose(transform.position, transform.quaternion, transform.scale); // Rotation: y and z axes are inverted
85
+ transform.matrix.decompose(transform.position, transform.quaternion, transform.scale);
91
86
 
87
+ // Rotation: y and z axes are inverted
92
88
  transform.rotation.y *= -1;
93
89
  transform.rotation.z *= -1;
94
- sightDirQuaternion.setFromEuler(transform.rotation); // Offset: y and z axes are inverted
90
+ sightDirQuaternion.setFromEuler(transform.rotation);
95
91
 
92
+ // Offset: y and z axes are inverted
96
93
  if (offset) {
97
94
  var _offsetRef$current;
98
-
99
95
  transform.position.y *= -1;
100
96
  transform.position.z *= -1;
101
- (_offsetRef$current = offsetRef.current) == null ? void 0 : _offsetRef$current.position.copy(transform.position.divideScalar(offsetScalar));
97
+ (_offsetRef$current = offsetRef.current) == null || _offsetRef$current.position.copy(transform.position.divideScalar(offsetScalar));
102
98
  } else {
103
99
  var _offsetRef$current2;
104
-
105
- (_offsetRef$current2 = offsetRef.current) == null ? void 0 : _offsetRef$current2.position.set(0, 0, 0); // reset
100
+ (_offsetRef$current2 = offsetRef.current) == null || _offsetRef$current2.position.set(0, 0, 0); // reset
106
101
  }
107
102
  } else {
108
103
  // normal to verticalTri
109
104
  normal(points[verticalTri[0]], points[verticalTri[1]], points[verticalTri[2]], sightDir);
110
105
  sightDirQuaternion.setFromUnitVectors(defaultLookAt, sightDir);
111
106
  }
107
+ const sightDirQuaternionInverse = sightDirQuaternion.clone().invert();
112
108
 
113
- const sightDirQuaternionInverse = sightDirQuaternion.clone().invert(); //
109
+ //
114
110
  // B. geometry (straightened)
115
111
  //
116
- // 1. center (before rotate back)
117
112
 
113
+ // 1. center (before rotate back)
118
114
  faceGeometry.computeBoundingBox();
119
115
  if (debug) invalidate(); // invalidate to force re-render for box3Helper (after .computeBoundingBox())
116
+ faceGeometry.center();
120
117
 
121
- faceGeometry.center(); // 2. rotate back + rotate outerRef (once 1.)
122
-
118
+ // 2. rotate back + rotate outerRef (once 1.)
123
119
  faceGeometry.applyQuaternion(sightDirQuaternionInverse);
124
- (_outerRef$current = outerRef.current) == null ? void 0 : _outerRef$current.setRotationFromQuaternion(sightDirQuaternion); // 3. 👀 eyes
120
+ (_outerRef$current = outerRef.current) == null || _outerRef$current.setRotationFromQuaternion(sightDirQuaternion);
125
121
 
122
+ // 3. 👀 eyes
126
123
  if (eyes) {
127
124
  if (!faceBlendshapes) {
128
125
  console.warn('Facemesh `eyes` option only works if `faceBlendshapes` is provided: skipping.');
@@ -131,30 +128,25 @@ const Facemesh = /*#__PURE__*/React.forwardRef(({
131
128
  if (eyesAsOrigin) {
132
129
  // compute the middle of the 2 eyes as the `origin`
133
130
  const eyeRightSphere = eyeRightRef.current._computeSphere(faceGeometry);
134
-
135
131
  const eyeLeftSphere = eyeLeftRef.current._computeSphere(faceGeometry);
136
-
137
132
  const eyesCenter = mean(eyeRightSphere.center, eyeLeftSphere.center);
138
133
  origin = eyesCenter.negate(); // eslint-disable-line react-hooks/exhaustive-deps
139
134
 
140
135
  eyeRightRef.current._update(faceGeometry, faceBlendshapes, eyeRightSphere);
141
-
142
136
  eyeLeftRef.current._update(faceGeometry, faceBlendshapes, eyeLeftSphere);
143
137
  } else {
144
138
  eyeRightRef.current._update(faceGeometry, faceBlendshapes);
145
-
146
139
  eyeLeftRef.current._update(faceGeometry, faceBlendshapes);
147
140
  }
148
141
  }
149
142
  }
150
- } // 3. origin
151
-
143
+ }
152
144
 
145
+ // 3. origin
153
146
  if (originRef.current) {
154
147
  if (origin !== undefined) {
155
148
  if (typeof origin === 'number') {
156
149
  const position = faceGeometry.getAttribute('position');
157
-
158
150
  _origin.set(-position.getX(origin), -position.getY(origin), -position.getZ(origin));
159
151
  } else if (origin.isVector3) {
160
152
  _origin.copy(origin);
@@ -162,29 +154,26 @@ const Facemesh = /*#__PURE__*/React.forwardRef(({
162
154
  } else {
163
155
  _origin.setScalar(0);
164
156
  }
165
-
166
157
  originRef.current.position.copy(_origin);
167
- } // 4. re-scale
168
-
158
+ }
169
159
 
160
+ // 4. re-scale
170
161
  if (scaleRef.current) {
171
162
  let scale = 1;
172
-
173
163
  if (width || height || depth) {
174
164
  faceGeometry.boundingBox.getSize(bboxSize);
175
165
  if (width) scale = width / bboxSize.x; // fit in width
176
-
177
166
  if (height) scale = height / bboxSize.y; // fit in height
178
-
179
167
  if (depth) scale = depth / bboxSize.z; // fit in depth
180
168
  }
181
169
 
182
170
  scaleRef.current.scale.setScalar(scale !== 1 ? scale : 1);
183
171
  }
184
-
185
172
  faceGeometry.computeVertexNormals();
186
173
  faceGeometry.attributes.position.needsUpdate = true;
187
- }, [points, facialTransformationMatrix, faceBlendshapes, transform, offset, offsetScalar, width, height, depth, verticalTri, origin, eyes, debug, invalidate, sightDir, sightDirQuaternion, bboxSize, _origin]); //
174
+ }, [points, facialTransformationMatrix, faceBlendshapes, transform, offset, offsetScalar, width, height, depth, verticalTri, origin, eyes, debug, invalidate, sightDir, sightDirQuaternion, bboxSize, _origin]);
175
+
176
+ //
188
177
  // API
189
178
  //
190
179
 
@@ -227,10 +216,11 @@ const Facemesh = /*#__PURE__*/React.forwardRef(({
227
216
  }, children, debug ? /*#__PURE__*/React.createElement(React.Fragment, null, bbox && /*#__PURE__*/React.createElement("box3Helper", {
228
217
  args: [bbox]
229
218
  })) : null))))));
230
- }); //
219
+ });
220
+
221
+ //
231
222
  // 👁️ FacemeshEye
232
223
  //
233
-
234
224
  const FacemeshEyeDefaults = {
235
225
  contourLandmarks: {
236
226
  right: [33, 133, 159, 145, 153],
@@ -240,8 +230,8 @@ const FacemeshEyeDefaults = {
240
230
  right: [14, 16, 18, 12],
241
231
  // lookIn,lookOut, lookUp,lookDown
242
232
  left: [13, 15, 17, 11] // lookIn,lookOut, lookUp,lookDown
243
-
244
233
  },
234
+
245
235
  color: {
246
236
  right: 'red',
247
237
  left: '#00ff00'
@@ -256,28 +246,33 @@ const FacemeshEye = /*#__PURE__*/React.forwardRef(({
256
246
  debug = true
257
247
  }, fref) => {
258
248
  const eyeMeshRef = React.useRef(null);
259
- const irisDirRef = React.useRef(null); //
249
+ const irisDirRef = React.useRef(null);
250
+
251
+ //
260
252
  // _computeSphere()
261
253
  //
262
254
  // Compute eye's sphere .position and .radius
263
255
  //
264
256
 
265
257
  const [sphere] = React.useState(() => new THREE.Sphere());
266
-
267
258
  const _computeSphere = React.useCallback(faceGeometry => {
268
- const position = faceGeometry.getAttribute('position'); // get some eye contour landmarks points (from geometry)
259
+ const position = faceGeometry.getAttribute('position');
269
260
 
261
+ // get some eye contour landmarks points (from geometry)
270
262
  const eyeContourLandmarks = FacemeshEyeDefaults.contourLandmarks[side];
271
263
  const eyeContourPoints = eyeContourLandmarks.map(i => new THREE.Vector3(position.getX(i), position.getY(i), position.getZ(i))); // prettier-ignore
272
- // compute center (centroid from eyeContourPoints)
273
264
 
265
+ // compute center (centroid from eyeContourPoints)
274
266
  sphere.center.set(0, 0, 0);
275
267
  eyeContourPoints.forEach(v => sphere.center.add(v));
276
- sphere.center.divideScalar(eyeContourPoints.length); // radius (eye half-width)
268
+ sphere.center.divideScalar(eyeContourPoints.length);
277
269
 
270
+ // radius (eye half-width)
278
271
  sphere.radius = eyeContourPoints[0].sub(eyeContourPoints[1]).length() / 2;
279
272
  return sphere;
280
- }, [sphere, side]); //
273
+ }, [sphere, side]);
274
+
275
+ //
281
276
  // _update()
282
277
  //
283
278
  // Update:
@@ -285,21 +280,17 @@ const FacemeshEye = /*#__PURE__*/React.forwardRef(({
285
280
  // - B. iris direction (according to "look*" blendshapes)
286
281
  //
287
282
 
288
-
289
283
  const [rotation] = React.useState(() => new THREE.Euler());
290
-
291
284
  const _update = React.useCallback((faceGeometry, faceBlendshapes, sphere) => {
292
285
  // A.
293
286
  if (eyeMeshRef.current) {
294
287
  var _sphere;
295
-
296
288
  (_sphere = sphere) !== null && _sphere !== void 0 ? _sphere : sphere = _computeSphere(faceGeometry); // compute sphere dims (if not passed)
297
-
298
289
  eyeMeshRef.current.position.copy(sphere.center);
299
290
  eyeMeshRef.current.scale.setScalar(sphere.radius);
300
- } // B.
301
-
291
+ }
302
292
 
293
+ // B.
303
294
  if (faceBlendshapes && irisDirRef.current) {
304
295
  const blendshapes = FacemeshEyeDefaults.blendshapes[side];
305
296
  const lookIn = faceBlendshapes.categories[blendshapes[0]].score;
@@ -313,11 +304,12 @@ const FacemeshEye = /*#__PURE__*/React.forwardRef(({
313
304
  rotation.set(rx, ry, 0);
314
305
  irisDirRef.current.setRotationFromEuler(rotation);
315
306
  }
316
- }, [_computeSphere, side, rotation]); //
307
+ }, [_computeSphere, side, rotation]);
308
+
309
+ //
317
310
  // API
318
311
  //
319
312
 
320
-
321
313
  const api = React.useMemo(() => ({
322
314
  eyeMeshRef: eyeMeshRef,
323
315
  irisDirRef: irisDirRef,
@@ -335,7 +327,9 @@ const FacemeshEye = /*#__PURE__*/React.forwardRef(({
335
327
  lineWidth: 1,
336
328
  color: color
337
329
  })))));
338
- }); //
330
+ });
331
+
332
+ //
339
333
  // Sample datas
340
334
  //
341
335
 
@@ -1,7 +1,7 @@
1
1
  import { Object3DNode } from '@react-three/fiber';
2
2
  import { FirstPersonControls as FirstPersonControlImpl } from 'three-stdlib';
3
3
  import { ForwardRefComponent } from '../helpers/ts-utils';
4
- export declare type FirstPersonControlsProps = Object3DNode<FirstPersonControlImpl, typeof FirstPersonControlImpl> & {
4
+ export type FirstPersonControlsProps = Object3DNode<FirstPersonControlImpl, typeof FirstPersonControlImpl> & {
5
5
  domElement?: HTMLElement;
6
6
  makeDefault?: boolean;
7
7
  };
package/core/Float.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import * as THREE from 'three';
3
3
  import { ForwardRefComponent } from '../helpers/ts-utils';
4
- export declare type FloatProps = JSX.IntrinsicElements['group'] & {
4
+ export type FloatProps = JSX.IntrinsicElements['group'] & {
5
5
  enabled?: boolean;
6
6
  speed?: number;
7
7
  rotationIntensity?: number;
package/core/Float.js CHANGED
@@ -16,7 +16,6 @@ const Float = /*#__PURE__*/React.forwardRef(({
16
16
  const offset = React.useRef(Math.random() * 10000);
17
17
  useFrame(state => {
18
18
  var _floatingRange$, _floatingRange$2;
19
-
20
19
  if (!enabled || speed === 0) return;
21
20
  const t = offset.current + state.clock.getElapsedTime();
22
21
  ref.current.rotation.x = Math.cos(t / 4 * speed) / 8 * rotationIntensity;
@@ -2,7 +2,7 @@ import { ReactThreeFiber } from '@react-three/fiber';
2
2
  import * as THREE from 'three';
3
3
  import { FlyControls as FlyControlsImpl } from 'three-stdlib';
4
4
  import { ForwardRefComponent } from '../helpers/ts-utils';
5
- export declare type FlyControlsProps = ReactThreeFiber.Object3DNode<FlyControlsImpl, typeof FlyControlsImpl> & {
5
+ export type FlyControlsProps = ReactThreeFiber.Object3DNode<FlyControlsImpl, typeof FlyControlsImpl> & {
6
6
  onChange?: (e?: THREE.Event) => void;
7
7
  domElement?: HTMLElement;
8
8
  makeDefault?: boolean;
@@ -29,8 +29,7 @@ const FlyControls = /*#__PURE__*/React.forwardRef(({
29
29
  invalidate();
30
30
  if (onChange) onChange(e);
31
31
  };
32
-
33
- controls.addEventListener == null ? void 0 : controls.addEventListener('change', callback);
32
+ controls.addEventListener == null || controls.addEventListener('change', callback);
34
33
  return () => controls.removeEventListener == null ? void 0 : controls.removeEventListener('change', callback);
35
34
  }, [onChange, invalidate]);
36
35
  React.useEffect(() => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-three/fiber"),t=require("three"),n=require("./OrthographicCamera.cjs.js"),u=require("./Hud.cjs.js");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("@babel/runtime/helpers/extends"),require("react-merge-refs"),require("./useFBO.cjs.js");var i=o(e);const a=i.createContext({}),c=2*Math.PI,s=new t.Object3D,l=new t.Matrix4,[p,d]=[new t.Quaternion,new t.Quaternion],f=new t.Vector3,h=new t.Vector3;exports.GizmoHelper=({alignment:e="bottom-right",margin:o=[80,80],renderPriority:m=1,onUpdate:y,onTarget:g,children:b})=>{const j=r.useThree((e=>e.size)),w=r.useThree((e=>e.camera)),q=r.useThree((e=>e.controls)),v=r.useThree((e=>e.invalidate)),O=i.useRef(),x=i.useRef(null),P=i.useRef(!1),T=i.useRef(0),C=i.useRef(new t.Vector3(0,0,0)),R=i.useRef(new t.Vector3(0,0,0));i.useEffect((()=>{R.current.copy(w.up)}),[w]);const E=i.useCallback((e=>{P.current=!0,(q||g)&&(C.current=(null==q?void 0:q.target)||(null==g?void 0:g())),T.current=w.position.distanceTo(f),p.copy(w.quaternion),h.copy(e).multiplyScalar(T.current).add(f),s.lookAt(h),s.up.copy(w.up),d.copy(s.quaternion),v()}),[q,w,g,v]);r.useFrame(((e,r)=>{if(x.current&&O.current){var t;if(P.current)if(p.angleTo(d)<.01)P.current=!1,"minPolarAngle"in q&&w.up.copy(R.current);else{const e=r*c;p.rotateTowards(d,e),w.position.set(0,0,1).applyQuaternion(p).multiplyScalar(T.current).add(C.current),w.up.set(0,1,0).applyQuaternion(p).normalize(),w.quaternion.copy(p),y?y():q&&q.update(),v()}l.copy(w.matrix).invert(),null==(t=O.current)||t.quaternion.setFromRotationMatrix(l)}}));const M=i.useMemo((()=>({tweenCamera:E})),[E]),[z,k]=o,Q=e.endsWith("-center")?0:e.endsWith("-left")?-j.width/2+z:j.width/2-z,V=e.startsWith("center-")?0:e.startsWith("top-")?j.height/2-k:-j.height/2+k;return i.createElement(u.Hud,{renderPriority:m},i.createElement(a.Provider,{value:M},i.createElement(n.OrthographicCamera,{makeDefault:!0,ref:x,position:[0,0,200]}),i.createElement("group",{ref:O,position:[Q,V,0]},b)))},exports.useGizmoContext=()=>i.useContext(a);
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@react-three/fiber"),t=require("three"),n=require("./OrthographicCamera.cjs.js"),u=require("./Hud.cjs.js");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}require("@babel/runtime/helpers/extends"),require("react-merge-refs"),require("./useFBO.cjs.js");var i=o(e);const a=i.createContext({}),c=2*Math.PI,s=new t.Object3D,l=new t.Matrix4,[p,d]=[new t.Quaternion,new t.Quaternion],f=new t.Vector3,h=new t.Vector3;exports.GizmoHelper=({alignment:e="bottom-right",margin:o=[80,80],renderPriority:m=1,onUpdate:y,onTarget:g,children:b})=>{const j=r.useThree((e=>e.size)),w=r.useThree((e=>e.camera)),q=r.useThree((e=>e.controls)),v=r.useThree((e=>e.invalidate)),O=i.useRef(null),x=i.useRef(null),P=i.useRef(!1),T=i.useRef(0),C=i.useRef(new t.Vector3(0,0,0)),R=i.useRef(new t.Vector3(0,0,0));i.useEffect((()=>{R.current.copy(w.up)}),[w]);const E=i.useCallback((e=>{P.current=!0,(q||g)&&(C.current=(null==q?void 0:q.target)||(null==g?void 0:g())),T.current=w.position.distanceTo(f),p.copy(w.quaternion),h.copy(e).multiplyScalar(T.current).add(f),s.lookAt(h),s.up.copy(w.up),d.copy(s.quaternion),v()}),[q,w,g,v]);r.useFrame(((e,r)=>{if(x.current&&O.current){var t;if(P.current)if(p.angleTo(d)<.01)P.current=!1,"minPolarAngle"in q&&w.up.copy(R.current);else{const e=r*c;p.rotateTowards(d,e),w.position.set(0,0,1).applyQuaternion(p).multiplyScalar(T.current).add(C.current),w.up.set(0,1,0).applyQuaternion(p).normalize(),w.quaternion.copy(p),y?y():q&&q.update(),v()}l.copy(w.matrix).invert(),null==(t=O.current)||t.quaternion.setFromRotationMatrix(l)}}));const M=i.useMemo((()=>({tweenCamera:E})),[E]),[z,k]=o,Q=e.endsWith("-center")?0:e.endsWith("-left")?-j.width/2+z:j.width/2-z,V=e.startsWith("center-")?0:e.startsWith("top-")?j.height/2-k:-j.height/2+k;return i.createElement(u.Hud,{renderPriority:m},i.createElement(a.Provider,{value:M},i.createElement(n.OrthographicCamera,{makeDefault:!0,ref:x,position:[0,0,200]}),i.createElement("group",{ref:O,position:[Q,V,0]},b)))},exports.useGizmoContext=()=>i.useContext(a);