@luma.gl/graph 10.0.0-alpha.15 → 10.0.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow/arrow-utils/arrow-paths.cjs +4 -3
- package/dist/arrow/arrow-utils/arrow-paths.d.ts.map +1 -1
- package/dist/arrow/arrow-utils/arrow-paths.js +5 -4
- package/dist/arrow/arrow-utils/arrow-paths.js.map +1 -1
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.cjs +9 -10
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts +3 -4
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts.map +1 -1
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js +2 -3
- package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js.map +1 -1
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.cjs +10 -10
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js +2 -2
- package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js.map +1 -1
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.cjs +2 -2
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js +1 -1
- package/dist/arrow/geoarrow/arrow-polygon-tessellation.js.map +1 -1
- package/dist/arrow/index.cjs.map +2 -2
- package/dist/arrow/internal.cjs.map +2 -2
- package/dist/dist.dev.js +3 -3
- package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
- package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
- package/dist/gpu-core/gpu-expression-operation.js +1 -1
- package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
- package/dist/gpu-dataframe/portable-expression.cjs +1 -1
- package/dist/gpu-dataframe/portable-expression.d.ts +2 -2
- package/dist/gpu-dataframe/portable-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/portable-expression.js +2 -2
- package/dist/gpu-dataframe/portable-expression.js.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +159 -1
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +21 -0
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +178 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +2 -2
- package/dist/gpu-physics/index.d.ts +1 -0
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-vehicle.cjs +90 -0
- package/dist/gpu-physics/rigid-body-vehicle.d.ts +35 -0
- package/dist/gpu-physics/rigid-body-vehicle.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-vehicle.js +66 -0
- package/dist/gpu-physics/rigid-body-vehicle.js.map +1 -0
- package/dist/gpu-project/cpu-geoarrow.d.ts +1 -1
- package/dist/gpu-project/cpu-geoarrow.d.ts.map +1 -1
- package/dist/gpu-project/cpu-geometry-pipelines.cjs +2 -2
- package/dist/gpu-project/cpu-geometry-pipelines.d.ts +2 -1
- package/dist/gpu-project/cpu-geometry-pipelines.d.ts.map +1 -1
- package/dist/gpu-project/cpu-geometry-pipelines.js +1 -1
- package/dist/gpu-project/cpu-geometry-pipelines.js.map +1 -1
- package/dist/gpu-project/geoarrow.cjs.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +8 -4
- package/dist/gpu-sql/gpu-sql.js +5 -1
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +1 -1
- package/package.json +8 -8
- package/src/arrow/arrow-utils/arrow-paths.ts +5 -3
- package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +4 -6
- package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +2 -2
- package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +1 -1
- package/src/gpu-core/gpu-expression-operation.ts +1 -1
- package/src/gpu-dataframe/portable-expression.ts +2 -2
- package/src/gpu-physics/gpu-rigid-body-world.ts +219 -1
- package/src/gpu-physics/index.ts +1 -0
- package/src/gpu-physics/rigid-body-vehicle.ts +99 -0
- package/src/gpu-project/cpu-geoarrow.ts +1 -1
- package/src/gpu-project/cpu-geometry-pipelines.ts +2 -2
- package/src/gpu-sql/gpu-sql.ts +4 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {tessellateGeoArrowPolygons} from '@math.gl/arrow
|
|
5
|
+
import {tessellateGeoArrowPolygons} from '@math.gl/geometry/arrow';
|
|
6
6
|
import {
|
|
7
7
|
DataType,
|
|
8
8
|
DenseUnion,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {parse, type Expression} from '@math.gl/expressions';
|
|
5
|
+
import {parse, type Expression} from '@math.gl/sql/expressions';
|
|
6
6
|
import {getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
7
7
|
import {gpuGraph, type GPUGraphVectorFormat} from './gpu-graph-value';
|
|
8
8
|
import type {GPUOperationContract} from './gpu-operation-contract';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Independently implemented for WebGPU; inspired by NVIDIA RAPIDS cuDF.
|
|
5
5
|
|
|
6
|
-
import {validateExpressionAST, type Expression} from '@math.gl/expressions';
|
|
6
|
+
import {validateExpressionAST, type Expression} from '@math.gl/sql/expressions';
|
|
7
7
|
import {
|
|
8
8
|
GPUExpression,
|
|
9
9
|
isBooleanExpressionNode,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
*
|
|
19
19
|
* @example
|
|
20
20
|
* ```ts
|
|
21
|
-
* import {parseSQLExpression} from '@math.gl/
|
|
21
|
+
* import {parseSQLExpression} from '@math.gl/sql/parser';
|
|
22
22
|
*
|
|
23
23
|
* const position = makeGPUExpressionFromPortableAST(
|
|
24
24
|
* parseSQLExpression('ARRAY[x,y,z]::REAL[3]')
|
|
@@ -76,6 +76,8 @@ import {
|
|
|
76
76
|
import {addRigidBodyPosePublication, type GPURigidBodyBounds} from './rigid-body-publication';
|
|
77
77
|
import {getRigidBodyShader} from './rigid-body-shaders';
|
|
78
78
|
|
|
79
|
+
import {VEHICLE_SHADER, type GPURigidBodyVehicle} from './rigid-body-vehicle';
|
|
80
|
+
|
|
79
81
|
type Vector3 = readonly [number, number, number];
|
|
80
82
|
import {
|
|
81
83
|
decodeRigidBodyContactEvents,
|
|
@@ -128,6 +130,8 @@ export type GPURigidBodyWorldProps = {
|
|
|
128
130
|
/** Up to 64 joints. Parallel solving supports static-anchored distance joints only. */
|
|
129
131
|
joints?: readonly GPURigidBodyJoint[];
|
|
130
132
|
gravity?: Vector3;
|
|
133
|
+
/** Optional four-wheel suspension evaluated against static terrain each fixed step. */
|
|
134
|
+
vehicle?: GPURigidBodyVehicle;
|
|
131
135
|
timeStep?: number;
|
|
132
136
|
iterations?: number;
|
|
133
137
|
contactSlop?: number;
|
|
@@ -228,6 +232,7 @@ export class GPURigidBodyWorld {
|
|
|
228
232
|
private eventRead: Promise<GPURigidBodyContactBatch> | null = null;
|
|
229
233
|
private queryComputation: BoundKernel | null = null;
|
|
230
234
|
private queryReduction: BoundKernel | null = null;
|
|
235
|
+
private vehicleBuffer: Buffer | null = null;
|
|
231
236
|
private querySettings: Buffer | null = null;
|
|
232
237
|
private querySelection: Buffer | null = null;
|
|
233
238
|
private queryOutput: Buffer | null = null;
|
|
@@ -505,8 +510,35 @@ export class GPURigidBodyWorld {
|
|
|
505
510
|
}
|
|
506
511
|
// Clone together so collider edits preserve geometry identity in captured body definitions.
|
|
507
512
|
const definitions = structuredClone({colliders, props});
|
|
508
|
-
this.colliders = definitions.colliders;
|
|
509
513
|
this.props = definitions.props;
|
|
514
|
+
this.colliders = definitions.colliders;
|
|
515
|
+
const vehicle = this.props.vehicle;
|
|
516
|
+
if (vehicle) {
|
|
517
|
+
const terrain = this.colliders[vehicle.terrainCollider];
|
|
518
|
+
const chassis = this.props.bodies[vehicle.chassis];
|
|
519
|
+
const ground = terrain && this.props.bodies[terrain.body];
|
|
520
|
+
if (
|
|
521
|
+
!chassis ||
|
|
522
|
+
!ground ||
|
|
523
|
+
vehicle.chassis === terrain.body ||
|
|
524
|
+
(chassis.mode ?? (chassis.mass === 0 ? 'static' : 'dynamic')) !== 'dynamic' ||
|
|
525
|
+
(ground.mode ?? (ground.mass === 0 ? 'static' : 'dynamic')) !== 'static' ||
|
|
526
|
+
vehicle.wheels.length !== 4 ||
|
|
527
|
+
this.props.failurePolicy === 'rollback' ||
|
|
528
|
+
this.props.ensembleBodiesPerInstance ||
|
|
529
|
+
![vehicle.radius, vehicle.travel, vehicle.springRate, vehicle.wheelInertia].every(
|
|
530
|
+
value => Number.isFinite(value) && value > 0
|
|
531
|
+
) ||
|
|
532
|
+
![vehicle.damping, vehicle.grip, vehicle.motorTorque, vehicle.brakeTorque].every(
|
|
533
|
+
value => Number.isFinite(value) && value >= 0
|
|
534
|
+
) ||
|
|
535
|
+
vehicle.wheels.some(
|
|
536
|
+
wheel => wheel.mount.length !== 3 || !wheel.mount.every(Number.isFinite)
|
|
537
|
+
)
|
|
538
|
+
)
|
|
539
|
+
throw new Error('Invalid vehicle configuration');
|
|
540
|
+
}
|
|
541
|
+
|
|
510
542
|
if (props.ensembleBodiesPerInstance)
|
|
511
543
|
this.initialEnsembleBodies = this.props.bodies.slice(0, props.ensembleBodiesPerInstance);
|
|
512
544
|
}
|
|
@@ -541,6 +573,8 @@ export class GPURigidBodyWorld {
|
|
|
541
573
|
this.props.ensembleBodiesPerInstance ? this.count / this.props.ensembleBodiesPerInstance : 0
|
|
542
574
|
)
|
|
543
575
|
};
|
|
576
|
+
if (this.props.vehicle)
|
|
577
|
+
storage.buffers.push({name: 'vehicle', byteLength: 512, uniform: false});
|
|
544
578
|
if (this.props.continuous?.mode === 'convex') {
|
|
545
579
|
storage.buffers = storage.buffers.filter(buffer => buffer.name !== 'continuous-previous');
|
|
546
580
|
storage.buffers.push({name: 'continuous-dispatch', byteLength: 16, uniform: false});
|
|
@@ -1235,6 +1269,120 @@ export class GPURigidBodyWorld {
|
|
|
1235
1269
|
parallelMarkSleep: 'Identify islands whose bodies are quiet enough to sleep.',
|
|
1236
1270
|
parallelSleep: 'Put quiet constraint islands to sleep.'
|
|
1237
1271
|
};
|
|
1272
|
+
const vehicle = this.props.vehicle;
|
|
1273
|
+
if (vehicle) {
|
|
1274
|
+
const data = new Float32Array(128);
|
|
1275
|
+
data.set(
|
|
1276
|
+
[
|
|
1277
|
+
vehicle.radius,
|
|
1278
|
+
vehicle.travel,
|
|
1279
|
+
vehicle.springRate,
|
|
1280
|
+
vehicle.damping,
|
|
1281
|
+
vehicle.grip,
|
|
1282
|
+
vehicle.motorTorque,
|
|
1283
|
+
vehicle.brakeTorque,
|
|
1284
|
+
vehicle.wheelInertia
|
|
1285
|
+
],
|
|
1286
|
+
4
|
|
1287
|
+
);
|
|
1288
|
+
new Uint32Array(data.buffer).set([vehicle.chassis, vehicle.terrainCollider], 12);
|
|
1289
|
+
vehicle.wheels.forEach((wheel, index) => {
|
|
1290
|
+
const offset = 16 + index * 12;
|
|
1291
|
+
data.set(wheel.mount, offset);
|
|
1292
|
+
data.set([Number(Boolean(wheel.steer)), Number(Boolean(wheel.drive))], offset + 4);
|
|
1293
|
+
data[offset + 10] = vehicle.travel;
|
|
1294
|
+
data.set(
|
|
1295
|
+
[
|
|
1296
|
+
1,
|
|
1297
|
+
0,
|
|
1298
|
+
0,
|
|
1299
|
+
0,
|
|
1300
|
+
0,
|
|
1301
|
+
1,
|
|
1302
|
+
0,
|
|
1303
|
+
0,
|
|
1304
|
+
0,
|
|
1305
|
+
0,
|
|
1306
|
+
1,
|
|
1307
|
+
0,
|
|
1308
|
+
wheel.mount[0],
|
|
1309
|
+
wheel.mount[1],
|
|
1310
|
+
wheel.mount[2] - vehicle.travel,
|
|
1311
|
+
1
|
|
1312
|
+
],
|
|
1313
|
+
64 + 16 * index
|
|
1314
|
+
);
|
|
1315
|
+
});
|
|
1316
|
+
this.vehicleBuffer = allocate('vehicle', data);
|
|
1317
|
+
const vehicleBindings = [
|
|
1318
|
+
...bindings.filter(binding =>
|
|
1319
|
+
[
|
|
1320
|
+
'settings',
|
|
1321
|
+
'positions',
|
|
1322
|
+
'orientations',
|
|
1323
|
+
'velocities',
|
|
1324
|
+
'angularVelocities',
|
|
1325
|
+
'bodies',
|
|
1326
|
+
'sleepStates'
|
|
1327
|
+
].includes(binding.name)
|
|
1328
|
+
),
|
|
1329
|
+
{
|
|
1330
|
+
name: 'vehicle',
|
|
1331
|
+
location: 12,
|
|
1332
|
+
buffer: this.vehicleBuffer,
|
|
1333
|
+
resource: graph.importBuffer(
|
|
1334
|
+
{id: this.id + '-vehicle', byteLength: data.byteLength, usage: Buffer.STORAGE},
|
|
1335
|
+
this.vehicleBuffer
|
|
1336
|
+
)
|
|
1337
|
+
}
|
|
1338
|
+
];
|
|
1339
|
+
const properties: BoundKernelProps = {
|
|
1340
|
+
id: this.id + '-suspension',
|
|
1341
|
+
source: source + RIGID_BODY_QUERY_GEOMETRY_SHADER + VEHICLE_SHADER,
|
|
1342
|
+
entryPoint: 'advanceVehicle',
|
|
1343
|
+
shaderLayout: {
|
|
1344
|
+
bindings: vehicleBindings.map(
|
|
1345
|
+
({name, location}): BindingDeclaration =>
|
|
1346
|
+
name === 'settings'
|
|
1347
|
+
? {name, location, group: 0, type: 'uniform'}
|
|
1348
|
+
: {
|
|
1349
|
+
name,
|
|
1350
|
+
location,
|
|
1351
|
+
group: 0,
|
|
1352
|
+
type: name === 'bodies' ? 'read-only-storage' : 'storage'
|
|
1353
|
+
}
|
|
1354
|
+
)
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
const executable = (
|
|
1358
|
+
computation: BoundKernel
|
|
1359
|
+
): GPUCommandGraphComputeExecutable<Parameters> => ({
|
|
1360
|
+
encode: ({computePass, getBuffer}) => {
|
|
1361
|
+
Object.assign(
|
|
1362
|
+
computation.bindings,
|
|
1363
|
+
Object.fromEntries(
|
|
1364
|
+
vehicleBindings.map(binding => [binding.name, getBuffer(binding.resource)])
|
|
1365
|
+
)
|
|
1366
|
+
);
|
|
1367
|
+
computation.kernel.dispatch(computePass, {bindings: computation.bindings, x: 1});
|
|
1368
|
+
},
|
|
1369
|
+
destroy: () => computation.kernel.destroy()
|
|
1370
|
+
});
|
|
1371
|
+
graph.addComputePass({
|
|
1372
|
+
id: properties.id!,
|
|
1373
|
+
resources: vehicleBindings.map(binding => ({
|
|
1374
|
+
buffer: binding.resource,
|
|
1375
|
+
usage:
|
|
1376
|
+
binding.name === 'settings'
|
|
1377
|
+
? 'uniform'
|
|
1378
|
+
: binding.name === 'bodies'
|
|
1379
|
+
? 'storage-read'
|
|
1380
|
+
: 'storage-read-write'
|
|
1381
|
+
})),
|
|
1382
|
+
compile: () => executable(createBoundKernel(graph.device, properties)),
|
|
1383
|
+
compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
|
|
1384
|
+
});
|
|
1385
|
+
}
|
|
1238
1386
|
for (const entryPoint of [
|
|
1239
1387
|
...(this.ensembleBuffer
|
|
1240
1388
|
? ['ensembleClear', 'ensembleMark', 'ensembleCompact', 'ensembleDispatch']
|
|
@@ -1988,6 +2136,76 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
1988
2136
|
: undefined;
|
|
1989
2137
|
}
|
|
1990
2138
|
|
|
2139
|
+
/** Set signed throttle, steering angle in radians and brake fraction for upcoming substeps. */
|
|
2140
|
+
setVehicleControls(throttle: number, steering: number, brake: number): void {
|
|
2141
|
+
if (
|
|
2142
|
+
!this.vehicleBuffer ||
|
|
2143
|
+
this.destroyed ||
|
|
2144
|
+
![throttle, steering, brake].every(Number.isFinite)
|
|
2145
|
+
)
|
|
2146
|
+
throw new Error('Invalid vehicle controls');
|
|
2147
|
+
this.vehicleBuffer.write(
|
|
2148
|
+
new Float32Array([
|
|
2149
|
+
Math.max(-1, Math.min(1, throttle)),
|
|
2150
|
+
steering,
|
|
2151
|
+
Math.max(0, Math.min(1, brake)),
|
|
2152
|
+
0
|
|
2153
|
+
])
|
|
2154
|
+
);
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
/** Borrow four column-major wheel transforms relative to the chassis node, ordered by mount. */
|
|
2158
|
+
get vehicleWheelPoses() {
|
|
2159
|
+
return this.vehicleBuffer && !this.destroyed
|
|
2160
|
+
? {buffer: this.vehicleBuffer, byteOffset: 256, byteLength: 256}
|
|
2161
|
+
: null;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
/** Transfer wheel motion between rebuilt worlds for wheels with matching chassis-local mounts. */
|
|
2165
|
+
copyVehicleMotionFrom(previous: GPURigidBodyWorld): void {
|
|
2166
|
+
const sourceBuffer = previous.vehicleBuffer;
|
|
2167
|
+
const destinationBuffer = this.vehicleBuffer;
|
|
2168
|
+
const previousVehicle = previous.props.vehicle;
|
|
2169
|
+
if (!this.device || !sourceBuffer || !destinationBuffer || !previousVehicle) return;
|
|
2170
|
+
const encoder = this.device.createCommandEncoder();
|
|
2171
|
+
this.props.vehicle?.wheels.forEach((wheel, index) => {
|
|
2172
|
+
const sourceIndex = previousVehicle.wheels.findIndex(source =>
|
|
2173
|
+
source.mount.every((coordinate, axis) => coordinate === wheel.mount[axis])
|
|
2174
|
+
);
|
|
2175
|
+
if (sourceIndex < 0) return;
|
|
2176
|
+
encoder.copyBufferToBuffer({
|
|
2177
|
+
sourceBuffer,
|
|
2178
|
+
destinationBuffer,
|
|
2179
|
+
sourceOffset: 96 + sourceIndex * 48,
|
|
2180
|
+
destinationOffset: 96 + index * 48,
|
|
2181
|
+
size: 16
|
|
2182
|
+
});
|
|
2183
|
+
encoder.copyBufferToBuffer({
|
|
2184
|
+
sourceBuffer,
|
|
2185
|
+
destinationBuffer,
|
|
2186
|
+
sourceOffset: 256 + sourceIndex * 64,
|
|
2187
|
+
destinationOffset: 256 + index * 64,
|
|
2188
|
+
size: 64
|
|
2189
|
+
});
|
|
2190
|
+
});
|
|
2191
|
+
this.device.submit(encoder.finish());
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
/** Read wheel spin, angle, suspension length and normal load after submitted steps. */
|
|
2195
|
+
async readVehicleWheels() {
|
|
2196
|
+
if (!this.vehicleBuffer || this.destroyed) throw new Error('Vehicle unavailable');
|
|
2197
|
+
const values = new Float32Array((await this.vehicleBuffer.readAsync(0, 256)).buffer);
|
|
2198
|
+
return Array.from({length: 4}, (_, index) => {
|
|
2199
|
+
const offset = 24 + index * 12;
|
|
2200
|
+
return {
|
|
2201
|
+
speed: values[offset],
|
|
2202
|
+
angle: values[offset + 1],
|
|
2203
|
+
length: values[offset + 2],
|
|
2204
|
+
load: values[offset + 3]
|
|
2205
|
+
};
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
|
|
1991
2209
|
/** Submit an impulse at a world-space point, or the current GPU center of mass when omitted. */
|
|
1992
2210
|
applyImpulse(body: number, impulse: Vector3, point?: Vector3): void {
|
|
1993
2211
|
if (
|
package/src/gpu-physics/index.ts
CHANGED
|
@@ -116,3 +116,4 @@ export type {GPURigidBodyJointLimit, GPURigidBodyJointDrive} from './joint-types
|
|
|
116
116
|
|
|
117
117
|
export {rotateRigidBodyVector, normalizeRigidBodyRotation} from './rigid-body-properties';
|
|
118
118
|
export type {GPURigidBodyGeneralConstraint} from './rigid-body-general-joints';
|
|
119
|
+
export type {GPURigidBodyVehicle} from './rigid-body-vehicle';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Four independently sprung wheels in a chassis frame with +X forward and +Z up. */
|
|
6
|
+
export type GPURigidBodyVehicle = {
|
|
7
|
+
/** Index of the dynamic chassis body. */
|
|
8
|
+
chassis: number;
|
|
9
|
+
/** Index of the static collider sampled by all wheels. */
|
|
10
|
+
terrainCollider: number;
|
|
11
|
+
/** Four independently suspended wheels, in rendering and telemetry order. */
|
|
12
|
+
wheels: readonly {
|
|
13
|
+
/** At full compression the wheel center is here, in chassis node coordinates (meters). */
|
|
14
|
+
mount: readonly [number, number, number];
|
|
15
|
+
/** Turn this wheel about chassis +Z by the commanded steering angle. */
|
|
16
|
+
steer?: boolean;
|
|
17
|
+
/** Apply the commanded drive torque to this wheel. */
|
|
18
|
+
drive?: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
/** Wheel contact sphere radius in meters. */
|
|
21
|
+
radius: number;
|
|
22
|
+
/** Maximum downward distance of the wheel center from its mount in meters. */
|
|
23
|
+
travel: number;
|
|
24
|
+
/** Per-wheel spring stiffness in newtons per meter. */
|
|
25
|
+
springRate: number;
|
|
26
|
+
/** Per-wheel damping coefficient in newton seconds per meter. */
|
|
27
|
+
damping: number;
|
|
28
|
+
/** Dimensionless tire friction coefficient limiting combined longitudinal and lateral force. */
|
|
29
|
+
grip: number;
|
|
30
|
+
/** Torque per driven wheel in N m. */
|
|
31
|
+
motorTorque: number;
|
|
32
|
+
/** Maximum braking torque per wheel in newton meters. */
|
|
33
|
+
brakeTorque: number;
|
|
34
|
+
/** Rotational inertia of one wheel in kilogram meters squared. */
|
|
35
|
+
wheelInertia: number;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** One invocation owns the chassis. All wheels sample the same pre-step velocity. */
|
|
39
|
+
export const VEHICLE_SHADER = /* wgsl */ `
|
|
40
|
+
struct Wheel { mount:vec4f, flags:vec4f, state:vec4f }
|
|
41
|
+
struct Vehicle { controls:vec4f, geometry:vec4f, tire:vec4f, indices:vec4u, wheels:array<Wheel,4>, poses:array<mat4x4f,4> }
|
|
42
|
+
@group(0) @binding(12) var<storage,read_write> vehicle:Vehicle;
|
|
43
|
+
@compute @workgroup_size(1) fn advanceVehicle() {
|
|
44
|
+
let chassis=vehicle.indices.x;
|
|
45
|
+
let terrain=vehicle.indices.y;
|
|
46
|
+
let rotation=orientations[chassis];
|
|
47
|
+
let center=positions[chassis].xyz;
|
|
48
|
+
let down=rotate(rotation,vec3f(0,0,-1));
|
|
49
|
+
let radius=vehicle.geometry.x;
|
|
50
|
+
let travel=vehicle.geometry.y;
|
|
51
|
+
let timestep=settings.gravity.w;
|
|
52
|
+
var impulse=vec3f(0);
|
|
53
|
+
var torque=vec3f(0);
|
|
54
|
+
for(var index=0u;index<4u;index++){
|
|
55
|
+
let wheel=vehicle.wheels[index];
|
|
56
|
+
let mount=center+rotate(rotation,wheel.mount.xyz-bodyCenter(chassis));
|
|
57
|
+
let hit=sweepSphere(terrain,colliderLocal(terrain,mount-colliderPosition(terrain)),colliderLocal(terrain,down),travel,radius,false);
|
|
58
|
+
var speed=wheel.state.x+vehicle.controls.x*vehicle.tire.y*wheel.flags.y*timestep/vehicle.tire.w;
|
|
59
|
+
speed-=sign(speed)*min(abs(speed),vehicle.controls.z*vehicle.tire.z*timestep/vehicle.tire.w);
|
|
60
|
+
let steering=vehicle.controls.y*wheel.flags.x;
|
|
61
|
+
var lengthNow=travel;
|
|
62
|
+
var load=0.0;
|
|
63
|
+
if(hit.hit!=0u && hit.complete!=0u){
|
|
64
|
+
let normal=rotate(colliderRotation(terrain),hit.normal);
|
|
65
|
+
let support=dot(normal,-down);
|
|
66
|
+
if(support>0.15){
|
|
67
|
+
lengthNow=hit.distance;
|
|
68
|
+
let lever=colliderPosition(terrain)+rotate(colliderRotation(terrain),hit.point)-center;
|
|
69
|
+
let velocity=velocities[chassis].xyz+cross(angularVelocities[chassis].xyz,lever);
|
|
70
|
+
load=max(0.0,(travel-lengthNow)*vehicle.geometry.z-vehicle.geometry.w*dot(velocity,normal)/support);
|
|
71
|
+
let heading=rotate(rotation,vec3f(cos(steering),sin(steering),0));
|
|
72
|
+
let side=normalize(cross(normal,heading));
|
|
73
|
+
let forward=cross(side,normal);
|
|
74
|
+
let slip=vec2f(speed*radius-dot(velocity,forward),-dot(velocity,side));
|
|
75
|
+
let demand=slip*load*vec2f(1.1,1.5);
|
|
76
|
+
var friction=demand*min(1.0,vehicle.tire.x*load/max(length(demand),0.0001));
|
|
77
|
+
// Bound tire feedback so a light wheel cannot overshoot rolling speed in one step.
|
|
78
|
+
let longitudinalLimit=abs(slip.x)*vehicle.tire.w/(radius*radius*timestep);
|
|
79
|
+
friction.x=clamp(friction.x,-longitudinalLimit,longitudinalLimit);
|
|
80
|
+
let change=(normal*load+forward*friction.x+side*friction.y)*timestep;
|
|
81
|
+
impulse+=change;
|
|
82
|
+
torque+=cross(lever,change);
|
|
83
|
+
speed-=friction.x*radius*timestep/vehicle.tire.w;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let angle=wheel.state.y+speed*timestep;
|
|
87
|
+
vehicle.wheels[index].state=vec4f(speed,angle,lengthNow,load);
|
|
88
|
+
let heading=vec3f(cos(steering),sin(steering),0);
|
|
89
|
+
let axle=vec3f(-sin(steering),cos(steering),0);
|
|
90
|
+
let vertical=vec3f(0,0,1);
|
|
91
|
+
let hub=wheel.mount.xyz-vertical*lengthNow;
|
|
92
|
+
vehicle.poses[index]=mat4x4f(vec4f(heading*cos(angle)-vertical*sin(angle),0),
|
|
93
|
+
vec4f(axle,0),vec4f(heading*sin(angle)+vertical*cos(angle),0),vec4f(hub,1));
|
|
94
|
+
}
|
|
95
|
+
velocities[chassis]=vec4f(velocities[chassis].xyz+impulse*velocities[chassis].w,velocities[chassis].w);
|
|
96
|
+
angularVelocities[chassis]=vec4f(angularVelocities[chassis].xyz+inverseInertia(chassis,torque),0);
|
|
97
|
+
sleepStates[chassis]=vec4f(0);
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
GeoArrowDimension,
|
|
11
11
|
GeoArrowArray,
|
|
12
12
|
GeoArrowFixedSizeList
|
|
13
|
-
} from '@math.gl/arrow
|
|
13
|
+
} from '@math.gl/core/arrow';
|
|
14
14
|
|
|
15
15
|
/** Borrow CPU coordinate chunks as native GeoArrow points or single-level coordinate lists. */
|
|
16
16
|
export function makeGeoArrowColumnFromCPUVector(
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
import {assert} from '@luma.gl/core';
|
|
7
7
|
import {CPUData, CPUVector, getGPUVectorFormatInfo} from '@luma.gl/graph/gpu-data';
|
|
8
8
|
import type {Projection} from '@math.gl/geospatial/projection/types';
|
|
9
|
+
import type {GeoArrowColumn} from '@math.gl/core/arrow';
|
|
9
10
|
import {
|
|
10
11
|
tessellateGeoArrowPolygons,
|
|
11
|
-
type GeoArrowColumn,
|
|
12
12
|
type TessellateGeoArrowPolygonsOptions
|
|
13
|
-
} from '@math.gl/arrow
|
|
13
|
+
} from '@math.gl/geometry/arrow';
|
|
14
14
|
import {makeGeoArrowColumnFromCPUVector, makeCPUVectorFromGeoArrowColumn} from './cpu-geoarrow';
|
|
15
15
|
|
|
16
16
|
/** Project Float32 coordinates while retaining single-level row topology and null rows. */
|
package/src/gpu-sql/gpu-sql.ts
CHANGED
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
parseSQLSelectStatement,
|
|
9
9
|
SQLParseError,
|
|
10
10
|
type SQLSelectStatement
|
|
11
|
-
} from '@math.gl/
|
|
12
|
-
import type {Expression} from '@math.gl/expressions';
|
|
11
|
+
} from '@math.gl/sql/parser';
|
|
12
|
+
import type {Expression} from '@math.gl/sql/expressions';
|
|
13
13
|
import type {GPUCommandGraph} from '@luma.gl/graph/gpu-core';
|
|
14
14
|
import {GPUDataFrame} from '../gpu-dataframe/gpu-data-frame';
|
|
15
15
|
import {GPUDataFrameQuery} from '../gpu-dataframe/gpu-data-frame-query';
|
|
@@ -366,6 +366,8 @@ function parseGPUSQLStatement(
|
|
|
366
366
|
const join = statement.joins[0];
|
|
367
367
|
let loweredJoin: GPUSQLStatement['join'];
|
|
368
368
|
if (join) {
|
|
369
|
+
if (join.unnest) throw new Error('GPUSQL does not support JOIN UNNEST');
|
|
370
|
+
if (join.type === 'cross') throw new Error('GPUSQL does not support CROSS JOIN');
|
|
369
371
|
if (join.on.type !== 'BinaryExpression' || join.on.operator !== '==') {
|
|
370
372
|
throw new Error('GPUSQL JOIN requires equality between two columns');
|
|
371
373
|
}
|