@pinkaphant/kolmo 0.5.2 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -14
- package/dist/engine/actor.d.ts +1 -1
- package/dist/engine/index.d.ts +3 -0
- package/dist/engine/index.js +44 -34
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/surface.d.ts +5 -6
- package/dist/engine/traits.d.ts +27 -0
- package/dist/engine/world.d.ts +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -5
- package/dist/physics/index.d.ts +2 -1
- package/dist/physics/index.js +3 -1
- package/dist/physics-KYWAXctg.js +233 -0
- package/dist/physics-KYWAXctg.js.map +1 -0
- package/dist/replay/index.d.ts +84 -0
- package/dist/replay/index.js +380 -0
- package/dist/replay/index.js.map +1 -0
- package/dist/terrain/index.d.ts +119 -0
- package/dist/terrain/index.js +495 -0
- package/dist/terrain/index.js.map +1 -0
- package/dist/toolgun/Toolgun.d.ts +11 -4
- package/dist/toolgun/index.d.ts +2 -2
- package/dist/toolgun/index.js +1 -1
- package/dist/{toolgun-CFCNO00q.js → toolgun-COu_5SxS.js} +202 -542
- package/dist/toolgun-COu_5SxS.js.map +1 -0
- package/dist/traits-Dp1ey_4w.js +267 -0
- package/dist/traits-Dp1ey_4w.js.map +1 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/index.js.map +1 -1
- package/dist/water/index.d.ts +71 -0
- package/dist/water/index.js +442 -0
- package/dist/water/index.js.map +1 -0
- package/dist/{world-BljtS6Fb.js → world-BDhBihjW.js} +114 -139
- package/dist/world-BDhBihjW.js.map +1 -0
- package/docs/api-reference.md +201 -0
- package/package.json +23 -6
- package/dist/physics-CA1abDCY.js +0 -476
- package/dist/physics-CA1abDCY.js.map +0 -1
- package/dist/toolgun/c12Outlets.d.ts +0 -36
- package/dist/toolgun-CFCNO00q.js.map +0 -1
- package/dist/world-BljtS6Fb.js.map +0 -1
package/dist/physics-CA1abDCY.js
DELETED
|
@@ -1,476 +0,0 @@
|
|
|
1
|
-
import { Suspense, createContext, useContext, useLayoutEffect, useMemo } from "react";
|
|
2
|
-
import * as THREE from "three";
|
|
3
|
-
import { PhysicsWorld } from "@khr3/core";
|
|
4
|
-
import { useCustomGravity } from "@pinkaphant/ecctrl/gravity";
|
|
5
|
-
import { createActions, createQuery, createWorld, getStore, relation, trait, unpackEntity } from "koota";
|
|
6
|
-
import { WorldProvider } from "koota/react";
|
|
7
|
-
import { jsx } from "react/jsx-runtime";
|
|
8
|
-
// src/engine/traits.ts
|
|
9
|
-
var VehicleTrait = trait(() => ({
|
|
10
|
-
id: "",
|
|
11
|
-
handle: null,
|
|
12
|
-
jointsHandle: null,
|
|
13
|
-
seatOffset: [
|
|
14
|
-
0,
|
|
15
|
-
.55,
|
|
16
|
-
0
|
|
17
|
-
],
|
|
18
|
-
exitOffset: [
|
|
19
|
-
-1.5,
|
|
20
|
-
.45,
|
|
21
|
-
0
|
|
22
|
-
],
|
|
23
|
-
isFlight: false
|
|
24
|
-
}));
|
|
25
|
-
var ActorTrait = trait(() => ({
|
|
26
|
-
id: "pilot",
|
|
27
|
-
handle: null,
|
|
28
|
-
exitSpawnPos: null,
|
|
29
|
-
exitSpawnYaw: 0,
|
|
30
|
-
exitLinVel: null
|
|
31
|
-
}));
|
|
32
|
-
var TransformTrait = trait({
|
|
33
|
-
x: 0,
|
|
34
|
-
y: 0,
|
|
35
|
-
z: 0,
|
|
36
|
-
qx: 0,
|
|
37
|
-
qy: 0,
|
|
38
|
-
qz: 0,
|
|
39
|
-
qw: 1
|
|
40
|
-
});
|
|
41
|
-
var VelocityTrait = trait({
|
|
42
|
-
vx: 0,
|
|
43
|
-
vy: 0,
|
|
44
|
-
vz: 0,
|
|
45
|
-
speedKmh: 0
|
|
46
|
-
});
|
|
47
|
-
var VehicleTelemetryTrait = trait({
|
|
48
|
-
rpm: 0,
|
|
49
|
-
gear: 1,
|
|
50
|
-
throttle: 0,
|
|
51
|
-
boost: 0,
|
|
52
|
-
slip: 0
|
|
53
|
-
});
|
|
54
|
-
var InteractableTrait = trait({
|
|
55
|
-
id: "",
|
|
56
|
-
radius: 4,
|
|
57
|
-
kind: "vehicle"
|
|
58
|
-
});
|
|
59
|
-
var PilotedTag = trait();
|
|
60
|
-
var PilotLink = relation({ exclusive: true });
|
|
61
|
-
var WorldSessionTrait = trait({ nearVehicleId: "" });
|
|
62
|
-
var vehicleSimQuery = createQuery(VehicleTrait, TransformTrait, VelocityTrait, VehicleTelemetryTrait);
|
|
63
|
-
var pilotedVehicleQuery = createQuery(VehicleTrait, PilotedTag);
|
|
64
|
-
var kolmoWorld = createWorld(WorldSessionTrait);
|
|
65
|
-
var KolmoWorldContext = createContext(null);
|
|
66
|
-
function useOptionalKootaWorld() {
|
|
67
|
-
return useContext(KolmoWorldContext);
|
|
68
|
-
}
|
|
69
|
-
function useActiveKolmoWorld() {
|
|
70
|
-
return useContext(KolmoWorldContext) ?? kolmoWorld;
|
|
71
|
-
}
|
|
72
|
-
function ensureWorldSession(w) {
|
|
73
|
-
if (!w.has(WorldSessionTrait)) w.add(WorldSessionTrait);
|
|
74
|
-
}
|
|
75
|
-
function createEmptyVehicleCmd(brake = false) {
|
|
76
|
-
return {
|
|
77
|
-
forward: false,
|
|
78
|
-
backward: false,
|
|
79
|
-
steerLeft: false,
|
|
80
|
-
steerRight: false,
|
|
81
|
-
brake,
|
|
82
|
-
throttleUp: false,
|
|
83
|
-
throttleDown: false,
|
|
84
|
-
yawLeft: false,
|
|
85
|
-
yawRight: false,
|
|
86
|
-
pitchForward: false,
|
|
87
|
-
pitchBackward: false,
|
|
88
|
-
rollLeft: false,
|
|
89
|
-
rollRight: false,
|
|
90
|
-
joystickL: {
|
|
91
|
-
x: 0,
|
|
92
|
-
y: 0
|
|
93
|
-
},
|
|
94
|
-
joystickR: {
|
|
95
|
-
x: 0,
|
|
96
|
-
y: 0
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
/** Zero-allocation SoA typed-array writer using Koota's public `unpackEntity` + `getStore`. */
|
|
101
|
-
function writeEntityKinematics(world, entity, pos, quat, linVel, speedKmh) {
|
|
102
|
-
const { entityId } = unpackEntity(entity);
|
|
103
|
-
if (entity.has(TransformTrait)) {
|
|
104
|
-
const xf = getStore(world, TransformTrait);
|
|
105
|
-
xf.x[entityId] = pos.x;
|
|
106
|
-
xf.y[entityId] = pos.y;
|
|
107
|
-
xf.z[entityId] = pos.z;
|
|
108
|
-
xf.qx[entityId] = quat.x;
|
|
109
|
-
xf.qy[entityId] = quat.y;
|
|
110
|
-
xf.qz[entityId] = quat.z;
|
|
111
|
-
xf.qw[entityId] = quat.w;
|
|
112
|
-
}
|
|
113
|
-
if (entity.has(VelocityTrait)) {
|
|
114
|
-
const vl = getStore(world, VelocityTrait);
|
|
115
|
-
vl.vx[entityId] = linVel.x;
|
|
116
|
-
vl.vy[entityId] = linVel.y;
|
|
117
|
-
vl.vz[entityId] = linVel.z;
|
|
118
|
-
vl.speedKmh[entityId] = speedKmh;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/** Zero-allocation SoA typed-array writer for `VehicleTelemetryTrait` inside `useFrame`. */
|
|
122
|
-
function writeVehicleTelemetry(world, entity, rpm, gear, throttle, boost, slip) {
|
|
123
|
-
if (!entity.has(VehicleTelemetryTrait)) return;
|
|
124
|
-
const { entityId } = unpackEntity(entity);
|
|
125
|
-
const st = getStore(world, VehicleTelemetryTrait);
|
|
126
|
-
st.rpm[entityId] = rpm;
|
|
127
|
-
st.gear[entityId] = gear;
|
|
128
|
-
st.throttle[entityId] = throttle;
|
|
129
|
-
st.boost[entityId] = boost;
|
|
130
|
-
st.slip[entityId] = slip;
|
|
131
|
-
}
|
|
132
|
-
var _exitPos = new THREE.Vector3();
|
|
133
|
-
var _exitFwd = new THREE.Vector3();
|
|
134
|
-
var _flipUp = new THREE.Vector3();
|
|
135
|
-
var _flipFwd = new THREE.Vector3();
|
|
136
|
-
var _flipRight = new THREE.Vector3();
|
|
137
|
-
var _flipMat = new THREE.Matrix4();
|
|
138
|
-
var _flipQuat = new THREE.Quaternion();
|
|
139
|
-
function flipVehicleBodyUpright(veh, joints) {
|
|
140
|
-
const body = veh.body;
|
|
141
|
-
if (!body) return;
|
|
142
|
-
const pos = body.translation();
|
|
143
|
-
_flipUp.copy(veh.upAxis);
|
|
144
|
-
if (_flipUp.lengthSq() < 1e-6) _flipUp.set(0, 1, 0);
|
|
145
|
-
else _flipUp.normalize();
|
|
146
|
-
_flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);
|
|
147
|
-
if (_flipFwd.lengthSq() < 1e-6) {
|
|
148
|
-
if (Math.abs(_flipUp.y) < .9) _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);
|
|
149
|
-
else _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);
|
|
150
|
-
}
|
|
151
|
-
_flipFwd.normalize();
|
|
152
|
-
_flipRight.crossVectors(_flipUp, _flipFwd).normalize();
|
|
153
|
-
_flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);
|
|
154
|
-
_flipQuat.setFromRotationMatrix(_flipMat);
|
|
155
|
-
body.setTranslation({
|
|
156
|
-
x: pos.x + _flipUp.x * 1.35,
|
|
157
|
-
y: pos.y + _flipUp.y * 1.35,
|
|
158
|
-
z: pos.z + _flipUp.z * 1.35
|
|
159
|
-
}, true);
|
|
160
|
-
body.setRotation({
|
|
161
|
-
x: _flipQuat.x,
|
|
162
|
-
y: _flipQuat.y,
|
|
163
|
-
z: _flipQuat.z,
|
|
164
|
-
w: _flipQuat.w
|
|
165
|
-
}, true);
|
|
166
|
-
body.setLinvel({
|
|
167
|
-
x: 0,
|
|
168
|
-
y: 0,
|
|
169
|
-
z: 0
|
|
170
|
-
}, true);
|
|
171
|
-
body.setAngvel({
|
|
172
|
-
x: 0,
|
|
173
|
-
y: 0,
|
|
174
|
-
z: 0
|
|
175
|
-
}, true);
|
|
176
|
-
joints?.syncBodiesToParent();
|
|
177
|
-
}
|
|
178
|
-
var kolmoActions = createActions((world) => ({
|
|
179
|
-
boardVehicle: (vehicleId) => {
|
|
180
|
-
if (!vehicleId) return;
|
|
181
|
-
ensureWorldSession(world);
|
|
182
|
-
let targetEnt;
|
|
183
|
-
for (const vehEnt of world.query(VehicleTrait)) if (vehEnt.get(VehicleTrait)?.id === vehicleId) {
|
|
184
|
-
targetEnt = vehEnt;
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
if (!targetEnt) return;
|
|
188
|
-
for (const prev of world.query(pilotedVehicleQuery)) if (prev !== targetEnt && prev.has(PilotedTag)) prev.remove(PilotedTag);
|
|
189
|
-
if (!targetEnt.has(PilotedTag)) targetEnt.add(PilotedTag);
|
|
190
|
-
const pilot = world.queryFirst(ActorTrait);
|
|
191
|
-
if (pilot) pilot.add(PilotLink(targetEnt));
|
|
192
|
-
if (world.get(WorldSessionTrait)?.nearVehicleId) world.set(WorldSessionTrait, { nearVehicleId: "" });
|
|
193
|
-
},
|
|
194
|
-
exitVehicle: () => {
|
|
195
|
-
ensureWorldSession(world);
|
|
196
|
-
const pilot = world.queryFirst(ActorTrait);
|
|
197
|
-
const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);
|
|
198
|
-
if (linked) {
|
|
199
|
-
const v = linked.get(VehicleTrait);
|
|
200
|
-
if (pilot) {
|
|
201
|
-
if (pilot.has(PilotLink(linked))) pilot.remove(PilotLink(linked));
|
|
202
|
-
if (v?.handle) {
|
|
203
|
-
_exitPos.set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2]).applyQuaternion(v.handle.currQuat).add(v.handle.currPos);
|
|
204
|
-
_exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();
|
|
205
|
-
const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;
|
|
206
|
-
const lv = v.handle.currLinVel;
|
|
207
|
-
const curActor = pilot.get(ActorTrait);
|
|
208
|
-
pilot.set(ActorTrait, {
|
|
209
|
-
id: curActor?.id ?? "pilot",
|
|
210
|
-
handle: curActor?.handle ?? null,
|
|
211
|
-
exitSpawnPos: [
|
|
212
|
-
_exitPos.x,
|
|
213
|
-
_exitPos.y,
|
|
214
|
-
_exitPos.z
|
|
215
|
-
],
|
|
216
|
-
exitSpawnYaw: yaw,
|
|
217
|
-
exitLinVel: [
|
|
218
|
-
lv.x,
|
|
219
|
-
lv.y,
|
|
220
|
-
lv.z
|
|
221
|
-
]
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
if (linked.has(PilotedTag)) linked.remove(PilotedTag);
|
|
226
|
-
v?.handle?.setMovement(createEmptyVehicleCmd(!v.isFlight));
|
|
227
|
-
}
|
|
228
|
-
for (const extra of world.query(pilotedVehicleQuery)) if (extra.has(PilotedTag)) extra.remove(PilotedTag);
|
|
229
|
-
},
|
|
230
|
-
resetVehicle: (vehicleId) => {
|
|
231
|
-
let target;
|
|
232
|
-
if (vehicleId) for (const ent of world.query(VehicleTrait)) {
|
|
233
|
-
const v = ent.get(VehicleTrait);
|
|
234
|
-
if (v?.id === vehicleId && v.handle?.body) {
|
|
235
|
-
target = v;
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
if (!target) {
|
|
240
|
-
const pv = (world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery))?.get(VehicleTrait);
|
|
241
|
-
if (pv?.handle?.body) target = pv;
|
|
242
|
-
}
|
|
243
|
-
if (!target) for (const ent of world.query(VehicleTrait)) {
|
|
244
|
-
const v = ent.get(VehicleTrait);
|
|
245
|
-
if (v?.handle?.body) {
|
|
246
|
-
target = v;
|
|
247
|
-
break;
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
if (target?.handle) flipVehicleBodyUpright(target.handle, target.jointsHandle);
|
|
251
|
-
}
|
|
252
|
-
}));
|
|
253
|
-
// src/physics/nBodyGravity.ts
|
|
254
|
-
/** CODATA Newtonian gravitational constant in SI units (m^3 kg^-1 s^-2). */
|
|
255
|
-
var G_SI = 66743e-15;
|
|
256
|
-
function resolveAttractorMu(attractor, gravitationalConstant = G_SI) {
|
|
257
|
-
const rRef = Math.max(0, attractor.radius ?? 0);
|
|
258
|
-
const eps = Math.max(1e-4, attractor.softeningM ?? (rRef > 0 ? rRef * .05 : .5));
|
|
259
|
-
const epsSq = eps * eps;
|
|
260
|
-
if (typeof attractor.mu === "number" && Number.isFinite(attractor.mu)) return {
|
|
261
|
-
mu: Math.max(0, attractor.mu),
|
|
262
|
-
epsSq
|
|
263
|
-
};
|
|
264
|
-
if (typeof attractor.surfaceG === "number" && Number.isFinite(attractor.surfaceG) && rRef > 0) {
|
|
265
|
-
const denom = Math.pow(rRef * rRef + epsSq, 1.5);
|
|
266
|
-
return {
|
|
267
|
-
mu: Math.max(0, attractor.surfaceG * denom / rRef),
|
|
268
|
-
epsSq
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
if (typeof attractor.massKg === "number" && Number.isFinite(attractor.massKg)) return {
|
|
272
|
-
mu: Math.max(0, attractor.massKg * gravitationalConstant),
|
|
273
|
-
epsSq
|
|
274
|
-
};
|
|
275
|
-
return {
|
|
276
|
-
mu: 0,
|
|
277
|
-
epsSq
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
function prepareAttractors(attractors, gravitationalConstant = G_SI) {
|
|
281
|
-
const out = [];
|
|
282
|
-
for (let i = 0; i < attractors.length; i++) {
|
|
283
|
-
const a = attractors[i];
|
|
284
|
-
const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);
|
|
285
|
-
if (mu > 0) out.push({
|
|
286
|
-
px: a.position[0],
|
|
287
|
-
py: a.position[1],
|
|
288
|
-
pz: a.position[2],
|
|
289
|
-
mu,
|
|
290
|
-
epsSq
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
return out;
|
|
294
|
-
}
|
|
295
|
-
function evaluatePreparedNBodyGravity(pos, prepared, out) {
|
|
296
|
-
let gx = 0, gy = 0, gz = 0;
|
|
297
|
-
for (let i = 0; i < prepared.length; i++) {
|
|
298
|
-
const a = prepared[i];
|
|
299
|
-
const dx = a.px - pos.x;
|
|
300
|
-
const dy = a.py - pos.y;
|
|
301
|
-
const dz = a.pz - pos.z;
|
|
302
|
-
const rSq = dx * dx + dy * dy + dz * dz;
|
|
303
|
-
if (rSq < 1e-12) continue;
|
|
304
|
-
const scale = a.mu / Math.pow(rSq + a.epsSq, 1.5);
|
|
305
|
-
gx += dx * scale;
|
|
306
|
-
gy += dy * scale;
|
|
307
|
-
gz += dz * scale;
|
|
308
|
-
}
|
|
309
|
-
return out.set(gx, gy, gz);
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Evaluates softened Newtonian multi-attractor gravitational acceleration (m/s^2):
|
|
313
|
-
* g(x) = sum_i mu_i * (p_i - x) / (|p_i - x|^2 + eps_i^2)^(3/2)
|
|
314
|
-
*/
|
|
315
|
-
function evaluateNBodyGravity(pos, attractors, out, gravitationalConstant = G_SI) {
|
|
316
|
-
let gx = 0, gy = 0, gz = 0;
|
|
317
|
-
for (let i = 0; i < attractors.length; i++) {
|
|
318
|
-
const a = attractors[i];
|
|
319
|
-
const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);
|
|
320
|
-
if (mu <= 0) continue;
|
|
321
|
-
const dx = a.position[0] - pos.x;
|
|
322
|
-
const dy = a.position[1] - pos.y;
|
|
323
|
-
const dz = a.position[2] - pos.z;
|
|
324
|
-
const rSq = dx * dx + dy * dy + dz * dz;
|
|
325
|
-
if (rSq < 1e-12) continue;
|
|
326
|
-
const scale = mu / Math.pow(rSq + epsSq, 1.5);
|
|
327
|
-
gx += dx * scale;
|
|
328
|
-
gy += dy * scale;
|
|
329
|
-
gz += dz * scale;
|
|
330
|
-
}
|
|
331
|
-
return out.set(gx, gy, gz);
|
|
332
|
-
}
|
|
333
|
-
function createNBodyGravityField(attractors, gravitationalConstant = G_SI) {
|
|
334
|
-
const prepared = prepareAttractors(attractors, gravitationalConstant);
|
|
335
|
-
return (pos, out = new THREE.Vector3()) => evaluatePreparedNBodyGravity(pos, prepared, out);
|
|
336
|
-
}
|
|
337
|
-
function computeCircularOrbitSpeed(attractor, orbitRadiusM, gravitationalConstant = G_SI) {
|
|
338
|
-
if (orbitRadiusM <= 0) return 0;
|
|
339
|
-
const { mu, epsSq } = resolveAttractorMu(attractor, gravitationalConstant);
|
|
340
|
-
if (mu <= 0) return 0;
|
|
341
|
-
return orbitRadiusM * Math.sqrt(mu / Math.pow(orbitRadiusM * orbitRadiusM + epsSq, 1.5));
|
|
342
|
-
}
|
|
343
|
-
// src/physics/index.tsx
|
|
344
|
-
var KolmoGravityContext = createContext(false);
|
|
345
|
-
function isGravityTuple(g) {
|
|
346
|
-
return Array.isArray(g);
|
|
347
|
-
}
|
|
348
|
-
function isPointGravity(g) {
|
|
349
|
-
return typeof g === "object" && !Array.isArray(g) && "kind" in g && g.kind === "point";
|
|
350
|
-
}
|
|
351
|
-
function isNBodyGravity(g) {
|
|
352
|
-
return typeof g === "object" && !Array.isArray(g) && "kind" in g && g.kind === "nbody";
|
|
353
|
-
}
|
|
354
|
-
var DEFAULT_GRAVITY_FN = () => new THREE.Vector3(0, -9.81, 0);
|
|
355
|
-
function KolmoPhysics({ gravity = "planar", paused = false, timeScale = 1, maxDelta, physicsDebug = false, world = null, children, ...physicsProps }) {
|
|
356
|
-
const outerWorld = useOptionalKootaWorld();
|
|
357
|
-
const resolvedWorld = world ?? outerWorld ?? kolmoWorld;
|
|
358
|
-
const isCallback = typeof gravity === "function";
|
|
359
|
-
const isTuple = isGravityTuple(gravity);
|
|
360
|
-
const isZero = gravity === "zero";
|
|
361
|
-
const isCustomLiteral = gravity === "custom";
|
|
362
|
-
const isPoint = isPointGravity(gravity);
|
|
363
|
-
const isNBody = isNBodyGravity(gravity);
|
|
364
|
-
const isCustomGravity = isCallback || isPoint || isNBody || isCustomLiteral;
|
|
365
|
-
const gx = isTuple ? gravity[0] : 0;
|
|
366
|
-
const gy = isTuple ? gravity[1] : -9.81;
|
|
367
|
-
const gz = isTuple ? gravity[2] : 0;
|
|
368
|
-
const cx = isPoint ? gravity.center[0] : 0;
|
|
369
|
-
const cy = isPoint ? gravity.center[1] : 0;
|
|
370
|
-
const cz = isPoint ? gravity.center[2] : 0;
|
|
371
|
-
const pointRadius = isPoint ? gravity.radius : 1;
|
|
372
|
-
const pointInverseSq = isPoint ? Boolean(gravity.inverseSquare) : false;
|
|
373
|
-
const surfaceG = isPoint ? gravity.surfaceG : isZero ? 0 : 9.81;
|
|
374
|
-
const gravityFn = isCallback ? gravity : null;
|
|
375
|
-
const nBodySpec = isNBody ? gravity : null;
|
|
376
|
-
const preparedAttractors = useMemo(() => {
|
|
377
|
-
if (nBodySpec) return prepareAttractors(nBodySpec.attractors, nBodySpec.gravitationalConstant);
|
|
378
|
-
if (isPoint && pointInverseSq) return prepareAttractors([{
|
|
379
|
-
position: [
|
|
380
|
-
cx,
|
|
381
|
-
cy,
|
|
382
|
-
cz
|
|
383
|
-
],
|
|
384
|
-
surfaceG,
|
|
385
|
-
radius: pointRadius
|
|
386
|
-
}]);
|
|
387
|
-
return [];
|
|
388
|
-
}, [
|
|
389
|
-
nBodySpec,
|
|
390
|
-
isPoint,
|
|
391
|
-
pointInverseSq,
|
|
392
|
-
cx,
|
|
393
|
-
cy,
|
|
394
|
-
cz,
|
|
395
|
-
surfaceG,
|
|
396
|
-
pointRadius
|
|
397
|
-
]);
|
|
398
|
-
const rapierGravity = useMemo(() => isTuple ? [
|
|
399
|
-
gx,
|
|
400
|
-
gy,
|
|
401
|
-
gz
|
|
402
|
-
] : isCustomGravity || isZero ? [
|
|
403
|
-
0,
|
|
404
|
-
0,
|
|
405
|
-
0
|
|
406
|
-
] : [
|
|
407
|
-
0,
|
|
408
|
-
-9.81,
|
|
409
|
-
0
|
|
410
|
-
], [
|
|
411
|
-
isTuple,
|
|
412
|
-
gx,
|
|
413
|
-
gy,
|
|
414
|
-
gz,
|
|
415
|
-
isCustomGravity,
|
|
416
|
-
isZero
|
|
417
|
-
]);
|
|
418
|
-
useLayoutEffect(() => {
|
|
419
|
-
if (isCustomLiteral || !isCallback && !isPoint && !isNBody) return;
|
|
420
|
-
const scratch = new THREE.Vector3();
|
|
421
|
-
let installed = null;
|
|
422
|
-
if (gravityFn) installed = (pos) => gravityFn(pos, scratch.set(0, 0, 0));
|
|
423
|
-
else if (nBodySpec || isPoint && pointInverseSq) installed = (pos) => evaluatePreparedNBodyGravity(pos, preparedAttractors, scratch);
|
|
424
|
-
else if (isPoint) installed = (pos) => {
|
|
425
|
-
scratch.set(pos.x - cx, pos.y - cy, pos.z - cz);
|
|
426
|
-
const lenSq = scratch.lengthSq();
|
|
427
|
-
return lenSq < 1e-8 ? scratch.set(0, -surfaceG, 0) : scratch.multiplyScalar(-surfaceG / Math.sqrt(lenSq));
|
|
428
|
-
};
|
|
429
|
-
if (!installed) return;
|
|
430
|
-
useCustomGravity.getState().setGravityField(installed);
|
|
431
|
-
return () => {
|
|
432
|
-
if (useCustomGravity.getState().gravityField === installed) useCustomGravity.getState().setGravityField(DEFAULT_GRAVITY_FN);
|
|
433
|
-
};
|
|
434
|
-
}, [
|
|
435
|
-
isCustomLiteral,
|
|
436
|
-
isCallback,
|
|
437
|
-
isPoint,
|
|
438
|
-
isNBody,
|
|
439
|
-
gravityFn,
|
|
440
|
-
nBodySpec,
|
|
441
|
-
preparedAttractors,
|
|
442
|
-
cx,
|
|
443
|
-
cy,
|
|
444
|
-
cz,
|
|
445
|
-
pointInverseSq,
|
|
446
|
-
surfaceG
|
|
447
|
-
]);
|
|
448
|
-
const content = /* @__PURE__ */ jsx(KolmoGravityContext.Provider, {
|
|
449
|
-
value: isCustomGravity,
|
|
450
|
-
children: /* @__PURE__ */ jsx(PhysicsWorld, {
|
|
451
|
-
...physicsProps,
|
|
452
|
-
paused,
|
|
453
|
-
timeScale,
|
|
454
|
-
...maxDelta === void 0 ? {} : { maxDelta },
|
|
455
|
-
gravity: rapierGravity,
|
|
456
|
-
debug: physicsDebug,
|
|
457
|
-
children: /* @__PURE__ */ jsx(Suspense, {
|
|
458
|
-
fallback: null,
|
|
459
|
-
children
|
|
460
|
-
})
|
|
461
|
-
})
|
|
462
|
-
});
|
|
463
|
-
return resolvedWorld !== outerWorld ? /* @__PURE__ */ jsx(KolmoWorldContext.Provider, {
|
|
464
|
-
value: resolvedWorld,
|
|
465
|
-
children: /* @__PURE__ */ jsx(WorldProvider, {
|
|
466
|
-
world: resolvedWorld,
|
|
467
|
-
children: content
|
|
468
|
-
})
|
|
469
|
-
}) : content;
|
|
470
|
-
}
|
|
471
|
-
function useIsKolmoCustomGravity() {
|
|
472
|
-
return useContext(KolmoGravityContext);
|
|
473
|
-
}
|
|
474
|
-
export { writeEntityKinematics as A, flipVehicleBodyUpright as C, useActiveKolmoWorld as D, pilotedVehicleQuery as E, useOptionalKootaWorld as O, ensureWorldSession as S, kolmoWorld as T, VehicleTelemetryTrait as _, computeCircularOrbitSpeed as a, WorldSessionTrait as b, evaluatePreparedNBodyGravity as c, ActorTrait as d, InteractableTrait as f, TransformTrait as g, PilotedTag as h, G_SI as i, writeVehicleTelemetry as j, vehicleSimQuery as k, prepareAttractors as l, PilotLink as m, KolmoPhysics as n, createNBodyGravityField as o, KolmoWorldContext as p, useIsKolmoCustomGravity as r, evaluateNBodyGravity as s, KolmoGravityContext as t, resolveAttractorMu as u, VehicleTrait as v, kolmoActions as w, createEmptyVehicleCmd as x, VelocityTrait as y };
|
|
475
|
-
|
|
476
|
-
//# sourceMappingURL=physics-CA1abDCY.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"physics-CA1abDCY.js","names":["_jsx"],"sources":["../src/engine/traits.ts","../src/physics/nBodyGravity.ts","../src/physics/index.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport * as THREE from \"three\";\nimport {\n createActions,\n createQuery,\n createWorld,\n getStore,\n relation,\n trait,\n unpackEntity,\n type Entity,\n type World,\n} from \"koota\";\nimport type { EcctrlHandle } from \"@pinkaphant/ecctrl\";\nimport type { EcctrlVehicleHandle, VehicleInput } from \"@pinkaphant/ecctrl/vehicle\";\nimport type { KhrVehicleJointsHandle } from \"@khr3/core/vehicle\";\n\nexport type KolmoControlMode = \"foot\" | \"car\" | \"flight\";\n\nexport interface VehicleTraitData {\n id: string;\n handle: EcctrlVehicleHandle | null;\n jointsHandle?: KhrVehicleJointsHandle | null;\n seatOffset: [number, number, number];\n exitOffset: [number, number, number];\n isFlight: boolean;\n}\n\nexport interface ActorTraitData {\n id: string;\n handle: EcctrlHandle | null;\n exitSpawnPos: [number, number, number] | null;\n exitSpawnYaw: number;\n exitLinVel: [number, number, number] | null;\n}\n\nexport const VehicleTrait = trait((): VehicleTraitData => ({\n id: \"\",\n handle: null,\n jointsHandle: null,\n seatOffset: [0, 0.55, 0],\n exitOffset: [-1.5, 0.45, 0],\n isFlight: false,\n}));\n\nexport const ActorTrait = trait((): ActorTraitData => ({\n id: \"pilot\",\n handle: null,\n exitSpawnPos: null,\n exitSpawnYaw: 0,\n exitLinVel: null,\n}));\n\nexport const TransformTrait = trait({ x: 0, y: 0, z: 0, qx: 0, qy: 0, qz: 0, qw: 1 });\nexport const VelocityTrait = trait({ vx: 0, vy: 0, vz: 0, speedKmh: 0 });\nexport const VehicleTelemetryTrait = trait({ rpm: 0, gear: 1, throttle: 0, boost: 0, slip: 0 });\nexport const InteractableTrait = trait({ id: \"\", radius: 4, kind: \"vehicle\" as \"vehicle\" | \"prop\" });\nexport const PilotedTag = trait();\nexport const PilotLink = relation({ exclusive: true });\nexport const WorldSessionTrait = trait({ nearVehicleId: \"\" });\n\nexport const vehicleSimQuery = createQuery(VehicleTrait, TransformTrait, VelocityTrait, VehicleTelemetryTrait);\nexport const pilotedVehicleQuery = createQuery(VehicleTrait, PilotedTag);\n\nexport const kolmoWorld: World = createWorld(WorldSessionTrait);\nexport const KolmoWorldContext = createContext<World | null>(null);\n\nexport function useOptionalKootaWorld(): World | null {\n return useContext(KolmoWorldContext);\n}\n\nexport function useActiveKolmoWorld(): World {\n return useContext(KolmoWorldContext) ?? kolmoWorld;\n}\n\nexport function ensureWorldSession(w: World): void {\n if (!w.has(WorldSessionTrait))\n w.add(WorldSessionTrait);\n}\n\nexport function createEmptyVehicleCmd(brake = false): VehicleInput {\n return {\n forward: false,\n backward: false,\n steerLeft: false,\n steerRight: false,\n brake,\n throttleUp: false,\n throttleDown: false,\n yawLeft: false,\n yawRight: false,\n pitchForward: false,\n pitchBackward: false,\n rollLeft: false,\n rollRight: false,\n joystickL: { x: 0, y: 0 },\n joystickR: { x: 0, y: 0 },\n };\n}\n\n/** Zero-allocation SoA typed-array writer using Koota's public `unpackEntity` + `getStore`. */\nexport function writeEntityKinematics(\n world: World,\n entity: Entity,\n pos: { readonly x: number; readonly y: number; readonly z: number },\n quat: { readonly x: number; readonly y: number; readonly z: number; readonly w: number },\n linVel: { readonly x: number; readonly y: number; readonly z: number },\n speedKmh: number,\n): void {\n const { entityId } = unpackEntity(entity);\n if (entity.has(TransformTrait)) {\n const xf = getStore(world, TransformTrait);\n xf.x[entityId] = pos.x;\n xf.y[entityId] = pos.y;\n xf.z[entityId] = pos.z;\n xf.qx[entityId] = quat.x;\n xf.qy[entityId] = quat.y;\n xf.qz[entityId] = quat.z;\n xf.qw[entityId] = quat.w;\n }\n if (entity.has(VelocityTrait)) {\n const vl = getStore(world, VelocityTrait);\n vl.vx[entityId] = linVel.x;\n vl.vy[entityId] = linVel.y;\n vl.vz[entityId] = linVel.z;\n vl.speedKmh[entityId] = speedKmh;\n }\n}\n\n/** Zero-allocation SoA typed-array writer for `VehicleTelemetryTrait` inside `useFrame`. */\nexport function writeVehicleTelemetry(\n world: World,\n entity: Entity,\n rpm: number,\n gear: number,\n throttle: number,\n boost: number,\n slip: number,\n): void {\n if (!entity.has(VehicleTelemetryTrait))\n return;\n const { entityId } = unpackEntity(entity);\n const st = getStore(world, VehicleTelemetryTrait);\n st.rpm[entityId] = rpm;\n st.gear[entityId] = gear;\n st.throttle[entityId] = throttle;\n st.boost[entityId] = boost;\n st.slip[entityId] = slip;\n}\n\nconst _exitPos = new THREE.Vector3();\nconst _exitFwd = new THREE.Vector3();\nconst _flipUp = new THREE.Vector3();\nconst _flipFwd = new THREE.Vector3();\nconst _flipRight = new THREE.Vector3();\nconst _flipMat = new THREE.Matrix4();\nconst _flipQuat = new THREE.Quaternion();\n\nexport function flipVehicleBodyUpright(veh: EcctrlVehicleHandle, joints?: KhrVehicleJointsHandle | null): void {\n const body = veh.body;\n if (!body)\n return;\n const pos = body.translation();\n _flipUp.copy(veh.upAxis);\n if (_flipUp.lengthSq() < 1e-6)\n _flipUp.set(0, 1, 0);\n else\n _flipUp.normalize();\n\n _flipFwd.copy(veh.bodyZAxis).projectOnPlane(_flipUp);\n if (_flipFwd.lengthSq() < 1e-6) {\n if (Math.abs(_flipUp.y) < 0.9)\n _flipFwd.set(0, 1, 0).projectOnPlane(_flipUp);\n else\n _flipFwd.set(0, 0, 1).projectOnPlane(_flipUp);\n }\n _flipFwd.normalize();\n _flipRight.crossVectors(_flipUp, _flipFwd).normalize();\n _flipMat.makeBasis(_flipRight, _flipUp, _flipFwd);\n _flipQuat.setFromRotationMatrix(_flipMat);\n\n body.setTranslation({ x: pos.x + _flipUp.x * 1.35, y: pos.y + _flipUp.y * 1.35, z: pos.z + _flipUp.z * 1.35 }, true);\n body.setRotation({ x: _flipQuat.x, y: _flipQuat.y, z: _flipQuat.z, w: _flipQuat.w }, true);\n body.setLinvel({ x: 0, y: 0, z: 0 }, true);\n body.setAngvel({ x: 0, y: 0, z: 0 }, true);\n joints?.syncBodiesToParent();\n}\n\nexport const kolmoActions = createActions((world) => ({\n boardVehicle: (vehicleId: string) => {\n if (!vehicleId)\n return;\n ensureWorldSession(world);\n let targetEnt: Entity | undefined;\n for (const vehEnt of world.query(VehicleTrait)) {\n const v = vehEnt.get(VehicleTrait);\n if (v?.id === vehicleId) {\n targetEnt = vehEnt;\n break;\n }\n }\n if (!targetEnt)\n return;\n\n for (const prev of world.query(pilotedVehicleQuery)) {\n if (prev !== targetEnt && prev.has(PilotedTag))\n prev.remove(PilotedTag);\n }\n if (!targetEnt.has(PilotedTag))\n targetEnt.add(PilotedTag);\n\n const pilot = world.queryFirst(ActorTrait);\n if (pilot)\n pilot.add(PilotLink(targetEnt));\n\n if (world.get(WorldSessionTrait)?.nearVehicleId) {\n world.set(WorldSessionTrait, { nearVehicleId: \"\" });\n }\n },\n exitVehicle: () => {\n ensureWorldSession(world);\n const pilot = world.queryFirst(ActorTrait);\n const linked = pilot?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n if (linked) {\n const v = linked.get(VehicleTrait);\n if (pilot) {\n if (pilot.has(PilotLink(linked)))\n pilot.remove(PilotLink(linked));\n if (v?.handle) {\n _exitPos\n .set(v.exitOffset[0], v.exitOffset[1], v.exitOffset[2])\n .applyQuaternion(v.handle.currQuat)\n .add(v.handle.currPos);\n _exitFwd.copy(v.handle.bodyZAxis).projectOnPlane(v.handle.upAxis).normalize();\n const yaw = _exitFwd.lengthSq() > 1e-6 ? Math.atan2(_exitFwd.x, _exitFwd.z) : 0;\n const lv = v.handle.currLinVel;\n const curActor = pilot.get(ActorTrait);\n pilot.set(ActorTrait, {\n id: curActor?.id ?? \"pilot\",\n handle: curActor?.handle ?? null,\n exitSpawnPos: [_exitPos.x, _exitPos.y, _exitPos.z],\n exitSpawnYaw: yaw,\n exitLinVel: [lv.x, lv.y, lv.z],\n });\n }\n }\n if (linked.has(PilotedTag))\n linked.remove(PilotedTag);\n v?.handle?.setMovement(createEmptyVehicleCmd(!v.isFlight));\n }\n for (const extra of world.query(pilotedVehicleQuery)) {\n if (extra.has(PilotedTag))\n extra.remove(PilotedTag);\n }\n },\n resetVehicle: (vehicleId?: string) => {\n let target: VehicleTraitData | undefined;\n if (vehicleId) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.id === vehicleId && v.handle?.body) {\n target = v;\n break;\n }\n }\n }\n if (!target) {\n const piloted = world.queryFirst(ActorTrait)?.targetFor(PilotLink) ?? world.queryFirst(pilotedVehicleQuery);\n const pv = piloted?.get(VehicleTrait);\n if (pv?.handle?.body)\n target = pv;\n }\n if (!target) {\n for (const ent of world.query(VehicleTrait)) {\n const v = ent.get(VehicleTrait);\n if (v?.handle?.body) {\n target = v;\n break;\n }\n }\n }\n if (target?.handle)\n flipVehicleBodyUpright(target.handle, target.jointsHandle);\n },\n}));\n","import * as THREE from \"three\";\n\n/** CODATA Newtonian gravitational constant in SI units (m^3 kg^-1 s^-2). */\nexport const G_SI = 6.6743e-11;\n\nexport interface KolmoGravityAttractor {\n readonly id?: string;\n readonly position: readonly [number, number, number];\n /** Direct standard gravitational parameter mu = G * M (m^3 / s^2). */\n readonly mu?: number;\n /** Mass in kilograms (used with `gravitationalConstant`, defaults to `G_SI`). */\n readonly massKg?: number;\n /** Surface gravity (m/s^2) paired with `radius` (m) -> mu = surfaceG * (radius^2 + softeningM^2)^(3/2) / radius. */\n readonly surfaceG?: number;\n readonly radius?: number;\n /** Plummer softening length epsilon (m) preventing r -> 0 singularities. */\n readonly softeningM?: number;\n}\n\nexport interface KolmoNBodyGravity {\n readonly kind: \"nbody\";\n readonly attractors: readonly KolmoGravityAttractor[];\n readonly gravitationalConstant?: number;\n}\n\nexport interface PreparedGravityAttractor {\n readonly px: number;\n readonly py: number;\n readonly pz: number;\n readonly mu: number;\n readonly epsSq: number;\n}\n\nexport function resolveAttractorMu(\n attractor: KolmoGravityAttractor,\n gravitationalConstant = G_SI,\n): { mu: number; epsSq: number } {\n const rRef = Math.max(0, attractor.radius ?? 0);\n const eps = Math.max(1e-4, attractor.softeningM ?? (rRef > 0 ? rRef * 0.05 : 0.5));\n const epsSq = eps * eps;\n if (typeof attractor.mu === \"number\" && Number.isFinite(attractor.mu)) {\n return { mu: Math.max(0, attractor.mu), epsSq };\n }\n if (typeof attractor.surfaceG === \"number\" && Number.isFinite(attractor.surfaceG) && rRef > 0) {\n const denom = Math.pow(rRef * rRef + epsSq, 1.5);\n return { mu: Math.max(0, (attractor.surfaceG * denom) / rRef), epsSq };\n }\n if (typeof attractor.massKg === \"number\" && Number.isFinite(attractor.massKg)) {\n return { mu: Math.max(0, attractor.massKg * gravitationalConstant), epsSq };\n }\n return { mu: 0, epsSq };\n}\n\nexport function prepareAttractors(\n attractors: readonly KolmoGravityAttractor[],\n gravitationalConstant = G_SI,\n): PreparedGravityAttractor[] {\n const out: PreparedGravityAttractor[] = [];\n for (let i = 0; i < attractors.length; i++) {\n const a = attractors[i];\n const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);\n if (mu > 0) {\n out.push({ px: a.position[0], py: a.position[1], pz: a.position[2], mu, epsSq });\n }\n }\n return out;\n}\n\nexport function evaluatePreparedNBodyGravity(\n pos: { readonly x: number; readonly y: number; readonly z: number },\n prepared: readonly PreparedGravityAttractor[],\n out: THREE.Vector3,\n): THREE.Vector3 {\n let gx = 0, gy = 0, gz = 0;\n for (let i = 0; i < prepared.length; i++) {\n const a = prepared[i];\n const dx = a.px - pos.x;\n const dy = a.py - pos.y;\n const dz = a.pz - pos.z;\n const rSq = dx * dx + dy * dy + dz * dz;\n if (rSq < 1e-12)\n continue;\n const scale = a.mu / Math.pow(rSq + a.epsSq, 1.5);\n gx += dx * scale;\n gy += dy * scale;\n gz += dz * scale;\n }\n return out.set(gx, gy, gz);\n}\n\n/**\n * Evaluates softened Newtonian multi-attractor gravitational acceleration (m/s^2):\n * g(x) = sum_i mu_i * (p_i - x) / (|p_i - x|^2 + eps_i^2)^(3/2)\n */\nexport function evaluateNBodyGravity(\n pos: { readonly x: number; readonly y: number; readonly z: number },\n attractors: readonly KolmoGravityAttractor[],\n out: THREE.Vector3,\n gravitationalConstant = G_SI,\n): THREE.Vector3 {\n let gx = 0, gy = 0, gz = 0;\n for (let i = 0; i < attractors.length; i++) {\n const a = attractors[i];\n const { mu, epsSq } = resolveAttractorMu(a, gravitationalConstant);\n if (mu <= 0)\n continue;\n const dx = a.position[0] - pos.x;\n const dy = a.position[1] - pos.y;\n const dz = a.position[2] - pos.z;\n const rSq = dx * dx + dy * dy + dz * dz;\n if (rSq < 1e-12)\n continue;\n const scale = mu / Math.pow(rSq + epsSq, 1.5);\n gx += dx * scale;\n gy += dy * scale;\n gz += dz * scale;\n }\n return out.set(gx, gy, gz);\n}\n\nexport function createNBodyGravityField(\n attractors: readonly KolmoGravityAttractor[],\n gravitationalConstant = G_SI,\n): (pos: THREE.Vector3, out?: THREE.Vector3) => THREE.Vector3 {\n const prepared = prepareAttractors(attractors, gravitationalConstant);\n return (pos, out = new THREE.Vector3()) => evaluatePreparedNBodyGravity(pos, prepared, out);\n}\n\nexport function computeCircularOrbitSpeed(\n attractor: KolmoGravityAttractor,\n orbitRadiusM: number,\n gravitationalConstant = G_SI,\n): number {\n if (orbitRadiusM <= 0)\n return 0;\n const { mu, epsSq } = resolveAttractorMu(attractor, gravitationalConstant);\n if (mu <= 0)\n return 0;\n return orbitRadiusM * Math.sqrt(mu / Math.pow(orbitRadiusM * orbitRadiusM + epsSq, 1.5));\n}\n","import React, { Suspense, createContext, useContext, useLayoutEffect, useMemo, type ReactNode, type RefObject } from \"react\";\nimport * as THREE from \"three\";\nimport { PhysicsWorld, type PhysicsWorldProps } from \"@khr3/core\";\nimport { useCustomGravity } from \"@pinkaphant/ecctrl/gravity\";\nimport { type World } from \"koota\";\nimport { WorldProvider } from \"koota/react\";\nimport { KolmoWorldContext, kolmoWorld, useOptionalKootaWorld } from \"../engine/traits.js\";\nimport {\n G_SI,\n computeCircularOrbitSpeed,\n createNBodyGravityField,\n evaluateNBodyGravity,\n evaluatePreparedNBodyGravity,\n prepareAttractors,\n resolveAttractorMu,\n type KolmoGravityAttractor,\n type KolmoNBodyGravity,\n type PreparedGravityAttractor,\n} from \"./nBodyGravity.js\";\n\nexport {\n G_SI,\n computeCircularOrbitSpeed,\n createNBodyGravityField,\n evaluateNBodyGravity,\n evaluatePreparedNBodyGravity,\n prepareAttractors,\n resolveAttractorMu,\n useOptionalKootaWorld,\n type KolmoGravityAttractor,\n type KolmoNBodyGravity,\n type PreparedGravityAttractor,\n};\n\nexport type KolmoTimeControlValue = number | RefObject<number>;\n\nexport type KolmoPointGravity = {\n readonly kind: \"point\";\n readonly center: readonly [number, number, number];\n readonly surfaceG: number;\n readonly radius: number;\n readonly inverseSquare?: boolean;\n};\n\nexport type KolmoGravityCallback = (pos: THREE.Vector3, out: THREE.Vector3) => THREE.Vector3;\n\nexport type KolmoGravitySpec =\n | \"planar\"\n | \"zero\"\n | \"custom\"\n | readonly [number, number, number]\n | KolmoPointGravity\n | KolmoNBodyGravity\n | KolmoGravityCallback;\n\nexport const KolmoGravityContext = createContext<boolean>(false);\n\nfunction isGravityTuple(g: KolmoGravitySpec): g is readonly [number, number, number] {\n return Array.isArray(g);\n}\n\nfunction isPointGravity(g: KolmoGravitySpec): g is KolmoPointGravity {\n return typeof g === \"object\" && !Array.isArray(g) && \"kind\" in g && g.kind === \"point\";\n}\n\nfunction isNBodyGravity(g: KolmoGravitySpec): g is KolmoNBodyGravity {\n return typeof g === \"object\" && !Array.isArray(g) && \"kind\" in g && g.kind === \"nbody\";\n}\n\nconst DEFAULT_GRAVITY_FN = (): THREE.Vector3 => new THREE.Vector3(0, -9.81, 0);\n\nexport interface KolmoPhysicsProps extends Omit<PhysicsWorldProps, \"gravity\" | \"debug\" | \"timeScale\" | \"maxDelta\" | \"children\"> {\n readonly gravity?: KolmoGravitySpec;\n readonly paused?: boolean;\n readonly timeScale?: KolmoTimeControlValue;\n readonly maxDelta?: KolmoTimeControlValue;\n readonly physicsDebug?: boolean;\n readonly world?: World | null;\n readonly children: ReactNode;\n}\n\nexport function KolmoPhysics({\n gravity = \"planar\",\n paused = false,\n timeScale = 1,\n maxDelta,\n physicsDebug = false,\n world = null,\n children,\n ...physicsProps\n}: KolmoPhysicsProps): React.JSX.Element {\n const outerWorld = useOptionalKootaWorld();\n const resolvedWorld = world ?? outerWorld ?? kolmoWorld;\n const isCallback = typeof gravity === \"function\";\n const isTuple = isGravityTuple(gravity);\n const isZero = gravity === \"zero\";\n const isCustomLiteral = gravity === \"custom\";\n const isPoint = isPointGravity(gravity);\n const isNBody = isNBodyGravity(gravity);\n const isCustomGravity = isCallback || isPoint || isNBody || isCustomLiteral;\n\n const gx = isTuple ? gravity[0] : 0;\n const gy = isTuple ? gravity[1] : -9.81;\n const gz = isTuple ? gravity[2] : 0;\n const cx = isPoint ? gravity.center[0] : 0;\n const cy = isPoint ? gravity.center[1] : 0;\n const cz = isPoint ? gravity.center[2] : 0;\n const pointRadius = isPoint ? gravity.radius : 1;\n const pointInverseSq = isPoint ? Boolean(gravity.inverseSquare) : false;\n const surfaceG = isPoint ? gravity.surfaceG : isZero ? 0 : 9.81;\n const gravityFn = isCallback ? gravity : null;\n const nBodySpec = isNBody ? gravity : null;\n\n const preparedAttractors = useMemo<readonly PreparedGravityAttractor[]>(() => {\n if (nBodySpec)\n return prepareAttractors(nBodySpec.attractors, nBodySpec.gravitationalConstant);\n if (isPoint && pointInverseSq)\n return prepareAttractors([{ position: [cx, cy, cz], surfaceG, radius: pointRadius }]);\n return [];\n }, [nBodySpec, isPoint, pointInverseSq, cx, cy, cz, surfaceG, pointRadius]);\n\n const rapierGravity = useMemo<[number, number, number]>(\n () => (isTuple ? [gx, gy, gz] : isCustomGravity || isZero ? [0, 0, 0] : [0, -9.81, 0]),\n [isTuple, gx, gy, gz, isCustomGravity, isZero],\n );\n\n useLayoutEffect(() => {\n if (isCustomLiteral || (!isCallback && !isPoint && !isNBody))\n return;\n const scratch = new THREE.Vector3();\n let installed: ((pos: THREE.Vector3) => THREE.Vector3) | null = null;\n if (gravityFn) {\n installed = (pos: THREE.Vector3) => gravityFn(pos, scratch.set(0, 0, 0));\n }\n else if (nBodySpec || (isPoint && pointInverseSq)) {\n installed = (pos: THREE.Vector3) => evaluatePreparedNBodyGravity(pos, preparedAttractors, scratch);\n }\n else if (isPoint) {\n installed = (pos: THREE.Vector3) => {\n scratch.set(pos.x - cx, pos.y - cy, pos.z - cz);\n const lenSq = scratch.lengthSq();\n return lenSq < 1e-8 ? scratch.set(0, -surfaceG, 0) : scratch.multiplyScalar(-surfaceG / Math.sqrt(lenSq));\n };\n }\n if (!installed)\n return;\n useCustomGravity.getState().setGravityField(installed);\n return () => {\n if (useCustomGravity.getState().gravityField === installed) {\n useCustomGravity.getState().setGravityField(DEFAULT_GRAVITY_FN);\n }\n };\n }, [isCustomLiteral, isCallback, isPoint, isNBody, gravityFn, nBodySpec, preparedAttractors, cx, cy, cz, pointInverseSq, surfaceG]);\n\n const content = (\n <KolmoGravityContext.Provider value={isCustomGravity}>\n <PhysicsWorld\n {...physicsProps}\n paused={paused}\n timeScale={timeScale}\n {...(maxDelta === undefined ? {} : { maxDelta })}\n gravity={rapierGravity}\n debug={physicsDebug}\n >\n <Suspense fallback={null}>{children}</Suspense>\n </PhysicsWorld>\n </KolmoGravityContext.Provider>\n );\n\n return resolvedWorld !== outerWorld ? (\n <KolmoWorldContext.Provider value={resolvedWorld}>\n <WorldProvider world={resolvedWorld}>{content}</WorldProvider>\n </KolmoWorldContext.Provider>\n ) : (\n content\n );\n}\n\nexport function useIsKolmoCustomGravity(): boolean {\n return useContext(KolmoGravityContext);\n}\n"],"mappings":";;;;;;;;AAoCA,IAAa,eAAe,aAA+B;CACvD,IAAI;CACJ,QAAQ;CACR,cAAc;CACd,YAAY;EAAC;EAAG;EAAM;CAAC;CACvB,YAAY;EAAC;EAAM;EAAM;CAAC;CAC1B,UAAU;AACd,EAAE;AAEF,IAAa,aAAa,aAA6B;CACnD,IAAI;CACJ,QAAQ;CACR,cAAc;CACd,cAAc;CACd,YAAY;AAChB,EAAE;AAEF,IAAa,iBAAiB,MAAM;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG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AA;CACY,CAAA;CAGlC,OAAO,kBAAkB,aACrBA,oBAAC,kBAAkB,UAAnB;EAA4B,OAAO;EAC/B,UAAAA,oBAAC,eAAD;GAAe,OAAO;GAAgB,UAAA;EAAuB,CAAA;CACrC,CAAA,IAE5B;AAER;AAEA,SAAgB,0BAAmC;CAC/C,OAAO,WAAW,mBAAmB;AACzC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import * as THREE from "three";
|
|
3
|
-
import { type PieceKind, type PlacedPiece } from "@khr3/c12";
|
|
4
|
-
import type { BuildSnapCandidate } from "./store.js";
|
|
5
|
-
export declare const WALL_THICK = 0.2;
|
|
6
|
-
export declare const SLAB_THICK = 0.2;
|
|
7
|
-
interface SharedC12Resources {
|
|
8
|
-
readonly slabGeo: THREE.BoxGeometry;
|
|
9
|
-
readonly wallGeo: THREE.BoxGeometry;
|
|
10
|
-
readonly jambGeo: THREE.BoxGeometry;
|
|
11
|
-
readonly lintelGeo: THREE.BoxGeometry;
|
|
12
|
-
readonly rampGeo: THREE.BoxGeometry;
|
|
13
|
-
readonly triGroundGeo: THREE.BufferGeometry;
|
|
14
|
-
readonly triUpperGeo: THREE.BufferGeometry;
|
|
15
|
-
readonly triGroundVerts: Float32Array;
|
|
16
|
-
readonly triUpperVerts: Float32Array;
|
|
17
|
-
readonly slabMat: THREE.MeshStandardMaterial;
|
|
18
|
-
readonly roofMat: THREE.MeshStandardMaterial;
|
|
19
|
-
readonly streetMat: THREE.MeshStandardMaterial;
|
|
20
|
-
readonly wallMat: THREE.MeshStandardMaterial;
|
|
21
|
-
readonly stairMat: THREE.MeshStandardMaterial;
|
|
22
|
-
readonly ghostValidMat: THREE.MeshBasicMaterial;
|
|
23
|
-
readonly ghostInvalidMat: THREE.MeshBasicMaterial;
|
|
24
|
-
}
|
|
25
|
-
export declare function getSharedC12Resources(): SharedC12Resources;
|
|
26
|
-
export declare function C12PieceMeshes({ kind, overrideMaterial, }: {
|
|
27
|
-
kind: PieceKind;
|
|
28
|
-
overrideMaterial?: THREE.Material;
|
|
29
|
-
}): React.JSX.Element;
|
|
30
|
-
export declare function C12PieceColliderAndMesh({ piece }: {
|
|
31
|
-
piece: PlacedPiece;
|
|
32
|
-
}): React.JSX.Element;
|
|
33
|
-
export declare function BuildGhostPreview({ candidate }: {
|
|
34
|
-
candidate: BuildSnapCandidate;
|
|
35
|
-
}): React.JSX.Element;
|
|
36
|
-
export {};
|