@egret/engine 0.0.0-stage → 7.0.2

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 (601) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +21 -0
  3. package/README.md +101 -2
  4. package/README.zh-CN.md +102 -0
  5. package/dist/Engine.d.ts +77 -0
  6. package/dist/Engine.js +469 -0
  7. package/dist/animation/index.d.ts +6 -0
  8. package/dist/animation/index.js +5 -0
  9. package/dist/animation/sequenceController.d.ts +22 -0
  10. package/dist/animation/sequenceController.js +618 -0
  11. package/dist/animation/sequenceCoordinator.d.ts +26 -0
  12. package/dist/animation/sequenceCoordinator.js +161 -0
  13. package/dist/animation/sequenceInput.d.ts +25 -0
  14. package/dist/animation/sequenceInput.js +108 -0
  15. package/dist/animation/sequenceMath.d.ts +35 -0
  16. package/dist/animation/sequenceMath.js +164 -0
  17. package/dist/animation/sequenceResetSlot.d.ts +7 -0
  18. package/dist/animation/sequenceResetSlot.js +367 -0
  19. package/dist/animation/sequenceResetTypes.d.ts +48 -0
  20. package/dist/animation/sequenceResetTypes.js +2 -0
  21. package/dist/animation/types.d.ts +75 -0
  22. package/dist/animation/types.js +2 -0
  23. package/dist/assetBundle.d.ts +54 -0
  24. package/dist/assetBundle.js +173 -0
  25. package/dist/assetGroup.d.ts +17 -0
  26. package/dist/assetGroup.js +332 -0
  27. package/dist/assetGroupTypes.d.ts +17 -0
  28. package/dist/assetGroupTypes.js +2 -0
  29. package/dist/audio.d.ts +4 -0
  30. package/dist/audio.js +4 -0
  31. package/dist/audioCues.d.ts +47 -0
  32. package/dist/audioCues.js +127 -0
  33. package/dist/audioMixer.d.ts +7 -0
  34. package/dist/audioMixer.js +785 -0
  35. package/dist/audioTypes.d.ts +246 -0
  36. package/dist/audioTypes.js +3 -0
  37. package/dist/bitmapBindingTicket.d.ts +24 -0
  38. package/dist/bitmapBindingTicket.js +215 -0
  39. package/dist/bitmapButton.d.ts +4 -0
  40. package/dist/bitmapButton.js +407 -0
  41. package/dist/bitmapButtonTypes.d.ts +31 -0
  42. package/dist/bitmapButtonTypes.js +2 -0
  43. package/dist/bitmapFontParse.d.ts +10 -0
  44. package/dist/bitmapFontParse.js +246 -0
  45. package/dist/bitmapFontTypes.d.ts +112 -0
  46. package/dist/bitmapFontTypes.js +2 -0
  47. package/dist/bitmapResourceSlot.d.ts +26 -0
  48. package/dist/bitmapResourceSlot.js +340 -0
  49. package/dist/bitmapText.d.ts +6 -0
  50. package/dist/bitmapText.js +320 -0
  51. package/dist/bitmapfont.d.ts +5 -0
  52. package/dist/bitmapfont.js +5 -0
  53. package/dist/camera.d.ts +4 -0
  54. package/dist/camera.js +4 -0
  55. package/dist/camera2d.d.ts +7 -0
  56. package/dist/camera2d.js +419 -0
  57. package/dist/cameraTypes.d.ts +126 -0
  58. package/dist/cameraTypes.js +2 -0
  59. package/dist/closeHost.d.ts +4 -0
  60. package/dist/closeHost.js +66 -0
  61. package/dist/contentArtifacts.d.ts +12 -0
  62. package/dist/contentArtifacts.js +153 -0
  63. package/dist/contentAtlasPages.d.ts +13 -0
  64. package/dist/contentAtlasPages.js +117 -0
  65. package/dist/contentLoader.d.ts +6 -0
  66. package/dist/contentLoader.js +327 -0
  67. package/dist/contentTypes.d.ts +35 -0
  68. package/dist/contentTypes.js +2 -0
  69. package/dist/createEngine.d.ts +7 -0
  70. package/dist/createEngine.js +25 -0
  71. package/dist/createEngineForProfile.d.ts +5 -0
  72. package/dist/createEngineForProfile.js +45 -0
  73. package/dist/displaySubtreeTicket.d.ts +25 -0
  74. package/dist/displaySubtreeTicket.js +76 -0
  75. package/dist/fontContentLoader.d.ts +6 -0
  76. package/dist/fontContentLoader.js +298 -0
  77. package/dist/fontContentTypes.d.ts +39 -0
  78. package/dist/fontContentTypes.js +2 -0
  79. package/dist/gameClock.d.ts +24 -0
  80. package/dist/gameClock.js +246 -0
  81. package/dist/gameClockTypes.d.ts +37 -0
  82. package/dist/gameClockTypes.js +2 -0
  83. package/dist/gameRun.d.ts +53 -0
  84. package/dist/gameRun.js +97 -0
  85. package/dist/gamepad.d.ts +5 -0
  86. package/dist/gamepad.js +5 -0
  87. package/dist/gamepadInput.d.ts +4 -0
  88. package/dist/gamepadInput.js +281 -0
  89. package/dist/gamepadKeys.d.ts +4 -0
  90. package/dist/gamepadKeys.js +205 -0
  91. package/dist/gamepadTypes.d.ts +142 -0
  92. package/dist/gamepadTypes.js +3 -0
  93. package/dist/hover.d.ts +4 -0
  94. package/dist/hover.js +4 -0
  95. package/dist/hoverInput.d.ts +8 -0
  96. package/dist/hoverInput.js +503 -0
  97. package/dist/hoverInputTypes.d.ts +129 -0
  98. package/dist/hoverInputTypes.js +2 -0
  99. package/dist/index.d.ts +52 -0
  100. package/dist/index.js +21 -0
  101. package/dist/input.d.ts +6 -0
  102. package/dist/input.js +5 -0
  103. package/dist/inputActions.d.ts +86 -0
  104. package/dist/inputActions.js +330 -0
  105. package/dist/internal/contentFactoryState.d.ts +19 -0
  106. package/dist/internal/contentFactoryState.js +42 -0
  107. package/dist/internal/mouseInputFactoryState.d.ts +57 -0
  108. package/dist/internal/mouseInputFactoryState.js +125 -0
  109. package/dist/internal/sequenceControllerFactoryState.d.ts +42 -0
  110. package/dist/internal/sequenceControllerFactoryState.js +98 -0
  111. package/dist/internal/textFieldFactoryState.d.ts +11 -0
  112. package/dist/internal/textFieldFactoryState.js +32 -0
  113. package/dist/internal/texturedFrameState.d.ts +4 -0
  114. package/dist/internal/texturedFrameState.js +12 -0
  115. package/dist/internal/uiFactoryState.d.ts +68 -0
  116. package/dist/internal/uiFactoryState.js +173 -0
  117. package/dist/internal/uiRootState.d.ts +67 -0
  118. package/dist/internal/uiRootState.js +103 -0
  119. package/dist/keyboardInput.d.ts +13 -0
  120. package/dist/keyboardInput.js +579 -0
  121. package/dist/keyboardInputTypes.d.ts +93 -0
  122. package/dist/keyboardInputTypes.js +2 -0
  123. package/dist/kit.d.ts +16 -0
  124. package/dist/kit.js +10 -0
  125. package/dist/layout.d.ts +5 -0
  126. package/dist/layout.js +132 -0
  127. package/dist/layoutTypes.d.ts +28 -0
  128. package/dist/layoutTypes.js +2 -0
  129. package/dist/manifestAssetGroup.d.ts +10 -0
  130. package/dist/manifestAssetGroup.js +477 -0
  131. package/dist/manifestResourceState.d.ts +17 -0
  132. package/dist/manifestResourceState.js +58 -0
  133. package/dist/manifestResourceTypes.d.ts +26 -0
  134. package/dist/manifestResourceTypes.js +2 -0
  135. package/dist/motion.d.ts +35 -0
  136. package/dist/motion.js +206 -0
  137. package/dist/mouseInput.d.ts +102 -0
  138. package/dist/mouseInput.js +562 -0
  139. package/dist/mouseInputTypes.d.ts +41 -0
  140. package/dist/mouseInputTypes.js +2 -0
  141. package/dist/paragraph.d.ts +8 -0
  142. package/dist/paragraph.js +7 -0
  143. package/dist/particleEmitter.d.ts +4 -0
  144. package/dist/particleEmitter.js +300 -0
  145. package/dist/particleTypes.d.ts +115 -0
  146. package/dist/particleTypes.js +2 -0
  147. package/dist/particles.d.ts +4 -0
  148. package/dist/particles.js +4 -0
  149. package/dist/physics2d.d.ts +4 -0
  150. package/dist/physics2d.js +4 -0
  151. package/dist/physics2dGeometry.d.ts +39 -0
  152. package/dist/physics2dGeometry.js +230 -0
  153. package/dist/physics2dTypes.d.ts +221 -0
  154. package/dist/physics2dTypes.js +2 -0
  155. package/dist/physics2dWorld.d.ts +4 -0
  156. package/dist/physics2dWorld.js +823 -0
  157. package/dist/pointerInput.d.ts +12 -0
  158. package/dist/pointerInput.js +300 -0
  159. package/dist/pointerInputTypes.d.ts +41 -0
  160. package/dist/pointerInputTypes.js +2 -0
  161. package/dist/random.d.ts +30 -0
  162. package/dist/random.js +131 -0
  163. package/dist/rendering/ownedPreparationFailure2D.d.ts +5 -0
  164. package/dist/rendering/ownedPreparationFailure2D.js +33 -0
  165. package/dist/rendering/packSharedDraws2D.d.ts +50 -0
  166. package/dist/rendering/packSharedDraws2D.js +379 -0
  167. package/dist/rendering/packedOrientation.d.ts +4 -0
  168. package/dist/rendering/packedOrientation.js +7 -0
  169. package/dist/rendering/prepareRectangles2D.d.ts +92 -0
  170. package/dist/rendering/prepareRectangles2D.js +481 -0
  171. package/dist/rendering/prepareSharedDraws2D.d.ts +90 -0
  172. package/dist/rendering/prepareSharedDraws2D.js +663 -0
  173. package/dist/rendering/preparedBatches2D.d.ts +17 -0
  174. package/dist/rendering/preparedBatches2D.js +30 -0
  175. package/dist/rendering/preparedSharedBatches2D.d.ts +44 -0
  176. package/dist/rendering/preparedSharedBatches2D.js +247 -0
  177. package/dist/rendering/sharedColor2D.d.ts +52 -0
  178. package/dist/rendering/sharedColor2D.js +191 -0
  179. package/dist/rendering/sharedEffects2D.d.ts +23 -0
  180. package/dist/rendering/sharedEffects2D.js +126 -0
  181. package/dist/rendering/sharedPreparationRetention2D.d.ts +120 -0
  182. package/dist/rendering/sharedPreparationRetention2D.js +357 -0
  183. package/dist/rendering/srgbBytes.d.ts +3 -0
  184. package/dist/rendering/srgbBytes.js +64 -0
  185. package/dist/rendering/texturedPreparationBudget2D.d.ts +31 -0
  186. package/dist/rendering/texturedPreparationBudget2D.js +81 -0
  187. package/dist/rendering/world3d/Animation3D.d.ts +104 -0
  188. package/dist/rendering/world3d/Animation3D.js +384 -0
  189. package/dist/rendering/world3d/AnimationTexture3D.d.ts +163 -0
  190. package/dist/rendering/world3d/AnimationTexture3D.js +603 -0
  191. package/dist/rendering/world3d/Batch3D.d.ts +75 -0
  192. package/dist/rendering/world3d/Batch3D.js +332 -0
  193. package/dist/rendering/world3d/Camera3D.d.ts +62 -0
  194. package/dist/rendering/world3d/Camera3D.js +132 -0
  195. package/dist/rendering/world3d/Character3D.d.ts +127 -0
  196. package/dist/rendering/world3d/Character3D.js +305 -0
  197. package/dist/rendering/world3d/Cloth3D.d.ts +130 -0
  198. package/dist/rendering/world3d/Cloth3D.js +503 -0
  199. package/dist/rendering/world3d/Compression3D.d.ts +22 -0
  200. package/dist/rendering/world3d/Compression3D.js +703 -0
  201. package/dist/rendering/world3d/Curves3D.d.ts +119 -0
  202. package/dist/rendering/world3d/Curves3D.js +460 -0
  203. package/dist/rendering/world3d/Decal3D.d.ts +43 -0
  204. package/dist/rendering/world3d/Decal3D.js +242 -0
  205. package/dist/rendering/world3d/Export3D.d.ts +13 -0
  206. package/dist/rendering/world3d/Export3D.js +263 -0
  207. package/dist/rendering/world3d/Geometry3D.d.ts +95 -0
  208. package/dist/rendering/world3d/Geometry3D.js +335 -0
  209. package/dist/rendering/world3d/GeometryBuilder3D.d.ts +53 -0
  210. package/dist/rendering/world3d/GeometryBuilder3D.js +196 -0
  211. package/dist/rendering/world3d/Gizmo3D.d.ts +80 -0
  212. package/dist/rendering/world3d/Gizmo3D.js +514 -0
  213. package/dist/rendering/world3d/Gltf3D.d.ts +73 -0
  214. package/dist/rendering/world3d/Gltf3D.js +996 -0
  215. package/dist/rendering/world3d/GpuParticles3D.d.ts +109 -0
  216. package/dist/rendering/world3d/GpuParticles3D.js +401 -0
  217. package/dist/rendering/world3d/Hdr3D.d.ts +35 -0
  218. package/dist/rendering/world3d/Hdr3D.js +191 -0
  219. package/dist/rendering/world3d/Jelly3D.d.ts +77 -0
  220. package/dist/rendering/world3d/Jelly3D.js +267 -0
  221. package/dist/rendering/world3d/Ktx23D.d.ts +30 -0
  222. package/dist/rendering/world3d/Ktx23D.js +112 -0
  223. package/dist/rendering/world3d/Light3D.d.ts +84 -0
  224. package/dist/rendering/world3d/Light3D.js +97 -0
  225. package/dist/rendering/world3d/Material3D.d.ts +253 -0
  226. package/dist/rendering/world3d/Material3D.js +269 -0
  227. package/dist/rendering/world3d/Mesh3D.d.ts +112 -0
  228. package/dist/rendering/world3d/Mesh3D.js +337 -0
  229. package/dist/rendering/world3d/Meshopt3D.d.ts +15 -0
  230. package/dist/rendering/world3d/Meshopt3D.js +276 -0
  231. package/dist/rendering/world3d/Navigation3D.d.ts +213 -0
  232. package/dist/rendering/world3d/Navigation3D.js +1043 -0
  233. package/dist/rendering/world3d/Object3D.d.ts +118 -0
  234. package/dist/rendering/world3d/Object3D.js +315 -0
  235. package/dist/rendering/world3d/Particles3D.d.ts +90 -0
  236. package/dist/rendering/world3d/Particles3D.js +277 -0
  237. package/dist/rendering/world3d/Physics3D.d.ts +430 -0
  238. package/dist/rendering/world3d/Physics3D.js +2840 -0
  239. package/dist/rendering/world3d/PhysicsHull3D.d.ts +37 -0
  240. package/dist/rendering/world3d/PhysicsHull3D.js +229 -0
  241. package/dist/rendering/world3d/PhysicsMesh3D.d.ts +41 -0
  242. package/dist/rendering/world3d/PhysicsMesh3D.js +340 -0
  243. package/dist/rendering/world3d/PhysicsQueries3D.d.ts +24 -0
  244. package/dist/rendering/world3d/PhysicsQueries3D.js +323 -0
  245. package/dist/rendering/world3d/PhysicsRemote3D.d.ts +179 -0
  246. package/dist/rendering/world3d/PhysicsRemote3D.js +536 -0
  247. package/dist/rendering/world3d/Ragdoll3D.d.ts +74 -0
  248. package/dist/rendering/world3d/Ragdoll3D.js +202 -0
  249. package/dist/rendering/world3d/Raycast3D.d.ts +40 -0
  250. package/dist/rendering/world3d/Raycast3D.js +247 -0
  251. package/dist/rendering/world3d/RenderList3D.d.ts +91 -0
  252. package/dist/rendering/world3d/RenderList3D.js +502 -0
  253. package/dist/rendering/world3d/Retarget3D.d.ts +21 -0
  254. package/dist/rendering/world3d/Retarget3D.js +185 -0
  255. package/dist/rendering/world3d/Rig3D.d.ts +57 -0
  256. package/dist/rendering/world3d/Rig3D.js +219 -0
  257. package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
  258. package/dist/rendering/world3d/Sdf3D.js +1136 -0
  259. package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
  260. package/dist/rendering/world3d/SdfLod3D.js +56 -0
  261. package/dist/rendering/world3d/Serialize3D.d.ts +66 -0
  262. package/dist/rendering/world3d/Serialize3D.js +629 -0
  263. package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
  264. package/dist/rendering/world3d/Simplify3D.js +426 -0
  265. package/dist/rendering/world3d/StateMachine3D.d.ts +87 -0
  266. package/dist/rendering/world3d/StateMachine3D.js +280 -0
  267. package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
  268. package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
  269. package/dist/rendering/world3d/Terrain3D.d.ts +248 -0
  270. package/dist/rendering/world3d/Terrain3D.js +827 -0
  271. package/dist/rendering/world3d/Text3D.d.ts +95 -0
  272. package/dist/rendering/world3d/Text3D.js +560 -0
  273. package/dist/rendering/world3d/Texture3D.d.ts +148 -0
  274. package/dist/rendering/world3d/Texture3D.js +270 -0
  275. package/dist/rendering/world3d/Trail3D.d.ts +62 -0
  276. package/dist/rendering/world3d/Trail3D.js +195 -0
  277. package/dist/rendering/world3d/Vehicle3D.d.ts +102 -0
  278. package/dist/rendering/world3d/Vehicle3D.js +228 -0
  279. package/dist/rendering/world3d/VolumetricFog3D.d.ts +57 -0
  280. package/dist/rendering/world3d/VolumetricFog3D.js +230 -0
  281. package/dist/rendering/world3d/Water3D.d.ts +165 -0
  282. package/dist/rendering/world3d/Water3D.js +607 -0
  283. package/dist/rendering/world3d/core3D.d.ts +36 -0
  284. package/dist/rendering/world3d/core3D.js +99 -0
  285. package/dist/rendering/world3d/debug3D.d.ts +69 -0
  286. package/dist/rendering/world3d/debug3D.js +262 -0
  287. package/dist/rendering/world3d/decoders3D.d.ts +42 -0
  288. package/dist/rendering/world3d/decoders3D.js +133 -0
  289. package/dist/rendering/world3d/geometries3D.d.ts +111 -0
  290. package/dist/rendering/world3d/geometries3D.js +610 -0
  291. package/dist/rendering/world3d/helpers3D.d.ts +67 -0
  292. package/dist/rendering/world3d/helpers3D.js +178 -0
  293. package/dist/rendering/world3d/index.d.ts +103 -0
  294. package/dist/rendering/world3d/index.js +62 -0
  295. package/dist/rendering/world3d/math3D.d.ts +114 -0
  296. package/dist/rendering/world3d/math3D.js +675 -0
  297. package/dist/rendering/world3d/primitives3D.d.ts +67 -0
  298. package/dist/rendering/world3d/primitives3D.js +197 -0
  299. package/dist/resources.d.ts +8 -0
  300. package/dist/resources.js +6 -0
  301. package/dist/saveStore.d.ts +71 -0
  302. package/dist/saveStore.js +182 -0
  303. package/dist/semanticList.d.ts +126 -0
  304. package/dist/semanticList.js +175 -0
  305. package/dist/semanticTree.d.ts +10 -0
  306. package/dist/semanticTree.js +539 -0
  307. package/dist/semanticTypes.d.ts +175 -0
  308. package/dist/semanticTypes.js +2 -0
  309. package/dist/semantics.d.ts +6 -0
  310. package/dist/semantics.js +5 -0
  311. package/dist/sequencePlayback.d.ts +19 -0
  312. package/dist/sequencePlayback.js +391 -0
  313. package/dist/sequencePlaybackTypes.d.ts +24 -0
  314. package/dist/sequencePlaybackTypes.js +2 -0
  315. package/dist/sequenceTargetClaims.d.ts +10 -0
  316. package/dist/sequenceTargetClaims.js +31 -0
  317. package/dist/srgbBytes.d.ts +3 -0
  318. package/dist/srgbBytes.js +64 -0
  319. package/dist/startEngine.d.ts +5 -0
  320. package/dist/startEngine.js +31 -0
  321. package/dist/surfaceOwnership.d.ts +3 -0
  322. package/dist/surfaceOwnership.js +15 -0
  323. package/dist/text.d.ts +24 -0
  324. package/dist/text.js +4 -0
  325. package/dist/textField.d.ts +6 -0
  326. package/dist/textField.js +6 -0
  327. package/dist/textTable.d.ts +41 -0
  328. package/dist/textTable.js +114 -0
  329. package/dist/tileMapDraw.d.ts +7 -0
  330. package/dist/tileMapDraw.js +310 -0
  331. package/dist/tiledImport.d.ts +9 -0
  332. package/dist/tiledImport.js +357 -0
  333. package/dist/tilemap.d.ts +5 -0
  334. package/dist/tilemap.js +5 -0
  335. package/dist/tilemapTypes.d.ts +182 -0
  336. package/dist/tilemapTypes.js +2 -0
  337. package/dist/timer.d.ts +34 -0
  338. package/dist/timer.js +119 -0
  339. package/dist/tween.d.ts +15 -0
  340. package/dist/tween.js +329 -0
  341. package/dist/tweenTypes.d.ts +31 -0
  342. package/dist/tweenTypes.js +2 -0
  343. package/dist/ui/controlKeys.d.ts +113 -0
  344. package/dist/ui/controlKeys.js +250 -0
  345. package/dist/ui/controls.d.ts +58 -0
  346. package/dist/ui/controls.js +290 -0
  347. package/dist/ui/editing.d.ts +3 -0
  348. package/dist/ui/editing.js +3 -0
  349. package/dist/ui/index.d.ts +19 -0
  350. package/dist/ui/index.js +11 -0
  351. package/dist/ui/keyboardFocus.d.ts +32 -0
  352. package/dist/ui/keyboardFocus.js +146 -0
  353. package/dist/ui/layerTypes.d.ts +98 -0
  354. package/dist/ui/layerTypes.js +2 -0
  355. package/dist/ui/layers.d.ts +4 -0
  356. package/dist/ui/layers.js +586 -0
  357. package/dist/ui/leafContent.d.ts +21 -0
  358. package/dist/ui/leafContent.js +136 -0
  359. package/dist/ui/rangeControl.d.ts +53 -0
  360. package/dist/ui/rangeControl.js +168 -0
  361. package/dist/ui/scrollControl.d.ts +84 -0
  362. package/dist/ui/scrollControl.js +222 -0
  363. package/dist/ui/stateControls.d.ts +90 -0
  364. package/dist/ui/stateControls.js +331 -0
  365. package/dist/ui/textEditor.d.ts +54 -0
  366. package/dist/ui/textEditor.js +371 -0
  367. package/dist/ui/textEditorTypes.d.ts +85 -0
  368. package/dist/ui/textEditorTypes.js +2 -0
  369. package/dist/ui/textFieldControl.d.ts +100 -0
  370. package/dist/ui/textFieldControl.js +260 -0
  371. package/dist/ui/theme.d.ts +64 -0
  372. package/dist/ui/theme.js +166 -0
  373. package/dist/ui/types.d.ts +285 -0
  374. package/dist/ui/types.js +2 -0
  375. package/dist/ui/uiRoot.d.ts +4 -0
  376. package/dist/ui/uiRoot.js +1526 -0
  377. package/dist/ui/uiRootDisplay.d.ts +46 -0
  378. package/dist/ui/uiRootDisplay.js +148 -0
  379. package/dist/ui/uiRootModel.d.ts +114 -0
  380. package/dist/ui/uiRootModel.js +66 -0
  381. package/dist/ui/virtualList.d.ts +20 -0
  382. package/dist/ui/virtualList.js +105 -0
  383. package/dist/video.d.ts +4 -0
  384. package/dist/video.js +4 -0
  385. package/dist/videoPlayer.d.ts +4 -0
  386. package/dist/videoPlayer.js +215 -0
  387. package/dist/videoTypes.d.ts +77 -0
  388. package/dist/videoTypes.js +2 -0
  389. package/dist/web/BrowserAssetBundle.d.ts +41 -0
  390. package/dist/web/BrowserAssetBundle.js +136 -0
  391. package/dist/web/BrowserAudio.d.ts +74 -0
  392. package/dist/web/BrowserAudio.js +503 -0
  393. package/dist/web/BrowserFrameLoop.d.ts +69 -0
  394. package/dist/web/BrowserFrameLoop.js +125 -0
  395. package/dist/web/BrowserGame.d.ts +174 -0
  396. package/dist/web/BrowserGame.js +473 -0
  397. package/dist/web/BrowserGamepadInput.d.ts +38 -0
  398. package/dist/web/BrowserGamepadInput.js +134 -0
  399. package/dist/web/BrowserHoverInput.d.ts +25 -0
  400. package/dist/web/BrowserHoverInput.js +266 -0
  401. package/dist/web/BrowserImageTextures.d.ts +72 -0
  402. package/dist/web/BrowserImageTextures.js +169 -0
  403. package/dist/web/BrowserInputActions.d.ts +63 -0
  404. package/dist/web/BrowserInputActions.js +345 -0
  405. package/dist/web/BrowserKeyboardInput.d.ts +4 -0
  406. package/dist/web/BrowserKeyboardInput.js +223 -0
  407. package/dist/web/BrowserPlay.d.ts +417 -0
  408. package/dist/web/BrowserPlay.js +1648 -0
  409. package/dist/web/BrowserPointerInput.d.ts +4 -0
  410. package/dist/web/BrowserPointerInput.js +511 -0
  411. package/dist/web/BrowserPreferences.d.ts +10 -0
  412. package/dist/web/BrowserPreferences.js +39 -0
  413. package/dist/web/BrowserSemantics.d.ts +36 -0
  414. package/dist/web/BrowserSemantics.js +418 -0
  415. package/dist/web/BrowserStatsPanel.d.ts +56 -0
  416. package/dist/web/BrowserStatsPanel.js +143 -0
  417. package/dist/web/BrowserStorage.d.ts +35 -0
  418. package/dist/web/BrowserStorage.js +132 -0
  419. package/dist/web/BrowserTextEditor.d.ts +52 -0
  420. package/dist/web/BrowserTextEditor.js +839 -0
  421. package/dist/web/BrowserTextInput.d.ts +89 -0
  422. package/dist/web/BrowserTextInput.js +524 -0
  423. package/dist/web/BrowserTextureProvider.d.ts +58 -0
  424. package/dist/web/BrowserTextureProvider.js +935 -0
  425. package/dist/web/BrowserVideo.d.ts +40 -0
  426. package/dist/web/BrowserVideo.js +237 -0
  427. package/dist/web/CanvasKitFontSetProvider.d.ts +32 -0
  428. package/dist/web/CanvasKitFontSetProvider.js +215 -0
  429. package/dist/web/CanvasKitParagraphProvider.d.ts +173 -0
  430. package/dist/web/CanvasKitParagraphProvider.js +692 -0
  431. package/dist/web/CanvasTextRasterProvider.d.ts +4 -0
  432. package/dist/web/CanvasTextRasterProvider.js +312 -0
  433. package/dist/web/ManifestByteSource.d.ts +151 -0
  434. package/dist/web/ManifestByteSource.js +975 -0
  435. package/dist/web/ManifestFontContentLoader.d.ts +13 -0
  436. package/dist/web/ManifestFontContentLoader.js +30 -0
  437. package/dist/web/MouseInput.d.ts +4 -0
  438. package/dist/web/MouseInput.js +218 -0
  439. package/dist/web/WebGL2Host.d.ts +5 -0
  440. package/dist/web/WebGL2Host.js +2711 -0
  441. package/dist/web/WebGPUHost.d.ts +100 -0
  442. package/dist/web/WebGPUHost.js +3430 -0
  443. package/dist/web/audio.d.ts +3 -0
  444. package/dist/web/audio.js +4 -0
  445. package/dist/web/canvasKitParagraphGeometry.d.ts +27 -0
  446. package/dist/web/canvasKitParagraphGeometry.js +83 -0
  447. package/dist/web/editing.d.ts +5 -0
  448. package/dist/web/editing.js +4 -0
  449. package/dist/web/editorFonts.d.ts +54 -0
  450. package/dist/web/editorFonts.js +297 -0
  451. package/dist/web/game.d.ts +5 -0
  452. package/dist/web/game.js +6 -0
  453. package/dist/web/gamepad.d.ts +3 -0
  454. package/dist/web/gamepad.js +4 -0
  455. package/dist/web/hover.d.ts +3 -0
  456. package/dist/web/hover.js +4 -0
  457. package/dist/web/image.d.ts +4 -0
  458. package/dist/web/image.js +4 -0
  459. package/dist/web/imageProjections2D.d.ts +16 -0
  460. package/dist/web/imageProjections2D.js +2 -0
  461. package/dist/web/input.d.ts +6 -0
  462. package/dist/web/input.js +4 -0
  463. package/dist/web/keyboard.d.ts +3 -0
  464. package/dist/web/keyboard.js +3 -0
  465. package/dist/web/kit.d.ts +11 -0
  466. package/dist/web/kit.js +8 -0
  467. package/dist/web/loop.d.ts +3 -0
  468. package/dist/web/loop.js +4 -0
  469. package/dist/web/paragraph.d.ts +6 -0
  470. package/dist/web/paragraph.js +4 -0
  471. package/dist/web/play.d.ts +10 -0
  472. package/dist/web/play.js +9 -0
  473. package/dist/web/playMusic.d.ts +33 -0
  474. package/dist/web/playMusic.js +194 -0
  475. package/dist/web/playSfx.d.ts +36 -0
  476. package/dist/web/playSfx.js +112 -0
  477. package/dist/web/playTouch.d.ts +45 -0
  478. package/dist/web/playTouch.js +141 -0
  479. package/dist/web/playWidgets.d.ts +71 -0
  480. package/dist/web/playWidgets.js +431 -0
  481. package/dist/web/pointer.d.ts +3 -0
  482. package/dist/web/pointer.js +3 -0
  483. package/dist/web/prepareSharedSubmission2D.d.ts +27 -0
  484. package/dist/web/prepareSharedSubmission2D.js +63 -0
  485. package/dist/web/resources.d.ts +29 -0
  486. package/dist/web/resources.js +96 -0
  487. package/dist/web/semantics.d.ts +3 -0
  488. package/dist/web/semantics.js +4 -0
  489. package/dist/web/sharedDeviceSession.d.ts +64 -0
  490. package/dist/web/sharedDeviceSession.js +2 -0
  491. package/dist/web/sharedEffectShaders.d.ts +13 -0
  492. package/dist/web/sharedEffectShaders.js +181 -0
  493. package/dist/web/sharedFrameUpload.d.ts +25 -0
  494. package/dist/web/sharedFrameUpload.js +2 -0
  495. package/dist/web/sharedHostDeferred.d.ts +7 -0
  496. package/dist/web/sharedHostDeferred.js +12 -0
  497. package/dist/web/sharedRetentionLedger.d.ts +85 -0
  498. package/dist/web/sharedRetentionLedger.js +391 -0
  499. package/dist/web/sharedSubmissionStorage2D.d.ts +56 -0
  500. package/dist/web/sharedSubmissionStorage2D.js +73 -0
  501. package/dist/web/sharedWebGL2Arena.d.ts +40 -0
  502. package/dist/web/sharedWebGL2Arena.js +77 -0
  503. package/dist/web/sharedWebGL2Options.d.ts +33 -0
  504. package/dist/web/sharedWebGL2Options.js +102 -0
  505. package/dist/web/sharedWebGL2Shaders.d.ts +33 -0
  506. package/dist/web/sharedWebGL2Shaders.js +408 -0
  507. package/dist/web/sharedWebGPUOptions.d.ts +41 -0
  508. package/dist/web/sharedWebGPUOptions.js +130 -0
  509. package/dist/web/text.d.ts +3 -0
  510. package/dist/web/text.js +3 -0
  511. package/dist/web/textInput.d.ts +3 -0
  512. package/dist/web/textInput.js +3 -0
  513. package/dist/web/video.d.ts +3 -0
  514. package/dist/web/video.js +4 -0
  515. package/dist/web/webgl2.d.ts +7 -0
  516. package/dist/web/webgl2.js +4 -0
  517. package/dist/web/webgl2LayerState.d.ts +50 -0
  518. package/dist/web/webgl2LayerState.js +102 -0
  519. package/dist/web/webgl2Native.d.ts +72 -0
  520. package/dist/web/webgl2Native.js +572 -0
  521. package/dist/web/webgl2Types.d.ts +150 -0
  522. package/dist/web/webgl2Types.js +2 -0
  523. package/dist/web/webgpu.d.ts +6 -0
  524. package/dist/web/webgpu.js +2 -0
  525. package/dist/web/webgpuBindingCache.d.ts +26 -0
  526. package/dist/web/webgpuBindingCache.js +223 -0
  527. package/dist/web/webgpuBufferPool.d.ts +51 -0
  528. package/dist/web/webgpuBufferPool.js +58 -0
  529. package/dist/web/webgpuImageResidency.d.ts +56 -0
  530. package/dist/web/webgpuImageResidency.js +65 -0
  531. package/dist/web/webgpuLifetime.d.ts +45 -0
  532. package/dist/web/webgpuLifetime.js +64 -0
  533. package/dist/web/webgpuRetentionPool.d.ts +66 -0
  534. package/dist/web/webgpuRetentionPool.js +85 -0
  535. package/dist/web/webgpuSharedPass.d.ts +7 -0
  536. package/dist/web/webgpuSharedPass.js +293 -0
  537. package/dist/web/webgpuSharedResolvePass.d.ts +3 -0
  538. package/dist/web/webgpuSharedResolvePass.js +34 -0
  539. package/dist/web/world3d/Audio3D.d.ts +85 -0
  540. package/dist/web/world3d/Audio3D.js +271 -0
  541. package/dist/web/world3d/BrowserPlay3D.d.ts +295 -0
  542. package/dist/web/world3d/BrowserPlay3D.js +1256 -0
  543. package/dist/web/world3d/FlyControls3D.d.ts +59 -0
  544. package/dist/web/world3d/FlyControls3D.js +162 -0
  545. package/dist/web/world3d/FollowControls3D.d.ts +31 -0
  546. package/dist/web/world3d/FollowControls3D.js +119 -0
  547. package/dist/web/world3d/OrbitControls3D.d.ts +58 -0
  548. package/dist/web/world3d/OrbitControls3D.js +189 -0
  549. package/dist/web/world3d/TransformControls3D.d.ts +37 -0
  550. package/dist/web/world3d/TransformControls3D.js +128 -0
  551. package/dist/web/world3d/WebGL2Renderer3D.d.ts +136 -0
  552. package/dist/web/world3d/WebGL2Renderer3D.js +1175 -0
  553. package/dist/web/world3d/WebGPURenderer3D.d.ts +112 -0
  554. package/dist/web/world3d/WebGPURenderer3D.js +1916 -0
  555. package/dist/web/world3d/World3DView.d.ts +54 -0
  556. package/dist/web/world3d/World3DView.js +79 -0
  557. package/dist/web/world3d/app3D.d.ts +143 -0
  558. package/dist/web/world3d/app3D.js +305 -0
  559. package/dist/web/world3d/assets3D.d.ts +39 -0
  560. package/dist/web/world3d/assets3D.js +112 -0
  561. package/dist/web/world3d/atmosphere3D.d.ts +56 -0
  562. package/dist/web/world3d/atmosphere3D.js +193 -0
  563. package/dist/web/world3d/canvasFont3D.d.ts +21 -0
  564. package/dist/web/world3d/canvasFont3D.js +165 -0
  565. package/dist/web/world3d/frame3D.d.ts +144 -0
  566. package/dist/web/world3d/frame3D.js +388 -0
  567. package/dist/web/world3d/gpuResources3D.d.ts +98 -0
  568. package/dist/web/world3d/gpuResources3D.js +901 -0
  569. package/dist/web/world3d/host3D.d.ts +24 -0
  570. package/dist/web/world3d/host3D.js +61 -0
  571. package/dist/web/world3d/index.d.ts +40 -0
  572. package/dist/web/world3d/index.js +24 -0
  573. package/dist/web/world3d/loaders3D.d.ts +27 -0
  574. package/dist/web/world3d/loaders3D.js +138 -0
  575. package/dist/web/world3d/markers3D.d.ts +53 -0
  576. package/dist/web/world3d/markers3D.js +130 -0
  577. package/dist/web/world3d/materialWebGL23D.d.ts +34 -0
  578. package/dist/web/world3d/materialWebGL23D.js +218 -0
  579. package/dist/web/world3d/overlay3D.d.ts +47 -0
  580. package/dist/web/world3d/overlay3D.js +187 -0
  581. package/dist/web/world3d/post3D.d.ts +116 -0
  582. package/dist/web/world3d/post3D.js +462 -0
  583. package/dist/web/world3d/postWebGL23D.d.ts +24 -0
  584. package/dist/web/world3d/postWebGL23D.js +237 -0
  585. package/dist/web/world3d/postWebGPU3D.d.ts +23 -0
  586. package/dist/web/world3d/postWebGPU3D.js +255 -0
  587. package/dist/web/world3d/probe3D.d.ts +15 -0
  588. package/dist/web/world3d/probe3D.js +66 -0
  589. package/dist/web/world3d/shaders3D.d.ts +43 -0
  590. package/dist/web/world3d/shaders3D.js +851 -0
  591. package/dist/web/world3d/stats3D.d.ts +34 -0
  592. package/dist/web/world3d/stats3D.js +81 -0
  593. package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +71 -0
  594. package/dist/web/world3d/webGL2FrameMetrics3D.js +185 -0
  595. package/dist/web/world3d/webgpu.d.ts +37 -0
  596. package/dist/web/world3d/webgpu.js +23 -0
  597. package/dist/web/world3d/webgpuPacking3D.d.ts +13 -0
  598. package/dist/web/world3d/webgpuPacking3D.js +85 -0
  599. package/dist/web/world3d/wgsl3D.d.ts +68 -0
  600. package/dist/web/world3d/wgsl3D.js +781 -0
  601. package/package.json +220 -4
@@ -0,0 +1,1136 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Models made in code as distance fields: rounded primitives joined smoothly, cut and mirrored, then turned into
3
+ // one coloured mesh. A soft union lets an arm grow out of a body and a mouth be carved into a head without the
4
+ // seams of boxes pushed through each other; the mesh comes with normals from the field, colours blended where parts
5
+ // meet, and the shade of creases and hollows baked into its vertex colours. Each shape is a plain value: a game
6
+ // keeps the field to ask how far a point is from the model, and makes the mesh once.
7
+ //
8
+ // The distance functions are the standard closed forms of signed distance fields (sphere, rounded box, ellipsoid
9
+ // approximation, round cone, capped cone, torus) and the polynomial smooth minimum; the mesh is extracted by surface
10
+ // nets on a regular grid, with each vertex moved onto the surface along the field's gradient.
11
+ import { World3DError } from './core3D.js';
12
+ import { Attribute3D, Geometry3D } from './Geometry3D.js';
13
+ import { colorFromHex, quatFromEuler } from './math3D.js';
14
+ import { simplifyGeometry3D } from './Simplify3D.js';
15
+ /** A shape as a signed distance field: negative inside, positive outside, zero on the surface. */
16
+ export class SdfShape3D {
17
+ /** The box the shape lies in, as [minX, minY, minZ, maxX, maxY, maxZ]. */
18
+ bounds;
19
+ /** @internal */
20
+ paint;
21
+ #inverse;
22
+ #at;
23
+ #scale;
24
+ /** @internal */
25
+ constructor(options, local) {
26
+ const o = checkOptions(options);
27
+ this.#at = o.at;
28
+ this.#scale = o.scale;
29
+ this.paint = o.color;
30
+ let rotation;
31
+ if (o.rotation[0] !== 0 || o.rotation[1] !== 0 || o.rotation[2] !== 0) {
32
+ const q = quatFromEuler(new Float64Array(4), o.rotation[0], o.rotation[1], o.rotation[2]);
33
+ rotation = matrixOf(q);
34
+ // The transpose of a rotation turns it back.
35
+ const t = new Float64Array(9);
36
+ for (let r = 0; r < 3; r++)
37
+ for (let c = 0; c < 3; c++)
38
+ t[r * 3 + c] = rotation[c * 3 + r];
39
+ this.#inverse = t;
40
+ }
41
+ this.bounds = Object.freeze(placeBounds(local, rotation, o.at, o.scale));
42
+ }
43
+ /** How far the point is from the surface: negative inside. */
44
+ distance(x, y, z) {
45
+ const p = this.#toLocal(x, y, z);
46
+ return this.local(p[0], p[1], p[2]) * this.#scale;
47
+ }
48
+ /** @internal The linear colour of the shape at a point, written to `out`; `inherited` when it has none. */
49
+ colorAt(x, y, z, out, inherited) {
50
+ const p = this.#toLocal(x, y, z);
51
+ this.localColor(p[0], p[1], p[2], out, this.paint ?? inherited);
52
+ }
53
+ /** @internal */
54
+ localColor(_x, _y, _z, out, paint) {
55
+ out.set(paint);
56
+ }
57
+ #toLocal(x, y, z) {
58
+ const s = this.#scale;
59
+ let px = x - this.#at[0], py = y - this.#at[1], pz = z - this.#at[2];
60
+ const m = this.#inverse;
61
+ if (m !== undefined) {
62
+ const rx = m[0] * px + m[1] * py + m[2] * pz, ry = m[3] * px + m[4] * py + m[5] * pz, rz = m[6] * px + m[7] * py + m[8] * pz;
63
+ px = rx;
64
+ py = ry;
65
+ pz = rz;
66
+ }
67
+ return [px / s, py / s, pz / s];
68
+ }
69
+ }
70
+ const ZERO = [0, 0, 0];
71
+ function invalid(what) {
72
+ return new World3DError('WORLD3D_INPUT_INVALID', what);
73
+ }
74
+ function vec3(value, what) {
75
+ if (!Array.isArray(value) || value.length !== 3 || !value.every(Number.isFinite))
76
+ throw invalid(what);
77
+ return value;
78
+ }
79
+ function positive(value, what) {
80
+ if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
81
+ throw invalid(what);
82
+ return value;
83
+ }
84
+ function nonNegative(value, what) {
85
+ if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
86
+ throw invalid(what);
87
+ return value;
88
+ }
89
+ function linear(input, what) {
90
+ const out = new Float32Array(3);
91
+ if (typeof input === 'number') {
92
+ if (!Number.isInteger(input) || input < 0 || input > 0xffffff)
93
+ throw invalid(what);
94
+ return colorFromHex(out, input);
95
+ }
96
+ if (Array.isArray(input) && input.length === 3 && input.every(Number.isFinite)) {
97
+ out.set(input);
98
+ return out;
99
+ }
100
+ throw invalid(what);
101
+ }
102
+ function checkOptions(options) {
103
+ if (options === undefined)
104
+ return { at: ZERO, rotation: ZERO, scale: 1, color: undefined };
105
+ if (options === null || typeof options !== 'object')
106
+ throw invalid('sdf options');
107
+ return {
108
+ at: options.at === undefined ? ZERO : vec3(options.at, 'sdf at'),
109
+ rotation: options.rotation === undefined ? ZERO : vec3(options.rotation, 'sdf rotation'),
110
+ scale: options.scale === undefined ? 1 : positive(options.scale, 'sdf scale'),
111
+ color: options.color === undefined ? undefined : linear(options.color, 'sdf color')
112
+ };
113
+ }
114
+ function matrixOf(q) {
115
+ const x = q[0], y = q[1], z = q[2], w = q[3];
116
+ // Row-major: row r, column c at r * 3 + c.
117
+ return new Float64Array([
118
+ 1 - 2 * (y * y + z * z),
119
+ 2 * (x * y - z * w),
120
+ 2 * (x * z + y * w),
121
+ 2 * (x * y + z * w),
122
+ 1 - 2 * (x * x + z * z),
123
+ 2 * (y * z - x * w),
124
+ 2 * (x * z - y * w),
125
+ 2 * (y * z + x * w),
126
+ 1 - 2 * (x * x + y * y)
127
+ ]);
128
+ }
129
+ function placeBounds(local, rotation, at, scale) {
130
+ const out = [Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity];
131
+ for (let corner = 0; corner < 8; corner++) {
132
+ let x = (corner & 1 ? local[3] : local[0]) * scale, y = (corner & 2 ? local[4] : local[1]) * scale, z = (corner & 4 ? local[5] : local[2]) * scale;
133
+ if (rotation !== undefined) {
134
+ const rx = rotation[0] * x + rotation[1] * y + rotation[2] * z, ry = rotation[3] * x + rotation[4] * y + rotation[5] * z, rz = rotation[6] * x + rotation[7] * y + rotation[8] * z;
135
+ x = rx;
136
+ y = ry;
137
+ z = rz;
138
+ }
139
+ const p = [x + at[0], y + at[1], z + at[2]];
140
+ for (let a = 0; a < 3; a++) {
141
+ if (p[a] < out[a])
142
+ out[a] = p[a];
143
+ if (p[a] > out[a + 3])
144
+ out[a + 3] = p[a];
145
+ }
146
+ }
147
+ return out;
148
+ }
149
+ const box = (r) => [-r, -r, -r, r, r, r];
150
+ const grow = (b, by) => [
151
+ b[0] - by,
152
+ b[1] - by,
153
+ b[2] - by,
154
+ b[3] + by,
155
+ b[4] + by,
156
+ b[5] + by
157
+ ];
158
+ const len2 = (x, y) => Math.sqrt(x * x + y * y);
159
+ const len3 = (x, y, z) => Math.sqrt(x * x + y * y + z * z);
160
+ const clamp01 = (v) => (v < 0 ? 0 : v > 1 ? 1 : v);
161
+ // ---- primitives ---------------------------------------------------------------------------------------------------
162
+ class Sphere extends SdfShape3D {
163
+ radius;
164
+ constructor(radius, options) {
165
+ super(options, box(radius));
166
+ this.radius = radius;
167
+ }
168
+ local(x, y, z) {
169
+ return len3(x, y, z) - this.radius;
170
+ }
171
+ }
172
+ class Box extends SdfShape3D {
173
+ #half;
174
+ #round;
175
+ constructor(size, round, options) {
176
+ const h = [size[0] / 2, size[1] / 2, size[2] / 2];
177
+ super(options, [-h[0], -h[1], -h[2], h[0], h[1], h[2]]);
178
+ this.#half = h;
179
+ this.#round = round;
180
+ }
181
+ local(x, y, z) {
182
+ const r = this.#round;
183
+ const qx = Math.abs(x) - this.#half[0] + r, qy = Math.abs(y) - this.#half[1] + r, qz = Math.abs(z) - this.#half[2] + r;
184
+ return len3(Math.max(qx, 0), Math.max(qy, 0), Math.max(qz, 0)) + Math.min(Math.max(qx, Math.max(qy, qz)), 0) - r;
185
+ }
186
+ }
187
+ class Ellipsoid extends SdfShape3D {
188
+ #r;
189
+ constructor(radii, options) {
190
+ super(options, [-radii[0], -radii[1], -radii[2], radii[0], radii[1], radii[2]]);
191
+ this.#r = radii;
192
+ }
193
+ local(x, y, z) {
194
+ const r = this.#r;
195
+ const k0 = len3(x / r[0], y / r[1], z / r[2]), k1 = len3(x / (r[0] * r[0]), y / (r[1] * r[1]), z / (r[2] * r[2]));
196
+ if (k1 === 0)
197
+ return -Math.min(r[0], r[1], r[2]);
198
+ return (k0 * (k0 - 1)) / k1;
199
+ }
200
+ }
201
+ class RoundCone extends SdfShape3D {
202
+ #a;
203
+ #b;
204
+ #r1;
205
+ #r2;
206
+ constructor(from, to, r1, r2, options) {
207
+ const r = Math.max(r1, r2);
208
+ super(options, [
209
+ Math.min(from[0], to[0]) - r,
210
+ Math.min(from[1], to[1]) - r,
211
+ Math.min(from[2], to[2]) - r,
212
+ Math.max(from[0], to[0]) + r,
213
+ Math.max(from[1], to[1]) + r,
214
+ Math.max(from[2], to[2]) + r
215
+ ]);
216
+ this.#a = from;
217
+ this.#b = to;
218
+ this.#r1 = r1;
219
+ this.#r2 = r2;
220
+ }
221
+ local(x, y, z) {
222
+ const a = this.#a, b = this.#b, r1 = this.#r1, r2 = this.#r2;
223
+ const bax = b[0] - a[0], bay = b[1] - a[1], baz = b[2] - a[2];
224
+ const l2 = bax * bax + bay * bay + baz * baz, rr = r1 - r2, a2 = l2 - rr * rr;
225
+ const pax = x - a[0], pay = y - a[1], paz = z - a[2];
226
+ // One end swallows the other: the shape is the larger ball.
227
+ if (a2 <= 1e-12) {
228
+ return r1 >= r2 ? len3(pax, pay, paz) - r1 : len3(x - b[0], y - b[1], z - b[2]) - r2;
229
+ }
230
+ const il2 = 1 / l2;
231
+ const yy = pax * bax + pay * bay + paz * baz, zz = yy - l2;
232
+ const cx = pax * l2 - bax * yy, cy = pay * l2 - bay * yy, cz = paz * l2 - baz * yy;
233
+ const x2 = cx * cx + cy * cy + cz * cz, y2 = yy * yy * l2, z2 = zz * zz * l2;
234
+ const k = Math.sign(rr) * rr * rr * x2;
235
+ if (Math.sign(zz) * a2 * z2 > k)
236
+ return Math.sqrt(x2 + z2) * il2 - r2;
237
+ if (Math.sign(yy) * a2 * y2 < k)
238
+ return Math.sqrt(x2 + y2) * il2 - r1;
239
+ return (Math.sqrt(x2 * a2 * il2) + yy * rr) * il2 - r1;
240
+ }
241
+ }
242
+ class Cylinder extends SdfShape3D {
243
+ #r;
244
+ #h;
245
+ #round;
246
+ constructor(radius, height, round, options) {
247
+ super(options, [-radius, -height / 2, -radius, radius, height / 2, radius]);
248
+ this.#r = radius;
249
+ this.#h = height / 2;
250
+ this.#round = round;
251
+ }
252
+ local(x, y, z) {
253
+ const r = this.#round;
254
+ const dx = len2(x, z) - this.#r + r, dy = Math.abs(y) - this.#h + r;
255
+ return Math.min(Math.max(dx, dy), 0) + len2(Math.max(dx, 0), Math.max(dy, 0)) - r;
256
+ }
257
+ }
258
+ class Cone extends SdfShape3D {
259
+ #r1;
260
+ #r2;
261
+ #h;
262
+ constructor(bottom, top, height, options) {
263
+ const r = Math.max(bottom, top);
264
+ super(options, [-r, -height / 2, -r, r, height / 2, r]);
265
+ this.#r1 = bottom;
266
+ this.#r2 = top;
267
+ this.#h = height / 2;
268
+ }
269
+ local(x, y, z) {
270
+ const r1 = this.#r1, r2 = this.#r2, h = this.#h;
271
+ const qx = len2(x, z), qy = y;
272
+ const k2x = r2 - r1, k2y = 2 * h;
273
+ const cax = qx - Math.min(qx, qy < 0 ? r1 : r2), cay = Math.abs(qy) - h;
274
+ const t = clamp01(((r2 - qx) * k2x + (h - qy) * k2y) / (k2x * k2x + k2y * k2y));
275
+ const cbx = qx - r2 + k2x * t, cby = qy - h + k2y * t;
276
+ const s = cbx < 0 && cay < 0 ? -1 : 1;
277
+ return s * Math.sqrt(Math.min(cax * cax + cay * cay, cbx * cbx + cby * cby));
278
+ }
279
+ }
280
+ class Torus extends SdfShape3D {
281
+ #big;
282
+ #tube;
283
+ constructor(radius, tube, options) {
284
+ super(options, [-radius - tube, -tube, -radius - tube, radius + tube, tube, radius + tube]);
285
+ this.#big = radius;
286
+ this.#tube = tube;
287
+ }
288
+ local(x, y, z) {
289
+ return len2(len2(x, z) - this.#big, y) - this.#tube;
290
+ }
291
+ }
292
+ /** A ball of `radius`. */
293
+ export function sdfSphere(radius, options) {
294
+ return new Sphere(positive(radius, 'sdf sphere radius'), options);
295
+ }
296
+ /** A box of `size` [width, height, depth], its edges rounded by `round` (0 for sharp; more than half the smallest side is taken as that). */
297
+ export function sdfBox(size, options) {
298
+ const s = vec3(size, 'sdf box size');
299
+ if (!s.every(v => v > 0))
300
+ throw invalid('sdf box size');
301
+ const round = options?.round === undefined ? 0 : nonNegative(options.round, 'sdf box round');
302
+ return new Box(s, Math.min(round, Math.min(s[0], s[1], s[2]) / 2), options);
303
+ }
304
+ /** A stretched ball with `radii` [x, y, z]: heads, bodies, eggs and stones. */
305
+ export function sdfEllipsoid(radii, options) {
306
+ const r = vec3(radii, 'sdf ellipsoid radii');
307
+ if (!r.every(v => v > 0))
308
+ throw invalid('sdf ellipsoid radii');
309
+ return new Ellipsoid(r, options);
310
+ }
311
+ /**
312
+ * A rounded limb from `from` to `to`: `radius` thick at the start, `radiusEnd` (the same unless given) at the end.
313
+ * Arms, legs, necks, tails, branches and horns.
314
+ */
315
+ export function sdfCapsule(from, to, radius, options) {
316
+ const r1 = positive(radius, 'sdf capsule radius');
317
+ const r2 = options?.radiusEnd === undefined ? r1 : positive(options.radiusEnd, 'sdf capsule radiusEnd');
318
+ return new RoundCone(vec3(from, 'sdf capsule from'), vec3(to, 'sdf capsule to'), r1, r2, options);
319
+ }
320
+ /** An upright cylinder of `radius` and `height` along y, its rims rounded by `round` (at most the radius or half the height). */
321
+ export function sdfCylinder(radius, height, options) {
322
+ const r = positive(radius, 'sdf cylinder radius'), h = positive(height, 'sdf cylinder height');
323
+ const round = options?.round === undefined ? 0 : nonNegative(options.round, 'sdf cylinder round');
324
+ return new Cylinder(r, h, Math.min(round, r, h / 2), options);
325
+ }
326
+ /** An upright cone of `height` along y, `bottom` wide at its foot and `top` (0 for a point) at its head. */
327
+ export function sdfCone(bottom, top, height, options) {
328
+ const r1 = nonNegative(bottom, 'sdf cone bottom'), r2 = nonNegative(top, 'sdf cone top');
329
+ if (r1 === 0 && r2 === 0)
330
+ throw invalid('sdf cone radii');
331
+ return new Cone(r1, r2, positive(height, 'sdf cone height'), options);
332
+ }
333
+ /** A ring lying flat: `radius` to the middle of the tube, `tube` the tube's radius. */
334
+ export function sdfTorus(radius, tube, options) {
335
+ return new Torus(positive(radius, 'sdf torus radius'), positive(tube, 'sdf torus tube'), options);
336
+ }
337
+ function points2(list, what) {
338
+ if (!Array.isArray(list) || list.length < 3)
339
+ throw invalid(what);
340
+ for (const p of list)
341
+ if (!Array.isArray(p) || p.length !== 2 || !p.every(Number.isFinite))
342
+ throw invalid(what);
343
+ return list;
344
+ }
345
+ /**
346
+ * The signed distance to a closed polygon in a plane: negative inside. With `axis`, edges lying on x = 0 are not
347
+ * surface: the axis a profile is turned about.
348
+ */
349
+ function polygon2(px, py, v, axis = false) {
350
+ let d = Infinity, s = 1;
351
+ for (let i = 0, j = v.length - 1; i < v.length; j = i, i++) {
352
+ const ex = v[j][0] - v[i][0], ey = v[j][1] - v[i][1];
353
+ const wx = px - v[i][0], wy = py - v[i][1];
354
+ if (!(axis && v[i][0] === 0 && v[j][0] === 0)) {
355
+ const t = clamp01((wx * ex + wy * ey) / (ex * ex + ey * ey || 1));
356
+ const bx = wx - ex * t, by = wy - ey * t;
357
+ d = Math.min(d, bx * bx + by * by);
358
+ }
359
+ const c1 = py >= v[i][1], c2 = py < v[j][1], c3 = ex * wy > ey * wx;
360
+ if ((c1 && c2 && c3) || (!c1 && !c2 && !c3))
361
+ s = -s;
362
+ }
363
+ return s * Math.sqrt(d);
364
+ }
365
+ class Lathe extends SdfShape3D {
366
+ #profile;
367
+ #round;
368
+ constructor(profile, round, options) {
369
+ let r = 0, y0 = Infinity, y1 = -Infinity;
370
+ for (const [pr, py] of profile) {
371
+ r = Math.max(r, pr);
372
+ y0 = Math.min(y0, py);
373
+ y1 = Math.max(y1, py);
374
+ }
375
+ super(options, [-r - round, y0 - round, -r - round, r + round, y1 + round, r + round]);
376
+ this.#profile = profile;
377
+ this.#round = round;
378
+ }
379
+ local(x, y, z) {
380
+ return polygon2(len2(x, z), y, this.#profile, true) - this.#round;
381
+ }
382
+ }
383
+ class Extrude extends SdfShape3D {
384
+ #outline;
385
+ #half;
386
+ #round;
387
+ constructor(outline, depth, round, options) {
388
+ let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
389
+ for (const [px, py] of outline) {
390
+ x0 = Math.min(x0, px);
391
+ y0 = Math.min(y0, py);
392
+ x1 = Math.max(x1, px);
393
+ y1 = Math.max(y1, py);
394
+ }
395
+ super(options, [x0, y0, -depth / 2, x1, y1, depth / 2]);
396
+ this.#outline = outline;
397
+ this.#half = depth / 2;
398
+ this.#round = round;
399
+ }
400
+ local(x, y, z) {
401
+ const r = this.#round;
402
+ // The outline shrunk by the rounding, then grown back round: edges and corners rounded by `round`.
403
+ const wx = polygon2(x, y, this.#outline) + r, wy = Math.abs(z) - this.#half + r;
404
+ return Math.min(Math.max(wx, wy), 0) + len2(Math.max(wx, 0), Math.max(wy, 0)) - r;
405
+ }
406
+ }
407
+ /**
408
+ * A shape turned about the y axis from its `profile`: points [radius, height] going round a closed outline, as a
409
+ * potter draws half a vase. Vases, bottles, pillars, bells, towers, lamp posts, chess pieces.
410
+ */
411
+ export function sdfLathe(profile, options) {
412
+ const points = points2(profile, 'sdf lathe profile');
413
+ if (points.some(p => p[0] < 0))
414
+ throw invalid('sdf lathe profile');
415
+ const round = options?.round === undefined ? 0 : nonNegative(options.round, 'sdf lathe round');
416
+ return new Lathe(points, round, options);
417
+ }
418
+ /**
419
+ * A flat `outline` of points [x, y] in the xy plane, closed, pushed `depth` deep along z about its middle, its
420
+ * edges rounded by `round`: signs, gables, blades, stars, letters, tiles, cut-out shapes.
421
+ */
422
+ export function sdfExtrude(outline, depth, options) {
423
+ const points = points2(outline, 'sdf extrude outline');
424
+ const d = positive(depth, 'sdf extrude depth');
425
+ const round = options?.round === undefined ? 0 : nonNegative(options.round, 'sdf extrude round');
426
+ return new Extrude(points, d, Math.min(round, d / 2), options);
427
+ }
428
+ // ---- joining ------------------------------------------------------------------------------------------------------
429
+ function shapes(list, what) {
430
+ const items = list instanceof SdfShape3D ? [list] : list;
431
+ if (!Array.isArray(items) || items.length === 0 || !items.every(item => item instanceof SdfShape3D))
432
+ throw invalid(what);
433
+ return items;
434
+ }
435
+ function smoothOf(options) {
436
+ return options?.smooth === undefined ? 0 : nonNegative(options.smooth, 'sdf smooth');
437
+ }
438
+ function unionBounds(list) {
439
+ const out = [Infinity, Infinity, Infinity, -Infinity, -Infinity, -Infinity];
440
+ for (const item of list)
441
+ for (let a = 0; a < 3; a++) {
442
+ out[a] = Math.min(out[a], item.bounds[a]);
443
+ out[a + 3] = Math.max(out[a + 3], item.bounds[a + 3]);
444
+ }
445
+ return out;
446
+ }
447
+ const mix3 = (out, a, b, t) => {
448
+ out[0] = a[0] + (b[0] - a[0]) * t;
449
+ out[1] = a[1] + (b[1] - a[1]) * t;
450
+ out[2] = a[2] + (b[2] - a[2]) * t;
451
+ };
452
+ class Union extends SdfShape3D {
453
+ #items;
454
+ #k;
455
+ constructor(items, k, options) {
456
+ super(options, grow(unionBounds(items), k * 0.25));
457
+ this.#items = items;
458
+ this.#k = k;
459
+ }
460
+ local(x, y, z) {
461
+ const k = this.#k;
462
+ let d = this.#items[0].distance(x, y, z);
463
+ for (let i = 1; i < this.#items.length; i++) {
464
+ const e = this.#items[i].distance(x, y, z);
465
+ if (k === 0)
466
+ d = Math.min(d, e);
467
+ else {
468
+ const h = clamp01(0.5 + (0.5 * (e - d)) / k);
469
+ d = e + (d - e) * h - k * h * (1 - h);
470
+ }
471
+ }
472
+ return d;
473
+ }
474
+ localColor(x, y, z, out, paint) {
475
+ const k = this.#k, other = new Float32Array(3);
476
+ this.#items[0].colorAt(x, y, z, out, paint);
477
+ let d = this.#items[0].distance(x, y, z);
478
+ for (let i = 1; i < this.#items.length; i++) {
479
+ const item = this.#items[i], e = item.distance(x, y, z);
480
+ item.colorAt(x, y, z, other, paint);
481
+ // h is the share of what is joined so far; 1 - h that of this shape.
482
+ const h = k === 0 ? (d <= e ? 1 : 0) : clamp01(0.5 + (0.5 * (e - d)) / k);
483
+ mix3(out, other, out, h);
484
+ d = k === 0 ? Math.min(d, e) : e + (d - e) * h - k * h * (1 - h);
485
+ }
486
+ }
487
+ }
488
+ class Subtract extends SdfShape3D {
489
+ #base;
490
+ #cut;
491
+ #k;
492
+ constructor(base, cut, k, options) {
493
+ super(options, grow(base.bounds, k * 0.25));
494
+ this.#base = base;
495
+ this.#cut = cut;
496
+ this.#k = k;
497
+ }
498
+ #step(d, c) {
499
+ const k = this.#k;
500
+ if (k === 0)
501
+ return -c > d ? [-c, 1] : [d, 0];
502
+ const h = clamp01(0.5 - (0.5 * (d + c)) / k);
503
+ return [d + (-c - d) * h + k * h * (1 - h), h];
504
+ }
505
+ local(x, y, z) {
506
+ let d = this.#base.distance(x, y, z);
507
+ for (const cut of this.#cut)
508
+ d = this.#step(d, cut.distance(x, y, z))[0];
509
+ return d;
510
+ }
511
+ localColor(x, y, z, out, paint) {
512
+ const other = new Float32Array(3);
513
+ this.#base.colorAt(x, y, z, out, paint);
514
+ let d = this.#base.distance(x, y, z);
515
+ for (const cut of this.#cut) {
516
+ const [next, h] = this.#step(d, cut.distance(x, y, z));
517
+ // A cut with its own colour paints the faces it leaves, as the inside of a mouth.
518
+ if (cut.paint !== undefined) {
519
+ cut.colorAt(x, y, z, other, paint);
520
+ mix3(out, out, other, h);
521
+ }
522
+ d = next;
523
+ }
524
+ }
525
+ }
526
+ class Intersect extends SdfShape3D {
527
+ #items;
528
+ #k;
529
+ constructor(items, k, options) {
530
+ const b = items[0].bounds.slice();
531
+ for (const item of items)
532
+ for (let a = 0; a < 3; a++) {
533
+ b[a] = Math.max(b[a], item.bounds[a]);
534
+ b[a + 3] = Math.min(b[a + 3], item.bounds[a + 3]);
535
+ }
536
+ for (let a = 0; a < 3; a++)
537
+ if (b[a] > b[a + 3])
538
+ b[a + 3] = b[a];
539
+ super(options, grow(b, k * 0.25));
540
+ this.#items = items;
541
+ this.#k = k;
542
+ }
543
+ local(x, y, z) {
544
+ const k = this.#k;
545
+ let d = this.#items[0].distance(x, y, z);
546
+ for (let i = 1; i < this.#items.length; i++) {
547
+ const e = this.#items[i].distance(x, y, z);
548
+ if (k === 0)
549
+ d = Math.max(d, e);
550
+ else {
551
+ const h = clamp01(0.5 - (0.5 * (e - d)) / k);
552
+ d = e + (d - e) * h + k * h * (1 - h);
553
+ }
554
+ }
555
+ return d;
556
+ }
557
+ localColor(x, y, z, out, paint) {
558
+ // Shapes with a colour paint what is kept; one without acts as a cutter and paints nothing, as a box that cuts a
559
+ // ring in half leaves the ring its colour on the cut faces too.
560
+ const k = this.#k, other = new Float32Array(3);
561
+ let d;
562
+ for (const item of this.#items) {
563
+ if (item.paint === undefined)
564
+ continue;
565
+ const e = item.distance(x, y, z);
566
+ if (d === undefined) {
567
+ item.colorAt(x, y, z, out, paint);
568
+ d = e;
569
+ continue;
570
+ }
571
+ item.colorAt(x, y, z, other, paint);
572
+ const h = k === 0 ? (d >= e ? 1 : 0) : clamp01(0.5 - (0.5 * (e - d)) / k);
573
+ mix3(out, other, out, h);
574
+ d = k === 0 ? Math.max(d, e) : e + (d - e) * h + k * h * (1 - h);
575
+ }
576
+ if (d === undefined)
577
+ this.#items[0].colorAt(x, y, z, out, paint);
578
+ }
579
+ }
580
+ class Mirror extends SdfShape3D {
581
+ #shape;
582
+ #axis;
583
+ constructor(shape, axis, options) {
584
+ const b = shape.bounds.slice();
585
+ const m = Math.max(Math.abs(b[axis]), Math.abs(b[axis + 3]));
586
+ b[axis] = -m;
587
+ b[axis + 3] = m;
588
+ super(options, b);
589
+ this.#shape = shape;
590
+ this.#axis = axis;
591
+ }
592
+ #fold(x, y, z) {
593
+ return this.#axis === 0 ? [Math.abs(x), y, z] : this.#axis === 1 ? [x, Math.abs(y), z] : [x, y, Math.abs(z)];
594
+ }
595
+ local(x, y, z) {
596
+ const p = this.#fold(x, y, z);
597
+ return this.#shape.distance(p[0], p[1], p[2]);
598
+ }
599
+ localColor(x, y, z, out, paint) {
600
+ const p = this.#fold(x, y, z);
601
+ this.#shape.colorAt(p[0], p[1], p[2], out, paint);
602
+ }
603
+ }
604
+ class Modify extends SdfShape3D {
605
+ #shape;
606
+ #change;
607
+ constructor(shape, by, change, options) {
608
+ super(options, grow(shape.bounds, by));
609
+ this.#shape = shape;
610
+ this.#change = change;
611
+ }
612
+ local(x, y, z) {
613
+ return this.#change(this.#shape.distance(x, y, z), x, y, z);
614
+ }
615
+ localColor(x, y, z, out, paint) {
616
+ this.#shape.colorAt(x, y, z, out, paint);
617
+ }
618
+ }
619
+ /** The shapes joined into one; with `smooth`, blended where they meet. */
620
+ export function sdfUnion(items, options) {
621
+ return new Union(shapes(items, 'sdf union shapes'), smoothOf(options), options);
622
+ }
623
+ /**
624
+ * `base` with `cut` taken away; with `smooth`, the edges of the hollow rounded. A cut that has a colour paints the
625
+ * faces it leaves, as the inside of a mouth or a window.
626
+ */
627
+ export function sdfSubtract(base, cut, options) {
628
+ return new Subtract(shapes(base, 'sdf subtract base')[0], shapes(cut, 'sdf subtract cut'), smoothOf(options), options);
629
+ }
630
+ /**
631
+ * What the shapes have in common; with `smooth`, its edges rounded. The shapes with a colour paint it, cut faces
632
+ * included; a shape without one only cuts.
633
+ */
634
+ export function sdfIntersect(items, options) {
635
+ return new Intersect(shapes(items, 'sdf intersect shapes'), smoothOf(options), options);
636
+ }
637
+ /**
638
+ * The shape and its mirror image across the plane through the origin square to `axis` ('x' unless given): make one
639
+ * eye, ear, arm or leg on the positive side and get the pair.
640
+ */
641
+ export function sdfMirror(shape, options) {
642
+ const axis = options?.axis ?? 'x';
643
+ if (axis !== 'x' && axis !== 'y' && axis !== 'z')
644
+ throw invalid('sdf mirror axis');
645
+ return new Mirror(shapes(shape, 'sdf mirror shape')[0], axis === 'x' ? 0 : axis === 'y' ? 1 : 2, options);
646
+ }
647
+ /** The shape grown by `radius` all round, its edges rounded by as much. */
648
+ export function sdfRound(shape, radius, options) {
649
+ const r = nonNegative(radius, 'sdf round radius');
650
+ return new Modify(shapes(shape, 'sdf round shape')[0], r, d => d - r, options);
651
+ }
652
+ /** A hollow skin of the shape, `thickness` thick: bowls, pots, helmets, when cut open. */
653
+ export function sdfShell(shape, thickness, options) {
654
+ const t = positive(thickness, 'sdf shell thickness') / 2;
655
+ return new Modify(shapes(shape, 'sdf shell shape')[0], t, d => Math.abs(d) - t, options);
656
+ }
657
+ /** The surface pushed in and out by smooth noise: rocks, bark, rough earth, a lumpy creature. */
658
+ export function sdfDisplace(shape, options) {
659
+ if (options === null || typeof options !== 'object')
660
+ throw invalid('sdf displace options');
661
+ const amount = nonNegative(options.amount, 'sdf displace amount');
662
+ const f = options.frequency === undefined ? 4 : positive(options.frequency, 'sdf displace frequency');
663
+ const seed = options.seed === undefined ? 0 : Math.floor(requireNumber(options.seed, 'sdf displace seed'));
664
+ // The surface only: placing and painting belong to the shape displaced.
665
+ return new Modify(shapes(shape, 'sdf displace shape')[0], amount, (d, x, y, z) => {
666
+ return d + amount * noise3(x * f, y * f, z * f, seed);
667
+ });
668
+ }
669
+ class Paint extends SdfShape3D {
670
+ #shape;
671
+ #share;
672
+ #color;
673
+ constructor(shape, color, share) {
674
+ super(undefined, shape.bounds);
675
+ this.#shape = shape;
676
+ this.#share = share;
677
+ this.#color = color;
678
+ }
679
+ local(x, y, z) {
680
+ return this.#shape.distance(x, y, z);
681
+ }
682
+ localColor(x, y, z, out, paint) {
683
+ this.#shape.colorAt(x, y, z, out, paint);
684
+ mix3(out, out, this.#color, clamp01(this.#share(x, y, z)));
685
+ }
686
+ }
687
+ const smooth01 = (edge0, edge1, x) => {
688
+ const t = clamp01((x - edge0) / (edge1 - edge0));
689
+ return t * t * (3 - 2 * t);
690
+ };
691
+ /**
692
+ * `shape` with a pattern painted over its colours, in the coordinates of the model; the surface does not move. The
693
+ * pattern is written into vertex colours, so it is as fine as the mesh: keep `frequency` at a few per unit.
694
+ */
695
+ export function sdfPattern(shape, options) {
696
+ const base = shapes(shape, 'sdf pattern shape')[0];
697
+ if (options === null || typeof options !== 'object')
698
+ throw invalid('sdf pattern options');
699
+ const color = linear(options.color, 'sdf pattern color');
700
+ const f = options.frequency === undefined ? 4 : positive(options.frequency, 'sdf pattern frequency');
701
+ const amount = options.amount === undefined ? 1 : nonNegative(options.amount, 'sdf pattern amount');
702
+ if (amount > 1)
703
+ throw invalid('sdf pattern amount');
704
+ const axisName = options.axis ?? 'y';
705
+ if (axisName !== 'x' && axisName !== 'y' && axisName !== 'z')
706
+ throw invalid('sdf pattern axis');
707
+ const axis = axisName === 'x' ? 0 : axisName === 'y' ? 1 : 2;
708
+ const seed = options.seed === undefined ? 0 : Math.floor(requireNumber(options.seed, 'sdf pattern seed'));
709
+ const pick = (x, y, z) => (axis === 0 ? x : axis === 1 ? y : z);
710
+ let share;
711
+ switch (options.kind) {
712
+ case 'spots': {
713
+ const size = options.size === undefined ? 0.35 : positive(options.size, 'sdf pattern size');
714
+ if (size > 1)
715
+ throw invalid('sdf pattern size');
716
+ share = (x, y, z) => {
717
+ // The nearest of one jittered point per unit cell.
718
+ const px = x * f, py = y * f, pz = z * f;
719
+ const cx = Math.floor(px), cy = Math.floor(py), cz = Math.floor(pz);
720
+ let best = Infinity;
721
+ for (let i = -1; i <= 1; i++)
722
+ for (let j = -1; j <= 1; j++)
723
+ for (let k = -1; k <= 1; k++) {
724
+ const qx = cx + i + 0.5 + 0.4 * hash3(cx + i, cy + j, cz + k, seed), qy = cy + j + 0.5 + 0.4 * hash3(cx + i, cy + j, cz + k, seed + 1), qz = cz + k + 0.5 + 0.4 * hash3(cx + i, cy + j, cz + k, seed + 2);
725
+ best = Math.min(best, len3(px - qx, py - qy, pz - qz));
726
+ }
727
+ const r = size * 0.5;
728
+ return amount * (1 - smooth01(r * 0.6, r, best));
729
+ };
730
+ break;
731
+ }
732
+ case 'stripes': {
733
+ const size = options.size === undefined ? 0.5 : positive(options.size, 'sdf pattern size');
734
+ if (size > 1)
735
+ throw invalid('sdf pattern size');
736
+ share = (x, y, z) => {
737
+ const t = pick(x, y, z) * f + 0.15 * noise3(x * f * 0.5, y * f * 0.5, z * f * 0.5, seed);
738
+ const u = t - Math.floor(t);
739
+ // Edges soft over a sixth of a stripe: vertex colours cannot hold a line finer than the triangles.
740
+ const edge = Math.min(0.15, size / 3);
741
+ return amount * smooth01(0, edge, u) * (1 - smooth01(size - edge, size, u));
742
+ };
743
+ break;
744
+ }
745
+ case 'noise':
746
+ share = (x, y, z) => amount * smooth01(-0.15, 0.25, noise3(x * f, y * f, z * f, seed));
747
+ break;
748
+ case 'gradient': {
749
+ const from = options.from === undefined ? base.bounds[axis] : requireNumber(options.from, 'sdf pattern from');
750
+ const to = options.to === undefined ? base.bounds[axis + 3] : requireNumber(options.to, 'sdf pattern to');
751
+ if (from === to)
752
+ throw invalid('sdf pattern from');
753
+ share = (x, y, z) => amount * smooth01(0, 1, (pick(x, y, z) - from) / (to - from));
754
+ break;
755
+ }
756
+ default:
757
+ throw invalid('sdf pattern kind');
758
+ }
759
+ return new Paint(base, color, share);
760
+ }
761
+ function requireNumber(value, what) {
762
+ if (typeof value !== 'number' || !Number.isFinite(value))
763
+ throw invalid(what);
764
+ return value;
765
+ }
766
+ // ---- noise --------------------------------------------------------------------------------------------------------
767
+ function hash3(x, y, z, seed) {
768
+ let h = Math.imul(x, 374761393) ^ Math.imul(y, 668265263) ^ Math.imul(z, 2147483647) ^ Math.imul(seed, 1274126177);
769
+ h = Math.imul(h ^ (h >>> 13), 1274126177);
770
+ h ^= h >>> 16;
771
+ return (h & 0xffffff) / 0x7fffff - 1;
772
+ }
773
+ /** Smooth value noise in [-1, 1]. */
774
+ function noise3(x, y, z, seed) {
775
+ const ix = Math.floor(x), iy = Math.floor(y), iz = Math.floor(z);
776
+ const fx = x - ix, fy = y - iy, fz = z - iz;
777
+ const ux = fx * fx * (3 - 2 * fx), uy = fy * fy * (3 - 2 * fy), uz = fz * fz * (3 - 2 * fz);
778
+ const lerp = (a, b, t) => a + (b - a) * t;
779
+ const c = (dx, dy, dz) => hash3(ix + dx, iy + dy, iz + dz, seed);
780
+ return lerp(lerp(lerp(c(0, 0, 0), c(1, 0, 0), ux), lerp(c(0, 1, 0), c(1, 1, 0), ux), uy), lerp(lerp(c(0, 0, 1), c(1, 0, 1), ux), lerp(c(0, 1, 1), c(1, 1, 1), ux), uy), uz);
781
+ }
782
+ const MAX_RESOLUTION = 192;
783
+ /**
784
+ * The mesh of the field's surface, with smooth normals and linear vertex colours (draw it with a material that has
785
+ * `vertexColors: true`). Made once, when a level or a model is set up: at the default resolution a model takes a few
786
+ * tens of milliseconds.
787
+ */
788
+ export function createSdfGeometry3D(shape, options = {}) {
789
+ if (!(shape instanceof SdfShape3D))
790
+ throw invalid('sdf shape');
791
+ if (options === null || typeof options !== 'object')
792
+ throw invalid('sdf mesh options');
793
+ const resolution = options.resolution === undefined ? 64 : options.resolution;
794
+ if (!Number.isInteger(resolution) || resolution < 8)
795
+ throw invalid('sdf mesh resolution');
796
+ if (resolution > MAX_RESOLUTION)
797
+ throw new World3DError('WORLD3D_BUDGET', 'sdf mesh resolution');
798
+ const occlusion = options.occlusion === undefined ? 0.7 : nonNegative(options.occlusion, 'sdf mesh occlusion');
799
+ if (occlusion > 1)
800
+ throw invalid('sdf mesh occlusion');
801
+ const variation = options.variation;
802
+ let varAmount = 0, varFrequency = 3, varSeed = 0;
803
+ if (variation !== undefined) {
804
+ if (variation === null || typeof variation !== 'object')
805
+ throw invalid('sdf mesh variation');
806
+ varAmount = nonNegative(variation.amount, 'sdf mesh variation amount');
807
+ if (variation.frequency !== undefined)
808
+ varFrequency = positive(variation.frequency, 'sdf mesh variation frequency');
809
+ if (variation.seed !== undefined)
810
+ varSeed = Math.floor(requireNumber(variation.seed, 'sdf mesh variation seed'));
811
+ }
812
+ let edgeAmount = 0, edgeColor;
813
+ if (options.edges !== undefined) {
814
+ if (options.edges === null || typeof options.edges !== 'object')
815
+ throw invalid('sdf mesh edges');
816
+ edgeAmount = nonNegative(options.edges.amount, 'sdf mesh edges amount');
817
+ if (edgeAmount > 1)
818
+ throw invalid('sdf mesh edges amount');
819
+ if (options.edges.color !== undefined)
820
+ edgeColor = linear(options.edges.color, 'sdf mesh edges color');
821
+ }
822
+ let crease = 0;
823
+ if (options.sharp !== undefined && options.sharp !== false) {
824
+ crease = options.sharp === true ? 40 : positive(options.sharp, 'sdf mesh sharp');
825
+ if (crease >= 180)
826
+ throw invalid('sdf mesh sharp');
827
+ }
828
+ const triangles = options.triangles === undefined ? 8000 : options.triangles;
829
+ if (!Number.isInteger(triangles) || triangles < 0)
830
+ throw invalid('sdf mesh triangles');
831
+ const base = options.color === undefined ? new Float32Array([1, 1, 1]) : linear(options.color, 'sdf mesh color');
832
+ const b = shape.bounds;
833
+ if (!b.every(Number.isFinite))
834
+ throw invalid('sdf shape bounds');
835
+ const size = Math.max(b[3] - b[0], b[4] - b[1], b[5] - b[2]);
836
+ if (!(size > 0))
837
+ throw invalid('sdf shape bounds');
838
+ const cell = size / resolution;
839
+ const radius = options.occlusionRadius === undefined
840
+ ? Math.max(size * 0.1, cell * 2)
841
+ : positive(options.occlusionRadius, 'sdf mesh occlusionRadius');
842
+ // One cell of room on every side, so a surface touching the bounds is closed.
843
+ const ox = b[0] - cell * 1.5, oy = b[1] - cell * 1.5, oz = b[2] - cell * 1.5;
844
+ const nx = Math.ceil((b[3] - b[0]) / cell) + 3, ny = Math.ceil((b[4] - b[1]) / cell) + 3, nz = Math.ceil((b[5] - b[2]) / cell) + 3;
845
+ const sx = nx + 1, sxy = (nx + 1) * (ny + 1);
846
+ const field = new Float32Array(sxy * (nz + 1));
847
+ // Blocks of corners far from the surface take the distance at their centre: only its sign is read there, since a
848
+ // corner of a cell the surface crosses is never more than two cells from it.
849
+ const B = 4, reach = (Math.sqrt(3) * B * cell) / 2 + cell * 2;
850
+ for (let bk = 0; bk <= nz; bk += B)
851
+ for (let bj = 0; bj <= ny; bj += B)
852
+ for (let bi = 0; bi <= nx; bi += B) {
853
+ const ek = Math.min(bk + B, nz + 1), ej = Math.min(bj + B, ny + 1), ei = Math.min(bi + B, nx + 1);
854
+ const centre = shape.distance(ox + ((bi + ei - 1) / 2) * cell, oy + ((bj + ej - 1) / 2) * cell, oz + ((bk + ek - 1) / 2) * cell);
855
+ const far = Math.abs(centre) > reach;
856
+ for (let k = bk; k < ek; k++)
857
+ for (let j = bj; j < ej; j++)
858
+ for (let i = bi; i < ei; i++)
859
+ field[i + j * sx + k * sxy] = far ? centre : shape.distance(ox + i * cell, oy + j * cell, oz + k * cell);
860
+ }
861
+ const at = (i, j, k) => field[i + j * sx + k * sxy];
862
+ const cellIndex = new Int32Array(nx * ny * nz).fill(-1);
863
+ const positions = [];
864
+ const corner = new Float64Array(8);
865
+ const EDGES = [
866
+ [0, 1],
867
+ [2, 3],
868
+ [4, 5],
869
+ [6, 7],
870
+ [0, 2],
871
+ [1, 3],
872
+ [4, 6],
873
+ [5, 7],
874
+ [0, 4],
875
+ [1, 5],
876
+ [2, 6],
877
+ [3, 7]
878
+ ];
879
+ const grad = (x, y, z) => {
880
+ const e = cell * 0.5;
881
+ return [
882
+ shape.distance(x + e, y, z) - shape.distance(x - e, y, z),
883
+ shape.distance(x, y + e, z) - shape.distance(x, y - e, z),
884
+ shape.distance(x, y, z + e) - shape.distance(x, y, z - e)
885
+ ];
886
+ };
887
+ for (let k = 0; k < nz; k++)
888
+ for (let j = 0; j < ny; j++)
889
+ for (let i = 0; i < nx; i++) {
890
+ let inside = 0;
891
+ for (let c = 0; c < 8; c++) {
892
+ corner[c] = at(i + (c & 1), j + ((c >> 1) & 1), k + ((c >> 2) & 1));
893
+ if (corner[c] < 0)
894
+ inside++;
895
+ }
896
+ if (inside === 0 || inside === 8)
897
+ continue;
898
+ // The mean of the points where the surface crosses the cell's edges.
899
+ let px = 0, py = 0, pz = 0, n = 0;
900
+ for (const [a, c] of EDGES) {
901
+ const da = corner[a], dc = corner[c];
902
+ if (da < 0 === dc < 0)
903
+ continue;
904
+ const t = da / (da - dc);
905
+ px += (a & 1) + ((c & 1) - (a & 1)) * t;
906
+ py += ((a >> 1) & 1) + (((c >> 1) & 1) - ((a >> 1) & 1)) * t;
907
+ pz += ((a >> 2) & 1) + (((c >> 2) & 1) - ((a >> 2) & 1)) * t;
908
+ n++;
909
+ }
910
+ let x = ox + (i + px / n) * cell, y = oy + (j + py / n) * cell, z = oz + (k + pz / n) * cell;
911
+ if (crease > 0) {
912
+ // Dual contouring: the point nearest every tangent plane at the crossings, pulled a little towards their
913
+ // mean so a flat face (where the planes do not pin a point) stays put. It lands on a corner or an edge
914
+ // where the planes meet there.
915
+ const ata = new Float64Array(6), atb = new Float64Array(3);
916
+ for (const [a, c] of EDGES) {
917
+ const da = corner[a], dc = corner[c];
918
+ if (da < 0 === dc < 0)
919
+ continue;
920
+ const t = da / (da - dc);
921
+ const cx = ox + (i + (a & 1) + ((c & 1) - (a & 1)) * t) * cell, cy = oy + (j + ((a >> 1) & 1) + (((c >> 1) & 1) - ((a >> 1) & 1)) * t) * cell, cz = oz + (k + ((a >> 2) & 1) + (((c >> 2) & 1) - ((a >> 2) & 1)) * t) * cell;
922
+ const g = grad(cx, cy, cz), gl = Math.hypot(g[0], g[1], g[2]);
923
+ if (gl === 0)
924
+ continue;
925
+ const nx0 = g[0] / gl, ny0 = g[1] / gl, nz0 = g[2] / gl;
926
+ // Relative to the mean, so the solve works on small numbers.
927
+ const dot = nx0 * (cx - x) + ny0 * (cy - y) + nz0 * (cz - z);
928
+ ata[0] = ata[0] + nx0 * nx0;
929
+ ata[1] = ata[1] + nx0 * ny0;
930
+ ata[2] = ata[2] + nx0 * nz0;
931
+ ata[3] = ata[3] + ny0 * ny0;
932
+ ata[4] = ata[4] + ny0 * nz0;
933
+ ata[5] = ata[5] + nz0 * nz0;
934
+ atb[0] = atb[0] + nx0 * dot;
935
+ atb[1] = atb[1] + ny0 * dot;
936
+ atb[2] = atb[2] + nz0 * dot;
937
+ }
938
+ const pull = 0.05;
939
+ const m = solve3(ata[0] + pull, ata[1], ata[2], ata[3] + pull, ata[4], ata[5] + pull, atb[0], atb[1], atb[2]);
940
+ if (m !== undefined) {
941
+ x = Math.min(Math.max(x + m[0], ox + i * cell), ox + (i + 1) * cell);
942
+ y = Math.min(Math.max(y + m[1], oy + j * cell), oy + (j + 1) * cell);
943
+ z = Math.min(Math.max(z + m[2], oz + k * cell), oz + (k + 1) * cell);
944
+ }
945
+ }
946
+ // Onto the surface along the gradient, kept in the cell so a sharp edge cannot fold the mesh.
947
+ for (let step = 0; step < (crease > 0 ? 0 : 2); step++) {
948
+ const d = shape.distance(x, y, z), g = grad(x, y, z), gg = g[0] * g[0] + g[1] * g[1] + g[2] * g[2];
949
+ if (gg < 1e-20)
950
+ break;
951
+ const f = (d * cell) / gg;
952
+ x = Math.min(Math.max(x - g[0] * f, ox + i * cell), ox + (i + 1) * cell);
953
+ y = Math.min(Math.max(y - g[1] * f, oy + j * cell), oy + (j + 1) * cell);
954
+ z = Math.min(Math.max(z - g[2] * f, oz + k * cell), oz + (k + 1) * cell);
955
+ }
956
+ cellIndex[i + j * nx + k * nx * ny] = positions.length / 3;
957
+ positions.push(x, y, z);
958
+ }
959
+ const indices = [];
960
+ const cellOf = (i, j, k) => cellIndex[i + j * nx + k * nx * ny];
961
+ const quad = (a, b2, c, d, flip) => {
962
+ if (a < 0 || b2 < 0 || c < 0 || d < 0)
963
+ return;
964
+ if (flip)
965
+ indices.push(a, c, b2, a, d, c);
966
+ else
967
+ indices.push(a, b2, c, a, c, d);
968
+ };
969
+ for (let k = 1; k < nz; k++)
970
+ for (let j = 1; j < ny; j++)
971
+ for (let i = 0; i < nx; i++) {
972
+ const d0 = at(i, j, k), d1 = at(i + 1, j, k);
973
+ if (d0 < 0 === d1 < 0)
974
+ continue;
975
+ quad(cellOf(i, j - 1, k - 1), cellOf(i, j, k - 1), cellOf(i, j, k), cellOf(i, j - 1, k), !(d0 < 0));
976
+ }
977
+ for (let k = 1; k < nz; k++)
978
+ for (let j = 0; j < ny; j++)
979
+ for (let i = 1; i < nx; i++) {
980
+ const d0 = at(i, j, k), d1 = at(i, j + 1, k);
981
+ if (d0 < 0 === d1 < 0)
982
+ continue;
983
+ quad(cellOf(i - 1, j, k - 1), cellOf(i - 1, j, k), cellOf(i, j, k), cellOf(i, j, k - 1), !(d0 < 0));
984
+ }
985
+ for (let k = 0; k < nz; k++)
986
+ for (let j = 1; j < ny; j++)
987
+ for (let i = 1; i < nx; i++) {
988
+ const d0 = at(i, j, k), d1 = at(i, j, k + 1);
989
+ if (d0 < 0 === d1 < 0)
990
+ continue;
991
+ quad(cellOf(i - 1, j - 1, k), cellOf(i, j - 1, k), cellOf(i, j, k), cellOf(i - 1, j, k), !(d0 < 0));
992
+ }
993
+ const count = positions.length / 3;
994
+ const normals = new Float32Array(count * 3), colors = new Float32Array(count * 3), rgb = new Float32Array(3);
995
+ for (let v = 0; v < count; v++) {
996
+ const x = positions[v * 3], y = positions[v * 3 + 1], z = positions[v * 3 + 2];
997
+ const g = grad(x, y, z), gl = Math.hypot(g[0], g[1], g[2]) || 1;
998
+ const nxv = g[0] / gl, nyv = g[1] / gl, nzv = g[2] / gl;
999
+ normals[v * 3] = nxv;
1000
+ normals[v * 3 + 1] = nyv;
1001
+ normals[v * 3 + 2] = nzv;
1002
+ shape.colorAt(x, y, z, rgb, base);
1003
+ let shade = 1;
1004
+ if (occlusion > 0) {
1005
+ // How much of the space along the normal is taken by the model itself, near samples counting most.
1006
+ let blocked = 0, weight = 0, w = 1;
1007
+ for (let s = 1; s <= 5; s++) {
1008
+ const r = (radius * s) / 5, d = shape.distance(x + nxv * r, y + nyv * r, z + nzv * r);
1009
+ blocked += w * clamp01((r - d) / r);
1010
+ weight += w;
1011
+ w *= 0.7;
1012
+ }
1013
+ shade = 1 - occlusion * clamp01((blocked / weight) * 1.6);
1014
+ }
1015
+ if (varAmount > 0)
1016
+ shade *= 1 + varAmount * noise3(x * varFrequency, y * varFrequency, z * varFrequency, varSeed + 7919);
1017
+ if (edgeAmount > 0) {
1018
+ // How sharply the surface turns outward here: the field's Laplacian, about 2 / radius on a ball, measured a
1019
+ // cell and a half around, so only edges near the grid's own size count.
1020
+ const e = cell * 1.5, d0 = shape.distance(x, y, z);
1021
+ const lap = shape.distance(x + e, y, z) +
1022
+ shape.distance(x - e, y, z) +
1023
+ shape.distance(x, y + e, z) +
1024
+ shape.distance(x, y - e, z) +
1025
+ shape.distance(x, y, z + e) +
1026
+ shape.distance(x, y, z - e) -
1027
+ 6 * d0;
1028
+ const t = edgeAmount * smooth01(0.08, 0.5, lap / e);
1029
+ if (t > 0) {
1030
+ const target = edgeColor ??
1031
+ new Float32Array([
1032
+ Math.min(1, rgb[0] * 1.8 + 0.08),
1033
+ Math.min(1, rgb[1] * 1.8 + 0.08),
1034
+ Math.min(1, rgb[2] * 1.8 + 0.08)
1035
+ ]);
1036
+ mix3(rgb, rgb, target, t);
1037
+ }
1038
+ }
1039
+ colors[v * 3] = Math.max(0, rgb[0] * shade);
1040
+ colors[v * 3 + 1] = Math.max(0, rgb[1] * shade);
1041
+ colors[v * 3 + 2] = Math.max(0, rgb[2] * shade);
1042
+ }
1043
+ const geometry = new Geometry3D();
1044
+ geometry.setAttribute('position', new Attribute3D(Float32Array.from(positions), 3));
1045
+ geometry.setAttribute('normal', new Attribute3D(normals, 3));
1046
+ geometry.setAttribute('color', new Attribute3D(colors, 3));
1047
+ geometry.setIndex(count > 65535 ? Uint32Array.from(indices) : Uint16Array.from(indices));
1048
+ let result = geometry;
1049
+ if (triangles > 0 && indices.length / 3 > triangles) {
1050
+ result = simplifyGeometry3D(geometry, { triangles }).geometry;
1051
+ geometry.dispose();
1052
+ }
1053
+ if (crease === 0)
1054
+ return result;
1055
+ const split = creaseNormals(result, crease);
1056
+ result.dispose();
1057
+ return split;
1058
+ }
1059
+ /** The solution of a symmetric 3 x 3 system, or undefined when it has none to speak of. */
1060
+ function solve3(a, b, c, d, e, f, x, y, z) {
1061
+ // [a b c; b d e; c e f] v = [x y z], by Cramer's rule.
1062
+ const det = a * (d * f - e * e) - b * (b * f - e * c) + c * (b * e - d * c);
1063
+ if (Math.abs(det) < 1e-12)
1064
+ return undefined;
1065
+ return [
1066
+ (x * (d * f - e * e) - b * (y * f - e * z) + c * (y * e - d * z)) / det,
1067
+ (a * (y * f - e * z) - x * (b * f - e * c) + c * (b * z - y * c)) / det,
1068
+ (a * (d * z - y * e) - b * (b * z - y * c) + x * (b * e - d * c)) / det
1069
+ ];
1070
+ }
1071
+ /**
1072
+ * A copy of a triangle geometry whose normals are those of its faces, averaged only over faces that meet at less than
1073
+ * `degrees`: a vertex on an edge is split into one per side, so the edge shades sharp.
1074
+ */
1075
+ function creaseNormals(geometry, degrees) {
1076
+ const P = geometry.getAttribute('position').data, I = geometry.index.data;
1077
+ const faces = I.length / 3;
1078
+ const fn = new Float64Array(faces * 3), area = new Float64Array(faces);
1079
+ for (let f = 0; f < faces; f++) {
1080
+ const a = I[f * 3], b = I[f * 3 + 1], c = I[f * 3 + 2];
1081
+ const ux = P[b * 3] - P[a * 3], uy = P[b * 3 + 1] - P[a * 3 + 1], uz = P[b * 3 + 2] - P[a * 3 + 2], vx = P[c * 3] - P[a * 3], vy = P[c * 3 + 1] - P[a * 3 + 1], vz = P[c * 3 + 2] - P[a * 3 + 2];
1082
+ const nx = uy * vz - uz * vy, ny = uz * vx - ux * vz, nz = ux * vy - uy * vx;
1083
+ const l = Math.hypot(nx, ny, nz) || 1;
1084
+ fn[f * 3] = nx / l;
1085
+ fn[f * 3 + 1] = ny / l;
1086
+ fn[f * 3 + 2] = nz / l;
1087
+ area[f] = l / 2;
1088
+ }
1089
+ const around = Array.from({ length: P.length / 3 }, () => []);
1090
+ for (let f = 0; f < faces; f++)
1091
+ for (let k = 0; k < 3; k++)
1092
+ around[I[f * 3 + k]].push(f);
1093
+ const limit = Math.cos((degrees * Math.PI) / 180);
1094
+ const order = [], normals = [], index = new Uint32Array(I.length);
1095
+ const made = new Map();
1096
+ for (let f = 0; f < faces; f++)
1097
+ for (let k = 0; k < 3; k++) {
1098
+ const v = I[f * 3 + k];
1099
+ let nx = 0, ny = 0, nz = 0;
1100
+ for (const g of around[v]) {
1101
+ if (fn[f * 3] * fn[g * 3] + fn[f * 3 + 1] * fn[g * 3 + 1] + fn[f * 3 + 2] * fn[g * 3 + 2] < limit)
1102
+ continue;
1103
+ nx += fn[g * 3] * area[g];
1104
+ ny += fn[g * 3 + 1] * area[g];
1105
+ nz += fn[g * 3 + 2] * area[g];
1106
+ }
1107
+ const l = Math.hypot(nx, ny, nz) || 1;
1108
+ nx /= l;
1109
+ ny /= l;
1110
+ nz /= l;
1111
+ const key = v + ':' + Math.round(nx * 1e4) + ',' + Math.round(ny * 1e4) + ',' + Math.round(nz * 1e4);
1112
+ let at = made.get(key);
1113
+ if (at === undefined) {
1114
+ at = order.length;
1115
+ made.set(key, at);
1116
+ order.push(v);
1117
+ normals.push(nx, ny, nz);
1118
+ }
1119
+ index[f * 3 + k] = at;
1120
+ }
1121
+ const out = new Geometry3D();
1122
+ for (const [name, attribute] of geometry.attributes) {
1123
+ if (name === 'normal')
1124
+ continue;
1125
+ const size = attribute.itemSize, data = attribute.data;
1126
+ const copy = new data.constructor(order.length * size);
1127
+ for (let i = 0; i < order.length; i++)
1128
+ for (let c = 0; c < size; c++)
1129
+ copy[i * size + c] = data[order[i] * size + c];
1130
+ out.setAttribute(name, new Attribute3D(copy, size, attribute.normalized));
1131
+ }
1132
+ out.setAttribute('normal', new Attribute3D(Float32Array.from(normals), 3));
1133
+ out.setIndex(order.length > 65535 ? index : Uint16Array.from(index));
1134
+ return out;
1135
+ }
1136
+ //# sourceMappingURL=Sdf3D.js.map