@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.
Files changed (66) hide show
  1. package/dist/arrow/arrow-utils/arrow-paths.cjs +4 -3
  2. package/dist/arrow/arrow-utils/arrow-paths.d.ts.map +1 -1
  3. package/dist/arrow/arrow-utils/arrow-paths.js +5 -4
  4. package/dist/arrow/arrow-utils/arrow-paths.js.map +1 -1
  5. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.cjs +9 -10
  6. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts +3 -4
  7. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.d.ts.map +1 -1
  8. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js +2 -3
  9. package/dist/arrow/geoarrow/arrow-geoarrow-adapter.js.map +1 -1
  10. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.cjs +10 -10
  11. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js +2 -2
  12. package/dist/arrow/geoarrow/arrow-geoarrow-conversion.js.map +1 -1
  13. package/dist/arrow/geoarrow/arrow-polygon-tessellation.cjs +2 -2
  14. package/dist/arrow/geoarrow/arrow-polygon-tessellation.js +1 -1
  15. package/dist/arrow/geoarrow/arrow-polygon-tessellation.js.map +1 -1
  16. package/dist/arrow/index.cjs.map +2 -2
  17. package/dist/arrow/internal.cjs.map +2 -2
  18. package/dist/dist.dev.js +3 -3
  19. package/dist/gpu-core/gpu-expression-operation.cjs +1 -1
  20. package/dist/gpu-core/gpu-expression-operation.d.ts +1 -1
  21. package/dist/gpu-core/gpu-expression-operation.d.ts.map +1 -1
  22. package/dist/gpu-core/gpu-expression-operation.js +1 -1
  23. package/dist/gpu-core/gpu-expression-operation.js.map +1 -1
  24. package/dist/gpu-dataframe/portable-expression.cjs +1 -1
  25. package/dist/gpu-dataframe/portable-expression.d.ts +2 -2
  26. package/dist/gpu-dataframe/portable-expression.d.ts.map +1 -1
  27. package/dist/gpu-dataframe/portable-expression.js +2 -2
  28. package/dist/gpu-dataframe/portable-expression.js.map +1 -1
  29. package/dist/gpu-physics/gpu-rigid-body-world.cjs +159 -1
  30. package/dist/gpu-physics/gpu-rigid-body-world.d.ts +21 -0
  31. package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
  32. package/dist/gpu-physics/gpu-rigid-body-world.js +178 -1
  33. package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
  34. package/dist/gpu-physics/index.cjs.map +2 -2
  35. package/dist/gpu-physics/index.d.ts +1 -0
  36. package/dist/gpu-physics/index.d.ts.map +1 -1
  37. package/dist/gpu-physics/rigid-body-vehicle.cjs +90 -0
  38. package/dist/gpu-physics/rigid-body-vehicle.d.ts +35 -0
  39. package/dist/gpu-physics/rigid-body-vehicle.d.ts.map +1 -0
  40. package/dist/gpu-physics/rigid-body-vehicle.js +66 -0
  41. package/dist/gpu-physics/rigid-body-vehicle.js.map +1 -0
  42. package/dist/gpu-project/cpu-geoarrow.d.ts +1 -1
  43. package/dist/gpu-project/cpu-geoarrow.d.ts.map +1 -1
  44. package/dist/gpu-project/cpu-geometry-pipelines.cjs +2 -2
  45. package/dist/gpu-project/cpu-geometry-pipelines.d.ts +2 -1
  46. package/dist/gpu-project/cpu-geometry-pipelines.d.ts.map +1 -1
  47. package/dist/gpu-project/cpu-geometry-pipelines.js +1 -1
  48. package/dist/gpu-project/cpu-geometry-pipelines.js.map +1 -1
  49. package/dist/gpu-project/geoarrow.cjs.map +1 -1
  50. package/dist/gpu-sql/gpu-sql.cjs +8 -4
  51. package/dist/gpu-sql/gpu-sql.js +5 -1
  52. package/dist/gpu-sql/gpu-sql.js.map +1 -1
  53. package/dist/gpu-sql/index.cjs.map +1 -1
  54. package/package.json +8 -8
  55. package/src/arrow/arrow-utils/arrow-paths.ts +5 -3
  56. package/src/arrow/geoarrow/arrow-geoarrow-adapter.ts +4 -6
  57. package/src/arrow/geoarrow/arrow-geoarrow-conversion.ts +2 -2
  58. package/src/arrow/geoarrow/arrow-polygon-tessellation.ts +1 -1
  59. package/src/gpu-core/gpu-expression-operation.ts +1 -1
  60. package/src/gpu-dataframe/portable-expression.ts +2 -2
  61. package/src/gpu-physics/gpu-rigid-body-world.ts +219 -1
  62. package/src/gpu-physics/index.ts +1 -0
  63. package/src/gpu-physics/rigid-body-vehicle.ts +99 -0
  64. package/src/gpu-project/cpu-geoarrow.ts +1 -1
  65. package/src/gpu-project/cpu-geometry-pipelines.ts +2 -2
  66. package/src/gpu-sql/gpu-sql.ts +4 -2
@@ -22,6 +22,7 @@ import { addRigidBodyCheckpoint } from "./rigid-body-transaction.js";
22
22
  import { getRigidBodyJointShader, packRigidBodyJointState, RIGID_BODY_JOINT_STATE_BYTES, validateRigidBodyJoints } from "./rigid-body-joints.js";
23
23
  import { addRigidBodyPosePublication } from "./rigid-body-publication.js";
24
24
  import { getRigidBodyShader } from "./rigid-body-shaders.js";
25
+ import { VEHICLE_SHADER } from "./rigid-body-vehicle.js";
25
26
  import { decodeRigidBodyContactEvents, getRigidBodyEventShader } from "./rigid-body-events.js";
26
27
  import { RIGID_BODY_QUERY_SHADER } from "./rigid-body-queries.js";
27
28
  export class GPURigidBodyWorld {
@@ -52,6 +53,7 @@ export class GPURigidBodyWorld {
52
53
  eventRead = null;
53
54
  queryComputation = null;
54
55
  queryReduction = null;
56
+ vehicleBuffer = null;
55
57
  querySettings = null;
56
58
  querySelection = null;
57
59
  queryOutput = null;
@@ -278,8 +280,26 @@ export class GPURigidBodyWorld {
278
280
  }
279
281
  // Clone together so collider edits preserve geometry identity in captured body definitions.
280
282
  const definitions = structuredClone({ colliders, props });
281
- this.colliders = definitions.colliders;
282
283
  this.props = definitions.props;
284
+ this.colliders = definitions.colliders;
285
+ const vehicle = this.props.vehicle;
286
+ if (vehicle) {
287
+ const terrain = this.colliders[vehicle.terrainCollider];
288
+ const chassis = this.props.bodies[vehicle.chassis];
289
+ const ground = terrain && this.props.bodies[terrain.body];
290
+ if (!chassis ||
291
+ !ground ||
292
+ vehicle.chassis === terrain.body ||
293
+ (chassis.mode ?? (chassis.mass === 0 ? 'static' : 'dynamic')) !== 'dynamic' ||
294
+ (ground.mode ?? (ground.mass === 0 ? 'static' : 'dynamic')) !== 'static' ||
295
+ vehicle.wheels.length !== 4 ||
296
+ this.props.failurePolicy === 'rollback' ||
297
+ this.props.ensembleBodiesPerInstance ||
298
+ ![vehicle.radius, vehicle.travel, vehicle.springRate, vehicle.wheelInertia].every(value => Number.isFinite(value) && value > 0) ||
299
+ ![vehicle.damping, vehicle.grip, vehicle.motorTorque, vehicle.brakeTorque].every(value => Number.isFinite(value) && value >= 0) ||
300
+ vehicle.wheels.some(wheel => wheel.mount.length !== 3 || !wheel.mount.every(Number.isFinite)))
301
+ throw new Error('Invalid vehicle configuration');
302
+ }
283
303
  if (props.ensembleBodiesPerInstance)
284
304
  this.initialEnsembleBodies = this.props.bodies.slice(0, props.ensembleBodiesPerInstance);
285
305
  }
@@ -296,6 +316,8 @@ export class GPURigidBodyWorld {
296
316
  parallel,
297
317
  ...getRigidBodyStorageLayout(this.count, this.colliderStorageCount, this.maximumPairs, packed.geometry.length, sparse, extended, parallel, this.props.eventCapacity ?? 0, this.props.enableQueries ?? false, this.props.failurePolicy === 'rollback', Boolean(this.props.continuous), this.props.joints?.length ?? 0, this.props.ensembleBodiesPerInstance ? this.count / this.props.ensembleBodiesPerInstance : 0)
298
318
  };
319
+ if (this.props.vehicle)
320
+ storage.buffers.push({ name: 'vehicle', byteLength: 512, uniform: false });
299
321
  if (this.props.continuous?.mode === 'convex') {
300
322
  storage.buffers = storage.buffers.filter(buffer => buffer.name !== 'continuous-previous');
301
323
  storage.buffers.push({ name: 'continuous-dispatch', byteLength: 16, uniform: false });
@@ -825,6 +847,98 @@ export class GPURigidBodyWorld {
825
847
  parallelMarkSleep: 'Identify islands whose bodies are quiet enough to sleep.',
826
848
  parallelSleep: 'Put quiet constraint islands to sleep.'
827
849
  };
850
+ const vehicle = this.props.vehicle;
851
+ if (vehicle) {
852
+ const data = new Float32Array(128);
853
+ data.set([
854
+ vehicle.radius,
855
+ vehicle.travel,
856
+ vehicle.springRate,
857
+ vehicle.damping,
858
+ vehicle.grip,
859
+ vehicle.motorTorque,
860
+ vehicle.brakeTorque,
861
+ vehicle.wheelInertia
862
+ ], 4);
863
+ new Uint32Array(data.buffer).set([vehicle.chassis, vehicle.terrainCollider], 12);
864
+ vehicle.wheels.forEach((wheel, index) => {
865
+ const offset = 16 + index * 12;
866
+ data.set(wheel.mount, offset);
867
+ data.set([Number(Boolean(wheel.steer)), Number(Boolean(wheel.drive))], offset + 4);
868
+ data[offset + 10] = vehicle.travel;
869
+ data.set([
870
+ 1,
871
+ 0,
872
+ 0,
873
+ 0,
874
+ 0,
875
+ 1,
876
+ 0,
877
+ 0,
878
+ 0,
879
+ 0,
880
+ 1,
881
+ 0,
882
+ wheel.mount[0],
883
+ wheel.mount[1],
884
+ wheel.mount[2] - vehicle.travel,
885
+ 1
886
+ ], 64 + 16 * index);
887
+ });
888
+ this.vehicleBuffer = allocate('vehicle', data);
889
+ const vehicleBindings = [
890
+ ...bindings.filter(binding => [
891
+ 'settings',
892
+ 'positions',
893
+ 'orientations',
894
+ 'velocities',
895
+ 'angularVelocities',
896
+ 'bodies',
897
+ 'sleepStates'
898
+ ].includes(binding.name)),
899
+ {
900
+ name: 'vehicle',
901
+ location: 12,
902
+ buffer: this.vehicleBuffer,
903
+ resource: graph.importBuffer({ id: this.id + '-vehicle', byteLength: data.byteLength, usage: Buffer.STORAGE }, this.vehicleBuffer)
904
+ }
905
+ ];
906
+ const properties = {
907
+ id: this.id + '-suspension',
908
+ source: source + RIGID_BODY_QUERY_GEOMETRY_SHADER + VEHICLE_SHADER,
909
+ entryPoint: 'advanceVehicle',
910
+ shaderLayout: {
911
+ bindings: vehicleBindings.map(({ name, location }) => name === 'settings'
912
+ ? { name, location, group: 0, type: 'uniform' }
913
+ : {
914
+ name,
915
+ location,
916
+ group: 0,
917
+ type: name === 'bodies' ? 'read-only-storage' : 'storage'
918
+ })
919
+ }
920
+ };
921
+ const executable = (computation) => ({
922
+ encode: ({ computePass, getBuffer }) => {
923
+ Object.assign(computation.bindings, Object.fromEntries(vehicleBindings.map(binding => [binding.name, getBuffer(binding.resource)])));
924
+ computation.kernel.dispatch(computePass, { bindings: computation.bindings, x: 1 });
925
+ },
926
+ destroy: () => computation.kernel.destroy()
927
+ });
928
+ graph.addComputePass({
929
+ id: properties.id,
930
+ resources: vehicleBindings.map(binding => ({
931
+ buffer: binding.resource,
932
+ usage: binding.name === 'settings'
933
+ ? 'uniform'
934
+ : binding.name === 'bodies'
935
+ ? 'storage-read'
936
+ : 'storage-read-write'
937
+ })),
938
+ compile: () => executable(createBoundKernel(graph.device, properties)),
939
+ compileAsync: async () => executable(await createBoundKernelAsync(graph.device, properties))
940
+ });
941
+ }
828
942
  for (const entryPoint of [
829
943
  ...(this.ensembleBuffer
830
944
  ? ['ensembleClear', 'ensembleMark', 'ensembleCompact', 'ensembleDispatch']
@@ -1455,6 +1569,69 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
1455
1569
  ? (definition.mode ?? ((definition.mass ?? 1) === 0 ? 'static' : 'dynamic'))
1456
1570
  : undefined;
1457
1571
  }
1572
+ /** Set signed throttle, steering angle in radians and brake fraction for upcoming substeps. */
1573
+ setVehicleControls(throttle, steering, brake) {
1574
+ if (!this.vehicleBuffer ||
1575
+ this.destroyed ||
1576
+ ![throttle, steering, brake].every(Number.isFinite))
1577
+ throw new Error('Invalid vehicle controls');
1578
+ this.vehicleBuffer.write(new Float32Array([
1579
+ Math.max(-1, Math.min(1, throttle)),
1580
+ steering,
1581
+ Math.max(0, Math.min(1, brake)),
1582
+ 0
1583
+ ]));
1584
+ }
1585
+ /** Borrow four column-major wheel transforms relative to the chassis node, ordered by mount. */
1586
+ get vehicleWheelPoses() {
1587
+ return this.vehicleBuffer && !this.destroyed
1588
+ ? { buffer: this.vehicleBuffer, byteOffset: 256, byteLength: 256 }
1589
+ : null;
1590
+ }
1591
+ /** Transfer wheel motion between rebuilt worlds for wheels with matching chassis-local mounts. */
1592
+ copyVehicleMotionFrom(previous) {
1593
+ const sourceBuffer = previous.vehicleBuffer;
1594
+ const destinationBuffer = this.vehicleBuffer;
1595
+ const previousVehicle = previous.props.vehicle;
1596
+ if (!this.device || !sourceBuffer || !destinationBuffer || !previousVehicle)
1597
+ return;
1598
+ const encoder = this.device.createCommandEncoder();
1599
+ this.props.vehicle?.wheels.forEach((wheel, index) => {
1600
+ const sourceIndex = previousVehicle.wheels.findIndex(source => source.mount.every((coordinate, axis) => coordinate === wheel.mount[axis]));
1601
+ if (sourceIndex < 0)
1602
+ return;
1603
+ encoder.copyBufferToBuffer({
1604
+ sourceBuffer,
1605
+ destinationBuffer,
1606
+ sourceOffset: 96 + sourceIndex * 48,
1607
+ destinationOffset: 96 + index * 48,
1608
+ size: 16
1609
+ });
1610
+ encoder.copyBufferToBuffer({
1611
+ sourceBuffer,
1612
+ destinationBuffer,
1613
+ sourceOffset: 256 + sourceIndex * 64,
1614
+ destinationOffset: 256 + index * 64,
1615
+ size: 64
1616
+ });
1617
+ });
1618
+ this.device.submit(encoder.finish());
1619
+ }
1620
+ /** Read wheel spin, angle, suspension length and normal load after submitted steps. */
1621
+ async readVehicleWheels() {
1622
+ if (!this.vehicleBuffer || this.destroyed)
1623
+ throw new Error('Vehicle unavailable');
1624
+ const values = new Float32Array((await this.vehicleBuffer.readAsync(0, 256)).buffer);
1625
+ return Array.from({ length: 4 }, (_, index) => {
1626
+ const offset = 24 + index * 12;
1627
+ return {
1628
+ speed: values[offset],
1629
+ angle: values[offset + 1],
1630
+ length: values[offset + 2],
1631
+ load: values[offset + 3]
1632
+ };
1633
+ });
1634
+ }
1458
1635
  /** Submit an impulse at a world-space point, or the current GPU center of mass when omitted. */
1459
1636
  applyImpulse(body, impulse, point) {
1460
1637
  if (!this.control ||