@needle-tools/engine 4.11.5-next.d9019e4 → 4.11.5-next.dedc70b

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 (367) hide show
  1. package/components.needle.json +1 -1
  2. package/custom-elements.json +436 -0
  3. package/dist/{needle-engine.bundle-GILPT50v.min.js → needle-engine.bundle-CJlEyOBM.min.js} +4 -4
  4. package/dist/{needle-engine.bundle-DbRanrPL.umd.cjs → needle-engine.bundle-DgiVW9bH.umd.cjs} +6 -6
  5. package/dist/{needle-engine.bundle-D4DKOVeW.js → needle-engine.bundle-F4gDjlNg.js} +60 -14
  6. package/dist/needle-engine.d.ts +18154 -1
  7. package/dist/needle-engine.js +2 -2
  8. package/dist/needle-engine.min.js +1 -1
  9. package/dist/needle-engine.umd.cjs +1 -1
  10. package/lib/engine/api.d.ts +0 -1
  11. package/lib/engine/api.js +0 -1
  12. package/lib/engine/api.js.map +1 -1
  13. package/lib/engine/engine_texture.d.ts +1 -1
  14. package/lib/engine/engine_tonemapping.d.ts +1 -1
  15. package/lib/engine/webcomponents/logo-element.d.ts +11 -0
  16. package/lib/engine/webcomponents/logo-element.js +6 -0
  17. package/lib/engine/webcomponents/logo-element.js.map +1 -1
  18. package/lib/engine/webcomponents/needle menu/needle-menu.d.ts +24 -3
  19. package/lib/engine/webcomponents/needle menu/needle-menu.js +18 -3
  20. package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
  21. package/lib/engine/webcomponents/needle-button.d.ts +5 -0
  22. package/lib/engine/webcomponents/needle-button.js.map +1 -1
  23. package/lib/engine/webcomponents/needle-engine.d.ts +209 -8
  24. package/lib/engine/webcomponents/needle-engine.js +91 -13
  25. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  26. package/lib/engine-components/AlignmentConstraint.d.ts +9 -0
  27. package/lib/engine-components/AlignmentConstraint.js +9 -0
  28. package/lib/engine-components/AlignmentConstraint.js.map +1 -1
  29. package/lib/engine-components/Animator.d.ts +1 -0
  30. package/lib/engine-components/Animator.js.map +1 -1
  31. package/lib/engine-components/AudioListener.d.ts +2 -0
  32. package/lib/engine-components/AudioListener.js +2 -0
  33. package/lib/engine-components/AudioListener.js.map +1 -1
  34. package/lib/engine-components/AudioSource.d.ts +1 -0
  35. package/lib/engine-components/AudioSource.js +1 -0
  36. package/lib/engine-components/AudioSource.js.map +1 -1
  37. package/lib/engine-components/AxesHelper.d.ts +2 -0
  38. package/lib/engine-components/AxesHelper.js +2 -0
  39. package/lib/engine-components/AxesHelper.js.map +1 -1
  40. package/lib/engine-components/Camera.d.ts +1 -0
  41. package/lib/engine-components/Camera.js +1 -0
  42. package/lib/engine-components/Camera.js.map +1 -1
  43. package/lib/engine-components/CharacterController.d.ts +4 -1
  44. package/lib/engine-components/CharacterController.js +4 -1
  45. package/lib/engine-components/CharacterController.js.map +1 -1
  46. package/lib/engine-components/DeleteBox.d.ts +2 -0
  47. package/lib/engine-components/DeleteBox.js +2 -0
  48. package/lib/engine-components/DeleteBox.js.map +1 -1
  49. package/lib/engine-components/DeviceFlag.d.ts +4 -0
  50. package/lib/engine-components/DeviceFlag.js +4 -0
  51. package/lib/engine-components/DeviceFlag.js.map +1 -1
  52. package/lib/engine-components/DragControls.d.ts +1 -0
  53. package/lib/engine-components/DragControls.js +1 -0
  54. package/lib/engine-components/DragControls.js.map +1 -1
  55. package/lib/engine-components/DropListener.d.ts +1 -0
  56. package/lib/engine-components/DropListener.js +1 -0
  57. package/lib/engine-components/DropListener.js.map +1 -1
  58. package/lib/engine-components/Duplicatable.d.ts +1 -0
  59. package/lib/engine-components/Duplicatable.js +1 -0
  60. package/lib/engine-components/Duplicatable.js.map +1 -1
  61. package/lib/engine-components/EventTrigger.d.ts +2 -0
  62. package/lib/engine-components/EventTrigger.js +2 -0
  63. package/lib/engine-components/EventTrigger.js.map +1 -1
  64. package/lib/engine-components/GridHelper.d.ts +2 -0
  65. package/lib/engine-components/GridHelper.js +2 -0
  66. package/lib/engine-components/GridHelper.js.map +1 -1
  67. package/lib/engine-components/GroundProjection.d.ts +1 -0
  68. package/lib/engine-components/GroundProjection.js +1 -0
  69. package/lib/engine-components/GroundProjection.js.map +1 -1
  70. package/lib/engine-components/LODGroup.d.ts +2 -0
  71. package/lib/engine-components/LODGroup.js +2 -0
  72. package/lib/engine-components/LODGroup.js.map +1 -1
  73. package/lib/engine-components/Light.d.ts +1 -0
  74. package/lib/engine-components/Light.js +1 -0
  75. package/lib/engine-components/Light.js.map +1 -1
  76. package/lib/engine-components/LookAtConstraint.d.ts +1 -0
  77. package/lib/engine-components/LookAtConstraint.js +1 -0
  78. package/lib/engine-components/LookAtConstraint.js.map +1 -1
  79. package/lib/engine-components/NeedleMenu.d.ts +1 -0
  80. package/lib/engine-components/NeedleMenu.js +1 -0
  81. package/lib/engine-components/NeedleMenu.js.map +1 -1
  82. package/lib/engine-components/NestedGltf.d.ts +1 -0
  83. package/lib/engine-components/NestedGltf.js +1 -0
  84. package/lib/engine-components/NestedGltf.js.map +1 -1
  85. package/lib/engine-components/Networking.d.ts +1 -0
  86. package/lib/engine-components/Networking.js +1 -0
  87. package/lib/engine-components/Networking.js.map +1 -1
  88. package/lib/engine-components/OffsetConstraint.d.ts +7 -0
  89. package/lib/engine-components/OffsetConstraint.js +7 -0
  90. package/lib/engine-components/OffsetConstraint.js.map +1 -1
  91. package/lib/engine-components/OrbitControls.d.ts +1 -0
  92. package/lib/engine-components/OrbitControls.js +1 -0
  93. package/lib/engine-components/OrbitControls.js.map +1 -1
  94. package/lib/engine-components/PlayerColor.d.ts +2 -0
  95. package/lib/engine-components/PlayerColor.js +2 -0
  96. package/lib/engine-components/PlayerColor.js.map +1 -1
  97. package/lib/engine-components/ReflectionProbe.d.ts +1 -0
  98. package/lib/engine-components/ReflectionProbe.js +1 -0
  99. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  100. package/lib/engine-components/RigidBody.d.ts +1 -0
  101. package/lib/engine-components/RigidBody.js +1 -0
  102. package/lib/engine-components/RigidBody.js.map +1 -1
  103. package/lib/engine-components/SceneSwitcher.d.ts +1 -0
  104. package/lib/engine-components/SceneSwitcher.js +1 -0
  105. package/lib/engine-components/SceneSwitcher.js.map +1 -1
  106. package/lib/engine-components/ScreenCapture.d.ts +1 -0
  107. package/lib/engine-components/ScreenCapture.js +1 -0
  108. package/lib/engine-components/ScreenCapture.js.map +1 -1
  109. package/lib/engine-components/SeeThrough.d.ts +1 -0
  110. package/lib/engine-components/SeeThrough.js +1 -0
  111. package/lib/engine-components/SeeThrough.js.map +1 -1
  112. package/lib/engine-components/ShadowCatcher.d.ts +2 -0
  113. package/lib/engine-components/ShadowCatcher.js +2 -0
  114. package/lib/engine-components/ShadowCatcher.js.map +1 -1
  115. package/lib/engine-components/Skybox.d.ts +1 -0
  116. package/lib/engine-components/Skybox.js +1 -0
  117. package/lib/engine-components/Skybox.js.map +1 -1
  118. package/lib/engine-components/SmoothFollow.d.ts +1 -0
  119. package/lib/engine-components/SmoothFollow.js +1 -0
  120. package/lib/engine-components/SmoothFollow.js.map +1 -1
  121. package/lib/engine-components/SpatialTrigger.d.ts +1 -0
  122. package/lib/engine-components/SpatialTrigger.js +1 -0
  123. package/lib/engine-components/SpatialTrigger.js.map +1 -1
  124. package/lib/engine-components/SpectatorCamera.d.ts +1 -0
  125. package/lib/engine-components/SpectatorCamera.js +1 -0
  126. package/lib/engine-components/SpectatorCamera.js.map +1 -1
  127. package/lib/engine-components/SpriteRenderer.d.ts +1 -0
  128. package/lib/engine-components/SpriteRenderer.js +1 -0
  129. package/lib/engine-components/SpriteRenderer.js.map +1 -1
  130. package/lib/engine-components/SyncedCamera.d.ts +2 -0
  131. package/lib/engine-components/SyncedCamera.js +2 -0
  132. package/lib/engine-components/SyncedCamera.js.map +1 -1
  133. package/lib/engine-components/SyncedRoom.d.ts +1 -0
  134. package/lib/engine-components/SyncedRoom.js +1 -0
  135. package/lib/engine-components/SyncedRoom.js.map +1 -1
  136. package/lib/engine-components/SyncedTransform.d.ts +2 -0
  137. package/lib/engine-components/SyncedTransform.js +2 -0
  138. package/lib/engine-components/SyncedTransform.js.map +1 -1
  139. package/lib/engine-components/TransformGizmo.d.ts +2 -0
  140. package/lib/engine-components/TransformGizmo.js +2 -0
  141. package/lib/engine-components/TransformGizmo.js.map +1 -1
  142. package/lib/engine-components/VideoPlayer.d.ts +1 -0
  143. package/lib/engine-components/VideoPlayer.js +1 -0
  144. package/lib/engine-components/VideoPlayer.js.map +1 -1
  145. package/lib/engine-components/Voip.d.ts +1 -0
  146. package/lib/engine-components/Voip.js +1 -0
  147. package/lib/engine-components/Voip.js.map +1 -1
  148. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.d.ts +18 -0
  149. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js +18 -0
  150. package/lib/engine-components/export/usdz/extensions/behavior/BehaviourComponents.js.map +1 -1
  151. package/lib/engine-components/particlesystem/ParticleSystem.d.ts +1 -0
  152. package/lib/engine-components/particlesystem/ParticleSystem.js +1 -0
  153. package/lib/engine-components/particlesystem/ParticleSystem.js.map +1 -1
  154. package/lib/engine-components/physics/Attractor.d.ts +3 -0
  155. package/lib/engine-components/physics/Attractor.js +3 -0
  156. package/lib/engine-components/physics/Attractor.js.map +1 -1
  157. package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +1 -0
  158. package/lib/engine-components/postprocessing/Effects/BloomEffect.js +1 -0
  159. package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
  160. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.d.ts +4 -0
  161. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js +4 -0
  162. package/lib/engine-components/postprocessing/Effects/ChromaticAberration.js.map +1 -1
  163. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +3 -0
  164. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +3 -0
  165. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
  166. package/lib/engine-components/postprocessing/Effects/DepthOfField.d.ts +4 -0
  167. package/lib/engine-components/postprocessing/Effects/DepthOfField.js +4 -0
  168. package/lib/engine-components/postprocessing/Effects/DepthOfField.js.map +1 -1
  169. package/lib/engine-components/postprocessing/Effects/EffectWrapper.d.ts +1 -0
  170. package/lib/engine-components/postprocessing/Effects/EffectWrapper.js +1 -0
  171. package/lib/engine-components/postprocessing/Effects/EffectWrapper.js.map +1 -1
  172. package/lib/engine-components/postprocessing/Effects/Pixelation.d.ts +3 -0
  173. package/lib/engine-components/postprocessing/Effects/Pixelation.js +3 -0
  174. package/lib/engine-components/postprocessing/Effects/Pixelation.js.map +1 -1
  175. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.d.ts +4 -0
  176. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +4 -0
  177. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
  178. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +4 -0
  179. package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
  180. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  181. package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.d.ts +4 -0
  182. package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.js +4 -0
  183. package/lib/engine-components/postprocessing/Effects/TiltShiftEffect.js.map +1 -1
  184. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +4 -0
  185. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +4 -0
  186. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  187. package/lib/engine-components/postprocessing/Effects/Vignette.d.ts +4 -0
  188. package/lib/engine-components/postprocessing/Effects/Vignette.js +4 -0
  189. package/lib/engine-components/postprocessing/Effects/Vignette.js.map +1 -1
  190. package/lib/engine-components/postprocessing/Volume.d.ts +1 -0
  191. package/lib/engine-components/postprocessing/Volume.js +1 -0
  192. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  193. package/lib/engine-components/splines/Spline.d.ts +1 -0
  194. package/lib/engine-components/splines/Spline.js +1 -0
  195. package/lib/engine-components/splines/Spline.js.map +1 -1
  196. package/lib/engine-components/splines/SplineWalker.d.ts +1 -0
  197. package/lib/engine-components/splines/SplineWalker.js +1 -0
  198. package/lib/engine-components/splines/SplineWalker.js.map +1 -1
  199. package/lib/engine-components/timeline/PlayableDirector.d.ts +1 -0
  200. package/lib/engine-components/timeline/PlayableDirector.js +1 -0
  201. package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
  202. package/lib/engine-components/timeline/SignalAsset.d.ts +1 -0
  203. package/lib/engine-components/timeline/SignalAsset.js +1 -0
  204. package/lib/engine-components/timeline/SignalAsset.js.map +1 -1
  205. package/lib/engine-components/ui/Button.d.ts +4 -0
  206. package/lib/engine-components/ui/Button.js +4 -0
  207. package/lib/engine-components/ui/Button.js.map +1 -1
  208. package/lib/engine-components/ui/Canvas.d.ts +5 -0
  209. package/lib/engine-components/ui/Canvas.js +5 -0
  210. package/lib/engine-components/ui/Canvas.js.map +1 -1
  211. package/lib/engine-components/ui/CanvasGroup.d.ts +4 -0
  212. package/lib/engine-components/ui/CanvasGroup.js +4 -0
  213. package/lib/engine-components/ui/CanvasGroup.js.map +1 -1
  214. package/lib/engine-components/ui/EventSystem.d.ts +2 -0
  215. package/lib/engine-components/ui/EventSystem.js +2 -0
  216. package/lib/engine-components/ui/EventSystem.js.map +1 -1
  217. package/lib/engine-components/ui/Image.d.ts +4 -0
  218. package/lib/engine-components/ui/Image.js +4 -0
  219. package/lib/engine-components/ui/Image.js.map +1 -1
  220. package/lib/engine-components/ui/InputField.d.ts +4 -0
  221. package/lib/engine-components/ui/InputField.js +4 -0
  222. package/lib/engine-components/ui/InputField.js.map +1 -1
  223. package/lib/engine-components/ui/Outline.d.ts +7 -0
  224. package/lib/engine-components/ui/Outline.js +7 -0
  225. package/lib/engine-components/ui/Outline.js.map +1 -1
  226. package/lib/engine-components/ui/Text.d.ts +1 -0
  227. package/lib/engine-components/ui/Text.js +1 -0
  228. package/lib/engine-components/ui/Text.js.map +1 -1
  229. package/lib/engine-components/utils/LookAt.d.ts +1 -0
  230. package/lib/engine-components/utils/LookAt.js +1 -0
  231. package/lib/engine-components/utils/LookAt.js.map +1 -1
  232. package/lib/engine-components/web/Clickthrough.d.ts +1 -1
  233. package/lib/engine-components/web/Clickthrough.js +1 -1
  234. package/lib/engine-components/web/CursorFollow.d.ts +1 -0
  235. package/lib/engine-components/web/CursorFollow.js +1 -0
  236. package/lib/engine-components/web/CursorFollow.js.map +1 -1
  237. package/lib/engine-components/web/HoverAnimation.d.ts +1 -0
  238. package/lib/engine-components/web/HoverAnimation.js +1 -0
  239. package/lib/engine-components/web/HoverAnimation.js.map +1 -1
  240. package/lib/engine-components/web/ScrollFollow.d.ts +2 -0
  241. package/lib/engine-components/web/ScrollFollow.js +2 -0
  242. package/lib/engine-components/web/ScrollFollow.js.map +1 -1
  243. package/lib/engine-components/web/ViewBox.d.ts +1 -0
  244. package/lib/engine-components/web/ViewBox.js +1 -0
  245. package/lib/engine-components/web/ViewBox.js.map +1 -1
  246. package/lib/engine-components/webxr/Avatar.d.ts +5 -0
  247. package/lib/engine-components/webxr/Avatar.js +5 -0
  248. package/lib/engine-components/webxr/Avatar.js.map +1 -1
  249. package/lib/engine-components/webxr/WebARCameraBackground.d.ts +1 -0
  250. package/lib/engine-components/webxr/WebARCameraBackground.js +1 -0
  251. package/lib/engine-components/webxr/WebARCameraBackground.js.map +1 -1
  252. package/lib/engine-components/webxr/WebARSessionRoot.d.ts +1 -0
  253. package/lib/engine-components/webxr/WebARSessionRoot.js +1 -0
  254. package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
  255. package/lib/engine-components/webxr/WebXR.d.ts +1 -1
  256. package/lib/engine-components/webxr/WebXR.js +1 -1
  257. package/lib/engine-components/webxr/controllers/XRControllerFollow.d.ts +1 -0
  258. package/lib/engine-components/webxr/controllers/XRControllerFollow.js +1 -0
  259. package/lib/engine-components/webxr/controllers/XRControllerFollow.js.map +1 -1
  260. package/lib/engine-components/webxr/controllers/XRControllerModel.d.ts +4 -0
  261. package/lib/engine-components/webxr/controllers/XRControllerModel.js +4 -0
  262. package/lib/engine-components/webxr/controllers/XRControllerModel.js.map +1 -1
  263. package/lib/engine-components/webxr/controllers/XRControllerMovement.d.ts +1 -0
  264. package/lib/engine-components/webxr/controllers/XRControllerMovement.js +1 -0
  265. package/lib/engine-components/webxr/controllers/XRControllerMovement.js.map +1 -1
  266. package/lib/engine-components-experimental/networking/PlayerSync.d.ts +2 -0
  267. package/lib/engine-components-experimental/networking/PlayerSync.js +2 -0
  268. package/lib/engine-components-experimental/networking/PlayerSync.js.map +1 -1
  269. package/package.json +19 -12
  270. package/plugins/types/needleConfig.d.ts +1 -1
  271. package/plugins/types/next.d.ts +1 -1
  272. package/plugins/types/userconfig.d.ts +4 -1
  273. package/plugins/vite/custom-element-data.js +80 -0
  274. package/plugins/vite/index.js +4 -0
  275. package/src/engine/api.ts +0 -1
  276. package/src/engine/engine_texture.ts +1 -1
  277. package/src/engine/engine_tonemapping.ts +1 -1
  278. package/src/engine/webcomponents/logo-element.ts +12 -0
  279. package/src/engine/webcomponents/needle menu/needle-menu.ts +24 -3
  280. package/src/engine/webcomponents/needle-button.ts +6 -0
  281. package/src/engine/webcomponents/needle-engine.ts +317 -22
  282. package/src/engine-components/AlignmentConstraint.ts +9 -0
  283. package/src/engine-components/Animator.ts +1 -0
  284. package/src/engine-components/AudioListener.ts +2 -0
  285. package/src/engine-components/AudioSource.ts +1 -0
  286. package/src/engine-components/AxesHelper.ts +2 -0
  287. package/src/engine-components/Camera.ts +1 -0
  288. package/src/engine-components/CharacterController.ts +4 -1
  289. package/src/engine-components/DeleteBox.ts +2 -0
  290. package/src/engine-components/DeviceFlag.ts +4 -0
  291. package/src/engine-components/DragControls.ts +1 -0
  292. package/src/engine-components/DropListener.ts +1 -0
  293. package/src/engine-components/Duplicatable.ts +1 -0
  294. package/src/engine-components/EventTrigger.ts +2 -0
  295. package/src/engine-components/GridHelper.ts +2 -0
  296. package/src/engine-components/GroundProjection.ts +1 -0
  297. package/src/engine-components/LODGroup.ts +2 -0
  298. package/src/engine-components/Light.ts +1 -0
  299. package/src/engine-components/LookAtConstraint.ts +1 -0
  300. package/src/engine-components/NeedleMenu.ts +1 -0
  301. package/src/engine-components/NestedGltf.ts +1 -0
  302. package/src/engine-components/Networking.ts +1 -0
  303. package/src/engine-components/OffsetConstraint.ts +7 -0
  304. package/src/engine-components/OrbitControls.ts +1 -0
  305. package/src/engine-components/PlayerColor.ts +2 -0
  306. package/src/engine-components/ReflectionProbe.ts +1 -0
  307. package/src/engine-components/RigidBody.ts +1 -0
  308. package/src/engine-components/SceneSwitcher.ts +1 -0
  309. package/src/engine-components/ScreenCapture.ts +1 -0
  310. package/src/engine-components/SeeThrough.ts +1 -0
  311. package/src/engine-components/ShadowCatcher.ts +2 -0
  312. package/src/engine-components/Skybox.ts +1 -0
  313. package/src/engine-components/SmoothFollow.ts +1 -0
  314. package/src/engine-components/SpatialTrigger.ts +1 -0
  315. package/src/engine-components/SpectatorCamera.ts +1 -0
  316. package/src/engine-components/SpriteRenderer.ts +1 -0
  317. package/src/engine-components/SyncedCamera.ts +2 -0
  318. package/src/engine-components/SyncedRoom.ts +1 -0
  319. package/src/engine-components/SyncedTransform.ts +2 -0
  320. package/src/engine-components/TransformGizmo.ts +2 -0
  321. package/src/engine-components/VideoPlayer.ts +1 -0
  322. package/src/engine-components/Voip.ts +1 -0
  323. package/src/engine-components/export/usdz/extensions/behavior/BehaviourComponents.ts +18 -0
  324. package/src/engine-components/particlesystem/ParticleSystem.ts +1 -0
  325. package/src/engine-components/physics/Attractor.ts +3 -0
  326. package/src/engine-components/postprocessing/Effects/BloomEffect.ts +1 -0
  327. package/src/engine-components/postprocessing/Effects/ChromaticAberration.ts +4 -0
  328. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +3 -0
  329. package/src/engine-components/postprocessing/Effects/DepthOfField.ts +4 -0
  330. package/src/engine-components/postprocessing/Effects/EffectWrapper.ts +1 -0
  331. package/src/engine-components/postprocessing/Effects/Pixelation.ts +3 -0
  332. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +4 -0
  333. package/src/engine-components/postprocessing/Effects/Sharpening.ts +4 -0
  334. package/src/engine-components/postprocessing/Effects/TiltShiftEffect.ts +4 -0
  335. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +4 -0
  336. package/src/engine-components/postprocessing/Effects/Vignette.ts +4 -0
  337. package/src/engine-components/postprocessing/Volume.ts +1 -0
  338. package/src/engine-components/splines/Spline.ts +1 -0
  339. package/src/engine-components/splines/SplineWalker.ts +1 -0
  340. package/src/engine-components/timeline/PlayableDirector.ts +1 -0
  341. package/src/engine-components/timeline/SignalAsset.ts +1 -0
  342. package/src/engine-components/ui/Button.ts +4 -0
  343. package/src/engine-components/ui/Canvas.ts +5 -0
  344. package/src/engine-components/ui/CanvasGroup.ts +4 -0
  345. package/src/engine-components/ui/EventSystem.ts +2 -0
  346. package/src/engine-components/ui/Image.ts +4 -0
  347. package/src/engine-components/ui/InputField.ts +4 -0
  348. package/src/engine-components/ui/Outline.ts +7 -0
  349. package/src/engine-components/ui/Text.ts +1 -0
  350. package/src/engine-components/utils/LookAt.ts +1 -0
  351. package/src/engine-components/web/Clickthrough.ts +1 -1
  352. package/src/engine-components/web/CursorFollow.ts +1 -0
  353. package/src/engine-components/web/HoverAnimation.ts +1 -0
  354. package/src/engine-components/web/ScrollFollow.ts +2 -0
  355. package/src/engine-components/web/ViewBox.ts +1 -0
  356. package/src/engine-components/webxr/Avatar.ts +5 -0
  357. package/src/engine-components/webxr/WebARCameraBackground.ts +1 -0
  358. package/src/engine-components/webxr/WebARSessionRoot.ts +1 -0
  359. package/src/engine-components/webxr/WebXR.ts +1 -1
  360. package/src/engine-components/webxr/controllers/XRControllerFollow.ts +1 -0
  361. package/src/engine-components/webxr/controllers/XRControllerModel.ts +4 -0
  362. package/src/engine-components/webxr/controllers/XRControllerMovement.ts +1 -0
  363. package/src/engine-components-experimental/networking/PlayerSync.ts +2 -0
  364. package/lib/engine/webcomponents/needle-engine.attributes.d.ts +0 -70
  365. package/lib/engine/webcomponents/needle-engine.attributes.js +0 -2
  366. package/lib/engine/webcomponents/needle-engine.attributes.js.map +0 -1
  367. package/src/engine/webcomponents/needle-engine.attributes.ts +0 -85
@@ -141,7 +141,7 @@ void main(){
141
141
  #__vconsole .vc-mask {
142
142
  overflow: hidden;
143
143
  }
144
- `,br?.prepend(i),o===!0&&Nb()<=0&&p_(),console.log("\u{1F335} Debug console has loaded")}},e.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),cc=!1,Hi=null},e.src="https://cdn.jsdelivr.net/npm/vconsole@3.15.1/dist/vconsole.min.js",document.body.appendChild(e)}function TO(){if(!globalThis.VConsole)return;const o=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),e=()=>document.querySelector("#__vc_plug_"+o._id+" iframe");return o.on("renderTab",function(t){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const s=n.indexOf("?");s>-1&&(n=n.substring(0,s));const r=location.protocol+"//"+location.host+location.pathname+"/"+n,a=encodeURIComponent(r);o.fullUrl="https://viewer.needle.tools?inspect&file="+a;var l='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';t(l)}),o.on("show",function(){const t=e();t&&t.src!==o.fullUrl&&(t.src=o.fullUrl)}),o.on("hide",function(){const t=e();t&&(t.src="")}),o.on("addTopBar",function(t){var i=new Array;i.push({name:"Open in new window \u2197",onClick:function(n){window.open(o.fullUrl,"_blank"),Hi?.hide()}}),i.push({name:"Reload",onClick:function(n){const s=e();s&&(s.src=o.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const s=e();s.requestFullscreen?s.requestFullscreen():s.webkitRequestFullscreen instanceof Function&&s.webkitRequestFullscreen()}}),t(i)}),o}function EO(){return document.querySelector("#__vconsole .vc-switch")||null}function AO(){return document.querySelector("#__vconsole")||null}const g_=v("debugdefines");fs('if(!globalThis["NEEDLE_ENGINE_VERSION"]) globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";'),fs('if(!globalThis["NEEDLE_ENGINE_GENERATOR"]) globalThis["NEEDLE_ENGINE_GENERATOR"] = "unknown";'),fs('if(!globalThis["NEEDLE_PROJECT_BUILD_TIME"]) globalThis["NEEDLE_PROJECT_BUILD_TIME"] = "unknown";'),fs('if(!globalThis["NEEDLE_PUBLIC_KEY"]) globalThis["NEEDLE_PUBLIC_KEY"] = "unknown";'),fs('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.11.5";'),fs('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),fs('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Wed Dec 03 2025 10:35:46 GMT+0000 (Coordinated Universal Time)";'),fs('globalThis["__NEEDLE_PUBLIC_KEY__"] = "'+NEEDLE_PUBLIC_KEY+'";');const bn="4.11.5",Fd="undefined",sg="Wed Dec 03 2025 10:35:46 GMT+0000 (Coordinated Universal Time)";g_&&console.log(`Engine version: ${bn} (generator: ${Fd})
144
+ `,br?.prepend(i),o===!0&&Nb()<=0&&p_(),console.log("\u{1F335} Debug console has loaded")}},e.onerror=()=>{console.warn("\u{1F335} Debug console failed to load."+(window.crossOriginIsolated?"This page is using cross-origin isolation, so external scripts can't be loaded.":"")),cc=!1,Hi=null},e.src="https://cdn.jsdelivr.net/npm/vconsole@3.15.1/dist/vconsole.min.js",document.body.appendChild(e)}function TO(){if(!globalThis.VConsole)return;const o=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),e=()=>document.querySelector("#__vc_plug_"+o._id+" iframe");return o.on("renderTab",function(t){const i=globalThis["needle:codegen_files"];if(!i||i.length===0)return;let n=globalThis["needle:codegen_files"][0];const s=n.indexOf("?");s>-1&&(n=n.substring(0,s));const r=location.protocol+"//"+location.host+location.pathname+"/"+n,a=encodeURIComponent(r);o.fullUrl="https://viewer.needle.tools?inspect&file="+a;var l='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';t(l)}),o.on("show",function(){const t=e();t&&t.src!==o.fullUrl&&(t.src=o.fullUrl)}),o.on("hide",function(){const t=e();t&&(t.src="")}),o.on("addTopBar",function(t){var i=new Array;i.push({name:"Open in new window \u2197",onClick:function(n){window.open(o.fullUrl,"_blank"),Hi?.hide()}}),i.push({name:"Reload",onClick:function(n){const s=e();s&&(s.src=o.fullUrl)}}),i.push({name:"Fullscreen",onClick:function(n){const s=e();s.requestFullscreen?s.requestFullscreen():s.webkitRequestFullscreen instanceof Function&&s.webkitRequestFullscreen()}}),t(i)}),o}function EO(){return document.querySelector("#__vconsole .vc-switch")||null}function AO(){return document.querySelector("#__vconsole")||null}const g_=v("debugdefines");fs('if(!globalThis["NEEDLE_ENGINE_VERSION"]) globalThis["NEEDLE_ENGINE_VERSION"] = "0.0.0";'),fs('if(!globalThis["NEEDLE_ENGINE_GENERATOR"]) globalThis["NEEDLE_ENGINE_GENERATOR"] = "unknown";'),fs('if(!globalThis["NEEDLE_PROJECT_BUILD_TIME"]) globalThis["NEEDLE_PROJECT_BUILD_TIME"] = "unknown";'),fs('if(!globalThis["NEEDLE_PUBLIC_KEY"]) globalThis["NEEDLE_PUBLIC_KEY"] = "unknown";'),fs('globalThis["__NEEDLE_ENGINE_VERSION__"] = "4.11.5";'),fs('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),fs('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Thu Dec 04 2025 13:06:37 GMT+0000 (Coordinated Universal Time)";'),fs('globalThis["__NEEDLE_PUBLIC_KEY__"] = "'+NEEDLE_PUBLIC_KEY+'";');const bn="4.11.5",Fd="undefined",sg="Thu Dec 04 2025 13:06:37 GMT+0000 (Coordinated Universal Time)";g_&&console.log(`Engine version: ${bn} (generator: ${Fd})
145
145
  Project built at ${sg}`);const Ia=NEEDLE_PUBLIC_KEY,ko="needle_isActiveInHierarchy",_r="builtin_components",hc="needle_editor_guid";function fs(o){try{(0,eval)(o)}catch(e){g_&&console.error(e)}}let f_,y_=null;function _n(){return f_}function rg(o){if(o==null){console.warn("Oh no: someone tried registering a non-existend gltf-loader. When you see this log it might mean that needle-engine is being imported multiple times. Please check your project setup.");return}y_!==o&&(y_=o,f_=new o)}function IO(o,e){if(typeof window!==void 0&&window.SPECTOR){console.log(window.SPECTOR);const t=new URLSearchParams(window.location.search);if(t.has("spector")){let i=function(){if(n>o.time.frame)return window.requestAnimationFrame(()=>i());const r=s.captureCanvas(e);r&&r instanceof Promise?r.then(()=>s.displayUI()):s.displayUI()};const n=Number.parseInt(t.get("spector")||"0")||0;console.log("Scheduled Spector capture at frame #"+n);const s=new window.SPECTOR.Spector;s.spyCanvases=!0,i();return}else A()&&console.debug("Spector available: Add '?spector=<frame>' to the URL to enable it and capture a frame.")}}const Mi=Symbol("shadowDomOwner"),LO=v("debugpatch");function Ud(o,e,t,i){const n=LO===e;if(!t&&!i)return;const s=e+"___needle";DO(o,e,t,i);const r=Object.getOwnPropertyDescriptor(o,e),a=o[e];n&&console.log("Patch",o.constructor.name,e,r,a),r?(n&&console.log("Apply patch with existing descriptor",o.constructor.name,e,r),typeof r.value=="function"&&(o[e]=__(r.value,o,e))):(n&&console.log("Create patch with new property",o.constructor.name,e,r),Object.defineProperty(o,e,{set:function(l){if(typeof l=="function")this[s]=__(l,o,e);else{const c=this[s];v_(o,e,this,c,l),this[s]=l,w_(o,e,this,c,l)}},get:function(){const l=this[s];return typeof l=="function"&&l[s]?l[s]:l}}))}function jO(o,e,t){const i=lg(o,e);if(i)for(let n=i.length-1;n>=0;n--){const s=i[n];s.prefix===t&&(s.prefix=null),s.postfix===t&&(s.postfix=null),!s.prefix&&!s.postfix&&i.splice(n,1)}}const b_=Symbol("Needle:Patches:WrappedFunction");function __(o,e,t){if(o[b_])return o;const i=function(...n){v_(e,t,this,...n);const s=o.apply(this,n);return w_(e,t,this,s,...n),s};return i[b_]=!0,i}const zd="Needle:Patches";function ag(){return globalThis[zd]||(globalThis[zd]=new WeakMap),globalThis[zd]}function lg(o,e){const t=ag().get(o);return t?t.get(e):null}function DO(o,e,t,i){let n=ag().get(o);n||(n=new Map,ag().set(o,n));let s=n.get(e);s||(s=[],n.set(e,s)),s.push({prefix:t,postfix:i})}function v_(o,e,t,...i){if(!t)return;const n=lg(o,e);if(n)for(const s of n)s.prefix?.call(t,...i)}function w_(o,e,t,i,...n){if(!t)return;const s=lg(o,e);if(s)for(const r of s)r.postfix?.call(t,i,...n)}const La=[];function Nd(o){La.indexOf(o)===-1&&La.push(o)}function BO(o){const e=La.indexOf(o);e!==-1&&La.splice(e,1)}const ja=[];function cg(o){ja.indexOf(o)===-1&&ja.push(o)}function FO(o){const e=ja.indexOf(o);e!==-1&&ja.splice(e,1)}function x_(o){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:o}));for(let e=0;e<La.length;e++)La[e](o)}function S_(o){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:o}));for(let e=0;e<ja.length;e++)ja[e](o)}const st=v("debuginput");var Vd=(o=>(o.Mouse="mouse",o.Touch="touch",o.Controller="controller",o.Hand="hand",o))(Vd||{}),Ee=(o=>(o.PointerDown="pointerdown",o.PointerUp="pointerup",o.PointerMove="pointermove",o.KeyDown="keydown",o.KeyUp="keyup",o.KeyPressed="keypress",o))(Ee||{});class Mo extends PointerEvent{clientZ;deviceIndex;origin;source;mode;get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new vo(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}_ray;space;isClick=!1;isDoubleClick=!1;get used(){return this._used}_used=!1;use(){this._used=!0}get pointerId(){return this._pointerid}_pointerid;get pointerType(){return this._pointerType}_pointerType;get type(){return this._type}_type;metadata={};intersections=new Array;constructor(e,t,i){super(e,i),this.clientZ=i.clientZ,this._pointerid=i.pointerId,this._pointerType=i.pointerType,this._type=e,this.deviceIndex=i.deviceIndex,this.origin=i.origin,this.source=t,this.mode=i.mode,this._ray=i.ray,this.space=i.device}_immediatePropagationStopped=!1;get immediatePropagationStopped(){return this._immediatePropagationStopped}_propagationStopped=!1;get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),this.source?.stopImmediatePropagation()}stopPropagation(){this._propagationStopped=!0,super.stopPropagation(),this.source?.stopPropagation(),st&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class dc extends KeyboardEvent{source;constructor(e,t,i){super(e,i),this.source=t}stopImmediatePropagation(){super.stopImmediatePropagation(),this.source?.stopImmediatePropagation()}}class UO{key;keyType;source;constructor(e){this.key=e.key,this.keyType=e.type,this.source=e}}var ai=(o=>(o[o.Early=-100]="Early",o[o.Default=0]="Default",o[o.Late=100]="Late",o))(ai||{});class C_{_eventListeners={};addEventListener(e,t,i){if(this._eventListeners[e]||(this._eventListeners[e]=[]),!t||typeof t!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}i?i={...i}:i={};let n=0;i?.queue!=null&&(n=i.queue);const s=this._eventListeners[e],r=s.find(a=>a.priority===n);r?r.listeners.push({callback:t,options:i}):(s.push({priority:n,listeners:[{callback:t,options:i}]}),s.sort((a,l)=>a.priority-l.priority))}removeEventListener(e,t,i){if(!this._eventListeners[e]||!t)return;const n=this._eventListeners[e];if(i?.queue!=null){const s=n.find(a=>a.priority===i.queue);if(!s)return;const r=s.listeners.findIndex(a=>a.callback===t);r>=0&&s.listeners.splice(r,1)}else for(const s of n){const r=s.listeners.findIndex(a=>a.callback===t);r>=0&&s.listeners.splice(r,1)}}dispatchEvent(e){let t=!1;if(e instanceof dc){const i=this._eventListeners[e.type];if(i)for(const n of i)for(let s=0;s<n.listeners.length;s++){const r=n.listeners[s];if(r.options?.signal?.aborted){n.listeners.splice(s,1),s--;continue}r.options.once&&(n.listeners.splice(s,1),s--),r.callback(e)}}if(e instanceof Mo){const i=this._eventListeners[e.type];if(i)for(const n of i){if(t)break;for(let s=0;s<n.listeners.length;s++){const r=n.listeners[s];if(r.options?.signal?.aborted){n.listeners.splice(s,1),s--;continue}if(e.immediatePropagationStopped){t=!0,st&&console.log("immediatePropagationStopped",e.type);break}else e.propagationStopped&&(t=!0,st&&console.log("propagationStopped",e.type));r.options.once&&(n.listeners.splice(s,1),s--),r.callback(e)}}}}_doubleClickTimeThreshold=.2;_longPressTimeThreshold=1;get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}get click(){return this._pointerClick[0]}get doubleClick(){return this._pointerDoubleClick[0]}getGamepad(e=0){return typeof navigator<"u"&&"getGamepads"in navigator&&navigator.getGamepads()[e]||null}_setCursorTypes=[];setCursorPointer(){this.setCursor("pointer")}setCursorNormal(){this.unsetCursor("pointer")}setCursor(e){this._setCursorTypes.push(e),this._setCursorTypes.length>10&&this._setCursorTypes.shift(),this.updateCursor()}unsetCursor(e){for(let t=this._setCursorTypes.length-1;t>=0;t--)if(this._setCursorTypes[t]===e){this._setCursorTypes.splice(t,1),this.updateCursor();break}}updateCursor(){this._setCursorTypes?.length==0?this.context.domElement.style.cursor="default":this.context.domElement.style.cursor=this._setCursorTypes[this._setCursorTypes.length-1]}getIsPointerIdInUse(e){for(const t of this._pointerEventsPressed)if(t.pointerId===e&&t.used)return!0;return!1}getPointerPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&e++;return e}getPointerPosition(e){return e>=this._pointerPositions.length?null:this._pointerPositions[e]}getPointerPositionLastFrame(e){return e>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[e]}getPointerPositionDelta(e){return e>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[e]}getPointerPositionRC(e){return e>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[e]}getPointerDown(e){return e>=this._pointerDown.length?!1:this._pointerDown[e]}getPointerUp(e){return e>=this._pointerUp.length?!1:this._pointerUp[e]}getPointerPressed(e){return e>=this._pointerPressed.length?!1:this._pointerPressed[e]}getPointerClicked(e){return e>=this._pointerClick.length?!1:this._pointerClick[e]}getPointerDoubleClicked(e){return e>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[e]}getPointerDownTime(e){return e>=this._pointerDownTime.length?-1:this._pointerDownTime[e]}getPointerUpTime(e){return e>=this._pointerUpTime.length?-1:this._pointerUpTime[e]}getPointerLongPress(e){return e>=this._pointerDownTime.length?!1:this.getPointerPressed(e)&&this.context.time.time-this._pointerDownTime[e]>this._longPressTimeThreshold}getIsMouse(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="mouse"}getIsTouch(e){return e<0||e>=this._pointerTypes.length?!1:this._pointerTypes[e]==="touch"}getTouchesPressedCount(){let e=0;for(let t=0;t<this._pointerPressed.length;t++)this._pointerPressed[t]&&this.getIsTouch(t)&&e++;return e}getMouseWheelChanged(e=0){return e>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[e]}getMouseWheelDeltaY(e=0){return e>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[e]}getPointerEvent(e){if(!(e>=this._pointerEvent.length))return this._pointerEvent[e]??void 0}*foreachPointerId(e){for(let t=0;t<this._pointerTypes.length;t++)if(this._pointerIsActive(t)){if(e!==void 0){const i=this._pointerTypes[t];if(Array.isArray(e)){let n=!1;for(const s of e)if(i===s){n=!0;break}if(!n)continue}else if(e!==i)continue}yield t}}*foreachTouchId(){for(let e=0;e<this._pointerTypes.length;e++)this._pointerTypes[e]==="touch"&&this._pointerIsActive[e]&&(yield e)}_pointerIsActive(e){return e<0?!1:this._pointerPressed[e]||this._pointerDown[e]||this._pointerUp[e]}context;_pointerDown=[!1];_pointerUp=[!1];_pointerClick=[!1];_pointerDoubleClick=[!1];_pointerPressed=[!1];_pointerPositions=[new ee];_pointerPositionsLastFrame=[new ee];_pointerPositionsDelta=[new ee];_pointerPositionsRC=[new ee];_pointerPositionDown=[new b];_pointerDownTime=[];_pointerUpTime=[];_pointerUpTimestamp=[];_pointerIds=[];_pointerTypes=[""];_mouseWheelChanged=[!1];_mouseWheelDeltaY=[0];_pointerEvent=[];_pointerEventsPressed=[];_pointerSpace=[];_pressedStack=new Map;onDownButton(e,t){let i=this._pressedStack.get(e);i||(i=[],this._pressedStack.set(e,i)),i.push(t)}onReleaseButton(e,t){const i=this._pressedStack.get(e);if(!i)return;const n=i.indexOf(t);n>=0&&i.splice(n,1)}getFirstPressedButtonForPointer(e){const t=this._pressedStack.get(e);if(t)return t[0]}getLatestPressedButtonForPointer(e){const t=this._pressedStack.get(e);if(t)return t[t.length-1]}getKeyDown(e){if(e!==void 0)return this.isKeyDown(e);for(const t in this.keysPressed){const i=this.keysPressed[t];if(i.startFrame===this.context.time.frameCount)return i.key}return null}getKeyPressed(e){if(e!==void 0)return this.isKeyPressed(e);for(const t in this.keysPressed){const i=this.keysPressed[t];if(i.pressed)return i.key}return null}getKeyUp(e){if(e!==void 0)return this.isKeyUp(e);for(const t in this.keysPressed){const i=this.keysPressed[t];return i.pressed===!1&&i.frame===this.context.time.frameCount}return null}isKeyDown(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const n of t)if(this.isKeyDown(n))return!0;return!1}const i=this.keysPressed[e];return i?i.startFrame===this.context.time.frameCount&&i.pressed:!1}isKeyUp(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const n of t)if(this.isKeyUp(n))return!0;return!1}const i=this.keysPressed[e];return i?i.frame===this.context.time.frameCount&&i.pressed===!1:!1}isKeyPressed(e){if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const t=this.getCodeForCommonKeyName(e);if(t!==null){for(const n of t)if(this.isKeyPressed(n))return!0;return!1}const i=this.keysPressed[e];return i&&i.pressed||!1}getCodeForCommonKeyName(e){if(e.length===1){if(e>="0"&&e<="9")return["Digit"+e];if(e>="a"&&e<="z")return["Key"+e.toUpperCase()];if(e==" ")return["Space"]}switch(e){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(e){switch(e.type){case"pointerdown":st&&Te("Create Pointer down"),this.onDownButton(e.deviceIndex,e.button),this.onDown(e);break;case"pointermove":st&&Te("Create Pointer move"),this.onMove(e);break;case"pointerup":st&&Te("Create Pointer up"),this.onUp(e),this.onReleaseButton(e.deviceIndex,e.button);break}}convertScreenspaceToRaycastSpace(e){return e.x=(e.x-this.context.domX)/this.context.domWidth*2-1,e.y=-((e.y-this.context.domY)/this.context.domHeight)*2+1,e}constructor(e){this.context=e,this.context.post_render_callbacks.push(this.onEndOfFrame)}_htmlEventSource;bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){for(const e in this._eventListeners)this._eventListeners[e].length=0;window.removeEventListener("contextmenu",this.onContextMenu),this._htmlEventSource?.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),window.removeEventListener("touchstart",this.onTouchStart),window.removeEventListener("touchmove",this.onTouchMove),window.removeEventListener("touchend",this.onTouchEnd),this._htmlEventSource?.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const e=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);e>=0&&this.context.post_render_callbacks.splice(e,1),this.unbindEvents()}onLostFocus=()=>{for(const e in this.keysPressed)this.keysPressed[e].pressed=!1};_receivedPointerMoveEventsThisFrame=new Array;onEndOfFrame=()=>{this._receivedPointerMoveEventsThisFrame.length=0;for(let e=0;e<this._pointerUp.length;e++)this._pointerUp[e]=!1;for(let e=0;e<this._pointerDown.length;e++)this._pointerDown[e]=!1;for(let e=0;e<this._pointerClick.length;e++)this._pointerClick[e]=!1;for(let e=0;e<this._pointerDoubleClick.length;e++)this._pointerDoubleClick[e]=!1;for(const e of this._pointerPositionsDelta)e.set(0,0);for(let e=0;e<this._mouseWheelChanged.length;e++)this._mouseWheelChanged[e]=!1;for(let e=0;e<this._mouseWheelDeltaY.length;e++)this._mouseWheelDeltaY[e]=0};canReceiveInput(e){return e.target===this.context.renderer?.domElement||e.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&e.target===document.body&&q.isMozillaXR()?!0:(st&&console.warn("CanReceiveInput:False for",e.target),!1)}onContextMenu=e=>{this.canReceiveInput(e)!==!1&&e instanceof PointerEvent&&e.pointerType};keysPressed={};onKeyDown=e=>{if(st&&console.log(`key down ${e.code}, ${this.context.application.hasFocus}`,e),!this.context.application.hasFocus)return;const t=this.keysPressed[e.code];if(t&&t.pressed)return;this.keysPressed[e.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:e.key,code:e.code};const i=new dc("keydown",e,e);this.onDispatchEvent(i)};onKeyPressed=e=>{if(!this.context.application.hasFocus)return;const t=this.keysPressed[e.code];if(!t)return;t.pressed=!0,t.frame=this.context.time.frameCount+1;const i=new dc("keypress",e,e);this.onDispatchEvent(i)};onKeyUp=e=>{if(!this.context.application.hasFocus)return;const t=this.keysPressed[e.code];if(!t)return;t.pressed=!1,t.frame=this.context.time.frameCount+1;const i=new dc("keyup",e,e);this.onDispatchEvent(i)};onWheelWindow=e=>{document.pointerLockElement&&this.onMouseWheel(e)};onMouseWheel=e=>{if(this.canReceiveInput(e)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const t=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=t+e.deltaY};onPointerDown=e=>{if(this.context.isInAR||this.canReceiveInput(e)===!1)return;e.target instanceof HTMLElement&&e.target.setPointerCapture(e.pointerId);const t=this.getPointerId(e);st&&Te(`pointer down #${t}, identifier:${e.pointerId}`);const i=this.getAndUpdateSpatialObjectForScreenPosition(t,e.clientX,e.clientY),n=new Mo("pointerdown",e,{origin:this,mode:"screen",deviceIndex:0,pointerId:t,button:e.button,clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,buttonName:this.getButtonName(e),device:i,pressure:e.pressure});this.onDown(n)};onPointerMove=e=>{if(this.context.isInAR||this._receivedPointerMoveEventsThisFrame.includes(e.pointerId))return;this._receivedPointerMoveEventsThisFrame.push(e.pointerId);let t=e.button;e.pointerType==="mouse"&&(t=this.getFirstPressedButtonForPointer(0)??0);const i=this.getPointerId(e,t);t===-1&&(t=i);const n=this.getAndUpdateSpatialObjectForScreenPosition(i,e.clientX,e.clientY),s=new Mo("pointermove",e,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:t,clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,buttonName:this.getButtonName(e),device:n,pressure:e.pressure});this.onMove(s)};onPointerCancel=e=>{this.context.isInAR||(st&&console.log("Pointer cancel",e),this.onPointerUp(e))};onPointerUp=e=>{if(this.context.isInAR)return;e.target instanceof HTMLElement&&e.target.releasePointerCapture(e.pointerId);const t=this.getPointerId(e),i=new Mo("pointerup",e,{origin:this,mode:"screen",deviceIndex:0,pointerId:t,button:e.button,clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,buttonName:this.getButtonName(e),device:this.getAndUpdateSpatialObjectForScreenPosition(t,e.clientX,e.clientY),pressure:e.pressure});this.onUp(i),this._pointerIds[t]=-1,st&&console.log("ID="+t,"PointerId="+e.pointerId,"ALL:",[...this._pointerIds])};getPointerId(e,t){return e.pointerType==="mouse"?0+(t??e.button):this.getPointerIndex(e.pointerId)}getButtonName(e){const t=e.button;if(e.pointerType==="mouse")switch(t){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}onTouchStart=e=>{if(this.context.isInAR)for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t],n=this.getPointerIndex(i.identifier),s=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),r=new Mo("pointerdown",e,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:s,pressure:i.force});this.onDown(r)}};onTouchMove=e=>{if(this.context.isInAR)for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t],n=this.getPointerIndex(i.identifier),s=this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),r=new Mo("pointermove",e,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:s,pressure:i.force});this.onMove(r)}};onTouchEnd=e=>{if(this.context.isInAR)for(let t=0;t<e.changedTouches.length;t++){const i=e.changedTouches[t],n=this.getPointerIndex(i.identifier),s=new Mo("pointerup",e,{origin:this,mode:"screen",deviceIndex:0,pointerId:n,button:0,clientX:i.clientX,clientY:i.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(n,i.clientX,i.clientY),pressure:i.force});this.onUp(s),this._pointerIds[n]=-1}};tempNearPlaneVector=new b;tempFarPlaneVector=new b;tempLookMatrix=new K;getAndUpdateSpatialObjectForScreenPosition(e,t,i){let n=this._pointerSpace[e];n||(n=new k,this._pointerSpace[e]=n),this._pointerSpace[e]=n;const s=this.context.mainCamera;if(s){const r=this.tempNearPlaneVector.set(t,i,-1);this.convertScreenspaceToRaycastSpace(r);const a=this.tempFarPlaneVector.set(r.x,r.y,1);r.unproject(s),a.unproject(s);const l=s.worldUp||D(0,1,0).applyQuaternion(be(s));this.tempLookMatrix.lookAt(a,r,l),n.position.set(r.x,r.y,r.z),n.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return n}isInRect(e){if(this.context.isInXR)return!0;const t=this.context.domElement.getBoundingClientRect(),i=e.clientX,n=e.clientY,s=i>=t.x&&i<=t.right&&n>=t.y&&n<=t.bottom;return st&&!s&&console.log("Not in rect",t,i,n),s}onDown(e){const t=e.pointerId;if(this.getPointerPressed(t)&&console.warn(`Received pointerDown for pointerId that is already pressed: ${t}`,st?e:""),st&&console.log(e.pointerType,"DOWN",t),!!this.isInRect(e)){for(this.setPointerState(t,this._pointerPressed,!0),this.setPointerState(t,this._pointerDown,!0),this.setPointerStateT(t,this._pointerEvent,e.source);t>=this._pointerTypes.length;)this._pointerTypes.push(e.pointerType);for(this._pointerTypes[t]=e.pointerType;t>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new b);for(this._pointerPositionDown[t].set(e.clientX,e.clientY,e.clientZ??0);t>=this._pointerPositions.length;)this._pointerPositions.push(new ee);this._pointerPositions[t].set(e.clientX,e.clientY),t>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[t]=this.context.time.realtimeSinceStartup,this.updatePointerPosition(e),this._pointerEventsPressed.push(e),this.onDispatchEvent(e)}}onMove(e){const t=e.pointerId,i=this.getPointerPressed(t);i===!1&&!this.isInRect(e)||e.pointerType==="touch"&&!i||(this.updatePointerPosition(e),this.setPointerStateT(t,this._pointerEvent,e.source),this.onDispatchEvent(e))}onUp(e){const t=e.pointerId;if(!this.getPointerPressed(t)){st&&console.log(e.pointerType,"UP",t,"was not down");return}st&&console.log(e.pointerType,"UP",t),this.setPointerState(t,this._pointerPressed,!1),this.setPointerStateT(t,this._pointerEvent,e.source),this.setPointerState(t,this._pointerUp,!0),this.updatePointerPosition(e);for(let a=this._pointerEventsPressed.length-1;a>=0;a--)if(this._pointerEventsPressed[a].pointerId===t){this._pointerEventsPressed.splice(a,1);break}if(!this._pointerPositionDown[t]){st&&ye("Received pointer up event without matching down event for button: "+t),console.warn("Received pointer up event without matching down event for button: "+t);return}const i=this._pointerUpTime[t],n=this._pointerDownTime[t],s=this.context.time.realtimeSinceStartup,r=s-n;if(t>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),this._pointerUpTime[t]=s,r<1){let a=e.clientX-this._pointerPositionDown[t].x,l=e.clientY-this._pointerPositionDown[t].y,c=0;if(e.isSpatial&&e.clientZ!=null&&(c=e.clientZ-this._pointerPositionDown[t].z,a*=200,l*=200,c*=200),Math.abs(a)<5&&Math.abs(l)<5&&Math.abs(c)<5){this.setPointerState(t,this._pointerClick,!0),e.isClick=!0;const h=s-i;st&&console.log("CLICK",t,a,l,c,h),h<this._doubleClickTimeThreshold&&h>0&&(this.setPointerState(t,this._pointerDoubleClick,!0),e.isDoubleClick=!0)}}this.onDispatchEvent(e)}updatePointerPosition(e){const t=e.pointerId;for(;t>=this._pointerPositions.length;)this._pointerPositions.push(new ee);for(;t>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new ee);for(;t>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new ee);const i=this._pointerPositionsLastFrame[t];i.copy(this._pointerPositions[t]);const n=this._pointerPositionsDelta[t];let s=e.clientX-i.x,r=e.clientY-i.y;if(e.source instanceof MouseEvent||e.source instanceof TouchEvent){const h=e.source;s===0&&h.movementX!==0&&(s=h.movementX||0),r===0&&h.movementY!==0&&(r=h.movementY||0)}n.x+=s,n.y+=r,this._pointerPositions[t].x=e.clientX,this._pointerPositions[t].y=e.clientY;const a=e.clientX,l=e.clientY;for(;t>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new ee);const c=this._pointerPositionsRC[t];c.set(a,l),this.convertScreenspaceToRaycastSpace(c)}getPointerIndex(e){let t=-1;for(let i=0;i<this._pointerIds.length;i++){if(this._pointerIds[i]===e)return i;t===-1&&this._pointerIds[i]===-1&&(t=i)}return t!==-1?(this._pointerIds[t]=e,t):(st&&console.log("PUSH pointerId:",e),this._pointerIds.push(e),this._pointerIds.length-1)}setPointerState(e,t,i){t[e]=i}setPointerStateT(e,t,i){return t[e]=i,i}onDispatchEvent(e){const t=z.Current;try{z.Current=this.context,this.dispatchEvent(e)}finally{z.Current=t}}}const Da=new K().makeRotationY(Math.PI),Gi=new U().setFromAxisAngle(new b(0,1,0),Math.PI),zO=v("debugwebxr");class NO{priority=-1e5;gameObject;isXRRig(){return!0}get isActive(){return this.gameObject.visible}constructor(){if(this.gameObject=new k,this.gameObject.name="Implicit XR Rig",zO){const e=Cg(16733661);e.position.y+=.5,this.gameObject.add(e)}}}const Ro=v("debugwebxr"),Wd=v("debugcustomgesture"),VO="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",WO="generic-trigger",$O=new U().setFromEuler(new ot(wo.degToRad(0),wo.degToRad(-90),wo.degToRad(-90))),HO=new b(.04,-.04,0);class hg{xr;get context(){return this.xr.context}inputSource;index=0;emitEvents=!0;get connected(){return this._connected}_connected=!0;get isTracking(){return this._isTracking}_isTracking=!1;get gamepad(){return this.__gamepad??=this.inputSource.gamepad}__gamepad;get isHand(){return this.hand!=null}get hand(){return this.__hand??=this.inputSource.hand}__hand;get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.__side??=this.inputSource.handedness}__side=void 0;get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get isStylus(){return this._isMxInk}getHitTestSource(){return this._hitTestSource||this._requestHitTestSource(),this._hitTestSource}get hasHitTestSource(){return this._hitTestSource}cancelHitTestSource(){this._hitTestSource&&(this._hitTestSource.cancel(),this._hitTestSource=void 0)}_hitTestSource=void 0;_hasSelectEvent=!1;get hasSelectEvent(){return this._hasSelectEvent}_isMxInk=!1;_isMetaQuestTouchController=!1;getHitTest(){return this.xr.getHitTest(this)}_handJointPoses=new Map;getHandJointPose(e,t){if(t=t||this.xr.frame,!this.hand||!t?.getJointPose||!this.xr.referenceSpace)return null;let i=this._handJointPoses?.get(e);return i||(i=t.getJointPose(e,this.xr.referenceSpace),i&&this._handJointPoses.set(e,i),i)}_gripMatrix=new K;_gripPosition=new b;_gripQuaternion=new U;_linearVelocity=new b;_rayPositionRaw=new b;_rayRotationRaw=new U;_rayMatrix=new K;_rayPosition=new b;_rayQuaternion=new U;get gripPosition(){return D(this._gripPosition)}get gripQuaternion(){return ri(this._gripQuaternion)}get gripMatrix(){return this._gripMatrix}get gripLinearVelocity(){return D(this._linearVelocity).applyQuaternion(Gi)}get rayPosition(){return D(this._rayPosition)}get rayQuaternion(){return ri(this._rayQuaternion)}get gripWorldPosition(){return D(this._gripWorldPosition)}_gripWorldPosition=new b;get gripWorldQuaternion(){return ri(this._gripWorldQuaternion)}_gripWorldQuaternion=new U;get rayWorldPosition(){return D(this._rayWorldPosition)}_rayWorldPosition=new b;updateRayWorldPosition(){const e=this.xr.context.mainCamera?.parent;this._rayWorldPosition.copy(this._rayPositionRaw),e&&this._rayWorldPosition.applyMatrix4(e.matrixWorld)}get rayWorldQuaternion(){return ri(this._rayWorldQuaternion)}_rayWorldQuaternion=new U;get pinchPosition(){return D(this._pinchPosition)}_pinchPosition=new b;updateRayWorldQuaternion(){const e=this.xr.context.mainCamera?.parent,t=e?be(e):void 0;this._rayWorldQuaternion.copy(this._rayRotationRaw).multiply(Gi),t&&this._rayWorldQuaternion.premultiply(t)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(D(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}_ray;_hand_wristDotUp=void 0;get handWristDotUp(){if(this._hand_wristDotUp!==void 0)return this._hand_wristDotUp;const e=this.handObject?.joints.wrist;if(e){const t=D(0,1,0).applyQuaternion(e.quaternion),i=D(0,1,0).dot(t);return this._hand_wristDotUp=i}}get isHandUpsideDown(){return this.handWristDotUp!==void 0?this.handWristDotUp<-.7:!1}get isTeleportGesture(){return this.isHandUpsideDown&&this.getGesture("pinch")?.isDown}get object(){return this._object}_object;_gripSpaceObject;_raySpaceObject;model=null;_debugAxesHelper=new Si(.15);_debugGripAxesHelper=new Si(.07);_debugRayAxesHelper=new Si(.07);async getModelUrl(){return this.getMotionController?.then(e=>e?.assetUrl||null)}constructor(e,t,i){this.xr=e,this.inputSource=t,this.index=i,this._object=new k,this._object.name=`NeedleXRController_${i}`,Ro&&(this._object.add(this._debugAxesHelper),this._gripSpaceObject=new k,this._raySpaceObject=new k,this._gripSpaceObject.name=`NeedleXRController_${i}_gripSpace`,this._raySpaceObject.name=`NeedleXRController_${i}_raySpace`,this._gripSpaceObject.add(this._debugGripAxesHelper),this._raySpaceObject.add(this._debugRayAxesHelper),this.xr.context.scene.add(this._gripSpaceObject),this.xr.context.scene.add(this._raySpaceObject)),this.xr.context.scene.add(this._object),this._ray=new vo,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents()}_hitTestSourcePromise=null;_requestHitTestSource(){return this._hitTestSourcePromise?this._hitTestSourcePromise:this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&this.xr.session.requestHitTestSourceForTransientInput?this._hitTestSourcePromise=this.xr.session.requestHitTestSourceForTransientInput({profile:this.inputSource.profiles[0],offsetRay:new XRRay})?.then(e=>(this._hitTestSourcePromise=null,this.connected?this._hitTestSource=e:(e.cancel(),null)))??null:null}onPointerHits=e=>{};onUpdate(e){this.onUpdateFrame(e),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){B.DrawSphere(this.rayWorldPosition,.003),B.DrawDirection(this.rayWorldPosition,D(0,0,10).applyQuaternion(this.rayWorldQuaternion));const e=(this.inputSource.gripSpace?this.gripWorldPosition:this.object.worldPosition).sub(this.object.worldForward.multiplyScalar(.1)),t=this.inputSource.profiles.join(`
146
146
  `);let i=`Controller[${this.index}] (${this.inputSource.targetRayMode}, ${this.side})
147
147
  C:${this.connected?"x":"-"} T:${this.isTracking?"x":"-"} Hand:${this.inputSource.hand?"x":"-"} Pen: ${this._isMxInk?"x":"-"}`;if(this.inputSource.hand&&(i+=`
@@ -1526,7 +1526,7 @@ Please refer to the documentation on <a href="https://fwd.needle.tools/needle-en
1526
1526
  width: 100%;
1527
1527
  opacity: 0;
1528
1528
  transition: opacity 1s ease-in-out 4s;
1529
- `,setTimeout(()=>{d.style.opacity="1"},1),this._loadingElement.appendChild(d);const p=document.createElement("div"),m=100;return p.style.display="flex",p.style.width=m+"%",p.style.height="5px",p.style.position="absolute",p.style.left="0",p.style.top="0px",p.style.opacity="0",p.style.transition="opacity 1s ease-in-out",p.style.backgroundColor="rgba(240,240,240,.5)",setTimeout(()=>{p.style.opacity="1"},1),this._loadingElement.appendChild(p),this._loadingBar=document.createElement("div"),p.appendChild(this._loadingBar),this._loadingBar.style.backgroundAttachment="fixed",this._loadingBar.style.background="#c4c4c4ab",this._loadingBarFinishedColor="#ddddddab",this._loadingBar.style.width="0%",this._loadingBar.style.height="100%",this._loadingElement}}rg(q1);const Me=v("debugwebcomponent"),eS="needle-engine",tS="vr",iS="desktop",eL=[K1,tS,iS],id="ar-session-active",nd="desktop-session-active",tL=["public-key","version","hash","src","camera-controls","loadstart","progress","loadfinished","dracoDecoderPath","dracoDecoderType","ktx2DecoderPath","tone-mapping","tone-mapping-exposure","background-blurriness","background-color","environment-intensity","focus-rect"];class N0 extends HTMLElement{static get observedAttributes(){return tL}get loadingProgress01(){return this._loadingProgress01}get loadingFinished(){return this.loadingProgress01>.999}get cameraControls(){const e=this.getAttribute("camera-controls");return e==null?null:!(e===null||e==="False"||e==="false"||e==="0"||e==="none")}set cameraControls(e){e===null?this.removeAttribute("camera-controls"):this.setAttribute("camera-controls",e?"true":"false")}getContext(){return new Promise((e,t)=>{if(this._context&&this.loadingFinished)e(this._context);else{const i=()=>{this.removeEventListener("loadfinished",i),this._context&&this.loadingFinished&&e(this._context)};this.addEventListener("loadfinished",i)}})}get context(){return this._context}_context;_overlay_ar;_loadingProgress01=0;_loadingView;_previousSrc=null;_didFullyLoad=!1;constructor(){super(),this._overlay_ar=new KI,this.addEventListener("ready",this.onReady),dw(),this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>
1529
+ `,setTimeout(()=>{d.style.opacity="1"},1),this._loadingElement.appendChild(d);const p=document.createElement("div"),m=100;return p.style.display="flex",p.style.width=m+"%",p.style.height="5px",p.style.position="absolute",p.style.left="0",p.style.top="0px",p.style.opacity="0",p.style.transition="opacity 1s ease-in-out",p.style.backgroundColor="rgba(240,240,240,.5)",setTimeout(()=>{p.style.opacity="1"},1),this._loadingElement.appendChild(p),this._loadingBar=document.createElement("div"),p.appendChild(this._loadingBar),this._loadingBar.style.backgroundAttachment="fixed",this._loadingBar.style.background="#c4c4c4ab",this._loadingBarFinishedColor="#ddddddab",this._loadingBar.style.width="0%",this._loadingBar.style.height="100%",this._loadingElement}}rg(q1);const Me=v("debugwebcomponent"),eS="needle-engine",tS="vr",iS="desktop",eL=[K1,tS,iS],id="ar-session-active",nd="desktop-session-active",tL=["src","hash","camera-controls","dracoDecoderPath","dracoDecoderType","ktx2DecoderPath","public-key","version","tone-mapping","tone-mapping-exposure","background-blurriness","background-color","environment-intensity","focus-rect","loadstart","progress","loadfinished"];class N0 extends HTMLElement{static get observedAttributes(){return tL}get loadingProgress01(){return this._loadingProgress01}get loadingFinished(){return this.loadingProgress01>.999}get cameraControls(){const e=this.getAttribute("camera-controls");return e==null?null:!(e===null||e==="False"||e==="false"||e==="0"||e==="none")}set cameraControls(e){e===null?this.removeAttribute("camera-controls"):this.setAttribute("camera-controls",e?"true":"false")}getContext(){return new Promise((e,t)=>{if(this._context&&this.loadingFinished)e(this._context);else{const i=()=>{this.removeEventListener("loadfinished",i),this._context&&this.loadingFinished&&e(this._context)};this.addEventListener("loadfinished",i)}})}get context(){return this._context}_context;_overlay_ar;_loadingProgress01=0;_loadingView;_previousSrc=null;_didFullyLoad=!1;constructor(){super(),this._overlay_ar=new KI,this.addEventListener("ready",this.onReady),dw(),this.attachShadow({mode:"open"});const e=document.createElement("template");e.innerHTML=`<style>
1530
1530
  @import url('https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap');
1531
1531
 
1532
1532
  :host {
@@ -1604,12 +1604,12 @@ Please refer to the documentation on <a href="https://fwd.needle.tools/needle-en
1604
1604
  <slot class="overlay-content"></slot>
1605
1605
  </div>
1606
1606
  `,this.shadowRoot&&this.shadowRoot.appendChild(e.content.cloneNode(!0)),this._context=new z({domElement:this}),this.addEventListener("error",this.onError)}async connectedCallback(){if(Me&&console.log("<needle-engine> connected"),this.setPublicKey(),this.setVersion(),(this.getAttribute("tabindex")===null||this.getAttribute("tabindex")===void 0)&&this.setAttribute("tabindex","0"),this.addEventListener("xr-session-started",this.onXRSessionStarted),this.onSetupDesktop(),!this.getAttribute("src")){const t=globalThis["needle:codegen_files"];Me&&console.log('src is null, trying to load from globalThis["needle:codegen_files"]',t),t&&(Me&&console.log('globalThis["needle:codegen_files"]',t),this.setAttribute("src",t))}Me&&console.log("src",this.getAttribute("src"));const e=this._loadId;setTimeout(()=>{this.isConnected!==!1&&e===this._loadId&&this.onLoad()},1)}disconnectedCallback(){this.removeEventListener("xr-session-started",this.onXRSessionStarted),this._didFullyLoad=!1;const e=this.getAttribute("keep-alive"),t=e==null||e?.length>0&&e!=="true"&&e!=="1";Me&&console.warn('<needle-engine> disconnected, keep-alive: "'+e+'"',typeof e,"Dispose=",t),t?(Me&&console.warn("<needle-engine> dispose"),this._context?.dispose(),this._context=null,this._lastSourceFiles=null,this._loadId+=1):Me&&console.warn("<needle-engine> is not disposed because keep-alive is set")}connectedMoveCallback(){}attributeChangedCallback(e,t,i){switch(Me&&console.log("attributeChangedCallback",e,t,i),e){case"src":Me&&console.warn(`<needle-engine src>
1607
- changed from "`,t,'" to "',i,'"'),this.onLoad();break;case"hash":this._context&&(this._context.hash=i);break;case"loadstart":case"progress":case"loadfinished":typeof i=="string"&&i.length>0&&(Me&&console.log(e+" attribute changed",i),this.registerEventFromAttribute(e,i));break;case"dracoDecoderPath":Me&&console.log("dracoDecoderPath",i),ww(i);break;case"dracoDecoderType":i==="wasm"||i==="js"?(Me&&console.log("dracoDecoderType",i),xw(i)):console.error("Invalid dracoDecoderType",i,"expected js or wasm");break;case"ktx2DecoderPath":Me&&console.log("ktx2DecoderPath",i),Sw(i);break;case"tonemapping":case"tone-mapping":case"tone-mapping-exposure":case"background-blurriness":case"background-color":case"environment-intensity":{this.applyAttributes();break}case"public-key":{i!=Ia&&this.setPublicKey();break}case"version":{i!=bn&&this.setVersion();break}case"focus-rect":{const n=this.getAttribute("focus-rect");if(n&&this._context)if(n===null)this._context.setCameraFocusRect(null);else if(typeof n=="string"&&n.length>0){const s=document.querySelector(n);this._context.setCameraFocusRect(s instanceof HTMLElement?s:null)}else n instanceof HTMLElement&&this._context.setCameraFocusRect(n)}break}}get toneMapping(){return this.getAttribute("tonemapping")||this.getAttribute("tone-mapping")}_loadId=0;_abortController=null;_lastSourceFiles=null;_createContextPromise=null;async onLoad(){if(!this.isConnected)return;if(this._context||(Me&&console.warn("Create new context"),this._context=new z({domElement:this})),!this._context){console.error("Needle Engine: Context not initialized");return}const e=this.getSourceFiles();if(!this.checkIfSourceHasChanged(e,this._lastSourceFiles))return;this._abortController&&(Me&&console.warn("Abort previous loading process"),this._abortController.abort(),this._abortController=null),this._lastSourceFiles=e;const t=++this._loadId;if((e==null||e.length<=0)&&(Me&&console.warn("Clear scene",e),this._context.clear(),t!==this._loadId))return;const i=this.getAttribute("alias");this.classList.add("loading");const n=Io();this.ensureLoadStartIsRegistered();let s=this.dispatchEvent(new CustomEvent("loadstart",{detail:{context:this._context,alias:i},cancelable:!0}));if(n){const f=this.getAttribute("hide-loading-overlay");f!=null&&f!=="0"&&(s=!1)}s===!1&&!n&&(A()||(s=!0),console.warn("Needle Engine: You need a commercial license to override the default loading view. Visit https://needle.tools/pricing"),A()&&ye('You need a <a target="_blank" href="https://needle.tools/pricing">commercial license</a> to override the default loading view. This will not work in production.')),!this._loadingView&&s&&(this._loadingView=new md(this)),s&&(this._didFullyLoad!==!0?this._loadingView?.onLoadingBegin("begin load"):setTimeout(()=>{this._loadingView&&this._loadingProgress01<.3&&this._loadId===t&&this._loadingView.onLoadingBegin("begin load")},300)),Me&&console.warn(`--------------
1607
+ changed from "`,t,'" to "',i,'"'),this.onLoad();break;case"hash":this._context&&(this._context.hash=i);break;case"loadstart":case"progress":case"loadfinished":typeof i=="string"&&i.length>0&&(Me&&console.log(e+" attribute changed",i),this.registerEventFromAttribute("loadfinished",i));break;case"dracoDecoderPath":Me&&console.log("dracoDecoderPath",i),ww(i);break;case"dracoDecoderType":i==="wasm"||i==="js"?(Me&&console.log("dracoDecoderType",i),xw(i)):console.error("Invalid dracoDecoderType",i,"expected js or wasm");break;case"ktx2DecoderPath":Me&&console.log("ktx2DecoderPath",i),Sw(i);break;case"tonemapping":case"tone-mapping":case"tone-mapping-exposure":case"background-blurriness":case"background-color":case"environment-intensity":{this.applyAttributes();break}case"public-key":{i!=Ia&&this.setPublicKey();break}case"version":{i!=bn&&this.setVersion();break}case"focus-rect":{const n=this.getAttribute("focus-rect");if(n&&this._context)if(n===null)this._context.setCameraFocusRect(null);else if(typeof n=="string"&&n.length>0){const s=document.querySelector(n);this._context.setCameraFocusRect(s instanceof HTMLElement?s:null)}else n instanceof HTMLElement&&this._context.setCameraFocusRect(n)}break}}get toneMapping(){return this.getAttribute("tonemapping")||this.getAttribute("tone-mapping")}_loadId=0;_abortController=null;_lastSourceFiles=null;_createContextPromise=null;async onLoad(){if(!this.isConnected)return;if(this._context||(Me&&console.warn("Create new context"),this._context=new z({domElement:this})),!this._context){console.error("Needle Engine: Context not initialized");return}const e=this.getSourceFiles();if(!this.checkIfSourceHasChanged(e,this._lastSourceFiles))return;this._abortController&&(Me&&console.warn("Abort previous loading process"),this._abortController.abort(),this._abortController=null),this._lastSourceFiles=e;const t=++this._loadId;if((e==null||e.length<=0)&&(Me&&console.warn("Clear scene",e),this._context.clear(),t!==this._loadId))return;const i=this.getAttribute("alias");this.classList.add("loading");const n=Io();this.ensureLoadStartIsRegistered();let s=this.dispatchEvent(new CustomEvent("loadstart",{detail:{context:this._context,alias:i},cancelable:!0}));if(n){const f=this.getAttribute("hide-loading-overlay");f!=null&&f!=="0"&&(s=!1)}s===!1&&!n&&(A()||(s=!0),console.warn("Needle Engine: You need a commercial license to override the default loading view. Visit https://needle.tools/pricing"),A()&&ye('You need a <a target="_blank" href="https://needle.tools/pricing">commercial license</a> to override the default loading view. This will not work in production.')),!this._loadingView&&s&&(this._loadingView=new md(this)),s&&(this._didFullyLoad!==!0?this._loadingView?.onLoadingBegin("begin load"):setTimeout(()=>{this._loadingView&&this._loadingProgress01<.3&&this._loadId===t&&this._loadingView.onLoadingBegin("begin load")},300)),Me&&console.warn(`--------------
1608
1608
  Needle Engine: Begin loading `+t+`
1609
1609
  `,e),this.onBeforeBeginLoading();const r=[],a={context:this._context,name:"",progress:{},index:0,count:e.length,totalProgress01:this._loadingProgress01},l=new CustomEvent("progress",{detail:a}),c=new Array,h=new AbortController;this._abortController=h;const d={files:e,abortSignal:h.signal,onLoadingProgress:f=>{if(Me&&console.debug("Loading progress: ",f),h.signal.aborted)return;const g=f.index;!c[g]&&f.name&&(c[g]=iL(f.name)),f.name=c[g],s&&this._loadingView?.onLoadingUpdate(f),a.name=f.name,a.progress=f.progress,this._loadingProgress01=z0(f),a.totalProgress01=this._loadingProgress01,this.dispatchEvent(l)},onLoadingFinished:(f,g,y)=>{Me&&console.debug(`Finished loading "${g}" (aborted? ${h.signal.aborted})`),!h.signal.aborted&&y&&r.push({src:g,file:y})}};nL(this);const p=this.getAttribute("hash");p!=null&&(this._context.hash=p),this._context.alias=i,this._createContextPromise=this._context.create(d);const m=await this._createContextPromise;if(this.applyAttributes(),Me&&console.warn(`--------------
1610
1610
  Needle Engine: finished loading `+t+`
1611
1611
  `,e,`Aborted? ${h.signal.aborted}`),h.signal.aborted){console.log("Loading finished but aborted...");return}if(this._loadId!==t){console.log("Load id changed during loading process");return}this._loadingProgress01=1,s&&m&&this._loadingView?.onLoadingUpdate(1,"creating scene"),this._didFullyLoad=!0,this.classList.remove("loading"),this.classList.add("loading-finished"),this.dispatchEvent(new CustomEvent("loadfinished",{detail:{context:this._context,src:i,loadedFiles:r}}))}applyAttributes(){if(this._context?.renderer){const n=aw(this.toneMapping);n!==void 0&&(this._context.renderer.toneMapping=n);const s=this.getAttribute("tone-mapping-exposure");if(s!=null){const r=parseFloat(s);isNaN(r)||(this._context.renderer.toneMappingExposure=r)}}const e=this.getAttribute("background-blurriness");if(e!=null){const n=parseFloat(e);!isNaN(n)&&this._context&&(this._context.scene.backgroundBlurriness=n)}const t=this.getAttribute("environment-intensity");if(t!=null&&this._context){const n=parseFloat(t);!isNaN(n)&&this._context&&(this._context.scene.environmentIntensity=n)}const i=this.getAttribute("background-color");if(this._context?.renderer)if(typeof i=="string"&&i.length>0){const n=oe.fromColorRepresentation(i);Me&&console.debug("<needle-engine> background-color changed, str:",i,"\u2192",n),this._context.renderer.setClearColor(n,n.alpha),this.context.scene.background=null}else this.getAttribute("background-image")&&this.setAttribute("background-image",this.getAttribute("background-image"))}onXRSessionStarted=()=>{const e=this.context.xrSessionMode;e==="immersive-ar"?this.onEnterAR(this.context.xrSession):e==="immersive-vr"&&this.onEnterVR(this.context.xrSession),this.context.xrSession?.addEventListener("end",()=>{this.dispatchEvent(new CustomEvent("xr-session-ended",{detail:{session:this.context.xrSession,context:this._context,sessionMode:e}})),e==="immersive-ar"?this.onExitAR(this.context.xrSession):e==="immersive-vr"&&this.onExitVR(this.context.xrSession)})};onReady=()=>this._loadingView?.onLoadingFinished();onError=()=>this._loadingView?.setMessage("Loading failed!");getSourceFiles(){const e=this.getAttribute("src");if(!e)return[];let t;Array.isArray(e)?t=e:e.startsWith("[")&&e.endsWith("]")?t=JSON.parse(e):e.includes(",")?t=e.split(","):t=[e];for(let i=t.length-1;i>=0;i--){const n=t[i];(n==="null"||n==="undefined"||n?.length<=0)&&t.splice(i,1)}return t}checkIfSourceHasChanged(e,t){if(e?.length!==t?.length||e==null&&t!==null||e!==null&&t==null)return!0;if(e!==null&&t!==null){for(let i=0;i<e?.length;i++)if(e[i]!==t[i])return!0}return!1}_previouslyRegisteredMap=new Map;ensureLoadStartIsRegistered(){const e=this.getAttribute("loadstart");e&&this.registerEventFromAttribute("loadstart",e)}registerEventFromAttribute(e,t){const i=this._previouslyRegisteredMap.get(e);if(i&&(this._previouslyRegisteredMap.delete(e),this.removeEventListener(e,i)),typeof t=="string"&&t.length>0)try{const n=(0,eval)(t);typeof n=="function"&&(this._previouslyRegisteredMap.set(e,n),this.addEventListener(e,s=>n?.call(globalThis,this._context,s)))}catch(n){console.error("Error registering event "+e+'="'+t+`" failed with the following error:
1612
- `,n)}}setPublicKey(){Ia&&Ia.length>0&&this.setAttribute("public-key",Ia)}setVersion(){bn.length>0&&this.setAttribute("version",bn)}getAROverlayContainer(){return this._overlay_ar.createOverlayContainer(this)}getVROverlayContainer(){for(let e=0;e<this.children.length;e++){const t=this.children[e];if(t.classList.contains("vr"))return t}return null}onEnterAR(e){this.onSetupAR();const t=this.getAROverlayContainer();this._overlay_ar.onBegin(this._context,t,e),this.dispatchEvent(new CustomEvent("enter-ar",{detail:{session:e,context:this._context,htmlContainer:this._overlay_ar?.ARContainer}}))}onExitAR(e){this._overlay_ar.onEnd(this._context),this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-ar",{detail:{session:e,context:this._context,htmlContainer:this._overlay_ar?.ARContainer}}))}onEnterVR(e){this.onSetupVR(),this.dispatchEvent(new CustomEvent("enter-vr",{detail:{session:e,context:this._context}}))}onExitVR(e){this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-vr",{detail:{session:e,context:this._context}}))}onSetupAR(){this.classList.add(id),this.classList.remove(nd);const e=this.getAROverlayContainer();Me&&console.warn("onSetupAR:",e),e&&(e.classList.add(id),e.classList.remove(nd)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,K1))}onSetupVR(){this.classList.remove(id),this.classList.remove(nd),this.foreachHtmlElement(e=>this.setupElementsForMode(e,tS))}onSetupDesktop(){this.classList.remove(id),this.classList.add(nd);const e=this.getAROverlayContainer();e&&(e.classList.remove(id),e.classList.add(nd)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,iS))}setupElementsForMode(e,t,i=null){if(!(e===this._context?.renderer?.domElement||e.id==="VRButton"||e.id==="ARButton"))if(e.classList.contains(t))e.style.visibility="visible",e.style.display==="none"&&(e.style.display="block");else for(const n of eL)e.classList.contains(n)&&(e.style.visibility="hidden",e.style.display="none")}foreachHtmlElement(e){for(let t=0;t<this.children.length;t++){const i=this.children[t];i.style&&e(i)}}onBeforeBeginLoading(){const e=this.getAttribute("dracoDecoderPath");e&&(Me&&console.log("using custom draco decoder path",e),ww(e));const t=this.getAttribute("dracoDecoderType");t&&(Me&&console.log("using custom draco decoder type",t),xw(t));const i=this.getAttribute("ktx2DecoderPath");i&&(Me&&console.log("using custom ktx2 decoder path",i),Sw(i))}}typeof window<"u"&&!window.customElements.get(eS)&&window.customElements.define(eS,N0);function iL(o){if(o.startsWith("blob:"))return"blob";const e=o.split("/");let t=e[e.length-1];const i=t.indexOf("?");i>0&&(t=t.substring(0,i));const n=t.indexOf("=");n>0&&(t=t.substring(n));const s=t.split(".").pop(),r=s?["glb","gltf","usdz","usd","fbx","obj","mtl"].indexOf(s.toLowerCase()):-1;if(s&&r>=0&&(t=t.substring(0,t.length-s.length-1)),t=decodeURIComponent(t),t.length>3){let a="",l=!1;const c=["(",")","[","]","{","}",":",";",",",".","!","?"];for(let h=0;h<t.length;h++){let d=t[h];(d==="_"||d==="-")&&(d=" "),!(d===" "&&a.length<=0||c.includes(d)||(a.length===0&&(d=d.toUpperCase()),l&&d===" "))&&(l&&(d=d.toUpperCase()),l=!1,a+=d,d===" "&&(l=!0))}return A()&&t!==a&&console.debug('Generated display name: "'+t+'" \u2192 "'+a+'"'),a.trim()}return A()&&console.debug("Loading: use default name",t),t}function nL(o){Cu(e=>{const t=o.getAttribute("loading-blur");if(t!==null&&t!=="0"&&e.domElement===o){const i=e.lodsManager.manager?.awaitLoading({frames:5,signal:AbortSignal.timeout(1e4),maxPromisesPerObject:1}).catch(r=>{});let n="20px";t.endsWith("px")&&(n=t);const s=170;if(e.scene.background===null){const r=o,a=e.renderer.domElement,l=a.style.filter,c=a.style.overflow;a.style.filter+=`blur(${n})`,r.style.overflow="hidden",i?.then(()=>{const h=a.animate([{filter:"blur(0px)"}],{duration:s,easing:"ease-in"});h.onfinish=()=>{a.style.filter=l,r.style.overflow=c}})}else{const r=document.createElement("div");e.domElement.prepend(r),r.style.cssText="position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none",r.style.backdropFilter=`blur(${n})`,i?.then(()=>{const a=r.animate([{backdropFilter:"blur(0px)",opacity:0}],{duration:s,easing:"ease-in"});a.onfinish=()=>{r.remove()}})}}},{once:!0})}const oL=Object.freeze(Object.defineProperty({__proto__:null,NeedleEngineWebComponent:N0},Symbol.toStringTag,{value:"Module"}));function sL(){Dn.registerWaitForInteraction(()=>{const o=DC.getContext();o.addEventListener("statechange",()=>{setTimeout(()=>{const e=o.state;(e==="suspended"||e==="interrupted")&&o.resume().then(()=>{console.log("AudioContext resumed successfully")}).catch(t=>{console.log("Failed to resume AudioContext: "+t)})},500)})})}setTimeout(sL,1e3);const $e=v("debugphysics"),V0=v("debugcolliderplacement"),W0=v("debugcollisions"),rL=v("showcolliders"),nm=v("debugraycasts"),_i=Symbol("needle component"),Gt=Symbol("physics body"),nS=Symbol("rigidbody");globalThis.NEEDLE_USE_RAPIER=globalThis.NEEDLE_USE_RAPIER!==void 0?globalThis.NEEDLE_USE_RAPIER:!0,$e&&console.log("Use Rapier",!0,globalThis.NEEDLE_USE_RAPIER),ue.registerCallback(de.ContextCreationStart,o=>{$e&&console.log("Register rapier physics backend"),o.context.physics.engine=new Ql(o.context)});class Ql{debugRenderColliders=!1;debugRenderRaycasts=!1;removeBody(e){if($e&&console.log("REMOVE BODY",e?.name,e[Gt]),!e)return;this.validate();const t=e[Gt];if(e[Gt]=null,t&&this.world){const i=this.objects.findIndex(n=>n===e);if(i>=0){const n=this.bodies[i];if(this.bodies.splice(i,1),this.objects.splice(i,1),n instanceof E.RAPIER_PHYSICS.MODULE.Collider){const s=n;this.world?.removeCollider(s,!0);const r=s.parent();r&&r.numColliders()<=0&&(r[_i]||this.world?.removeRigidBody(r))}else n instanceof E.RAPIER_PHYSICS.MODULE.RigidBody&&(n.numColliders()<=0?this.world?.removeRigidBody(n):A()&&(n.did_log_removing||setTimeout(()=>{n.numColliders()>0&&(n.did_log_removing=!0,console.warn("RapierPhysics: removing rigidbody with colliders from the physics world is not possible right now, please remove the colliders first"))},1)))}}}updateBody(e,t,i){if(this.validate(),!!this.enabled&&!(e.destroyed||!e.gameObject)&&!(!t&&!i))if(e.isCollider===!0)console.warn("TODO: implement updating collider position");else{const n=e,s=n[Gt];s&&this.syncPhysicsBody(n.gameObject,s,t,i)}}updateProperties(e){if(this.validate(),e.isCollider){const t=e,i=t[Gt];i&&(this.internalUpdateColliderProperties(t,i),t.sharedMaterial&&this.updatePhysicsMaterial(t))}else{const t=e,i=this.internal_getRigidbody(t);i&&this.internalUpdateRigidbodyProperties(t,i)}}addForce(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.addForce(t,i):this._isInitialized&&console.warn("Physics Body doesn't exist: can not apply force (does your object with the Rigidbody have a collider?)")}addImpulse(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.applyImpulse(t,i):this._isInitialized&&console.warn("Physics Body doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}getLinearVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.linvel():null}getAngularVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.angvel():null}resetForces(e,t){this.validate(),this.internal_getRigidbody(e)?.resetForces(t)}resetTorques(e,t){this.validate(),this.internal_getRigidbody(e)?.resetTorques(t)}applyImpulse(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.applyImpulse(t,i):this._isInitialized&&console.warn("Rigidbody doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}wakeup(e){this.validate();const t=this.internal_getRigidbody(e);t?t.wakeUp():this._isInitialized&&console.warn("Rigidbody doesn't exist: can not wake up (does your object with the Rigidbody have a collider?)")}isSleeping(e){return this.validate(),this.internal_getRigidbody(e)?.isSleeping()}setAngularVelocity(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.setAngvel(t,i):this._isInitialized&&console.warn("Rigidbody doesn't exist: can not set angular velocity (does your object with the Rigidbody have a collider?)")}setLinearVelocity(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.setLinvel(t,i):this._isInitialized&&console.warn("Rigidbody doesn't exist: can not set linear velocity (does your object with the Rigidbody have a collider?)")}context;_initializePromise;_isInitialized=!1;constructor(e){this.context=e}get isInitialized(){return this._isInitialized}async initialize(){return this._initializePromise||(this._initializePromise=this.internalInitialization()),this._initializePromise}async internalInitialization(){return v("__nophysics")?(console.warn("Physics are disabled"),!1):($e&&console.log("Initialize rapier physics engine"),this._hasCreatedWorld?(console.error("Invalid call to create physics world: world is already created"),!0):(this._hasCreatedWorld=!0,E.RAPIER_PHYSICS.MAYBEMODULE==null&&($e&&console.trace("Loading rapier physics engine"),await(await E.RAPIER_PHYSICS.load()).init()),$e&&console.log("Physics engine initialized, creating world..."),this._world=new E.RAPIER_PHYSICS.MODULE.World(this._gravity),this.rapierRay=new E.RAPIER_PHYSICS.MODULE.Ray({x:0,y:0,z:0},{x:0,y:0,z:1}),this.enabled=!0,this._isInitialized=!0,$e&&console.log("Physics world created"),!0))}validate(){this._isInitialized||$e&&(this._lastWarnTime=this._lastWarnTime??0,Date.now()-this._lastWarnTime>1e3&&(this._lastWarnTime=Date.now(),console.warn("Physics engine is not initialized")))}rapierRay;raycastVectorsBuffer=new Oi(()=>new b,10);raycast(e,t,i){if(!this._isInitialized)return console.log("Physics engine is not initialized"),null;let n=i?.maxDistance,s=i?.solid;n===void 0&&(n=1/0),s===void 0&&(s=!0);const r=this.getPhysicsRay(this.rapierRay,e,t);if(!r)return null;(this.debugRenderRaycasts||nm)&&B.DrawRay(r.origin,r.dir,255,1);const a=this.world?.castRay(r,n,s,i?.queryFilterFlags,i?.filterGroups,void 0,void 0,l=>{const c=l[_i];return i?.filterPredicate?i.filterPredicate(c):i?.useIgnoreRaycastLayer!==!1?!c?.gameObject.layers.isEnabled(2):!0});if(a){const l=r.pointAt(a.timeOfImpact),c=this.raycastVectorsBuffer.get();return c.set(l.x,l.y,l.z),{point:c,collider:a.collider[_i]}}return null}raycastAndGetNormal(e,t,i){if(!this._isInitialized)return null;let n=i?.maxDistance,s=i?.solid;n===void 0&&(n=1/0),s===void 0&&(s=!0);const r=this.getPhysicsRay(this.rapierRay,e,t);if(!r)return null;(this.debugRenderRaycasts||nm)&&B.DrawRay(r.origin,r.dir,255,1);const a=this.world?.castRayAndGetNormal(r,n,s,i?.queryFilterFlags,i?.filterGroups,void 0,void 0,l=>{const c=l[_i];return i?.filterPredicate?i.filterPredicate(c):i?.useIgnoreRaycastLayer!==!1?!c?.gameObject.layers.isEnabled(2):!0});if(a){const l=r.pointAt(a.timeOfImpact),c=a.normal,h=this.raycastVectorsBuffer.get(),d=this.raycastVectorsBuffer.get();return h.set(l.x,l.y,l.z),d.set(c.x,c.y,c.z),{point:h,normal:d,collider:a.collider[_i]}}return null}getPhysicsRay(e,t,i){const n=this.context?.mainCamera;if(t===void 0){const a=this.context?.input.getPointerPosition(0);if(a)t=a;else return null}if(t.z===void 0){if(!n)return console.error("Can not perform raycast from 2d point - no main camera found"),null;const a=this.raycastVectorsBuffer.get();a.x=t.x,a.y=t.y,a.z=0,(a.x>1||a.y>1||a.y<-1||a.x<-1)&&($e&&console.warn("Converting screenspace to raycast space",a),this.context?.input.convertScreenspaceToRaycastSpace(a)),a.unproject(n),t=a}const s=t;e.origin.x=s.x,e.origin.y=s.y,e.origin.z=s.z;const r=this.raycastVectorsBuffer.get();if(i)r.set(i.x,i.y,i.z);else{if(!n)return console.error("Can not perform raycast - no camera found"),null;r.set(e.origin.x,e.origin.y,e.origin.z);const a=J(n);r.sub(a)}return r.normalize(),e.dir.x=r.x,e.dir.y=r.y,e.dir.z=r.z,e}rapierSphere=null;rapierBox=null;rapierColliderArray=[];rapierIdentityRotation={x:0,y:0,z:0,w:1};rapierForwardVector={x:0,y:0,z:1};sphereOverlap(e,t){return this.rapierSphere??=new E.RAPIER_PHYSICS.MODULE.Ball(t),this.rapierSphere.radius=t,(this.debugRenderRaycasts||nm)&&B.DrawWireSphere(e,t,3359999,1),this.shapeOverlap(e,this.rapierIdentityRotation,this.rapierSphere)}boxOverlap(e,t,i=null){return i===null&&(i=this.rapierIdentityRotation),this.rapierBox??=new E.RAPIER_PHYSICS.MODULE.Cuboid(1,1,1),this.rapierBox.halfExtents.x=t.x*.5,this.rapierBox.halfExtents.y=t.y*.5,this.rapierBox.halfExtents.z=t.z*.5,(this.debugRenderRaycasts||nm)&&B.DrawWireBox(e,t,3359999,1,!0,i),this.shapeOverlap(e,i,this.rapierBox)}shapeOverlap(e,t,i){return this.rapierColliderArray.length=0,this._isInitialized?this.world?(this.world.intersectionsWithShape(e,t,i,n=>{const s=n[_i],r=new Gw(s.gameObject,s);return this.rapierColliderArray.push(r),!0},void 0,void 0,void 0,void 0,n=>n.isSensor()?!1:n[_i].gameObject.layers.isEnabled(2)==!1),this.rapierColliderArray):this.rapierColliderArray:this.rapierColliderArray}enabled=!1;get world(){return this._world}_tempPosition=new b;_tempQuaternion=new U;_tempScale=new b;_tempMatrix=new K;static _didLoadPhysicsEngine=!1;_isUpdatingPhysicsWorld=!1;get isUpdating(){return this._isUpdatingPhysicsWorld}_world;_hasCreatedWorld=!1;eventQueue;collisionHandler;objects=[];bodies=[];_meshCache=new Map;_gravity={x:0,y:-9.81,z:0};get gravity(){return this.world?.gravity??this._gravity}set gravity(e){this.world?this.world.gravity=e:this._gravity=e}clearCaches(){this._meshCache.clear(),this.eventQueue?.raw&&this.eventQueue?.free(),this.world?.bodies&&this.world?.free()}async addBoxCollider(e,t){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){$e&&console.warn("Physics are disabled");return}const i=e.gameObject,n=He(i,this._tempPosition).multiply(t);n.multiplyScalar(.5),n.x<0&&(n.x=Math.abs(n.x)),n.y<0&&(n.y=Math.abs(n.y)),n.z<0&&(n.z=Math.abs(n.z));const s=1e-7;n.x<s&&(n.x=s),n.y<s&&(n.y=s),n.z<s&&(n.z=s);const r=E.RAPIER_PHYSICS.MODULE.ColliderDesc.cuboid(n.x,n.y,n.z);this.createCollider(e,r)}async addSphereCollider(e){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){$e&&console.warn("Physics are disabled");return}const t=E.RAPIER_PHYSICS.MODULE.ColliderDesc.ball(.5);this.createCollider(e,t),this.updateProperties(e)}async addCapsuleCollider(e,t,i){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){$e&&console.warn("Physics are disabled");return}const n=e.gameObject.worldScale;n.x=Math.abs(n.x),n.y=Math.abs(n.y);const s=i*n.x;t=Math.max(t,s);const r=L.clamp(t*.5*n.y-i*n.x,0,Number.MAX_SAFE_INTEGER),a=E.RAPIER_PHYSICS.MODULE.ColliderDesc.capsule(r,s);this.createCollider(e,a)}async addMeshCollider(e,t,i,n){let s=t.geometry;if(!s){$e&&console.warn("Missing mesh geometry",t.name);return}s.index?.array?.length||(console.warn(`Your MeshCollider is missing vertices or indices in the assined mesh "${t.name}". Consider providing an indexed geometry.`),s=sP(s));let r=null;const a=s.getAttribute("position");if(a instanceof nb){const d=a.count;r=new Float32Array(d*3);for(let p=0;p<d;p++){const m=a.getX(p),f=a.getY(p),g=a.getZ(p);r[p*3]=m,r[p*3+1]=f,r[p*3+2]=g}}else r=a.array;if(await this.initialize(),!this.enabled){$e&&console.warn("Physics are disabled");return}if(!e.activeAndEnabled)return;const l=s.index?.array,c=e.gameObject.worldScale.clone();if(n&&c.multiply(n),Math.abs(c.x-1)>1e-4||Math.abs(c.y-1)>1e-4||Math.abs(c.z-1)>1e-4){const d=`${s.uuid}_${c.x}_${c.y}_${c.z}_${i}`;if(this._meshCache.has(d))$e&&console.warn("Use cached mesh collider"),r=this._meshCache.get(d);else{($e||A())&&console.debug(`[Performance] Your MeshCollider "${e.name}" is scaled: consider applying the scale to the collider mesh instead (${c.x}, ${c.y}, ${c.z})`);const p=new Float32Array(r.length);for(let m=0;m<r.length;m+=3)p[m]=r[m]*c.x,p[m+1]=r[m+1]*c.y,p[m+2]=r[m+2]*c.z;r=p,this._meshCache.set(d,p)}}const h=i?E.RAPIER_PHYSICS.MODULE.ColliderDesc.convexHull(r):E.RAPIER_PHYSICS.MODULE.ColliderDesc.trimesh(r,l);h&&this.createCollider(e,h)}updatePhysicsMaterial(e){if(!e)return;const t=e.sharedMaterial,i=e[Gt];if(i&&t){if(t.bounciness!==void 0&&i.setRestitution(t.bounciness),t.bounceCombine!==void 0)switch(t.bounceCombine){case bt.Average:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(t.dynamicFriction!==void 0&&i.setFriction(t.dynamicFriction),t.frictionCombine!==void 0)switch(t.frictionCombine){case bt.Average:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}}getBody(e){return e?e[Gt]:null}getComponent(e){return e?e[_i]:null}createCollider(e,t){if(!this.world)throw new Error("Physics world not initialized");const i=this._tempMatrix;let n;e.attachedRigidbody?n=this.getRigidbody(e,this._tempMatrix):($e&&console.log("Create collider without rigidbody",e.name),i.makeRotationFromQuaternion(be(e.gameObject)),i.setPosition(J(e.gameObject))),i.decompose(this._tempPosition,this._tempQuaternion,this._tempScale),this.tryApplyCenter(e,this._tempPosition),t.setTranslation(this._tempPosition.x,this._tempPosition.y,this._tempPosition.z),t.setRotation(this._tempQuaternion),t.setSensor(e.isTrigger);const s=e.sharedMaterial;if(s){if(s.bounciness!==void 0&&t.setRestitution(s.bounciness),s.bounceCombine!==void 0)switch(s.bounceCombine){case bt.Average:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(s.dynamicFriction!==void 0&&t.setFriction(s.dynamicFriction),s.frictionCombine!==void 0)switch(s.frictionCombine){case bt.Average:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}e.attachedRigidbody?.autoMass===!1&&(t.setDensity(1e-6),t.setMass(1e-6));try{const r=this.world.createCollider(t,n);return r[_i]=e,e[Gt]=r,r.setActiveEvents(E.RAPIER_PHYSICS.MODULE.ActiveEvents.COLLISION_EVENTS),r.setActiveCollisionTypes(E.RAPIER_PHYSICS.MODULE.ActiveCollisionTypes.ALL),this.objects.push(e),this.bodies.push(r),this.updateColliderCollisionGroups(e),$e&&console.log("Created collider",e.name,r),r}catch(r){return console.error('Error creating collider "'+e.name+`"
1612
+ `,n)}}setPublicKey(){Ia&&Ia.length>0&&this.setAttribute("public-key",Ia)}setVersion(){bn.length>0&&this.setAttribute("version",bn)}getAROverlayContainer(){return this._overlay_ar.createOverlayContainer(this)}getVROverlayContainer(){for(let e=0;e<this.children.length;e++){const t=this.children[e];if(t.classList.contains("vr"))return t}return null}onEnterAR(e){this.onSetupAR();const t=this.getAROverlayContainer();this._overlay_ar.onBegin(this._context,t,e),this.dispatchEvent(new CustomEvent("enter-ar",{detail:{session:e,context:this._context,htmlContainer:this._overlay_ar?.ARContainer}}))}onExitAR(e){this._overlay_ar.onEnd(this._context),this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-ar",{detail:{session:e,context:this._context,htmlContainer:this._overlay_ar?.ARContainer}}))}onEnterVR(e){this.onSetupVR(),this.dispatchEvent(new CustomEvent("enter-vr",{detail:{session:e,context:this._context}}))}onExitVR(e){this.onSetupDesktop(),this.dispatchEvent(new CustomEvent("exit-vr",{detail:{session:e,context:this._context}}))}onSetupAR(){this.classList.add(id),this.classList.remove(nd);const e=this.getAROverlayContainer();Me&&console.warn("onSetupAR:",e),e&&(e.classList.add(id),e.classList.remove(nd)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,K1))}onSetupVR(){this.classList.remove(id),this.classList.remove(nd),this.foreachHtmlElement(e=>this.setupElementsForMode(e,tS))}onSetupDesktop(){this.classList.remove(id),this.classList.add(nd);const e=this.getAROverlayContainer();e&&(e.classList.remove(id),e.classList.add(nd)),this.foreachHtmlElement(t=>this.setupElementsForMode(t,iS))}setupElementsForMode(e,t,i=null){if(!(e===this._context?.renderer?.domElement||e.id==="VRButton"||e.id==="ARButton"))if(e.classList.contains(t))e.style.visibility="visible",e.style.display==="none"&&(e.style.display="block");else for(const n of eL)e.classList.contains(n)&&(e.style.visibility="hidden",e.style.display="none")}foreachHtmlElement(e){for(let t=0;t<this.children.length;t++){const i=this.children[t];i.style&&e(i)}}onBeforeBeginLoading(){const e=this.getAttribute("dracoDecoderPath");e&&(Me&&console.log("using custom draco decoder path",e),ww(e));const t=this.getAttribute("dracoDecoderType");t&&(Me&&console.log("using custom draco decoder type",t),xw(t));const i=this.getAttribute("ktx2DecoderPath");i&&(Me&&console.log("using custom ktx2 decoder path",i),Sw(i))}setAttribute(e,t){super.setAttribute(e,t)}getAttribute(e){return super.getAttribute(e)}addEventListener(e,t,i){return super.addEventListener(e,t,i)}}typeof window<"u"&&!window.customElements.get(eS)&&window.customElements.define(eS,N0);function iL(o){if(o.startsWith("blob:"))return"blob";const e=o.split("/");let t=e[e.length-1];const i=t.indexOf("?");i>0&&(t=t.substring(0,i));const n=t.indexOf("=");n>0&&(t=t.substring(n));const s=t.split(".").pop(),r=s?["glb","gltf","usdz","usd","fbx","obj","mtl"].indexOf(s.toLowerCase()):-1;if(s&&r>=0&&(t=t.substring(0,t.length-s.length-1)),t=decodeURIComponent(t),t.length>3){let a="",l=!1;const c=["(",")","[","]","{","}",":",";",",",".","!","?"];for(let h=0;h<t.length;h++){let d=t[h];(d==="_"||d==="-")&&(d=" "),!(d===" "&&a.length<=0||c.includes(d)||(a.length===0&&(d=d.toUpperCase()),l&&d===" "))&&(l&&(d=d.toUpperCase()),l=!1,a+=d,d===" "&&(l=!0))}return A()&&t!==a&&console.debug('Generated display name: "'+t+'" \u2192 "'+a+'"'),a.trim()}return A()&&console.debug("Loading: use default name",t),t}function nL(o){Cu(e=>{const t=o.getAttribute("loading-blur");if(t!==null&&t!=="0"&&e.domElement===o){const i=e.lodsManager.manager?.awaitLoading({frames:5,signal:AbortSignal.timeout(1e4),maxPromisesPerObject:1}).catch(r=>{});let n="20px";t.endsWith("px")&&(n=t);const s=170;if(e.scene.background===null){const r=o,a=e.renderer.domElement,l=a.style.filter,c=a.style.overflow;a.style.filter+=`blur(${n})`,r.style.overflow="hidden",i?.then(()=>{const h=a.animate([{filter:"blur(0px)"}],{duration:s,easing:"ease-in"});h.onfinish=()=>{a.style.filter=l,r.style.overflow=c}})}else{const r=document.createElement("div");e.domElement.prepend(r),r.style.cssText="position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 10; pointer-events: none",r.style.backdropFilter=`blur(${n})`,i?.then(()=>{const a=r.animate([{backdropFilter:"blur(0px)",opacity:0}],{duration:s,easing:"ease-in"});a.onfinish=()=>{r.remove()}})}}},{once:!0})}const oL=Object.freeze(Object.defineProperty({__proto__:null,NeedleEngineWebComponent:N0},Symbol.toStringTag,{value:"Module"}));function sL(){Dn.registerWaitForInteraction(()=>{const o=DC.getContext();o.addEventListener("statechange",()=>{setTimeout(()=>{const e=o.state;(e==="suspended"||e==="interrupted")&&o.resume().then(()=>{console.log("AudioContext resumed successfully")}).catch(t=>{console.log("Failed to resume AudioContext: "+t)})},500)})})}setTimeout(sL,1e3);const $e=v("debugphysics"),V0=v("debugcolliderplacement"),W0=v("debugcollisions"),rL=v("showcolliders"),nm=v("debugraycasts"),_i=Symbol("needle component"),Gt=Symbol("physics body"),nS=Symbol("rigidbody");globalThis.NEEDLE_USE_RAPIER=globalThis.NEEDLE_USE_RAPIER!==void 0?globalThis.NEEDLE_USE_RAPIER:!0,$e&&console.log("Use Rapier",!0,globalThis.NEEDLE_USE_RAPIER),ue.registerCallback(de.ContextCreationStart,o=>{$e&&console.log("Register rapier physics backend"),o.context.physics.engine=new Ql(o.context)});class Ql{debugRenderColliders=!1;debugRenderRaycasts=!1;removeBody(e){if($e&&console.log("REMOVE BODY",e?.name,e[Gt]),!e)return;this.validate();const t=e[Gt];if(e[Gt]=null,t&&this.world){const i=this.objects.findIndex(n=>n===e);if(i>=0){const n=this.bodies[i];if(this.bodies.splice(i,1),this.objects.splice(i,1),n instanceof E.RAPIER_PHYSICS.MODULE.Collider){const s=n;this.world?.removeCollider(s,!0);const r=s.parent();r&&r.numColliders()<=0&&(r[_i]||this.world?.removeRigidBody(r))}else n instanceof E.RAPIER_PHYSICS.MODULE.RigidBody&&(n.numColliders()<=0?this.world?.removeRigidBody(n):A()&&(n.did_log_removing||setTimeout(()=>{n.numColliders()>0&&(n.did_log_removing=!0,console.warn("RapierPhysics: removing rigidbody with colliders from the physics world is not possible right now, please remove the colliders first"))},1)))}}}updateBody(e,t,i){if(this.validate(),!!this.enabled&&!(e.destroyed||!e.gameObject)&&!(!t&&!i))if(e.isCollider===!0)console.warn("TODO: implement updating collider position");else{const n=e,s=n[Gt];s&&this.syncPhysicsBody(n.gameObject,s,t,i)}}updateProperties(e){if(this.validate(),e.isCollider){const t=e,i=t[Gt];i&&(this.internalUpdateColliderProperties(t,i),t.sharedMaterial&&this.updatePhysicsMaterial(t))}else{const t=e,i=this.internal_getRigidbody(t);i&&this.internalUpdateRigidbodyProperties(t,i)}}addForce(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.addForce(t,i):this._isInitialized&&console.warn("Physics Body doesn't exist: can not apply force (does your object with the Rigidbody have a collider?)")}addImpulse(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.applyImpulse(t,i):this._isInitialized&&console.warn("Physics Body doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}getLinearVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.linvel():null}getAngularVelocity(e){this.validate();const t=this.internal_getRigidbody(e);return t?t.angvel():null}resetForces(e,t){this.validate(),this.internal_getRigidbody(e)?.resetForces(t)}resetTorques(e,t){this.validate(),this.internal_getRigidbody(e)?.resetTorques(t)}applyImpulse(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.applyImpulse(t,i):this._isInitialized&&console.warn("Rigidbody doesn't exist: can not apply impulse (does your object with the Rigidbody have a collider?)")}wakeup(e){this.validate();const t=this.internal_getRigidbody(e);t?t.wakeUp():this._isInitialized&&console.warn("Rigidbody doesn't exist: can not wake up (does your object with the Rigidbody have a collider?)")}isSleeping(e){return this.validate(),this.internal_getRigidbody(e)?.isSleeping()}setAngularVelocity(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.setAngvel(t,i):this._isInitialized&&console.warn("Rigidbody doesn't exist: can not set angular velocity (does your object with the Rigidbody have a collider?)")}setLinearVelocity(e,t,i){this.validate();const n=this.internal_getRigidbody(e);n?n.setLinvel(t,i):this._isInitialized&&console.warn("Rigidbody doesn't exist: can not set linear velocity (does your object with the Rigidbody have a collider?)")}context;_initializePromise;_isInitialized=!1;constructor(e){this.context=e}get isInitialized(){return this._isInitialized}async initialize(){return this._initializePromise||(this._initializePromise=this.internalInitialization()),this._initializePromise}async internalInitialization(){return v("__nophysics")?(console.warn("Physics are disabled"),!1):($e&&console.log("Initialize rapier physics engine"),this._hasCreatedWorld?(console.error("Invalid call to create physics world: world is already created"),!0):(this._hasCreatedWorld=!0,E.RAPIER_PHYSICS.MAYBEMODULE==null&&($e&&console.trace("Loading rapier physics engine"),await(await E.RAPIER_PHYSICS.load()).init()),$e&&console.log("Physics engine initialized, creating world..."),this._world=new E.RAPIER_PHYSICS.MODULE.World(this._gravity),this.rapierRay=new E.RAPIER_PHYSICS.MODULE.Ray({x:0,y:0,z:0},{x:0,y:0,z:1}),this.enabled=!0,this._isInitialized=!0,$e&&console.log("Physics world created"),!0))}validate(){this._isInitialized||$e&&(this._lastWarnTime=this._lastWarnTime??0,Date.now()-this._lastWarnTime>1e3&&(this._lastWarnTime=Date.now(),console.warn("Physics engine is not initialized")))}rapierRay;raycastVectorsBuffer=new Oi(()=>new b,10);raycast(e,t,i){if(!this._isInitialized)return console.log("Physics engine is not initialized"),null;let n=i?.maxDistance,s=i?.solid;n===void 0&&(n=1/0),s===void 0&&(s=!0);const r=this.getPhysicsRay(this.rapierRay,e,t);if(!r)return null;(this.debugRenderRaycasts||nm)&&B.DrawRay(r.origin,r.dir,255,1);const a=this.world?.castRay(r,n,s,i?.queryFilterFlags,i?.filterGroups,void 0,void 0,l=>{const c=l[_i];return i?.filterPredicate?i.filterPredicate(c):i?.useIgnoreRaycastLayer!==!1?!c?.gameObject.layers.isEnabled(2):!0});if(a){const l=r.pointAt(a.timeOfImpact),c=this.raycastVectorsBuffer.get();return c.set(l.x,l.y,l.z),{point:c,collider:a.collider[_i]}}return null}raycastAndGetNormal(e,t,i){if(!this._isInitialized)return null;let n=i?.maxDistance,s=i?.solid;n===void 0&&(n=1/0),s===void 0&&(s=!0);const r=this.getPhysicsRay(this.rapierRay,e,t);if(!r)return null;(this.debugRenderRaycasts||nm)&&B.DrawRay(r.origin,r.dir,255,1);const a=this.world?.castRayAndGetNormal(r,n,s,i?.queryFilterFlags,i?.filterGroups,void 0,void 0,l=>{const c=l[_i];return i?.filterPredicate?i.filterPredicate(c):i?.useIgnoreRaycastLayer!==!1?!c?.gameObject.layers.isEnabled(2):!0});if(a){const l=r.pointAt(a.timeOfImpact),c=a.normal,h=this.raycastVectorsBuffer.get(),d=this.raycastVectorsBuffer.get();return h.set(l.x,l.y,l.z),d.set(c.x,c.y,c.z),{point:h,normal:d,collider:a.collider[_i]}}return null}getPhysicsRay(e,t,i){const n=this.context?.mainCamera;if(t===void 0){const a=this.context?.input.getPointerPosition(0);if(a)t=a;else return null}if(t.z===void 0){if(!n)return console.error("Can not perform raycast from 2d point - no main camera found"),null;const a=this.raycastVectorsBuffer.get();a.x=t.x,a.y=t.y,a.z=0,(a.x>1||a.y>1||a.y<-1||a.x<-1)&&($e&&console.warn("Converting screenspace to raycast space",a),this.context?.input.convertScreenspaceToRaycastSpace(a)),a.unproject(n),t=a}const s=t;e.origin.x=s.x,e.origin.y=s.y,e.origin.z=s.z;const r=this.raycastVectorsBuffer.get();if(i)r.set(i.x,i.y,i.z);else{if(!n)return console.error("Can not perform raycast - no camera found"),null;r.set(e.origin.x,e.origin.y,e.origin.z);const a=J(n);r.sub(a)}return r.normalize(),e.dir.x=r.x,e.dir.y=r.y,e.dir.z=r.z,e}rapierSphere=null;rapierBox=null;rapierColliderArray=[];rapierIdentityRotation={x:0,y:0,z:0,w:1};rapierForwardVector={x:0,y:0,z:1};sphereOverlap(e,t){return this.rapierSphere??=new E.RAPIER_PHYSICS.MODULE.Ball(t),this.rapierSphere.radius=t,(this.debugRenderRaycasts||nm)&&B.DrawWireSphere(e,t,3359999,1),this.shapeOverlap(e,this.rapierIdentityRotation,this.rapierSphere)}boxOverlap(e,t,i=null){return i===null&&(i=this.rapierIdentityRotation),this.rapierBox??=new E.RAPIER_PHYSICS.MODULE.Cuboid(1,1,1),this.rapierBox.halfExtents.x=t.x*.5,this.rapierBox.halfExtents.y=t.y*.5,this.rapierBox.halfExtents.z=t.z*.5,(this.debugRenderRaycasts||nm)&&B.DrawWireBox(e,t,3359999,1,!0,i),this.shapeOverlap(e,i,this.rapierBox)}shapeOverlap(e,t,i){return this.rapierColliderArray.length=0,this._isInitialized?this.world?(this.world.intersectionsWithShape(e,t,i,n=>{const s=n[_i],r=new Gw(s.gameObject,s);return this.rapierColliderArray.push(r),!0},void 0,void 0,void 0,void 0,n=>n.isSensor()?!1:n[_i].gameObject.layers.isEnabled(2)==!1),this.rapierColliderArray):this.rapierColliderArray:this.rapierColliderArray}enabled=!1;get world(){return this._world}_tempPosition=new b;_tempQuaternion=new U;_tempScale=new b;_tempMatrix=new K;static _didLoadPhysicsEngine=!1;_isUpdatingPhysicsWorld=!1;get isUpdating(){return this._isUpdatingPhysicsWorld}_world;_hasCreatedWorld=!1;eventQueue;collisionHandler;objects=[];bodies=[];_meshCache=new Map;_gravity={x:0,y:-9.81,z:0};get gravity(){return this.world?.gravity??this._gravity}set gravity(e){this.world?this.world.gravity=e:this._gravity=e}clearCaches(){this._meshCache.clear(),this.eventQueue?.raw&&this.eventQueue?.free(),this.world?.bodies&&this.world?.free()}async addBoxCollider(e,t){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){$e&&console.warn("Physics are disabled");return}const i=e.gameObject,n=He(i,this._tempPosition).multiply(t);n.multiplyScalar(.5),n.x<0&&(n.x=Math.abs(n.x)),n.y<0&&(n.y=Math.abs(n.y)),n.z<0&&(n.z=Math.abs(n.z));const s=1e-7;n.x<s&&(n.x=s),n.y<s&&(n.y=s),n.z<s&&(n.z=s);const r=E.RAPIER_PHYSICS.MODULE.ColliderDesc.cuboid(n.x,n.y,n.z);this.createCollider(e,r)}async addSphereCollider(e){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){$e&&console.warn("Physics are disabled");return}const t=E.RAPIER_PHYSICS.MODULE.ColliderDesc.ball(.5);this.createCollider(e,t),this.updateProperties(e)}async addCapsuleCollider(e,t,i){if(this._isInitialized||await this.initialize(),!e.activeAndEnabled)return;if(!this.enabled){$e&&console.warn("Physics are disabled");return}const n=e.gameObject.worldScale;n.x=Math.abs(n.x),n.y=Math.abs(n.y);const s=i*n.x;t=Math.max(t,s);const r=L.clamp(t*.5*n.y-i*n.x,0,Number.MAX_SAFE_INTEGER),a=E.RAPIER_PHYSICS.MODULE.ColliderDesc.capsule(r,s);this.createCollider(e,a)}async addMeshCollider(e,t,i,n){let s=t.geometry;if(!s){$e&&console.warn("Missing mesh geometry",t.name);return}s.index?.array?.length||(console.warn(`Your MeshCollider is missing vertices or indices in the assined mesh "${t.name}". Consider providing an indexed geometry.`),s=sP(s));let r=null;const a=s.getAttribute("position");if(a instanceof nb){const d=a.count;r=new Float32Array(d*3);for(let p=0;p<d;p++){const m=a.getX(p),f=a.getY(p),g=a.getZ(p);r[p*3]=m,r[p*3+1]=f,r[p*3+2]=g}}else r=a.array;if(await this.initialize(),!this.enabled){$e&&console.warn("Physics are disabled");return}if(!e.activeAndEnabled)return;const l=s.index?.array,c=e.gameObject.worldScale.clone();if(n&&c.multiply(n),Math.abs(c.x-1)>1e-4||Math.abs(c.y-1)>1e-4||Math.abs(c.z-1)>1e-4){const d=`${s.uuid}_${c.x}_${c.y}_${c.z}_${i}`;if(this._meshCache.has(d))$e&&console.warn("Use cached mesh collider"),r=this._meshCache.get(d);else{($e||A())&&console.debug(`[Performance] Your MeshCollider "${e.name}" is scaled: consider applying the scale to the collider mesh instead (${c.x}, ${c.y}, ${c.z})`);const p=new Float32Array(r.length);for(let m=0;m<r.length;m+=3)p[m]=r[m]*c.x,p[m+1]=r[m+1]*c.y,p[m+2]=r[m+2]*c.z;r=p,this._meshCache.set(d,p)}}const h=i?E.RAPIER_PHYSICS.MODULE.ColliderDesc.convexHull(r):E.RAPIER_PHYSICS.MODULE.ColliderDesc.trimesh(r,l);h&&this.createCollider(e,h)}updatePhysicsMaterial(e){if(!e)return;const t=e.sharedMaterial,i=e[Gt];if(i&&t){if(t.bounciness!==void 0&&i.setRestitution(t.bounciness),t.bounceCombine!==void 0)switch(t.bounceCombine){case bt.Average:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:i.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(t.dynamicFriction!==void 0&&i.setFriction(t.dynamicFriction),t.frictionCombine!==void 0)switch(t.frictionCombine){case bt.Average:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:i.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}}getBody(e){return e?e[Gt]:null}getComponent(e){return e?e[_i]:null}createCollider(e,t){if(!this.world)throw new Error("Physics world not initialized");const i=this._tempMatrix;let n;e.attachedRigidbody?n=this.getRigidbody(e,this._tempMatrix):($e&&console.log("Create collider without rigidbody",e.name),i.makeRotationFromQuaternion(be(e.gameObject)),i.setPosition(J(e.gameObject))),i.decompose(this._tempPosition,this._tempQuaternion,this._tempScale),this.tryApplyCenter(e,this._tempPosition),t.setTranslation(this._tempPosition.x,this._tempPosition.y,this._tempPosition.z),t.setRotation(this._tempQuaternion),t.setSensor(e.isTrigger);const s=e.sharedMaterial;if(s){if(s.bounciness!==void 0&&t.setRestitution(s.bounciness),s.bounceCombine!==void 0)switch(s.bounceCombine){case bt.Average:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:t.setRestitutionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}if(s.dynamicFriction!==void 0&&t.setFriction(s.dynamicFriction),s.frictionCombine!==void 0)switch(s.frictionCombine){case bt.Average:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Average);break;case bt.Maximum:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Max);break;case bt.Minimum:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Min);break;case bt.Multiply:t.setFrictionCombineRule(E.RAPIER_PHYSICS.MODULE.CoefficientCombineRule.Multiply);break}}e.attachedRigidbody?.autoMass===!1&&(t.setDensity(1e-6),t.setMass(1e-6));try{const r=this.world.createCollider(t,n);return r[_i]=e,e[Gt]=r,r.setActiveEvents(E.RAPIER_PHYSICS.MODULE.ActiveEvents.COLLISION_EVENTS),r.setActiveCollisionTypes(E.RAPIER_PHYSICS.MODULE.ActiveCollisionTypes.ALL),this.objects.push(e),this.bodies.push(r),this.updateColliderCollisionGroups(e),$e&&console.log("Created collider",e.name,r),r}catch(r){return console.error('Error creating collider "'+e.name+`"
1613
1613
  Error:`,r),null}}updateColliderCollisionGroups(e){const t=e[Gt],i=e.membership;let n=0;if(i==null)n=65535;else for(let a=0;a<i.length;a++){const l=i[a];l>31?console.error(`Rapier only supports 32 layers, layer ${l} is not supported`):n|=1<<Math.floor(l)}const s=e.filter;let r=0;if(s==null)r=65535;else for(let a=0;a<s.length;a++){const l=s[a];l>31?console.error(`Rapier only supports 32 layers, layer ${l} is not supported`):r|=1<<Math.floor(l)}t.setCollisionGroups(n<<16|r)}getRigidbody(e,t){if(!this.world)throw new Error("Physics world not initialized");let i=null;if(e.attachedRigidbody){const n=e.attachedRigidbody;if(i=n[Gt],!i){const s=n.isKinematic&&!V0;$e&&console.log("Create rigidbody",s);const r=s?E.RAPIER_PHYSICS.MODULE.RigidBodyDesc.kinematicPositionBased():E.RAPIER_PHYSICS.MODULE.RigidBodyDesc.dynamic(),a=J(e.attachedRigidbody.gameObject);r.setTranslation(a.x,a.y,a.z),r.setRotation(be(e.attachedRigidbody.gameObject)),r.centerOfMass=new E.RAPIER_PHYSICS.MODULE.Vector3(n.centerOfMass.x,n.centerOfMass.y,n.centerOfMass.z),i=this.world.createRigidBody(r),this.bodies.push(i),this.objects.push(n)}i[_i]=n,n[Gt]=i,this.internalUpdateRigidbodyProperties(n,i),this.getRigidbodyRelativeMatrix(e.gameObject,n.gameObject,t),e[nS]=i}else{const n=E.RAPIER_PHYSICS.MODULE.RigidBodyDesc.kinematicPositionBased(),s=J(e.gameObject);n.setTranslation(s.x,s.y,s.z),n.setRotation(be(e.gameObject)),i=this.world.createRigidBody(n),t.identity(),i[_i]=null}return i}internal_getRigidbody(e){return e.isCollider===!0?e[nS]:e[Gt]}internalUpdateColliderProperties(e,t){const i=t.shape;let n=!1;switch(i.type){case E.RAPIER_PHYSICS.MODULE.ShapeType.Ball:{const p=i,m=e,f=e.gameObject,g=He(f,this._tempPosition),y=Math.abs(m.radius*g.x);n=p.radius!==y,p.radius=y,n&&t.setShape(p);break}case E.RAPIER_PHYSICS.MODULE.ShapeType.Cuboid:const s=i,r=e,a=e.gameObject,l=He(a,this._tempPosition),c=Math.abs(r.size.x*.5*l.x),h=Math.abs(r.size.y*.5*l.y),d=Math.abs(r.size.z*.5*l.z);n=s.halfExtents.x!==c||s.halfExtents.y!==h||s.halfExtents.z!==d,s.halfExtents.x=c,s.halfExtents.y=h,s.halfExtents.z=d,n&&t.setShape(s);break}if(n){const s=e.attachedRigidbody;s?.autoMass&&this.getBody(s)?.recomputeMassPropertiesFromColliders()}this.updateColliderCollisionGroups(e),e.isTrigger!==t.isSensor()&&t.setSensor(e.isTrigger)}internalUpdateRigidbodyProperties(e,t){if(t.enableCcd(e.collisionDetectionMode!==Ru.Discrete),t.setLinearDamping(e.drag),t.setAngularDamping(e.angularDrag),t.setGravityScale(e.useGravity?e.gravityScale:0,!0),e.dominanceGroup<=127&&e.dominanceGroup>=-127?t.setDominanceGroup(Math.floor(e.dominanceGroup)):t.setDominanceGroup(0),e.autoMass){t.setAdditionalMass(0,!1);for(let i=0;i<t.numColliders();i++)t.collider(i).setDensity(1);t.recomputeMassPropertiesFromColliders()}else{t.setAdditionalMass(e.mass,!1);for(let i=0;i<t.numColliders();i++)t.collider(i).setDensity(1e-7);t.recomputeMassPropertiesFromColliders()}t.setEnabledRotations(!e.lockRotationX,!e.lockRotationY,!e.lockRotationZ,!1),t.setEnabledTranslations(!e.lockPositionX,!e.lockPositionY,!e.lockPositionZ,!1),e.isKinematic?t.setBodyType(E.RAPIER_PHYSICS.MODULE.RigidBodyType.KinematicPositionBased,!1):t.setBodyType(E.RAPIER_PHYSICS.MODULE.RigidBodyType.Dynamic,!1)}lines;step(e){if(this.world&&this.enabled){if(this._isUpdatingPhysicsWorld=!0,this.eventQueue||(this.eventQueue=new E.RAPIER_PHYSICS.MODULE.EventQueue(!1)),e===void 0||e<=0){this._isUpdatingPhysicsWorld=!1;return}else if(e!==void 0){const t=L.lerp(this.world.timestep,e,.8);this.world.timestep=t}try{this.world.step(this.eventQueue)}catch(t){console.warn("Error running physics step",{timestep:this.world.timestep},t)}this._isUpdatingPhysicsWorld=!1}}postStep(){this.world&&this.enabled&&(this._isUpdatingPhysicsWorld=!0,this.syncObjects(),this._isUpdatingPhysicsWorld=!1,this.eventQueue&&!this.collisionHandler&&(this.collisionHandler=new aL(this.world,this.eventQueue)),this.collisionHandler&&(this.collisionHandler.handleCollisionEvents(),this.collisionHandler.update()),this.updateDebugRendering(this.world))}updateDebugRendering(e){if($e||V0||rL||this.debugRenderColliders===!0){if(!this.lines){const i=new gm({color:7855479,fog:!1}),n=new gn;this.lines=new ib(n,i),this.lines.layers.disableAll(),this.lines.layers.enable(2)}this.lines.parent!==this.context?.scene&&this.context?.scene.add(this.lines);const t=e.debugRender();this.lines.geometry.setAttribute("position",new mt(t.vertices,3)),this.lines.geometry.setAttribute("color",new mt(t.colors,4)),(this.context.time.frame%30===0||this.lines.geometry.boundingSphere?.radius===0)&&this.lines.geometry.computeBoundingSphere()}else this.lines&&this.context?.scene.remove(this.lines)}syncObjects(){if(!V0)for(let e=0;e<this.bodies.length;e++){const t=this.objects[e],i=this.bodies[e],n=t;if(n?.isCollider===!0&&!n.attachedRigidbody){const l=i.parent();l?this.syncPhysicsBody(t.gameObject,l,!0,!0):this.syncPhysicsBody(t.gameObject,i,!0,!0);continue}const s=i.translation(),r=i.rotation();if(Number.isNaN(s.x)||Number.isNaN(r.x)){!n.__COLLIDER_NAN&&A()&&(console.warn("Collider has NaN values",n.name,n.gameObject,i),n.__COLLIDER_NAN=!0);continue}const a=t.center;if(a&&a.isVector3){this._tempQuaternion.set(r.x,r.y,r.z,r.w);const l=this._tempPosition.copy(a).applyQuaternion(this._tempQuaternion),c=He(t.gameObject);l.multiply(c),s.x-=l.x,s.y-=l.y,s.z-=l.z}mr(t.gameObject,s.x,s.y,s.z),Zm(t.gameObject,r.x,r.y,r.z,r.w)}}syncPhysicsBody(e,t,i,n){if(t instanceof E.RAPIER_PHYSICS.MODULE.RigidBody){const s=J(e,this._tempPosition),r=be(e,this._tempQuaternion);switch(t.bodyType()){case E.RAPIER_PHYSICS.MODULE.RigidBodyType.Fixed:case E.RAPIER_PHYSICS.MODULE.RigidBodyType.KinematicPositionBased:case E.RAPIER_PHYSICS.MODULE.RigidBodyType.KinematicVelocityBased:i&&t.setNextKinematicTranslation(s),n&&t.setNextKinematicRotation(r);break;default:i&&t.setTranslation(s,!1),n&&t.setRotation(r,!1);break}}else if(t instanceof E.RAPIER_PHYSICS.MODULE.Collider){e.matrixWorldNeedsUpdate&&e.updateWorldMatrix(!0,!1),e.matrixWorld.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const s=this._tempPosition,r=this._tempQuaternion,a=t[_i];if(this.tryApplyCenter(a,s),i){const l=t.translation();(l.x!==s.x||l.y!==s.y||l.z!==s.z)&&t.setTranslation(s)}if(n){const l=t.rotation();(l.x!==r.x||l.y!==r.y||l.z!==r.z||l.w!==r.w)&&t.setRotation(r)}}}_tempCenterPos=new b;_tempCenterVec=new b;_tempCenterQuaternion=new U;tryApplyCenter(e,t){const i=e.center;i&&e.gameObject&&(i.x!==0||i.y!==0||i.z!==0)&&(this._tempCenterPos.x=i.x,this._tempCenterPos.y=i.y,this._tempCenterPos.z=i.z,He(e.gameObject,this._tempCenterVec),this._tempCenterPos.multiply(this._tempCenterVec),e.attachedRigidbody?this._tempCenterPos.applyQuaternion(e.gameObject.quaternion):(be(e.gameObject,this._tempCenterQuaternion),this._tempCenterPos.applyQuaternion(this._tempCenterQuaternion)),t.x+=this._tempCenterPos.x,t.y+=this._tempCenterPos.y,t.z+=this._tempCenterPos.z)}static _matricesBuffer=[];getRigidbodyRelativeMatrix(e,t,i,n){if(n===void 0&&(n=Ql._matricesBuffer,n.length=0),e===t){const s=He(e,this._tempPosition);i.makeScale(s.x,s.y,s.z);for(let r=n.length-1;r>=0;r--)i.multiply(n[r]);return i}return n.push(e.matrix),e.parent&&this.getRigidbodyRelativeMatrix(e.parent,t,i,n),i}static centerConnectionPos={x:0,y:0,z:0};static centerConnectionRot={x:0,y:0,z:0,w:1};addFixedJoint(e,t){if(!this.world){console.error("Physics world not initialized");return}const i=e[Gt],n=t[Gt];this.calculateJointRelativeMatrices(e.gameObject,t.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const s=E.RAPIER_PHYSICS.MODULE.JointData.fixed(Ql.centerConnectionPos,Ql.centerConnectionRot,this._tempPosition,this._tempQuaternion),r=this.world.createImpulseJoint(s,i,n,!0);$e&&console.log("ADD FIXED JOINT",r)}addHingeJoint(e,t,i,n){if(!this.world){console.error("Physics world not initialized");return}const s=e[Gt],r=t[Gt];this.calculateJointRelativeMatrices(e.gameObject,t.gameObject,this._tempMatrix),this._tempMatrix.decompose(this._tempPosition,this._tempQuaternion,this._tempScale);const a=E.RAPIER_PHYSICS.MODULE.JointData.revolute(i,this._tempPosition,n),l=this.world.createImpulseJoint(a,s,r,!0);$e&&console.log("ADD HINGE JOINT",l)}calculateJointRelativeMatrices(e,t,i){e.updateWorldMatrix(!0,!1),t.updateWorldMatrix(!0,!1);const n=e.matrixWorld,s=t.matrixWorld;n.elements[0]=1,n.elements[5]=1,n.elements[10]=1,s.elements[0]=1,s.elements[5]=1,s.elements[10]=1,i.copy(s).premultiply(n.invert()).invert()}}class aL{world;eventQueue;constructor(e,t){this.world=e,this.eventQueue=t}activeCollisions=[];activeCollisionsStay=[];activeTriggers=[];handleCollisionEvents(){this.eventQueue&&this.world&&this.eventQueue.drainCollisionEvents((e,t,i)=>{const n=this.world.getCollider(e),s=this.world.getCollider(t);if(!n||!s)return;const r=n[_i],a=s[_i];W0&&console.log("EVT",r.name,a.name,i,n,s),r&&a&&(i?(this.onCollisionStarted(r,n,a,s),this.onCollisionStarted(a,s,r,n)):(this.onCollisionEnded(r,a),this.onCollisionEnded(a,r)))})}update(){this.onHandleCollisionStay()}onCollisionStarted(e,t,i,n){let s=null;if(e.isTrigger||i.isTrigger)Er(e.gameObject,r=>{r.onTriggerEnter&&!r.destroyed&&r.onTriggerEnter(i),this.activeTriggers.push({collider:e,component:r,otherCollider:i})});else{const r=e.gameObject;this.world.contactPair(t,n,(a,l)=>{Er(r,c=>{if(c.destroyed)return;const h=c.onCollisionEnter||c.onCollisionStay||c.onCollisionExit;if(h||W0){if(!s){const d=[],p=a.normal();i instanceof Rs&&i.convex&&(p.x=-p.x,p.y=-p.y,p.z=-p.z);for(let m=0;m<a.numSolverContacts();m++){const f=a.solverContactPoint(m),g=a.contactImpulse(m);if(f){const y=a.contactDist(m),_=a.solverContactFriction(m),w=a.solverContactTangentVelocity(m),P=new $w(f,y,p,g,_,w);d.push(P),W0&&B.DrawDirection(f,p,16711680,3,!0)}}s=new Hw(r,i,d)}if(h){const d={collider:e,component:c,collision:s};this.activeCollisions.push(d),c.onCollisionStay&&this.activeCollisionsStay.push(d),c.onCollisionEnter?.call(c,s)}}})})}}onHandleCollisionStay(){for(const e of this.activeCollisionsStay){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onCollisionStay){if(e.collision.collider.destroyed)continue;const i=e.collision;t.onCollisionStay(i)}}for(const e of this.activeTriggers){const t=e.component;if(!t.destroyed&&t.activeAndEnabled&&t.onTriggerStay){const i=e.otherCollider;if(i.destroyed)continue;t.onTriggerStay(i)}}}onCollisionEnded(e,t){if(!(e.destroyed||t.destroyed)){for(let i=0;i<this.activeCollisions.length;i++){const n=this.activeCollisions[i],s=n.collider;if(s.destroyed||n.collision.collider.destroyed){this.activeCollisions.splice(i,1),i--;continue}if(s===e&&n.collision.collider===t){const r=n.component;if(this.activeCollisions.splice(i,1),i--,r.activeAndEnabled&&r.onCollisionExit){const a=n.collision;r.onCollisionExit(a)}}}for(let i=0;i<this.activeCollisionsStay.length;i++){const n=this.activeCollisionsStay[i],s=n.collider;if(s.destroyed||n.collision.collider.destroyed){this.activeCollisionsStay.splice(i,1),i--;continue}if(s===e&&n.collision.collider===t){const r=n.component;if(this.activeCollisionsStay.splice(i,1),i--,r.activeAndEnabled&&r.onCollisionExit){const a=n.collision;r.onCollisionExit(a)}}}for(let i=0;i<this.activeTriggers.length;i++){const n=this.activeTriggers[i],s=n.collider;if(s.destroyed||n.otherCollider.destroyed){this.activeTriggers.splice(i,1),i--;continue}if(s===e&&n.otherCollider===t){const r=n.component;if(this.activeTriggers.splice(i,1),i--,r.activeAndEnabled&&r.onTriggerExit){const a=n.otherCollider;r.onTriggerExit(a)}}}}}}class lL{static async createComparisonScene(e){const{files:t}=e,i=await Promise.all(t.map(f=>new ie(f).loadAssetAsync())),n=new wi;let s=0;for(const f of i)if(f instanceof k){f.position.y=s,n.add(f);const g=Xt([f]);s+=g.getSize(new b).y,s+=.1}const r=new re(20);n.add(r);const a=e.environment||"https://dl.polyhaven.org/file/ph-assets/HDRIs/exr/1k/studio_small_09_1k.exr";{let f=null;if(a.endsWith(".hdr")){const g=(await import("./three-examples-D1P7eEhn.min.js").then(y=>y.RGBELoader$1)).RGBELoader;f=new g}else if(a.endsWith(".exr")){const g=(await import("./three-examples-D1P7eEhn.min.js").then(y=>y.EXRLoader$1)).EXRLoader;f=new g}if(f){const g=await f.loadAsync(a).catch(y=>(console.error(y),null));g&&(g.mapping=Nn,g.needsUpdate=!0,n.background=g,n.environment=g,n.backgroundBlurriness=.75)}else console.warn("Unsupported environment map format",a)}const l=Xt(n.children),c=l.getCenter(new b),h=l.getSize(new b),d=Math.max(h.x,h.y,h.z)/(2*Math.tan(Math.PI*r.fov/360));r.position.set(c.x,c.y,d),r.lookAt(c);const p=new bb(r,e.domElement||document.body);p.target=c,p.update();const m=(e.domElement||document.body).getBoundingClientRect();return r.aspect=m.width/m.height,r.updateProjectionMatrix(),{scene:n,camera:r}}}let $0=0;function oS(o){o?$0++:$0--}function cL(){return $0>0}const hL={binary:!0,animations:!0};async function dL(o){if(!o.context)throw new Error("No context provided to exportAsGLTF");o.scene||(o.scene=o.context.scene);const e={...hL,...o},{context:t}=e,i=new _b;i.register(a=>new wx(a)),i.register(a=>new NT(a)),i.register(a=>new vx(a)),Gf(i,e.context);const n={binary:e.binary,animations:pL(t,e.scene,[])},s=new uL;console.debug("Exporting GLTF",n),s.onBeforeExport(e),oS(!0);const r=await i.parseAsync(e.scene,n).catch(a=>(console.error(a),null));if(oS(!1),s.onAfterExport(e),!r)throw new Error("Failed to export GLTF");if(e.downloadAs!=null){let a=null;if(r instanceof ArrayBuffer?a=new Blob([r],{type:"application/octet-stream"}):console.error("Can not download GLTF as a blob",r),a){const l=URL.createObjectURL(a),c=document.createElement("a");c.href=l;let h=e.downloadAs;!h.endsWith(".glb")&&!h.endsWith(".gltf")&&(h+=e.binary?".glb":".gltf"),c.download=h,c.click()}}return r}const sS=Symbol("needle:weight");class uL{_undo=[];onBeforeExport(e){e.context.animations.mixers.forEach(t=>{const i=vs.tryGetActionsFromMixer(t);if(i)for(let n=0;n<i.length;n++){const s=i[n];s[sS]=s.weight,s.weight=0,this._undo.push(()=>{s.weight=s[sS]})}t.update(0)}),e.context.scene.traverse(t=>{if(!ty(t)){const i=t.parent;i&&(t.removeFromParent(),this._undo.push(()=>i.add(t)))}})}onAfterExport(e){this._undo.forEach(t=>t()),this._undo.length=0}}function pL(o,e,t){o.animations.mixers.forEach(n=>{const s=vs.tryGetActionsFromMixer(n);if(s)for(let r=0;r<s.length;r++){const a=s[r].getClip();t.push(a)}}),Array.isArray(e)||(e=[e]);for(const n of e)vs.tryGetAnimationClipsFromObjectHierarchy(n,t);const i=new Set(t);return Array.from(i)}const rS="needle-button",H0=A();class aS extends HTMLElement{static observedAttributes=["ar","vr","quicklook"];constructor(){super(),this.removeEventListener("click",this.#r),this.addEventListener("click",this.#r)}attributeChangedCallback(e,t,i){this.#a()}#t;#n;#o;#e;#i;#s;#a(){if(this.#e?.remove(),this.getAttribute("ar")!=null)this.#i??=new or,this.#e=this.#i.createARButton();else if(this.getAttribute("vr")!=null)this.#i??=new or,this.#e=this.#i.createVRButton();else if(this.getAttribute("quicklook")!=null)this.#i??=new or,this.#e=this.#i.createQuicklookButton();else{H0?console.warn("No button type specified for <needle-button>. Use either ar, vr or quicklook attribute."):console.debug("No button type specified for <needle-button>. Use either ar, vr or quicklook attribute.");return}this.#t??=this.attachShadow({mode:"open"}),this.#n??=document.createElement("slot"),this.#o??=document.createElement("style"),this.#o.innerHTML=`
1614
1614
  button {
1615
1615
  all: initial;