@pinkaphant/ecctrl 0.0.0-stage → 2.0.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/LICENSE +21 -0
  3. package/NOTICE +10 -0
  4. package/dist/Color-V9u0UyNg.cjs +81 -0
  5. package/dist/Color-V9u0UyNg.cjs.map +1 -0
  6. package/dist/Color-rCfz0rNn.js +28 -0
  7. package/dist/Color-rCfz0rNn.js.map +1 -0
  8. package/dist/CurveLUT-BfMhx3LX.js +88 -0
  9. package/dist/CurveLUT-BfMhx3LX.js.map +1 -0
  10. package/dist/CurveLUT-Ck18ZlkK.cjs +99 -0
  11. package/dist/CurveLUT-Ck18ZlkK.cjs.map +1 -0
  12. package/dist/EcctrlAnimationStateController-41Cm1Tt1.cjs +111 -0
  13. package/dist/EcctrlAnimationStateController-41Cm1Tt1.cjs.map +1 -0
  14. package/dist/EcctrlAnimationStateController-Bb2fARWF.js +94 -0
  15. package/dist/EcctrlAnimationStateController-Bb2fARWF.js.map +1 -0
  16. package/dist/Math-BkrN2TZK.js +49 -0
  17. package/dist/Math-BkrN2TZK.js.map +1 -0
  18. package/dist/Math-ByyUpUHB.cjs +68 -0
  19. package/dist/Math-ByyUpUHB.cjs.map +1 -0
  20. package/dist/all.cjs +52 -0
  21. package/dist/all.cjs.map +1 -0
  22. package/dist/all.d.ts +16 -0
  23. package/dist/all.js +32 -0
  24. package/dist/all.js.map +1 -0
  25. package/dist/animation.cjs +23 -0
  26. package/dist/animation.cjs.map +1 -0
  27. package/dist/animation.d.ts +8 -0
  28. package/dist/animation.js +20 -0
  29. package/dist/animation.js.map +1 -0
  30. package/dist/camera-B_UgIm14.js +71 -0
  31. package/dist/camera-B_UgIm14.js.map +1 -0
  32. package/dist/camera-CzMKt9dI.cjs +79 -0
  33. package/dist/camera-CzMKt9dI.cjs.map +1 -0
  34. package/dist/camera.cjs +10 -0
  35. package/dist/camera.d.ts +9 -0
  36. package/dist/camera.js +9 -0
  37. package/dist/character/Ecctrl.d.ts +105 -0
  38. package/dist/character/animation/EcctrlAnimationStateController.d.ts +17 -0
  39. package/dist/character/animation/index.d.ts +13 -0
  40. package/dist/character/animation/resolveAnimationState.d.ts +9 -0
  41. package/dist/character/animation/types.d.ts +19 -0
  42. package/dist/character/animation/useEcctrlAnimationStore.d.ts +21 -0
  43. package/dist/character/types.d.ts +27 -0
  44. package/dist/chunk-D6vf50IK.cjs +35 -0
  45. package/dist/curves/CurveLUT.d.ts +27 -0
  46. package/dist/curves.cjs +22 -0
  47. package/dist/curves.cjs.map +1 -0
  48. package/dist/curves.d.ts +9 -0
  49. package/dist/curves.js +20 -0
  50. package/dist/curves.js.map +1 -0
  51. package/dist/gravity/EcctrlCameraControls.d.ts +28 -0
  52. package/dist/gravity/useCustomGravity.d.ts +23 -0
  53. package/dist/gravity.cjs +21 -0
  54. package/dist/gravity.cjs.map +1 -0
  55. package/dist/gravity.d.ts +9 -0
  56. package/dist/gravity.js +20 -0
  57. package/dist/gravity.js.map +1 -0
  58. package/dist/index.cjs +14 -0
  59. package/dist/index.d.ts +12 -0
  60. package/dist/index.js +10 -0
  61. package/dist/input/Joystick.d.ts +18 -0
  62. package/dist/input/VirtualButton.d.ts +17 -0
  63. package/dist/input/stores/useButtonStore.d.ts +21 -0
  64. package/dist/input/stores/useJoystickStore.d.ts +26 -0
  65. package/dist/input-CrNBMRxm.js +315 -0
  66. package/dist/input-CrNBMRxm.js.map +1 -0
  67. package/dist/input-DBhf3WZe.cjs +340 -0
  68. package/dist/input-DBhf3WZe.cjs.map +1 -0
  69. package/dist/input.cjs +13 -0
  70. package/dist/input.d.ts +15 -0
  71. package/dist/input.js +9 -0
  72. package/dist/leva--ZV58vPr.cjs +771 -0
  73. package/dist/leva--ZV58vPr.cjs.map +1 -0
  74. package/dist/leva-BjLuypTs.js +764 -0
  75. package/dist/leva-BjLuypTs.js.map +1 -0
  76. package/dist/leva.cjs +10 -0
  77. package/dist/leva.d.ts +9 -0
  78. package/dist/leva.js +9 -0
  79. package/dist/plugins/leva/CurveEditorPlugin.d.ts +72 -0
  80. package/dist/shared/Math.d.ts +11 -0
  81. package/dist/shared/constants/Color.d.ts +16 -0
  82. package/dist/shared/types.d.ts +16 -0
  83. package/dist/src-Cz0JLHDZ.js +1164 -0
  84. package/dist/src-Cz0JLHDZ.js.map +1 -0
  85. package/dist/src-Qj3Pzy6X.cjs +1172 -0
  86. package/dist/src-Qj3Pzy6X.cjs.map +1 -0
  87. package/dist/time/TimeControl.d.ts +16 -0
  88. package/dist/time-CHRDN3n2.cjs +48 -0
  89. package/dist/time-CHRDN3n2.cjs.map +1 -0
  90. package/dist/time-D3dS_ohx.js +43 -0
  91. package/dist/time-D3dS_ohx.js.map +1 -0
  92. package/dist/time.cjs +10 -0
  93. package/dist/time.d.ts +9 -0
  94. package/dist/time.js +9 -0
  95. package/dist/useCustomGravity-B35U0d4V.cjs +45 -0
  96. package/dist/useCustomGravity-B35U0d4V.cjs.map +1 -0
  97. package/dist/useCustomGravity-elzlTR6Y.js +38 -0
  98. package/dist/useCustomGravity-elzlTR6Y.js.map +1 -0
  99. package/dist/utils.cjs +23 -0
  100. package/dist/utils.cjs.map +1 -0
  101. package/dist/utils.d.ts +8 -0
  102. package/dist/utils.js +20 -0
  103. package/dist/utils.js.map +1 -0
  104. package/dist/vehicle-B8WqQHee.js +2069 -0
  105. package/dist/vehicle-B8WqQHee.js.map +1 -0
  106. package/dist/vehicle-DYwDt5rB.cjs +2089 -0
  107. package/dist/vehicle-DYwDt5rB.cjs.map +1 -0
  108. package/dist/vehicle.cjs +12 -0
  109. package/dist/vehicle.d.ts +14 -0
  110. package/dist/vehicle.js +9 -0
  111. package/dist/vehicles/EcctrlVehicle.d.ts +109 -0
  112. package/dist/vehicles/components/ShapeCastWheel.d.ts +107 -0
  113. package/dist/vehicles/components/ThrustPropeller.d.ts +50 -0
  114. package/dist/vehicles/types.d.ts +39 -0
  115. package/package.json +155 -4
  116. package/readme.md +737 -0
  117. package/README.md +0 -3
@@ -0,0 +1,2089 @@
1
+ /*!
2
+ * Ecctrl
3
+ * https://github.com/pmndrs/ecctrl
4
+ *
5
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
6
+ * SPDX-License-Identifier: MIT
7
+ */
8
+ const require_chunk = require("./chunk-D6vf50IK.cjs");
9
+ const require_useCustomGravity = require("./useCustomGravity-B35U0d4V.cjs");
10
+ const require_CurveLUT = require("./CurveLUT-Ck18ZlkK.cjs");
11
+ const require_Math = require("./Math-ByyUpUHB.cjs");
12
+ const require_Color = require("./Color-V9u0UyNg.cjs");
13
+ let three = require("three");
14
+ three = require_chunk.__toESM(three, 1);
15
+ let _react_three_fiber = require("@react-three/fiber");
16
+ let _react_three_rapier = require("@react-three/rapier");
17
+ let react = require("react");
18
+ react = require_chunk.__toESM(react, 1);
19
+ let _dimforge_rapier3d_compat = require("@dimforge/rapier3d-compat");
20
+ let three_src_math_MathUtils_js = require("three/src/math/MathUtils.js");
21
+ //#region src/vehicles/EcctrlVehicle.tsx
22
+ /*!
23
+ * Ecctrl
24
+ * https://github.com/pmndrs/ecctrl
25
+ *
26
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
27
+ * SPDX-License-Identifier: MIT
28
+ */
29
+ var DEFAULT_CAR_CONFIG = {
30
+ controlMode: "VELOCITY",
31
+ engineHorsepower: 6,
32
+ engineMaxRPM: 6e3,
33
+ gearRatios: [10],
34
+ finalDriveRatio: 1,
35
+ transmissionMode: "auto",
36
+ shiftUpRPM: 5200,
37
+ shiftDownRPM: 2200,
38
+ shiftCooldown: .35,
39
+ steerRate: Math.PI * 2,
40
+ maxSteerAngle: Math.PI / 6,
41
+ reverseTorqueScale: 1,
42
+ reverseRPMScale: .3,
43
+ engineTorqueCurveData: {
44
+ points: [{
45
+ x: 0,
46
+ y: 1,
47
+ r_out: 0
48
+ }, {
49
+ x: 1,
50
+ y: 0,
51
+ r_in: 0
52
+ }],
53
+ samples: 50
54
+ },
55
+ steerAngleCurveData: {
56
+ points: [
57
+ {
58
+ x: 0,
59
+ y: 1,
60
+ r_out: 0
61
+ },
62
+ {
63
+ x: .2,
64
+ y: 1,
65
+ r_in: 0,
66
+ r_out: 0
67
+ },
68
+ {
69
+ x: 1,
70
+ y: .4,
71
+ r_in: 0
72
+ }
73
+ ],
74
+ samples: 50
75
+ }
76
+ };
77
+ var DEFAULT_DRONE_CONFIG = {
78
+ controlMode: "VELOCITY",
79
+ maxYawRate: 2,
80
+ maxHorizSpeed: 30,
81
+ maxVertSpeed: 8,
82
+ maxTiltAngle: Math.PI / 4,
83
+ airDragFactor: .2,
84
+ TILT_P: 15,
85
+ TILT_D: 3,
86
+ YAW_POS_P: 6,
87
+ YAW_VEL_P: 4,
88
+ VERT_POS_P: 9,
89
+ VERT_POS_D: 7,
90
+ HORIZ_POS_P: 5,
91
+ HORIZ_POS_D: 5.5,
92
+ HORIZ_VEL_P: 1,
93
+ VERT_VEL_P: 2
94
+ };
95
+ var getDriveRatio = (gearRatios, gearIndex, finalDriveRatio) => {
96
+ var _ref, _gearRatios$gearIndex;
97
+ return ((_ref = (_gearRatios$gearIndex = gearRatios[gearIndex]) !== null && _gearRatios$gearIndex !== void 0 ? _gearRatios$gearIndex : gearRatios[0]) !== null && _ref !== void 0 ? _ref : 0) * finalDriveRatio;
98
+ };
99
+ var getMaxWheelAngVel = (engineMaxRPM, driveRatio) => driveRatio !== 0 ? engineMaxRPM / driveRatio * (2 * Math.PI / 60) : 0;
100
+ var VehicleContext = (0, react.createContext)(null);
101
+ var EcctrlVehicle = /* @__PURE__ */ (0, react.forwardRef)(({ children, enable = true, carConfig = {}, droneConfig = {}, enableCustomGravity = false, gravityDirLerpSpeed = 6, ...props }, ref) => {
102
+ /**
103
+ * Rapier preset
104
+ */
105
+ const { rapier, world } = (0, _react_three_rapier.useRapier)();
106
+ /**
107
+ * Vehicle controls preset
108
+ */
109
+ const carControlConfig = (0, react.useMemo)(() => ({
110
+ ...DEFAULT_CAR_CONFIG,
111
+ ...carConfig
112
+ }), [carConfig]);
113
+ const droneControlConfig = (0, react.useMemo)(() => ({
114
+ ...DEFAULT_DRONE_CONFIG,
115
+ ...droneConfig
116
+ }), [droneConfig]);
117
+ /**
118
+ * Car controller preset
119
+ */
120
+ const engineMaxTorque = (0, react.useRef)(0);
121
+ engineMaxTorque.current = carControlConfig.engineMaxRPM !== 0 ? carControlConfig.engineHorsepower * 7022 / carControlConfig.engineMaxRPM : 0;
122
+ const gearRatios = Array.isArray(carControlConfig.gearRatios) && carControlConfig.gearRatios.length > 0 ? carControlConfig.gearRatios : DEFAULT_CAR_CONFIG.gearRatios;
123
+ const gearIndex = (0, react.useRef)(0);
124
+ gearIndex.current = (0, three_src_math_MathUtils_js.clamp)(Math.floor(gearIndex.current), 0, gearRatios.length - 1);
125
+ const driveRatio = (0, react.useRef)(getDriveRatio(gearRatios, gearIndex.current, carControlConfig.finalDriveRatio));
126
+ driveRatio.current = getDriveRatio(gearRatios, gearIndex.current, carControlConfig.finalDriveRatio);
127
+ const engineRPM = (0, react.useRef)(0);
128
+ const shiftCooldownTimer = (0, react.useRef)(0);
129
+ const engineTorqueCurve = (0, react.useMemo)(() => {
130
+ var _carControlConfig$eng;
131
+ return require_CurveLUT.bakeCurveLUT(carControlConfig.engineTorqueCurveData.points, (_carControlConfig$eng = carControlConfig.engineTorqueCurveData.samples) !== null && _carControlConfig$eng !== void 0 ? _carControlConfig$eng : 50);
132
+ }, [carControlConfig.engineTorqueCurveData]);
133
+ const steerAngleCurve = (0, react.useMemo)(() => {
134
+ var _carControlConfig$ste;
135
+ return require_CurveLUT.bakeCurveLUT(carControlConfig.steerAngleCurveData.points || [], (_carControlConfig$ste = carControlConfig.steerAngleCurveData.samples) !== null && _carControlConfig$ste !== void 0 ? _carControlConfig$ste : 50);
136
+ }, [carControlConfig.steerAngleCurveData]);
137
+ const maxWheelAngVel = (0, react.useRef)(getMaxWheelAngVel(carControlConfig.engineMaxRPM, driveRatio.current));
138
+ maxWheelAngVel.current = getMaxWheelAngVel(carControlConfig.engineMaxRPM, driveRatio.current);
139
+ const driveWheelConfig = (0, react.useRef)({
140
+ maxDriveTorque: 0,
141
+ maxWheelAngVel: maxWheelAngVel.current,
142
+ engineTorqueCurve,
143
+ reverseTorqueScale: carControlConfig.reverseTorqueScale,
144
+ reverseRPMScale: carControlConfig.reverseRPMScale,
145
+ driveRatio: driveRatio.current
146
+ });
147
+ driveWheelConfig.current.maxWheelAngVel = maxWheelAngVel.current;
148
+ driveWheelConfig.current.engineTorqueCurve = engineTorqueCurve;
149
+ driveWheelConfig.current.reverseTorqueScale = carControlConfig.reverseTorqueScale;
150
+ driveWheelConfig.current.reverseRPMScale = carControlConfig.reverseRPMScale;
151
+ driveWheelConfig.current.driveRatio = driveRatio.current;
152
+ const steerWheelConfig = (0, react.useRef)({
153
+ steerAngleCurve,
154
+ steerRate: carControlConfig.steerRate,
155
+ maxSteerAngle: carControlConfig.maxSteerAngle,
156
+ maxWheelAngVel: maxWheelAngVel.current
157
+ });
158
+ steerWheelConfig.current.steerAngleCurve = steerAngleCurve;
159
+ steerWheelConfig.current.steerRate = carControlConfig.steerRate;
160
+ steerWheelConfig.current.maxSteerAngle = carControlConfig.maxSteerAngle;
161
+ steerWheelConfig.current.maxWheelAngVel = maxWheelAngVel.current;
162
+ const syncTransmissionConfig = (0, react.useCallback)(() => {
163
+ driveRatio.current = getDriveRatio(gearRatios, gearIndex.current, carControlConfig.finalDriveRatio);
164
+ maxWheelAngVel.current = getMaxWheelAngVel(carControlConfig.engineMaxRPM, driveRatio.current);
165
+ driveWheelConfig.current.driveRatio = driveRatio.current;
166
+ driveWheelConfig.current.maxWheelAngVel = maxWheelAngVel.current;
167
+ steerWheelConfig.current.maxWheelAngVel = maxWheelAngVel.current;
168
+ }, [
169
+ carControlConfig.engineMaxRPM,
170
+ carControlConfig.finalDriveRatio,
171
+ gearRatios
172
+ ]);
173
+ /**
174
+ * Drone controller preset
175
+ */
176
+ const maxTiltTan = (0, react.useMemo)(() => Math.tan(droneControlConfig.maxTiltAngle), [droneControlConfig.maxTiltAngle]);
177
+ const hoverThrottle = (0, react.useRef)(0);
178
+ const targetUp = (0, react.useRef)(new three.Vector3());
179
+ const tiltError = (0, react.useRef)(new three.Vector3());
180
+ const tiltAngVel = (0, react.useRef)(new three.Vector3());
181
+ const torqueWorld = (0, react.useRef)(new three.Vector3());
182
+ const torqueBody = (0, react.useRef)(new three.Vector3());
183
+ const airDragImpulse = (0, react.useRef)(new three.Vector3());
184
+ const worldThrustDir = (0, react.useRef)(new three.Vector3());
185
+ const worldThrustPos = (0, react.useRef)(new three.Vector3());
186
+ const worldTorqueDir = (0, react.useRef)(new three.Vector3());
187
+ const targetPosition = (0, react.useRef)(new three.Vector3());
188
+ const targetHeading = (0, react.useRef)(new three.Vector3());
189
+ const targetFwd = (0, react.useRef)(new three.Vector3());
190
+ const currentFwd = (0, react.useRef)(new three.Vector3());
191
+ const posError = (0, react.useRef)(new three.Vector3());
192
+ const horizPosError = (0, react.useRef)(new three.Vector3());
193
+ const horizLinVel = (0, react.useRef)(new three.Vector3());
194
+ const horizForce = (0, react.useRef)(new three.Vector3());
195
+ const worldXAxis = (0, react.useRef)(new three.Vector3());
196
+ const worldZAxis = (0, react.useRef)(new three.Vector3());
197
+ const vertAccCmd = (0, react.useRef)(0);
198
+ const horizAccCmd = (0, react.useRef)(new three.Vector3());
199
+ const targetLinVel = (0, react.useRef)(new three.Vector3());
200
+ const linVelError = (0, react.useRef)(new three.Vector3());
201
+ /**
202
+ * Gravity controls preset
203
+ */
204
+ const gravityField = require_useCustomGravity.useCustomGravity((state) => state.gravityField);
205
+ const applyGravityField = require_useCustomGravity.useCustomGravity((state) => state.applyGravityField);
206
+ const upAxis = (0, react.useRef)(new three.Vector3());
207
+ const referenceGravity = (0, react.useRef)(new three.Vector3());
208
+ const referenceGravityMag = (0, react.useRef)(0);
209
+ const referenceGravityDir = (0, react.useRef)(new three.Vector3());
210
+ const gravityDir = (0, react.useRef)(new three.Vector3());
211
+ const slerpRef = (0, react.useRef)(require_Math.createSlerpVec3());
212
+ /**
213
+ * User controls setup
214
+ */
215
+ const movementState = (0, react.useRef)({
216
+ forward: false,
217
+ backward: false,
218
+ steerLeft: false,
219
+ steerRight: false,
220
+ brake: false,
221
+ throttleUp: false,
222
+ throttleDown: false,
223
+ yawLeft: false,
224
+ yawRight: false,
225
+ pitchForward: false,
226
+ pitchBackward: false,
227
+ rollLeft: false,
228
+ rollRight: false,
229
+ joystickL: {
230
+ x: 0,
231
+ y: 0
232
+ },
233
+ joystickR: {
234
+ x: 0,
235
+ y: 0
236
+ }
237
+ });
238
+ /**
239
+ * Vehicle collider/model preset
240
+ */
241
+ const vehicleRef = (0, react.useRef)(null);
242
+ const vehiclePos = (0, react.useRef)(new three.Vector3());
243
+ const vehicleQuat = (0, react.useRef)(new three.Quaternion());
244
+ const vehicleInvertQuat = (0, react.useRef)(new three.Quaternion());
245
+ const vehicleLinVel = (0, react.useRef)(new three.Vector3());
246
+ const vehicleAngVel = (0, react.useRef)(new three.Vector3());
247
+ const vehicleXAxis = (0, react.useRef)(new three.Vector3());
248
+ const vehicleYAxis = (0, react.useRef)(new three.Vector3());
249
+ const vehicleZAxis = (0, react.useRef)(new three.Vector3());
250
+ const setMovement = (0, react.useCallback)((movement) => {
251
+ if (movement.forward !== void 0) movementState.current.forward = movement.forward;
252
+ if (movement.backward !== void 0) movementState.current.backward = movement.backward;
253
+ if (movement.steerLeft !== void 0) movementState.current.steerLeft = movement.steerLeft;
254
+ if (movement.steerRight !== void 0) movementState.current.steerRight = movement.steerRight;
255
+ if (movement.brake !== void 0) movementState.current.brake = movement.brake;
256
+ if (movement.throttleUp !== void 0) movementState.current.throttleUp = movement.throttleUp;
257
+ if (movement.throttleDown !== void 0) movementState.current.throttleDown = movement.throttleDown;
258
+ if (movement.yawLeft !== void 0) movementState.current.yawLeft = movement.yawLeft;
259
+ if (movement.yawRight !== void 0) movementState.current.yawRight = movement.yawRight;
260
+ if (movement.pitchForward !== void 0) movementState.current.pitchForward = movement.pitchForward;
261
+ if (movement.pitchBackward !== void 0) movementState.current.pitchBackward = movement.pitchBackward;
262
+ if (movement.rollLeft !== void 0) movementState.current.rollLeft = movement.rollLeft;
263
+ if (movement.rollRight !== void 0) movementState.current.rollRight = movement.rollRight;
264
+ if (movement.joystickL) {
265
+ movementState.current.joystickL.x = movement.joystickL.x;
266
+ movementState.current.joystickL.y = movement.joystickL.y;
267
+ }
268
+ if (movement.joystickR) {
269
+ movementState.current.joystickR.x = movement.joystickR.x;
270
+ movementState.current.joystickR.y = movement.joystickR.y;
271
+ }
272
+ }, []);
273
+ const setTarget = (0, react.useCallback)((pos, dir) => {
274
+ if (pos) targetPosition.current.copy(pos);
275
+ if (dir) targetHeading.current.copy(dir);
276
+ }, []);
277
+ /**
278
+ * Register/unregister wheels information
279
+ */
280
+ const wheelsInfo = (0, react.useRef)(/* @__PURE__ */ new Map());
281
+ const syncWheelConfig = (0, react.useCallback)(() => {
282
+ let totalDriveTorqueWeight = 0;
283
+ wheelsInfo.current.forEach((wheelInfo) => {
284
+ var _wheelInfo$current$dr;
285
+ if (!wheelInfo.current.driveWheel) return;
286
+ totalDriveTorqueWeight += Math.max(0, (_wheelInfo$current$dr = wheelInfo.current.driveTorqueWeight) !== null && _wheelInfo$current$dr !== void 0 ? _wheelInfo$current$dr : 1);
287
+ });
288
+ wheelsInfo.current.forEach((wheelInfo) => {
289
+ var _wheelInfo$current$se2, _wheelInfo$current2;
290
+ if (wheelInfo.current.driveWheel) {
291
+ var _wheelInfo$current$dr2, _wheelInfo$current$se, _wheelInfo$current;
292
+ const driveTorqueWeight = Math.max(0, (_wheelInfo$current$dr2 = wheelInfo.current.driveTorqueWeight) !== null && _wheelInfo$current$dr2 !== void 0 ? _wheelInfo$current$dr2 : 1);
293
+ (_wheelInfo$current$se = (_wheelInfo$current = wheelInfo.current).setDriveWheelConfig) === null || _wheelInfo$current$se === void 0 || _wheelInfo$current$se.call(_wheelInfo$current, {
294
+ ...driveWheelConfig.current,
295
+ maxDriveTorque: totalDriveTorqueWeight > 0 ? engineMaxTorque.current * driveTorqueWeight / totalDriveTorqueWeight : 0
296
+ });
297
+ }
298
+ if (wheelInfo.current.steerWheel) (_wheelInfo$current$se2 = (_wheelInfo$current2 = wheelInfo.current).setSteerWheelConfig) === null || _wheelInfo$current$se2 === void 0 || _wheelInfo$current$se2.call(_wheelInfo$current2, steerWheelConfig.current);
299
+ });
300
+ }, []);
301
+ const regWheel = (0, react.useCallback)((wheelInfo) => {
302
+ const id = wheelInfo.current.id;
303
+ if (!wheelsInfo.current.has(id)) {
304
+ wheelsInfo.current.set(id, wheelInfo);
305
+ syncWheelConfig();
306
+ }
307
+ }, [syncWheelConfig]);
308
+ const unregWheel = (0, react.useCallback)((id) => {
309
+ if (wheelsInfo.current.delete(id)) syncWheelConfig();
310
+ }, [syncWheelConfig]);
311
+ const setGear = (0, react.useCallback)((index) => {
312
+ const nextGearIndex = (0, three_src_math_MathUtils_js.clamp)(Math.floor(index), 0, gearRatios.length - 1);
313
+ if (gearIndex.current === nextGearIndex) return;
314
+ gearIndex.current = nextGearIndex;
315
+ shiftCooldownTimer.current = carControlConfig.shiftCooldown;
316
+ syncTransmissionConfig();
317
+ syncWheelConfig();
318
+ }, [
319
+ carControlConfig.shiftCooldown,
320
+ gearRatios.length,
321
+ syncTransmissionConfig,
322
+ syncWheelConfig
323
+ ]);
324
+ (0, react.useEffect)(() => {
325
+ syncTransmissionConfig();
326
+ syncWheelConfig();
327
+ }, [
328
+ carControlConfig.engineHorsepower,
329
+ carControlConfig.engineMaxRPM,
330
+ carControlConfig.finalDriveRatio,
331
+ carControlConfig.maxSteerAngle,
332
+ carControlConfig.reverseRPMScale,
333
+ carControlConfig.reverseTorqueScale,
334
+ carControlConfig.steerRate,
335
+ engineTorqueCurve,
336
+ gearRatios,
337
+ steerAngleCurve,
338
+ syncTransmissionConfig,
339
+ syncWheelConfig
340
+ ]);
341
+ /**
342
+ * Register/unregister propellers information
343
+ */
344
+ const propellersInfo = (0, react.useRef)(/* @__PURE__ */ new Map());
345
+ const regPropeller = (0, react.useCallback)((propellerInfo) => {
346
+ const id = propellerInfo.current.id;
347
+ if (!propellersInfo.current.has(id)) propellersInfo.current.set(id, propellerInfo);
348
+ }, []);
349
+ const unregPropeller = (0, react.useCallback)((id) => propellersInfo.current.delete(id), []);
350
+ /**
351
+ * Expose vehicle info and control functions to children via ref and context
352
+ */
353
+ (0, react.useImperativeHandle)(ref, () => ({
354
+ get body() {
355
+ return vehicleRef.current;
356
+ },
357
+ get upAxis() {
358
+ return upAxis.current;
359
+ },
360
+ get gravityDir() {
361
+ return gravityDir.current;
362
+ },
363
+ get gravityMag() {
364
+ return referenceGravityMag.current;
365
+ },
366
+ get currPos() {
367
+ return vehiclePos.current;
368
+ },
369
+ get currQuat() {
370
+ return vehicleQuat.current;
371
+ },
372
+ get currLinVel() {
373
+ return vehicleLinVel.current;
374
+ },
375
+ get currAngVel() {
376
+ return vehicleAngVel.current;
377
+ },
378
+ get bodyXAxis() {
379
+ return vehicleXAxis.current;
380
+ },
381
+ get bodyYAxis() {
382
+ return vehicleYAxis.current;
383
+ },
384
+ get bodyZAxis() {
385
+ return vehicleZAxis.current;
386
+ },
387
+ get targetPos() {
388
+ return targetPosition.current;
389
+ },
390
+ get targetFwd() {
391
+ return targetHeading.current;
392
+ },
393
+ get input() {
394
+ return movementState.current;
395
+ },
396
+ get wheelsInfo() {
397
+ return wheelsInfo.current;
398
+ },
399
+ get propellersInfo() {
400
+ return propellersInfo.current;
401
+ },
402
+ get gearIndex() {
403
+ return gearIndex.current;
404
+ },
405
+ get driveRatio() {
406
+ return driveRatio.current;
407
+ },
408
+ get engineRPM() {
409
+ return engineRPM.current;
410
+ },
411
+ setMovement,
412
+ setTarget,
413
+ setGear
414
+ }), [
415
+ setGear,
416
+ setMovement,
417
+ setTarget
418
+ ]);
419
+ /**
420
+ *
421
+ *
422
+ *
423
+ *
424
+ *
425
+ *
426
+ *
427
+ *
428
+ *
429
+ *
430
+ *
431
+ *
432
+ *
433
+ *
434
+ *
435
+ *
436
+ *
437
+ *
438
+ *
439
+ *
440
+ *
441
+ *
442
+ *
443
+ *
444
+ *
445
+ */
446
+ /**
447
+ * Update vehicle info function
448
+ */
449
+ const updateVehicleInfo = (0, react.useCallback)((body) => {
450
+ vehiclePos.current.copy(body.translation());
451
+ vehicleQuat.current.copy(body.rotation());
452
+ vehicleInvertQuat.current.copy(vehicleQuat.current).invert();
453
+ vehicleLinVel.current.copy(body.linvel());
454
+ vehicleAngVel.current.copy(body.angvel());
455
+ vehicleYAxis.current.set(0, 1, 0).applyQuaternion(vehicleQuat.current);
456
+ vehicleXAxis.current.set(1, 0, 0).applyQuaternion(vehicleQuat.current);
457
+ vehicleZAxis.current.set(0, 0, 1).applyQuaternion(vehicleQuat.current);
458
+ }, []);
459
+ /**
460
+ * Update gravity/upAxis direction and value
461
+ */
462
+ const updateGravityInfo = (0, react.useCallback)((body) => {
463
+ if (enableCustomGravity) {
464
+ referenceGravity.current.copy(gravityField(vehiclePos.current));
465
+ applyGravityField(body, world.timestep);
466
+ } else referenceGravity.current.copy(world.gravity);
467
+ referenceGravityMag.current = referenceGravity.current.length();
468
+ referenceGravityDir.current.copy(referenceGravity.current).normalize();
469
+ if (referenceGravityDir.current.lengthSq() === 0) referenceGravityDir.current.copy(vehicleYAxis.current).negate();
470
+ gravityDir.current.copy(slerpRef.current(gravityDir.current, referenceGravityDir.current, 1 - Math.exp(-gravityDirLerpSpeed * world.timestep), vehicleZAxis.current));
471
+ upAxis.current.copy(gravityDir.current).negate();
472
+ }, [
473
+ enableCustomGravity,
474
+ gravityDirLerpSpeed,
475
+ gravityField,
476
+ applyGravityField
477
+ ]);
478
+ /**
479
+ *
480
+ *
481
+ *
482
+ *
483
+ *
484
+ *
485
+ *
486
+ *
487
+ *
488
+ *
489
+ *
490
+ *
491
+ *
492
+ *
493
+ *
494
+ *
495
+ *
496
+ *
497
+ *
498
+ *
499
+ *
500
+ *
501
+ *
502
+ *
503
+ *
504
+ */
505
+ /**
506
+ * Car overall control logics
507
+ */
508
+ const updateTransmission = (0, react.useCallback)((wheels) => {
509
+ let totalWheelRPM = 0;
510
+ let totalDriveTorqueWeight = 0;
511
+ wheels.forEach((wheel) => {
512
+ var _wheel$current$driveT;
513
+ if (!wheel.current.driveWheel) return;
514
+ const driveTorqueWeight = Math.max(0, (_wheel$current$driveT = wheel.current.driveTorqueWeight) !== null && _wheel$current$driveT !== void 0 ? _wheel$current$driveT : 1);
515
+ totalWheelRPM += Math.abs(wheel.current.wheelAngVel) * 60 / (Math.PI * 2) * driveTorqueWeight;
516
+ totalDriveTorqueWeight += driveTorqueWeight;
517
+ });
518
+ engineRPM.current = (totalDriveTorqueWeight > 0 ? totalWheelRPM / totalDriveTorqueWeight : 0) * Math.abs(driveRatio.current);
519
+ if (carControlConfig.transmissionMode !== "auto" || gearRatios.length <= 1) return;
520
+ if (shiftCooldownTimer.current > 0) {
521
+ shiftCooldownTimer.current = Math.max(0, shiftCooldownTimer.current - world.timestep);
522
+ return;
523
+ }
524
+ if (engineRPM.current > carControlConfig.shiftUpRPM && gearIndex.current < gearRatios.length - 1) setGear(gearIndex.current + 1);
525
+ else if (engineRPM.current < carControlConfig.shiftDownRPM && gearIndex.current > 0) setGear(gearIndex.current - 1);
526
+ }, [
527
+ carControlConfig.shiftDownRPM,
528
+ carControlConfig.shiftUpRPM,
529
+ carControlConfig.transmissionMode,
530
+ gearRatios.length,
531
+ setGear,
532
+ world.timestep
533
+ ]);
534
+ const velocityBasedCarControl = (0, react.useCallback)((input, wheels) => {
535
+ var _input$joystickL$x, _input$joystickL;
536
+ const driveIn = (0, three_src_math_MathUtils_js.clamp)((input.forward ? 1 : 0) - (input.backward ? 1 : 0), -1, 1);
537
+ const steerIn = (0, three_src_math_MathUtils_js.clamp)((input.steerLeft ? 1 : 0) - (input.steerRight ? 1 : 0) - ((_input$joystickL$x = (_input$joystickL = input.joystickL) === null || _input$joystickL === void 0 ? void 0 : _input$joystickL.x) !== null && _input$joystickL$x !== void 0 ? _input$joystickL$x : 0), -1, 1);
538
+ const brakeIn = input.brake ? 1 : 0;
539
+ wheels.forEach((wheel) => {
540
+ if (wheel.current.driveWheel && wheel.current.setDriveDemand) wheel.current.setDriveDemand(driveIn);
541
+ if (wheel.current.brakeWheel && wheel.current.setBrakeDemand) wheel.current.setBrakeDemand(brakeIn);
542
+ if (wheel.current.steerWheel && wheel.current.setSteerDemand) wheel.current.setSteerDemand(steerIn);
543
+ });
544
+ }, []);
545
+ const applyWheelImpulse = (0, react.useCallback)((wheels, body) => {
546
+ if (!body) return;
547
+ if (body.isSleeping()) {
548
+ let shouldWake = false;
549
+ for (const wheel of wheels.values()) {
550
+ const w = wheel.current;
551
+ if (!w.rayHit) continue;
552
+ if (w.isOnPlatform || Math.abs(w.wheelLinVel) > 1e-4) {
553
+ shouldWake = true;
554
+ break;
555
+ }
556
+ }
557
+ if (!shouldWake) return;
558
+ body.wakeUp();
559
+ return;
560
+ }
561
+ wheels.forEach((wheel) => {
562
+ if (!wheel.current.rayHit) return;
563
+ body.applyImpulseAtPoint(wheel.current.floatImp, wheel.current.supPos, false);
564
+ body.applyImpulseAtPoint(wheel.current.lngFricImp, wheel.current.rayHitPos, false);
565
+ body.applyImpulseAtPoint(wheel.current.latFricImp, wheel.current.rayHitPos, false);
566
+ });
567
+ }, []);
568
+ const applyCarControl = (0, react.useCallback)((wheels, body, input) => {
569
+ if (!body) return;
570
+ updateTransmission(wheels);
571
+ velocityBasedCarControl(input, wheels);
572
+ applyWheelImpulse(wheels, body);
573
+ }, [
574
+ applyWheelImpulse,
575
+ updateTransmission,
576
+ velocityBasedCarControl
577
+ ]);
578
+ /**
579
+ *
580
+ *
581
+ *
582
+ *
583
+ *
584
+ *
585
+ *
586
+ *
587
+ *
588
+ *
589
+ *
590
+ *
591
+ *
592
+ *
593
+ *
594
+ *
595
+ *
596
+ *
597
+ *
598
+ *
599
+ *
600
+ *
601
+ *
602
+ *
603
+ *
604
+ *
605
+ */
606
+ /**
607
+ * Drone overall control logics
608
+ */
609
+ const propellerPotential = (0, react.useRef)({
610
+ sumLX: 0,
611
+ sumLY: 0,
612
+ sumLZ: 0,
613
+ sumAX: 0,
614
+ sumAY: 0,
615
+ sumAZ: 0
616
+ });
617
+ const computePropellerPotential = (0, react.useCallback)((propellers) => {
618
+ let sumLX = 0, sumLY = 0, sumLZ = 0;
619
+ let sumAX = 0, sumAY = 0, sumAZ = 0;
620
+ propellers.forEach((p) => {
621
+ sumLX += p.current.lx;
622
+ sumLY += p.current.ly;
623
+ sumLZ += p.current.lz;
624
+ sumAX += Math.abs(p.current.ax);
625
+ sumAY += Math.abs(p.current.ay);
626
+ sumAZ += Math.abs(p.current.az);
627
+ });
628
+ propellerPotential.current.sumLX = sumLX;
629
+ propellerPotential.current.sumLY = sumLY;
630
+ propellerPotential.current.sumLZ = sumLZ;
631
+ propellerPotential.current.sumAX = sumAX;
632
+ propellerPotential.current.sumAY = sumAY;
633
+ propellerPotential.current.sumAZ = sumAZ;
634
+ }, []);
635
+ const positionBasedDroneControl = (0, react.useCallback)((weight, sumWorldLY) => {
636
+ posError.current.subVectors(targetPosition.current, vehiclePos.current);
637
+ const vertPosErrorMag = posError.current.dot(upAxis.current);
638
+ horizPosError.current.copy(posError.current).projectOnPlane(upAxis.current);
639
+ const vertLinVelMag = vehicleLinVel.current.dot(upAxis.current);
640
+ horizLinVel.current.copy(vehicleLinVel.current).projectOnPlane(upAxis.current);
641
+ const vertForceMag = weight + (0, three_src_math_MathUtils_js.clamp)(vertPosErrorMag * droneControlConfig.VERT_POS_P, -droneControlConfig.VERT_POS_D * droneControlConfig.maxVertSpeed, droneControlConfig.VERT_POS_D * droneControlConfig.maxVertSpeed) - vertLinVelMag * droneControlConfig.VERT_POS_D;
642
+ hoverThrottle.current = Math.max(0, vertForceMag / (sumWorldLY || 1));
643
+ horizForce.current.set(0, 0, 0).addScaledVector(horizPosError.current, droneControlConfig.HORIZ_POS_P).addScaledVector(horizLinVel.current, -droneControlConfig.HORIZ_POS_D).clampLength(0, droneControlConfig.HORIZ_POS_D * droneControlConfig.maxHorizSpeed);
644
+ targetUp.current.copy(upAxis.current).multiplyScalar(weight).add(horizForce.current.clampLength(0, weight * maxTiltTan)).normalize();
645
+ tiltError.current.crossVectors(vehicleYAxis.current, targetUp.current);
646
+ tiltAngVel.current.copy(vehicleAngVel.current).projectOnPlane(upAxis.current);
647
+ targetFwd.current.copy(targetHeading.current).projectOnPlane(upAxis.current).normalize();
648
+ currentFwd.current.copy(vehicleZAxis.current).projectOnPlane(upAxis.current).normalize();
649
+ const yawError = targetFwd.current.angleTo(currentFwd.current) * Math.sign(currentFwd.current.cross(targetFwd.current).dot(upAxis.current));
650
+ const currentYawRate = vehicleAngVel.current.dot(upAxis.current);
651
+ const yawRateError = (0, three_src_math_MathUtils_js.clamp)(yawError * droneControlConfig.YAW_POS_P, -droneControlConfig.maxYawRate, droneControlConfig.maxYawRate) - currentYawRate;
652
+ torqueWorld.current.set(0, 0, 0).addScaledVector(tiltError.current, droneControlConfig.TILT_P).addScaledVector(tiltAngVel.current, -droneControlConfig.TILT_D).addScaledVector(upAxis.current, yawRateError * droneControlConfig.YAW_VEL_P);
653
+ torqueBody.current.copy(torqueWorld.current).applyQuaternion(vehicleInvertQuat.current);
654
+ }, [droneControlConfig, maxTiltTan]);
655
+ const velocityBasedDroneControl = (0, react.useCallback)((input, body, weight, sumWorldLY) => {
656
+ var _input$joystickL$y, _input$joystickL2, _input$joystickL$x2, _input$joystickL3, _input$joystickR$y, _input$joystickR, _input$joystickR$x, _input$joystickR2;
657
+ const throttleIn = (0, three_src_math_MathUtils_js.clamp)((input.throttleUp ? 1 : 0) - (input.throttleDown ? 1 : 0) + ((_input$joystickL$y = (_input$joystickL2 = input.joystickL) === null || _input$joystickL2 === void 0 ? void 0 : _input$joystickL2.y) !== null && _input$joystickL$y !== void 0 ? _input$joystickL$y : 0), -1, 1);
658
+ const yawIn = (0, three_src_math_MathUtils_js.clamp)((input.yawLeft ? 1 : 0) - (input.yawRight ? 1 : 0) - ((_input$joystickL$x2 = (_input$joystickL3 = input.joystickL) === null || _input$joystickL3 === void 0 ? void 0 : _input$joystickL3.x) !== null && _input$joystickL$x2 !== void 0 ? _input$joystickL$x2 : 0), -1, 1);
659
+ const pitchIn = (0, three_src_math_MathUtils_js.clamp)((input.pitchForward ? 1 : 0) - (input.pitchBackward ? 1 : 0) + ((_input$joystickR$y = (_input$joystickR = input.joystickR) === null || _input$joystickR === void 0 ? void 0 : _input$joystickR.y) !== null && _input$joystickR$y !== void 0 ? _input$joystickR$y : 0), -1, 1);
660
+ const rollIn = (0, three_src_math_MathUtils_js.clamp)((input.rollRight ? 1 : 0) - (input.rollLeft ? 1 : 0) + ((_input$joystickR$x = (_input$joystickR2 = input.joystickR) === null || _input$joystickR2 === void 0 ? void 0 : _input$joystickR2.x) !== null && _input$joystickR$x !== void 0 ? _input$joystickR$x : 0), -1, 1);
661
+ worldXAxis.current.copy(vehicleXAxis.current).projectOnPlane(upAxis.current).normalize();
662
+ worldZAxis.current.copy(vehicleZAxis.current).projectOnPlane(upAxis.current).normalize();
663
+ targetLinVel.current.set(0, 0, 0).addScaledVector(worldXAxis.current, -rollIn * droneControlConfig.maxHorizSpeed).addScaledVector(worldZAxis.current, pitchIn * droneControlConfig.maxHorizSpeed).addScaledVector(upAxis.current, throttleIn * droneControlConfig.maxVertSpeed);
664
+ linVelError.current.subVectors(targetLinVel.current, vehicleLinVel.current);
665
+ vertAccCmd.current = (0, three_src_math_MathUtils_js.clamp)(linVelError.current.dot(upAxis.current) * droneControlConfig.VERT_VEL_P, -referenceGravityMag.current, referenceGravityMag.current);
666
+ horizAccCmd.current.copy(linVelError.current).projectOnPlane(upAxis.current).multiplyScalar(droneControlConfig.HORIZ_VEL_P).clampLength(0, referenceGravityMag.current * maxTiltTan);
667
+ const verticalForceMag = weight + vertAccCmd.current * body.mass();
668
+ hoverThrottle.current = Math.max(0, verticalForceMag / (sumWorldLY || 1));
669
+ targetUp.current.copy(upAxis.current).multiplyScalar(referenceGravityMag.current).add(horizAccCmd.current).normalize();
670
+ tiltError.current.crossVectors(vehicleYAxis.current, targetUp.current);
671
+ tiltAngVel.current.copy(vehicleAngVel.current).projectOnPlane(upAxis.current);
672
+ const currentYawRate = vehicleAngVel.current.dot(upAxis.current);
673
+ const yawRateError = yawIn * droneControlConfig.maxYawRate - currentYawRate;
674
+ torqueWorld.current.set(0, 0, 0).addScaledVector(tiltError.current, droneControlConfig.TILT_P).addScaledVector(tiltAngVel.current, -droneControlConfig.TILT_D).addScaledVector(upAxis.current, yawRateError * droneControlConfig.YAW_VEL_P);
675
+ torqueBody.current.copy(torqueWorld.current).applyQuaternion(vehicleInvertQuat.current);
676
+ }, [droneControlConfig, maxTiltTan]);
677
+ const computePropellerFinalThrottle = (0, react.useCallback)((propeller, maxSafeMix) => {
678
+ const mix = torqueBody.current.x * propeller.ax / (propellerPotential.current.sumAX || 1) + torqueBody.current.z * propeller.az / (propellerPotential.current.sumAZ || 1) + torqueBody.current.y * propeller.ay / (propellerPotential.current.sumAY || 1);
679
+ return (0, three_src_math_MathUtils_js.clamp)(hoverThrottle.current + (0, three_src_math_MathUtils_js.clamp)(mix, -maxSafeMix, maxSafeMix), 0, 1);
680
+ }, []);
681
+ const applyMixerImpulse = (0, react.useCallback)((propellers, body) => {
682
+ const maxSafeMix = Math.min(1 - hoverThrottle.current, hoverThrottle.current);
683
+ if (body.isSleeping()) {
684
+ let shouldWake = false;
685
+ for (const propeller of propellers.values()) {
686
+ const info = propeller.current;
687
+ const finalThrottle = computePropellerFinalThrottle(info, maxSafeMix);
688
+ if (Math.abs(finalThrottle - info.throttle) > 1e-4) {
689
+ shouldWake = true;
690
+ break;
691
+ }
692
+ }
693
+ if (!shouldWake) return;
694
+ body.wakeUp();
695
+ }
696
+ propellers.forEach((propeller) => {
697
+ const info = propeller.current;
698
+ const finalThrottle = computePropellerFinalThrottle(info, maxSafeMix);
699
+ info.finalThrottle = finalThrottle;
700
+ if (info.setThrottle) info.setThrottle(finalThrottle);
701
+ worldThrustDir.current.copy(info.thrustDir).applyQuaternion(vehicleQuat.current).normalize();
702
+ worldThrustPos.current.copy(info.thrustPos).applyQuaternion(vehicleQuat.current).add(vehiclePos.current);
703
+ worldTorqueDir.current.copy(info.torqueDir).applyQuaternion(vehicleQuat.current).normalize();
704
+ info.worldThrustDir.copy(worldThrustDir.current);
705
+ info.worldThrustPos.copy(worldThrustPos.current);
706
+ info.worldTorqueDir.copy(worldTorqueDir.current);
707
+ info.thrustImpulse.copy(worldThrustDir.current).multiplyScalar(info.maxThrust * finalThrottle * world.timestep);
708
+ info.torqueImpulse.copy(worldTorqueDir.current).multiplyScalar(info.maxThrust * finalThrottle * world.timestep * info.torqueRatio);
709
+ body.applyImpulseAtPoint(info.thrustImpulse, info.worldThrustPos, false);
710
+ body.applyTorqueImpulse(info.torqueImpulse, false);
711
+ });
712
+ }, [computePropellerFinalThrottle]);
713
+ const applyAirDrag = (0, react.useCallback)((body) => {
714
+ airDragImpulse.current.copy(vehicleLinVel.current).multiplyScalar(-droneControlConfig.airDragFactor * world.timestep);
715
+ body.applyImpulse(airDragImpulse.current, false);
716
+ }, [droneControlConfig.airDragFactor, world.timestep]);
717
+ const applyDroneControl = (0, react.useCallback)((propellers, body, input) => {
718
+ if (!body) return;
719
+ computePropellerPotential(propellers);
720
+ const sumWorldLY = propellerPotential.current.sumLX * vehicleXAxis.current.dot(upAxis.current) + propellerPotential.current.sumLY * vehicleYAxis.current.dot(upAxis.current) + propellerPotential.current.sumLZ * vehicleZAxis.current.dot(upAxis.current);
721
+ const weight = body.mass() * referenceGravityMag.current;
722
+ switch (droneControlConfig.controlMode) {
723
+ case "POSITION":
724
+ positionBasedDroneControl(weight, sumWorldLY);
725
+ break;
726
+ case "VELOCITY":
727
+ velocityBasedDroneControl(input, body, weight, sumWorldLY);
728
+ break;
729
+ }
730
+ applyMixerImpulse(propellers, body);
731
+ applyAirDrag(body);
732
+ }, [
733
+ computePropellerPotential,
734
+ positionBasedDroneControl,
735
+ velocityBasedDroneControl,
736
+ droneControlConfig.controlMode,
737
+ applyMixerImpulse,
738
+ applyAirDrag
739
+ ]);
740
+ /**
741
+ *
742
+ *
743
+ *
744
+ *
745
+ *
746
+ *
747
+ *
748
+ *
749
+ *
750
+ *
751
+ *
752
+ *
753
+ *
754
+ *
755
+ *
756
+ *
757
+ *
758
+ *
759
+ *
760
+ */
761
+ (0, _react_three_fiber.useFrame)(() => {
762
+ if (!enable || !vehicleRef.current) return;
763
+ /**
764
+ * Update when character is not sleeping
765
+ */
766
+ if (!vehicleRef.current.isSleeping()) {
767
+ updateVehicleInfo(vehicleRef.current);
768
+ updateGravityInfo(vehicleRef.current);
769
+ }
770
+ /**
771
+ * Apply drive/brake/friction impulse from shape cast wheels
772
+ * whenever there is a wheel component
773
+ */
774
+ if (wheelsInfo.current.size > 0) applyCarControl(wheelsInfo.current, vehicleRef.current, movementState.current);
775
+ /**
776
+ * Apply drone control logics
777
+ * whenever there is a propeller component
778
+ */
779
+ if (propellersInfo.current.size > 0) applyDroneControl(propellersInfo.current, vehicleRef.current, movementState.current);
780
+ });
781
+ /**
782
+ *
783
+ *
784
+ *
785
+ *
786
+ *
787
+ *
788
+ *
789
+ *
790
+ *
791
+ *
792
+ *
793
+ *
794
+ */
795
+ const vehicleContextValue = (0, react.useMemo)(() => ({
796
+ body: vehicleRef,
797
+ upAxis,
798
+ gravityDir,
799
+ gravityMag: referenceGravityMag,
800
+ currPos: vehiclePos,
801
+ currQuat: vehicleQuat,
802
+ currLinvel: vehicleLinVel,
803
+ currAngvel: vehicleAngVel,
804
+ bodyXAxis: vehicleXAxis,
805
+ bodyYAxis: vehicleYAxis,
806
+ bodyZAxis: vehicleZAxis,
807
+ movementState,
808
+ wheelsInfo,
809
+ propellersInfo,
810
+ regWheel,
811
+ unregWheel,
812
+ regPropeller,
813
+ unregPropeller
814
+ }), [
815
+ regWheel,
816
+ unregWheel,
817
+ regPropeller,
818
+ unregPropeller
819
+ ]);
820
+ return /* @__PURE__ */ react.default.createElement(VehicleContext.Provider, { value: vehicleContextValue }, /* @__PURE__ */ react.default.createElement(_react_three_rapier.RigidBody, {
821
+ colliders: false,
822
+ ref: vehicleRef,
823
+ ...props
824
+ }, children));
825
+ });
826
+ var EcctrlVehicle_default = react.default.memo(EcctrlVehicle);
827
+ //#endregion
828
+ //#region src/vehicles/components/ShapeCastWheel.tsx
829
+ /*!
830
+ * Ecctrl
831
+ * https://github.com/pmndrs/ecctrl
832
+ *
833
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
834
+ * SPDX-License-Identifier: MIT
835
+ */
836
+ var ShapeCastWheel = /* @__PURE__ */ (0, react.forwardRef)(({ children, debug = false, enable = true, name = "", groundDetection = "shapeCast", rayShapeR = .5, rayShapeH = .15, rayLength = .5, springK = 180, dampingC = 16, driveInvert = false, driveWheel = false, driveTorqueWeight = 1, steerInvert = false, steerWheel = false, brakeWheel = false, maxBrakeTorque = 40, rollingResistanceCoef = .007, lowVelThreshold = .4, tireGripFactor = 1.5, lngFrictionEllipseScale = 1, latFrictionEllipseScale = 1, relaxLngRate = .05, relaxLatRate = .1, minLngRelaxCoeff = .3, minLatRelaxCoeff = .3, lngSlipRatioCurveData = { points: [
837
+ {
838
+ x: 0,
839
+ y: 0,
840
+ r_out: 1.45
841
+ },
842
+ {
843
+ x: .25,
844
+ y: 1,
845
+ r_in: 0,
846
+ r_out: 0
847
+ },
848
+ {
849
+ x: 1,
850
+ y: .7,
851
+ r_in: 0
852
+ }
853
+ ] }, latSlipRatioCurveData = { points: [
854
+ {
855
+ x: 0,
856
+ y: 0,
857
+ r_out: 1.45
858
+ },
859
+ {
860
+ x: .15,
861
+ y: 1,
862
+ r_in: 0,
863
+ r_out: 0
864
+ },
865
+ {
866
+ x: 1,
867
+ y: .9,
868
+ r_in: 0
869
+ }
870
+ ] }, followPlatform = true, massRatioFallOffCurveData = { points: [
871
+ {
872
+ x: 0,
873
+ y: .5,
874
+ r_out: 0
875
+ },
876
+ {
877
+ x: .5,
878
+ y: 1,
879
+ r_out: 0
880
+ },
881
+ {
882
+ x: 1,
883
+ y: 1,
884
+ r_in: 0
885
+ }
886
+ ] }, applyCounterMass = true, applyCounterFriction = true, showWheelModel = true, wheelModelDensity = 1.5, wheelModelUpdate = true, wheelModelRadius = .5, wheelModelLerpPosRate = 10, wheelModelReversRotation = false, debuggerArrowScale = 10, ...props }, ref) => {
887
+ /**
888
+ * Rapier preset
889
+ */
890
+ const { rapier, world } = (0, _react_three_rapier.useRapier)();
891
+ /**
892
+ * Retrieve context object from ecctrl vehicle
893
+ */
894
+ const vehicleValue = (0, react.useContext)(VehicleContext);
895
+ const fixedScale = (0, react.useMemo)(() => new three.Vector3(1, 1, 1), []);
896
+ (0, react.useMemo)(() => new three.Vector3(0, 0, 0), []);
897
+ (0, react.useMemo)(() => new three.Vector3(1, 0, 0), []);
898
+ (0, react.useMemo)(() => new three.Vector3(0, 1, 0), []);
899
+ const fixedZAxis = (0, react.useMemo)(() => new three.Vector3(0, 0, 1), []);
900
+ const vehiclePos = (0, react.useRef)(new three.Vector3());
901
+ const vehicleQuat = (0, react.useRef)(new three.Quaternion());
902
+ const vehicleInvertQuat = (0, react.useRef)(new three.Quaternion());
903
+ const vehicleMatrix = (0, react.useRef)(new three.Matrix4());
904
+ const vehicleInvertMatrix = (0, react.useRef)(new three.Matrix4());
905
+ const vehicleLinVel = (0, react.useRef)(new three.Vector3());
906
+ const vehicleAngVel = (0, react.useRef)(new three.Vector3());
907
+ const vehicleXAxis = (0, react.useRef)(new three.Vector3());
908
+ const vehicleYAxis = (0, react.useRef)(new three.Vector3());
909
+ const vehicleZAxis = (0, react.useRef)(new three.Vector3());
910
+ /**
911
+ * Wheel physical properties and states
912
+ */
913
+ const effectiveInertia = (0, react.useRef)(0);
914
+ const wheelAngVel = (0, react.useRef)(0);
915
+ const supportPoint = (0, react.useRef)(new three.Vector3());
916
+ const wheelVolume = (0, react.useMemo)(() => Math.PI * rayShapeR * rayShapeR * (rayShapeH * 2), [rayShapeR, rayShapeH]);
917
+ const wheelMass = (0, react.useMemo)(() => wheelModelDensity * wheelVolume, [wheelModelDensity, wheelVolume]);
918
+ const wheelInertia = (0, react.useMemo)(() => .5 * wheelMass * rayShapeR * rayShapeR, [wheelMass, rayShapeR]);
919
+ /**
920
+ * Control preset
921
+ */
922
+ const frictionCoef = (0, react.useRef)(0);
923
+ const lngAxis = (0, react.useRef)(new three.Vector3());
924
+ const latAxis = (0, react.useRef)(new three.Vector3());
925
+ const lngFrictionImp = (0, react.useRef)(new three.Vector3());
926
+ const latFrictionImp = (0, react.useRef)(new three.Vector3());
927
+ const lngSlipRatioCurve = (0, react.useMemo)(() => {
928
+ var _lngSlipRatioCurveDat;
929
+ return require_CurveLUT.bakeCurveLUT(lngSlipRatioCurveData.points, (_lngSlipRatioCurveDat = lngSlipRatioCurveData.samples) !== null && _lngSlipRatioCurveDat !== void 0 ? _lngSlipRatioCurveDat : 50);
930
+ }, [lngSlipRatioCurveData]);
931
+ const latSlipRatioCurve = (0, react.useMemo)(() => {
932
+ var _latSlipRatioCurveDat;
933
+ return require_CurveLUT.bakeCurveLUT(latSlipRatioCurveData.points, (_latSlipRatioCurveDat = latSlipRatioCurveData.samples) !== null && _latSlipRatioCurveDat !== void 0 ? _latSlipRatioCurveDat : 50);
934
+ }, [latSlipRatioCurveData]);
935
+ const lngSlipRatio = (0, react.useRef)(0);
936
+ const latSlipRatio = (0, react.useRef)(0);
937
+ const slipStrength = (0, react.useRef)(0);
938
+ const smoothedLngImpulse = (0, react.useRef)(0);
939
+ const smoothedLatImpulse = (0, react.useRef)(0);
940
+ const desiredLngImpulse = (0, react.useRef)(0);
941
+ const desiredLatImpulse = (0, react.useRef)(0);
942
+ const steerAngle = (0, react.useRef)(0);
943
+ const steerTarget = (0, react.useRef)(0);
944
+ const steerIncrement = (0, react.useRef)(0);
945
+ const steerDemand = (0, react.useRef)(0);
946
+ const steerWheelConfig = (0, react.useRef)(null);
947
+ const setSteerDemand = (0, react.useCallback)((value) => steerDemand.current = value, []);
948
+ const setSteerWheelConfig = (0, react.useCallback)((value) => steerWheelConfig.current = value, []);
949
+ const driveTorque = (0, react.useRef)(0);
950
+ const driveDemand = (0, react.useRef)(0);
951
+ const driveWheelConfig = (0, react.useRef)(null);
952
+ const setDriveDemand = (0, react.useCallback)((value) => driveDemand.current = value, []);
953
+ const setDriveWheelConfig = (0, react.useCallback)((value) => driveWheelConfig.current = value, []);
954
+ const brakeTorque = (0, react.useRef)(0);
955
+ const brakeDemand = (0, react.useRef)(0);
956
+ const setBrakeDemand = (0, react.useCallback)((value) => brakeDemand.current = value, []);
957
+ /**
958
+ * Shape cast preset
959
+ */
960
+ const distFromRayOriginToVehicle = (0, react.useRef)(new three.Vector3());
961
+ const angvelToLinvel = (0, react.useRef)(new three.Vector3());
962
+ const floatingImpulse = (0, react.useRef)(new three.Vector3());
963
+ const rayOrigin = (0, react.useRef)(new three.Vector3());
964
+ const rayRotation = (0, react.useRef)(new three.Quaternion());
965
+ const rayDirection = (0, react.useRef)(new three.Vector3());
966
+ const rayOriginVel = (0, react.useRef)(new three.Vector3());
967
+ const rayUpAxis = (0, react.useRef)(new three.Vector3());
968
+ const rayFWDAxis = (0, react.useRef)(new three.Vector3());
969
+ const rayBWDAxis = (0, react.useRef)(new three.Vector3());
970
+ const rayLeftAxis = (0, react.useRef)(new three.Vector3());
971
+ const rayShape = (0, react.useMemo)(() => new rapier.Cylinder(rayShapeH, rayShapeR), [rayShapeH, rayShapeR]);
972
+ const rotZ90 = (0, react.useMemo)(() => new three.Quaternion().setFromAxisAngle(fixedZAxis, Math.PI / 2), []);
973
+ const shapeRayHit = (0, react.useRef)(null);
974
+ const rayHit = (0, react.useRef)(null);
975
+ const rayCast = (0, react.useMemo)(() => new rapier.Ray(rayOrigin.current, rayDirection.current), [rapier]);
976
+ const suspensionToi = (0, react.useRef)(0);
977
+ const rayHitBody = (0, react.useRef)(null);
978
+ const rayShapeCenter = (0, react.useRef)(new three.Vector3());
979
+ const stableRayHitPoint = (0, react.useRef)(new three.Vector3());
980
+ const targetRayHitPoint = (0, react.useRef)(new three.Vector3());
981
+ const rayHitPointOffset = (0, react.useRef)(new three.Vector3());
982
+ const rayHitPointPosition = (0, react.useRef)(new three.Vector3());
983
+ const rayHitPointVelocity = (0, react.useRef)(new three.Vector3());
984
+ const rayHitPointVelOnPlane = (0, react.useRef)(new three.Vector3());
985
+ const rayHitPointNormal = (0, react.useRef)(new three.Vector3());
986
+ const rayHitPointFriction = (0, react.useRef)(0);
987
+ (0, react.useEffect)(() => {
988
+ if (groundDetection === "rayCast") shapeRayHit.current = null;
989
+ else rayHit.current = null;
990
+ }, [groundDetection]);
991
+ /**
992
+ * Moving platform preset
993
+ */
994
+ const massRatio = (0, react.useRef)(1);
995
+ const isOnMovingObject = (0, react.useRef)(false);
996
+ const wheelSupportForceMag = (0, react.useRef)(0);
997
+ const wheelSupportImpulse = (0, react.useRef)(new three.Vector3());
998
+ const wheelFrictionImpulse = (0, react.useRef)(new three.Vector3());
999
+ const movingObjectPosition = (0, react.useRef)(new three.Vector3());
1000
+ const movingObjectVelocity = (0, react.useRef)(new three.Vector3());
1001
+ const movingObjectVelocityOnPlane = (0, react.useRef)(new three.Vector3());
1002
+ const movingObjectLinearVelocity = (0, react.useRef)(new three.Vector3());
1003
+ const movingObjectAngularVelocity = (0, react.useRef)(new three.Vector3());
1004
+ const distanceFromOriginToObjectPoint = (0, react.useRef)(new three.Vector3());
1005
+ const movingObjectAngvelToLinvel = (0, react.useRef)(new three.Vector3());
1006
+ const massRatioFallOffCurve = (0, react.useMemo)(() => {
1007
+ var _massRatioFallOffCurv;
1008
+ return require_CurveLUT.bakeCurveLUT(massRatioFallOffCurveData.points, (_massRatioFallOffCurv = massRatioFallOffCurveData.samples) !== null && _massRatioFallOffCurv !== void 0 ? _massRatioFallOffCurv : 50);
1009
+ }, [massRatioFallOffCurveData]);
1010
+ /**
1011
+ * Wheel ref preset and handles
1012
+ */
1013
+ const shapeCastWheelRef = (0, react.useRef)(null);
1014
+ const modelRef = (0, react.useRef)(null);
1015
+ const wheelRef = (0, react.useRef)(null);
1016
+ const worldPos = (0, react.useRef)(new three.Vector3());
1017
+ const worldQuat = (0, react.useRef)(new three.Quaternion());
1018
+ (0, react.useImperativeHandle)(ref, () => shapeCastWheelRef.current, []);
1019
+ /**
1020
+ * Register wheel information
1021
+ */
1022
+ const wheelId = (0, react.useMemo)(() => {
1023
+ var _props$id;
1024
+ return String((_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : (0, three_src_math_MathUtils_js.generateUUID)());
1025
+ }, [props.id]);
1026
+ const wheelInfo = (0, react.useRef)({
1027
+ id: wheelId,
1028
+ name,
1029
+ enable,
1030
+ debug,
1031
+ rayShapeR,
1032
+ rayShapeH,
1033
+ rayLength,
1034
+ springK,
1035
+ dampingC,
1036
+ steerInvert,
1037
+ steerWheel,
1038
+ driveInvert,
1039
+ driveWheel,
1040
+ driveTorqueWeight,
1041
+ brakeWheel,
1042
+ maxBrakeTorque,
1043
+ rollingResistanceCoef,
1044
+ lowVelThreshold,
1045
+ tireGripFactor,
1046
+ lngFrictionEllipseScale,
1047
+ latFrictionEllipseScale,
1048
+ relaxLngRate,
1049
+ relaxLatRate,
1050
+ minLngRelaxCoeff,
1051
+ minLatRelaxCoeff,
1052
+ followPlatform,
1053
+ applyCounterMass,
1054
+ applyCounterFriction,
1055
+ showWheelModel,
1056
+ wheelModelDensity,
1057
+ wheelModelUpdate,
1058
+ wheelModelRadius,
1059
+ wheelModelLerpPosRate,
1060
+ wheelModelReversRotation,
1061
+ debuggerArrowScale,
1062
+ rayPos: new three.Vector3(),
1063
+ rayDir: new three.Vector3(),
1064
+ rayRot: new three.Quaternion(),
1065
+ rayUpDir: new three.Vector3(),
1066
+ rayFwdDir: new three.Vector3(),
1067
+ rayLeftDir: new three.Vector3(),
1068
+ floatImp: new three.Vector3(),
1069
+ rayHit: null,
1070
+ rayHitBody: null,
1071
+ rayHitPos: new three.Vector3(),
1072
+ rayHitNormal: new three.Vector3(),
1073
+ rayHitFriciton: 0,
1074
+ rayOriginVel: new three.Vector3(),
1075
+ rayHitPointVel: new three.Vector3(),
1076
+ isOnPlatform: false,
1077
+ lngSlipRatio: 0,
1078
+ latSlipRatio: 0,
1079
+ slipStrength: 0,
1080
+ lngAxis: new three.Vector3(),
1081
+ latAxis: new three.Vector3(),
1082
+ lngFricImp: new three.Vector3(),
1083
+ latFricImp: new three.Vector3(),
1084
+ effInertia: 0,
1085
+ supPos: new three.Vector3(),
1086
+ steerAngle: 0,
1087
+ driveTorque: 0,
1088
+ brakeTorque: 0,
1089
+ wheelLinVel: 0,
1090
+ wheelAngVel: 0,
1091
+ setDriveDemand,
1092
+ setBrakeDemand,
1093
+ setSteerDemand,
1094
+ setDriveWheelConfig,
1095
+ setSteerWheelConfig
1096
+ });
1097
+ wheelInfo.current.driveWheel = driveWheel;
1098
+ wheelInfo.current.driveTorqueWeight = driveTorqueWeight;
1099
+ wheelInfo.current.steerWheel = steerWheel;
1100
+ /**
1101
+ * Register the wheel to vehicle on mount, and unregister on unmount
1102
+ */
1103
+ (0, react.useEffect)(() => {
1104
+ vehicleValue === null || vehicleValue === void 0 || vehicleValue.regWheel(wheelInfo);
1105
+ return () => vehicleValue === null || vehicleValue === void 0 ? void 0 : vehicleValue.unregWheel(wheelId);
1106
+ }, [
1107
+ vehicleValue,
1108
+ wheelId,
1109
+ driveWheel,
1110
+ driveTorqueWeight,
1111
+ steerWheel
1112
+ ]);
1113
+ /**
1114
+ * Debug indicators preset
1115
+ */
1116
+ const forwardIndicatorRef = (0, react.useRef)(null);
1117
+ const rayHitPointRef = (0, react.useRef)(null);
1118
+ const xAxisPointRef = (0, react.useRef)(null);
1119
+ const yAxisPointRef = (0, react.useRef)(null);
1120
+ const zAxisPointRef = (0, react.useRef)(null);
1121
+ const currFloatArrowRef = (0, react.useRef)(null);
1122
+ const currFloatArrowDir = (0, react.useRef)(new three.Vector3());
1123
+ const currDriftArrowRef = (0, react.useRef)(null);
1124
+ const currDriftArrowDir = (0, react.useRef)(new three.Vector3());
1125
+ const currEngineArrowRef = (0, react.useRef)(null);
1126
+ const currEngineArrowDir = (0, react.useRef)(new three.Vector3());
1127
+ const debugAssets = (0, react.useMemo)(() => {
1128
+ if (!debug) return null;
1129
+ return {
1130
+ forwardRingGeo: new three.RingGeometry(rayShapeH * 1.6, rayShapeH * 2, 12),
1131
+ forwardPointerGeo: new three.PlaneGeometry(rayShapeH, rayShapeH),
1132
+ forwardIndicatorMat: new three.MeshBasicMaterial({
1133
+ color: require_Color.EC_AZURE,
1134
+ side: three.DoubleSide
1135
+ }),
1136
+ rayCastGeo: new three.CircleGeometry(rayShapeH * .5, 12),
1137
+ rayCastHalfGeo: new three.CylinderGeometry(rayShapeR, rayShapeR, rayShapeH * 2, 12, 1, true, 0, -Math.PI),
1138
+ rayCastMat: new three.MeshBasicMaterial({
1139
+ color: require_Color.EC_MED_PURPLE,
1140
+ side: three.DoubleSide,
1141
+ transparent: true,
1142
+ opacity: .5
1143
+ }),
1144
+ standingGeo: new three.OctahedronGeometry(rayShapeH * .5, 3),
1145
+ standingMat: new three.MeshBasicMaterial({
1146
+ color: require_Color.EC_PURPLE,
1147
+ transparent: true,
1148
+ opacity: .5
1149
+ }),
1150
+ xAxisPointMat: new three.MeshBasicMaterial({
1151
+ color: require_Color.EC_GREEN,
1152
+ transparent: true,
1153
+ opacity: 1
1154
+ }),
1155
+ yAxisPointMat: new three.MeshBasicMaterial({
1156
+ color: require_Color.EC_BLUE,
1157
+ transparent: true,
1158
+ opacity: 1
1159
+ }),
1160
+ zAxisPointMat: new three.MeshBasicMaterial({
1161
+ color: require_Color.EC_RED,
1162
+ transparent: true,
1163
+ opacity: 1
1164
+ })
1165
+ };
1166
+ }, [
1167
+ debug,
1168
+ rayShapeR,
1169
+ rayShapeH
1170
+ ]);
1171
+ (0, react.useEffect)(() => {
1172
+ return () => {
1173
+ if (!debugAssets) return;
1174
+ for (const key in debugAssets) {
1175
+ const item = debugAssets[key];
1176
+ if ("dispose" in item && typeof item.dispose === "function") item.dispose();
1177
+ }
1178
+ };
1179
+ }, [debugAssets]);
1180
+ /**
1181
+ *
1182
+ *
1183
+ *
1184
+ *
1185
+ *
1186
+ *
1187
+ *
1188
+ *
1189
+ *
1190
+ *
1191
+ *
1192
+ *
1193
+ *
1194
+ *
1195
+ *
1196
+ *
1197
+ *
1198
+ *
1199
+ *
1200
+ *
1201
+ *
1202
+ *
1203
+ *
1204
+ *
1205
+ *
1206
+ *
1207
+ *
1208
+ *
1209
+ *
1210
+ */
1211
+ /**
1212
+ * Update vehicle/wheel info function
1213
+ * (needs to recompute vehicle's info for each wheel, to gain the most updated info)
1214
+ */
1215
+ const updateVehicleInfo = (0, react.useCallback)((body) => {
1216
+ vehiclePos.current.copy(body.translation());
1217
+ vehicleQuat.current.copy(body.rotation());
1218
+ vehicleMatrix.current.compose(vehiclePos.current, vehicleQuat.current, fixedScale);
1219
+ vehicleYAxis.current.set(0, 1, 0).applyQuaternion(vehicleQuat.current);
1220
+ vehicleXAxis.current.set(1, 0, 0).applyQuaternion(vehicleQuat.current);
1221
+ vehicleZAxis.current.set(0, 0, 1).applyQuaternion(vehicleQuat.current);
1222
+ vehicleLinVel.current.copy(body.linvel());
1223
+ vehicleAngVel.current.copy(body.angvel());
1224
+ wheelInfo.current.rayPos = rayOrigin.current;
1225
+ wheelInfo.current.rayDir = rayDirection.current;
1226
+ wheelInfo.current.rayRot = rayRotation.current;
1227
+ wheelInfo.current.rayUpDir = rayUpAxis.current;
1228
+ wheelInfo.current.rayFwdDir = rayFWDAxis.current;
1229
+ wheelInfo.current.rayLeftDir = rayLeftAxis.current;
1230
+ wheelInfo.current.rayHit = groundDetection === "rayCast" ? rayHit.current : shapeRayHit.current;
1231
+ wheelInfo.current.rayHitBody = rayHitBody.current;
1232
+ wheelInfo.current.rayHitPos = rayHitPointPosition.current;
1233
+ wheelInfo.current.rayHitNormal = rayHitPointNormal.current;
1234
+ wheelInfo.current.rayHitFriciton = rayHitPointFriction.current;
1235
+ wheelInfo.current.rayOriginVel = rayOriginVel.current;
1236
+ wheelInfo.current.rayHitPointVel = rayHitPointVelocity.current;
1237
+ wheelInfo.current.isOnPlatform = isOnMovingObject.current;
1238
+ wheelInfo.current.floatImp = floatingImpulse.current;
1239
+ wheelInfo.current.lngSlipRatio = lngSlipRatio.current;
1240
+ wheelInfo.current.latSlipRatio = latSlipRatio.current;
1241
+ wheelInfo.current.slipStrength = slipStrength.current;
1242
+ wheelInfo.current.lngAxis = lngAxis.current;
1243
+ wheelInfo.current.latAxis = latAxis.current;
1244
+ wheelInfo.current.lngFricImp = lngFrictionImp.current;
1245
+ wheelInfo.current.latFricImp = latFrictionImp.current;
1246
+ wheelInfo.current.effInertia = effectiveInertia.current;
1247
+ wheelInfo.current.supPos = supportPoint.current;
1248
+ wheelInfo.current.steerAngle = steerAngle.current;
1249
+ wheelInfo.current.driveTorque = driveTorque.current;
1250
+ wheelInfo.current.brakeTorque = brakeTorque.current;
1251
+ wheelInfo.current.wheelAngVel = wheelAngVel.current;
1252
+ wheelInfo.current.wheelLinVel = wheelAngVel.current * rayShapeR;
1253
+ }, [groundDetection, rayShapeR]);
1254
+ /**
1255
+ * Compute ray hit point relative velocity
1256
+ */
1257
+ const computeRelativeVelocity = (0, react.useCallback)(() => {
1258
+ rayHitPointVelocity.current.copy(rayOriginVel.current);
1259
+ rayHitPointVelOnPlane.current.copy(rayHitPointVelocity.current).projectOnPlane(rayHitPointNormal.current);
1260
+ if (isOnMovingObject.current && followPlatform) {
1261
+ rayHitPointVelocity.current.sub(movingObjectVelocity.current);
1262
+ rayHitPointVelOnPlane.current.sub(movingObjectVelocityOnPlane.current);
1263
+ }
1264
+ }, [followPlatform]);
1265
+ /**
1266
+ * Update shape cast info
1267
+ */
1268
+ const updateShapeCastDir = (0, react.useCallback)(() => {
1269
+ if (!shapeCastWheelRef.current) return;
1270
+ if (steerWheel) shapeCastWheelRef.current.rotateY(steerIncrement.current);
1271
+ shapeCastWheelRef.current.getWorldPosition(worldPos.current);
1272
+ shapeCastWheelRef.current.getWorldQuaternion(worldQuat.current);
1273
+ rayOrigin.current.copy(worldPos.current);
1274
+ rayDirection.current.set(0, -1, 0).applyQuaternion(worldQuat.current);
1275
+ rayUpAxis.current.copy(rayDirection.current).negate();
1276
+ rayFWDAxis.current.set(0, 0, 1).applyQuaternion(worldQuat.current);
1277
+ rayBWDAxis.current.copy(rayFWDAxis.current).negate();
1278
+ rayLeftAxis.current.crossVectors(rayUpAxis.current, rayFWDAxis.current).normalize();
1279
+ distFromRayOriginToVehicle.current.copy(rayOrigin.current).sub(vehiclePos.current);
1280
+ angvelToLinvel.current.crossVectors(vehicleAngVel.current, distFromRayOriginToVehicle.current);
1281
+ rayOriginVel.current.copy(vehicleLinVel.current).add(angvelToLinvel.current);
1282
+ }, [steerWheel]);
1283
+ /**
1284
+ * Floating function
1285
+ */
1286
+ const ecctrlVehicleRayFilter = (0, react.useCallback)((collider) => {
1287
+ var _collider$parent, _userData$ecctrl, _userData$ecctrl2;
1288
+ const userData = (_collider$parent = collider.parent) === null || _collider$parent === void 0 || (_collider$parent = _collider$parent.call(collider)) === null || _collider$parent === void 0 ? void 0 : _collider$parent.userData;
1289
+ return !((userData === null || userData === void 0 || (_userData$ecctrl = userData.ecctrl) === null || _userData$ecctrl === void 0 ? void 0 : _userData$ecctrl.excludeRay) || (userData === null || userData === void 0 || (_userData$ecctrl2 = userData.ecctrl) === null || _userData$ecctrl2 === void 0 ? void 0 : _userData$ecctrl2.excludeVehicleRay));
1290
+ }, []);
1291
+ const floatVehicle = (0, react.useCallback)((body) => {
1292
+ var _rayHit$current, _shapeRayHit$current, _rayHit$current2, _shapeRayHit$current2;
1293
+ if (groundDetection === "rayCast") rayHit.current = world.castRayAndGetNormal(rayCast, rayLength + rayShapeR, false, _dimforge_rapier3d_compat.QueryFilterFlags.EXCLUDE_SENSORS, void 0, void 0, body, ecctrlVehicleRayFilter);
1294
+ else shapeRayHit.current = world.castShape(rayOrigin.current, rayRotation.current.copy(worldQuat.current).multiply(rotZ90), rayDirection.current, rayShape, 0, rayLength, false, _dimforge_rapier3d_compat.QueryFilterFlags.EXCLUDE_SENSORS, void 0, void 0, body, ecctrlVehicleRayFilter);
1295
+ const hitCollider = groundDetection === "rayCast" ? (_rayHit$current = rayHit.current) === null || _rayHit$current === void 0 ? void 0 : _rayHit$current.collider : (_shapeRayHit$current = shapeRayHit.current) === null || _shapeRayHit$current === void 0 ? void 0 : _shapeRayHit$current.collider;
1296
+ const hitDistance = groundDetection === "rayCast" ? (_rayHit$current2 = rayHit.current) === null || _rayHit$current2 === void 0 ? void 0 : _rayHit$current2.timeOfImpact : (_shapeRayHit$current2 = shapeRayHit.current) === null || _shapeRayHit$current2 === void 0 ? void 0 : _shapeRayHit$current2.time_of_impact;
1297
+ if (hitCollider && hitDistance != null) {
1298
+ var _hitCollider$friction;
1299
+ suspensionToi.current = groundDetection === "rayCast" ? Math.max(0, hitDistance - rayShapeR) : hitDistance;
1300
+ rayHitBody.current = hitCollider.parent();
1301
+ if (groundDetection === "rayCast") targetRayHitPoint.current.copy(rayOrigin.current).addScaledVector(rayDirection.current, hitDistance);
1302
+ else targetRayHitPoint.current.copy(shapeRayHit.current.witness1);
1303
+ rayHitPointNormal.current.copy(groundDetection === "rayCast" ? rayHit.current.normal : shapeRayHit.current.normal1).normalize();
1304
+ rayShapeCenter.current.copy(rayOrigin.current).addScaledVector(rayDirection.current, suspensionToi.current);
1305
+ let supportOffset = 0;
1306
+ if (groundDetection === "rayCast") stableRayHitPoint.current.copy(targetRayHitPoint.current);
1307
+ else {
1308
+ const rawOffset = (0, three_src_math_MathUtils_js.clamp)(rayHitPointOffset.current.copy(targetRayHitPoint.current).sub(rayShapeCenter.current).dot(rayLeftAxis.current), -rayShapeH, rayShapeH);
1309
+ stableRayHitPoint.current.copy(targetRayHitPoint.current).addScaledVector(rayLeftAxis.current, -rawOffset);
1310
+ const normalSide = rayHitPointNormal.current.dot(rayLeftAxis.current);
1311
+ const normalFwd = rayHitPointNormal.current.dot(rayFWDAxis.current);
1312
+ const sideWeight = (0, three_src_math_MathUtils_js.clamp)(Math.abs(normalSide) / Math.sqrt(Math.max(1 - normalFwd * normalFwd, 1e-6)), 0, 1);
1313
+ supportOffset = -Math.abs(rawOffset) * Math.sign(normalSide) * sideWeight;
1314
+ }
1315
+ rayHitPointPosition.current.copy(stableRayHitPoint.current).addScaledVector(rayLeftAxis.current, supportOffset);
1316
+ supportPoint.current.copy(rayShapeCenter.current).addScaledVector(rayLeftAxis.current, supportOffset);
1317
+ if (rayHitPointFriction.current !== hitCollider.friction()) rayHitPointFriction.current = (_hitCollider$friction = hitCollider.friction()) !== null && _hitCollider$friction !== void 0 ? _hitCollider$friction : 0;
1318
+ const springForce = springK * Math.max(0, rayLength - suspensionToi.current);
1319
+ const dampingForce = dampingC * rayHitPointVelocity.current.dot(rayUpAxis.current);
1320
+ floatingImpulse.current.copy(rayHitPointNormal.current).multiplyScalar(springForce - dampingForce).multiplyScalar(world.timestep);
1321
+ } else {
1322
+ rayHitBody.current = null;
1323
+ suspensionToi.current = 0;
1324
+ rayHitPointFriction.current = 0;
1325
+ floatingImpulse.current.set(0, 0, 0);
1326
+ }
1327
+ }, [
1328
+ groundDetection,
1329
+ rayCast,
1330
+ rayShape,
1331
+ rayLength,
1332
+ rayShapeR,
1333
+ rayShapeH,
1334
+ springK,
1335
+ dampingC,
1336
+ ecctrlVehicleRayFilter
1337
+ ]);
1338
+ /**
1339
+ * Detect is on a moving object
1340
+ */
1341
+ const isOnMovingObjectDetect = (0, react.useCallback)((body) => {
1342
+ if (followPlatform && rayHitBody.current && (rayHitBody.current.bodyType() === 0 || rayHitBody.current.bodyType() === 2)) {
1343
+ isOnMovingObject.current = true;
1344
+ if (rayHitBody.current.bodyType() === 0) massRatio.current = require_CurveLUT.evaluateCurveLUT((0, three_src_math_MathUtils_js.clamp)(rayHitBody.current.mass() / Math.max(body.mass(), 1e-6), 0, 1), massRatioFallOffCurve);
1345
+ else massRatio.current = 1;
1346
+ movingObjectPosition.current.copy(rayHitBody.current.translation());
1347
+ distanceFromOriginToObjectPoint.current.copy(rayOrigin.current).sub(movingObjectPosition.current);
1348
+ movingObjectLinearVelocity.current.copy(rayHitBody.current.linvel());
1349
+ movingObjectAngularVelocity.current.copy(rayHitBody.current.angvel());
1350
+ movingObjectAngvelToLinvel.current.crossVectors(movingObjectAngularVelocity.current, distanceFromOriginToObjectPoint.current);
1351
+ movingObjectVelocity.current.copy(movingObjectLinearVelocity.current).add(movingObjectAngvelToLinvel.current).multiplyScalar(massRatio.current);
1352
+ movingObjectVelocityOnPlane.current.copy(movingObjectVelocity.current).projectOnPlane(rayHitPointNormal.current);
1353
+ } else {
1354
+ isOnMovingObject.current = false;
1355
+ movingObjectVelocity.current.set(0, 0, 0);
1356
+ movingObjectVelocityOnPlane.current.set(0, 0, 0);
1357
+ massRatio.current = 1;
1358
+ }
1359
+ }, [followPlatform, massRatioFallOffCurve]);
1360
+ /**
1361
+ * Apply wheel mass on standing collider
1362
+ */
1363
+ const applyMassOnStandCollider = (0, react.useCallback)(() => {
1364
+ if (!rayHitBody.current || rayHitBody.current.bodyType() !== 0 || !applyCounterMass) return;
1365
+ wheelSupportImpulse.current.copy(rayHitPointNormal.current).multiplyScalar(-1 * wheelSupportForceMag.current * world.timestep * massRatio.current);
1366
+ if (wheelSupportForceMag.current > 0) rayHitBody.current.applyImpulseAtPoint(wheelSupportImpulse.current, rayHitPointPosition.current, true);
1367
+ }, [applyCounterMass]);
1368
+ /**
1369
+ * Apply tire friction on standing collider
1370
+ */
1371
+ const applyFricitonOnStandCollider = (0, react.useCallback)(() => {
1372
+ if (!rayHitBody.current || rayHitBody.current.bodyType() !== 0 || !applyCounterFriction) return;
1373
+ wheelFrictionImpulse.current.addVectors(lngFrictionImp.current, latFrictionImp.current).multiplyScalar(-1 * massRatio.current);
1374
+ if (wheelFrictionImpulse.current.lengthSq() > 1e-4) rayHitBody.current.applyImpulseAtPoint(wheelFrictionImpulse.current, rayHitPointPosition.current, true);
1375
+ }, [applyCounterFriction]);
1376
+ /**
1377
+ * Handle user input function
1378
+ */
1379
+ const handleUserInput = (0, react.useCallback)(() => {
1380
+ const currDriveConfig = driveWheelConfig.current;
1381
+ const currSteerConfig = steerWheelConfig.current;
1382
+ if (driveWheel && currDriveConfig && currDriveConfig.maxDriveTorque !== 0) {
1383
+ const maxAngVel = currDriveConfig.maxWheelAngVel * (driveDemand.current < 0 ? currDriveConfig.reverseRPMScale : 1);
1384
+ const angvelRatio = maxAngVel > 0 ? Math.abs(wheelAngVel.current) / maxAngVel : 1;
1385
+ driveTorque.current = driveDemand.current * currDriveConfig.maxDriveTorque * currDriveConfig.driveRatio * (driveDemand.current < 0 ? currDriveConfig.reverseTorqueScale : 1) * require_CurveLUT.evaluateCurveLUT(angvelRatio, currDriveConfig.engineTorqueCurve) * (driveInvert ? -1 : 1);
1386
+ }
1387
+ if (steerWheel && currSteerConfig) {
1388
+ var _currSteerConfig$maxW;
1389
+ const steerMaxWheelAngVel = (_currSteerConfig$maxW = currSteerConfig === null || currSteerConfig === void 0 ? void 0 : currSteerConfig.maxWheelAngVel) !== null && _currSteerConfig$maxW !== void 0 ? _currSteerConfig$maxW : 0;
1390
+ const speedRatio = steerMaxWheelAngVel > 0 ? (0, three_src_math_MathUtils_js.clamp)(vehicleLinVel.current.dot(vehicleZAxis.current) / (steerMaxWheelAngVel * rayShapeR), 0, 1) : 0;
1391
+ steerTarget.current = steerDemand.current * currSteerConfig.maxSteerAngle * require_CurveLUT.evaluateCurveLUT(speedRatio, currSteerConfig.steerAngleCurve) * (steerInvert ? -1 : 1);
1392
+ }
1393
+ if (brakeWheel) brakeTorque.current = brakeDemand.current * maxBrakeTorque;
1394
+ }, [
1395
+ driveWheel,
1396
+ driveInvert,
1397
+ maxBrakeTorque,
1398
+ steerWheel,
1399
+ steerInvert
1400
+ ]);
1401
+ /**
1402
+ * Steering wheel function
1403
+ */
1404
+ const steeringWheel = (0, react.useCallback)(() => {
1405
+ var _steerWheelConfig$cur, _steerWheelConfig$cur2;
1406
+ const angleDiff = steerTarget.current - steerAngle.current;
1407
+ const maxIncrement = ((_steerWheelConfig$cur = (_steerWheelConfig$cur2 = steerWheelConfig.current) === null || _steerWheelConfig$cur2 === void 0 ? void 0 : _steerWheelConfig$cur2.steerRate) !== null && _steerWheelConfig$cur !== void 0 ? _steerWheelConfig$cur : 0) * world.timestep;
1408
+ steerIncrement.current = Math.sign(angleDiff) * Math.min(Math.abs(angleDiff), maxIncrement);
1409
+ steerAngle.current += steerIncrement.current;
1410
+ }, [steerWheelConfig]);
1411
+ /**
1412
+ * Compute friction coefficient based on contact surface friction and tire grip factor
1413
+ */
1414
+ const computeContactFriction = (0, react.useCallback)(() => {
1415
+ if (rayHitBody.current) frictionCoef.current = Math.max((rayHitPointFriction.current + tireGripFactor) * .5, 0);
1416
+ else frictionCoef.current = 0;
1417
+ }, [tireGripFactor]);
1418
+ /**
1419
+ * Compute longitudinal and lateral friction impulses based on wheel slip and contact conditions
1420
+ */
1421
+ const computeWheelFrictionImpulse = (0, react.useCallback)((gravityMag) => {
1422
+ if (!rayHitBody.current) {
1423
+ wheelSupportForceMag.current = wheelMass * gravityMag;
1424
+ effectiveInertia.current = wheelInertia + wheelSupportForceMag.current / gravityMag * rayShapeR * rayShapeR;
1425
+ lngSlipRatio.current = 0;
1426
+ latSlipRatio.current = 0;
1427
+ slipStrength.current = 0;
1428
+ return;
1429
+ }
1430
+ wheelSupportForceMag.current = Math.max(floatingImpulse.current.dot(rayHitPointNormal.current), 0) / world.timestep;
1431
+ effectiveInertia.current = wheelInertia + wheelSupportForceMag.current / gravityMag * rayShapeR * rayShapeR;
1432
+ lngAxis.current.copy(rayFWDAxis.current).projectOnPlane(rayHitPointNormal.current).normalize();
1433
+ latAxis.current.copy(rayLeftAxis.current).projectOnPlane(rayHitPointNormal.current).normalize();
1434
+ const lngContactVel = rayHitPointVelocity.current.dot(lngAxis.current);
1435
+ const latContactVel = rayHitPointVelocity.current.dot(latAxis.current);
1436
+ const lngContactVelAbs = Math.abs(lngContactVel);
1437
+ const latContactVelAbs = Math.abs(latContactVel);
1438
+ const slipDiff = wheelAngVel.current * rayShapeR - lngContactVel;
1439
+ const slipDiffAbs = Math.abs(slipDiff);
1440
+ lngSlipRatio.current = slipDiffAbs / Math.max(lngContactVelAbs, 1e-4);
1441
+ latSlipRatio.current = latContactVelAbs === 0 && lngContactVelAbs === 0 ? 0 : (0, three_src_math_MathUtils_js.clamp)(Math.atan2(latContactVelAbs, lngContactVelAbs) / (Math.PI / 2), 0, 1);
1442
+ slipStrength.current = Math.max(lngSlipRatio.current, latSlipRatio.current);
1443
+ const lngSlipValue = require_CurveLUT.evaluateCurveLUT(lngSlipRatio.current, lngSlipRatioCurve);
1444
+ const latSlipValue = require_CurveLUT.evaluateCurveLUT(latSlipRatio.current, latSlipRatioCurve);
1445
+ const finalLngSlipValue = require_Math.remap((0, three_src_math_MathUtils_js.clamp)(1 - Math.max(slipDiffAbs, lngContactVelAbs) / lowVelThreshold, 0, 1), 0, 1, lngSlipValue, 1);
1446
+ const finalLatSlipValue = require_Math.remap((0, three_src_math_MathUtils_js.clamp)(1 - Math.max(latContactVelAbs, lngContactVelAbs) / lowVelThreshold, 0, 1), 0, 1, latSlipValue, 1);
1447
+ const maxLngImp = wheelSupportForceMag.current * finalLngSlipValue * frictionCoef.current * world.timestep * lngFrictionEllipseScale;
1448
+ const maxLatImp = wheelSupportForceMag.current * finalLatSlipValue * frictionCoef.current * world.timestep * latFrictionEllipseScale;
1449
+ desiredLngImpulse.current = slipDiff * effectiveInertia.current / (rayShapeR * rayShapeR);
1450
+ desiredLatImpulse.current = latContactVel * (wheelSupportForceMag.current / gravityMag);
1451
+ const ellipseUsage = Math.sqrt(desiredLngImpulse.current / maxLngImp * desiredLngImpulse.current / maxLngImp + desiredLatImpulse.current / maxLatImp * desiredLatImpulse.current / maxLatImp);
1452
+ if (ellipseUsage > 1) {
1453
+ desiredLngImpulse.current /= ellipseUsage;
1454
+ desiredLatImpulse.current /= ellipseUsage;
1455
+ }
1456
+ let lngCoeff = (0, three_src_math_MathUtils_js.clamp)(Math.max(minLngRelaxCoeff, lngContactVelAbs / Math.max(relaxLngRate, 1e-6) * world.timestep), 0, 1);
1457
+ let latCoeff = (0, three_src_math_MathUtils_js.clamp)(Math.max(minLatRelaxCoeff, latContactVelAbs / Math.max(relaxLatRate, 1e-6) * world.timestep), 0, 1);
1458
+ smoothedLngImpulse.current += (desiredLngImpulse.current - smoothedLngImpulse.current) * lngCoeff;
1459
+ smoothedLatImpulse.current += (desiredLatImpulse.current - smoothedLatImpulse.current) * latCoeff;
1460
+ lngFrictionImp.current.copy(lngAxis.current).multiplyScalar(smoothedLngImpulse.current);
1461
+ latFrictionImp.current.copy(latAxis.current).multiplyScalar(-smoothedLatImpulse.current);
1462
+ }, [
1463
+ wheelMass,
1464
+ wheelInertia,
1465
+ rayShapeR,
1466
+ lowVelThreshold,
1467
+ lngSlipRatioCurve,
1468
+ latSlipRatioCurve,
1469
+ lngFrictionEllipseScale,
1470
+ latFrictionEllipseScale,
1471
+ relaxLngRate,
1472
+ relaxLatRate,
1473
+ minLngRelaxCoeff,
1474
+ minLatRelaxCoeff
1475
+ ]);
1476
+ /**
1477
+ * Solve wheel rotation based on drive/brake torque and friction torque
1478
+ */
1479
+ const solveWheelRotation = (0, react.useCallback)(() => {
1480
+ const isDriving = driveWheel && Math.abs(driveTorque.current) > 0 && rayHitBody.current;
1481
+ const isBraking = brakeWheel && Math.abs(brakeTorque.current) > 0 && rayHitBody.current;
1482
+ const isFreeRolling = !isDriving && !isBraking;
1483
+ if (rayHitBody.current) wheelAngVel.current -= lngFrictionImp.current.dot(lngAxis.current) * rayShapeR / effectiveInertia.current;
1484
+ if (rayHitBody.current && isFreeRolling || !rayHitBody.current && wheelAngVel.current !== 0) {
1485
+ const rollingResistTorque = -rollingResistanceCoef * wheelSupportForceMag.current * wheelAngVel.current;
1486
+ wheelAngVel.current += rollingResistTorque / effectiveInertia.current * world.timestep;
1487
+ }
1488
+ if (isDriving && !isBraking) wheelAngVel.current += driveTorque.current / effectiveInertia.current * world.timestep;
1489
+ if (isBraking) {
1490
+ const appliedBrakeTorque = brakeTorque.current * -Math.sign(wheelAngVel.current);
1491
+ wheelAngVel.current += Math.min(Math.abs(wheelAngVel.current), Math.abs(appliedBrakeTorque / effectiveInertia.current) * world.timestep) * -Math.sign(wheelAngVel.current);
1492
+ }
1493
+ }, [
1494
+ rollingResistanceCoef,
1495
+ effectiveInertia,
1496
+ driveTorque,
1497
+ brakeTorque,
1498
+ rayShapeR,
1499
+ driveWheel,
1500
+ brakeWheel
1501
+ ]);
1502
+ /**
1503
+ * Update wheel models
1504
+ */
1505
+ const updateWheelModel = (0, react.useCallback)(() => {
1506
+ if (!wheelRef.current || !modelRef.current || !wheelModelUpdate) return;
1507
+ const offsetY = (groundDetection === "rayCast" ? rayHit.current : shapeRayHit.current) ? -(rayLength + rayShapeR) + wheelModelRadius + (rayLength - suspensionToi.current) : -(rayLength + rayShapeR) + wheelModelRadius;
1508
+ wheelRef.current.position.y = three.MathUtils.lerp(wheelRef.current.position.y, offsetY, 1 - Math.exp(-wheelModelLerpPosRate * world.timestep));
1509
+ modelRef.current.rotation.x += wheelAngVel.current * world.timestep * (wheelModelReversRotation ? -1 : 1);
1510
+ }, [
1511
+ groundDetection,
1512
+ wheelModelRadius,
1513
+ rayLength,
1514
+ rayShapeR,
1515
+ wheelModelLerpPosRate,
1516
+ rayLength,
1517
+ rayShapeR
1518
+ ]);
1519
+ /**
1520
+ * Update debug indicators
1521
+ */
1522
+ const updateDebugger = (0, react.useCallback)(() => {
1523
+ const hasContact = groundDetection === "rayCast" ? rayHit.current : shapeRayHit.current;
1524
+ vehicleInvertQuat.current.copy(vehicleQuat.current).invert();
1525
+ vehicleInvertMatrix.current.copy(vehicleMatrix.current).invert();
1526
+ if (rayHitPointRef.current) rayHitPointRef.current.position.copy(rayHitPointPosition.current).applyMatrix4(vehicleInvertMatrix.current);
1527
+ if (!shapeCastWheelRef.current) return;
1528
+ if (currFloatArrowRef.current) {
1529
+ currFloatArrowRef.current.position.copy(shapeCastWheelRef.current.position);
1530
+ currFloatArrowDir.current.copy(rayHitPointNormal.current).applyQuaternion(vehicleInvertQuat.current);
1531
+ currFloatArrowRef.current.setDirection(currFloatArrowDir.current);
1532
+ const length = hasContact ? wheelSupportForceMag.current * world.timestep * debuggerArrowScale : 0;
1533
+ currFloatArrowRef.current.setLength(length);
1534
+ }
1535
+ if (currDriftArrowRef.current) {
1536
+ currDriftArrowRef.current.position.copy(shapeCastWheelRef.current.position);
1537
+ currDriftArrowDir.current.copy(latAxis.current).negate().applyQuaternion(vehicleInvertQuat.current);
1538
+ currDriftArrowRef.current.setDirection(currDriftArrowDir.current);
1539
+ const length = hasContact ? desiredLatImpulse.current * debuggerArrowScale : 0;
1540
+ currDriftArrowRef.current.setLength(length);
1541
+ }
1542
+ if (currEngineArrowRef.current) {
1543
+ currEngineArrowRef.current.position.copy(shapeCastWheelRef.current.position);
1544
+ currEngineArrowDir.current.copy(lngAxis.current).applyQuaternion(vehicleInvertQuat.current);
1545
+ currEngineArrowRef.current.setDirection(currEngineArrowDir.current);
1546
+ const length = hasContact ? desiredLngImpulse.current * debuggerArrowScale : 0;
1547
+ currEngineArrowRef.current.setLength(length);
1548
+ }
1549
+ }, [groundDetection, debuggerArrowScale]);
1550
+ /**
1551
+ *
1552
+ *
1553
+ *
1554
+ *
1555
+ *
1556
+ *
1557
+ *
1558
+ *
1559
+ *
1560
+ *
1561
+ *
1562
+ *
1563
+ *
1564
+ *
1565
+ *
1566
+ *
1567
+ *
1568
+ *
1569
+ *
1570
+ *
1571
+ *
1572
+ *
1573
+ *
1574
+ *
1575
+ */
1576
+ (0, _react_three_fiber.useFrame)(() => {
1577
+ if (!vehicleValue || !enable) return;
1578
+ const vehicleBody = vehicleValue.body.current;
1579
+ const vehicleGravityMag = vehicleValue.gravityMag.current;
1580
+ if (!vehicleBody) return;
1581
+ updateVehicleInfo(vehicleBody);
1582
+ updateShapeCastDir();
1583
+ handleUserInput();
1584
+ steeringWheel();
1585
+ floatVehicle(vehicleBody);
1586
+ isOnMovingObjectDetect(vehicleBody);
1587
+ applyMassOnStandCollider();
1588
+ applyFricitonOnStandCollider();
1589
+ computeRelativeVelocity();
1590
+ computeContactFriction();
1591
+ computeWheelFrictionImpulse(vehicleGravityMag);
1592
+ solveWheelRotation();
1593
+ updateWheelModel();
1594
+ if (debug) updateDebugger();
1595
+ });
1596
+ return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("group", {
1597
+ ref: shapeCastWheelRef,
1598
+ ...props
1599
+ }, showWheelModel && /* @__PURE__ */ react.default.createElement("group", { ref: wheelRef }, /* @__PURE__ */ react.default.createElement("group", { ref: modelRef }, children)), debug && debugAssets && /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("group", { ref: forwardIndicatorRef }, /* @__PURE__ */ react.default.createElement("mesh", {
1600
+ rotation: [
1601
+ Math.PI / 2,
1602
+ 0,
1603
+ 0
1604
+ ],
1605
+ geometry: debugAssets.forwardRingGeo,
1606
+ material: debugAssets.forwardIndicatorMat
1607
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
1608
+ rotation: [
1609
+ Math.PI / 2,
1610
+ 0,
1611
+ Math.PI / 4
1612
+ ],
1613
+ position: [
1614
+ 0,
1615
+ 0,
1616
+ rayShapeH * 1.6
1617
+ ],
1618
+ geometry: debugAssets.forwardPointerGeo,
1619
+ material: debugAssets.forwardIndicatorMat
1620
+ })), groundDetection === "shapeCast" && /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
1621
+ rotation: [
1622
+ Math.PI,
1623
+ 0,
1624
+ Math.PI / 2
1625
+ ],
1626
+ geometry: debugAssets.rayCastHalfGeo,
1627
+ material: debugAssets.rayCastMat
1628
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
1629
+ position: [
1630
+ 0,
1631
+ -rayLength,
1632
+ 0
1633
+ ],
1634
+ rotation: [
1635
+ 0,
1636
+ 0,
1637
+ Math.PI / 2
1638
+ ],
1639
+ geometry: debugAssets.rayCastHalfGeo,
1640
+ material: debugAssets.rayCastMat
1641
+ })), groundDetection === "rayCast" && /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
1642
+ rotation: [
1643
+ -Math.PI / 2,
1644
+ 0,
1645
+ 0
1646
+ ],
1647
+ geometry: debugAssets.rayCastGeo,
1648
+ material: debugAssets.rayCastMat
1649
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
1650
+ position: [
1651
+ 0,
1652
+ -(rayLength + rayShapeR),
1653
+ 0
1654
+ ],
1655
+ rotation: [
1656
+ -Math.PI / 2,
1657
+ 0,
1658
+ 0
1659
+ ],
1660
+ geometry: debugAssets.rayCastGeo,
1661
+ material: debugAssets.rayCastMat
1662
+ })), /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
1663
+ ref: xAxisPointRef,
1664
+ position: [
1665
+ 1,
1666
+ 0,
1667
+ 0
1668
+ ],
1669
+ geometry: debugAssets.standingGeo,
1670
+ material: debugAssets.xAxisPointMat
1671
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
1672
+ ref: yAxisPointRef,
1673
+ position: [
1674
+ 0,
1675
+ 1,
1676
+ 0
1677
+ ],
1678
+ geometry: debugAssets.standingGeo,
1679
+ material: debugAssets.yAxisPointMat
1680
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
1681
+ ref: zAxisPointRef,
1682
+ position: [
1683
+ 0,
1684
+ 0,
1685
+ 1
1686
+ ],
1687
+ geometry: debugAssets.standingGeo,
1688
+ material: debugAssets.zAxisPointMat
1689
+ })))), debug && debugAssets && /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
1690
+ ref: rayHitPointRef,
1691
+ geometry: debugAssets.standingGeo,
1692
+ material: debugAssets.standingMat
1693
+ }), /* @__PURE__ */ react.default.createElement("arrowHelper", {
1694
+ ref: currFloatArrowRef,
1695
+ args: [
1696
+ void 0,
1697
+ void 0,
1698
+ void 0,
1699
+ "#87CEFA"
1700
+ ]
1701
+ }), /* @__PURE__ */ react.default.createElement("arrowHelper", {
1702
+ ref: currDriftArrowRef,
1703
+ args: [
1704
+ void 0,
1705
+ void 0,
1706
+ void 0,
1707
+ "#96FA87"
1708
+ ]
1709
+ }), /* @__PURE__ */ react.default.createElement("arrowHelper", {
1710
+ ref: currEngineArrowRef,
1711
+ args: [
1712
+ void 0,
1713
+ void 0,
1714
+ void 0,
1715
+ "#FA8787"
1716
+ ]
1717
+ })));
1718
+ });
1719
+ var ShapeCastWheel_default = react.default.memo(ShapeCastWheel);
1720
+ //#endregion
1721
+ //#region src/vehicles/components/ThrustPropeller.tsx
1722
+ /*!
1723
+ * Ecctrl
1724
+ * https://github.com/pmndrs/ecctrl
1725
+ *
1726
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
1727
+ * SPDX-License-Identifier: MIT
1728
+ */
1729
+ var ThrustPropeller = /* @__PURE__ */ (0, react.forwardRef)(({ children, debug = true, enable = true, name = "", maxThrust = 500, torqueRatio = .6, invertThrust = false, invertTorque = false, showPropellerModel = true, propellerModelUpdate = true, propellerModelMaxSpin = 50, propellerModelLerpSpinRate = 10, debuggerScale = 1, debuggerArrowScale = 35, ...props }, ref) => {
1730
+ /**
1731
+ * Rapier preset
1732
+ */
1733
+ const { rapier, world } = (0, _react_three_rapier.useRapier)();
1734
+ /**
1735
+ * Retrieve context object from ecctrl vehicle
1736
+ */
1737
+ const vehicleValue = (0, react.useContext)(VehicleContext);
1738
+ const vehicleBody = vehicleValue.body.current;
1739
+ const vehiclePos = (0, react.useRef)(new three.Vector3());
1740
+ const vehicleQuat = (0, react.useRef)(new three.Quaternion());
1741
+ const vehicleInvertQuat = (0, react.useRef)(new three.Quaternion());
1742
+ const vehicleLinVel = (0, react.useRef)(new three.Vector3());
1743
+ const vehicleAngVel = (0, react.useRef)(new three.Vector3());
1744
+ /**
1745
+ * Control preset
1746
+ */
1747
+ const localPos = (0, react.useRef)(new three.Vector3());
1748
+ const localQuat = (0, react.useRef)(new three.Quaternion());
1749
+ const worldPos = (0, react.useRef)(new three.Vector3());
1750
+ const worldQuat = (0, react.useRef)(new three.Quaternion());
1751
+ const thrustDir = (0, react.useRef)(new three.Vector3());
1752
+ const thrustForce = (0, react.useRef)(new three.Vector3());
1753
+ const leverageTorque = (0, react.useRef)(new three.Vector3());
1754
+ const reactionTorque = (0, react.useRef)(new three.Vector3());
1755
+ const reactionTorqueDir = (0, react.useRef)(new three.Vector3());
1756
+ const torqueInfluence = (0, react.useRef)(new three.Vector3());
1757
+ const throttle = (0, react.useRef)(0);
1758
+ const setThrottle = (0, react.useCallback)((value) => throttle.current = (0, three_src_math_MathUtils_js.clamp)(value, 0, 1), []);
1759
+ /**
1760
+ * Refs and handles
1761
+ */
1762
+ const thrustPropellerRef = (0, react.useRef)(null);
1763
+ (0, react.useImperativeHandle)(ref, () => thrustPropellerRef.current, []);
1764
+ /**
1765
+ * Propeller model preset
1766
+ */
1767
+ const modelRef = (0, react.useRef)(null);
1768
+ const modelSpinVel = (0, react.useRef)(0);
1769
+ /**
1770
+ * Register propeller information
1771
+ */
1772
+ const propellerId = (0, react.useMemo)(() => {
1773
+ var _props$id;
1774
+ return String((_props$id = props.id) !== null && _props$id !== void 0 ? _props$id : (0, three_src_math_MathUtils_js.generateUUID)());
1775
+ }, [props.id]);
1776
+ const propellerInfo = (0, react.useRef)({
1777
+ id: propellerId,
1778
+ name,
1779
+ enable,
1780
+ debug,
1781
+ maxThrust,
1782
+ torqueRatio,
1783
+ debuggerScale,
1784
+ invertThrust,
1785
+ invertTorque,
1786
+ thrustPos: new three.Vector3(),
1787
+ thrustDir: new three.Vector3(),
1788
+ thrustPot: new three.Vector3(),
1789
+ torqueDir: new three.Vector3(),
1790
+ torquePot: new three.Vector3(),
1791
+ worldThrustPos: new three.Vector3(),
1792
+ worldThrustDir: new three.Vector3(),
1793
+ worldTorqueDir: new three.Vector3(),
1794
+ thrustImpulse: new three.Vector3(),
1795
+ torqueImpulse: new three.Vector3(),
1796
+ finalThrottle: 0,
1797
+ throttle: throttle.current,
1798
+ setThrottle,
1799
+ lx: 0,
1800
+ ly: 0,
1801
+ lz: 0,
1802
+ ax: 0,
1803
+ ay: 0,
1804
+ az: 0
1805
+ });
1806
+ (0, react.useEffect)(() => {
1807
+ vehicleValue === null || vehicleValue === void 0 || vehicleValue.regPropeller(propellerInfo);
1808
+ return () => vehicleValue === null || vehicleValue === void 0 ? void 0 : vehicleValue.unregPropeller(propellerId);
1809
+ }, [vehicleValue]);
1810
+ /**
1811
+ * Debug indicators preset
1812
+ */
1813
+ const xAxisPointRef = (0, react.useRef)(null);
1814
+ const yAxisPointRef = (0, react.useRef)(null);
1815
+ const zAxisPointRef = (0, react.useRef)(null);
1816
+ const currThrustArrowRef = (0, react.useRef)(null);
1817
+ const currTorqueArrowRef = (0, react.useRef)(null);
1818
+ const debugAssets = (0, react.useMemo)(() => {
1819
+ if (!debug) return null;
1820
+ return {
1821
+ thrustRingGeo: new three.RingGeometry(debuggerScale * .5, debuggerScale * .55, 12, 1, 0, -Math.PI * 1),
1822
+ thrustRingMat: new three.MeshBasicMaterial({
1823
+ color: require_Color.EC_AZURE,
1824
+ side: three.DoubleSide
1825
+ }),
1826
+ thrustPointerGeo: new three.ConeGeometry(debuggerScale * .06, debuggerScale * .5, 8, 1, true),
1827
+ thrustIndicatorMat: new three.MeshBasicMaterial({
1828
+ color: require_Color.EC_MED_PURPLE,
1829
+ side: three.DoubleSide,
1830
+ transparent: true,
1831
+ opacity: .3
1832
+ }),
1833
+ axisPointGeo: new three.OctahedronGeometry(debuggerScale * .05, 3),
1834
+ xAxisPointMat: new three.MeshBasicMaterial({
1835
+ color: require_Color.EC_GREEN,
1836
+ transparent: true,
1837
+ opacity: 1
1838
+ }),
1839
+ yAxisPointMat: new three.MeshBasicMaterial({
1840
+ color: require_Color.EC_BLUE,
1841
+ transparent: true,
1842
+ opacity: 1
1843
+ }),
1844
+ zAxisPointMat: new three.MeshBasicMaterial({
1845
+ color: require_Color.EC_RED,
1846
+ transparent: true,
1847
+ opacity: 1
1848
+ })
1849
+ };
1850
+ }, [debug, debuggerScale]);
1851
+ (0, react.useEffect)(() => {
1852
+ return () => {
1853
+ if (!debugAssets) return;
1854
+ for (const key in debugAssets) {
1855
+ const item = debugAssets[key];
1856
+ if ("dispose" in item && typeof item.dispose === "function") item.dispose();
1857
+ }
1858
+ };
1859
+ }, [debugAssets]);
1860
+ /**
1861
+ *
1862
+ *
1863
+ *
1864
+ *
1865
+ *
1866
+ *
1867
+ *
1868
+ *
1869
+ *
1870
+ *
1871
+ *
1872
+ *
1873
+ *
1874
+ *
1875
+ *
1876
+ *
1877
+ *
1878
+ *
1879
+ *
1880
+ *
1881
+ *
1882
+ *
1883
+ *
1884
+ *
1885
+ *
1886
+ *
1887
+ *
1888
+ *
1889
+ *
1890
+ *
1891
+ *
1892
+ *
1893
+ *
1894
+ *
1895
+ */
1896
+ /**
1897
+ * Update vehicle info function
1898
+ */
1899
+ const updateVehicleInfo = (0, react.useCallback)((body) => {
1900
+ vehiclePos.current.copy(body.translation());
1901
+ vehicleQuat.current.copy(body.rotation());
1902
+ vehicleLinVel.current.copy(body.linvel());
1903
+ vehicleAngVel.current.copy(body.angvel());
1904
+ }, []);
1905
+ /**
1906
+ * Update propeller info function
1907
+ */
1908
+ const updatePropellerInfo = (0, react.useCallback)(() => {
1909
+ if (!thrustPropellerRef.current) return;
1910
+ thrustPropellerRef.current.getWorldPosition(worldPos.current);
1911
+ thrustPropellerRef.current.getWorldQuaternion(worldQuat.current);
1912
+ vehicleInvertQuat.current.copy(vehicleQuat.current).invert();
1913
+ localPos.current.subVectors(worldPos.current, vehiclePos.current).applyQuaternion(vehicleInvertQuat.current);
1914
+ localQuat.current.multiplyQuaternions(vehicleInvertQuat.current, worldQuat.current);
1915
+ thrustDir.current.set(0, invertThrust ? -1 : 1, 0).applyQuaternion(localQuat.current);
1916
+ thrustForce.current.copy(thrustDir.current).multiplyScalar(maxThrust);
1917
+ leverageTorque.current.crossVectors(localPos.current, thrustForce.current);
1918
+ reactionTorqueDir.current.set(0, invertTorque ? -1 : 1, 0).applyQuaternion(localQuat.current);
1919
+ reactionTorque.current.copy(reactionTorqueDir.current).multiplyScalar(maxThrust * torqueRatio);
1920
+ torqueInfluence.current.copy(leverageTorque.current).add(reactionTorque.current);
1921
+ propellerInfo.current.lx = thrustForce.current.x;
1922
+ propellerInfo.current.ly = thrustForce.current.y;
1923
+ propellerInfo.current.lz = thrustForce.current.z;
1924
+ propellerInfo.current.ax = torqueInfluence.current.x;
1925
+ propellerInfo.current.ay = torqueInfluence.current.y;
1926
+ propellerInfo.current.az = torqueInfluence.current.z;
1927
+ propellerInfo.current.thrustPos = localPos.current;
1928
+ propellerInfo.current.thrustDir = thrustDir.current;
1929
+ propellerInfo.current.thrustPot = thrustForce.current;
1930
+ propellerInfo.current.torqueDir = reactionTorqueDir.current;
1931
+ propellerInfo.current.torquePot = torqueInfluence.current;
1932
+ propellerInfo.current.throttle = throttle.current;
1933
+ }, [
1934
+ invertThrust,
1935
+ invertTorque,
1936
+ maxThrust,
1937
+ torqueRatio
1938
+ ]);
1939
+ /**
1940
+ * Update propeller model function
1941
+ */
1942
+ const updatePropellerModel = (0, react.useCallback)((frameRateCorrection) => {
1943
+ if (!modelRef.current) return;
1944
+ const targetVel = throttle.current * propellerModelMaxSpin * (invertTorque ? -1 : 1);
1945
+ modelSpinVel.current = (0, three_src_math_MathUtils_js.lerp)(modelSpinVel.current, targetVel, 1 - Math.exp(-propellerModelLerpSpinRate * world.timestep));
1946
+ modelRef.current.rotateY(modelSpinVel.current * frameRateCorrection);
1947
+ }, [
1948
+ propellerModelMaxSpin,
1949
+ propellerModelLerpSpinRate,
1950
+ invertTorque
1951
+ ]);
1952
+ /**
1953
+ * Update debug indicators
1954
+ */
1955
+ const updateDebugger = (0, react.useCallback)(() => {
1956
+ if (currThrustArrowRef.current) currThrustArrowRef.current.setLength(throttle.current * debuggerArrowScale);
1957
+ if (currTorqueArrowRef.current) currTorqueArrowRef.current.setLength(throttle.current * debuggerArrowScale * torqueRatio);
1958
+ }, [debuggerArrowScale, torqueRatio]);
1959
+ /**
1960
+ *
1961
+ *
1962
+ *
1963
+ *
1964
+ *
1965
+ *
1966
+ *
1967
+ *
1968
+ *
1969
+ *
1970
+ *
1971
+ *
1972
+ *
1973
+ *
1974
+ *
1975
+ *
1976
+ *
1977
+ *
1978
+ *
1979
+ *
1980
+ */
1981
+ (0, _react_three_fiber.useFrame)(() => {
1982
+ if (!vehicleBody || !enable) return;
1983
+ const frameRateCorrection = 60 * world.timestep;
1984
+ updateVehicleInfo(vehicleBody);
1985
+ updatePropellerInfo();
1986
+ if (propellerModelUpdate) updatePropellerModel(frameRateCorrection);
1987
+ updateDebugger();
1988
+ });
1989
+ return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("group", {
1990
+ ref: thrustPropellerRef,
1991
+ ...props
1992
+ }, showPropellerModel && /* @__PURE__ */ react.default.createElement("group", { ref: modelRef }, children), debug && debugAssets && /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
1993
+ "rotation-x": invertThrust ? Math.PI : 0,
1994
+ position: [
1995
+ 0,
1996
+ debuggerScale * .25 * (invertThrust ? -1 : 1),
1997
+ 0
1998
+ ],
1999
+ geometry: debugAssets.thrustPointerGeo,
2000
+ material: debugAssets.thrustIndicatorMat
2001
+ })), /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
2002
+ "rotation-x": Math.PI / 2,
2003
+ position: [
2004
+ debuggerScale * .53 * (invertTorque ? 1 : -1),
2005
+ 0,
2006
+ debuggerScale * .25
2007
+ ],
2008
+ geometry: debugAssets.thrustPointerGeo,
2009
+ material: debugAssets.thrustRingMat
2010
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
2011
+ "rotation-x": Math.PI / 2,
2012
+ geometry: debugAssets.thrustRingGeo,
2013
+ material: debugAssets.thrustRingMat
2014
+ })), /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("mesh", {
2015
+ ref: xAxisPointRef,
2016
+ position: [
2017
+ debuggerScale,
2018
+ 0,
2019
+ 0
2020
+ ],
2021
+ geometry: debugAssets.axisPointGeo,
2022
+ material: debugAssets.xAxisPointMat
2023
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
2024
+ ref: yAxisPointRef,
2025
+ position: [
2026
+ 0,
2027
+ debuggerScale,
2028
+ 0
2029
+ ],
2030
+ geometry: debugAssets.axisPointGeo,
2031
+ material: debugAssets.yAxisPointMat
2032
+ }), /* @__PURE__ */ react.default.createElement("mesh", {
2033
+ ref: zAxisPointRef,
2034
+ position: [
2035
+ 0,
2036
+ 0,
2037
+ debuggerScale
2038
+ ],
2039
+ geometry: debugAssets.axisPointGeo,
2040
+ material: debugAssets.zAxisPointMat
2041
+ })), /* @__PURE__ */ react.default.createElement("group", null, /* @__PURE__ */ react.default.createElement("arrowHelper", {
2042
+ ref: currThrustArrowRef,
2043
+ args: [
2044
+ new three.Vector3(0, invertThrust ? -1 : 1, 0),
2045
+ void 0,
2046
+ 0,
2047
+ "#87CEFA"
2048
+ ]
2049
+ }), /* @__PURE__ */ react.default.createElement("arrowHelper", {
2050
+ ref: currTorqueArrowRef,
2051
+ args: [
2052
+ new three.Vector3(0, invertTorque ? -1 : 1, 0),
2053
+ void 0,
2054
+ 0,
2055
+ "#FA8787"
2056
+ ]
2057
+ })))));
2058
+ });
2059
+ var ThrustPropeller_default = react.default.memo(ThrustPropeller);
2060
+ //#endregion
2061
+ //#region src/vehicle.ts
2062
+ /*!
2063
+ * Ecctrl
2064
+ * https://github.com/pmndrs/ecctrl
2065
+ *
2066
+ * SPDX-FileCopyrightText: 2023-2026 Erdong Chen
2067
+ * SPDX-License-Identifier: MIT
2068
+ */
2069
+ //#endregion
2070
+ Object.defineProperty(exports, "EcctrlVehicle_default", {
2071
+ enumerable: true,
2072
+ get: function() {
2073
+ return EcctrlVehicle_default;
2074
+ }
2075
+ });
2076
+ Object.defineProperty(exports, "ShapeCastWheel_default", {
2077
+ enumerable: true,
2078
+ get: function() {
2079
+ return ShapeCastWheel_default;
2080
+ }
2081
+ });
2082
+ Object.defineProperty(exports, "ThrustPropeller_default", {
2083
+ enumerable: true,
2084
+ get: function() {
2085
+ return ThrustPropeller_default;
2086
+ }
2087
+ });
2088
+
2089
+ //# sourceMappingURL=vehicle-DYwDt5rB.cjs.map