react-three-rapier-unified 1.0.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.
@@ -0,0 +1,1667 @@
1
+ import { Vector3 as Qe, Quaternion as at, ActiveEvents as Je, ColliderDesc as kt, EventQueue as It, RigidBodyDesc as Wt } from "@dimforge/rapier3d-compat";
2
+ import { CoefficientCombineRule as bo, Collider as xo, RigidBody as Co } from "@dimforge/rapier3d-compat";
3
+ import ne, { useRef as D, useEffect as N, memo as he, useMemo as ve, useContext as Ct, useState as vt, createContext as Et, useCallback as Ge, Fragment as zt } from "react";
4
+ import { useFrame as Ze, useThree as ht } from "@react-three/fiber";
5
+ import { Quaternion as qe, Euler as Ue, Vector3 as G, Object3D as Dt, Matrix4 as Vt, BufferGeometry as Jt, BufferAttribute as lt, MathUtils as Ht, DynamicDrawUsage as Yt, Mesh as Gt, SphereGeometry as qt, MeshBasicMaterial as Ut } from "three";
6
+ import { suspend as $t } from "suspend-react";
7
+ import { mergeVertices as Lt, VertexNormalsHelper as Qt } from "three-stdlib";
8
+ var He = { exports: {} }, Oe = {};
9
+ /**
10
+ * @license React
11
+ * react-jsx-runtime.production.js
12
+ *
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */
18
+ var ut;
19
+ function Xt() {
20
+ if (ut) return Oe;
21
+ ut = 1;
22
+ var e = Symbol.for("react.transitional.element"), t = Symbol.for("react.fragment");
23
+ function o(n, i, s) {
24
+ var c = null;
25
+ if (s !== void 0 && (c = "" + s), i.key !== void 0 && (c = "" + i.key), "key" in i) {
26
+ s = {};
27
+ for (var a in i)
28
+ a !== "key" && (s[a] = i[a]);
29
+ } else s = i;
30
+ return i = s.ref, {
31
+ $$typeof: e,
32
+ type: n,
33
+ key: c,
34
+ ref: i !== void 0 ? i : null,
35
+ props: s
36
+ };
37
+ }
38
+ return Oe.Fragment = t, Oe.jsx = o, Oe.jsxs = o, Oe;
39
+ }
40
+ var _e = {};
41
+ /**
42
+ * @license React
43
+ * react-jsx-runtime.development.js
44
+ *
45
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
46
+ *
47
+ * This source code is licensed under the MIT license found in the
48
+ * LICENSE file in the root directory of this source tree.
49
+ */
50
+ var dt;
51
+ function Zt() {
52
+ return dt || (dt = 1, process.env.NODE_ENV !== "production" && (function() {
53
+ function e(r) {
54
+ if (r == null) return null;
55
+ if (typeof r == "function")
56
+ return r.$$typeof === ue ? null : r.displayName || r.name || null;
57
+ if (typeof r == "string") return r;
58
+ switch (r) {
59
+ case V:
60
+ return "Fragment";
61
+ case _:
62
+ return "Portal";
63
+ case we:
64
+ return "Profiler";
65
+ case Te:
66
+ return "StrictMode";
67
+ case je:
68
+ return "Suspense";
69
+ case Pe:
70
+ return "SuspenseList";
71
+ }
72
+ if (typeof r == "object")
73
+ switch (typeof r.tag == "number" && console.error(
74
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
75
+ ), r.$$typeof) {
76
+ case Re:
77
+ return (r.displayName || "Context") + ".Provider";
78
+ case Se:
79
+ return (r._context.displayName || "Context") + ".Consumer";
80
+ case Me:
81
+ var u = r.render;
82
+ return r = r.displayName, r || (r = u.displayName || u.name || "", r = r !== "" ? "ForwardRef(" + r + ")" : "ForwardRef"), r;
83
+ case A:
84
+ return u = r.displayName || null, u !== null ? u : e(r.type) || "Memo";
85
+ case Fe:
86
+ u = r._payload, r = r._init;
87
+ try {
88
+ return e(r(u));
89
+ } catch {
90
+ }
91
+ }
92
+ return null;
93
+ }
94
+ function t(r) {
95
+ return "" + r;
96
+ }
97
+ function o(r) {
98
+ try {
99
+ t(r);
100
+ var u = !1;
101
+ } catch {
102
+ u = !0;
103
+ }
104
+ if (u) {
105
+ u = console;
106
+ var l = u.error, C = typeof Symbol == "function" && Symbol.toStringTag && r[Symbol.toStringTag] || r.constructor.name || "Object";
107
+ return l.call(
108
+ u,
109
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
110
+ C
111
+ ), t(r);
112
+ }
113
+ }
114
+ function n() {
115
+ }
116
+ function i() {
117
+ if (U === 0) {
118
+ xe = console.log, K = console.info, fe = console.warn, d = console.error, T = console.group, E = console.groupCollapsed, y = console.groupEnd;
119
+ var r = {
120
+ configurable: !0,
121
+ enumerable: !0,
122
+ value: n,
123
+ writable: !0
124
+ };
125
+ Object.defineProperties(console, {
126
+ info: r,
127
+ log: r,
128
+ warn: r,
129
+ error: r,
130
+ group: r,
131
+ groupCollapsed: r,
132
+ groupEnd: r
133
+ });
134
+ }
135
+ U++;
136
+ }
137
+ function s() {
138
+ if (U--, U === 0) {
139
+ var r = { configurable: !0, enumerable: !0, writable: !0 };
140
+ Object.defineProperties(console, {
141
+ log: de({}, r, { value: xe }),
142
+ info: de({}, r, { value: K }),
143
+ warn: de({}, r, { value: fe }),
144
+ error: de({}, r, { value: d }),
145
+ group: de({}, r, { value: T }),
146
+ groupCollapsed: de({}, r, { value: E }),
147
+ groupEnd: de({}, r, { value: y })
148
+ });
149
+ }
150
+ 0 > U && console.error(
151
+ "disabledDepth fell below zero. This is a bug in React. Please file an issue."
152
+ );
153
+ }
154
+ function c(r) {
155
+ if (w === void 0)
156
+ try {
157
+ throw Error();
158
+ } catch (l) {
159
+ var u = l.stack.trim().match(/\n( *(at )?)/);
160
+ w = u && u[1] || "", k = -1 < l.stack.indexOf(`
161
+ at`) ? " (<anonymous>)" : -1 < l.stack.indexOf("@") ? "@unknown:0:0" : "";
162
+ }
163
+ return `
164
+ ` + w + r + k;
165
+ }
166
+ function a(r, u) {
167
+ if (!r || B) return "";
168
+ var l = J.get(r);
169
+ if (l !== void 0) return l;
170
+ B = !0, l = Error.prepareStackTrace, Error.prepareStackTrace = void 0;
171
+ var C = null;
172
+ C = Z.H, Z.H = null, i();
173
+ try {
174
+ var j = {
175
+ DetermineComponentFrameRoot: function() {
176
+ try {
177
+ if (u) {
178
+ var X = function() {
179
+ throw Error();
180
+ };
181
+ if (Object.defineProperty(X.prototype, "props", {
182
+ set: function() {
183
+ throw Error();
184
+ }
185
+ }), typeof Reflect == "object" && Reflect.construct) {
186
+ try {
187
+ Reflect.construct(X, []);
188
+ } catch ($) {
189
+ var Ce = $;
190
+ }
191
+ Reflect.construct(r, [], X);
192
+ } else {
193
+ try {
194
+ X.call();
195
+ } catch ($) {
196
+ Ce = $;
197
+ }
198
+ r.call(X.prototype);
199
+ }
200
+ } else {
201
+ try {
202
+ throw Error();
203
+ } catch ($) {
204
+ Ce = $;
205
+ }
206
+ (X = r()) && typeof X.catch == "function" && X.catch(function() {
207
+ });
208
+ }
209
+ } catch ($) {
210
+ if ($ && Ce && typeof $.stack == "string")
211
+ return [$.stack, Ce.stack];
212
+ }
213
+ return [null, null];
214
+ }
215
+ };
216
+ j.DetermineComponentFrameRoot.displayName = "DetermineComponentFrameRoot";
217
+ var h = Object.getOwnPropertyDescriptor(
218
+ j.DetermineComponentFrameRoot,
219
+ "name"
220
+ );
221
+ h && h.configurable && Object.defineProperty(
222
+ j.DetermineComponentFrameRoot,
223
+ "name",
224
+ { value: "DetermineComponentFrameRoot" }
225
+ );
226
+ var m = j.DetermineComponentFrameRoot(), re = m[0], ie = m[1];
227
+ if (re && ie) {
228
+ var I = re.split(`
229
+ `), oe = ie.split(`
230
+ `);
231
+ for (m = h = 0; h < I.length && !I[h].includes(
232
+ "DetermineComponentFrameRoot"
233
+ ); )
234
+ h++;
235
+ for (; m < oe.length && !oe[m].includes(
236
+ "DetermineComponentFrameRoot"
237
+ ); )
238
+ m++;
239
+ if (h === I.length || m === oe.length)
240
+ for (h = I.length - 1, m = oe.length - 1; 1 <= h && 0 <= m && I[h] !== oe[m]; )
241
+ m--;
242
+ for (; 1 <= h && 0 <= m; h--, m--)
243
+ if (I[h] !== oe[m]) {
244
+ if (h !== 1 || m !== 1)
245
+ do
246
+ if (h--, m--, 0 > m || I[h] !== oe[m]) {
247
+ var pe = `
248
+ ` + I[h].replace(
249
+ " at new ",
250
+ " at "
251
+ );
252
+ return r.displayName && pe.includes("<anonymous>") && (pe = pe.replace("<anonymous>", r.displayName)), typeof r == "function" && J.set(r, pe), pe;
253
+ }
254
+ while (1 <= h && 0 <= m);
255
+ break;
256
+ }
257
+ }
258
+ } finally {
259
+ B = !1, Z.H = C, s(), Error.prepareStackTrace = l;
260
+ }
261
+ return I = (I = r ? r.displayName || r.name : "") ? c(I) : "", typeof r == "function" && J.set(r, I), I;
262
+ }
263
+ function x(r) {
264
+ if (r == null) return "";
265
+ if (typeof r == "function") {
266
+ var u = r.prototype;
267
+ return a(
268
+ r,
269
+ !(!u || !u.isReactComponent)
270
+ );
271
+ }
272
+ if (typeof r == "string") return c(r);
273
+ switch (r) {
274
+ case je:
275
+ return c("Suspense");
276
+ case Pe:
277
+ return c("SuspenseList");
278
+ }
279
+ if (typeof r == "object")
280
+ switch (r.$$typeof) {
281
+ case Me:
282
+ return r = a(r.render, !1), r;
283
+ case A:
284
+ return x(r.type);
285
+ case Fe:
286
+ u = r._payload, r = r._init;
287
+ try {
288
+ return x(r(u));
289
+ } catch {
290
+ }
291
+ }
292
+ return "";
293
+ }
294
+ function g() {
295
+ var r = Z.A;
296
+ return r === null ? null : r.getOwner();
297
+ }
298
+ function f(r) {
299
+ if (Be.call(r, "key")) {
300
+ var u = Object.getOwnPropertyDescriptor(r, "key").get;
301
+ if (u && u.isReactWarning) return !1;
302
+ }
303
+ return r.key !== void 0;
304
+ }
305
+ function R(r, u) {
306
+ function l() {
307
+ ee || (ee = !0, console.error(
308
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
309
+ u
310
+ ));
311
+ }
312
+ l.isReactWarning = !0, Object.defineProperty(r, "key", {
313
+ get: l,
314
+ configurable: !0
315
+ });
316
+ }
317
+ function v() {
318
+ var r = e(this.type);
319
+ return me[r] || (me[r] = !0, console.error(
320
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
321
+ )), r = this.props.ref, r !== void 0 ? r : null;
322
+ }
323
+ function M(r, u, l, C, j, h) {
324
+ return l = h.ref, r = {
325
+ $$typeof: le,
326
+ type: r,
327
+ key: u,
328
+ props: h,
329
+ _owner: j
330
+ }, (l !== void 0 ? l : null) !== null ? Object.defineProperty(r, "ref", {
331
+ enumerable: !1,
332
+ get: v
333
+ }) : Object.defineProperty(r, "ref", { enumerable: !1, value: null }), r._store = {}, Object.defineProperty(r._store, "validated", {
334
+ configurable: !1,
335
+ enumerable: !1,
336
+ writable: !0,
337
+ value: 0
338
+ }), Object.defineProperty(r, "_debugInfo", {
339
+ configurable: !1,
340
+ enumerable: !1,
341
+ writable: !0,
342
+ value: null
343
+ }), Object.freeze && (Object.freeze(r.props), Object.freeze(r)), r;
344
+ }
345
+ function P(r, u, l, C, j, h) {
346
+ if (typeof r == "string" || typeof r == "function" || r === V || r === we || r === Te || r === je || r === Pe || r === Le || typeof r == "object" && r !== null && (r.$$typeof === Fe || r.$$typeof === A || r.$$typeof === Re || r.$$typeof === Se || r.$$typeof === Me || r.$$typeof === Y || r.getModuleId !== void 0)) {
347
+ var m = u.children;
348
+ if (m !== void 0)
349
+ if (C)
350
+ if (S(m)) {
351
+ for (C = 0; C < m.length; C++)
352
+ Q(m[C], r);
353
+ Object.freeze && Object.freeze(m);
354
+ } else
355
+ console.error(
356
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
357
+ );
358
+ else Q(m, r);
359
+ } else
360
+ m = "", (r === void 0 || typeof r == "object" && r !== null && Object.keys(r).length === 0) && (m += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."), r === null ? C = "null" : S(r) ? C = "array" : r !== void 0 && r.$$typeof === le ? (C = "<" + (e(r.type) || "Unknown") + " />", m = " Did you accidentally export a JSX literal instead of a component?") : C = typeof r, console.error(
361
+ "React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",
362
+ C,
363
+ m
364
+ );
365
+ if (Be.call(u, "key")) {
366
+ m = e(r);
367
+ var re = Object.keys(u).filter(function(I) {
368
+ return I !== "key";
369
+ });
370
+ C = 0 < re.length ? "{key: someKey, " + re.join(": ..., ") + ": ...}" : "{key: someKey}", te[m + C] || (re = 0 < re.length ? "{" + re.join(": ..., ") + ": ...}" : "{}", console.error(
371
+ `A props object containing a "key" prop is being spread into JSX:
372
+ let props = %s;
373
+ <%s {...props} />
374
+ React keys must be passed directly to JSX without using spread:
375
+ let props = %s;
376
+ <%s key={someKey} {...props} />`,
377
+ C,
378
+ m,
379
+ re,
380
+ m
381
+ ), te[m + C] = !0);
382
+ }
383
+ if (m = null, l !== void 0 && (o(l), m = "" + l), f(u) && (o(u.key), m = "" + u.key), "key" in u) {
384
+ l = {};
385
+ for (var ie in u)
386
+ ie !== "key" && (l[ie] = u[ie]);
387
+ } else l = u;
388
+ return m && R(
389
+ l,
390
+ typeof r == "function" ? r.displayName || r.name || "Unknown" : r
391
+ ), M(r, m, h, j, g(), l);
392
+ }
393
+ function Q(r, u) {
394
+ if (typeof r == "object" && r && r.$$typeof !== ae) {
395
+ if (S(r))
396
+ for (var l = 0; l < r.length; l++) {
397
+ var C = r[l];
398
+ p(C) && W(C, u);
399
+ }
400
+ else if (p(r))
401
+ r._store && (r._store.validated = 1);
402
+ else if (r === null || typeof r != "object" ? l = null : (l = be && r[be] || r["@@iterator"], l = typeof l == "function" ? l : null), typeof l == "function" && l !== r.entries && (l = l.call(r), l !== r))
403
+ for (; !(r = l.next()).done; )
404
+ p(r.value) && W(r.value, u);
405
+ }
406
+ }
407
+ function p(r) {
408
+ return typeof r == "object" && r !== null && r.$$typeof === le;
409
+ }
410
+ function W(r, u) {
411
+ if (r._store && !r._store.validated && r.key == null && (r._store.validated = 1, u = F(u), !ge[u])) {
412
+ ge[u] = !0;
413
+ var l = "";
414
+ r && r._owner != null && r._owner !== g() && (l = null, typeof r._owner.tag == "number" ? l = e(r._owner.type) : typeof r._owner.name == "string" && (l = r._owner.name), l = " It was passed a child from " + l + ".");
415
+ var C = Z.getCurrentStack;
416
+ Z.getCurrentStack = function() {
417
+ var j = x(r.type);
418
+ return C && (j += C() || ""), j;
419
+ }, console.error(
420
+ 'Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',
421
+ u,
422
+ l
423
+ ), Z.getCurrentStack = C;
424
+ }
425
+ }
426
+ function F(r) {
427
+ var u = "", l = g();
428
+ return l && (l = e(l.type)) && (u = `
429
+
430
+ Check the render method of \`` + l + "`."), u || (r = e(r)) && (u = `
431
+
432
+ Check the top-level render call using <` + r + ">."), u;
433
+ }
434
+ var O = ne, le = Symbol.for("react.transitional.element"), _ = Symbol.for("react.portal"), V = Symbol.for("react.fragment"), Te = Symbol.for("react.strict_mode"), we = Symbol.for("react.profiler"), Se = Symbol.for("react.consumer"), Re = Symbol.for("react.context"), Me = Symbol.for("react.forward_ref"), je = Symbol.for("react.suspense"), Pe = Symbol.for("react.suspense_list"), A = Symbol.for("react.memo"), Fe = Symbol.for("react.lazy"), Le = Symbol.for("react.offscreen"), be = Symbol.iterator, ue = Symbol.for("react.client.reference"), Z = O.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Be = Object.prototype.hasOwnProperty, de = Object.assign, Y = Symbol.for("react.client.reference"), S = Array.isArray, U = 0, xe, K, fe, d, T, E, y;
435
+ n.__reactDisabledLog = !0;
436
+ var w, k, B = !1, J = new (typeof WeakMap == "function" ? WeakMap : Map)(), ae = Symbol.for("react.client.reference"), ee, me = {}, te = {}, ge = {};
437
+ _e.Fragment = V, _e.jsx = function(r, u, l, C, j) {
438
+ return P(r, u, l, !1, C, j);
439
+ }, _e.jsxs = function(r, u, l, C, j) {
440
+ return P(r, u, l, !0, C, j);
441
+ };
442
+ })()), _e;
443
+ }
444
+ var ft;
445
+ function Kt() {
446
+ return ft || (ft = 1, process.env.NODE_ENV === "production" ? He.exports = Xt() : He.exports = Zt()), He.exports;
447
+ }
448
+ var b = Kt();
449
+ const er = new qe();
450
+ new Ue();
451
+ const tr = new G();
452
+ new Dt();
453
+ const ye = new Vt(), z = new G(), ce = new qe(), Ee = new G(), rr = (e) => {
454
+ const [t, o, n] = e;
455
+ return new G(t, o, n);
456
+ }, mt = ({
457
+ x: e,
458
+ y: t,
459
+ z: o,
460
+ w: n
461
+ }) => er.set(e, t, o, n), q = (e) => {
462
+ if (Array.isArray(e))
463
+ return new Qe(e[0], e[1], e[2]);
464
+ if (typeof e == "number")
465
+ return new Qe(e, e, e);
466
+ {
467
+ const t = e;
468
+ return new Qe(t.x, t.y, t.z);
469
+ }
470
+ }, gt = (e) => Array.isArray(e) ? new at(e[0], e[1], e[2], e[3]) : new at(e.x, e.y, e.z, e.w), or = {
471
+ fixed: 1,
472
+ dynamic: 0,
473
+ kinematicPosition: 2,
474
+ kinematicVelocity: 3
475
+ }, wt = (e) => or[e], nr = (e, t) => {
476
+ const o = Array.from(e);
477
+ for (let n = 0; n < e.length / 3; n++)
478
+ o[n * 3] *= t.x, o[n * 3 + 1] *= t.y, o[n * 3 + 2] *= t.z;
479
+ return o;
480
+ }, St = (e) => e ? e instanceof qe ? [e.x, e.y, e.z, e.w] : e instanceof G || e instanceof Ue ? [e.x, e.y, e.z] : Array.isArray(e) ? e : [e] : [0];
481
+ function se(e) {
482
+ const t = D(void 0);
483
+ return t.current === void 0 && (t.current = {
484
+ value: typeof e == "function" ? e() : e
485
+ }), t.current.value;
486
+ }
487
+ const ir = (e) => {
488
+ const t = D(e), o = D(0), n = D(0);
489
+ N(() => {
490
+ t.current = e;
491
+ }, [e]), N(() => {
492
+ const i = () => {
493
+ const s = performance.now(), c = s - n.current;
494
+ o.current = requestAnimationFrame(i), t.current(c / 1e3), n.current = s;
495
+ };
496
+ return o.current = requestAnimationFrame(i), () => cancelAnimationFrame(o.current);
497
+ }, []);
498
+ }, sr = ({ onStep: e, updatePriority: t }) => (Ze((o, n) => {
499
+ e(n);
500
+ }, t), null), cr = ({ onStep: e }) => (ir((t) => {
501
+ e(t);
502
+ }), null), ar = ({ onStep: e, type: t, updatePriority: o }) => t === "independent" ? /* @__PURE__ */ b.jsx(cr, { onStep: e }) : /* @__PURE__ */ b.jsx(sr, { onStep: e, updatePriority: o }), lr = he(ar), ur = (e, t, o) => {
503
+ const n = t.slice();
504
+ if (e === "heightfield") {
505
+ const s = n[3];
506
+ return s.x *= o.x, s.x *= o.y, s.x *= o.z, n;
507
+ }
508
+ if (e === "trimesh" || e === "convexHull")
509
+ return n[0] = nr(n[0], o), n;
510
+ const i = [o.x, o.y, o.z, o.x, o.x];
511
+ return n.map((s, c) => i[c] * s);
512
+ }, dr = (e, t, o, n) => {
513
+ const i = ur(e.shape, e.args, o), s = kt[e.shape](...i);
514
+ return t.createCollider(s, n == null ? void 0 : n());
515
+ }, fr = [
516
+ "shape",
517
+ "args"
518
+ ], pt = "Please pick ONLY ONE of the `density`, `mass` and `massProperties` options.", mr = (e, t) => {
519
+ if (t.density !== void 0) {
520
+ if (t.mass !== void 0 || t.massProperties !== void 0)
521
+ throw new Error(pt);
522
+ e.setDensity(t.density);
523
+ return;
524
+ }
525
+ if (t.mass !== void 0) {
526
+ if (t.massProperties !== void 0)
527
+ throw new Error(pt);
528
+ e.setMass(t.mass);
529
+ return;
530
+ }
531
+ t.massProperties !== void 0 && e.setMassProperties(
532
+ t.massProperties.mass,
533
+ t.massProperties.centerOfMass,
534
+ t.massProperties.principalAngularInertia,
535
+ t.massProperties.angularInertiaLocalFrame
536
+ );
537
+ }, Rt = {
538
+ sensor: (e, t) => {
539
+ e.setSensor(t);
540
+ },
541
+ collisionGroups: (e, t) => {
542
+ e.setCollisionGroups(t);
543
+ },
544
+ solverGroups: (e, t) => {
545
+ e.setSolverGroups(t);
546
+ },
547
+ friction: (e, t) => {
548
+ e.setFriction(t);
549
+ },
550
+ frictionCombineRule: (e, t) => {
551
+ e.setFrictionCombineRule(t);
552
+ },
553
+ restitution: (e, t) => {
554
+ e.setRestitution(t);
555
+ },
556
+ restitutionCombineRule: (e, t) => {
557
+ e.setRestitutionCombineRule(t);
558
+ },
559
+ activeCollisionTypes: (e, t) => {
560
+ e.setActiveCollisionTypes(t);
561
+ },
562
+ contactSkin: (e, t) => {
563
+ e.setContactSkin(t);
564
+ },
565
+ // To make sure the options all mutable options are listed
566
+ quaternion: () => {
567
+ },
568
+ position: () => {
569
+ },
570
+ rotation: () => {
571
+ },
572
+ scale: () => {
573
+ }
574
+ }, jt = Object.keys(
575
+ Rt
576
+ ), gr = (e, t, o) => {
577
+ var i;
578
+ const n = o.get(e.handle);
579
+ if (n) {
580
+ const s = n.object.parent.getWorldScale(tr), c = (i = n.worldParent) == null ? void 0 : i.matrixWorld.clone().invert();
581
+ n.object.updateWorldMatrix(!0, !1), ye.copy(n.object.matrixWorld), c && ye.premultiply(c), ye.decompose(z, ce, Ee), e.parent() ? (e.setTranslationWrtParent({
582
+ x: z.x * s.x,
583
+ y: z.y * s.y,
584
+ z: z.z * s.z
585
+ }), e.setRotationWrtParent(ce)) : (e.setTranslation({
586
+ x: z.x * s.x,
587
+ y: z.y * s.y,
588
+ z: z.z * s.z
589
+ }), e.setRotation(ce)), jt.forEach((a) => {
590
+ if (a in t) {
591
+ const x = t[a];
592
+ Rt[a](
593
+ e,
594
+ // @ts-ignore Option does not want to fit into the function, but it will
595
+ x,
596
+ t
597
+ );
598
+ }
599
+ }), mr(e, t);
600
+ }
601
+ }, pr = (e, t, o) => {
602
+ const n = ve(
603
+ () => jt.flatMap((i) => St(t[i])),
604
+ [t]
605
+ );
606
+ N(() => {
607
+ const i = e();
608
+ gr(i, t, o);
609
+ }, [...n, e]);
610
+ }, yr = (e) => {
611
+ let t = !1;
612
+ return e.traverseAncestors((o) => {
613
+ o.userData.r3RapierType === "MeshCollider" && (t = !0);
614
+ }), t;
615
+ }, br = (e, t, o) => ({
616
+ collider: e,
617
+ worldParent: o || void 0,
618
+ object: t
619
+ }), xr = {
620
+ cuboid: "cuboid",
621
+ ball: "ball",
622
+ hull: "convexHull",
623
+ trimesh: "trimesh"
624
+ }, Cr = ({ object: e, ignoreMeshColliders: t = !0, options: o }) => {
625
+ const n = [];
626
+ e.updateWorldMatrix(!0, !1);
627
+ const i = e.matrixWorld.clone().invert(), s = (c) => {
628
+ if ("isMesh" in c) {
629
+ if (t && yr(c)) return;
630
+ const a = c.getWorldScale(Ee), x = xr[o.colliders || "cuboid"];
631
+ c.updateWorldMatrix(!0, !1), ye.copy(c.matrixWorld).premultiply(i).decompose(z, ce, Ee);
632
+ const g = new Ue().setFromQuaternion(ce, "XYZ"), { geometry: f } = c, { args: R, offset: v } = vr(
633
+ f,
634
+ o.colliders || "cuboid"
635
+ ), M = {
636
+ ...At(o),
637
+ args: R,
638
+ shape: x,
639
+ rotation: [g.x, g.y, g.z],
640
+ position: [
641
+ z.x + v.x * a.x,
642
+ z.y + v.y * a.y,
643
+ z.z + v.z * a.z
644
+ ],
645
+ scale: [a.x, a.y, a.z]
646
+ };
647
+ n.push(M);
648
+ }
649
+ };
650
+ return o.includeInvisible ? e.traverse(s) : e.traverseVisible(s), n;
651
+ }, vr = (e, t) => {
652
+ var o;
653
+ switch (t) {
654
+ case "cuboid": {
655
+ e.computeBoundingBox();
656
+ const { boundingBox: n } = e, i = n.getSize(new G());
657
+ return {
658
+ args: [i.x / 2, i.y / 2, i.z / 2],
659
+ offset: n.getCenter(new G())
660
+ };
661
+ }
662
+ case "ball": {
663
+ e.computeBoundingSphere();
664
+ const { boundingSphere: n } = e;
665
+ return {
666
+ args: [n.radius],
667
+ offset: n.center
668
+ };
669
+ }
670
+ case "trimesh": {
671
+ const n = e.index ? e.clone() : Lt(e);
672
+ return {
673
+ args: [
674
+ n.attributes.position.array,
675
+ (o = n.index) == null ? void 0 : o.array
676
+ ],
677
+ offset: new G()
678
+ };
679
+ }
680
+ case "hull":
681
+ return {
682
+ args: [e.clone().attributes.position.array],
683
+ offset: new G()
684
+ };
685
+ }
686
+ return { args: [], offset: new G() };
687
+ }, Pt = (e) => ({
688
+ collision: !!(e != null && e.onCollisionEnter || e != null && e.onCollisionExit || e != null && e.onIntersectionEnter || e != null && e.onIntersectionExit),
689
+ contactForce: !!(e != null && e.onContactForce)
690
+ }), Er = (e, t, o, n = {}) => {
691
+ const {
692
+ onCollisionEnter: i,
693
+ onCollisionExit: s,
694
+ onIntersectionEnter: c,
695
+ onIntersectionExit: a,
696
+ onContactForce: x
697
+ } = t;
698
+ N(() => {
699
+ const g = e();
700
+ if (g) {
701
+ const {
702
+ collision: f,
703
+ contactForce: R
704
+ } = Pt(t), v = f || n.collision, M = R || n.contactForce;
705
+ v && M ? g.setActiveEvents(
706
+ Je.COLLISION_EVENTS | Je.CONTACT_FORCE_EVENTS
707
+ ) : v ? g.setActiveEvents(Je.COLLISION_EVENTS) : M && g.setActiveEvents(Je.CONTACT_FORCE_EVENTS), o.set(g.handle, {
708
+ onCollisionEnter: i,
709
+ onCollisionExit: s,
710
+ onIntersectionEnter: c,
711
+ onIntersectionExit: a,
712
+ onContactForce: x
713
+ });
714
+ }
715
+ return () => {
716
+ g && o.delete(g.handle);
717
+ };
718
+ }, [
719
+ i,
720
+ s,
721
+ c,
722
+ a,
723
+ x,
724
+ n
725
+ ]);
726
+ }, At = (e = {}) => {
727
+ const {
728
+ mass: t,
729
+ linearDamping: o,
730
+ angularDamping: n,
731
+ type: i,
732
+ onCollisionEnter: s,
733
+ onCollisionExit: c,
734
+ onIntersectionEnter: a,
735
+ onIntersectionExit: x,
736
+ onContactForce: g,
737
+ children: f,
738
+ canSleep: R,
739
+ ccd: v,
740
+ gravityScale: M,
741
+ softCcdPrediction: P,
742
+ ref: Q,
743
+ ...p
744
+ } = e;
745
+ return p;
746
+ }, $e = (e) => {
747
+ const t = D(e);
748
+ return N(() => {
749
+ t.current = e;
750
+ }, [e]), t;
751
+ }, H = () => {
752
+ const e = Ct(Tt);
753
+ if (!e)
754
+ throw new Error(
755
+ "react-three-rapier: useRapier must be used within <Physics />!"
756
+ );
757
+ return e;
758
+ }, hr = (e) => {
759
+ const { beforeStepCallbacks: t } = H(), o = $e(e);
760
+ N(() => (t.add(o), () => {
761
+ t.delete(o);
762
+ }), []);
763
+ }, Kr = (e) => {
764
+ const { afterStepCallbacks: t } = H(), o = $e(e);
765
+ N(() => (t.add(o), () => {
766
+ t.delete(o);
767
+ }), []);
768
+ }, eo = (e) => {
769
+ const { filterContactPairHooks: t } = H(), o = $e(e);
770
+ N(() => (t.add(o), () => {
771
+ t.delete(o);
772
+ }), []);
773
+ }, to = (e) => {
774
+ const { filterIntersectionPairHooks: t } = H(), o = $e(e);
775
+ N(() => (t.add(o), () => {
776
+ t.delete(o);
777
+ }), []);
778
+ }, Ke = (e, t, o = !0) => {
779
+ const [n, i] = vt([]);
780
+ return N(() => {
781
+ e.current && t.colliders !== !1 && i(
782
+ Cr({
783
+ object: e.current,
784
+ options: t,
785
+ ignoreMeshColliders: o
786
+ })
787
+ );
788
+ }, [t.colliders]), n;
789
+ }, wr = he(() => {
790
+ const { world: e } = H(), t = D(null);
791
+ return Ze(() => {
792
+ const o = t.current;
793
+ if (!o) return;
794
+ const n = e.debugRender(), i = new Jt();
795
+ i.setAttribute("position", new lt(n.vertices, 3)), i.setAttribute("color", new lt(n.colors, 4)), o.geometry.dispose(), o.geometry = i;
796
+ }), /* @__PURE__ */ b.jsx("group", { children: /* @__PURE__ */ b.jsxs("lineSegments", { ref: t, frustumCulled: !1, children: [
797
+ /* @__PURE__ */ b.jsx("lineBasicMaterial", { color: 16777215, vertexColors: !0 }),
798
+ /* @__PURE__ */ b.jsx("bufferGeometry", {})
799
+ ] }) });
800
+ }), Sr = (e) => {
801
+ let t;
802
+ const o = {
803
+ get(c, a) {
804
+ return t || (t = e()), Reflect.get(t, a);
805
+ },
806
+ set(c, a, x) {
807
+ return t || (t = e()), Reflect.set(t, a, x);
808
+ }
809
+ };
810
+ return { proxy: new Proxy({}, o), reset: () => {
811
+ t = void 0;
812
+ }, set: (c) => {
813
+ t = c;
814
+ } };
815
+ }, Tt = Et(
816
+ void 0
817
+ ), Ye = (e, t) => {
818
+ var o, n, i, s, c, a;
819
+ return {
820
+ target: {
821
+ rigidBody: e.rigidBody.object,
822
+ collider: e.collider.object,
823
+ colliderObject: (o = e.collider.state) == null ? void 0 : o.object,
824
+ rigidBodyObject: (n = e.rigidBody.state) == null ? void 0 : n.object
825
+ },
826
+ other: {
827
+ rigidBody: t.rigidBody.object,
828
+ collider: t.collider.object,
829
+ colliderObject: (i = t.collider.state) == null ? void 0 : i.object,
830
+ rigidBodyObject: (s = t.rigidBody.state) == null ? void 0 : s.object
831
+ },
832
+ rigidBody: t.rigidBody.object,
833
+ collider: t.collider.object,
834
+ colliderObject: (c = t.collider.state) == null ? void 0 : c.object,
835
+ rigidBodyObject: (a = t.rigidBody.state) == null ? void 0 : a.object
836
+ };
837
+ }, yt = async () => {
838
+ let e = await import("@dimforge/rapier3d-compat");
839
+ return await e.init(), e;
840
+ }, ro = (e) => {
841
+ const {
842
+ colliders: t = "cuboid",
843
+ children: o,
844
+ timeStep: n = 1 / 60,
845
+ paused: i = !1,
846
+ interpolate: s = !0,
847
+ updatePriority: c,
848
+ updateLoop: a = "follow",
849
+ debug: x = !1,
850
+ gravity: g = [0, -9.81, 0],
851
+ allowedLinearError: f = 1e-3,
852
+ predictionDistance: R = 2e-3,
853
+ numSolverIterations: v = 4,
854
+ numInternalPgsIterations: M = 1,
855
+ minIslandSize: P = 128,
856
+ maxCcdSubsteps: Q = 1,
857
+ contactNaturalFrequency: p = 30,
858
+ lengthUnit: W = 1
859
+ } = e, F = $t(yt, ["@react-thee/rapier", yt]), { invalidate: O } = ht(), le = se(() => /* @__PURE__ */ new Map()), _ = se(() => /* @__PURE__ */ new Map()), V = se(() => /* @__PURE__ */ new Map()), Te = se(() => /* @__PURE__ */ new Map()), we = se(() => new It(!1)), Se = se(
860
+ () => /* @__PURE__ */ new Set()
861
+ ), Re = se(() => /* @__PURE__ */ new Set()), Me = se(() => ({
862
+ filterContactPair: (...Y) => {
863
+ for (const S of Se) {
864
+ const U = S.current(...Y);
865
+ if (U !== null) return U;
866
+ }
867
+ return null;
868
+ },
869
+ filterIntersectionPair: (...Y) => {
870
+ for (const S of Re)
871
+ if (S.current(...Y) === !1) return !1;
872
+ return !0;
873
+ }
874
+ })), je = se(() => /* @__PURE__ */ new Set()), Pe = se(() => /* @__PURE__ */ new Set()), {
875
+ proxy: A,
876
+ reset: Fe,
877
+ set: Le
878
+ } = se(
879
+ () => Sr(
880
+ () => new F.World(rr(g))
881
+ )
882
+ );
883
+ N(() => () => {
884
+ A.free(), Fe();
885
+ }, []), N(() => {
886
+ A.gravity = q(g), A.integrationParameters.numSolverIterations = v, A.integrationParameters.numInternalPgsIterations = M, A.integrationParameters.normalizedAllowedLinearError = f, A.integrationParameters.minIslandSize = P, A.integrationParameters.maxCcdSubsteps = Q, A.integrationParameters.normalizedPredictionDistance = R, A.lengthUnit = W, A.integrationParameters.contact_natural_frequency = p;
887
+ }, [
888
+ A,
889
+ ...g,
890
+ v,
891
+ M,
892
+ f,
893
+ P,
894
+ Q,
895
+ R,
896
+ W,
897
+ p
898
+ ]);
899
+ const be = Ge((Y) => {
900
+ var y;
901
+ const S = A.getCollider(Y), U = Te.get(Y), xe = _.get(Y), K = (y = S == null ? void 0 : S.parent()) == null ? void 0 : y.handle, fe = K !== void 0 ? A.getRigidBody(K) : void 0, d = fe && K !== void 0 ? V.get(K) : void 0, T = K !== void 0 ? le.get(K) : void 0;
902
+ return {
903
+ collider: {
904
+ object: S,
905
+ events: U,
906
+ state: xe
907
+ },
908
+ rigidBody: {
909
+ object: fe,
910
+ events: d,
911
+ state: T
912
+ }
913
+ };
914
+ }, []), [ue] = vt({
915
+ previousState: {},
916
+ accumulator: 0
917
+ }), Z = Ge(
918
+ (Y) => {
919
+ const S = A, U = n === "vary", xe = Ht.clamp(Y, 0, 0.5), K = (d) => {
920
+ je.forEach((E) => {
921
+ E.current(S);
922
+ }), S.timestep = d;
923
+ const T = Se.size > 0 || Re.size > 0;
924
+ S.step(we, T ? Me : void 0), Pe.forEach((E) => {
925
+ E.current(S);
926
+ });
927
+ };
928
+ if (U)
929
+ K(xe);
930
+ else
931
+ for (ue.accumulator += xe; ue.accumulator >= n; )
932
+ s && (ue.previousState = {}, S.forEachRigidBody((d) => {
933
+ ue.previousState[d.handle] = {
934
+ position: d.translation(),
935
+ rotation: d.rotation()
936
+ };
937
+ })), K(n), ue.accumulator -= n;
938
+ const fe = U || !s || i ? 1 : ue.accumulator / n;
939
+ le.forEach((d, T) => {
940
+ var J, ae;
941
+ const E = S.getRigidBody(T), y = V.get(T);
942
+ if ((y != null && y.onSleep || y != null && y.onWake) && (E.isSleeping() && !d.isSleeping && ((J = y == null ? void 0 : y.onSleep) == null || J.call(y)), !E.isSleeping() && d.isSleeping && ((ae = y == null ? void 0 : y.onWake) == null || ae.call(y)), d.isSleeping = E.isSleeping()), !E || E.isSleeping() && !("isInstancedMesh" in d.object) || !d.setMatrix)
943
+ return;
944
+ let w = E.translation(), k = E.rotation(), B = ue.previousState[T];
945
+ B && (ye.compose(
946
+ B.position,
947
+ mt(B.rotation),
948
+ d.scale
949
+ ).premultiply(d.invertedWorldMatrix).decompose(z, ce, Ee), d.meshType == "mesh" && (d.object.position.copy(z), d.object.quaternion.copy(ce))), ye.compose(w, mt(k), d.scale).premultiply(d.invertedWorldMatrix).decompose(z, ce, Ee), d.meshType == "instancedMesh" ? d.setMatrix(ye) : (d.object.position.lerp(z, fe), d.object.quaternion.slerp(ce, fe));
950
+ }), we.drainCollisionEvents((d, T, E) => {
951
+ var J, ae, ee, me, te, ge, r, u, l, C, j, h, m, re, ie, I, oe, pe, X, Ce, $, rt, Ne, ot;
952
+ const y = be(d), w = be(T);
953
+ if (!(y != null && y.collider.object) || !(w != null && w.collider.object))
954
+ return;
955
+ const k = Ye(
956
+ y,
957
+ w
958
+ ), B = Ye(
959
+ w,
960
+ y
961
+ );
962
+ E ? S.contactPair(
963
+ y.collider.object,
964
+ w.collider.object,
965
+ (ke, Ie) => {
966
+ var We, nt, ze, it, De, st, Ve, ct;
967
+ (nt = (We = y.rigidBody.events) == null ? void 0 : We.onCollisionEnter) == null || nt.call(We, {
968
+ ...k,
969
+ manifold: ke,
970
+ flipped: Ie
971
+ }), (it = (ze = w.rigidBody.events) == null ? void 0 : ze.onCollisionEnter) == null || it.call(ze, {
972
+ ...B,
973
+ manifold: ke,
974
+ flipped: Ie
975
+ }), (st = (De = y.collider.events) == null ? void 0 : De.onCollisionEnter) == null || st.call(De, {
976
+ ...k,
977
+ manifold: ke,
978
+ flipped: Ie
979
+ }), (ct = (Ve = w.collider.events) == null ? void 0 : Ve.onCollisionEnter) == null || ct.call(Ve, {
980
+ ...B,
981
+ manifold: ke,
982
+ flipped: Ie
983
+ });
984
+ }
985
+ ) : ((ae = (J = y.rigidBody.events) == null ? void 0 : J.onCollisionExit) == null || ae.call(J, k), (me = (ee = w.rigidBody.events) == null ? void 0 : ee.onCollisionExit) == null || me.call(ee, B), (ge = (te = y.collider.events) == null ? void 0 : te.onCollisionExit) == null || ge.call(te, k), (u = (r = w.collider.events) == null ? void 0 : r.onCollisionExit) == null || u.call(r, B)), E ? S.intersectionPair(
986
+ y.collider.object,
987
+ w.collider.object
988
+ ) && ((C = (l = y.rigidBody.events) == null ? void 0 : l.onIntersectionEnter) == null || C.call(l, k), (h = (j = w.rigidBody.events) == null ? void 0 : j.onIntersectionEnter) == null || h.call(j, B), (re = (m = y.collider.events) == null ? void 0 : m.onIntersectionEnter) == null || re.call(m, k), (I = (ie = w.collider.events) == null ? void 0 : ie.onIntersectionEnter) == null || I.call(ie, B)) : ((pe = (oe = y.rigidBody.events) == null ? void 0 : oe.onIntersectionExit) == null || pe.call(oe, k), (Ce = (X = w.rigidBody.events) == null ? void 0 : X.onIntersectionExit) == null || Ce.call(X, B), (rt = ($ = y.collider.events) == null ? void 0 : $.onIntersectionExit) == null || rt.call($, k), (ot = (Ne = w.collider.events) == null ? void 0 : Ne.onIntersectionExit) == null || ot.call(Ne, B));
989
+ }), we.drainContactForceEvents((d) => {
990
+ var k, B, J, ae, ee, me, te, ge;
991
+ const T = be(d.collider1()), E = be(d.collider2());
992
+ if (!(T != null && T.collider.object) || !(E != null && E.collider.object))
993
+ return;
994
+ const y = Ye(
995
+ T,
996
+ E
997
+ ), w = Ye(
998
+ E,
999
+ T
1000
+ );
1001
+ (B = (k = T.rigidBody.events) == null ? void 0 : k.onContactForce) == null || B.call(k, {
1002
+ ...y,
1003
+ totalForce: d.totalForce(),
1004
+ totalForceMagnitude: d.totalForceMagnitude(),
1005
+ maxForceDirection: d.maxForceDirection(),
1006
+ maxForceMagnitude: d.maxForceMagnitude()
1007
+ }), (ae = (J = E.rigidBody.events) == null ? void 0 : J.onContactForce) == null || ae.call(J, {
1008
+ ...w,
1009
+ totalForce: d.totalForce(),
1010
+ totalForceMagnitude: d.totalForceMagnitude(),
1011
+ maxForceDirection: d.maxForceDirection(),
1012
+ maxForceMagnitude: d.maxForceMagnitude()
1013
+ }), (me = (ee = T.collider.events) == null ? void 0 : ee.onContactForce) == null || me.call(ee, {
1014
+ ...y,
1015
+ totalForce: d.totalForce(),
1016
+ totalForceMagnitude: d.totalForceMagnitude(),
1017
+ maxForceDirection: d.maxForceDirection(),
1018
+ maxForceMagnitude: d.maxForceMagnitude()
1019
+ }), (ge = (te = E.collider.events) == null ? void 0 : te.onContactForce) == null || ge.call(te, {
1020
+ ...w,
1021
+ totalForce: d.totalForce(),
1022
+ totalForceMagnitude: d.totalForceMagnitude(),
1023
+ maxForceDirection: d.maxForceDirection(),
1024
+ maxForceMagnitude: d.maxForceMagnitude()
1025
+ });
1026
+ }), S.forEachActiveRigidBody(() => {
1027
+ O();
1028
+ });
1029
+ },
1030
+ [i, n, s, A]
1031
+ ), Be = ve(
1032
+ () => ({
1033
+ rapier: F,
1034
+ world: A,
1035
+ setWorld: (Y) => {
1036
+ Le(Y);
1037
+ },
1038
+ physicsOptions: {
1039
+ colliders: t,
1040
+ gravity: g
1041
+ },
1042
+ rigidBodyStates: le,
1043
+ colliderStates: _,
1044
+ rigidBodyEvents: V,
1045
+ colliderEvents: Te,
1046
+ beforeStepCallbacks: je,
1047
+ afterStepCallbacks: Pe,
1048
+ isPaused: i,
1049
+ isDebug: x,
1050
+ step: Z,
1051
+ filterContactPairHooks: Se,
1052
+ filterIntersectionPairHooks: Re
1053
+ }),
1054
+ [i, Z, x, t, g]
1055
+ ), de = Ge(
1056
+ (Y) => {
1057
+ i || Z(Y);
1058
+ },
1059
+ [i, Z]
1060
+ );
1061
+ return /* @__PURE__ */ b.jsxs(Tt.Provider, { value: Be, children: [
1062
+ /* @__PURE__ */ b.jsx(
1063
+ lr,
1064
+ {
1065
+ onStep: de,
1066
+ type: a,
1067
+ updatePriority: c
1068
+ }
1069
+ ),
1070
+ x && /* @__PURE__ */ b.jsx(wr, {}),
1071
+ o
1072
+ ] });
1073
+ }, et = (e, t = null) => {
1074
+ const o = D(t);
1075
+ return e && typeof e != "function" ? (e.current || (e.current = o.current), e) : o;
1076
+ }, tt = (e, t, o) => {
1077
+ const n = D(void 0), i = Ge(() => (n.current || (n.current = e()), n.current), o);
1078
+ return N(() => {
1079
+ const s = i(), c = () => t(s);
1080
+ return () => {
1081
+ c(), n.current = void 0;
1082
+ };
1083
+ }, [i]), i;
1084
+ }, Rr = (e) => {
1085
+ const t = wt((e == null ? void 0 : e.type) || "dynamic"), o = new Wt(t);
1086
+ return o.canSleep = (e == null ? void 0 : e.canSleep) ?? !0, o;
1087
+ }, jr = ({
1088
+ rigidBody: e,
1089
+ object: t,
1090
+ setMatrix: o,
1091
+ getMatrix: n,
1092
+ worldScale: i,
1093
+ meshType: s = "mesh"
1094
+ }) => {
1095
+ t.updateWorldMatrix(!0, !1);
1096
+ const c = t.parent.matrixWorld.clone().invert();
1097
+ return {
1098
+ object: t,
1099
+ rigidBody: e,
1100
+ invertedWorldMatrix: c,
1101
+ setMatrix: o || ((a) => {
1102
+ t.matrix.copy(a);
1103
+ }),
1104
+ getMatrix: n || ((a) => a.copy(t.matrix)),
1105
+ scale: i || t.getWorldScale(Ee).clone(),
1106
+ isSleeping: !1,
1107
+ meshType: s
1108
+ };
1109
+ }, Pr = [
1110
+ "args",
1111
+ "colliders",
1112
+ "canSleep"
1113
+ ], Mt = {
1114
+ gravityScale: (e, t) => {
1115
+ e.setGravityScale(t, !0);
1116
+ },
1117
+ additionalSolverIterations(e, t) {
1118
+ e.setAdditionalSolverIterations(t);
1119
+ },
1120
+ linearDamping: (e, t) => {
1121
+ e.setLinearDamping(t);
1122
+ },
1123
+ angularDamping: (e, t) => {
1124
+ e.setAngularDamping(t);
1125
+ },
1126
+ dominanceGroup: (e, t) => {
1127
+ e.setDominanceGroup(t);
1128
+ },
1129
+ enabledRotations: (e, [t, o, n]) => {
1130
+ e.setEnabledRotations(t, o, n, !0);
1131
+ },
1132
+ enabledTranslations: (e, [t, o, n]) => {
1133
+ e.setEnabledTranslations(t, o, n, !0);
1134
+ },
1135
+ lockRotations: (e, t) => {
1136
+ e.lockRotations(t, !0);
1137
+ },
1138
+ lockTranslations: (e, t) => {
1139
+ e.lockTranslations(t, !0);
1140
+ },
1141
+ angularVelocity: (e, [t, o, n]) => {
1142
+ e.setAngvel({ x: t, y: o, z: n }, !0);
1143
+ },
1144
+ linearVelocity: (e, [t, o, n]) => {
1145
+ e.setLinvel({ x: t, y: o, z: n }, !0);
1146
+ },
1147
+ ccd: (e, t) => {
1148
+ e.enableCcd(t);
1149
+ },
1150
+ softCcdPrediction: (e, t) => {
1151
+ e.setSoftCcdPrediction(t);
1152
+ },
1153
+ userData: (e, t) => {
1154
+ e.userData = t;
1155
+ },
1156
+ type(e, t) {
1157
+ e.setBodyType(wt(t), !0);
1158
+ },
1159
+ position: () => {
1160
+ },
1161
+ rotation: () => {
1162
+ },
1163
+ quaternion: () => {
1164
+ },
1165
+ scale: () => {
1166
+ }
1167
+ }, Ft = Object.keys(Mt), Ar = (e, t, o, n = !0) => {
1168
+ if (!e)
1169
+ return;
1170
+ const i = o.get(e.handle);
1171
+ i && (n && (i.object.updateWorldMatrix(!0, !1), ye.copy(i.object.matrixWorld).decompose(z, ce, Ee), e.setTranslation(z, !1), e.setRotation(ce, !1)), Ft.forEach((s) => {
1172
+ s in t && Mt[s](
1173
+ e,
1174
+ t[s]
1175
+ );
1176
+ }));
1177
+ }, Tr = (e, t, o, n = !0) => {
1178
+ const i = ve(
1179
+ () => Ft.flatMap((s) => St(t[s])),
1180
+ [t]
1181
+ );
1182
+ N(() => {
1183
+ const s = e();
1184
+ Ar(s, t, o, n);
1185
+ }, i);
1186
+ }, Mr = (e, t, o) => {
1187
+ const {
1188
+ onWake: n,
1189
+ onSleep: i,
1190
+ onCollisionEnter: s,
1191
+ onCollisionExit: c,
1192
+ onIntersectionEnter: a,
1193
+ onIntersectionExit: x,
1194
+ onContactForce: g
1195
+ } = t, f = {
1196
+ onWake: n,
1197
+ onSleep: i,
1198
+ onCollisionEnter: s,
1199
+ onCollisionExit: c,
1200
+ onIntersectionEnter: a,
1201
+ onIntersectionExit: x,
1202
+ onContactForce: g
1203
+ };
1204
+ N(() => {
1205
+ const R = e();
1206
+ return o.set(R.handle, f), () => {
1207
+ o.delete(R.handle);
1208
+ };
1209
+ }, [
1210
+ n,
1211
+ i,
1212
+ s,
1213
+ c,
1214
+ a,
1215
+ x,
1216
+ g
1217
+ ]);
1218
+ }, Fr = ({ x: e, y: t, z: o } = { x: 0, y: 0, z: 0 }) => new G(e, t, o), oo = ({ x: e, y: t, z: o, w: n } = { x: 0, y: 0, z: 0, w: 1 }) => new qe(e, t, o, n), no = ({ x: e, y: t, z: o } = { x: 0, y: 0, z: 0 }) => new Ue(e, t, o), L = he((e) => {
1219
+ const { children: t, position: o, rotation: n, quaternion: i, scale: s, name: c } = e, { world: a, colliderEvents: x, colliderStates: g } = H(), f = Bt(), R = et(e.ref), v = D(null), M = fr.flatMap(
1220
+ (p) => (
1221
+ // Array.isArray(props[key]) ? [...props[key]] : props[key]
1222
+ Array.isArray(e[p]) ? e[p] : [e[p]]
1223
+ )
1224
+ ), P = tt(
1225
+ () => {
1226
+ const p = v.current.getWorldScale(Fr()), W = dr(
1227
+ e,
1228
+ a,
1229
+ p,
1230
+ f == null ? void 0 : f.getRigidBody
1231
+ );
1232
+ return typeof e.ref == "function" && e.ref(W), R.current = W, W;
1233
+ },
1234
+ (p) => {
1235
+ a.getCollider(p.handle) && a.removeCollider(p, !0);
1236
+ },
1237
+ [...M, f]
1238
+ );
1239
+ N(() => {
1240
+ const p = P();
1241
+ return g.set(
1242
+ p.handle,
1243
+ br(
1244
+ p,
1245
+ v.current,
1246
+ f == null ? void 0 : f.ref.current
1247
+ )
1248
+ ), () => {
1249
+ g.delete(p.handle);
1250
+ };
1251
+ }, [P]);
1252
+ const Q = ve(() => ({
1253
+ ...At(f == null ? void 0 : f.options),
1254
+ ...e
1255
+ }), [e, f == null ? void 0 : f.options]);
1256
+ return pr(P, Q, g), Er(
1257
+ P,
1258
+ Q,
1259
+ x,
1260
+ Pt(f == null ? void 0 : f.options)
1261
+ ), /* @__PURE__ */ b.jsx(
1262
+ "object3D",
1263
+ {
1264
+ position: o,
1265
+ rotation: n,
1266
+ quaternion: i,
1267
+ scale: s,
1268
+ ref: v,
1269
+ name: c,
1270
+ children: t
1271
+ }
1272
+ );
1273
+ }), Or = ne.forwardRef(
1274
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "cuboid", ref: t })
1275
+ );
1276
+ Or.displayName = "CuboidCollider";
1277
+ const _r = ne.forwardRef(
1278
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "roundCuboid", ref: t })
1279
+ );
1280
+ _r.displayName = "RoundCuboidCollider";
1281
+ const Br = ne.forwardRef(
1282
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "ball", ref: t })
1283
+ );
1284
+ Br.displayName = "BallCollider";
1285
+ const Nr = ne.forwardRef(
1286
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "capsule", ref: t })
1287
+ );
1288
+ Nr.displayName = "CapsuleCollider";
1289
+ const kr = ne.forwardRef(
1290
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "heightfield", ref: t })
1291
+ );
1292
+ kr.displayName = "HeightfieldCollider";
1293
+ const Ir = ne.forwardRef(
1294
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "trimesh", ref: t })
1295
+ );
1296
+ Ir.displayName = "TrimeshCollider";
1297
+ const Wr = ne.forwardRef(
1298
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "cone", ref: t })
1299
+ );
1300
+ Wr.displayName = "ConeCollider";
1301
+ const zr = ne.forwardRef(
1302
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "roundCone", ref: t })
1303
+ );
1304
+ zr.displayName = "RoundConeCollider";
1305
+ const Ot = ne.forwardRef(
1306
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "cylinder", ref: t })
1307
+ );
1308
+ Ot.displayName = "CylinderCollider";
1309
+ const io = ne.forwardRef(
1310
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "roundCylinder", ref: t })
1311
+ );
1312
+ Ot.displayName = "RoundCylinderCollider";
1313
+ const Dr = ne.forwardRef(
1314
+ (e, t) => /* @__PURE__ */ b.jsx(L, { ...e, shape: "convexHull", ref: t })
1315
+ );
1316
+ Dr.displayName = "ConvexHullCollider";
1317
+ const _t = Et(void 0), Bt = () => Ct(_t), Nt = he((e) => {
1318
+ const {
1319
+ ref: t,
1320
+ children: o,
1321
+ type: n,
1322
+ position: i,
1323
+ rotation: s,
1324
+ scale: c,
1325
+ quaternion: a,
1326
+ transformState: x,
1327
+ ...g
1328
+ } = e, f = D(null), R = et(t), { world: v, rigidBodyStates: M, physicsOptions: P, rigidBodyEvents: Q } = H(), p = ve(() => ({
1329
+ ...P,
1330
+ ...e,
1331
+ children: void 0
1332
+ }), [P, e]), W = Pr.flatMap((_) => Array.isArray(p[_]) ? [...p[_]] : p[_]), F = Ke(f, p), O = tt(
1333
+ () => {
1334
+ const _ = Rr(p), V = v.createRigidBody(_);
1335
+ return typeof t == "function" && t(V), R.current = V, V;
1336
+ },
1337
+ (_) => {
1338
+ v.getRigidBody(_.handle) && v.removeRigidBody(_);
1339
+ },
1340
+ W
1341
+ );
1342
+ N(() => {
1343
+ const _ = O(), V = jr({
1344
+ rigidBody: _,
1345
+ object: f.current
1346
+ });
1347
+ return M.set(
1348
+ _.handle,
1349
+ e.transformState ? e.transformState(V) : V
1350
+ ), () => {
1351
+ M.delete(_.handle);
1352
+ };
1353
+ }, [O]), Tr(O, p, M), Mr(O, p, Q);
1354
+ const le = ve(() => ({
1355
+ ref: f,
1356
+ getRigidBody: O,
1357
+ options: p
1358
+ }), [O]);
1359
+ return /* @__PURE__ */ b.jsx(_t.Provider, { value: le, children: /* @__PURE__ */ b.jsxs(
1360
+ "object3D",
1361
+ {
1362
+ ref: f,
1363
+ ...g,
1364
+ position: i,
1365
+ rotation: s,
1366
+ quaternion: a,
1367
+ scale: c,
1368
+ children: [
1369
+ o,
1370
+ F.map((_, V) => /* @__PURE__ */ b.jsx(L, { ..._ }, V))
1371
+ ]
1372
+ }
1373
+ ) });
1374
+ });
1375
+ Nt.displayName = "RigidBody";
1376
+ const Vr = he((e) => {
1377
+ const { children: t, type: o } = e, { physicsOptions: n } = H(), i = D(null), { options: s } = Bt(), c = ve(() => ({
1378
+ ...n,
1379
+ ...s,
1380
+ children: void 0,
1381
+ colliders: o
1382
+ }), [n, s]), a = Ke(
1383
+ i,
1384
+ c,
1385
+ !1
1386
+ );
1387
+ return /* @__PURE__ */ b.jsxs(
1388
+ "object3D",
1389
+ {
1390
+ ref: i,
1391
+ userData: {
1392
+ r3RapierType: "MeshCollider"
1393
+ },
1394
+ children: [
1395
+ t,
1396
+ a.map((x, g) => /* @__PURE__ */ b.jsx(L, { ...x }, g))
1397
+ ]
1398
+ }
1399
+ );
1400
+ });
1401
+ Vr.displayName = "MeshCollider";
1402
+ const Jr = he(
1403
+ ({ ref: e, ...t }) => {
1404
+ const o = et(e, []), n = D(null), i = D(null), {
1405
+ // instanced props
1406
+ children: s,
1407
+ instances: c,
1408
+ colliderNodes: a = [],
1409
+ // wrapper object props
1410
+ position: x,
1411
+ rotation: g,
1412
+ quaternion: f,
1413
+ scale: R,
1414
+ // rigid body specific props, and r3f-object props
1415
+ ...v
1416
+ } = t, M = Ke(n, {
1417
+ ...t,
1418
+ children: void 0
1419
+ }), P = () => {
1420
+ const p = i.current.children[0];
1421
+ if (p && "isInstancedMesh" in p)
1422
+ return p;
1423
+ };
1424
+ N(() => {
1425
+ const p = P();
1426
+ p ? p.instanceMatrix.setUsage(Yt) : console.warn(
1427
+ "InstancedRigidBodies expects exactly one child, which must be an InstancedMesh"
1428
+ );
1429
+ }, []);
1430
+ const Q = (p, W) => {
1431
+ const F = P();
1432
+ return F ? {
1433
+ ...p,
1434
+ getMatrix: (O) => (F.getMatrixAt(W, O), O),
1435
+ setMatrix: (O) => {
1436
+ F.setMatrixAt(W, O), F.instanceMatrix.needsUpdate = !0;
1437
+ },
1438
+ meshType: "instancedMesh"
1439
+ } : p;
1440
+ };
1441
+ return /* @__PURE__ */ b.jsxs(
1442
+ "object3D",
1443
+ {
1444
+ ref: n,
1445
+ ...v,
1446
+ position: x,
1447
+ rotation: g,
1448
+ quaternion: f,
1449
+ scale: R,
1450
+ children: [
1451
+ /* @__PURE__ */ b.jsx("object3D", { ref: i, children: s }),
1452
+ c == null ? void 0 : c.map((p, W) => /* @__PURE__ */ b.jsx(
1453
+ Nt,
1454
+ {
1455
+ ...v,
1456
+ ...p,
1457
+ ref: (F) => {
1458
+ o.current[W] = F;
1459
+ },
1460
+ transformState: (F) => Q(F, W),
1461
+ children: /* @__PURE__ */ b.jsxs(b.Fragment, { children: [
1462
+ a.map((F, O) => /* @__PURE__ */ b.jsx(zt, { children: F }, O)),
1463
+ M.map((F, O) => /* @__PURE__ */ b.jsx(L, { ...F }, O))
1464
+ ] })
1465
+ }
1466
+ ))
1467
+ ]
1468
+ }
1469
+ );
1470
+ }
1471
+ );
1472
+ Jr.displayName = "InstancedRigidBodies";
1473
+ const Ae = (e, t, o) => {
1474
+ const { world: n } = H(), i = D(void 0);
1475
+ return tt(
1476
+ () => {
1477
+ if (e.current && t.current) {
1478
+ const s = n.createImpulseJoint(
1479
+ o,
1480
+ e.current,
1481
+ t.current,
1482
+ !0
1483
+ );
1484
+ return i.current = s, s;
1485
+ }
1486
+ },
1487
+ (s) => {
1488
+ s && (i.current = void 0, n.getImpulseJoint(s.handle) && n.removeImpulseJoint(s, !0));
1489
+ },
1490
+ []
1491
+ ), i;
1492
+ }, so = (e, t, [o, n, i, s]) => {
1493
+ const { rapier: c } = H();
1494
+ return Ae(
1495
+ e,
1496
+ t,
1497
+ c.JointData.fixed(
1498
+ q(o),
1499
+ gt(n),
1500
+ q(i),
1501
+ gt(s)
1502
+ )
1503
+ );
1504
+ }, co = (e, t, [o, n]) => {
1505
+ const { rapier: i } = H();
1506
+ return Ae(
1507
+ e,
1508
+ t,
1509
+ i.JointData.spherical(
1510
+ q(o),
1511
+ q(n)
1512
+ )
1513
+ );
1514
+ }, ao = (e, t, [o, n, i, s]) => {
1515
+ const { rapier: c } = H(), a = c.JointData.revolute(
1516
+ q(o),
1517
+ q(n),
1518
+ q(i)
1519
+ );
1520
+ return s && (a.limitsEnabled = !0, a.limits = s), Ae(e, t, a);
1521
+ }, lo = (e, t, [o, n, i, s]) => {
1522
+ const { rapier: c } = H(), a = c.JointData.prismatic(
1523
+ q(o),
1524
+ q(n),
1525
+ q(i)
1526
+ );
1527
+ return s && (a.limitsEnabled = !0, a.limits = s), Ae(e, t, a);
1528
+ }, uo = (e, t, [o, n, i]) => {
1529
+ const { rapier: s } = H(), c = q(o), a = q(n), x = s.JointData.rope(i, c, a);
1530
+ return Ae(e, t, x);
1531
+ }, fo = (e, t, [o, n, i, s, c]) => {
1532
+ const { rapier: a } = H(), x = q(o), g = q(n), f = a.JointData.spring(
1533
+ i,
1534
+ s,
1535
+ c,
1536
+ x,
1537
+ g
1538
+ );
1539
+ return Ae(e, t, f);
1540
+ }, mo = (e, t) => (bt(e) << 16) + (t !== void 0 ? bt(t) : 65535), bt = (e) => [e].flat().reduce((t, o) => t | 1 << o, 0), Hr = new G(), Yr = (e) => {
1541
+ const { scene: t } = ht(), o = D(null), n = D(null), i = e.strength > 0 ? 255 : 16711680;
1542
+ return N(() => (o.current = new Gt(
1543
+ new qt(0.2, 6, 6),
1544
+ new Ut({ color: i, wireframe: !0 })
1545
+ ), n.current = new Qt(
1546
+ o.current,
1547
+ e.range,
1548
+ i
1549
+ ), n.current.frustumCulled = !1, t.add(o.current), t.add(n.current), () => {
1550
+ n.current && o.current && (t.remove(n.current), t.remove(o.current));
1551
+ }), [e, i]), Ze(() => {
1552
+ var s;
1553
+ if (o.current && e.object.current) {
1554
+ const c = e.object.current.getWorldPosition(Hr);
1555
+ o.current.position.copy(c), (s = n.current) == null || s.update();
1556
+ }
1557
+ }), null;
1558
+ }, Gr = {
1559
+ static: (e, t, o, n, i) => e,
1560
+ linear: (e, t, o, n, i) => e * (n / o),
1561
+ newtonian: (e, t, o, n, i) => i * e * t / Math.pow(n, 2)
1562
+ }, Xe = new G(), xt = new G(), qr = (e, {
1563
+ object: t,
1564
+ strength: o,
1565
+ range: n,
1566
+ gravitationalConstant: i,
1567
+ collisionGroups: s,
1568
+ type: c
1569
+ }) => {
1570
+ const a = e.translation();
1571
+ Xe.set(a.x, a.y, a.z);
1572
+ const x = t.getWorldPosition(new G()), g = x.distanceTo(Xe);
1573
+ if (g < n) {
1574
+ let f = Gr[c](
1575
+ o,
1576
+ e.mass(),
1577
+ n,
1578
+ g,
1579
+ i
1580
+ );
1581
+ f = f === 1 / 0 ? o : f;
1582
+ let R = s === void 0;
1583
+ if (s !== void 0)
1584
+ for (let v = 0; v < e.numColliders(); v++) {
1585
+ const P = e.collider(v).collisionGroups();
1586
+ if ((s >> 16 & P) != 0 && (P >> 16 & s) != 0) {
1587
+ R = !0;
1588
+ break;
1589
+ }
1590
+ }
1591
+ R && (xt.set(0, 0, 0).subVectors(x, Xe).normalize().multiplyScalar(f), e.applyImpulse(xt, !0));
1592
+ }
1593
+ }, go = he((e) => {
1594
+ const {
1595
+ position: t = [0, 0, 0],
1596
+ strength: o = 1,
1597
+ range: n = 10,
1598
+ type: i = "static",
1599
+ gravitationalConstant: s = 6673e-14,
1600
+ collisionGroups: c
1601
+ } = e, a = D(null), { isDebug: x } = H();
1602
+ return hr((g) => {
1603
+ a.current && g.bodies.forEach((f) => {
1604
+ f.isDynamic() && qr(f, {
1605
+ object: a.current,
1606
+ strength: o,
1607
+ range: n,
1608
+ type: i,
1609
+ gravitationalConstant: s,
1610
+ collisionGroups: c
1611
+ });
1612
+ });
1613
+ }), /* @__PURE__ */ b.jsxs(b.Fragment, { children: [
1614
+ /* @__PURE__ */ b.jsx("object3D", { ref: a, position: t }),
1615
+ x && /* @__PURE__ */ b.jsx(
1616
+ Yr,
1617
+ {
1618
+ strength: o,
1619
+ gravitationalConstant: s,
1620
+ range: n,
1621
+ type: i,
1622
+ collisionGroups: c,
1623
+ object: a
1624
+ }
1625
+ )
1626
+ ] });
1627
+ });
1628
+ export {
1629
+ L as AnyCollider,
1630
+ go as Attractor,
1631
+ Yr as AttractorDebugHelper,
1632
+ Br as BallCollider,
1633
+ Nr as CapsuleCollider,
1634
+ bo as CoefficientCombineRule,
1635
+ Wr as ConeCollider,
1636
+ Dr as ConvexHullCollider,
1637
+ Or as CuboidCollider,
1638
+ Ot as CylinderCollider,
1639
+ kr as HeightfieldCollider,
1640
+ Jr as InstancedRigidBodies,
1641
+ Vr as MeshCollider,
1642
+ ro as Physics,
1643
+ xo as RapierCollider,
1644
+ Co as RapierRigidBody,
1645
+ Nt as RigidBody,
1646
+ zr as RoundConeCollider,
1647
+ _r as RoundCuboidCollider,
1648
+ io as RoundCylinderCollider,
1649
+ Ir as TrimeshCollider,
1650
+ qr as applyAttractorForceOnRigidBody,
1651
+ no as euler,
1652
+ mo as interactionGroups,
1653
+ oo as quat,
1654
+ Kr as useAfterPhysicsStep,
1655
+ hr as useBeforePhysicsStep,
1656
+ eo as useFilterContactPair,
1657
+ to as useFilterIntersectionPair,
1658
+ so as useFixedJoint,
1659
+ Ae as useImpulseJoint,
1660
+ lo as usePrismaticJoint,
1661
+ H as useRapier,
1662
+ ao as useRevoluteJoint,
1663
+ uo as useRopeJoint,
1664
+ co as useSphericalJoint,
1665
+ fo as useSpringJoint,
1666
+ Fr as vec3
1667
+ };