@egret/engine 7.0.1-rc.3 → 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 (304) hide show
  1. package/dist/Engine.js +7 -2
  2. package/dist/animation/sequenceResetTypes.d.ts +6 -0
  3. package/dist/animation/types.d.ts +6 -0
  4. package/dist/assetBundle.d.ts +2 -0
  5. package/dist/assetGroupTypes.d.ts +2 -0
  6. package/dist/audioCues.d.ts +4 -0
  7. package/dist/audioTypes.d.ts +13 -0
  8. package/dist/bitmapButtonTypes.d.ts +2 -0
  9. package/dist/bitmapFontTypes.d.ts +3 -0
  10. package/dist/bitmapResourceSlot.d.ts +1 -0
  11. package/dist/camera2d.js +10 -2
  12. package/dist/cameraTypes.d.ts +12 -0
  13. package/dist/contentTypes.d.ts +2 -0
  14. package/dist/createEngineForProfile.js +8 -5
  15. package/dist/fontContentTypes.d.ts +5 -0
  16. package/dist/gameClockTypes.d.ts +6 -0
  17. package/dist/gameRun.d.ts +3 -0
  18. package/dist/gamepadTypes.d.ts +8 -0
  19. package/dist/hoverInputTypes.d.ts +10 -0
  20. package/dist/index.d.ts +5 -2
  21. package/dist/index.js +2 -1
  22. package/dist/inputActions.d.ts +5 -0
  23. package/dist/internal/uiFactoryState.d.ts +4 -0
  24. package/dist/internal/uiFactoryState.js +18 -2
  25. package/dist/keyboardInput.d.ts +1 -0
  26. package/dist/keyboardInput.js +1 -0
  27. package/dist/keyboardInputTypes.d.ts +12 -0
  28. package/dist/kit.d.ts +3 -1
  29. package/dist/kit.js +2 -1
  30. package/dist/manifestResourceState.d.ts +1 -0
  31. package/dist/manifestResourceState.js +1 -0
  32. package/dist/manifestResourceTypes.d.ts +1 -0
  33. package/dist/motion.d.ts +2 -0
  34. package/dist/mouseInputTypes.d.ts +4 -0
  35. package/dist/particleEmitter.js +8 -0
  36. package/dist/particleTypes.d.ts +8 -0
  37. package/dist/physics2d.d.ts +2 -2
  38. package/dist/physics2d.js +1 -1
  39. package/dist/physics2dTypes.d.ts +55 -1
  40. package/dist/physics2dWorld.js +209 -9
  41. package/dist/pointerInput.d.ts +1 -0
  42. package/dist/pointerInput.js +1 -0
  43. package/dist/pointerInputTypes.d.ts +3 -0
  44. package/dist/random.d.ts +1 -0
  45. package/dist/rendering/packSharedDraws2D.js +53 -5
  46. package/dist/rendering/prepareSharedDraws2D.d.ts +2 -0
  47. package/dist/rendering/prepareSharedDraws2D.js +17 -6
  48. package/dist/rendering/sharedColor2D.d.ts +35 -1
  49. package/dist/rendering/sharedColor2D.js +131 -8
  50. package/dist/rendering/sharedEffects2D.js +16 -8
  51. package/dist/rendering/world3d/Animation3D.d.ts +9 -0
  52. package/dist/rendering/world3d/Animation3D.js +4 -0
  53. package/dist/rendering/world3d/AnimationTexture3D.d.ts +6 -0
  54. package/dist/rendering/world3d/AnimationTexture3D.js +2 -0
  55. package/dist/rendering/world3d/Batch3D.d.ts +4 -0
  56. package/dist/rendering/world3d/Batch3D.js +3 -0
  57. package/dist/rendering/world3d/Camera3D.d.ts +5 -0
  58. package/dist/rendering/world3d/Camera3D.js +3 -0
  59. package/dist/rendering/world3d/Character3D.d.ts +4 -0
  60. package/dist/rendering/world3d/Character3D.js +2 -0
  61. package/dist/rendering/world3d/Cloth3D.d.ts +18 -3
  62. package/dist/rendering/world3d/Cloth3D.js +6 -1
  63. package/dist/rendering/world3d/Compression3D.d.ts +1 -0
  64. package/dist/rendering/world3d/Compression3D.js +1 -0
  65. package/dist/rendering/world3d/Curves3D.d.ts +8 -0
  66. package/dist/rendering/world3d/Curves3D.js +5 -0
  67. package/dist/rendering/world3d/Decal3D.d.ts +2 -0
  68. package/dist/rendering/world3d/Decal3D.js +1 -0
  69. package/dist/rendering/world3d/Export3D.d.ts +13 -0
  70. package/dist/rendering/world3d/Export3D.js +263 -0
  71. package/dist/rendering/world3d/Geometry3D.d.ts +11 -1
  72. package/dist/rendering/world3d/Geometry3D.js +10 -1
  73. package/dist/rendering/world3d/GeometryBuilder3D.d.ts +2 -0
  74. package/dist/rendering/world3d/Gizmo3D.d.ts +5 -0
  75. package/dist/rendering/world3d/Gizmo3D.js +2 -0
  76. package/dist/rendering/world3d/Gltf3D.d.ts +6 -0
  77. package/dist/rendering/world3d/Gltf3D.js +25 -5
  78. package/dist/rendering/world3d/GpuParticles3D.d.ts +2 -0
  79. package/dist/rendering/world3d/GpuParticles3D.js +1 -0
  80. package/dist/rendering/world3d/Hdr3D.d.ts +2 -0
  81. package/dist/rendering/world3d/Hdr3D.js +1 -0
  82. package/dist/rendering/world3d/Jelly3D.d.ts +2 -0
  83. package/dist/rendering/world3d/Jelly3D.js +1 -0
  84. package/dist/rendering/world3d/Ktx23D.d.ts +3 -0
  85. package/dist/rendering/world3d/Light3D.d.ts +9 -0
  86. package/dist/rendering/world3d/Light3D.js +4 -0
  87. package/dist/rendering/world3d/Material3D.d.ts +10 -0
  88. package/dist/rendering/world3d/Material3D.js +2 -0
  89. package/dist/rendering/world3d/Mesh3D.d.ts +4 -0
  90. package/dist/rendering/world3d/Mesh3D.js +16 -2
  91. package/dist/rendering/world3d/Meshopt3D.d.ts +3 -0
  92. package/dist/rendering/world3d/Meshopt3D.js +1 -0
  93. package/dist/rendering/world3d/Navigation3D.d.ts +41 -1
  94. package/dist/rendering/world3d/Navigation3D.js +74 -2
  95. package/dist/rendering/world3d/Object3D.d.ts +11 -0
  96. package/dist/rendering/world3d/Object3D.js +10 -0
  97. package/dist/rendering/world3d/Particles3D.d.ts +5 -0
  98. package/dist/rendering/world3d/Particles3D.js +3 -0
  99. package/dist/rendering/world3d/Physics3D.d.ts +14 -0
  100. package/dist/rendering/world3d/Physics3D.js +5 -0
  101. package/dist/rendering/world3d/PhysicsHull3D.d.ts +2 -0
  102. package/dist/rendering/world3d/PhysicsHull3D.js +2 -0
  103. package/dist/rendering/world3d/PhysicsMesh3D.d.ts +2 -0
  104. package/dist/rendering/world3d/PhysicsMesh3D.js +2 -0
  105. package/dist/rendering/world3d/PhysicsRemote3D.d.ts +5 -0
  106. package/dist/rendering/world3d/PhysicsRemote3D.js +2 -0
  107. package/dist/rendering/world3d/Ragdoll3D.d.ts +5 -0
  108. package/dist/rendering/world3d/Ragdoll3D.js +2 -0
  109. package/dist/rendering/world3d/Raycast3D.d.ts +3 -0
  110. package/dist/rendering/world3d/Raycast3D.js +1 -0
  111. package/dist/rendering/world3d/RenderList3D.d.ts +3 -0
  112. package/dist/rendering/world3d/RenderList3D.js +12 -0
  113. package/dist/rendering/world3d/Retarget3D.d.ts +1 -0
  114. package/dist/rendering/world3d/Rig3D.d.ts +57 -0
  115. package/dist/rendering/world3d/Rig3D.js +219 -0
  116. package/dist/rendering/world3d/Sdf3D.d.ts +181 -0
  117. package/dist/rendering/world3d/Sdf3D.js +1136 -0
  118. package/dist/rendering/world3d/SdfLod3D.d.ts +17 -0
  119. package/dist/rendering/world3d/SdfLod3D.js +56 -0
  120. package/dist/rendering/world3d/Serialize3D.d.ts +17 -0
  121. package/dist/rendering/world3d/Serialize3D.js +22 -0
  122. package/dist/rendering/world3d/Simplify3D.d.ts +29 -0
  123. package/dist/rendering/world3d/Simplify3D.js +426 -0
  124. package/dist/rendering/world3d/StateMachine3D.d.ts +9 -0
  125. package/dist/rendering/world3d/StateMachine3D.js +3 -0
  126. package/dist/rendering/world3d/SurfaceMaterial3D.d.ts +26 -0
  127. package/dist/rendering/world3d/SurfaceMaterial3D.js +138 -0
  128. package/dist/rendering/world3d/Terrain3D.d.ts +21 -0
  129. package/dist/rendering/world3d/Terrain3D.js +25 -1
  130. package/dist/rendering/world3d/Text3D.d.ts +5 -0
  131. package/dist/rendering/world3d/Text3D.js +2 -0
  132. package/dist/rendering/world3d/Texture3D.d.ts +16 -1
  133. package/dist/rendering/world3d/Texture3D.js +19 -1
  134. package/dist/rendering/world3d/Trail3D.d.ts +3 -0
  135. package/dist/rendering/world3d/Trail3D.js +2 -0
  136. package/dist/rendering/world3d/Vehicle3D.d.ts +5 -0
  137. package/dist/rendering/world3d/Vehicle3D.js +2 -0
  138. package/dist/rendering/world3d/VolumetricFog3D.d.ts +2 -0
  139. package/dist/rendering/world3d/VolumetricFog3D.js +1 -0
  140. package/dist/rendering/world3d/Water3D.d.ts +2 -0
  141. package/dist/rendering/world3d/Water3D.js +1 -0
  142. package/dist/rendering/world3d/core3D.d.ts +2 -0
  143. package/dist/rendering/world3d/debug3D.d.ts +5 -0
  144. package/dist/rendering/world3d/debug3D.js +5 -0
  145. package/dist/rendering/world3d/geometries3D.d.ts +12 -0
  146. package/dist/rendering/world3d/geometries3D.js +5 -0
  147. package/dist/rendering/world3d/helpers3D.d.ts +2 -0
  148. package/dist/rendering/world3d/helpers3D.js +1 -0
  149. package/dist/rendering/world3d/index.d.ts +12 -0
  150. package/dist/rendering/world3d/index.js +6 -0
  151. package/dist/rendering/world3d/math3D.d.ts +36 -0
  152. package/dist/rendering/world3d/math3D.js +35 -0
  153. package/dist/rendering/world3d/primitives3D.d.ts +7 -0
  154. package/dist/rendering/world3d/primitives3D.js +1 -0
  155. package/dist/saveStore.d.ts +18 -3
  156. package/dist/saveStore.js +23 -4
  157. package/dist/semanticList.d.ts +4 -0
  158. package/dist/semanticList.js +1 -0
  159. package/dist/semanticTree.js +11 -4
  160. package/dist/semanticTypes.d.ts +8 -0
  161. package/dist/sequencePlaybackTypes.d.ts +3 -0
  162. package/dist/text.d.ts +1 -0
  163. package/dist/textTable.d.ts +41 -0
  164. package/dist/textTable.js +114 -0
  165. package/dist/tilemapTypes.d.ts +13 -0
  166. package/dist/timer.d.ts +34 -0
  167. package/dist/timer.js +119 -0
  168. package/dist/tweenTypes.d.ts +4 -0
  169. package/dist/ui/controlKeys.d.ts +4 -0
  170. package/dist/ui/controlKeys.js +1 -0
  171. package/dist/ui/controls.d.ts +6 -0
  172. package/dist/ui/controls.js +2 -0
  173. package/dist/ui/layerTypes.d.ts +7 -0
  174. package/dist/ui/rangeControl.d.ts +3 -0
  175. package/dist/ui/rangeControl.js +1 -0
  176. package/dist/ui/scrollControl.d.ts +12 -0
  177. package/dist/ui/scrollControl.js +5 -1
  178. package/dist/ui/stateControls.d.ts +8 -0
  179. package/dist/ui/stateControls.js +3 -0
  180. package/dist/ui/textEditor.d.ts +1 -0
  181. package/dist/ui/textEditor.js +1 -0
  182. package/dist/ui/textEditorTypes.d.ts +7 -0
  183. package/dist/ui/textFieldControl.d.ts +4 -0
  184. package/dist/ui/textFieldControl.js +1 -0
  185. package/dist/ui/theme.d.ts +5 -0
  186. package/dist/ui/theme.js +1 -0
  187. package/dist/ui/types.d.ts +20 -0
  188. package/dist/ui/uiRoot.js +38 -9
  189. package/dist/ui/uiRootModel.d.ts +3 -1
  190. package/dist/ui/uiRootModel.js +8 -2
  191. package/dist/videoTypes.d.ts +3 -0
  192. package/dist/web/BrowserAssetBundle.d.ts +2 -0
  193. package/dist/web/BrowserAudio.d.ts +34 -1
  194. package/dist/web/BrowserAudio.js +69 -39
  195. package/dist/web/BrowserFrameLoop.d.ts +4 -0
  196. package/dist/web/BrowserGame.d.ts +64 -2
  197. package/dist/web/BrowserGame.js +129 -8
  198. package/dist/web/BrowserGamepadInput.d.ts +3 -0
  199. package/dist/web/BrowserHoverInput.d.ts +1 -0
  200. package/dist/web/BrowserImageTextures.d.ts +6 -0
  201. package/dist/web/BrowserInputActions.d.ts +10 -0
  202. package/dist/web/BrowserInputActions.js +4 -1
  203. package/dist/web/BrowserPlay.d.ts +130 -2
  204. package/dist/web/BrowserPlay.js +366 -19
  205. package/dist/web/BrowserPreferences.d.ts +10 -0
  206. package/dist/web/BrowserPreferences.js +39 -0
  207. package/dist/web/BrowserSemantics.d.ts +2 -0
  208. package/dist/web/BrowserStatsPanel.d.ts +10 -0
  209. package/dist/web/BrowserStatsPanel.js +9 -3
  210. package/dist/web/BrowserStorage.d.ts +2 -0
  211. package/dist/web/BrowserTextEditor.d.ts +3 -0
  212. package/dist/web/BrowserTextInput.d.ts +6 -0
  213. package/dist/web/BrowserTextureProvider.d.ts +6 -0
  214. package/dist/web/BrowserVideo.d.ts +13 -1
  215. package/dist/web/BrowserVideo.js +28 -2
  216. package/dist/web/CanvasKitFontSetProvider.d.ts +3 -0
  217. package/dist/web/CanvasKitParagraphProvider.d.ts +4 -0
  218. package/dist/web/CanvasKitParagraphProvider.js +1 -0
  219. package/dist/web/ManifestByteSource.d.ts +4 -0
  220. package/dist/web/ManifestByteSource.js +1 -0
  221. package/dist/web/ManifestFontContentLoader.d.ts +1 -0
  222. package/dist/web/WebGL2Host.js +64 -25
  223. package/dist/web/WebGPUHost.d.ts +13 -0
  224. package/dist/web/WebGPUHost.js +117 -36
  225. package/dist/web/audio.d.ts +2 -2
  226. package/dist/web/audio.js +1 -1
  227. package/dist/web/editorFonts.d.ts +4 -0
  228. package/dist/web/game.d.ts +1 -1
  229. package/dist/web/imageProjections2D.d.ts +2 -0
  230. package/dist/web/kit.d.ts +1 -0
  231. package/dist/web/kit.js +1 -0
  232. package/dist/web/play.d.ts +6 -1
  233. package/dist/web/play.js +4 -1
  234. package/dist/web/playMusic.d.ts +33 -0
  235. package/dist/web/playMusic.js +194 -0
  236. package/dist/web/playTouch.d.ts +45 -0
  237. package/dist/web/playTouch.js +141 -0
  238. package/dist/web/playWidgets.d.ts +71 -0
  239. package/dist/web/playWidgets.js +431 -0
  240. package/dist/web/prepareSharedSubmission2D.js +9 -3
  241. package/dist/web/resources.d.ts +2 -0
  242. package/dist/web/sharedEffectShaders.d.ts +6 -2
  243. package/dist/web/sharedEffectShaders.js +23 -7
  244. package/dist/web/sharedSubmissionStorage2D.js +1 -1
  245. package/dist/web/sharedWebGL2Options.d.ts +3 -0
  246. package/dist/web/sharedWebGL2Options.js +8 -2
  247. package/dist/web/sharedWebGL2Shaders.d.ts +15 -2
  248. package/dist/web/sharedWebGL2Shaders.js +108 -14
  249. package/dist/web/sharedWebGPUOptions.d.ts +5 -1
  250. package/dist/web/sharedWebGPUOptions.js +6 -2
  251. package/dist/web/video.d.ts +1 -1
  252. package/dist/web/webgl2Native.d.ts +3 -1
  253. package/dist/web/webgl2Native.js +9 -5
  254. package/dist/web/webgl2Types.d.ts +18 -0
  255. package/dist/web/webgpuImageResidency.d.ts +5 -2
  256. package/dist/web/webgpuImageResidency.js +7 -3
  257. package/dist/web/webgpuRetentionPool.d.ts +2 -2
  258. package/dist/web/webgpuRetentionPool.js +2 -1
  259. package/dist/web/webgpuSharedPass.d.ts +1 -1
  260. package/dist/web/webgpuSharedPass.js +87 -5
  261. package/dist/web/webgpuSharedResolvePass.d.ts +1 -1
  262. package/dist/web/webgpuSharedResolvePass.js +9 -4
  263. package/dist/web/world3d/Audio3D.d.ts +18 -1
  264. package/dist/web/world3d/Audio3D.js +62 -3
  265. package/dist/web/world3d/BrowserPlay3D.d.ts +115 -2
  266. package/dist/web/world3d/BrowserPlay3D.js +448 -43
  267. package/dist/web/world3d/FlyControls3D.d.ts +4 -0
  268. package/dist/web/world3d/FlyControls3D.js +2 -0
  269. package/dist/web/world3d/FollowControls3D.d.ts +3 -0
  270. package/dist/web/world3d/FollowControls3D.js +2 -0
  271. package/dist/web/world3d/OrbitControls3D.d.ts +3 -0
  272. package/dist/web/world3d/OrbitControls3D.js +2 -0
  273. package/dist/web/world3d/TransformControls3D.d.ts +5 -2
  274. package/dist/web/world3d/TransformControls3D.js +7 -4
  275. package/dist/web/world3d/WebGL2Renderer3D.d.ts +3 -0
  276. package/dist/web/world3d/WebGL2Renderer3D.js +2 -0
  277. package/dist/web/world3d/WebGPURenderer3D.d.ts +2 -0
  278. package/dist/web/world3d/WebGPURenderer3D.js +1 -0
  279. package/dist/web/world3d/World3DView.d.ts +3 -0
  280. package/dist/web/world3d/World3DView.js +2 -0
  281. package/dist/web/world3d/app3D.d.ts +7 -0
  282. package/dist/web/world3d/app3D.js +1 -0
  283. package/dist/web/world3d/assets3D.d.ts +1 -0
  284. package/dist/web/world3d/atmosphere3D.d.ts +9 -0
  285. package/dist/web/world3d/atmosphere3D.js +19 -4
  286. package/dist/web/world3d/canvasFont3D.d.ts +21 -0
  287. package/dist/web/world3d/canvasFont3D.js +165 -0
  288. package/dist/web/world3d/frame3D.d.ts +2 -0
  289. package/dist/web/world3d/host3D.d.ts +1 -0
  290. package/dist/web/world3d/index.d.ts +4 -2
  291. package/dist/web/world3d/index.js +2 -1
  292. package/dist/web/world3d/loaders3D.d.ts +1 -0
  293. package/dist/web/world3d/markers3D.d.ts +4 -0
  294. package/dist/web/world3d/overlay3D.d.ts +19 -0
  295. package/dist/web/world3d/overlay3D.js +21 -4
  296. package/dist/web/world3d/post3D.d.ts +4 -0
  297. package/dist/web/world3d/post3D.js +3 -0
  298. package/dist/web/world3d/probe3D.d.ts +1 -0
  299. package/dist/web/world3d/stats3D.d.ts +3 -0
  300. package/dist/web/world3d/stats3D.js +1 -0
  301. package/dist/web/world3d/webGL2FrameMetrics3D.d.ts +5 -0
  302. package/dist/web/world3d/webgpu.d.ts +2 -0
  303. package/dist/web/world3d/webgpu.js +1 -0
  304. package/package.json +3 -3
@@ -1,5 +1,8 @@
1
+ /** A point in 3D as x, y and z. */
1
2
  export type Point3D = [number, number, number];
3
+ /** A point in 2D as x and y. */
2
4
  export type Point2D = [number, number];
5
+ /** The most points and divisions a curve has. */
3
6
  export declare const CURVE3D_LIMITS: Readonly<{
4
7
  readonly maxPoints: 65536;
5
8
  readonly maxDivisions: 16384;
@@ -38,12 +41,14 @@ export declare abstract class Curve3D {
38
41
  binormals: Point3D[];
39
42
  };
40
43
  }
44
+ /** A straight line between two points, as a curve. */
41
45
  export declare class LineCurve3D extends Curve3D {
42
46
  readonly start: Point3D;
43
47
  readonly end: Point3D;
44
48
  constructor(start: ArrayLike<number>, end: ArrayLike<number>);
45
49
  getPoint(t: number, out?: Point3D): Point3D;
46
50
  }
51
+ /** A quadratic Bézier curve through three control points. */
47
52
  export declare class QuadraticBezierCurve3D extends Curve3D {
48
53
  readonly p0: Point3D;
49
54
  readonly p1: Point3D;
@@ -51,6 +56,7 @@ export declare class QuadraticBezierCurve3D extends Curve3D {
51
56
  constructor(p0: ArrayLike<number>, p1: ArrayLike<number>, p2: ArrayLike<number>);
52
57
  getPoint(t: number, out?: Point3D): Point3D;
53
58
  }
59
+ /** A cubic Bézier curve through four control points. */
54
60
  export declare class CubicBezierCurve3D extends Curve3D {
55
61
  readonly p0: Point3D;
56
62
  readonly p1: Point3D;
@@ -59,6 +65,7 @@ export declare class CubicBezierCurve3D extends Curve3D {
59
65
  constructor(p0: ArrayLike<number>, p1: ArrayLike<number>, p2: ArrayLike<number>, p3: ArrayLike<number>);
60
66
  getPoint(t: number, out?: Point3D): Point3D;
61
67
  }
68
+ /** How a Catmull-Rom curve is parameterized between its points. */
62
69
  export type CatmullRomKind3D = 'centripetal' | 'chordal' | 'uniform';
63
70
  /** Smooth curve through every control point. Centripetal spacing avoids loops and cusps. */
64
71
  export declare class CatmullRomCurve3D extends Curve3D {
@@ -98,6 +105,7 @@ export declare class Shape3D extends Path2D3D {
98
105
  readonly holes: Path2D3D[];
99
106
  constructor(points?: readonly (readonly [number, number])[]);
100
107
  }
108
+ /** The signed area of a 2D polygon: positive when its points run counterclockwise. */
101
109
  export declare function signedArea2D(points: readonly Point2D[]): number;
102
110
  /**
103
111
  * Triangulate an outline with holes by ear clipping. Returns the merged
@@ -3,6 +3,7 @@
3
3
  // and tangents by parameter or by distance travelled, and feed the tube,
4
4
  // lathe, extrude and shape geometries. Points are plain [x, y, z] arrays.
5
5
  import { World3DError, requireCount3D, requireFinite3D } from './core3D.js';
6
+ /** The most points and divisions a curve has. */
6
7
  export const CURVE3D_LIMITS = Object.freeze({ maxPoints: 65536, maxDivisions: 16384 });
7
8
  function point(value, field) {
8
9
  if (!value || value.length < 3)
@@ -136,6 +137,7 @@ function rotate(v, axis, angle) {
136
137
  const c = Math.cos(angle), s = Math.sin(angle), d = (axis[0] * v[0] + axis[1] * v[1] + axis[2] * v[2]) * (1 - c), k = cross(axis, v);
137
138
  return [v[0] * c + k[0] * s + axis[0] * d, v[1] * c + k[1] * s + axis[1] * d, v[2] * c + k[2] * s + axis[2] * d];
138
139
  }
140
+ /** A straight line between two points, as a curve. */
139
141
  export class LineCurve3D extends Curve3D {
140
142
  start;
141
143
  end;
@@ -152,6 +154,7 @@ export class LineCurve3D extends Curve3D {
152
154
  return out;
153
155
  }
154
156
  }
157
+ /** A quadratic Bézier curve through three control points. */
155
158
  export class QuadraticBezierCurve3D extends Curve3D {
156
159
  p0;
157
160
  p1;
@@ -169,6 +172,7 @@ export class QuadraticBezierCurve3D extends Curve3D {
169
172
  return out;
170
173
  }
171
174
  }
175
+ /** A cubic Bézier curve through four control points. */
172
176
  export class CubicBezierCurve3D extends Curve3D {
173
177
  p0;
174
178
  p1;
@@ -341,6 +345,7 @@ export class Shape3D extends Path2D3D {
341
345
  this.moveTo(p[0], p[1]);
342
346
  }
343
347
  }
348
+ /** The signed area of a 2D polygon: positive when its points run counterclockwise. */
344
349
  export function signedArea2D(points) {
345
350
  let area = 0;
346
351
  for (let i = 0, j = points.length - 1; i < points.length; j = i++)
@@ -1,9 +1,11 @@
1
1
  import { Geometry3D } from './Geometry3D.js';
2
2
  import type { Material3D } from './Material3D.js';
3
3
  import { Mesh3D } from './Mesh3D.js';
4
+ /** The most triangles a decal has. */
4
5
  export declare const DECAL3D_LIMITS: Readonly<{
5
6
  readonly maxTriangles: 262144;
6
7
  }>;
8
+ /** A decal to make: where it goes and which way it faces, its size and depth, its rotation, and the steepest surface it covers. */
7
9
  export interface DecalOptions3D {
8
10
  /** Center of the decal on the surface, in world space. */
9
11
  readonly position: ArrayLike<number>;
@@ -7,6 +7,7 @@ import { World3DError, requireFinite3D, requirePositive3D } from './core3D.js';
7
7
  import { Attribute3D, Geometry3D } from './Geometry3D.js';
8
8
  import { Mesh3D } from './Mesh3D.js';
9
9
  import { mat4Invert, mat4Multiply } from './math3D.js';
10
+ /** The most triangles a decal has. */
10
11
  export const DECAL3D_LIMITS = Object.freeze({ maxTriangles: 262144 });
11
12
  /**
12
13
  * Cut the part of a mesh's surface that lies inside the decal box. The
@@ -0,0 +1,13 @@
1
+ import { Geometry3D } from './Geometry3D.js';
2
+ import { Object3D } from './Object3D.js';
3
+ /** How a model is written. */
4
+ export interface GlbExportOptions3D {
5
+ /** The name of the root node; that of the object, or 'model', unless given. */
6
+ readonly name?: string;
7
+ }
8
+ /**
9
+ * The model as the bytes of a .glb file: a geometry alone (with a plain material that shows its vertex colours), or an
10
+ * object and everything under it. Meshes that draw lines or points are left out.
11
+ */
12
+ export declare function exportGlb3D(source: Geometry3D | Object3D, options?: GlbExportOptions3D): Uint8Array;
13
+ //# sourceMappingURL=Export3D.d.ts.map
@@ -0,0 +1,263 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Writes a model as a binary glTF (.glb): a mesh made in code saved once and loaded fast after, opened in Blender to be
3
+ // touched up, or handed to another tool. Geometry (positions, normals, vertex colours, texture coordinates, indices,
4
+ // material groups), the node tree with each node's position, rotation and scale, and each material's colour,
5
+ // opacity, metalness and roughness are written. Textures, skins, morph targets and animations are not.
6
+ import { World3DError } from './core3D.js';
7
+ import { Geometry3D } from './Geometry3D.js';
8
+ import { Mesh3D } from './Mesh3D.js';
9
+ import { Object3D } from './Object3D.js';
10
+ const FLOAT = 5126, UNSIGNED_SHORT = 5123, UNSIGNED_INT = 5125;
11
+ const ARRAY_BUFFER = 34962, ELEMENT_ARRAY_BUFFER = 34963;
12
+ const TYPES = { 1: 'SCALAR', 2: 'VEC2', 3: 'VEC3', 4: 'VEC4' };
13
+ const NAMES = { position: 'POSITION', normal: 'NORMAL', color: 'COLOR_0', uv: 'TEXCOORD_0' };
14
+ function invalid(what) {
15
+ return new World3DError('WORLD3D_INPUT_INVALID', what);
16
+ }
17
+ /** UTF-8 bytes of a string; this module runs where no TextEncoder is promised. */
18
+ function utf8(text) {
19
+ const out = [];
20
+ for (const ch of text) {
21
+ const c = ch.codePointAt(0);
22
+ if (c < 0x80)
23
+ out.push(c);
24
+ else if (c < 0x800)
25
+ out.push(0xc0 | (c >> 6), 0x80 | (c & 63));
26
+ else if (c < 0x10000)
27
+ out.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
28
+ else
29
+ out.push(0xf0 | (c >> 18), 0x80 | ((c >> 12) & 63), 0x80 | ((c >> 6) & 63), 0x80 | (c & 63));
30
+ }
31
+ return Uint8Array.from(out);
32
+ }
33
+ /** The attribute's values as floats, normalized integers turned into 0 to 1 (or -1 to 1). */
34
+ function floats(attribute) {
35
+ const data = attribute.data;
36
+ if (data instanceof Float32Array)
37
+ return data;
38
+ const out = new Float32Array(data.length);
39
+ let scale = 1;
40
+ if (attribute.normalized) {
41
+ if (data instanceof Uint8Array)
42
+ scale = 1 / 255;
43
+ else if (data instanceof Uint16Array)
44
+ scale = 1 / 65535;
45
+ else if (data instanceof Int8Array)
46
+ scale = 1 / 127;
47
+ else if (data instanceof Int16Array)
48
+ scale = 1 / 32767;
49
+ }
50
+ for (let i = 0; i < data.length; i++)
51
+ out[i] = data[i] * scale;
52
+ return out;
53
+ }
54
+ /**
55
+ * The model as the bytes of a .glb file: a geometry alone (with a plain material that shows its vertex colours), or an
56
+ * object and everything under it. Meshes that draw lines or points are left out.
57
+ */
58
+ export function exportGlb3D(source, options = {}) {
59
+ if (!(source instanceof Geometry3D) && !(source instanceof Object3D))
60
+ throw invalid('export source');
61
+ if (options === null || typeof options !== 'object')
62
+ throw invalid('export options');
63
+ if (options.name !== undefined && typeof options.name !== 'string')
64
+ throw invalid('export name');
65
+ const json = {
66
+ asset: { version: '2.0', generator: 'Egret Engine World3D' },
67
+ scene: 0,
68
+ scenes: [{ nodes: [0] }],
69
+ nodes: [],
70
+ meshes: [],
71
+ materials: [],
72
+ accessors: [],
73
+ bufferViews: [],
74
+ buffers: []
75
+ };
76
+ const chunks = [];
77
+ let byteLength = 0;
78
+ const view = (bytes, target) => {
79
+ const pad = (4 - (byteLength % 4)) % 4;
80
+ if (pad > 0) {
81
+ chunks.push(new Uint8Array(pad));
82
+ byteLength += pad;
83
+ }
84
+ json.bufferViews.push({ buffer: 0, byteOffset: byteLength, byteLength: bytes.byteLength, target });
85
+ chunks.push(bytes);
86
+ byteLength += bytes.byteLength;
87
+ return json.bufferViews.length - 1;
88
+ };
89
+ const accessor = (values, size, extra) => {
90
+ const bytes = new Uint8Array(values.buffer.slice(values.byteOffset, values.byteOffset + values.byteLength));
91
+ const isIndex = !(values instanceof Float32Array);
92
+ json.accessors.push({
93
+ bufferView: view(bytes, isIndex ? ELEMENT_ARRAY_BUFFER : ARRAY_BUFFER),
94
+ componentType: values instanceof Float32Array ? FLOAT : values instanceof Uint16Array ? UNSIGNED_SHORT : UNSIGNED_INT,
95
+ count: values.length / size,
96
+ type: TYPES[size],
97
+ ...extra
98
+ });
99
+ return json.accessors.length - 1;
100
+ };
101
+ const materialIndex = new Map();
102
+ const material = (m) => {
103
+ const known = materialIndex.get(m);
104
+ if (known !== undefined)
105
+ return known;
106
+ const entry = m === null
107
+ ? {
108
+ name: 'vertex colours',
109
+ pbrMetallicRoughness: { baseColorFactor: [1, 1, 1, 1], metallicFactor: 0, roughnessFactor: 0.8 }
110
+ }
111
+ : {
112
+ name: m.name || undefined,
113
+ pbrMetallicRoughness: {
114
+ baseColorFactor: [m.color[0], m.color[1], m.color[2], m.opacity],
115
+ metallicFactor: m.metallic,
116
+ roughnessFactor: m.roughness
117
+ },
118
+ ...(m.opacity < 1 ? { alphaMode: 'BLEND' } : {}),
119
+ ...(m.side === 'double' ? { doubleSided: true } : {})
120
+ };
121
+ json.materials.push(entry);
122
+ materialIndex.set(m, json.materials.length - 1);
123
+ return json.materials.length - 1;
124
+ };
125
+ const meshIndex = new Map();
126
+ const ids = new WeakMap();
127
+ let nextId = 1;
128
+ const idOf = (o) => {
129
+ let id = ids.get(o);
130
+ if (id === undefined)
131
+ ids.set(o, (id = nextId++));
132
+ return id;
133
+ };
134
+ const attributesOf = new Map();
135
+ const mesh = (geometry, materials) => {
136
+ if (geometry.topology !== 'triangles')
137
+ return undefined;
138
+ const position = geometry.getAttribute('position');
139
+ if (!position || position.itemSize !== 3 || position.count === 0)
140
+ return undefined;
141
+ const key = idOf(geometry) + ':' + materials.map(m => (m === null ? 0 : idOf(m))).join(',');
142
+ const known = meshIndex.get(key);
143
+ if (known !== undefined)
144
+ return known;
145
+ let attributes = attributesOf.get(geometry);
146
+ if (attributes === undefined) {
147
+ attributes = {};
148
+ for (const [name, gltfName] of Object.entries(NAMES)) {
149
+ const attribute = geometry.getAttribute(name);
150
+ if (!attribute)
151
+ continue;
152
+ if (name === 'position') {
153
+ const p = floats(attribute), min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
154
+ for (let i = 0; i < p.length; i += 3)
155
+ for (let a = 0; a < 3; a++) {
156
+ min[a] = Math.min(min[a], p[i + a]);
157
+ max[a] = Math.max(max[a], p[i + a]);
158
+ }
159
+ attributes[gltfName] = accessor(p, 3, { min, max });
160
+ }
161
+ else if ((name === 'color' && (attribute.itemSize === 3 || attribute.itemSize === 4)) || name !== 'color')
162
+ attributes[gltfName] = accessor(floats(attribute), attribute.itemSize, {});
163
+ }
164
+ attributesOf.set(geometry, attributes);
165
+ }
166
+ const count = position.count;
167
+ const index = geometry.index ? Array.from(geometry.index.data) : Array.from({ length: count }, (_, i) => i);
168
+ const ranges = geometry.groups.length > 0
169
+ ? geometry.groups.map(g => ({ start: g.start, count: g.count, material: g.materialIndex }))
170
+ : [{ start: 0, count: index.length, material: 0 }];
171
+ const primitives = [];
172
+ for (const range of ranges) {
173
+ const part = index.slice(range.start, range.start + range.count);
174
+ if (part.length === 0)
175
+ continue;
176
+ const values = count > 65535 ? Uint32Array.from(part) : Uint16Array.from(part);
177
+ primitives.push({
178
+ attributes,
179
+ indices: accessor(values, 1, {}),
180
+ material: material(materials[Math.min(range.material, materials.length - 1)] ?? null),
181
+ mode: 4
182
+ });
183
+ }
184
+ if (primitives.length === 0)
185
+ return undefined;
186
+ json.meshes.push({ primitives });
187
+ meshIndex.set(key, json.meshes.length - 1);
188
+ return json.meshes.length - 1;
189
+ };
190
+ const node = (object) => {
191
+ const entry = {};
192
+ if (object.name)
193
+ entry.name = object.name;
194
+ const [px, py, pz] = object.position, [qx, qy, qz, qw] = object.quaternion, [sx, sy, sz] = object.scale;
195
+ if (px !== 0 || py !== 0 || pz !== 0)
196
+ entry.translation = [px, py, pz];
197
+ if (qx !== 0 || qy !== 0 || qz !== 0 || qw !== 1)
198
+ entry.rotation = [qx, qy, qz, qw];
199
+ if (sx !== 1 || sy !== 1 || sz !== 1)
200
+ entry.scale = [sx, sy, sz];
201
+ if (object instanceof Mesh3D) {
202
+ const list = Array.isArray(object.material) ? object.material : [object.material];
203
+ const m = mesh(object.geometry, list);
204
+ if (m !== undefined)
205
+ entry.mesh = m;
206
+ }
207
+ json.nodes.push(entry);
208
+ const at = json.nodes.length - 1;
209
+ const children = object.children.map(node);
210
+ if (children.length > 0)
211
+ entry.children = children;
212
+ return at;
213
+ };
214
+ if (source instanceof Geometry3D) {
215
+ const m = mesh(source, [null]);
216
+ if (m === undefined)
217
+ throw invalid('export geometry');
218
+ json.nodes.push({ name: options.name ?? 'model', mesh: m });
219
+ }
220
+ else {
221
+ node(source);
222
+ if (options.name !== undefined)
223
+ json.nodes[0].name = options.name;
224
+ else if (json.nodes[0].name === undefined)
225
+ json.nodes[0].name = 'model';
226
+ }
227
+ if (json.materials.length === 0)
228
+ delete json.materials;
229
+ if (json.meshes.length === 0)
230
+ delete json.meshes;
231
+ if (byteLength === 0) {
232
+ delete json.accessors;
233
+ delete json.bufferViews;
234
+ delete json.buffers;
235
+ }
236
+ else
237
+ json.buffers.push({ byteLength: byteLength + ((4 - (byteLength % 4)) % 4) });
238
+ const text = utf8(JSON.stringify(json));
239
+ const jsonLength = text.byteLength + ((4 - (text.byteLength % 4)) % 4);
240
+ const binLength = byteLength === 0 ? 0 : byteLength + ((4 - (byteLength % 4)) % 4);
241
+ const total = 12 + 8 + jsonLength + (binLength > 0 ? 8 + binLength : 0);
242
+ const out = new Uint8Array(total);
243
+ const dv = new DataView(out.buffer);
244
+ dv.setUint32(0, 0x46546c67, true);
245
+ dv.setUint32(4, 2, true);
246
+ dv.setUint32(8, total, true);
247
+ dv.setUint32(12, jsonLength, true);
248
+ dv.setUint32(16, 0x4e4f534a, true);
249
+ out.set(text, 20);
250
+ out.fill(0x20, 20 + text.byteLength, 20 + jsonLength);
251
+ if (binLength > 0) {
252
+ let at = 20 + jsonLength;
253
+ dv.setUint32(at, binLength, true);
254
+ dv.setUint32(at + 4, 0x004e4942, true);
255
+ at += 8;
256
+ for (const chunk of chunks) {
257
+ out.set(chunk, at);
258
+ at += chunk.byteLength;
259
+ }
260
+ }
261
+ return out;
262
+ }
263
+ //# sourceMappingURL=Export3D.js.map
@@ -1,6 +1,9 @@
1
1
  import { Resource3D } from './core3D.js';
2
+ /** An array of vertex data. */
2
3
  export type AttributeArray3D = Float32Array | Uint32Array | Uint16Array | Uint8Array | Int16Array | Int8Array;
4
+ /** How a geometry's vertices are joined: as triangles, lines, a strip of lines, or points. */
3
5
  export type Topology3D = 'triangles' | 'lines' | 'line-strip' | 'points';
6
+ /** The most vertices, indices, morph targets and groups a geometry has. */
4
7
  export declare const GEOMETRY3D_LIMITS: Readonly<{
5
8
  readonly maxVertices: 4194304;
6
9
  readonly maxIndices: 12582912;
@@ -18,6 +21,7 @@ export declare const ATTRIBUTE_3D: Readonly<{
18
21
  readonly joints: 'joints';
19
22
  readonly weights: 'weights';
20
23
  }>;
24
+ /** One attribute of a geometry, such as positions: its data, how many numbers each vertex has, and whether they are normalized. */
21
25
  export declare class Attribute3D {
22
26
  #private;
23
27
  readonly data: AttributeArray3D;
@@ -31,17 +35,20 @@ export declare class Attribute3D {
31
35
  get version(): number;
32
36
  touch(): void;
33
37
  }
38
+ /** A range of a geometry's indices drawn with one of its mesh's materials. */
34
39
  export interface GeometryGroup3D {
35
40
  readonly start: number;
36
41
  readonly count: number;
37
42
  readonly materialIndex: number;
38
43
  }
44
+ /** A morph target: the positions, and normals, it moves a geometry toward. */
39
45
  export interface MorphTarget3D {
40
46
  readonly name: string;
41
47
  /** Per-vertex deltas relative to the base attribute. */
42
48
  readonly position?: Float32Array;
43
49
  readonly normal?: Float32Array;
44
50
  }
51
+ /** The vertices of a mesh: its attributes and indices, its groups and morph targets, and calls that compute normals and tangents. */
45
52
  export declare class Geometry3D extends Resource3D {
46
53
  #private;
47
54
  topology: Topology3D;
@@ -65,13 +72,16 @@ export declare class Geometry3D extends Resource3D {
65
72
  get boundingBox(): Float32Array;
66
73
  /** Local-space [x, y, z, radius]; radius is negative for an empty geometry. */
67
74
  get boundingSphere(): Float32Array;
68
- /** Call after editing position data in place. */
75
+ /** Counts `invalidateBounds` calls: what a mesh's world bounds are kept by, beside the structure version. */
76
+ get boundsVersion(): number;
77
+ /** Call after editing position data in place. Meshes of this geometry find their world bounds again. */
69
78
  invalidateBounds(): void;
70
79
  /** Area-weighted smooth normals for triangle geometry. */
71
80
  computeNormals(): this;
72
81
  /** Per-vertex tangents (xyz + handedness) from positions, normals and UVs. */
73
82
  computeTangents(): this;
74
83
  }
84
+ /** A geometry to make: its positions, and its normals, texture coordinates, colors and indices where given. */
75
85
  export interface GeometryInput3D {
76
86
  readonly positions: ArrayLike<number>;
77
87
  readonly normals?: ArrayLike<number>;
@@ -4,6 +4,7 @@
4
4
  // into them, then call touch() on the attribute to schedule a GPU refresh.
5
5
  import { Resource3D, World3DError, requireCount3D } from './core3D.js';
6
6
  import { box3Empty, box3ExpandByPoint, sphereFromBox } from './math3D.js';
7
+ /** The most vertices, indices, morph targets and groups a geometry has. */
7
8
  export const GEOMETRY3D_LIMITS = Object.freeze({
8
9
  maxVertices: 4194304,
9
10
  maxIndices: 12582912,
@@ -21,6 +22,7 @@ export const ATTRIBUTE_3D = Object.freeze({
21
22
  joints: 'joints',
22
23
  weights: 'weights'
23
24
  });
25
+ /** One attribute of a geometry, such as positions: its data, how many numbers each vertex has, and whether they are normalized. */
24
26
  export class Attribute3D {
25
27
  data;
26
28
  itemSize;
@@ -48,6 +50,7 @@ export class Attribute3D {
48
50
  this.#version++;
49
51
  }
50
52
  }
53
+ /** The vertices of a mesh: its attributes and indices, its groups and morph targets, and calls that compute normals and tangents. */
51
54
  export class Geometry3D extends Resource3D {
52
55
  topology = 'triangles';
53
56
  #attributes = new Map();
@@ -198,10 +201,16 @@ export class Geometry3D extends Resource3D {
198
201
  get boundingSphere() {
199
202
  return (this.#boundingSphere ??= sphereFromBox(new Float32Array(4), this.boundingBox));
200
203
  }
201
- /** Call after editing position data in place. */
204
+ #boundsVersion = 0;
205
+ /** Counts `invalidateBounds` calls: what a mesh's world bounds are kept by, beside the structure version. */
206
+ get boundsVersion() {
207
+ return this.#boundsVersion;
208
+ }
209
+ /** Call after editing position data in place. Meshes of this geometry find their world bounds again. */
202
210
  invalidateBounds() {
203
211
  this.#boundingBox = undefined;
204
212
  this.#boundingSphere = undefined;
213
+ this.#boundsVersion++;
205
214
  }
206
215
  // ---- derived attributes ------------------------------------------------
207
216
  /** Area-weighted smooth normals for triangle geometry. */
@@ -1,5 +1,6 @@
1
1
  import { Geometry3D } from './Geometry3D.js';
2
2
  import type { ColorInput3D } from './Material3D.js';
3
+ /** One geometry added to a builder: where, turned and scaled how, and its color. */
3
4
  export interface GeometryPart3D {
4
5
  /** Where the part goes; [0, 0, 0] by default. */
5
6
  readonly position?: readonly [number, number, number];
@@ -15,6 +16,7 @@ export interface GeometryPart3D {
15
16
  /** Multiplies each vertex colour already in the part, as for shading baked into it. */
16
17
  readonly keepColors?: boolean;
17
18
  }
19
+ /** Joins many geometries, each placed, into one. */
18
20
  export interface GeometryBuilder3D {
19
21
  /** Parts added so far. */
20
22
  readonly parts: number;
@@ -1,15 +1,19 @@
1
1
  import type { Camera3D } from './Camera3D.js';
2
2
  import { Object3D } from './Object3D.js';
3
+ /** Whether a gizmo moves, turns or scales what it is attached to. */
3
4
  export type GizmoMode3D = 'translate' | 'rotate' | 'scale';
5
+ /** Whether a gizmo's axes are the world's or the object's own. */
4
6
  export type GizmoSpace3D = 'world' | 'local';
5
7
  /** A single axis, a plane spanned by two axes, or 'xyz' for the center handle of the scale mode. */
6
8
  export type GizmoHandle3D = 'x' | 'y' | 'z' | 'xy' | 'yz' | 'xz' | 'xyz';
9
+ /** A gizmo to make: its mode, its space and its size. */
7
10
  export interface TransformGizmoOptions3D {
8
11
  readonly mode?: GizmoMode3D;
9
12
  readonly space?: GizmoSpace3D;
10
13
  /** Length of the handles as a share of the view height. Defaults to 0.18. */
11
14
  readonly size?: number;
12
15
  }
16
+ /** Handles to move, turn or scale an object by dragging them, with snapping. */
13
17
  export declare class TransformGizmo3D extends Object3D {
14
18
  #private;
15
19
  readonly camera: Camera3D;
@@ -71,5 +75,6 @@ export declare class TransformGizmo3D extends Object3D {
71
75
  /** Release the handle geometry and materials. */
72
76
  dispose(): void;
73
77
  }
78
+ /** Makes a transform gizmo seen by a camera. */
74
79
  export declare function createTransformGizmo3D(camera: Camera3D, options?: TransformGizmoOptions3D): TransformGizmo3D;
75
80
  //# sourceMappingURL=Gizmo3D.d.ts.map
@@ -27,6 +27,7 @@ const unit = (a) => {
27
27
  return [a[0] / size, a[1] / size, a[2] / size];
28
28
  };
29
29
  const snap = (value, step) => step !== undefined && step > 0 ? Math.round(value / step) * step : value;
30
+ /** Handles to move, turn or scale an object by dragging them, with snapping. */
30
31
  export class TransformGizmo3D extends Object3D {
31
32
  camera;
32
33
  mode;
@@ -506,6 +507,7 @@ export class TransformGizmo3D extends Object3D {
506
507
  entry.material.dispose();
507
508
  }
508
509
  }
510
+ /** Makes a transform gizmo seen by a camera. */
509
511
  export function createTransformGizmo3D(camera, options = {}) {
510
512
  return new TransformGizmo3D(camera, options);
511
513
  }
@@ -6,6 +6,7 @@ import { Object3D } from './Object3D.js';
6
6
  import type { Ktx2Options3D } from './Ktx23D.js';
7
7
  import { Texture3D } from './Texture3D.js';
8
8
  import type { TextureSource3D } from './Texture3D.js';
9
+ /** An image a glTF file needs decoded: its index, media type, and its bytes or URI. */
9
10
  export interface GltfImageRequest3D {
10
11
  readonly index: number;
11
12
  readonly mimeType: string | undefined;
@@ -14,6 +15,7 @@ export interface GltfImageRequest3D {
14
15
  /** Relative or absolute URI when the image is external. */
15
16
  readonly uri: string | undefined;
16
17
  }
18
+ /** How a glTF file's parts are loaded: its images, its other buffers, and its KTX2, meshopt and Draco data. */
17
19
  export interface GltfLoadOptions3D {
18
20
  /** Decode an encoded image into pixels or a host image object. */
19
21
  readonly decodeImage?: (request: GltfImageRequest3D) => Promise<TextureSource3D>;
@@ -29,6 +31,7 @@ export interface GltfLoadOptions3D {
29
31
  /** Decode one KHR_draco_mesh_compression primitive. */
30
32
  readonly decodeDraco?: (request: GltfDracoRequest3D) => Promise<GltfDracoResult3D> | GltfDracoResult3D;
31
33
  }
34
+ /** Meshopt data a glTF file needs decoded: its bytes, count, stride, mode and filter. */
32
35
  export interface GltfMeshoptRequest3D {
33
36
  readonly source: Uint8Array;
34
37
  readonly count: number;
@@ -36,6 +39,7 @@ export interface GltfMeshoptRequest3D {
36
39
  readonly mode: 'ATTRIBUTES' | 'TRIANGLES' | 'INDICES';
37
40
  readonly filter: 'NONE' | 'OCTAHEDRAL' | 'QUATERNION' | 'EXPONENTIAL';
38
41
  }
42
+ /** Draco data a glTF file needs decoded: its bytes and the attributes and component types it holds. */
39
43
  export interface GltfDracoRequest3D {
40
44
  readonly bytes: Uint8Array;
41
45
  /** glTF semantic (POSITION, NORMAL, ...) to Draco attribute id. */
@@ -45,11 +49,13 @@ export interface GltfDracoRequest3D {
45
49
  /** glTF component type of the index accessor, when the primitive is indexed. */
46
50
  readonly indexComponentType: number | undefined;
47
51
  }
52
+ /** Decoded Draco data: its attributes by name and its indices. */
48
53
  export interface GltfDracoResult3D {
49
54
  /** Decoded arrays by glTF semantic, in the component type of the matching accessor. */
50
55
  readonly attributes: Readonly<Record<string, Float32Array | Uint32Array | Uint16Array | Uint8Array | Int16Array | Int8Array>>;
51
56
  readonly indices?: Uint32Array | Uint16Array;
52
57
  }
58
+ /** A loaded glTF file: its scenes, animations, cameras, materials, textures and geometries. */
53
59
  export interface GltfAsset3D {
54
60
  /** Root of the default scene (or the first one). */
55
61
  readonly scene: Object3D;
@@ -938,6 +938,24 @@ async function unpack(data, options) {
938
938
  }));
939
939
  return { json, buffers };
940
940
  }
941
+ /** A resource listener can fail after its own retirement. Retire the rest of the asset before reporting it. */
942
+ function retireGltfResources(reader) {
943
+ const failures = [];
944
+ for (const resources of [reader.geometries, reader.materials, reader.textures]) {
945
+ for (const resource of resources) {
946
+ try {
947
+ resource.dispose();
948
+ }
949
+ catch (cause) {
950
+ failures.push(cause);
951
+ }
952
+ }
953
+ }
954
+ if (failures.length === 1)
955
+ throw failures[0];
956
+ if (failures.length > 1)
957
+ throw new AggregateError(failures, 'glTF resource cleanup failed');
958
+ }
941
959
  /** Parse a glTF 2.0 asset from .glb bytes, .gltf JSON bytes or an already parsed JSON object. */
942
960
  export async function loadGltf3D(data, options = {}) {
943
961
  const { json, buffers } = await unpack(data, options);
@@ -947,9 +965,12 @@ export async function loadGltf3D(data, options = {}) {
947
965
  built = await reader.build();
948
966
  }
949
967
  catch (cause) {
950
- // Never leak partially created resources when loading fails midway.
951
- for (const resource of [...reader.geometries, ...reader.materials, ...reader.textures])
952
- resource.dispose();
968
+ try {
969
+ retireGltfResources(reader);
970
+ }
971
+ catch (cleanup) {
972
+ throw new AggregateError([cause, cleanup], 'glTF load and cleanup failed', { cause });
973
+ }
953
974
  if (cause instanceof World3DError)
954
975
  throw cause;
955
976
  throw new World3DError('WORLD3D_GLTF_INVALID', 'malformed asset', cause);
@@ -968,8 +989,7 @@ export async function loadGltf3D(data, options = {}) {
968
989
  if (disposed)
969
990
  return;
970
991
  disposed = true;
971
- for (const resource of [...reader.geometries, ...reader.materials, ...reader.textures])
972
- resource.dispose();
992
+ retireGltfResources(reader);
973
993
  }
974
994
  });
975
995
  }
@@ -2,6 +2,7 @@ import { type Blending3D, type ColorInput3D } from './Material3D.js';
2
2
  import { InstancedMesh3D } from './Mesh3D.js';
3
3
  import type { Texture3D } from './Texture3D.js';
4
4
  type Range = number | readonly [number, number];
5
+ /** GPU particles to make: how many and how long they live, how they move, grow, turn and fade, where they come from and how they blend. */
5
6
  export interface GpuParticlesOptions3D {
6
7
  /** Number of particles. Default 10000. */
7
8
  readonly count?: number;
@@ -102,6 +103,7 @@ export declare class GpuParticles3D extends InstancedMesh3D {
102
103
  /** Release the geometry and the material. */
103
104
  dispose(): void;
104
105
  }
106
+ /** Makes particles simulated on the GPU. */
105
107
  export declare function createGpuParticles3D(options?: GpuParticlesOptions3D): GpuParticles3D;
106
108
  export {};
107
109
  //# sourceMappingURL=GpuParticles3D.d.ts.map
@@ -394,6 +394,7 @@ export class GpuParticles3D extends InstancedMesh3D {
394
394
  this.material.dispose();
395
395
  }
396
396
  }
397
+ /** Makes particles simulated on the GPU. */
397
398
  export function createGpuParticles3D(options = {}) {
398
399
  return new GpuParticles3D(options);
399
400
  }