@newkrok/nape-js 3.22.1 → 3.24.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.
- package/dist/{chunk-BGYJWPQX.cjs → chunk-OFVSWS4I.cjs} +2 -2
- package/dist/{chunk-XFL4PQ5L.js → chunk-ZNBQE3PX.js} +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +205 -1
- package/dist/index.d.ts +205 -1
- package/dist/index.js +1 -1
- package/dist/serialization/index.cjs +1 -1
- package/dist/serialization/index.js +1 -1
- package/llms-full.txt +44 -0
- package/llms.txt +6 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1169,6 +1169,70 @@ declare class PulleyJoint extends Constraint {
|
|
|
1169
1169
|
visitBodies(lambda: (body: Body) => void): void;
|
|
1170
1170
|
}
|
|
1171
1171
|
|
|
1172
|
+
/**
|
|
1173
|
+
* A spring/damper constraint between two anchor points on two bodies.
|
|
1174
|
+
*
|
|
1175
|
+
* Applies a spring force that pulls or pushes the anchors toward a target
|
|
1176
|
+
* `restLength`. The spring behavior is controlled by `frequency` (Hz) and
|
|
1177
|
+
* `damping` (ratio), inherited from {@link Constraint}.
|
|
1178
|
+
*
|
|
1179
|
+
* Unlike {@link DistanceJoint}, a SpringJoint:
|
|
1180
|
+
* - Is **always soft** — there is no rigid/stiff mode.
|
|
1181
|
+
* - Has a single `restLength` instead of a `[jointMin, jointMax]` range.
|
|
1182
|
+
* - Applies force in **both directions** (compression and extension).
|
|
1183
|
+
* - Never goes slack — the spring always exerts a restorative force.
|
|
1184
|
+
*
|
|
1185
|
+
* Ideal for: vehicle suspension, soft-body connections, ragdoll hair/cloth,
|
|
1186
|
+
* bouncy UI animations, bridge/rope segments, trampolines.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* const spring = new SpringJoint(
|
|
1191
|
+
* body1, body2,
|
|
1192
|
+
* Vec2.weak(0, 0), // anchor on body1 (local)
|
|
1193
|
+
* Vec2.weak(0, 0), // anchor on body2 (local)
|
|
1194
|
+
* 100, // rest length (pixels)
|
|
1195
|
+
* );
|
|
1196
|
+
* spring.frequency = 5; // 5 Hz oscillation
|
|
1197
|
+
* spring.damping = 0.5; // underdamped (bouncy)
|
|
1198
|
+
* spring.space = space;
|
|
1199
|
+
* ```
|
|
1200
|
+
*/
|
|
1201
|
+
declare class SpringJoint extends Constraint {
|
|
1202
|
+
/**
|
|
1203
|
+
* @param body1 - First body, or `null` for a static world anchor.
|
|
1204
|
+
* @param body2 - Second body, or `null` for a static world anchor.
|
|
1205
|
+
* @param anchor1 - Anchor point in `body1`'s local space (disposed if weak).
|
|
1206
|
+
* @param anchor2 - Anchor point in `body2`'s local space (disposed if weak).
|
|
1207
|
+
* @param restLength - Equilibrium distance between anchors (must be `>= 0`).
|
|
1208
|
+
*/
|
|
1209
|
+
constructor(body1: Body | null, body2: Body | null, anchor1: Vec2, anchor2: Vec2, restLength: number);
|
|
1210
|
+
/** First body. `null` treats the anchor as a static world point. */
|
|
1211
|
+
get body1(): Body;
|
|
1212
|
+
set body1(value: Body | null);
|
|
1213
|
+
/** Second body. `null` treats the anchor as a static world point. */
|
|
1214
|
+
get body2(): Body;
|
|
1215
|
+
set body2(value: Body | null);
|
|
1216
|
+
/** Anchor point on `body1` in local coordinates. */
|
|
1217
|
+
get anchor1(): Vec2;
|
|
1218
|
+
set anchor1(value: Vec2);
|
|
1219
|
+
/** Anchor point on `body2` in local coordinates. */
|
|
1220
|
+
get anchor2(): Vec2;
|
|
1221
|
+
set anchor2(value: Vec2);
|
|
1222
|
+
/** Equilibrium distance between anchors (pixels, must be `>= 0`). */
|
|
1223
|
+
get restLength(): number;
|
|
1224
|
+
set restLength(value: number);
|
|
1225
|
+
/**
|
|
1226
|
+
* SpringJoint is always soft — setting `stiff` to `true` is not allowed.
|
|
1227
|
+
* Use {@link DistanceJoint} if you need a rigid distance constraint.
|
|
1228
|
+
*/
|
|
1229
|
+
get stiff(): boolean;
|
|
1230
|
+
set stiff(_value: boolean);
|
|
1231
|
+
impulse(): MatMN;
|
|
1232
|
+
bodyImpulse(body: Body): Vec3;
|
|
1233
|
+
visitBodies(lambda: (body: Body) => void): void;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1172
1236
|
/**
|
|
1173
1237
|
* ZPP_Constraint — Internal base class for all constraints / joints.
|
|
1174
1238
|
*
|
|
@@ -1656,6 +1720,146 @@ declare class TriggerZone {
|
|
|
1656
1720
|
private _removeListener;
|
|
1657
1721
|
}
|
|
1658
1722
|
|
|
1723
|
+
/**
|
|
1724
|
+
* Voronoi diagram generation for 2D point sets.
|
|
1725
|
+
*
|
|
1726
|
+
* Uses the half-plane intersection method: for each site, start with the
|
|
1727
|
+
* bounding box and clip by the perpendicular bisector against every other site.
|
|
1728
|
+
* This is O(n²) but perfectly robust for the fracture use-case (typically 4–30
|
|
1729
|
+
* sites). Every cell is guaranteed to be a finite, closed, convex polygon.
|
|
1730
|
+
*
|
|
1731
|
+
* Designed for use in fracture/destruction systems.
|
|
1732
|
+
*/
|
|
1733
|
+
/** A 2D point (plain object — avoids coupling to Vec2 pooling). */
|
|
1734
|
+
interface VoronoiPoint {
|
|
1735
|
+
x: number;
|
|
1736
|
+
y: number;
|
|
1737
|
+
}
|
|
1738
|
+
/** A single Voronoi cell: the site that generated it and its polygon vertices (CCW). */
|
|
1739
|
+
interface VoronoiCell {
|
|
1740
|
+
/** The generating site index (into the original points array). */
|
|
1741
|
+
siteIndex: number;
|
|
1742
|
+
/** The generating site coordinates. */
|
|
1743
|
+
site: VoronoiPoint;
|
|
1744
|
+
/** Cell polygon vertices in counter-clockwise order. */
|
|
1745
|
+
vertices: VoronoiPoint[];
|
|
1746
|
+
}
|
|
1747
|
+
/** Result of a Voronoi diagram computation. */
|
|
1748
|
+
interface VoronoiResult {
|
|
1749
|
+
/** One cell per input site, in the same order as the input points. */
|
|
1750
|
+
cells: VoronoiCell[];
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Compute the Voronoi diagram for a set of 2D points, clipped to a bounding box.
|
|
1754
|
+
*
|
|
1755
|
+
* Uses half-plane intersection: for each site, clips the bounding rectangle by
|
|
1756
|
+
* the perpendicular bisector with every other site. Produces one convex cell per
|
|
1757
|
+
* site, all cells together tile the bounding box exactly.
|
|
1758
|
+
*
|
|
1759
|
+
* @param points - Array of site points. Must contain at least 1 point.
|
|
1760
|
+
* @param bounds - Clipping rectangle `{ minX, minY, maxX, maxY }`.
|
|
1761
|
+
* @returns A `VoronoiResult` containing one cell per input point.
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```ts
|
|
1765
|
+
* const result = computeVoronoi(
|
|
1766
|
+
* [{ x: 10, y: 10 }, { x: 90, y: 50 }, { x: 50, y: 90 }],
|
|
1767
|
+
* { minX: 0, minY: 0, maxX: 100, maxY: 100 },
|
|
1768
|
+
* );
|
|
1769
|
+
* for (const cell of result.cells) {
|
|
1770
|
+
* console.log(`Site ${cell.siteIndex}:`, cell.vertices);
|
|
1771
|
+
* }
|
|
1772
|
+
* ```
|
|
1773
|
+
*/
|
|
1774
|
+
declare function computeVoronoi(points: ReadonlyArray<Readonly<VoronoiPoint>>, bounds: {
|
|
1775
|
+
minX: number;
|
|
1776
|
+
minY: number;
|
|
1777
|
+
maxX: number;
|
|
1778
|
+
maxY: number;
|
|
1779
|
+
}): VoronoiResult;
|
|
1780
|
+
/**
|
|
1781
|
+
* Generate random Voronoi fracture sites within a polygon.
|
|
1782
|
+
*
|
|
1783
|
+
* Places `count` random points inside the given polygon using rejection
|
|
1784
|
+
* sampling. Useful for generating fracture patterns.
|
|
1785
|
+
*
|
|
1786
|
+
* @param vertices - Polygon vertices (as VoronoiPoint[]).
|
|
1787
|
+
* @param count - Number of sites to generate.
|
|
1788
|
+
* @param random - Optional RNG function (default `Math.random`).
|
|
1789
|
+
* @returns Array of points guaranteed to be inside the polygon.
|
|
1790
|
+
*/
|
|
1791
|
+
declare function generateFractureSites(vertices: ReadonlyArray<Readonly<VoronoiPoint>>, count: number, random?: () => number): VoronoiPoint[];
|
|
1792
|
+
|
|
1793
|
+
/**
|
|
1794
|
+
* Options for body fracture.
|
|
1795
|
+
*/
|
|
1796
|
+
interface FractureOptions {
|
|
1797
|
+
/** Number of fracture fragments to generate. Default `8`. */
|
|
1798
|
+
fragmentCount?: number;
|
|
1799
|
+
/**
|
|
1800
|
+
* Material to apply to all fragment shapes.
|
|
1801
|
+
* If not specified, the first shape's material is copied from the original body.
|
|
1802
|
+
*/
|
|
1803
|
+
material?: Material;
|
|
1804
|
+
/** Interaction filter for all fragment shapes. */
|
|
1805
|
+
filter?: InteractionFilter;
|
|
1806
|
+
/**
|
|
1807
|
+
* Explosion impulse magnitude applied radially from the impact point.
|
|
1808
|
+
* Default `0` (no explosion impulse — fragments inherit body velocity).
|
|
1809
|
+
*/
|
|
1810
|
+
explosionImpulse?: number;
|
|
1811
|
+
/**
|
|
1812
|
+
* Custom RNG function for reproducible fracture patterns.
|
|
1813
|
+
* Default `Math.random`.
|
|
1814
|
+
*/
|
|
1815
|
+
random?: () => number;
|
|
1816
|
+
/**
|
|
1817
|
+
* If true, automatically add fragments to the same space as the original body
|
|
1818
|
+
* and remove the original body. Default `true`.
|
|
1819
|
+
*/
|
|
1820
|
+
addToSpace?: boolean;
|
|
1821
|
+
/**
|
|
1822
|
+
* Custom Voronoi site positions (in body-local space).
|
|
1823
|
+
* If provided, `fragmentCount` is ignored and these exact sites are used.
|
|
1824
|
+
*/
|
|
1825
|
+
sites?: VoronoiPoint[];
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Result of a fracture operation.
|
|
1829
|
+
*/
|
|
1830
|
+
interface FractureResult {
|
|
1831
|
+
/** The generated fragment bodies. */
|
|
1832
|
+
fragments: Body[];
|
|
1833
|
+
/** The original body that was fractured (removed from space if `addToSpace` is true). */
|
|
1834
|
+
originalBody: Body;
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Fracture a body into multiple pieces using Voronoi decomposition.
|
|
1838
|
+
*
|
|
1839
|
+
* Takes the first polygon shape on the body, generates Voronoi cells within it,
|
|
1840
|
+
* clips each cell to the original polygon, and creates a new dynamic body for
|
|
1841
|
+
* each fragment. Fragments inherit the original body's linear and angular
|
|
1842
|
+
* velocity, plus an optional radial explosion impulse.
|
|
1843
|
+
*
|
|
1844
|
+
* @param body - The body to fracture. Must have at least one polygon shape.
|
|
1845
|
+
* @param impactPoint - World-space point where the fracture originates.
|
|
1846
|
+
* Used as the center bias for site generation and explosion impulse direction.
|
|
1847
|
+
* @param options - Fracture configuration.
|
|
1848
|
+
* @returns A `FractureResult` with the array of fragment bodies.
|
|
1849
|
+
*
|
|
1850
|
+
* @throws If the body has no polygon shapes.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```ts
|
|
1854
|
+
* const result = fractureBody(box, Vec2.get(100, 50), {
|
|
1855
|
+
* fragmentCount: 12,
|
|
1856
|
+
* explosionImpulse: 200,
|
|
1857
|
+
* });
|
|
1858
|
+
* // result.fragments are already in the space
|
|
1859
|
+
* ```
|
|
1860
|
+
*/
|
|
1861
|
+
declare function fractureBody(body: Body, impactPoint: Vec2, options?: FractureOptions): FractureResult;
|
|
1862
|
+
|
|
1659
1863
|
declare const VERSION: string;
|
|
1660
1864
|
|
|
1661
|
-
export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, type TriggerHandler, TriggerZone, type TriggerZoneOptions, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding, createConcaveBody };
|
|
1865
|
+
export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, type FractureOptions, type FractureResult, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, SpringJoint, type TriggerHandler, TriggerZone, type TriggerZoneOptions, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, type VoronoiCell, type VoronoiPoint, type VoronoiResult, WeldJoint, Winding, computeVoronoi, createConcaveBody, fractureBody, generateFractureSites };
|
package/dist/index.d.ts
CHANGED
|
@@ -1169,6 +1169,70 @@ declare class PulleyJoint extends Constraint {
|
|
|
1169
1169
|
visitBodies(lambda: (body: Body) => void): void;
|
|
1170
1170
|
}
|
|
1171
1171
|
|
|
1172
|
+
/**
|
|
1173
|
+
* A spring/damper constraint between two anchor points on two bodies.
|
|
1174
|
+
*
|
|
1175
|
+
* Applies a spring force that pulls or pushes the anchors toward a target
|
|
1176
|
+
* `restLength`. The spring behavior is controlled by `frequency` (Hz) and
|
|
1177
|
+
* `damping` (ratio), inherited from {@link Constraint}.
|
|
1178
|
+
*
|
|
1179
|
+
* Unlike {@link DistanceJoint}, a SpringJoint:
|
|
1180
|
+
* - Is **always soft** — there is no rigid/stiff mode.
|
|
1181
|
+
* - Has a single `restLength` instead of a `[jointMin, jointMax]` range.
|
|
1182
|
+
* - Applies force in **both directions** (compression and extension).
|
|
1183
|
+
* - Never goes slack — the spring always exerts a restorative force.
|
|
1184
|
+
*
|
|
1185
|
+
* Ideal for: vehicle suspension, soft-body connections, ragdoll hair/cloth,
|
|
1186
|
+
* bouncy UI animations, bridge/rope segments, trampolines.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```ts
|
|
1190
|
+
* const spring = new SpringJoint(
|
|
1191
|
+
* body1, body2,
|
|
1192
|
+
* Vec2.weak(0, 0), // anchor on body1 (local)
|
|
1193
|
+
* Vec2.weak(0, 0), // anchor on body2 (local)
|
|
1194
|
+
* 100, // rest length (pixels)
|
|
1195
|
+
* );
|
|
1196
|
+
* spring.frequency = 5; // 5 Hz oscillation
|
|
1197
|
+
* spring.damping = 0.5; // underdamped (bouncy)
|
|
1198
|
+
* spring.space = space;
|
|
1199
|
+
* ```
|
|
1200
|
+
*/
|
|
1201
|
+
declare class SpringJoint extends Constraint {
|
|
1202
|
+
/**
|
|
1203
|
+
* @param body1 - First body, or `null` for a static world anchor.
|
|
1204
|
+
* @param body2 - Second body, or `null` for a static world anchor.
|
|
1205
|
+
* @param anchor1 - Anchor point in `body1`'s local space (disposed if weak).
|
|
1206
|
+
* @param anchor2 - Anchor point in `body2`'s local space (disposed if weak).
|
|
1207
|
+
* @param restLength - Equilibrium distance between anchors (must be `>= 0`).
|
|
1208
|
+
*/
|
|
1209
|
+
constructor(body1: Body | null, body2: Body | null, anchor1: Vec2, anchor2: Vec2, restLength: number);
|
|
1210
|
+
/** First body. `null` treats the anchor as a static world point. */
|
|
1211
|
+
get body1(): Body;
|
|
1212
|
+
set body1(value: Body | null);
|
|
1213
|
+
/** Second body. `null` treats the anchor as a static world point. */
|
|
1214
|
+
get body2(): Body;
|
|
1215
|
+
set body2(value: Body | null);
|
|
1216
|
+
/** Anchor point on `body1` in local coordinates. */
|
|
1217
|
+
get anchor1(): Vec2;
|
|
1218
|
+
set anchor1(value: Vec2);
|
|
1219
|
+
/** Anchor point on `body2` in local coordinates. */
|
|
1220
|
+
get anchor2(): Vec2;
|
|
1221
|
+
set anchor2(value: Vec2);
|
|
1222
|
+
/** Equilibrium distance between anchors (pixels, must be `>= 0`). */
|
|
1223
|
+
get restLength(): number;
|
|
1224
|
+
set restLength(value: number);
|
|
1225
|
+
/**
|
|
1226
|
+
* SpringJoint is always soft — setting `stiff` to `true` is not allowed.
|
|
1227
|
+
* Use {@link DistanceJoint} if you need a rigid distance constraint.
|
|
1228
|
+
*/
|
|
1229
|
+
get stiff(): boolean;
|
|
1230
|
+
set stiff(_value: boolean);
|
|
1231
|
+
impulse(): MatMN;
|
|
1232
|
+
bodyImpulse(body: Body): Vec3;
|
|
1233
|
+
visitBodies(lambda: (body: Body) => void): void;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1172
1236
|
/**
|
|
1173
1237
|
* ZPP_Constraint — Internal base class for all constraints / joints.
|
|
1174
1238
|
*
|
|
@@ -1656,6 +1720,146 @@ declare class TriggerZone {
|
|
|
1656
1720
|
private _removeListener;
|
|
1657
1721
|
}
|
|
1658
1722
|
|
|
1723
|
+
/**
|
|
1724
|
+
* Voronoi diagram generation for 2D point sets.
|
|
1725
|
+
*
|
|
1726
|
+
* Uses the half-plane intersection method: for each site, start with the
|
|
1727
|
+
* bounding box and clip by the perpendicular bisector against every other site.
|
|
1728
|
+
* This is O(n²) but perfectly robust for the fracture use-case (typically 4–30
|
|
1729
|
+
* sites). Every cell is guaranteed to be a finite, closed, convex polygon.
|
|
1730
|
+
*
|
|
1731
|
+
* Designed for use in fracture/destruction systems.
|
|
1732
|
+
*/
|
|
1733
|
+
/** A 2D point (plain object — avoids coupling to Vec2 pooling). */
|
|
1734
|
+
interface VoronoiPoint {
|
|
1735
|
+
x: number;
|
|
1736
|
+
y: number;
|
|
1737
|
+
}
|
|
1738
|
+
/** A single Voronoi cell: the site that generated it and its polygon vertices (CCW). */
|
|
1739
|
+
interface VoronoiCell {
|
|
1740
|
+
/** The generating site index (into the original points array). */
|
|
1741
|
+
siteIndex: number;
|
|
1742
|
+
/** The generating site coordinates. */
|
|
1743
|
+
site: VoronoiPoint;
|
|
1744
|
+
/** Cell polygon vertices in counter-clockwise order. */
|
|
1745
|
+
vertices: VoronoiPoint[];
|
|
1746
|
+
}
|
|
1747
|
+
/** Result of a Voronoi diagram computation. */
|
|
1748
|
+
interface VoronoiResult {
|
|
1749
|
+
/** One cell per input site, in the same order as the input points. */
|
|
1750
|
+
cells: VoronoiCell[];
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* Compute the Voronoi diagram for a set of 2D points, clipped to a bounding box.
|
|
1754
|
+
*
|
|
1755
|
+
* Uses half-plane intersection: for each site, clips the bounding rectangle by
|
|
1756
|
+
* the perpendicular bisector with every other site. Produces one convex cell per
|
|
1757
|
+
* site, all cells together tile the bounding box exactly.
|
|
1758
|
+
*
|
|
1759
|
+
* @param points - Array of site points. Must contain at least 1 point.
|
|
1760
|
+
* @param bounds - Clipping rectangle `{ minX, minY, maxX, maxY }`.
|
|
1761
|
+
* @returns A `VoronoiResult` containing one cell per input point.
|
|
1762
|
+
*
|
|
1763
|
+
* @example
|
|
1764
|
+
* ```ts
|
|
1765
|
+
* const result = computeVoronoi(
|
|
1766
|
+
* [{ x: 10, y: 10 }, { x: 90, y: 50 }, { x: 50, y: 90 }],
|
|
1767
|
+
* { minX: 0, minY: 0, maxX: 100, maxY: 100 },
|
|
1768
|
+
* );
|
|
1769
|
+
* for (const cell of result.cells) {
|
|
1770
|
+
* console.log(`Site ${cell.siteIndex}:`, cell.vertices);
|
|
1771
|
+
* }
|
|
1772
|
+
* ```
|
|
1773
|
+
*/
|
|
1774
|
+
declare function computeVoronoi(points: ReadonlyArray<Readonly<VoronoiPoint>>, bounds: {
|
|
1775
|
+
minX: number;
|
|
1776
|
+
minY: number;
|
|
1777
|
+
maxX: number;
|
|
1778
|
+
maxY: number;
|
|
1779
|
+
}): VoronoiResult;
|
|
1780
|
+
/**
|
|
1781
|
+
* Generate random Voronoi fracture sites within a polygon.
|
|
1782
|
+
*
|
|
1783
|
+
* Places `count` random points inside the given polygon using rejection
|
|
1784
|
+
* sampling. Useful for generating fracture patterns.
|
|
1785
|
+
*
|
|
1786
|
+
* @param vertices - Polygon vertices (as VoronoiPoint[]).
|
|
1787
|
+
* @param count - Number of sites to generate.
|
|
1788
|
+
* @param random - Optional RNG function (default `Math.random`).
|
|
1789
|
+
* @returns Array of points guaranteed to be inside the polygon.
|
|
1790
|
+
*/
|
|
1791
|
+
declare function generateFractureSites(vertices: ReadonlyArray<Readonly<VoronoiPoint>>, count: number, random?: () => number): VoronoiPoint[];
|
|
1792
|
+
|
|
1793
|
+
/**
|
|
1794
|
+
* Options for body fracture.
|
|
1795
|
+
*/
|
|
1796
|
+
interface FractureOptions {
|
|
1797
|
+
/** Number of fracture fragments to generate. Default `8`. */
|
|
1798
|
+
fragmentCount?: number;
|
|
1799
|
+
/**
|
|
1800
|
+
* Material to apply to all fragment shapes.
|
|
1801
|
+
* If not specified, the first shape's material is copied from the original body.
|
|
1802
|
+
*/
|
|
1803
|
+
material?: Material;
|
|
1804
|
+
/** Interaction filter for all fragment shapes. */
|
|
1805
|
+
filter?: InteractionFilter;
|
|
1806
|
+
/**
|
|
1807
|
+
* Explosion impulse magnitude applied radially from the impact point.
|
|
1808
|
+
* Default `0` (no explosion impulse — fragments inherit body velocity).
|
|
1809
|
+
*/
|
|
1810
|
+
explosionImpulse?: number;
|
|
1811
|
+
/**
|
|
1812
|
+
* Custom RNG function for reproducible fracture patterns.
|
|
1813
|
+
* Default `Math.random`.
|
|
1814
|
+
*/
|
|
1815
|
+
random?: () => number;
|
|
1816
|
+
/**
|
|
1817
|
+
* If true, automatically add fragments to the same space as the original body
|
|
1818
|
+
* and remove the original body. Default `true`.
|
|
1819
|
+
*/
|
|
1820
|
+
addToSpace?: boolean;
|
|
1821
|
+
/**
|
|
1822
|
+
* Custom Voronoi site positions (in body-local space).
|
|
1823
|
+
* If provided, `fragmentCount` is ignored and these exact sites are used.
|
|
1824
|
+
*/
|
|
1825
|
+
sites?: VoronoiPoint[];
|
|
1826
|
+
}
|
|
1827
|
+
/**
|
|
1828
|
+
* Result of a fracture operation.
|
|
1829
|
+
*/
|
|
1830
|
+
interface FractureResult {
|
|
1831
|
+
/** The generated fragment bodies. */
|
|
1832
|
+
fragments: Body[];
|
|
1833
|
+
/** The original body that was fractured (removed from space if `addToSpace` is true). */
|
|
1834
|
+
originalBody: Body;
|
|
1835
|
+
}
|
|
1836
|
+
/**
|
|
1837
|
+
* Fracture a body into multiple pieces using Voronoi decomposition.
|
|
1838
|
+
*
|
|
1839
|
+
* Takes the first polygon shape on the body, generates Voronoi cells within it,
|
|
1840
|
+
* clips each cell to the original polygon, and creates a new dynamic body for
|
|
1841
|
+
* each fragment. Fragments inherit the original body's linear and angular
|
|
1842
|
+
* velocity, plus an optional radial explosion impulse.
|
|
1843
|
+
*
|
|
1844
|
+
* @param body - The body to fracture. Must have at least one polygon shape.
|
|
1845
|
+
* @param impactPoint - World-space point where the fracture originates.
|
|
1846
|
+
* Used as the center bias for site generation and explosion impulse direction.
|
|
1847
|
+
* @param options - Fracture configuration.
|
|
1848
|
+
* @returns A `FractureResult` with the array of fragment bodies.
|
|
1849
|
+
*
|
|
1850
|
+
* @throws If the body has no polygon shapes.
|
|
1851
|
+
*
|
|
1852
|
+
* @example
|
|
1853
|
+
* ```ts
|
|
1854
|
+
* const result = fractureBody(box, Vec2.get(100, 50), {
|
|
1855
|
+
* fragmentCount: 12,
|
|
1856
|
+
* explosionImpulse: 200,
|
|
1857
|
+
* });
|
|
1858
|
+
* // result.fragments are already in the space
|
|
1859
|
+
* ```
|
|
1860
|
+
*/
|
|
1861
|
+
declare function fractureBody(body: Body, impactPoint: Vec2, options?: FractureOptions): FractureResult;
|
|
1862
|
+
|
|
1659
1863
|
declare const VERSION: string;
|
|
1660
1864
|
|
|
1661
|
-
export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, type TriggerHandler, TriggerZone, type TriggerZoneOptions, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, WeldJoint, Winding, createConcaveBody };
|
|
1865
|
+
export { AABB, AngleJoint, Arbiter, Body, BodyCallback, BodyListener, BodyType, Callback, Capsule, CbEvent, CbType, CharacterController, type CharacterControllerOptions, Circle, CollisionArbiter, type ConcaveBodyOptions, Constraint, ConstraintCallback, ConstraintListener, Contact, DebugDrawFlags, DistanceJoint, type FractureOptions, type FractureResult, Geom, GeomPoly, InteractionCallback, InteractionFilter, InteractionListener, InteractionType, Interactor, LineJoint, Listener, MarchingSquares, MatMN, Material, MotorJoint, type MoveResult, OptionType, PivotJoint, PreCallback, PreFlag, PreListener, PulleyJoint, Shape, ShapeType, Space, SpringJoint, type TriggerHandler, TriggerZone, type TriggerZoneOptions, UserConstraint, VERSION, ValidationResult, Vec2, Vec3, type VoronoiCell, type VoronoiPoint, type VoronoiResult, WeldJoint, Winding, computeVoronoi, createConcaveBody, fractureBody, generateFractureSites };
|