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.
- package/LICENSE +9 -0
- package/README.md +166 -0
- package/dist/index.cjs.js +31 -0
- package/dist/index.d.ts +1191 -0
- package/dist/index.esm.js +1667 -0
- package/package.json +53 -0
- package/src/addons/attractor/Attractor.tsx +178 -0
- package/src/addons/attractor/AttractorDebugHelper.tsx +59 -0
- package/src/components/AnyCollider.tsx +286 -0
- package/src/components/Debug.tsx +33 -0
- package/src/components/FrameStepper.tsx +36 -0
- package/src/components/InstancedRigidBodies.tsx +135 -0
- package/src/components/MeshCollider.tsx +53 -0
- package/src/components/Physics.tsx +894 -0
- package/src/components/RigidBody.tsx +153 -0
- package/src/hooks/hooks.ts +211 -0
- package/src/hooks/joints.ts +221 -0
- package/src/hooks/use-forwarded-ref.ts +19 -0
- package/src/hooks/use-imperative-instance.ts +33 -0
- package/src/index.ts +55 -0
- package/src/types.ts +541 -0
- package/src/utils/interaction-groups.ts +43 -0
- package/src/utils/shared-objects.ts +10 -0
- package/src/utils/singleton-proxy.ts +51 -0
- package/src/utils/three-object-helpers.ts +25 -0
- package/src/utils/utils-collider.ts +491 -0
- package/src/utils/utils-physics.ts +26 -0
- package/src/utils/utils-rigidbody.ts +231 -0
- package/src/utils/utils.ts +105 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026-2027 Jeremy Guyet
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
HER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHET
|
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# React Three Rapier - Unified Package
|
|
2
|
+
|
|
3
|
+
Ce package unifié combine `@react-three/rapier` et `@react-three/rapier-addons` en un seul package facile à utiliser.
|
|
4
|
+
|
|
5
|
+
## 📦 Installation locale
|
|
6
|
+
|
|
7
|
+
### Option 1: Utiliser npm link (Recommandé pour le développement)
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Dans le dossier unified
|
|
11
|
+
npm install
|
|
12
|
+
npm run build
|
|
13
|
+
npm link
|
|
14
|
+
|
|
15
|
+
# Dans votre projet
|
|
16
|
+
npm link react-three-rapier-unified
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Option 2: Utiliser le chemin local dans package.json
|
|
20
|
+
|
|
21
|
+
Dans votre projet, ajoutez dans `package.json`:
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"react-three-rapier-unified": "file:../chemin/vers/react-three-rapier/unified"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Puis installez:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Option 3: Copier directement dans node_modules
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Depuis votre projet
|
|
41
|
+
cp -r /chemin/vers/react-three-rapier/unified node_modules/react-three-rapier-unified
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 🚀 Utilisation
|
|
45
|
+
|
|
46
|
+
Ce package exporte tous les composants, hooks et utilitaires des deux packages originaux:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import {
|
|
50
|
+
// Composants principaux
|
|
51
|
+
Physics,
|
|
52
|
+
RigidBody,
|
|
53
|
+
MeshCollider,
|
|
54
|
+
InstancedRigidBodies,
|
|
55
|
+
|
|
56
|
+
// Colliders
|
|
57
|
+
BallCollider,
|
|
58
|
+
CuboidCollider,
|
|
59
|
+
CapsuleCollider,
|
|
60
|
+
|
|
61
|
+
// Hooks
|
|
62
|
+
useRapier,
|
|
63
|
+
useBeforePhysicsStep,
|
|
64
|
+
useAfterPhysicsStep,
|
|
65
|
+
|
|
66
|
+
// Addons
|
|
67
|
+
Attractor,
|
|
68
|
+
AttractorDebugHelper,
|
|
69
|
+
|
|
70
|
+
// Utils
|
|
71
|
+
interactionGroups,
|
|
72
|
+
createWorldFromObject3D
|
|
73
|
+
} from 'react-three-rapier-unified';
|
|
74
|
+
|
|
75
|
+
function App() {
|
|
76
|
+
return (
|
|
77
|
+
<Canvas>
|
|
78
|
+
<Physics>
|
|
79
|
+
<RigidBody>
|
|
80
|
+
<mesh>
|
|
81
|
+
<boxGeometry />
|
|
82
|
+
<meshStandardMaterial />
|
|
83
|
+
</mesh>
|
|
84
|
+
</RigidBody>
|
|
85
|
+
|
|
86
|
+
{/* Utiliser les addons directement */}
|
|
87
|
+
<Attractor
|
|
88
|
+
range={10}
|
|
89
|
+
strength={1}
|
|
90
|
+
position={[0, 5, 0]}
|
|
91
|
+
/>
|
|
92
|
+
</Physics>
|
|
93
|
+
</Canvas>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 📚 Contenu du package
|
|
99
|
+
|
|
100
|
+
### Composants Core
|
|
101
|
+
- `Physics` - Le conteneur de physique principal
|
|
102
|
+
- `RigidBody` - Corps rigides
|
|
103
|
+
- `InstancedRigidBodies` - Corps rigides instanciés
|
|
104
|
+
- `MeshCollider` - Collider basé sur mesh
|
|
105
|
+
- Tous les colliders: `BallCollider`, `CuboidCollider`, `CapsuleCollider`, etc.
|
|
106
|
+
|
|
107
|
+
### Hooks
|
|
108
|
+
- `useRapier` - Accès au contexte Rapier
|
|
109
|
+
- `useBeforePhysicsStep` / `useAfterPhysicsStep` - Callbacks de simulation
|
|
110
|
+
- `useFilterContactPair` / `useFilterIntersectionPair` - Filtres de collision
|
|
111
|
+
- Hooks de joints: `useFixedJoint`, `useSphericalJoint`, etc.
|
|
112
|
+
|
|
113
|
+
### Addons
|
|
114
|
+
- `Attractor` - Composant d'attraction de corps rigides
|
|
115
|
+
- `AttractorDebugHelper` - Helper de debug pour l'attractor
|
|
116
|
+
|
|
117
|
+
### Utils
|
|
118
|
+
- `interactionGroups` - Gestion des groupes d'interaction
|
|
119
|
+
- `createWorldFromObject3D` - Helpers pour Three.js
|
|
120
|
+
|
|
121
|
+
## 🏗️ Développement
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
# Installer les dépendances
|
|
125
|
+
npm install
|
|
126
|
+
|
|
127
|
+
# Build du package
|
|
128
|
+
npm run build
|
|
129
|
+
|
|
130
|
+
# Mode watch pour développement
|
|
131
|
+
npm run dev
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 📝 Structure du projet
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
unified/
|
|
138
|
+
├── src/
|
|
139
|
+
│ ├── components/ # Tous les composants
|
|
140
|
+
│ ├── hooks/ # Tous les hooks
|
|
141
|
+
│ ├── utils/ # Utilitaires
|
|
142
|
+
│ ├── addons/ # Addons (Attractor, etc.)
|
|
143
|
+
│ ├── types.ts # Définitions de types
|
|
144
|
+
│ └── index.ts # Point d'entrée principal
|
|
145
|
+
├── dist/ # Fichiers buildés
|
|
146
|
+
├── package.json
|
|
147
|
+
├── tsconfig.json
|
|
148
|
+
└── vite.config.ts
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 🔧 Configuration TypeScript
|
|
152
|
+
|
|
153
|
+
Le package est entièrement typé avec TypeScript. Les définitions de types sont incluses dans le build.
|
|
154
|
+
|
|
155
|
+
## 📄 Licence
|
|
156
|
+
|
|
157
|
+
MIT - Voir le fichier LICENSE pour plus de détails.
|
|
158
|
+
|
|
159
|
+
## 🙏 Crédits
|
|
160
|
+
|
|
161
|
+
Ce package unifie le travail original de:
|
|
162
|
+
- [@react-three/rapier](https://github.com/pmndrs/react-three-rapier)
|
|
163
|
+
- [@react-three/rapier-addons](https://github.com/pmndrs/react-three-rapier)
|
|
164
|
+
|
|
165
|
+
Créé par Hugo Wiledal et la communauté Poimandres.
|
|
166
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";var Vt=Object.create;var rt=Object.defineProperty;var zt=Object.getOwnPropertyDescriptor;var Dt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,qt=Object.prototype.hasOwnProperty;var Ht=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Dt(t))!qt.call(e,i)&&i!==o&&rt(e,i,{get:()=>t[i],enumerable:!(n=zt(t,i))||n.enumerable});return e};var Gt=(e,t,o)=>(o=e!=null?Vt(Jt(e)):{},Ht(t||!e||!e.__esModule?rt(o,"default",{value:e,enumerable:!0}):o,e));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const G=require("@dimforge/rapier3d-compat"),c=require("react"),Fe=require("@react-three/fiber"),x=require("three"),Yt=require("suspend-react"),ft=require("three-stdlib");var ze={exports:{}},Me={};/**
|
|
2
|
+
* @license React
|
|
3
|
+
* react-jsx-runtime.production.js
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/var ot;function Ut(){if(ot)return Me;ot=1;var e=Symbol.for("react.transitional.element"),t=Symbol.for("react.fragment");function o(n,i,s){var a=null;if(s!==void 0&&(a=""+s),i.key!==void 0&&(a=""+i.key),"key"in i){s={};for(var l in i)l!=="key"&&(s[l]=i[l])}else s=i;return i=s.ref,{$$typeof:e,type:n,key:a,ref:i!==void 0?i:null,props:s}}return Me.Fragment=t,Me.jsx=o,Me.jsxs=o,Me}var Te={};/**
|
|
10
|
+
* @license React
|
|
11
|
+
* react-jsx-runtime.development.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
|
+
*/var nt;function $t(){return nt||(nt=1,process.env.NODE_ENV!=="production"&&(function(){function e(r){if(r==null)return null;if(typeof r=="function")return r.$$typeof===le?null:r.displayName||r.name||null;if(typeof r=="string")return r;switch(r){case J:return"Fragment";case k:return"Portal";case xe:return"Profiler";case je:return"StrictMode";case we:return"Suspense";case Se:return"SuspenseList"}if(typeof r=="object")switch(typeof r.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),r.$$typeof){case Re:return(r.displayName||"Context")+".Provider";case he:return(r._context.displayName||"Context")+".Consumer";case Pe:var d=r.render;return r=r.displayName,r||(r=d.displayName||d.name||"",r=r!==""?"ForwardRef("+r+")":"ForwardRef"),r;case T:return d=r.displayName||null,d!==null?d:e(r.type)||"Memo";case Ae:d=r._payload,r=r._init;try{return e(r(d))}catch{}}return null}function t(r){return""+r}function o(r){try{t(r);var d=!1}catch{d=!0}if(d){d=console;var u=d.error,v=typeof Symbol=="function"&&Symbol.toStringTag&&r[Symbol.toStringTag]||r.constructor.name||"Object";return u.call(d,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",v),t(r)}}function n(){}function i(){if($===0){be=console.log,K=console.info,de=console.warn,f=console.error,F=console.group,R=console.groupCollapsed,b=console.groupEnd;var r={configurable:!0,enumerable:!0,value:n,writable:!0};Object.defineProperties(console,{info:r,log:r,warn:r,error:r,group:r,groupCollapsed:r,groupEnd:r})}$++}function s(){if($--,$===0){var r={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:ue({},r,{value:be}),info:ue({},r,{value:K}),warn:ue({},r,{value:de}),error:ue({},r,{value:f}),group:ue({},r,{value:F}),groupCollapsed:ue({},r,{value:R}),groupEnd:ue({},r,{value:b})})}0>$&&console.error("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}function a(r){if(S===void 0)try{throw Error()}catch(u){var d=u.stack.trim().match(/\n( *(at )?)/);S=d&&d[1]||"",I=-1<u.stack.indexOf(`
|
|
18
|
+
at`)?" (<anonymous>)":-1<u.stack.indexOf("@")?"@unknown:0:0":""}return`
|
|
19
|
+
`+S+r+I}function l(r,d){if(!r||N)return"";var u=q.get(r);if(u!==void 0)return u;N=!0,u=Error.prepareStackTrace,Error.prepareStackTrace=void 0;var v=null;v=Z.H,Z.H=null,i();try{var A={DetermineComponentFrameRoot:function(){try{if(d){var X=function(){throw Error()};if(Object.defineProperty(X.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(X,[])}catch(L){var Ce=L}Reflect.construct(r,[],X)}else{try{X.call()}catch(L){Ce=L}r.call(X.prototype)}}else{try{throw Error()}catch(L){Ce=L}(X=r())&&typeof X.catch=="function"&&X.catch(function(){})}}catch(L){if(L&&Ce&&typeof L.stack=="string")return[L.stack,Ce.stack]}return[null,null]}};A.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var w=Object.getOwnPropertyDescriptor(A.DetermineComponentFrameRoot,"name");w&&w.configurable&&Object.defineProperty(A.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var g=A.DetermineComponentFrameRoot(),re=g[0],ne=g[1];if(re&&ne){var W=re.split(`
|
|
20
|
+
`),oe=ne.split(`
|
|
21
|
+
`);for(g=w=0;w<W.length&&!W[w].includes("DetermineComponentFrameRoot");)w++;for(;g<oe.length&&!oe[g].includes("DetermineComponentFrameRoot");)g++;if(w===W.length||g===oe.length)for(w=W.length-1,g=oe.length-1;1<=w&&0<=g&&W[w]!==oe[g];)g--;for(;1<=w&&0<=g;w--,g--)if(W[w]!==oe[g]){if(w!==1||g!==1)do if(w--,g--,0>g||W[w]!==oe[g]){var ge=`
|
|
22
|
+
`+W[w].replace(" at new "," at ");return r.displayName&&ge.includes("<anonymous>")&&(ge=ge.replace("<anonymous>",r.displayName)),typeof r=="function"&&q.set(r,ge),ge}while(1<=w&&0<=g);break}}}finally{N=!1,Z.H=v,s(),Error.prepareStackTrace=u}return W=(W=r?r.displayName||r.name:"")?a(W):"",typeof r=="function"&&q.set(r,W),W}function E(r){if(r==null)return"";if(typeof r=="function"){var d=r.prototype;return l(r,!(!d||!d.isReactComponent))}if(typeof r=="string")return a(r);switch(r){case we:return a("Suspense");case Se:return a("SuspenseList")}if(typeof r=="object")switch(r.$$typeof){case Pe:return r=l(r.render,!1),r;case T:return E(r.type);case Ae:d=r._payload,r=r._init;try{return E(r(d))}catch{}}return""}function p(){var r=Z.A;return r===null?null:r.getOwner()}function m(r){if(Oe.call(r,"key")){var d=Object.getOwnPropertyDescriptor(r,"key").get;if(d&&d.isReactWarning)return!1}return r.key!==void 0}function P(r,d){function u(){ee||(ee=!0,console.error("%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)",d))}u.isReactWarning=!0,Object.defineProperty(r,"key",{get:u,configurable:!0})}function h(){var r=e(this.type);return fe[r]||(fe[r]=!0,console.error("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.")),r=this.props.ref,r!==void 0?r:null}function O(r,d,u,v,A,w){return u=w.ref,r={$$typeof:ae,type:r,key:d,props:w,_owner:A},(u!==void 0?u:null)!==null?Object.defineProperty(r,"ref",{enumerable:!1,get:h}):Object.defineProperty(r,"ref",{enumerable:!1,value:null}),r._store={},Object.defineProperty(r._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(r,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.freeze&&(Object.freeze(r.props),Object.freeze(r)),r}function M(r,d,u,v,A,w){if(typeof r=="string"||typeof r=="function"||r===J||r===xe||r===je||r===we||r===Se||r===qe||typeof r=="object"&&r!==null&&(r.$$typeof===Ae||r.$$typeof===T||r.$$typeof===Re||r.$$typeof===he||r.$$typeof===Pe||r.$$typeof===H||r.getModuleId!==void 0)){var g=d.children;if(g!==void 0)if(v)if(j(g)){for(v=0;v<g.length;v++)Q(g[v],r);Object.freeze&&Object.freeze(g)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Q(g,r)}else g="",(r===void 0||typeof r=="object"&&r!==null&&Object.keys(r).length===0)&&(g+=" 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?v="null":j(r)?v="array":r!==void 0&&r.$$typeof===ae?(v="<"+(e(r.type)||"Unknown")+" />",g=" Did you accidentally export a JSX literal instead of a component?"):v=typeof r,console.error("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",v,g);if(Oe.call(d,"key")){g=e(r);var re=Object.keys(d).filter(function(W){return W!=="key"});v=0<re.length?"{key: someKey, "+re.join(": ..., ")+": ...}":"{key: someKey}",te[g+v]||(re=0<re.length?"{"+re.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
23
|
+
let props = %s;
|
|
24
|
+
<%s {...props} />
|
|
25
|
+
React keys must be passed directly to JSX without using spread:
|
|
26
|
+
let props = %s;
|
|
27
|
+
<%s key={someKey} {...props} />`,v,g,re,g),te[g+v]=!0)}if(g=null,u!==void 0&&(o(u),g=""+u),m(d)&&(o(d.key),g=""+d.key),"key"in d){u={};for(var ne in d)ne!=="key"&&(u[ne]=d[ne])}else u=d;return g&&P(u,typeof r=="function"?r.displayName||r.name||"Unknown":r),O(r,g,w,A,p(),u)}function Q(r,d){if(typeof r=="object"&&r&&r.$$typeof!==ce){if(j(r))for(var u=0;u<r.length;u++){var v=r[u];y(v)&&V(v,d)}else if(y(r))r._store&&(r._store.validated=1);else if(r===null||typeof r!="object"?u=null:(u=ye&&r[ye]||r["@@iterator"],u=typeof u=="function"?u:null),typeof u=="function"&&u!==r.entries&&(u=u.call(r),u!==r))for(;!(r=u.next()).done;)y(r.value)&&V(r.value,d)}}function y(r){return typeof r=="object"&&r!==null&&r.$$typeof===ae}function V(r,d){if(r._store&&!r._store.validated&&r.key==null&&(r._store.validated=1,d=B(d),!me[d])){me[d]=!0;var u="";r&&r._owner!=null&&r._owner!==p()&&(u=null,typeof r._owner.tag=="number"?u=e(r._owner.type):typeof r._owner.name=="string"&&(u=r._owner.name),u=" It was passed a child from "+u+".");var v=Z.getCurrentStack;Z.getCurrentStack=function(){var A=E(r.type);return v&&(A+=v()||""),A},console.error('Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',d,u),Z.getCurrentStack=v}}function B(r){var d="",u=p();return u&&(u=e(u.type))&&(d=`
|
|
28
|
+
|
|
29
|
+
Check the render method of \``+u+"`."),d||(r=e(r))&&(d=`
|
|
30
|
+
|
|
31
|
+
Check the top-level render call using <`+r+">."),d}var _=c,ae=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),J=Symbol.for("react.fragment"),je=Symbol.for("react.strict_mode"),xe=Symbol.for("react.profiler"),he=Symbol.for("react.consumer"),Re=Symbol.for("react.context"),Pe=Symbol.for("react.forward_ref"),we=Symbol.for("react.suspense"),Se=Symbol.for("react.suspense_list"),T=Symbol.for("react.memo"),Ae=Symbol.for("react.lazy"),qe=Symbol.for("react.offscreen"),ye=Symbol.iterator,le=Symbol.for("react.client.reference"),Z=_.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Oe=Object.prototype.hasOwnProperty,ue=Object.assign,H=Symbol.for("react.client.reference"),j=Array.isArray,$=0,be,K,de,f,F,R,b;n.__reactDisabledLog=!0;var S,I,N=!1,q=new(typeof WeakMap=="function"?WeakMap:Map),ce=Symbol.for("react.client.reference"),ee,fe={},te={},me={};Te.Fragment=J,Te.jsx=function(r,d,u,v,A){return M(r,d,u,!1,v,A)},Te.jsxs=function(r,d,u,v,A){return M(r,d,u,!0,v,A)}})()),Te}var it;function Lt(){return it||(it=1,process.env.NODE_ENV==="production"?ze.exports=Ut():ze.exports=$t()),ze.exports}var C=Lt();const Qt=new x.Quaternion;new x.Euler;const Xt=new x.Vector3;new x.Object3D;const pe=new x.Matrix4,z=new x.Vector3,se=new x.Quaternion,Ee=new x.Vector3,Zt=e=>{const[t,o,n]=e;return new x.Vector3(t,o,n)},st=({x:e,y:t,z:o,w:n})=>Qt.set(e,t,o,n),Y=e=>{if(Array.isArray(e))return new G.Vector3(e[0],e[1],e[2]);if(typeof e=="number")return new G.Vector3(e,e,e);{const t=e;return new G.Vector3(t.x,t.y,t.z)}},ct=e=>Array.isArray(e)?new G.Quaternion(e[0],e[1],e[2],e[3]):new G.Quaternion(e.x,e.y,e.z,e.w),Kt={fixed:1,dynamic:0,kinematicPosition:2,kinematicVelocity:3},mt=e=>Kt[e],er=(e,t)=>{const o=Array.from(e);for(let n=0;n<e.length/3;n++)o[n*3]*=t.x,o[n*3+1]*=t.y,o[n*3+2]*=t.z;return o},gt=e=>e?e instanceof x.Quaternion?[e.x,e.y,e.z,e.w]:e instanceof x.Vector3||e instanceof x.Euler?[e.x,e.y,e.z]:Array.isArray(e)?e:[e]:[0];function ie(e){const t=c.useRef(void 0);return t.current===void 0&&(t.current={value:typeof e=="function"?e():e}),t.current.value}const tr=e=>{const t=c.useRef(e),o=c.useRef(0),n=c.useRef(0);c.useEffect(()=>{t.current=e},[e]),c.useEffect(()=>{const i=()=>{const s=performance.now(),a=s-n.current;o.current=requestAnimationFrame(i),t.current(a/1e3),n.current=s};return o.current=requestAnimationFrame(i),()=>cancelAnimationFrame(o.current)},[])},rr=({onStep:e,updatePriority:t})=>(Fe.useFrame((o,n)=>{e(n)},t),null),or=({onStep:e})=>(tr(t=>{e(t)}),null),nr=({onStep:e,type:t,updatePriority:o})=>t==="independent"?C.jsx(or,{onStep:e}):C.jsx(rr,{onStep:e,updatePriority:o}),ir=c.memo(nr),sr=(e,t,o)=>{const n=t.slice();if(e==="heightfield"){const s=n[3];return s.x*=o.x,s.x*=o.y,s.x*=o.z,n}if(e==="trimesh"||e==="convexHull")return n[0]=er(n[0],o),n;const i=[o.x,o.y,o.z,o.x,o.x];return n.map((s,a)=>i[a]*s)},cr=(e,t,o,n)=>{const i=sr(e.shape,e.args,o),s=G.ColliderDesc[e.shape](...i);return t.createCollider(s,n==null?void 0:n())},ar=["shape","args"],at="Please pick ONLY ONE of the `density`, `mass` and `massProperties` options.",lr=(e,t)=>{if(t.density!==void 0){if(t.mass!==void 0||t.massProperties!==void 0)throw new Error(at);e.setDensity(t.density);return}if(t.mass!==void 0){if(t.massProperties!==void 0)throw new Error(at);e.setMass(t.mass);return}t.massProperties!==void 0&&e.setMassProperties(t.massProperties.mass,t.massProperties.centerOfMass,t.massProperties.principalAngularInertia,t.massProperties.angularInertiaLocalFrame)},pt={sensor:(e,t)=>{e.setSensor(t)},collisionGroups:(e,t)=>{e.setCollisionGroups(t)},solverGroups:(e,t)=>{e.setSolverGroups(t)},friction:(e,t)=>{e.setFriction(t)},frictionCombineRule:(e,t)=>{e.setFrictionCombineRule(t)},restitution:(e,t)=>{e.setRestitution(t)},restitutionCombineRule:(e,t)=>{e.setRestitutionCombineRule(t)},activeCollisionTypes:(e,t)=>{e.setActiveCollisionTypes(t)},contactSkin:(e,t)=>{e.setContactSkin(t)},quaternion:()=>{},position:()=>{},rotation:()=>{},scale:()=>{}},yt=Object.keys(pt),ur=(e,t,o)=>{var i;const n=o.get(e.handle);if(n){const s=n.object.parent.getWorldScale(Xt),a=(i=n.worldParent)==null?void 0:i.matrixWorld.clone().invert();n.object.updateWorldMatrix(!0,!1),pe.copy(n.object.matrixWorld),a&&pe.premultiply(a),pe.decompose(z,se,Ee),e.parent()?(e.setTranslationWrtParent({x:z.x*s.x,y:z.y*s.y,z:z.z*s.z}),e.setRotationWrtParent(se)):(e.setTranslation({x:z.x*s.x,y:z.y*s.y,z:z.z*s.z}),e.setRotation(se)),yt.forEach(l=>{if(l in t){const E=t[l];pt[l](e,E,t)}}),lr(e,t)}},dr=(e,t,o)=>{const n=c.useMemo(()=>yt.flatMap(i=>gt(t[i])),[t]);c.useEffect(()=>{const i=e();ur(i,t,o)},[...n,e])},fr=e=>{let t=!1;return e.traverseAncestors(o=>{o.userData.r3RapierType==="MeshCollider"&&(t=!0)}),t},mr=(e,t,o)=>({collider:e,worldParent:o||void 0,object:t}),gr={cuboid:"cuboid",ball:"ball",hull:"convexHull",trimesh:"trimesh"},pr=({object:e,ignoreMeshColliders:t=!0,options:o})=>{const n=[];e.updateWorldMatrix(!0,!1);const i=e.matrixWorld.clone().invert(),s=a=>{if("isMesh"in a){if(t&&fr(a))return;const l=a.getWorldScale(Ee),E=gr[o.colliders||"cuboid"];a.updateWorldMatrix(!0,!1),pe.copy(a.matrixWorld).premultiply(i).decompose(z,se,Ee);const p=new x.Euler().setFromQuaternion(se,"XYZ"),{geometry:m}=a,{args:P,offset:h}=yr(m,o.colliders||"cuboid"),O={...Ct(o),args:P,shape:E,rotation:[p.x,p.y,p.z],position:[z.x+h.x*l.x,z.y+h.y*l.y,z.z+h.z*l.z],scale:[l.x,l.y,l.z]};n.push(O)}};return o.includeInvisible?e.traverse(s):e.traverseVisible(s),n},yr=(e,t)=>{var o;switch(t){case"cuboid":{e.computeBoundingBox();const{boundingBox:n}=e,i=n.getSize(new x.Vector3);return{args:[i.x/2,i.y/2,i.z/2],offset:n.getCenter(new x.Vector3)}}case"ball":{e.computeBoundingSphere();const{boundingSphere:n}=e;return{args:[n.radius],offset:n.center}}case"trimesh":{const n=e.index?e.clone():ft.mergeVertices(e);return{args:[n.attributes.position.array,(o=n.index)==null?void 0:o.array],offset:new x.Vector3}}case"hull":return{args:[e.clone().attributes.position.array],offset:new x.Vector3}}return{args:[],offset:new x.Vector3}},bt=e=>({collision:!!(e!=null&&e.onCollisionEnter||e!=null&&e.onCollisionExit||e!=null&&e.onIntersectionEnter||e!=null&&e.onIntersectionExit),contactForce:!!(e!=null&&e.onContactForce)}),br=(e,t,o,n={})=>{const{onCollisionEnter:i,onCollisionExit:s,onIntersectionEnter:a,onIntersectionExit:l,onContactForce:E}=t;c.useEffect(()=>{const p=e();if(p){const{collision:m,contactForce:P}=bt(t),h=m||n.collision,O=P||n.contactForce;h&&O?p.setActiveEvents(G.ActiveEvents.COLLISION_EVENTS|G.ActiveEvents.CONTACT_FORCE_EVENTS):h?p.setActiveEvents(G.ActiveEvents.COLLISION_EVENTS):O&&p.setActiveEvents(G.ActiveEvents.CONTACT_FORCE_EVENTS),o.set(p.handle,{onCollisionEnter:i,onCollisionExit:s,onIntersectionEnter:a,onIntersectionExit:l,onContactForce:E})}return()=>{p&&o.delete(p.handle)}},[i,s,a,l,E,n])},Ct=(e={})=>{const{mass:t,linearDamping:o,angularDamping:n,type:i,onCollisionEnter:s,onCollisionExit:a,onIntersectionEnter:l,onIntersectionExit:E,onContactForce:p,children:m,canSleep:P,ccd:h,gravityScale:O,softCcdPrediction:M,ref:Q,...y}=e;return y},Je=e=>{const t=c.useRef(e);return c.useEffect(()=>{t.current=e},[e]),t},D=()=>{const e=c.useContext(vt);if(!e)throw new Error("react-three-rapier: useRapier must be used within <Physics />!");return e},Et=e=>{const{beforeStepCallbacks:t}=D(),o=Je(e);c.useEffect(()=>(t.add(o),()=>{t.delete(o)}),[])},Cr=e=>{const{afterStepCallbacks:t}=D(),o=Je(e);c.useEffect(()=>(t.add(o),()=>{t.delete(o)}),[])},Er=e=>{const{filterContactPairHooks:t}=D(),o=Je(e);c.useEffect(()=>(t.add(o),()=>{t.delete(o)}),[])},vr=e=>{const{filterIntersectionPairHooks:t}=D(),o=Je(e);c.useEffect(()=>(t.add(o),()=>{t.delete(o)}),[])},Ge=(e,t,o=!0)=>{const[n,i]=c.useState([]);return c.useEffect(()=>{e.current&&t.colliders!==!1&&i(pr({object:e.current,options:t,ignoreMeshColliders:o}))},[t.colliders]),n},xr=c.memo(()=>{const{world:e}=D(),t=c.useRef(null);return Fe.useFrame(()=>{const o=t.current;if(!o)return;const n=e.debugRender(),i=new x.BufferGeometry;i.setAttribute("position",new x.BufferAttribute(n.vertices,3)),i.setAttribute("color",new x.BufferAttribute(n.colors,4)),o.geometry.dispose(),o.geometry=i}),C.jsx("group",{children:C.jsxs("lineSegments",{ref:t,frustumCulled:!1,children:[C.jsx("lineBasicMaterial",{color:16777215,vertexColors:!0}),C.jsx("bufferGeometry",{})]})})}),hr=e=>{let t;const o={get(a,l){return t||(t=e()),Reflect.get(t,l)},set(a,l,E){return t||(t=e()),Reflect.set(t,l,E)}};return{proxy:new Proxy({},o),reset:()=>{t=void 0},set:a=>{t=a}}},vt=c.createContext(void 0),De=(e,t)=>{var o,n,i,s,a,l;return{target:{rigidBody:e.rigidBody.object,collider:e.collider.object,colliderObject:(o=e.collider.state)==null?void 0:o.object,rigidBodyObject:(n=e.rigidBody.state)==null?void 0:n.object},other:{rigidBody:t.rigidBody.object,collider:t.collider.object,colliderObject:(i=t.collider.state)==null?void 0:i.object,rigidBodyObject:(s=t.rigidBody.state)==null?void 0:s.object},rigidBody:t.rigidBody.object,collider:t.collider.object,colliderObject:(a=t.collider.state)==null?void 0:a.object,rigidBodyObject:(l=t.rigidBody.state)==null?void 0:l.object}},lt=async()=>{let e=await import("@dimforge/rapier3d-compat");return await e.init(),e},Rr=e=>{const{colliders:t="cuboid",children:o,timeStep:n=1/60,paused:i=!1,interpolate:s=!0,updatePriority:a,updateLoop:l="follow",debug:E=!1,gravity:p=[0,-9.81,0],allowedLinearError:m=.001,predictionDistance:P=.002,numSolverIterations:h=4,numInternalPgsIterations:O=1,minIslandSize:M=128,maxCcdSubsteps:Q=1,contactNaturalFrequency:y=30,lengthUnit:V=1}=e,B=Yt.suspend(lt,["@react-thee/rapier",lt]),{invalidate:_}=Fe.useThree(),ae=ie(()=>new Map),k=ie(()=>new Map),J=ie(()=>new Map),je=ie(()=>new Map),xe=ie(()=>new G.EventQueue(!1)),he=ie(()=>new Set),Re=ie(()=>new Set),Pe=ie(()=>({filterContactPair:(...H)=>{for(const j of he){const $=j.current(...H);if($!==null)return $}return null},filterIntersectionPair:(...H)=>{for(const j of Re)if(j.current(...H)===!1)return!1;return!0}})),we=ie(()=>new Set),Se=ie(()=>new Set),{proxy:T,reset:Ae,set:qe}=ie(()=>hr(()=>new B.World(Zt(p))));c.useEffect(()=>()=>{T.free(),Ae()},[]),c.useEffect(()=>{T.gravity=Y(p),T.integrationParameters.numSolverIterations=h,T.integrationParameters.numInternalPgsIterations=O,T.integrationParameters.normalizedAllowedLinearError=m,T.integrationParameters.minIslandSize=M,T.integrationParameters.maxCcdSubsteps=Q,T.integrationParameters.normalizedPredictionDistance=P,T.lengthUnit=V,T.integrationParameters.contact_natural_frequency=y},[T,...p,h,O,m,M,Q,P,V,y]);const ye=c.useCallback(H=>{var b;const j=T.getCollider(H),$=je.get(H),be=k.get(H),K=(b=j==null?void 0:j.parent())==null?void 0:b.handle,de=K!==void 0?T.getRigidBody(K):void 0,f=de&&K!==void 0?J.get(K):void 0,F=K!==void 0?ae.get(K):void 0;return{collider:{object:j,events:$,state:be},rigidBody:{object:de,events:f,state:F}}},[]),[le]=c.useState({previousState:{},accumulator:0}),Z=c.useCallback(H=>{const j=T,$=n==="vary",be=x.MathUtils.clamp(H,0,.5),K=f=>{we.forEach(R=>{R.current(j)}),j.timestep=f;const F=he.size>0||Re.size>0;j.step(xe,F?Pe:void 0),Se.forEach(R=>{R.current(j)})};if($)K(be);else for(le.accumulator+=be;le.accumulator>=n;)s&&(le.previousState={},j.forEachRigidBody(f=>{le.previousState[f.handle]={position:f.translation(),rotation:f.rotation()}})),K(n),le.accumulator-=n;const de=$||!s||i?1:le.accumulator/n;ae.forEach((f,F)=>{var q,ce;const R=j.getRigidBody(F),b=J.get(F);if((b!=null&&b.onSleep||b!=null&&b.onWake)&&(R.isSleeping()&&!f.isSleeping&&((q=b==null?void 0:b.onSleep)==null||q.call(b)),!R.isSleeping()&&f.isSleeping&&((ce=b==null?void 0:b.onWake)==null||ce.call(b)),f.isSleeping=R.isSleeping()),!R||R.isSleeping()&&!("isInstancedMesh"in f.object)||!f.setMatrix)return;let S=R.translation(),I=R.rotation(),N=le.previousState[F];N&&(pe.compose(N.position,st(N.rotation),f.scale).premultiply(f.invertedWorldMatrix).decompose(z,se,Ee),f.meshType=="mesh"&&(f.object.position.copy(z),f.object.quaternion.copy(se))),pe.compose(S,st(I),f.scale).premultiply(f.invertedWorldMatrix).decompose(z,se,Ee),f.meshType=="instancedMesh"?f.setMatrix(pe):(f.object.position.lerp(z,de),f.object.quaternion.slerp(se,de))}),xe.drainCollisionEvents((f,F,R)=>{var q,ce,ee,fe,te,me,r,d,u,v,A,w,g,re,ne,W,oe,ge,X,Ce,L,Qe,Be,Xe;const b=ye(f),S=ye(F);if(!(b!=null&&b.collider.object)||!(S!=null&&S.collider.object))return;const I=De(b,S),N=De(S,b);R?j.contactPair(b.collider.object,S.collider.object,(_e,ke)=>{var Ne,Ze,Ie,Ke,We,et,Ve,tt;(Ze=(Ne=b.rigidBody.events)==null?void 0:Ne.onCollisionEnter)==null||Ze.call(Ne,{...I,manifold:_e,flipped:ke}),(Ke=(Ie=S.rigidBody.events)==null?void 0:Ie.onCollisionEnter)==null||Ke.call(Ie,{...N,manifold:_e,flipped:ke}),(et=(We=b.collider.events)==null?void 0:We.onCollisionEnter)==null||et.call(We,{...I,manifold:_e,flipped:ke}),(tt=(Ve=S.collider.events)==null?void 0:Ve.onCollisionEnter)==null||tt.call(Ve,{...N,manifold:_e,flipped:ke})}):((ce=(q=b.rigidBody.events)==null?void 0:q.onCollisionExit)==null||ce.call(q,I),(fe=(ee=S.rigidBody.events)==null?void 0:ee.onCollisionExit)==null||fe.call(ee,N),(me=(te=b.collider.events)==null?void 0:te.onCollisionExit)==null||me.call(te,I),(d=(r=S.collider.events)==null?void 0:r.onCollisionExit)==null||d.call(r,N)),R?j.intersectionPair(b.collider.object,S.collider.object)&&((v=(u=b.rigidBody.events)==null?void 0:u.onIntersectionEnter)==null||v.call(u,I),(w=(A=S.rigidBody.events)==null?void 0:A.onIntersectionEnter)==null||w.call(A,N),(re=(g=b.collider.events)==null?void 0:g.onIntersectionEnter)==null||re.call(g,I),(W=(ne=S.collider.events)==null?void 0:ne.onIntersectionEnter)==null||W.call(ne,N)):((ge=(oe=b.rigidBody.events)==null?void 0:oe.onIntersectionExit)==null||ge.call(oe,I),(Ce=(X=S.rigidBody.events)==null?void 0:X.onIntersectionExit)==null||Ce.call(X,N),(Qe=(L=b.collider.events)==null?void 0:L.onIntersectionExit)==null||Qe.call(L,I),(Xe=(Be=S.collider.events)==null?void 0:Be.onIntersectionExit)==null||Xe.call(Be,N))}),xe.drainContactForceEvents(f=>{var I,N,q,ce,ee,fe,te,me;const F=ye(f.collider1()),R=ye(f.collider2());if(!(F!=null&&F.collider.object)||!(R!=null&&R.collider.object))return;const b=De(F,R),S=De(R,F);(N=(I=F.rigidBody.events)==null?void 0:I.onContactForce)==null||N.call(I,{...b,totalForce:f.totalForce(),totalForceMagnitude:f.totalForceMagnitude(),maxForceDirection:f.maxForceDirection(),maxForceMagnitude:f.maxForceMagnitude()}),(ce=(q=R.rigidBody.events)==null?void 0:q.onContactForce)==null||ce.call(q,{...S,totalForce:f.totalForce(),totalForceMagnitude:f.totalForceMagnitude(),maxForceDirection:f.maxForceDirection(),maxForceMagnitude:f.maxForceMagnitude()}),(fe=(ee=F.collider.events)==null?void 0:ee.onContactForce)==null||fe.call(ee,{...b,totalForce:f.totalForce(),totalForceMagnitude:f.totalForceMagnitude(),maxForceDirection:f.maxForceDirection(),maxForceMagnitude:f.maxForceMagnitude()}),(me=(te=R.collider.events)==null?void 0:te.onContactForce)==null||me.call(te,{...S,totalForce:f.totalForce(),totalForceMagnitude:f.totalForceMagnitude(),maxForceDirection:f.maxForceDirection(),maxForceMagnitude:f.maxForceMagnitude()})}),j.forEachActiveRigidBody(()=>{_()})},[i,n,s,T]),Oe=c.useMemo(()=>({rapier:B,world:T,setWorld:H=>{qe(H)},physicsOptions:{colliders:t,gravity:p},rigidBodyStates:ae,colliderStates:k,rigidBodyEvents:J,colliderEvents:je,beforeStepCallbacks:we,afterStepCallbacks:Se,isPaused:i,isDebug:E,step:Z,filterContactPairHooks:he,filterIntersectionPairHooks:Re}),[i,Z,E,t,p]),ue=c.useCallback(H=>{i||Z(H)},[i,Z]);return C.jsxs(vt.Provider,{value:Oe,children:[C.jsx(ir,{onStep:ue,type:l,updatePriority:a}),E&&C.jsx(xr,{}),o]})},Ye=(e,t=null)=>{const o=c.useRef(t);return e&&typeof e!="function"?(e.current||(e.current=o.current),e):o},Ue=(e,t,o)=>{const n=c.useRef(void 0),i=c.useCallback(()=>(n.current||(n.current=e()),n.current),o);return c.useEffect(()=>{const s=i(),a=()=>t(s);return()=>{a(),n.current=void 0}},[i]),i},wr=e=>{const t=mt((e==null?void 0:e.type)||"dynamic"),o=new G.RigidBodyDesc(t);return o.canSleep=(e==null?void 0:e.canSleep)??!0,o},Sr=({rigidBody:e,object:t,setMatrix:o,getMatrix:n,worldScale:i,meshType:s="mesh"})=>{t.updateWorldMatrix(!0,!1);const a=t.parent.matrixWorld.clone().invert();return{object:t,rigidBody:e,invertedWorldMatrix:a,setMatrix:o||(l=>{t.matrix.copy(l)}),getMatrix:n||(l=>l.copy(t.matrix)),scale:i||t.getWorldScale(Ee).clone(),isSleeping:!1,meshType:s}},jr=["args","colliders","canSleep"],xt={gravityScale:(e,t)=>{e.setGravityScale(t,!0)},additionalSolverIterations(e,t){e.setAdditionalSolverIterations(t)},linearDamping:(e,t)=>{e.setLinearDamping(t)},angularDamping:(e,t)=>{e.setAngularDamping(t)},dominanceGroup:(e,t)=>{e.setDominanceGroup(t)},enabledRotations:(e,[t,o,n])=>{e.setEnabledRotations(t,o,n,!0)},enabledTranslations:(e,[t,o,n])=>{e.setEnabledTranslations(t,o,n,!0)},lockRotations:(e,t)=>{e.lockRotations(t,!0)},lockTranslations:(e,t)=>{e.lockTranslations(t,!0)},angularVelocity:(e,[t,o,n])=>{e.setAngvel({x:t,y:o,z:n},!0)},linearVelocity:(e,[t,o,n])=>{e.setLinvel({x:t,y:o,z:n},!0)},ccd:(e,t)=>{e.enableCcd(t)},softCcdPrediction:(e,t)=>{e.setSoftCcdPrediction(t)},userData:(e,t)=>{e.userData=t},type(e,t){e.setBodyType(mt(t),!0)},position:()=>{},rotation:()=>{},quaternion:()=>{},scale:()=>{}},ht=Object.keys(xt),Pr=(e,t,o,n=!0)=>{if(!e)return;const i=o.get(e.handle);i&&(n&&(i.object.updateWorldMatrix(!0,!1),pe.copy(i.object.matrixWorld).decompose(z,se,Ee),e.setTranslation(z,!1),e.setRotation(se,!1)),ht.forEach(s=>{s in t&&xt[s](e,t[s])}))},Ar=(e,t,o,n=!0)=>{const i=c.useMemo(()=>ht.flatMap(s=>gt(t[s])),[t]);c.useEffect(()=>{const s=e();Pr(s,t,o,n)},i)},Mr=(e,t,o)=>{const{onWake:n,onSleep:i,onCollisionEnter:s,onCollisionExit:a,onIntersectionEnter:l,onIntersectionExit:E,onContactForce:p}=t,m={onWake:n,onSleep:i,onCollisionEnter:s,onCollisionExit:a,onIntersectionEnter:l,onIntersectionExit:E,onContactForce:p};c.useEffect(()=>{const P=e();return o.set(P.handle,m),()=>{o.delete(P.handle)}},[n,i,s,a,l,E,p])},Rt=({x:e,y:t,z:o}={x:0,y:0,z:0})=>new x.Vector3(e,t,o),Tr=({x:e,y:t,z:o,w:n}={x:0,y:0,z:0,w:1})=>new x.Quaternion(e,t,o,n),Fr=({x:e,y:t,z:o}={x:0,y:0,z:0})=>new x.Euler(e,t,o),U=c.memo(e=>{const{children:t,position:o,rotation:n,quaternion:i,scale:s,name:a}=e,{world:l,colliderEvents:E,colliderStates:p}=D(),m=_t(),P=Ye(e.ref),h=c.useRef(null),O=ar.flatMap(y=>Array.isArray(e[y])?e[y]:[e[y]]),M=Ue(()=>{const y=h.current.getWorldScale(Rt()),V=cr(e,l,y,m==null?void 0:m.getRigidBody);return typeof e.ref=="function"&&e.ref(V),P.current=V,V},y=>{l.getCollider(y.handle)&&l.removeCollider(y,!0)},[...O,m]);c.useEffect(()=>{const y=M();return p.set(y.handle,mr(y,h.current,m==null?void 0:m.ref.current)),()=>{p.delete(y.handle)}},[M]);const Q=c.useMemo(()=>({...Ct(m==null?void 0:m.options),...e}),[e,m==null?void 0:m.options]);return dr(M,Q,p),br(M,Q,E,bt(m==null?void 0:m.options)),C.jsx("object3D",{position:o,rotation:n,quaternion:i,scale:s,ref:h,name:a,children:t})}),wt=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"cuboid",ref:t}));wt.displayName="CuboidCollider";const St=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"roundCuboid",ref:t}));St.displayName="RoundCuboidCollider";const jt=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"ball",ref:t}));jt.displayName="BallCollider";const Pt=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"capsule",ref:t}));Pt.displayName="CapsuleCollider";const At=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"heightfield",ref:t}));At.displayName="HeightfieldCollider";const Mt=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"trimesh",ref:t}));Mt.displayName="TrimeshCollider";const Tt=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"cone",ref:t}));Tt.displayName="ConeCollider";const Ft=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"roundCone",ref:t}));Ft.displayName="RoundConeCollider";const $e=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"cylinder",ref:t}));$e.displayName="CylinderCollider";const Or=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"roundCylinder",ref:t}));$e.displayName="RoundCylinderCollider";const Ot=c.forwardRef((e,t)=>C.jsx(U,{...e,shape:"convexHull",ref:t}));Ot.displayName="ConvexHullCollider";const Bt=c.createContext(void 0),_t=()=>c.useContext(Bt),Le=c.memo(e=>{const{ref:t,children:o,type:n,position:i,rotation:s,scale:a,quaternion:l,transformState:E,...p}=e,m=c.useRef(null),P=Ye(t),{world:h,rigidBodyStates:O,physicsOptions:M,rigidBodyEvents:Q}=D(),y=c.useMemo(()=>({...M,...e,children:void 0}),[M,e]),V=jr.flatMap(k=>Array.isArray(y[k])?[...y[k]]:y[k]),B=Ge(m,y),_=Ue(()=>{const k=wr(y),J=h.createRigidBody(k);return typeof t=="function"&&t(J),P.current=J,J},k=>{h.getRigidBody(k.handle)&&h.removeRigidBody(k)},V);c.useEffect(()=>{const k=_(),J=Sr({rigidBody:k,object:m.current});return O.set(k.handle,e.transformState?e.transformState(J):J),()=>{O.delete(k.handle)}},[_]),Ar(_,y,O),Mr(_,y,Q);const ae=c.useMemo(()=>({ref:m,getRigidBody:_,options:y}),[_]);return C.jsx(Bt.Provider,{value:ae,children:C.jsxs("object3D",{ref:m,...p,position:i,rotation:s,quaternion:l,scale:a,children:[o,B.map((k,J)=>C.jsx(U,{...k},J))]})})});Le.displayName="RigidBody";const kt=c.memo(e=>{const{children:t,type:o}=e,{physicsOptions:n}=D(),i=c.useRef(null),{options:s}=_t(),a=c.useMemo(()=>({...n,...s,children:void 0,colliders:o}),[n,s]),l=Ge(i,a,!1);return C.jsxs("object3D",{ref:i,userData:{r3RapierType:"MeshCollider"},children:[t,l.map((E,p)=>C.jsx(U,{...E},p))]})});kt.displayName="MeshCollider";const Nt=c.memo(({ref:e,...t})=>{const o=Ye(e,[]),n=c.useRef(null),i=c.useRef(null),{children:s,instances:a,colliderNodes:l=[],position:E,rotation:p,quaternion:m,scale:P,...h}=t,O=Ge(n,{...t,children:void 0}),M=()=>{const y=i.current.children[0];if(y&&"isInstancedMesh"in y)return y};c.useEffect(()=>{const y=M();y?y.instanceMatrix.setUsage(x.DynamicDrawUsage):console.warn("InstancedRigidBodies expects exactly one child, which must be an InstancedMesh")},[]);const Q=(y,V)=>{const B=M();return B?{...y,getMatrix:_=>(B.getMatrixAt(V,_),_),setMatrix:_=>{B.setMatrixAt(V,_),B.instanceMatrix.needsUpdate=!0},meshType:"instancedMesh"}:y};return C.jsxs("object3D",{ref:n,...h,position:E,rotation:p,quaternion:m,scale:P,children:[C.jsx("object3D",{ref:i,children:s}),a==null?void 0:a.map((y,V)=>C.jsx(Le,{...h,...y,ref:B=>{o.current[V]=B},transformState:B=>Q(B,V),children:C.jsxs(C.Fragment,{children:[l.map((B,_)=>C.jsx(c.Fragment,{children:B},_)),O.map((B,_)=>C.jsx(U,{...B},_))]})}))]})});Nt.displayName="InstancedRigidBodies";const ve=(e,t,o)=>{const{world:n}=D(),i=c.useRef(void 0);return Ue(()=>{if(e.current&&t.current){const s=n.createImpulseJoint(o,e.current,t.current,!0);return i.current=s,s}},s=>{s&&(i.current=void 0,n.getImpulseJoint(s.handle)&&n.removeImpulseJoint(s,!0))},[]),i},Br=(e,t,[o,n,i,s])=>{const{rapier:a}=D();return ve(e,t,a.JointData.fixed(Y(o),ct(n),Y(i),ct(s)))},_r=(e,t,[o,n])=>{const{rapier:i}=D();return ve(e,t,i.JointData.spherical(Y(o),Y(n)))},kr=(e,t,[o,n,i,s])=>{const{rapier:a}=D(),l=a.JointData.revolute(Y(o),Y(n),Y(i));return s&&(l.limitsEnabled=!0,l.limits=s),ve(e,t,l)},Nr=(e,t,[o,n,i,s])=>{const{rapier:a}=D(),l=a.JointData.prismatic(Y(o),Y(n),Y(i));return s&&(l.limitsEnabled=!0,l.limits=s),ve(e,t,l)},Ir=(e,t,[o,n,i])=>{const{rapier:s}=D(),a=Y(o),l=Y(n),E=s.JointData.rope(i,a,l);return ve(e,t,E)},Wr=(e,t,[o,n,i,s,a])=>{const{rapier:l}=D(),E=Y(o),p=Y(n),m=l.JointData.spring(i,s,a,E,p);return ve(e,t,m)},Vr=(e,t)=>(ut(e)<<16)+(t!==void 0?ut(t):65535),ut=e=>[e].flat().reduce((t,o)=>t|1<<o,0),zr=new x.Vector3,It=e=>{const{scene:t}=Fe.useThree(),o=c.useRef(null),n=c.useRef(null),i=e.strength>0?255:16711680;return c.useEffect(()=>(o.current=new x.Mesh(new x.SphereGeometry(.2,6,6),new x.MeshBasicMaterial({color:i,wireframe:!0})),n.current=new ft.VertexNormalsHelper(o.current,e.range,i),n.current.frustumCulled=!1,t.add(o.current),t.add(n.current),()=>{n.current&&o.current&&(t.remove(n.current),t.remove(o.current))}),[e,i]),Fe.useFrame(()=>{var s;if(o.current&&e.object.current){const a=e.object.current.getWorldPosition(zr);o.current.position.copy(a),(s=n.current)==null||s.update()}}),null},Dr={static:(e,t,o,n,i)=>e,linear:(e,t,o,n,i)=>e*(n/o),newtonian:(e,t,o,n,i)=>i*e*t/Math.pow(n,2)},He=new x.Vector3,dt=new x.Vector3,Wt=(e,{object:t,strength:o,range:n,gravitationalConstant:i,collisionGroups:s,type:a})=>{const l=e.translation();He.set(l.x,l.y,l.z);const E=t.getWorldPosition(new x.Vector3),p=E.distanceTo(He);if(p<n){let m=Dr[a](o,e.mass(),n,p,i);m=m===1/0?o:m;let P=s===void 0;if(s!==void 0)for(let h=0;h<e.numColliders();h++){const M=e.collider(h).collisionGroups();if((s>>16&M)!=0&&(M>>16&s)!=0){P=!0;break}}P&&(dt.set(0,0,0).subVectors(E,He).normalize().multiplyScalar(m),e.applyImpulse(dt,!0))}},Jr=c.memo(e=>{const{position:t=[0,0,0],strength:o=1,range:n=10,type:i="static",gravitationalConstant:s=6673e-14,collisionGroups:a}=e,l=c.useRef(null),{isDebug:E}=D();return Et(p=>{l.current&&p.bodies.forEach(m=>{m.isDynamic()&&Wt(m,{object:l.current,strength:o,range:n,type:i,gravitationalConstant:s,collisionGroups:a})})}),C.jsxs(C.Fragment,{children:[C.jsx("object3D",{ref:l,position:t}),E&&C.jsx(It,{strength:o,gravitationalConstant:s,range:n,type:i,collisionGroups:a,object:l})]})});Object.defineProperty(exports,"CoefficientCombineRule",{enumerable:!0,get:()=>G.CoefficientCombineRule});Object.defineProperty(exports,"RapierCollider",{enumerable:!0,get:()=>G.Collider});Object.defineProperty(exports,"RapierRigidBody",{enumerable:!0,get:()=>G.RigidBody});exports.AnyCollider=U;exports.Attractor=Jr;exports.AttractorDebugHelper=It;exports.BallCollider=jt;exports.CapsuleCollider=Pt;exports.ConeCollider=Tt;exports.ConvexHullCollider=Ot;exports.CuboidCollider=wt;exports.CylinderCollider=$e;exports.HeightfieldCollider=At;exports.InstancedRigidBodies=Nt;exports.MeshCollider=kt;exports.Physics=Rr;exports.RigidBody=Le;exports.RoundConeCollider=Ft;exports.RoundCuboidCollider=St;exports.RoundCylinderCollider=Or;exports.TrimeshCollider=Mt;exports.applyAttractorForceOnRigidBody=Wt;exports.euler=Fr;exports.interactionGroups=Vr;exports.quat=Tr;exports.useAfterPhysicsStep=Cr;exports.useBeforePhysicsStep=Et;exports.useFilterContactPair=Er;exports.useFilterIntersectionPair=vr;exports.useFixedJoint=Br;exports.useImpulseJoint=ve;exports.usePrismaticJoint=Nr;exports.useRapier=D;exports.useRevoluteJoint=kr;exports.useRopeJoint=Ir;exports.useSphericalJoint=_r;exports.useSpringJoint=Wr;exports.vec3=Rt;
|