@driftengine/physics 3.61.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +9 -0
  3. package/README.md +503 -0
  4. package/dist/bodies.d.ts +121 -0
  5. package/dist/bodies.js +298 -0
  6. package/dist/buoyancy.d.ts +46 -0
  7. package/dist/buoyancy.js +45 -0
  8. package/dist/cloth.d.ts +226 -0
  9. package/dist/cloth.js +587 -0
  10. package/dist/collide/aabb.d.ts +10 -0
  11. package/dist/collide/aabb.js +11 -0
  12. package/dist/collide/body.d.ts +202 -0
  13. package/dist/collide/body.js +142 -0
  14. package/dist/collide/eject.d.ts +39 -0
  15. package/dist/collide/eject.js +142 -0
  16. package/dist/collide/index.d.ts +18 -0
  17. package/dist/collide/index.js +5 -0
  18. package/dist/collide/scratch.d.ts +8 -0
  19. package/dist/collide/scratch.js +9 -0
  20. package/dist/collide/segment.d.ts +12 -0
  21. package/dist/collide/segment.js +109 -0
  22. package/dist/collide/sweep.d.ts +3 -0
  23. package/dist/collide/sweep.js +1036 -0
  24. package/dist/colliderSet.d.ts +239 -0
  25. package/dist/colliderSet.js +546 -0
  26. package/dist/compoundContact.d.ts +70 -0
  27. package/dist/compoundContact.js +221 -0
  28. package/dist/controller.d.ts +351 -0
  29. package/dist/controller.js +641 -0
  30. package/dist/cylinder.d.ts +78 -0
  31. package/dist/cylinder.js +294 -0
  32. package/dist/cylinderContact.d.ts +7 -0
  33. package/dist/cylinderContact.js +704 -0
  34. package/dist/decompose.d.ts +105 -0
  35. package/dist/decompose.js +979 -0
  36. package/dist/events.d.ts +43 -0
  37. package/dist/events.js +95 -0
  38. package/dist/executor.d.ts +147 -0
  39. package/dist/executor.js +173 -0
  40. package/dist/faces.d.ts +26 -0
  41. package/dist/faces.js +34 -0
  42. package/dist/fingerprint.d.ts +61 -0
  43. package/dist/fingerprint.js +139 -0
  44. package/dist/groundMotor.d.ts +34 -0
  45. package/dist/groundMotor.js +41 -0
  46. package/dist/heightfieldShape.d.ts +128 -0
  47. package/dist/heightfieldShape.js +328 -0
  48. package/dist/index.d.ts +73 -0
  49. package/dist/index.js +47 -0
  50. package/dist/island.d.ts +55 -0
  51. package/dist/island.js +227 -0
  52. package/dist/islandSolve.d.ts +70 -0
  53. package/dist/islandSolve.js +171 -0
  54. package/dist/islandWorker.d.ts +18 -0
  55. package/dist/islandWorker.js +125 -0
  56. package/dist/joints.d.ts +180 -0
  57. package/dist/joints.js +1094 -0
  58. package/dist/manifold.d.ts +89 -0
  59. package/dist/manifold.js +608 -0
  60. package/dist/mass.d.ts +53 -0
  61. package/dist/mass.js +353 -0
  62. package/dist/meshContact.d.ts +57 -0
  63. package/dist/meshContact.js +393 -0
  64. package/dist/meshShape.d.ts +76 -0
  65. package/dist/meshShape.js +175 -0
  66. package/dist/pairs.d.ts +62 -0
  67. package/dist/pairs.js +154 -0
  68. package/dist/query.d.ts +71 -0
  69. package/dist/query.js +683 -0
  70. package/dist/ragdoll.d.ts +135 -0
  71. package/dist/ragdoll.js +489 -0
  72. package/dist/shape.d.ts +177 -0
  73. package/dist/shape.js +533 -0
  74. package/dist/solver.d.ts +136 -0
  75. package/dist/solver.js +601 -0
  76. package/dist/stage.d.ts +167 -0
  77. package/dist/stage.js +350 -0
  78. package/dist/stallEscape.d.ts +141 -0
  79. package/dist/stallEscape.js +254 -0
  80. package/dist/sweptStep.d.ts +173 -0
  81. package/dist/sweptStep.js +472 -0
  82. package/dist/tree.d.ts +61 -0
  83. package/dist/tree.js +348 -0
  84. package/dist/vehicle.d.ts +154 -0
  85. package/dist/vehicle.js +343 -0
  86. package/dist/workerPool.d.ts +107 -0
  87. package/dist/workerPool.js +239 -0
  88. package/dist/workers.d.ts +37 -0
  89. package/dist/workers.js +35 -0
  90. package/dist/world.d.ts +298 -0
  91. package/dist/world.js +712 -0
  92. package/package.json +55 -0
  93. package/src/bodies.ts +369 -0
  94. package/src/buoyancy.ts +78 -0
  95. package/src/cloth.ts +734 -0
  96. package/src/collide/aabb.ts +28 -0
  97. package/src/collide/body.ts +336 -0
  98. package/src/collide/eject.ts +156 -0
  99. package/src/collide/index.ts +26 -0
  100. package/src/collide/scratch.ts +10 -0
  101. package/src/collide/segment.ts +127 -0
  102. package/src/collide/sweep.ts +1132 -0
  103. package/src/colliderSet.ts +637 -0
  104. package/src/compoundContact.ts +284 -0
  105. package/src/controller.ts +817 -0
  106. package/src/cylinder.ts +340 -0
  107. package/src/cylinderContact.ts +825 -0
  108. package/src/decompose.ts +1198 -0
  109. package/src/events.ts +108 -0
  110. package/src/executor.ts +224 -0
  111. package/src/faces.ts +37 -0
  112. package/src/fingerprint.ts +146 -0
  113. package/src/groundMotor.ts +53 -0
  114. package/src/heightfieldShape.ts +395 -0
  115. package/src/index.ts +164 -0
  116. package/src/island.ts +219 -0
  117. package/src/islandSolve.ts +218 -0
  118. package/src/islandWorker.ts +141 -0
  119. package/src/joints.ts +1367 -0
  120. package/src/manifold.ts +798 -0
  121. package/src/mass.ts +424 -0
  122. package/src/meshContact.ts +443 -0
  123. package/src/meshShape.ts +261 -0
  124. package/src/pairs.ts +169 -0
  125. package/src/query.ts +844 -0
  126. package/src/ragdoll.ts +662 -0
  127. package/src/shape.ts +656 -0
  128. package/src/solver.ts +873 -0
  129. package/src/stage.ts +406 -0
  130. package/src/stallEscape.ts +362 -0
  131. package/src/sweptStep.ts +609 -0
  132. package/src/tree.ts +366 -0
  133. package/src/vehicle.ts +489 -0
  134. package/src/workerPool.ts +283 -0
  135. package/src/workers.ts +38 -0
  136. package/src/world.ts +961 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * A triangle mesh, offline, into a handful of convex hulls the runtime can carry on one body.
3
+ *
4
+ * **This is the only function in this package that is not meant to run in a frame**, and that is a
5
+ * statement about what it costs rather than about where it lives. It allocates three grids, walks
6
+ * every cell of them several times, and calls `hullShape` once per part. A bake does that; a tick
7
+ * does not. The convex-decomposition design records the
8
+ * refusal and what would reverse it.
9
+ *
10
+ * **It lives here anyway, beside `hullShape`, because that is what it produces.** The fixtures
11
+ * `scripts/size-gate.test.mjs` measures import named symbols and this package is `sideEffects:
12
+ * false`, so a consumer who never calls this never bundles it — which is measured by `physics-only`
13
+ * staying where it is rather than asserted here.
14
+ *
15
+ * **Why a voxel grid and not the triangles.** A collision mesh is a triangle soup: it is routinely
16
+ * not watertight, routinely self-intersecting, and routinely has a hole where an artist deleted a
17
+ * face nobody would see. Every decomposition that reasons over the source triangles has to decide
18
+ * what the inside of such a thing is, and gets it wrong in a way that depends on the mesh. A grid
19
+ * with a flood fill from the outside answers that question once, the same way, for any input — and
20
+ * its cost is set by the resolution rather than by the triangle count, so a 200,000-triangle
21
+ * collision mesh decomposes in the time a 2,000-triangle one does.
22
+ *
23
+ * **What it gives up** is everything below the cell size: a plate thinner than one cell either
24
+ * disappears or becomes a cell thick. `resolution` is the control, and `Decomposition.resolution`
25
+ * reports what was actually used so a caller who passed nothing can see it.
26
+ */
27
+ /** How the interior of the mesh is decided. See `DecomposeOptions.fill`. */
28
+ export type DecomposeFill = 'solid' | 'surface';
29
+ export interface DecomposeOptions {
30
+ /**
31
+ * Cells along the longest axis of the mesh's bounds. Default 64, refused above 256.
32
+ *
33
+ * **The cap is stated because the alternative is discovering it as an allocation failure.** Two
34
+ * grids are held, a byte of state and four bytes of region index per cell, so 256 is 16.8 million
35
+ * cells and **83.9 MB**. 64 is 262,144 cells and 1.3 MB, which is the design point.
36
+ */
37
+ readonly resolution?: number;
38
+ /** How many hulls to stop at. Default 16, refused above `MAX_BODY_PARTS`. */
39
+ readonly maxHulls?: number;
40
+ /**
41
+ * How empty a merged region's bounding box may be before the merge stops being free. Default 0.05.
42
+ *
43
+ * It does not cap the part count: merging continues past this while more than `maxHulls` regions
44
+ * remain, because a caller asked for a body that a body can be made of. Below that count it is
45
+ * what decides whether two neighbours are worth keeping apart.
46
+ */
47
+ readonly concavity?: number;
48
+ /**
49
+ * `'solid'` fills the interior, `'surface'` keeps the shell alone. Default `'solid'`.
50
+ *
51
+ * **A mesh with a hole in it leaks under `'solid'`, and the fill has no way to know.** The flood
52
+ * escapes through the hole, nothing is left marked inside, and the result is the shell — which is
53
+ * very nearly harmless for collision, because contact only ever touches the boundary, and wrong
54
+ * for mass, because a hollow solid has the wrong inertia. `Decomposition.sourceVolume` is the
55
+ * voxelised volume, so the hollow is visible in the number; `'surface'` is how a caller asks for
56
+ * it deliberately.
57
+ */
58
+ readonly fill?: DecomposeFill;
59
+ }
60
+ /** One convex piece of the decomposition, ready for `hullShape`. */
61
+ export interface ConvexPart {
62
+ /** xyz-packed, at most `SUPPORT_DIRECTIONS` points, in the source mesh's own space. */
63
+ readonly points: Float32Array;
64
+ /** The hull's volume, exactly, by the tetrahedral decomposition `mass.ts` already computes. */
65
+ readonly volume: number;
66
+ /** Cells this part was grown from, as a fraction of its own hull volume. */
67
+ readonly fill: number;
68
+ }
69
+ export interface Decomposition {
70
+ readonly parts: readonly ConvexPart[];
71
+ /** The voxelised source's volume. What `bloat` is measured against. */
72
+ readonly sourceVolume: number;
73
+ /** The parts' volumes summed, which double-counts wherever two hulls overlap. */
74
+ readonly hullVolume: number;
75
+ /**
76
+ * `(hullVolume - sourceVolume) / sourceVolume`: the empty space the decomposition added.
77
+ *
78
+ * **The number that says whether the decomposition is worth having.** A single hull of a bowl has
79
+ * an enormous one; a decomposition that respects the cavity has a small one. It is not a bound on
80
+ * error in either direction — a hull can only add space, never remove it — which is why
81
+ * `coverage` is reported beside it.
82
+ */
83
+ readonly bloat: number;
84
+ /**
85
+ * The fraction of solid cells whose centre lies inside the part they were grown into.
86
+ *
87
+ * **Below one, and that is the support sampling of `SUPPORT_DIRECTIONS` showing up.** A support
88
+ * set is inscribed in the true hull of a region's corners, so a cell at a corner the direction set
89
+ * does not point at can fall outside by a little. It is the one place this function loses material
90
+ * rather than adding it.
91
+ */
92
+ readonly coverage: number;
93
+ /** The grid that was used, which a caller who passed no resolution wants to know. */
94
+ readonly resolution: number;
95
+ /** Cells in that grid, all three axes multiplied. */
96
+ readonly cells: number;
97
+ }
98
+ /** The default `maxHulls`, chosen so a decomposed body is well inside `MAX_BODY_PARTS`. */
99
+ export declare const DEFAULT_MAX_HULLS = 16;
100
+ /** The default and maximum grids. See `DecomposeOptions.resolution`. */
101
+ export declare const DEFAULT_RESOLUTION = 64;
102
+ export declare const MAX_RESOLUTION = 256;
103
+ /** How many, which is also the most points any part can carry. */
104
+ export declare const SUPPORT_DIRECTIONS: number;
105
+ export declare function decomposeConvex(positions: ArrayLike<number>, indices: ArrayLike<number>, options?: DecomposeOptions): Decomposition;