@luma.gl/graph 10.0.0-beta.1 → 10.0.0-beta.2
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/experimental-models.cjs +21 -0
- package/dist/experimental-models.d.ts +2 -0
- package/dist/experimental-models.d.ts.map +1 -0
- package/dist/experimental-models.js +5 -0
- package/dist/experimental-models.js.map +1 -0
- package/dist/experimental-simulation.cjs +21 -0
- package/dist/experimental-simulation.d.ts +2 -0
- package/dist/experimental-simulation.d.ts.map +1 -0
- package/dist/experimental-simulation.js +5 -0
- package/dist/experimental-simulation.js.map +1 -0
- package/dist/gpu-dataframe/gpu-data-frame-query.cjs +7 -3
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.js +14 -4
- package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.cjs +87 -5
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts +2 -1
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.js +101 -5
- package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.cjs +86 -0
- package/dist/gpu-dataframe/gpu-expression.d.ts +23 -2
- package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.js +81 -0
- package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +0 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +0 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js +5 -3
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +23 -11
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js +24 -12
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +0 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +0 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.cjs +2 -2
- package/dist/gpu-dataframe/gpu-group-by-query.js +5 -3
- package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-histogram-compiler.cjs +0 -1
- package/dist/gpu-dataframe/gpu-histogram-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-histogram-compiler.js +0 -1
- package/dist/gpu-dataframe/gpu-histogram-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.cjs +0 -2
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.js +0 -2
- package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.cjs +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts +0 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-sort-compiler.cjs +0 -1
- package/dist/gpu-dataframe/gpu-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-sort-compiler.js +0 -1
- package/dist/gpu-dataframe/gpu-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-sort-query.cjs +13 -5
- package/dist/gpu-dataframe/gpu-sort-query.d.ts +4 -1
- package/dist/gpu-dataframe/gpu-sort-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-sort-query.js +14 -5
- package/dist/gpu-dataframe/gpu-sort-query.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs +8 -0
- package/dist/gpu-dataframe/index.cjs.map +2 -2
- package/dist/gpu-dataframe/index.d.ts +2 -2
- package/dist/gpu-dataframe/index.d.ts.map +1 -1
- package/dist/gpu-dataframe/index.js +1 -1
- package/dist/gpu-dataframe/index.js.map +1 -1
- package/dist/gpu-dataframe/portable-expression.cjs +68 -4
- package/dist/gpu-dataframe/portable-expression.d.ts +3 -1
- package/dist/gpu-dataframe/portable-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/portable-expression.js +69 -5
- package/dist/gpu-dataframe/portable-expression.js.map +1 -1
- package/dist/gpu-dggs-benchmarks.cjs +21 -0
- package/dist/gpu-dggs-benchmarks.d.ts +2 -0
- package/dist/gpu-dggs-benchmarks.d.ts.map +1 -0
- package/dist/gpu-dggs-benchmarks.js +5 -0
- package/dist/gpu-dggs-benchmarks.js.map +1 -0
- package/dist/gpu-graph-algorithms-benchmarks.cjs +21 -0
- package/dist/gpu-graph-algorithms-benchmarks.d.ts +2 -0
- package/dist/gpu-graph-algorithms-benchmarks.d.ts.map +1 -0
- package/dist/gpu-graph-algorithms-benchmarks.js +5 -0
- package/dist/gpu-graph-algorithms-benchmarks.js.map +1 -0
- package/dist/gpu-physics/gpu-physics-ensemble-terrain.cjs +116 -0
- package/dist/gpu-physics/gpu-physics-ensemble-terrain.d.ts +42 -0
- package/dist/gpu-physics/gpu-physics-ensemble-terrain.d.ts.map +1 -0
- package/dist/gpu-physics/gpu-physics-ensemble-terrain.js +90 -0
- package/dist/gpu-physics/gpu-physics-ensemble-terrain.js.map +1 -0
- package/dist/gpu-physics/gpu-physics-ensemble.cjs +97 -5
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts +31 -2
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.js +99 -3
- package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +483 -152
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +64 -3
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +523 -161
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs +23 -2
- package/dist/gpu-physics/index.cjs.map +3 -3
- package/dist/gpu-physics/index.d.ts +8 -2
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/index.js +6 -1
- package/dist/gpu-physics/index.js.map +1 -1
- package/dist/gpu-physics/rigid-body-bounds-shaders.cjs +21 -8
- package/dist/gpu-physics/rigid-body-bounds-shaders.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-bounds-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-bounds-shaders.js +15 -1
- package/dist/gpu-physics/rigid-body-bounds-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-convex-shaders.cjs +3 -2
- package/dist/gpu-physics/rigid-body-convex-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-convex-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-convex-shaders.js +3 -2
- package/dist/gpu-physics/rigid-body-convex-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +36 -7
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.js +42 -7
- package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +23 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +4 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js +25 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
- package/dist/gpu-physics/rigid-body-geometry.cjs +41 -4
- package/dist/gpu-physics/rigid-body-geometry.d.ts +10 -1
- package/dist/gpu-physics/rigid-body-geometry.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-geometry.js +44 -3
- package/dist/gpu-physics/rigid-body-geometry.js.map +1 -1
- package/dist/gpu-physics/rigid-body-height-field-shader.cjs +80 -0
- package/dist/gpu-physics/rigid-body-height-field-shader.d.ts +3 -0
- package/dist/gpu-physics/rigid-body-height-field-shader.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-height-field-shader.js +56 -0
- package/dist/gpu-physics/rigid-body-height-field-shader.js.map +1 -0
- package/dist/gpu-physics/rigid-body-height-field.cjs +166 -0
- package/dist/gpu-physics/rigid-body-height-field.d.ts +55 -0
- package/dist/gpu-physics/rigid-body-height-field.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-height-field.js +184 -0
- package/dist/gpu-physics/rigid-body-height-field.js.map +1 -0
- package/dist/gpu-physics/rigid-body-mesh-query-shaders.cjs +4 -2
- package/dist/gpu-physics/rigid-body-mesh-query-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-mesh-query-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-mesh-query-shaders.js +4 -2
- package/dist/gpu-physics/rigid-body-mesh-query-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-mesh.cjs +72 -17
- package/dist/gpu-physics/rigid-body-mesh.d.ts +3 -0
- package/dist/gpu-physics/rigid-body-mesh.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-mesh.js +76 -20
- package/dist/gpu-physics/rigid-body-mesh.js.map +1 -1
- package/dist/gpu-physics/rigid-body-properties.cjs +4 -4
- package/dist/gpu-physics/rigid-body-properties.d.ts +6 -0
- package/dist/gpu-physics/rigid-body-properties.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-properties.js +1 -1
- package/dist/gpu-physics/rigid-body-properties.js.map +1 -1
- package/dist/gpu-physics/rigid-body-publication.cjs +2 -2
- package/dist/gpu-physics/rigid-body-publication.js +1 -1
- package/dist/gpu-physics/rigid-body-publication.js.map +1 -1
- package/dist/gpu-physics/rigid-body-query-geometry.cjs +22 -4
- package/dist/gpu-physics/rigid-body-query-geometry.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-query-geometry.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-query-geometry.js +22 -4
- package/dist/gpu-physics/rigid-body-query-geometry.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +11 -5
- package/dist/gpu-physics/rigid-body-shaders.d.ts +1 -1
- package/dist/gpu-physics/rigid-body-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.js +14 -6
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shape-properties.cjs +2 -0
- package/dist/gpu-physics/rigid-body-shape-properties.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-shape-properties.js +2 -0
- package/dist/gpu-physics/rigid-body-shape-properties.js.map +1 -1
- package/dist/gpu-physics/rigid-body-terrain-atlas.cjs +287 -0
- package/dist/gpu-physics/rigid-body-terrain-atlas.d.ts +87 -0
- package/dist/gpu-physics/rigid-body-terrain-atlas.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-atlas.js +275 -0
- package/dist/gpu-physics/rigid-body-terrain-atlas.js.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-lod.cjs +240 -0
- package/dist/gpu-physics/rigid-body-terrain-lod.d.ts +76 -0
- package/dist/gpu-physics/rigid-body-terrain-lod.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-lod.js +247 -0
- package/dist/gpu-physics/rigid-body-terrain-lod.js.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-stitch.cjs +215 -0
- package/dist/gpu-physics/rigid-body-terrain-stitch.d.ts +25 -0
- package/dist/gpu-physics/rigid-body-terrain-stitch.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-stitch.js +218 -0
- package/dist/gpu-physics/rigid-body-terrain-stitch.js.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-stream.cjs +263 -0
- package/dist/gpu-physics/rigid-body-terrain-stream.d.ts +97 -0
- package/dist/gpu-physics/rigid-body-terrain-stream.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-terrain-stream.js +250 -0
- package/dist/gpu-physics/rigid-body-terrain-stream.js.map +1 -0
- package/dist/gpu-physics/rigid-body-triggers.cjs +1 -0
- package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.js +1 -0
- package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
- package/dist/gpu-physics/rigid-body-vehicle.cjs +99 -44
- package/dist/gpu-physics/rigid-body-vehicle.d.ts +15 -3
- package/dist/gpu-physics/rigid-body-vehicle.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-vehicle.js +93 -40
- package/dist/gpu-physics/rigid-body-vehicle.js.map +1 -1
- package/dist/gpu-project/cpu-geometry-pipelines.d.ts +1 -1
- package/dist/gpu-project/cpu-projection-operation.d.ts +1 -1
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/crs.d.ts +1 -1
- package/dist/gpu-project/projection-crs-benchmark.cjs +2 -2
- package/dist/gpu-project/projection-crs-benchmark.d.ts +1 -1
- package/dist/gpu-project/projection-crs-benchmark.js +1 -1
- package/dist/gpu-project/projection-crs-input.cjs +7 -7
- package/dist/gpu-project/projection-crs-input.d.ts +1 -1
- package/dist/gpu-project/projection-crs-input.js +4 -4
- package/dist/gpu-project/projection-engine.d.ts +2 -2
- package/dist/gpu-project-benchmarks.cjs +21 -0
- package/dist/gpu-project-benchmarks.d.ts +2 -0
- package/dist/gpu-project-benchmarks.d.ts.map +1 -0
- package/dist/gpu-project-benchmarks.js +5 -0
- package/dist/gpu-project-benchmarks.js.map +1 -0
- package/dist/gpu-project-crs.cjs +21 -0
- package/dist/gpu-project-crs.d.ts +2 -0
- package/dist/gpu-project-crs.d.ts.map +1 -0
- package/dist/gpu-project-crs.js +5 -0
- package/dist/gpu-project-crs.js.map +1 -0
- package/dist/gpu-project-geoarrow.cjs +21 -0
- package/dist/gpu-project-geoarrow.d.ts +2 -0
- package/dist/gpu-project-geoarrow.d.ts.map +1 -0
- package/dist/gpu-project-geoarrow.js +5 -0
- package/dist/gpu-project-geoarrow.js.map +1 -0
- package/dist/gpu-project-graph.cjs +21 -0
- package/dist/gpu-project-graph.d.ts +2 -0
- package/dist/gpu-project-graph.d.ts.map +1 -0
- package/dist/gpu-project-graph.js +5 -0
- package/dist/gpu-project-graph.js.map +1 -0
- package/dist/gpu-simple-graph/gpu-simple-graph-transfer.d.ts +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph-transfer.d.ts.map +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph-value.d.ts +1 -1
- package/dist/gpu-simple-graph/gpu-simple-graph-value.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts +1 -1
- package/dist/gpu-simple-graph/operation/gpu-data-evaluator.d.ts.map +1 -1
- package/dist/gpu-simple-graph/operation/operation.d.ts +1 -1
- package/dist/gpu-simple-graph/operation/operation.d.ts.map +1 -1
- package/dist/gpu-simple-graph-cpu.cjs +21 -0
- package/dist/gpu-simple-graph-cpu.d.ts +2 -0
- package/dist/gpu-simple-graph-cpu.d.ts.map +1 -0
- package/dist/gpu-simple-graph-cpu.js +5 -0
- package/dist/gpu-simple-graph-cpu.js.map +1 -0
- package/dist/gpu-simple-graph-webgl.cjs +21 -0
- package/dist/gpu-simple-graph-webgl.d.ts +2 -0
- package/dist/gpu-simple-graph-webgl.d.ts.map +1 -0
- package/dist/gpu-simple-graph-webgl.js +5 -0
- package/dist/gpu-simple-graph-webgl.js.map +1 -0
- package/dist/gpu-simple-graph-webgpu.cjs +21 -0
- package/dist/gpu-simple-graph-webgpu.d.ts +2 -0
- package/dist/gpu-simple-graph-webgpu.d.ts.map +1 -0
- package/dist/gpu-simple-graph-webgpu.js +5 -0
- package/dist/gpu-simple-graph-webgpu.js.map +1 -0
- package/dist/gpu-sql/gpu-sql.cjs +76 -122
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +99 -130
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +2 -2
- package/package.json +19 -19
- package/src/experimental-models.ts +5 -0
- package/src/experimental-simulation.ts +5 -0
- package/src/gpu-dataframe/gpu-data-frame-query.ts +18 -5
- package/src/gpu-dataframe/gpu-expression-shader.ts +128 -7
- package/src/gpu-dataframe/gpu-expression.ts +124 -1
- package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +0 -1
- package/src/gpu-dataframe/gpu-global-aggregation-query.ts +5 -3
- package/src/gpu-dataframe/gpu-global-sort-compiler.ts +26 -12
- package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +0 -1
- package/src/gpu-dataframe/gpu-group-by-query.ts +5 -3
- package/src/gpu-dataframe/gpu-histogram-compiler.ts +0 -1
- package/src/gpu-dataframe/gpu-join-compiler.ts +0 -2
- package/src/gpu-dataframe/gpu-query-compiler.ts +3 -3
- package/src/gpu-dataframe/gpu-sort-compiler.ts +0 -1
- package/src/gpu-dataframe/gpu-sort-query.ts +31 -5
- package/src/gpu-dataframe/index.ts +15 -2
- package/src/gpu-dataframe/portable-expression.ts +81 -4
- package/src/gpu-dggs-benchmarks.ts +5 -0
- package/src/gpu-graph-algorithms-benchmarks.ts +5 -0
- package/src/gpu-physics/gpu-physics-ensemble-terrain.ts +114 -0
- package/src/gpu-physics/gpu-physics-ensemble.ts +147 -4
- package/src/gpu-physics/gpu-rigid-body-world.ts +668 -198
- package/src/gpu-physics/index.ts +37 -0
- package/src/gpu-physics/rigid-body-bounds-shaders.ts +16 -1
- package/src/gpu-physics/rigid-body-convex-shaders.ts +3 -2
- package/src/gpu-physics/rigid-body-ensemble-reset.ts +48 -8
- package/src/gpu-physics/rigid-body-ensemble-transaction.ts +34 -1
- package/src/gpu-physics/rigid-body-geometry.ts +49 -4
- package/src/gpu-physics/rigid-body-height-field-shader.ts +56 -0
- package/src/gpu-physics/rigid-body-height-field.ts +257 -0
- package/src/gpu-physics/rigid-body-mesh-query-shaders.ts +4 -2
- package/src/gpu-physics/rigid-body-mesh.ts +97 -26
- package/src/gpu-physics/rigid-body-properties.ts +5 -2
- package/src/gpu-physics/rigid-body-publication.ts +1 -1
- package/src/gpu-physics/rigid-body-query-geometry.ts +22 -4
- package/src/gpu-physics/rigid-body-shaders.ts +17 -6
- package/src/gpu-physics/rigid-body-shape-properties.ts +2 -0
- package/src/gpu-physics/rigid-body-terrain-atlas.ts +378 -0
- package/src/gpu-physics/rigid-body-terrain-lod.ts +332 -0
- package/src/gpu-physics/rigid-body-terrain-stitch.ts +286 -0
- package/src/gpu-physics/rigid-body-terrain-stream.ts +323 -0
- package/src/gpu-physics/rigid-body-triggers.ts +1 -0
- package/src/gpu-physics/rigid-body-vehicle.ts +108 -41
- package/src/gpu-project/README.md +2 -2
- package/src/gpu-project/cpu-geometry-pipelines.ts +1 -1
- package/src/gpu-project/cpu-projection-operation.ts +1 -1
- package/src/gpu-project/crs.ts +2 -2
- package/src/gpu-project/projection-crs-benchmark.ts +2 -2
- package/src/gpu-project/projection-crs-input.ts +4 -4
- package/src/gpu-project/projection-engine.ts +2 -2
- package/src/gpu-project-benchmarks.ts +5 -0
- package/src/gpu-project-crs.ts +5 -0
- package/src/gpu-project-geoarrow.ts +5 -0
- package/src/gpu-project-graph.ts +5 -0
- package/src/gpu-simple-graph/gpu-simple-graph-transfer.ts +1 -1
- package/src/gpu-simple-graph/gpu-simple-graph-value.ts +1 -1
- package/src/gpu-simple-graph/operation/gpu-data-evaluator.ts +1 -1
- package/src/gpu-simple-graph/operation/operation.ts +1 -1
- package/src/gpu-simple-graph/operations/swizzle.ts +1 -1
- package/src/gpu-simple-graph-cpu.ts +5 -0
- package/src/gpu-simple-graph-webgl.ts +5 -0
- package/src/gpu-simple-graph-webgpu.ts +5 -0
- package/src/gpu-sql/gpu-sql.ts +150 -152
|
@@ -20,12 +20,19 @@ import {
|
|
|
20
20
|
|
|
21
21
|
import {
|
|
22
22
|
GPUCommandGraph,
|
|
23
|
-
type GPUCommandGraphComputeExecutable
|
|
23
|
+
type GPUCommandGraphComputeExecutable,
|
|
24
|
+
type GraphBufferHandle
|
|
24
25
|
} from '../gpu-core/gpu-command-graph';
|
|
25
26
|
import {shiftRigidBodyBuffers} from './rigid-body-origin';
|
|
27
|
+
import {type GPURigidBodyHeightField, packRigidBodyHeightField} from './rigid-body-height-field';
|
|
26
28
|
import {getRigidBodyShapeProperties} from './rigid-body-shape-properties';
|
|
27
29
|
import {addEnsembleStatus, readOnlyEnsembleShader} from './rigid-body-ensemble-shaders';
|
|
28
30
|
import {makeEnsembleReset} from './rigid-body-ensemble-reset';
|
|
31
|
+
import {
|
|
32
|
+
RigidBodyTerrainAtlas,
|
|
33
|
+
type GPUPhysicsTerrainAtlasPool,
|
|
34
|
+
type GPUPhysicsTerrainAtlasStats
|
|
35
|
+
} from './rigid-body-terrain-atlas';
|
|
29
36
|
import {packRigidBodyShapes} from './rigid-body-geometry';
|
|
30
37
|
import {
|
|
31
38
|
getCompoundBodyInertia,
|
|
@@ -76,7 +83,12 @@ import {
|
|
|
76
83
|
import {addRigidBodyPosePublication, type GPURigidBodyBounds} from './rigid-body-publication';
|
|
77
84
|
import {getRigidBodyShader} from './rigid-body-shaders';
|
|
78
85
|
|
|
79
|
-
import {
|
|
86
|
+
import {
|
|
87
|
+
getVehicleShader,
|
|
88
|
+
VEHICLE_STRIDE,
|
|
89
|
+
VEHICLE_TERRAIN_ROW_SIZE,
|
|
90
|
+
type GPURigidBodyVehicle
|
|
91
|
+
} from './rigid-body-vehicle';
|
|
80
92
|
|
|
81
93
|
type Vector3 = readonly [number, number, number];
|
|
82
94
|
import {
|
|
@@ -92,6 +104,16 @@ import {
|
|
|
92
104
|
type GPURigidBodyQueryResult
|
|
93
105
|
} from './rigid-body-queries';
|
|
94
106
|
|
|
107
|
+
/** One fixed-dimension slot update. A null field evicts the current tile. */
|
|
108
|
+
export type GPURigidBodyHeightFieldEdit = {
|
|
109
|
+
/** Stable index of the reserved collider slot. */
|
|
110
|
+
collider: number;
|
|
111
|
+
/** Replacement samples and transform, or null to evict. */
|
|
112
|
+
field: GPURigidBodyHeightField | null;
|
|
113
|
+
/** Optional new placement in the collider's body-local frame. */
|
|
114
|
+
position?: Vector3;
|
|
115
|
+
};
|
|
116
|
+
|
|
95
117
|
/** In-memory, structured-cloneable debug capture; tied to this implementation's storage layout. */
|
|
96
118
|
export type GPURigidBodyCapture = {
|
|
97
119
|
version: 1;
|
|
@@ -102,6 +124,10 @@ export type GPURigidBodyCapture = {
|
|
|
102
124
|
buffers: {name: string; data: Uint8Array}[];
|
|
103
125
|
contactCursor: number;
|
|
104
126
|
triggerCursor: number;
|
|
127
|
+
/** Last issued terrain edit stamp, for restoring into a different world. */
|
|
128
|
+
terrainRevision?: number;
|
|
129
|
+
/** Exact collider-to-page assignments for a captured shared atlas. */
|
|
130
|
+
terrainAtlasLeases?: readonly (readonly [collider: number, page: number])[];
|
|
105
131
|
colliderShapeScales?: [number, number[]][];
|
|
106
132
|
};
|
|
107
133
|
|
|
@@ -132,6 +158,8 @@ export type GPURigidBodyWorldProps = {
|
|
|
132
158
|
gravity?: Vector3;
|
|
133
159
|
/** Optional four-wheel suspension evaluated against static terrain each fixed step. */
|
|
134
160
|
vehicle?: GPURigidBodyVehicle;
|
|
161
|
+
/** Four-wheel chassis with distinct dynamic bodies, in vehicle-index order. Supply this or vehicle. */
|
|
162
|
+
vehicles?: readonly GPURigidBodyVehicle[];
|
|
135
163
|
timeStep?: number;
|
|
136
164
|
iterations?: number;
|
|
137
165
|
contactSlop?: number;
|
|
@@ -152,6 +180,10 @@ export type GPURigidBodyWorldProps = {
|
|
|
152
180
|
collisionPartitionSize?: number;
|
|
153
181
|
/** Equal body ranges for GPU-driven ensemble scheduling; requires parallel sparse partitions. */
|
|
154
182
|
ensembleBodiesPerInstance?: number;
|
|
183
|
+
/** @internal Global collider indices reserved for writable terrain in a fused ensemble. */
|
|
184
|
+
ensembleTerrainSlots?: readonly number[];
|
|
185
|
+
/** @internal Optional fused atlas page capacity by reserved grid. */
|
|
186
|
+
ensembleTerrainAtlas?: readonly GPUPhysicsTerrainAtlasPool[];
|
|
155
187
|
broadPhase?: 'all-pairs' | 'hierarchical-grid';
|
|
156
188
|
/** Parallel block-Jacobi contact solving; ordered impulses remain the numerical oracle. */
|
|
157
189
|
solver?: 'ordered' | 'parallel';
|
|
@@ -232,6 +264,12 @@ export class GPURigidBodyWorld {
|
|
|
232
264
|
private eventRead: Promise<GPURigidBodyContactBatch> | null = null;
|
|
233
265
|
private queryComputation: BoundKernel | null = null;
|
|
234
266
|
private queryReduction: BoundKernel | null = null;
|
|
267
|
+
/** Chassis definitions in GPU storage order. */
|
|
268
|
+
private readonly vehicles: readonly GPURigidBodyVehicle[];
|
|
269
|
+
/** Whether any chassis has more than one terrain candidate. */
|
|
270
|
+
private readonly multiSurfaceVehicles: boolean;
|
|
271
|
+
/** Number of vehicles in each equal-sized ensemble partition, or zero for a standalone world. */
|
|
272
|
+
private readonly vehiclesPerInstance: number;
|
|
235
273
|
private vehicleBuffer: Buffer | null = null;
|
|
236
274
|
private querySettings: Buffer | null = null;
|
|
237
275
|
private querySelection: Buffer | null = null;
|
|
@@ -240,9 +278,23 @@ export class GPURigidBodyWorld {
|
|
|
240
278
|
private targets: Buffer | null = null;
|
|
241
279
|
private simulationStatistics: Buffer | null = null;
|
|
242
280
|
private readonly colliders: readonly (GPURigidBodyCollider & {body: number})[];
|
|
281
|
+
private readonly bodyColliderStarts: Uint32Array;
|
|
282
|
+
private readonly ensembleTerrainSlots: ReadonlySet<number>;
|
|
243
283
|
private readonly props: GPURigidBodyWorldProps;
|
|
244
284
|
private readonly ownedBuffers: Buffer[] = [];
|
|
285
|
+
private allocationPlan?: GPURigidBodyCapacityInfo['buffers'];
|
|
245
286
|
private ensembleBuffer: Buffer | null = null;
|
|
287
|
+
/** Byte offsets of writable fixed-dimension height fields in the world metadata buffer. */
|
|
288
|
+
private heightFieldSlots = new Map<number, number>();
|
|
289
|
+
/** Float32-exact edit stamp, restored together with the contact cache. */
|
|
290
|
+
private terrainRevision = 1;
|
|
291
|
+
private terrainWake: BoundKernel | null = null;
|
|
292
|
+
/** Page ownership and live lease counts for an opt-in fused atlas. */
|
|
293
|
+
private readonly terrainAtlas?: RigidBodyTerrainAtlas;
|
|
294
|
+
/** Start of the shared atlas in the GPU metadata buffer, measured in 32-bit words. */
|
|
295
|
+
private terrainAtlasWord = 0;
|
|
296
|
+
/** Start of the shader geometry region in the GPU metadata buffer, measured in 32-bit words. */
|
|
297
|
+
private terrainGeometryWord = 0;
|
|
246
298
|
private ensembleResetOrigin?: readonly number[];
|
|
247
299
|
private ensembleReset?: ReturnType<typeof makeEnsembleReset>;
|
|
248
300
|
private initialEnsembleBodies?: readonly GPURigidBody[];
|
|
@@ -347,6 +399,11 @@ export class GPURigidBodyWorld {
|
|
|
347
399
|
const shapes: readonly GPURigidBodyCollider[] =
|
|
348
400
|
body.colliders ?? (body.shape ? [{shape: body.shape}] : []);
|
|
349
401
|
for (const collider of shapes) {
|
|
402
|
+
if (
|
|
403
|
+
collider.shape.type === 'height-field' &&
|
|
404
|
+
(body.mode ?? (body.mass === 0 ? 'static' : 'dynamic')) !== 'static'
|
|
405
|
+
)
|
|
406
|
+
throw new Error('Height fields require static bodies');
|
|
350
407
|
const properties = getRigidBodyShapeProperties(collider.shape);
|
|
351
408
|
if (
|
|
352
409
|
!Number.isFinite(properties.volume) ||
|
|
@@ -476,7 +533,9 @@ export class GPURigidBodyWorld {
|
|
|
476
533
|
(props.continuous.maximumCandidates ?? this.maximumPairs) > 0x40000000 ||
|
|
477
534
|
(props.continuous.mode === 'convex' &&
|
|
478
535
|
(Boolean(props.joints?.length) ||
|
|
479
|
-
colliders.some(collider =>
|
|
536
|
+
colliders.some(collider =>
|
|
537
|
+
['plane', 'triangle-mesh', 'height-field'].includes(collider.shape.type)
|
|
538
|
+
)))
|
|
480
539
|
)
|
|
481
540
|
throw new Error('Invalid continuous settings');
|
|
482
541
|
for (const index of props.continuous.bodies) {
|
|
@@ -512,39 +571,114 @@ export class GPURigidBodyWorld {
|
|
|
512
571
|
const definitions = structuredClone({colliders, props});
|
|
513
572
|
this.props = definitions.props;
|
|
514
573
|
this.colliders = definitions.colliders;
|
|
515
|
-
|
|
516
|
-
if (
|
|
517
|
-
|
|
574
|
+
this.ensembleTerrainSlots = new Set(this.props.ensembleTerrainSlots);
|
|
575
|
+
if (
|
|
576
|
+
this.ensembleTerrainSlots.size &&
|
|
577
|
+
(!this.props.ensembleBodiesPerInstance ||
|
|
578
|
+
[...this.ensembleTerrainSlots].some(
|
|
579
|
+
index => this.colliders[index]?.shape.type !== 'height-field'
|
|
580
|
+
))
|
|
581
|
+
)
|
|
582
|
+
throw new Error('Invalid ensemble terrain slots');
|
|
583
|
+
if (this.props.ensembleTerrainAtlas) {
|
|
584
|
+
this.terrainAtlas = new RigidBodyTerrainAtlas(
|
|
585
|
+
this.props.ensembleTerrainAtlas,
|
|
586
|
+
Array.from(this.ensembleTerrainSlots, collider => {
|
|
587
|
+
const shape = this.colliders[collider].shape;
|
|
588
|
+
if (shape.type !== 'height-field') throw new Error('Invalid ensemble terrain slot');
|
|
589
|
+
return {collider, width: shape.field.width, height: shape.field.height};
|
|
590
|
+
})
|
|
591
|
+
);
|
|
592
|
+
}
|
|
593
|
+
this.bodyColliderStarts = new Uint32Array(this.count + 1);
|
|
594
|
+
let colliderIndex = 0;
|
|
595
|
+
for (let body = 0; body < this.count; body++) {
|
|
596
|
+
this.bodyColliderStarts[body] = colliderIndex;
|
|
597
|
+
while (this.colliders[colliderIndex]?.body === body) colliderIndex++;
|
|
598
|
+
}
|
|
599
|
+
this.bodyColliderStarts[this.count] = colliderIndex;
|
|
600
|
+
if (this.props.vehicle && this.props.vehicles) throw new Error('Choose vehicle or vehicles');
|
|
601
|
+
this.vehicles = this.props.vehicles ?? (this.props.vehicle ? [this.props.vehicle] : []);
|
|
602
|
+
this.multiSurfaceVehicles = this.vehicles.some(
|
|
603
|
+
vehicle => vehicle.additionalTerrainColliders?.length
|
|
604
|
+
);
|
|
605
|
+
const bodiesPerInstance = props.ensembleBodiesPerInstance;
|
|
606
|
+
const collidersPerInstance = props.collisionPartitionSize!;
|
|
607
|
+
this.vehiclesPerInstance = bodiesPerInstance
|
|
608
|
+
? this.vehicles.length / (this.count / bodiesPerInstance)
|
|
609
|
+
: 0;
|
|
610
|
+
if (!Number.isInteger(this.vehiclesPerInstance))
|
|
611
|
+
throw new Error('Invalid ensemble vehicle layout');
|
|
612
|
+
const vehicleChassis = new Set<number>();
|
|
613
|
+
for (const [vehicleIndex, vehicle] of this.vehicles.entries()) {
|
|
614
|
+
const instance = bodiesPerInstance ? Math.floor(vehicleIndex / this.vehiclesPerInstance) : 0;
|
|
615
|
+
const terrainIndices = [
|
|
616
|
+
vehicle.terrainCollider,
|
|
617
|
+
...(vehicle.additionalTerrainColliders ?? [])
|
|
618
|
+
];
|
|
518
619
|
const chassis = this.props.bodies[vehicle.chassis];
|
|
519
|
-
const ground = terrain && this.props.bodies[terrain.body];
|
|
520
620
|
if (
|
|
521
621
|
!chassis ||
|
|
522
|
-
|
|
523
|
-
|
|
622
|
+
vehicleChassis.has(vehicle.chassis) ||
|
|
623
|
+
terrainIndices.length > 4 ||
|
|
624
|
+
new Set(terrainIndices).size !== terrainIndices.length ||
|
|
625
|
+
terrainIndices.some(colliderIndex => {
|
|
626
|
+
const collider = this.colliders[colliderIndex];
|
|
627
|
+
const ground = collider && this.props.bodies[collider.body];
|
|
628
|
+
return (
|
|
629
|
+
!ground ||
|
|
630
|
+
collider.isTrigger ||
|
|
631
|
+
this.getBodyMode(collider.body) !== 'static' ||
|
|
632
|
+
(bodiesPerInstance && Math.floor(colliderIndex / collidersPerInstance) !== instance)
|
|
633
|
+
);
|
|
634
|
+
}) ||
|
|
524
635
|
(chassis.mode ?? (chassis.mass === 0 ? 'static' : 'dynamic')) !== 'dynamic' ||
|
|
525
|
-
(ground.mode ?? (ground.mass === 0 ? 'static' : 'dynamic')) !== 'static' ||
|
|
526
636
|
vehicle.wheels.length !== 4 ||
|
|
527
|
-
|
|
528
|
-
this.props.ensembleBodiesPerInstance ||
|
|
637
|
+
(bodiesPerInstance && Math.floor(vehicle.chassis / bodiesPerInstance) !== instance) ||
|
|
529
638
|
![vehicle.radius, vehicle.travel, vehicle.springRate, vehicle.wheelInertia].every(
|
|
530
639
|
value => Number.isFinite(value) && value > 0
|
|
531
640
|
) ||
|
|
532
641
|
![vehicle.damping, vehicle.grip, vehicle.motorTorque, vehicle.brakeTorque].every(
|
|
533
642
|
value => Number.isFinite(value) && value >= 0
|
|
534
643
|
) ||
|
|
644
|
+
(vehicle.steeringWheelbase !== undefined &&
|
|
645
|
+
(!Number.isFinite(Math.fround(vehicle.steeringWheelbase)) ||
|
|
646
|
+
vehicle.steeringWheelbase <= 0)) ||
|
|
647
|
+
!Number.isFinite(Math.fround(vehicle.antiRollRate ?? 0)) ||
|
|
648
|
+
(vehicle.antiRollRate ?? 0) < 0 ||
|
|
649
|
+
(vehicle.slipGain !== undefined &&
|
|
650
|
+
(vehicle.slipGain.length !== 2 ||
|
|
651
|
+
!vehicle.slipGain.every(gain => Number.isFinite(Math.fround(gain)) && gain >= 0))) ||
|
|
535
652
|
vehicle.wheels.some(
|
|
536
653
|
wheel => wheel.mount.length !== 3 || !wheel.mount.every(Number.isFinite)
|
|
537
654
|
)
|
|
538
655
|
)
|
|
539
656
|
throw new Error('Invalid vehicle configuration');
|
|
657
|
+
vehicleChassis.add(vehicle.chassis);
|
|
540
658
|
}
|
|
541
659
|
|
|
542
660
|
if (props.ensembleBodiesPerInstance)
|
|
543
661
|
this.initialEnsembleBodies = this.props.bodies.slice(0, props.ensembleBodiesPerInstance);
|
|
544
662
|
}
|
|
545
663
|
|
|
664
|
+
/** Allocation size including optional immutable terrain rows after the wheel state. */
|
|
665
|
+
private getVehicleByteLength(): number {
|
|
666
|
+
return (
|
|
667
|
+
this.vehicles.length *
|
|
668
|
+
(VEHICLE_STRIDE + (this.multiSurfaceVehicles ? VEHICLE_TERRAIN_ROW_SIZE : 0))
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
|
|
546
672
|
private getStorageLayout() {
|
|
547
|
-
const packed = packRigidBodyShapes(
|
|
673
|
+
const packed = packRigidBodyShapes(
|
|
674
|
+
this.colliders,
|
|
675
|
+
Boolean(this.props.ensembleBodiesPerInstance),
|
|
676
|
+
this.ensembleTerrainSlots,
|
|
677
|
+
Boolean(this.terrainAtlas)
|
|
678
|
+
);
|
|
679
|
+
const geometryWords = packed.geometry.length + (this.terrainAtlas?.wordLength ?? 0);
|
|
680
|
+
if (this.terrainAtlas && geometryWords >= 2 ** 26)
|
|
681
|
+
throw new Error('Terrain atlas exceeds address capacity');
|
|
548
682
|
const sparse = this.broadPhase === 'hierarchical-grid';
|
|
549
683
|
const extended = this.colliders.some(
|
|
550
684
|
collider =>
|
|
@@ -561,7 +695,7 @@ export class GPURigidBodyWorld {
|
|
|
561
695
|
this.count,
|
|
562
696
|
this.colliderStorageCount,
|
|
563
697
|
this.maximumPairs,
|
|
564
|
-
|
|
698
|
+
geometryWords,
|
|
565
699
|
sparse,
|
|
566
700
|
extended,
|
|
567
701
|
parallel,
|
|
@@ -573,8 +707,17 @@ export class GPURigidBodyWorld {
|
|
|
573
707
|
this.props.ensembleBodiesPerInstance ? this.count / this.props.ensembleBodiesPerInstance : 0
|
|
574
708
|
)
|
|
575
709
|
};
|
|
576
|
-
if (this.
|
|
577
|
-
|
|
710
|
+
if (this.vehicles.length) {
|
|
711
|
+
const byteLength = this.getVehicleByteLength();
|
|
712
|
+
storage.buffers.push({name: 'vehicle', byteLength, uniform: false});
|
|
713
|
+
if (this.props.failurePolicy === 'rollback') {
|
|
714
|
+
storage.buffers.push({
|
|
715
|
+
name: this.vehiclesPerInstance ? 'checkpoint-vehicles' : 'checkpoint-7',
|
|
716
|
+
byteLength: this.vehiclesPerInstance ? this.vehicles.length * VEHICLE_STRIDE : byteLength,
|
|
717
|
+
uniform: false
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
578
721
|
if (this.props.continuous?.mode === 'convex') {
|
|
579
722
|
storage.buffers = storage.buffers.filter(buffer => buffer.name !== 'continuous-previous');
|
|
580
723
|
storage.buffers.push({name: 'continuous-dispatch', byteLength: 16, uniform: false});
|
|
@@ -648,7 +791,9 @@ export class GPURigidBodyWorld {
|
|
|
648
791
|
this.count,
|
|
649
792
|
this.props.ensembleBodiesPerInstance!,
|
|
650
793
|
this.props.collisionPartitionSize!,
|
|
651
|
-
this.maximumPairs
|
|
794
|
+
this.maximumPairs,
|
|
795
|
+
this.vehiclesPerInstance,
|
|
796
|
+
this.ensembleTerrainSlots
|
|
652
797
|
);
|
|
653
798
|
return this.ensembleReset.byteLength;
|
|
654
799
|
}
|
|
@@ -660,41 +805,40 @@ export class GPURigidBodyWorld {
|
|
|
660
805
|
const colliderStart = instance * this.props.collisionPartitionSize!;
|
|
661
806
|
let colliderIndex = colliderStart;
|
|
662
807
|
const restored = this.initialEnsembleBodies!.map(body => {
|
|
663
|
-
|
|
664
|
-
|
|
808
|
+
const {shape, colliders, ...properties} = body;
|
|
809
|
+
const resetCollider = (definition: GPURigidBodyCollider): GPURigidBodyCollider => {
|
|
810
|
+
const index = colliderIndex++;
|
|
811
|
+
const {body: _, ...current} = this.colliders[index];
|
|
812
|
+
if (this.ensembleTerrainSlots.has(index)) return current;
|
|
665
813
|
return {
|
|
666
|
-
...
|
|
814
|
+
...definition,
|
|
667
815
|
shape:
|
|
668
|
-
|
|
669
|
-
? current
|
|
670
|
-
:
|
|
816
|
+
definition.shape.type === 'convex-hull' || definition.shape.type === 'triangle-mesh'
|
|
817
|
+
? current.shape
|
|
818
|
+
: definition.shape,
|
|
819
|
+
excludedColliders: definition.excludedColliders?.map(index => index + colliderStart)
|
|
671
820
|
};
|
|
672
|
-
}
|
|
673
|
-
return {
|
|
674
|
-
...body,
|
|
675
|
-
colliders: body.colliders.map(collider => {
|
|
676
|
-
const current = this.colliders[colliderIndex++].shape;
|
|
677
|
-
return {
|
|
678
|
-
...collider,
|
|
679
|
-
shape:
|
|
680
|
-
collider.shape.type === 'convex-hull' || collider.shape.type === 'triangle-mesh'
|
|
681
|
-
? current
|
|
682
|
-
: collider.shape,
|
|
683
|
-
excludedColliders: collider.excludedColliders?.map(index => index + colliderStart)
|
|
684
|
-
};
|
|
685
|
-
})
|
|
686
821
|
};
|
|
822
|
+
if (shape && !this.ensembleTerrainSlots.has(colliderIndex))
|
|
823
|
+
return {...body, shape: resetCollider({shape}).shape};
|
|
824
|
+
return {...properties, colliders: (colliders ?? [{shape: shape!}]).map(resetCollider)};
|
|
687
825
|
});
|
|
688
|
-
const definitions =
|
|
826
|
+
const definitions = this.props.bodies as GPURigidBody[];
|
|
689
827
|
definitions.splice(bodyStart, restored.length, ...restored);
|
|
690
|
-
this.
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
828
|
+
this.restoreColliderDefinitions(bodyStart, bodyStart + restored.length);
|
|
829
|
+
const metadata = this.ownedBuffers.find(buffer => buffer.id === `${this.id}-bodies`)!;
|
|
830
|
+
for (let index = colliderStart; index < colliderIndex; index++) {
|
|
831
|
+
this.colliderShapeScales.delete(index);
|
|
832
|
+
if (!this.ensembleTerrainSlots.has(index)) continue;
|
|
833
|
+
const collider = this.colliders[index];
|
|
834
|
+
const center = definitions[collider.body].centerOfMass ?? [0, 0, 0];
|
|
835
|
+
metadata.write(
|
|
836
|
+
new Float32Array(
|
|
837
|
+
(collider.position ?? [0, 0, 0]).map((value, axis) => value - center[axis])
|
|
838
|
+
),
|
|
839
|
+
this.count * 48 + index * 96 + 16
|
|
840
|
+
);
|
|
841
|
+
}
|
|
698
842
|
this.ensembleReset.reset(
|
|
699
843
|
instance,
|
|
700
844
|
this.origin.map((value, axis) => value - this.ensembleResetOrigin![axis])
|
|
@@ -750,6 +894,7 @@ export class GPURigidBodyWorld {
|
|
|
750
894
|
claimedContacts,
|
|
751
895
|
journaledContacts,
|
|
752
896
|
bodySnapshotBytes: activeBodies * 80,
|
|
897
|
+
vehicleSnapshotBytes: activeInstances * this.vehiclesPerInstance * VEHICLE_STRIDE,
|
|
753
898
|
contactSnapshotBytes: journaledContacts * 416,
|
|
754
899
|
allocatorSnapshotBytes: (8 + activeInstances * 2 + journaledContacts * 3) * 4,
|
|
755
900
|
residentInstances: this.count / this.props.ensembleBodiesPerInstance!,
|
|
@@ -771,7 +916,9 @@ export class GPURigidBodyWorld {
|
|
|
771
916
|
|
|
772
917
|
/** Allocation preflight without GPU allocation. Graph scratch and driver overhead are separate. */
|
|
773
918
|
getCapacityInfo(): GPURigidBodyCapacityInfo {
|
|
774
|
-
const
|
|
919
|
+
const buffers = this.allocationPlan
|
|
920
|
+
? this.allocationPlan.map(buffer => ({...buffer}))
|
|
921
|
+
: this.getStorageLayout().buffers;
|
|
775
922
|
return {
|
|
776
923
|
bodyCount: this.count,
|
|
777
924
|
colliderCount: this.colliderCount,
|
|
@@ -808,6 +955,11 @@ export class GPURigidBodyWorld {
|
|
|
808
955
|
) > graph.device.limits.maxComputeWorkgroupsPerDimension
|
|
809
956
|
)
|
|
810
957
|
throw new Error('Continuous candidate dispatch exceeds device limits');
|
|
958
|
+
if (
|
|
959
|
+
!this.vehiclesPerInstance &&
|
|
960
|
+
this.vehicles.length > graph.device.limits.maxComputeWorkgroupsPerDimension
|
|
961
|
+
)
|
|
962
|
+
throw new Error('Vehicle dispatch exceeds device limits');
|
|
811
963
|
for (const buffer of allocationPlan) {
|
|
812
964
|
const bindingLimit = buffer.uniform
|
|
813
965
|
? graph.device.limits.maxUniformBufferBindingSize
|
|
@@ -815,6 +967,7 @@ export class GPURigidBodyWorld {
|
|
|
815
967
|
if (buffer.byteLength > Math.min(graph.device.limits.maxBufferSize, bindingLimit))
|
|
816
968
|
throw new Error(`Rigid-body ${buffer.name} storage exceeds device limits`);
|
|
817
969
|
}
|
|
970
|
+
this.allocationPlan = allocationPlan;
|
|
818
971
|
this.device = graph.device;
|
|
819
972
|
const allocate = (name: string, data: Float32Array | Uint32Array | number, uniform = false) => {
|
|
820
973
|
const buffer = graph.device.createBuffer({
|
|
@@ -844,6 +997,32 @@ export class GPURigidBodyWorld {
|
|
|
844
997
|
: undefined;
|
|
845
998
|
const metadata = new Float32Array(metadataLength);
|
|
846
999
|
metadata.set(packed.geometry, geometryOffset);
|
|
1000
|
+
if (this.terrainAtlas) {
|
|
1001
|
+
this.terrainGeometryWord = geometryOffset;
|
|
1002
|
+
this.terrainAtlasWord = geometryOffset + packed.geometry.length;
|
|
1003
|
+
const {wordsByCollider, uploads} = this.terrainAtlas.bind(
|
|
1004
|
+
Array.from(packed.atlasFields, ([collider, field]) => ({
|
|
1005
|
+
collider,
|
|
1006
|
+
data: new Float32Array(field.data)
|
|
1007
|
+
}))
|
|
1008
|
+
);
|
|
1009
|
+
for (const {word, data} of uploads) metadata.set(data, this.terrainAtlasWord + word);
|
|
1010
|
+
for (const [collider, word] of wordsByCollider) {
|
|
1011
|
+
const field = packed.atlasFields.get(collider)!;
|
|
1012
|
+
const address = (packed.geometry.length + word) / 4;
|
|
1013
|
+
const shape = packed.shapes[collider];
|
|
1014
|
+
shape.padding[0] = address;
|
|
1015
|
+
shape.padding[3] = field.triangleCount;
|
|
1016
|
+
shape.policies[0] = address + field.nodeOffset;
|
|
1017
|
+
shape.policies[1] = field.nodeCount;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
this.heightFieldSlots = new Map(
|
|
1021
|
+
Array.from(packed.heightFields, ([collider, offset]) => [
|
|
1022
|
+
collider,
|
|
1023
|
+
(geometryOffset + offset * 4) * 4
|
|
1024
|
+
])
|
|
1025
|
+
);
|
|
847
1026
|
const bodyColliders: GPURigidBodyCollider[][] = Array.from({length: this.count}, () => []);
|
|
848
1027
|
if (this.colliderCount)
|
|
849
1028
|
for (const collider of this.colliders) bodyColliders[collider.body].push(collider);
|
|
@@ -912,7 +1091,10 @@ export class GPURigidBodyWorld {
|
|
|
912
1091
|
material?.restitutionCombine ? policies.indexOf(material.restitutionCombine) : 4,
|
|
913
1092
|
material?.frictionCombine ? policies.indexOf(material.frictionCombine) : 4,
|
|
914
1093
|
...shape.policies,
|
|
915
|
-
|
|
1094
|
+
shape.padding[0],
|
|
1095
|
+
shape.padding[1],
|
|
1096
|
+
this.ensembleTerrainSlots.has(index) ? 1 : shape.padding[2],
|
|
1097
|
+
shape.padding[3]
|
|
916
1098
|
],
|
|
917
1099
|
this.count * 12 + index * 24
|
|
918
1100
|
);
|
|
@@ -1084,7 +1266,8 @@ export class GPURigidBodyWorld {
|
|
|
1084
1266
|
this.props.compactContacts ?? true,
|
|
1085
1267
|
this.props.collisionPartitionSize,
|
|
1086
1268
|
this.props.ensembleBodiesPerInstance,
|
|
1087
|
-
this.props.parallelContactSolver === 'block'
|
|
1269
|
+
this.props.parallelContactSolver === 'block',
|
|
1270
|
+
this.colliders.some(collider => collider.shape.type === 'height-field')
|
|
1088
1271
|
);
|
|
1089
1272
|
const parallelBindings: Record<string, readonly string[]> = {
|
|
1090
1273
|
parallelReset: ['parallelState'],
|
|
@@ -1158,51 +1341,6 @@ export class GPURigidBodyWorld {
|
|
|
1158
1341
|
{id: `${this.id}-statistics`, byteLength: 64, usage: Buffer.STORAGE},
|
|
1159
1342
|
this.simulationStatistics
|
|
1160
1343
|
);
|
|
1161
|
-
const checkpointStates = [
|
|
1162
|
-
'positions',
|
|
1163
|
-
'orientations',
|
|
1164
|
-
'velocities',
|
|
1165
|
-
'angularVelocities',
|
|
1166
|
-
'sleepStates',
|
|
1167
|
-
'targets'
|
|
1168
|
-
].map(name => {
|
|
1169
|
-
const binding = bindings.find(binding => binding.name === name)!;
|
|
1170
|
-
return {buffer: binding.buffer, resource: binding.resource};
|
|
1171
|
-
});
|
|
1172
|
-
const restoreCheckpoint =
|
|
1173
|
-
this.props.failurePolicy === 'rollback'
|
|
1174
|
-
? this.ensembleBuffer
|
|
1175
|
-
? addEnsembleCheckpoint(
|
|
1176
|
-
graph,
|
|
1177
|
-
this.id,
|
|
1178
|
-
checkpointStates,
|
|
1179
|
-
{buffer: this.simulationStatistics, resource: statisticsResource},
|
|
1180
|
-
bindings.find(binding => binding.name === 'ensemble')!,
|
|
1181
|
-
bindings.find(binding => binding.name === 'manifolds')!,
|
|
1182
|
-
this.props.ensembleBodiesPerInstance!,
|
|
1183
|
-
this.maximumPairs,
|
|
1184
|
-
allocate
|
|
1185
|
-
)
|
|
1186
|
-
: addRigidBodyCheckpoint(
|
|
1187
|
-
graph,
|
|
1188
|
-
this.id,
|
|
1189
|
-
[
|
|
1190
|
-
'positions',
|
|
1191
|
-
'orientations',
|
|
1192
|
-
'velocities',
|
|
1193
|
-
'angularVelocities',
|
|
1194
|
-
'sleepStates',
|
|
1195
|
-
'targets',
|
|
1196
|
-
...(this.ensembleBuffer ? [] : ['manifolds'])
|
|
1197
|
-
].map(name => {
|
|
1198
|
-
const binding = bindings.find(binding => binding.name === name)!;
|
|
1199
|
-
return {buffer: binding.buffer, resource: binding.resource};
|
|
1200
|
-
}),
|
|
1201
|
-
{buffer: this.simulationStatistics, resource: statisticsResource},
|
|
1202
|
-
allocate
|
|
1203
|
-
)
|
|
1204
|
-
: undefined;
|
|
1205
|
-
|
|
1206
1344
|
const continuousSelection = new Uint32Array(this.count);
|
|
1207
1345
|
for (const body of this.props.continuous?.bodies ?? [])
|
|
1208
1346
|
continuousSelection[body] = this.colliders.findIndex(collider => collider.body === body) + 1;
|
|
@@ -1269,51 +1407,88 @@ export class GPURigidBodyWorld {
|
|
|
1269
1407
|
parallelMarkSleep: 'Identify islands whose bodies are quiet enough to sleep.',
|
|
1270
1408
|
parallelSleep: 'Put quiet constraint islands to sleep.'
|
|
1271
1409
|
};
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
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;
|
|
1410
|
+
let vehicleResource: {buffer: Buffer; resource: GraphBufferHandle} | undefined;
|
|
1411
|
+
let addVehiclePass: (() => void) | undefined;
|
|
1412
|
+
if (this.vehicles.length) {
|
|
1413
|
+
const packed = new Float32Array(this.getVehicleByteLength() / 4);
|
|
1414
|
+
for (const [vehicleIndex, vehicle] of this.vehicles.entries()) {
|
|
1415
|
+
const data = packed.subarray(
|
|
1416
|
+
(vehicleIndex * VEHICLE_STRIDE) / 4,
|
|
1417
|
+
((vehicleIndex + 1) * VEHICLE_STRIDE) / 4
|
|
1418
|
+
);
|
|
1294
1419
|
data.set(
|
|
1295
1420
|
[
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
0,
|
|
1305
|
-
0,
|
|
1306
|
-
1,
|
|
1307
|
-
0,
|
|
1308
|
-
wheel.mount[0],
|
|
1309
|
-
wheel.mount[1],
|
|
1310
|
-
wheel.mount[2] - vehicle.travel,
|
|
1311
|
-
1
|
|
1421
|
+
vehicle.radius,
|
|
1422
|
+
vehicle.travel,
|
|
1423
|
+
vehicle.springRate,
|
|
1424
|
+
vehicle.damping,
|
|
1425
|
+
vehicle.grip,
|
|
1426
|
+
vehicle.motorTorque,
|
|
1427
|
+
vehicle.brakeTorque,
|
|
1428
|
+
vehicle.wheelInertia
|
|
1312
1429
|
],
|
|
1313
|
-
|
|
1430
|
+
4
|
|
1314
1431
|
);
|
|
1315
|
-
|
|
1316
|
-
|
|
1432
|
+
new Uint32Array(data.buffer, data.byteOffset, data.length).set(
|
|
1433
|
+
[vehicle.chassis, vehicle.terrainCollider],
|
|
1434
|
+
12
|
|
1435
|
+
);
|
|
1436
|
+
data.set([vehicle.steeringWheelbase ?? 0, vehicle.antiRollRate ?? 0], 14);
|
|
1437
|
+
const [longitudinalGain, lateralGain] = vehicle.slipGain ?? [1.1, 1.5];
|
|
1438
|
+
vehicle.wheels.forEach((wheel, index) => {
|
|
1439
|
+
const offset = 16 + index * 12;
|
|
1440
|
+
data.set([...wheel.mount, longitudinalGain + 1], offset);
|
|
1441
|
+
data.set(
|
|
1442
|
+
[Number(Boolean(wheel.steer)), Number(Boolean(wheel.drive)), lateralGain + 1],
|
|
1443
|
+
offset + 4
|
|
1444
|
+
);
|
|
1445
|
+
data[offset + 10] = vehicle.travel;
|
|
1446
|
+
data.set(
|
|
1447
|
+
[
|
|
1448
|
+
1,
|
|
1449
|
+
0,
|
|
1450
|
+
0,
|
|
1451
|
+
0,
|
|
1452
|
+
0,
|
|
1453
|
+
1,
|
|
1454
|
+
0,
|
|
1455
|
+
0,
|
|
1456
|
+
0,
|
|
1457
|
+
0,
|
|
1458
|
+
1,
|
|
1459
|
+
0,
|
|
1460
|
+
wheel.mount[0],
|
|
1461
|
+
wheel.mount[1],
|
|
1462
|
+
wheel.mount[2] - vehicle.travel,
|
|
1463
|
+
1
|
|
1464
|
+
],
|
|
1465
|
+
64 + 16 * index
|
|
1466
|
+
);
|
|
1467
|
+
});
|
|
1468
|
+
}
|
|
1469
|
+
if (this.multiSurfaceVehicles) {
|
|
1470
|
+
// Place the immutable terrain rows after the unchanged vehicle pose/telemetry ranges.
|
|
1471
|
+
const terrainRows = new Uint32Array(packed.buffer, this.vehicles.length * VEHICLE_STRIDE);
|
|
1472
|
+
terrainRows.fill(0xffffffff);
|
|
1473
|
+
for (const [vehicleIndex, vehicle] of this.vehicles.entries())
|
|
1474
|
+
terrainRows.set(
|
|
1475
|
+
vehicle.additionalTerrainColliders ?? [],
|
|
1476
|
+
vehicleIndex * (VEHICLE_TERRAIN_ROW_SIZE / 4)
|
|
1477
|
+
);
|
|
1478
|
+
}
|
|
1479
|
+
this.vehicleBuffer = allocate('vehicle', packed);
|
|
1480
|
+
vehicleResource = {
|
|
1481
|
+
buffer: this.vehicleBuffer,
|
|
1482
|
+
resource: graph.importBuffer(
|
|
1483
|
+
{
|
|
1484
|
+
id: this.id + '-vehicle',
|
|
1485
|
+
byteLength: packed.byteLength,
|
|
1486
|
+
usage: Buffer.STORAGE | Buffer.COPY_SRC
|
|
1487
|
+
},
|
|
1488
|
+
this.vehicleBuffer
|
|
1489
|
+
)
|
|
1490
|
+
};
|
|
1491
|
+
const ensembleBinding = bindings.find(binding => binding.name === 'ensemble');
|
|
1317
1492
|
const vehicleBindings = [
|
|
1318
1493
|
...bindings.filter(binding =>
|
|
1319
1494
|
[
|
|
@@ -1323,22 +1498,22 @@ export class GPURigidBodyWorld {
|
|
|
1323
1498
|
'velocities',
|
|
1324
1499
|
'angularVelocities',
|
|
1325
1500
|
'bodies',
|
|
1326
|
-
'sleepStates'
|
|
1501
|
+
'sleepStates',
|
|
1502
|
+
'ensemble'
|
|
1327
1503
|
].includes(binding.name)
|
|
1328
1504
|
),
|
|
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
|
-
}
|
|
1505
|
+
{name: 'vehicle', location: 12, ...vehicleResource}
|
|
1338
1506
|
];
|
|
1339
1507
|
const properties: BoundKernelProps = {
|
|
1340
1508
|
id: this.id + '-suspension',
|
|
1341
|
-
source:
|
|
1509
|
+
source:
|
|
1510
|
+
readOnlyEnsembleShader(source) +
|
|
1511
|
+
RIGID_BODY_QUERY_GEOMETRY_SHADER +
|
|
1512
|
+
getVehicleShader(
|
|
1513
|
+
this.vehicles.length,
|
|
1514
|
+
this.multiSurfaceVehicles,
|
|
1515
|
+
this.vehiclesPerInstance
|
|
1516
|
+
),
|
|
1342
1517
|
entryPoint: 'advanceVehicle',
|
|
1343
1518
|
shaderLayout: {
|
|
1344
1519
|
bindings: vehicleBindings.map(
|
|
@@ -1349,7 +1524,7 @@ export class GPURigidBodyWorld {
|
|
|
1349
1524
|
name,
|
|
1350
1525
|
location,
|
|
1351
1526
|
group: 0,
|
|
1352
|
-
type: name === 'bodies' ? 'read-only-storage' : 'storage'
|
|
1527
|
+
type: name === 'bodies' || name === 'ensemble' ? 'read-only-storage' : 'storage'
|
|
1353
1528
|
}
|
|
1354
1529
|
)
|
|
1355
1530
|
}
|
|
@@ -1364,25 +1539,88 @@ export class GPURigidBodyWorld {
|
|
|
1364
1539
|
vehicleBindings.map(binding => [binding.name, getBuffer(binding.resource)])
|
|
1365
1540
|
)
|
|
1366
1541
|
);
|
|
1367
|
-
|
|
1542
|
+
if (ensembleBinding)
|
|
1543
|
+
computation.kernel.dispatchIndirect(computePass, {
|
|
1544
|
+
bindings: computation.bindings,
|
|
1545
|
+
indirectBuffer: getBuffer(ensembleBinding.resource),
|
|
1546
|
+
indirectOffset: 16
|
|
1547
|
+
});
|
|
1548
|
+
else
|
|
1549
|
+
computation.kernel.dispatch(computePass, {
|
|
1550
|
+
bindings: computation.bindings,
|
|
1551
|
+
x: this.vehicles.length
|
|
1552
|
+
});
|
|
1368
1553
|
},
|
|
1369
1554
|
destroy: () => computation.kernel.destroy()
|
|
1370
1555
|
});
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1556
|
+
addVehiclePass = () =>
|
|
1557
|
+
graph.addComputePass({
|
|
1558
|
+
id: properties.id!,
|
|
1559
|
+
description: 'Sweep four wheels and apply suspension and tire forces per chassis.',
|
|
1560
|
+
resources: [
|
|
1561
|
+
...vehicleBindings.map(
|
|
1562
|
+
binding =>
|
|
1563
|
+
({
|
|
1564
|
+
buffer: binding.resource,
|
|
1565
|
+
usage:
|
|
1566
|
+
binding.name === 'settings'
|
|
1567
|
+
? 'uniform'
|
|
1568
|
+
: binding.name === 'bodies' || binding.name === 'ensemble'
|
|
1569
|
+
? 'storage-read'
|
|
1570
|
+
: 'storage-read-write'
|
|
1571
|
+
}) as const
|
|
1572
|
+
),
|
|
1573
|
+
...(ensembleBinding
|
|
1574
|
+
? [{buffer: ensembleBinding.resource, usage: 'indirect' as const}]
|
|
1575
|
+
: [])
|
|
1576
|
+
],
|
|
1577
|
+
compile: () => executable(createBoundKernel(graph.device, properties)),
|
|
1578
|
+
compileAsync: async () =>
|
|
1579
|
+
executable(await createBoundKernelAsync(graph.device, properties))
|
|
1580
|
+
});
|
|
1385
1581
|
}
|
|
1582
|
+
const checkpointStates = [
|
|
1583
|
+
'positions',
|
|
1584
|
+
'orientations',
|
|
1585
|
+
'velocities',
|
|
1586
|
+
'angularVelocities',
|
|
1587
|
+
'sleepStates',
|
|
1588
|
+
'targets'
|
|
1589
|
+
].map(name => {
|
|
1590
|
+
const binding = bindings.find(binding => binding.name === name)!;
|
|
1591
|
+
return {buffer: binding.buffer, resource: binding.resource};
|
|
1592
|
+
});
|
|
1593
|
+
const restoreCheckpoint =
|
|
1594
|
+
this.props.failurePolicy === 'rollback'
|
|
1595
|
+
? this.ensembleBuffer
|
|
1596
|
+
? addEnsembleCheckpoint(
|
|
1597
|
+
graph,
|
|
1598
|
+
this.id,
|
|
1599
|
+
checkpointStates,
|
|
1600
|
+
{buffer: this.simulationStatistics, resource: statisticsResource},
|
|
1601
|
+
bindings.find(binding => binding.name === 'ensemble')!,
|
|
1602
|
+
bindings.find(binding => binding.name === 'manifolds')!,
|
|
1603
|
+
this.props.ensembleBodiesPerInstance!,
|
|
1604
|
+
this.maximumPairs,
|
|
1605
|
+
allocate,
|
|
1606
|
+
vehicleResource && {
|
|
1607
|
+
state: vehicleResource,
|
|
1608
|
+
vehiclesPerInstance: this.vehiclesPerInstance
|
|
1609
|
+
}
|
|
1610
|
+
)
|
|
1611
|
+
: addRigidBodyCheckpoint(
|
|
1612
|
+
graph,
|
|
1613
|
+
this.id,
|
|
1614
|
+
[
|
|
1615
|
+
...checkpointStates,
|
|
1616
|
+
bindings.find(binding => binding.name === 'manifolds')!,
|
|
1617
|
+
...(vehicleResource ? [vehicleResource] : [])
|
|
1618
|
+
],
|
|
1619
|
+
{buffer: this.simulationStatistics, resource: statisticsResource},
|
|
1620
|
+
allocate
|
|
1621
|
+
)
|
|
1622
|
+
: undefined;
|
|
1623
|
+
|
|
1386
1624
|
for (const entryPoint of [
|
|
1387
1625
|
...(this.ensembleBuffer
|
|
1388
1626
|
? ['ensembleClear', 'ensembleMark', 'ensembleCompact', 'ensembleDispatch']
|
|
@@ -1421,7 +1659,10 @@ export class GPURigidBodyWorld {
|
|
|
1421
1659
|
]
|
|
1422
1660
|
: [...(extended && this.props.joints?.length ? ['meshCollect'] : []), 'solve', 'finish'])
|
|
1423
1661
|
]) {
|
|
1424
|
-
if (entryPoint === 'integrate')
|
|
1662
|
+
if (entryPoint === 'integrate') {
|
|
1663
|
+
restoreCheckpoint?.save?.();
|
|
1664
|
+
addVehiclePass?.();
|
|
1665
|
+
}
|
|
1425
1666
|
if (sparse && entryPoint === 'collide') {
|
|
1426
1667
|
const bodyBinding = bindings.find(binding => binding.name === 'bodies')!;
|
|
1427
1668
|
const minimumBinding = bindings.find(binding => binding.name === 'minima')!;
|
|
@@ -2079,6 +2320,52 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2079
2320
|
)
|
|
2080
2321
|
)
|
|
2081
2322
|
});
|
|
2323
|
+
if (this.heightFieldSlots.size && !this.ensembleBuffer) {
|
|
2324
|
+
this.terrainWake = createBoundKernel(graph.device, {
|
|
2325
|
+
id: `${this.id}-terrain-wake`,
|
|
2326
|
+
entryPoint: 'wakeTerrain',
|
|
2327
|
+
source:
|
|
2328
|
+
controlProperties.source +
|
|
2329
|
+
/* wgsl */ `
|
|
2330
|
+
@group(0) @binding(26) var<storage,read_write> terrainSleep:array<atomic<u32>>;
|
|
2331
|
+
@compute @workgroup_size(64) fn wakeTerrain(@builtin(global_invocation_id) invocation:vec3u) {
|
|
2332
|
+
let collider=invocation.x;if(collider>=COLLIDER_COUNT){return;}
|
|
2333
|
+
let body=colliderBody(collider);if(!dynamic(body)){return;}
|
|
2334
|
+
let tile=command.bodyIndex.x;if(bodies.colliders[tile].padding.w==0.0){return;}
|
|
2335
|
+
if(any(abs(colliderPosition(collider)-colliderPosition(tile))>shapeWorldExtent(collider)+shapeWorldExtent(tile)+vec3f(settings.solver.x))){return;}
|
|
2336
|
+
// Several colliders on one sleeping body may all overlap the tile.
|
|
2337
|
+
for(var axis=0u;axis<4u;axis++){atomicStore(&terrainSleep[body*4u+axis],0u);}
|
|
2338
|
+
}`,
|
|
2339
|
+
shaderLayout: {
|
|
2340
|
+
bindings: [
|
|
2341
|
+
...shaderLayout.bindings!.filter(binding =>
|
|
2342
|
+
['settings', 'positions', 'orientations', 'bodies'].includes(binding.name)
|
|
2343
|
+
),
|
|
2344
|
+
{name: 'command', group: 0, location: 8, type: 'uniform'},
|
|
2345
|
+
{name: 'terrainSleep', group: 0, location: 26, type: 'storage'}
|
|
2346
|
+
]
|
|
2347
|
+
},
|
|
2348
|
+
bindings: {
|
|
2349
|
+
settings: buffers.settings,
|
|
2350
|
+
positions: buffers.positions,
|
|
2351
|
+
orientations: buffers.orientations,
|
|
2352
|
+
bodies: buffers.bodies,
|
|
2353
|
+
command: this.controlSettings,
|
|
2354
|
+
terrainSleep: this.sleepStates!
|
|
2355
|
+
}
|
|
2356
|
+
});
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
|
|
2360
|
+
/** Wake sleeping bodies overlapping one published terrain footprint. */
|
|
2361
|
+
private wakeTerrainFootprint(collider: number): void {
|
|
2362
|
+
const {kernel, bindings} = this.terrainWake!;
|
|
2363
|
+
this.controlSettings!.write(new Uint32Array([collider]), 48);
|
|
2364
|
+
const encoder = this.device!.createCommandEncoder();
|
|
2365
|
+
const pass = encoder.beginComputePass();
|
|
2366
|
+
kernel.dispatch(pass, {bindings, x: Math.ceil(this.colliderStorageCount / 64)});
|
|
2367
|
+
pass.end();
|
|
2368
|
+
this.device!.submit(encoder.finish());
|
|
2082
2369
|
}
|
|
2083
2370
|
|
|
2084
2371
|
private invalidateState(pass: Parameters<BoundKernel['kernel']['dispatch']>[0]): void {
|
|
@@ -2137,11 +2424,12 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2137
2424
|
}
|
|
2138
2425
|
|
|
2139
2426
|
/** Set signed throttle, steering angle in radians and brake fraction for upcoming substeps. */
|
|
2140
|
-
setVehicleControls(throttle: number, steering: number, brake: number): void {
|
|
2427
|
+
setVehicleControls(throttle: number, steering: number, brake: number, vehicleIndex = 0): void {
|
|
2141
2428
|
if (
|
|
2142
2429
|
!this.vehicleBuffer ||
|
|
2143
2430
|
this.destroyed ||
|
|
2144
|
-
![
|
|
2431
|
+
!this.vehicles[vehicleIndex] ||
|
|
2432
|
+
![throttle, steering, brake].every(value => Number.isFinite(Math.fround(value)))
|
|
2145
2433
|
)
|
|
2146
2434
|
throw new Error('Invalid vehicle controls');
|
|
2147
2435
|
this.vehicleBuffer.write(
|
|
@@ -2150,25 +2438,43 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2150
2438
|
steering,
|
|
2151
2439
|
Math.max(0, Math.min(1, brake)),
|
|
2152
2440
|
0
|
|
2153
|
-
])
|
|
2441
|
+
]),
|
|
2442
|
+
vehicleIndex * VEHICLE_STRIDE
|
|
2154
2443
|
);
|
|
2444
|
+
if (this.vehiclesPerInstance) {
|
|
2445
|
+
const instance = Math.floor(vehicleIndex / this.vehiclesPerInstance);
|
|
2446
|
+
this.ensembleBuffer!.write(new Uint32Array([1]), (16 + instance * 8 + 6) * 4);
|
|
2447
|
+
}
|
|
2155
2448
|
}
|
|
2156
2449
|
|
|
2157
2450
|
/** Borrow four column-major wheel transforms relative to the chassis node, ordered by mount. */
|
|
2158
2451
|
get vehicleWheelPoses() {
|
|
2159
|
-
return this.
|
|
2160
|
-
|
|
2452
|
+
return this.getVehicleWheelPoses();
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
/** Borrow the indexed vehicle’s four chassis-local wheel poses, in mount order. */
|
|
2456
|
+
getVehicleWheelPoses(vehicleIndex = 0) {
|
|
2457
|
+
return this.vehicleBuffer && !this.destroyed && this.vehicles[vehicleIndex]
|
|
2458
|
+
? {
|
|
2459
|
+
buffer: this.vehicleBuffer,
|
|
2460
|
+
byteOffset: vehicleIndex * VEHICLE_STRIDE + 256,
|
|
2461
|
+
byteLength: 256
|
|
2462
|
+
}
|
|
2161
2463
|
: null;
|
|
2162
2464
|
}
|
|
2163
2465
|
|
|
2164
2466
|
/** Transfer wheel motion between rebuilt worlds for wheels with matching chassis-local mounts. */
|
|
2165
|
-
copyVehicleMotionFrom(
|
|
2467
|
+
copyVehicleMotionFrom(
|
|
2468
|
+
previous: GPURigidBodyWorld,
|
|
2469
|
+
vehicleIndex = 0,
|
|
2470
|
+
previousVehicleIndex = 0
|
|
2471
|
+
): void {
|
|
2166
2472
|
const sourceBuffer = previous.vehicleBuffer;
|
|
2167
2473
|
const destinationBuffer = this.vehicleBuffer;
|
|
2168
|
-
const previousVehicle = previous.
|
|
2474
|
+
const previousVehicle = previous.vehicles[previousVehicleIndex];
|
|
2169
2475
|
if (!this.device || !sourceBuffer || !destinationBuffer || !previousVehicle) return;
|
|
2170
2476
|
const encoder = this.device.createCommandEncoder();
|
|
2171
|
-
this.
|
|
2477
|
+
this.vehicles[vehicleIndex]?.wheels.forEach((wheel, index) => {
|
|
2172
2478
|
const sourceIndex = previousVehicle.wheels.findIndex(source =>
|
|
2173
2479
|
source.mount.every((coordinate, axis) => coordinate === wheel.mount[axis])
|
|
2174
2480
|
);
|
|
@@ -2176,15 +2482,15 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2176
2482
|
encoder.copyBufferToBuffer({
|
|
2177
2483
|
sourceBuffer,
|
|
2178
2484
|
destinationBuffer,
|
|
2179
|
-
sourceOffset:
|
|
2180
|
-
destinationOffset:
|
|
2181
|
-
size:
|
|
2485
|
+
sourceOffset: previousVehicleIndex * VEHICLE_STRIDE + 92 + sourceIndex * 48,
|
|
2486
|
+
destinationOffset: vehicleIndex * VEHICLE_STRIDE + 92 + index * 48,
|
|
2487
|
+
size: 20
|
|
2182
2488
|
});
|
|
2183
2489
|
encoder.copyBufferToBuffer({
|
|
2184
2490
|
sourceBuffer,
|
|
2185
2491
|
destinationBuffer,
|
|
2186
|
-
sourceOffset: 256 + sourceIndex * 64,
|
|
2187
|
-
destinationOffset: 256 + index * 64,
|
|
2492
|
+
sourceOffset: previousVehicleIndex * VEHICLE_STRIDE + 256 + sourceIndex * 64,
|
|
2493
|
+
destinationOffset: vehicleIndex * VEHICLE_STRIDE + 256 + index * 64,
|
|
2188
2494
|
size: 64
|
|
2189
2495
|
});
|
|
2190
2496
|
});
|
|
@@ -2192,16 +2498,19 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2192
2498
|
}
|
|
2193
2499
|
|
|
2194
2500
|
/** Read wheel spin, angle, suspension length and normal load after submitted steps. */
|
|
2195
|
-
async readVehicleWheels() {
|
|
2196
|
-
if (!this.vehicleBuffer || this.destroyed
|
|
2197
|
-
|
|
2501
|
+
async readVehicleWheels(vehicleIndex = 0) {
|
|
2502
|
+
if (!this.vehicleBuffer || this.destroyed || !this.vehicles[vehicleIndex])
|
|
2503
|
+
throw new Error('Vehicle unavailable');
|
|
2504
|
+
const bytes = await this.vehicleBuffer.readAsync(vehicleIndex * VEHICLE_STRIDE, 256);
|
|
2505
|
+
const values = new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
2198
2506
|
return Array.from({length: 4}, (_, index) => {
|
|
2199
2507
|
const offset = 24 + index * 12;
|
|
2200
2508
|
return {
|
|
2201
2509
|
speed: values[offset],
|
|
2202
2510
|
angle: values[offset + 1],
|
|
2203
2511
|
length: values[offset + 2],
|
|
2204
|
-
load: values[offset + 3]
|
|
2512
|
+
load: values[offset + 3],
|
|
2513
|
+
steering: values[offset - 1]
|
|
2205
2514
|
};
|
|
2206
2515
|
});
|
|
2207
2516
|
}
|
|
@@ -2340,7 +2649,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2340
2649
|
indices.has(edit.collider) ||
|
|
2341
2650
|
previous.type !== shape.type ||
|
|
2342
2651
|
shape.type === 'convex-hull' ||
|
|
2343
|
-
shape.type === 'triangle-mesh'
|
|
2652
|
+
shape.type === 'triangle-mesh' ||
|
|
2653
|
+
shape.type === 'height-field'
|
|
2344
2654
|
)
|
|
2345
2655
|
throw new Error('Shape edit requires a topology rebuild');
|
|
2346
2656
|
indices.add(edit.collider);
|
|
@@ -2376,6 +2686,115 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2376
2686
|
}
|
|
2377
2687
|
}
|
|
2378
2688
|
|
|
2689
|
+
/**
|
|
2690
|
+
* Replace or evict fixed-dimension height-field tiles between submissions.
|
|
2691
|
+
* Optional positions are in each collider's body-local frame. The caller owns
|
|
2692
|
+
* tile selection and must submit already encoded steps before editing residency.
|
|
2693
|
+
*/
|
|
2694
|
+
setHeightFieldTiles(edits: readonly GPURigidBodyHeightFieldEdit[]): void {
|
|
2695
|
+
if (!edits.length) return;
|
|
2696
|
+
const metadata = this.ownedBuffers.find(buffer => buffer.id === `${this.id}-bodies`);
|
|
2697
|
+
if (!metadata || this.destroyed || this.queryPending || this.eventRead || this.triggerRead)
|
|
2698
|
+
throw new Error('Terrain streaming requires an idle attached world');
|
|
2699
|
+
const seen = new Set<number>();
|
|
2700
|
+
const packedFields = this.terrainAtlas
|
|
2701
|
+
? new Map<
|
|
2702
|
+
GPURigidBodyHeightField,
|
|
2703
|
+
{
|
|
2704
|
+
field: GPURigidBodyHeightField;
|
|
2705
|
+
packed: ReturnType<typeof packRigidBodyHeightField>;
|
|
2706
|
+
data: Float32Array | null;
|
|
2707
|
+
}
|
|
2708
|
+
>()
|
|
2709
|
+
: undefined;
|
|
2710
|
+
const replacements = edits.map(({collider: colliderIndex, field, position}) => {
|
|
2711
|
+
const collider = this.colliders[colliderIndex];
|
|
2712
|
+
const offset = this.heightFieldSlots.get(colliderIndex);
|
|
2713
|
+
if (
|
|
2714
|
+
(offset === undefined &&
|
|
2715
|
+
!(this.terrainAtlas && this.ensembleTerrainSlots.has(colliderIndex))) ||
|
|
2716
|
+
collider?.shape.type !== 'height-field' ||
|
|
2717
|
+
seen.has(colliderIndex)
|
|
2718
|
+
)
|
|
2719
|
+
throw new Error('Invalid writable height-field slot');
|
|
2720
|
+
seen.add(colliderIndex);
|
|
2721
|
+
const previous = collider.shape.field;
|
|
2722
|
+
if (field && (field.width !== previous.width || field.height !== previous.height))
|
|
2723
|
+
throw new Error('Height-field slot dimensions are fixed');
|
|
2724
|
+
const center = this.props.bodies[collider.body].centerOfMass ?? [0, 0, 0];
|
|
2725
|
+
const localOffset = position?.map((value, axis) => value - center[axis]);
|
|
2726
|
+
if (
|
|
2727
|
+
position &&
|
|
2728
|
+
(position.length !== 3 || !localOffset?.every(value => Number.isFinite(Math.fround(value))))
|
|
2729
|
+
)
|
|
2730
|
+
throw new Error('Invalid height-field tile position');
|
|
2731
|
+
let payload = field ? packedFields?.get(field) : undefined;
|
|
2732
|
+
if (!payload) {
|
|
2733
|
+
const next = field
|
|
2734
|
+
? structuredClone(field)
|
|
2735
|
+
: {...previous, heights: undefined, validity: undefined};
|
|
2736
|
+
const packed = packRigidBodyHeightField(next);
|
|
2737
|
+
const data = packedFields && packed.nodeCount ? new Float32Array(packed.data) : null;
|
|
2738
|
+
payload = {field: next, packed, data};
|
|
2739
|
+
if (field) packedFields?.set(field, payload);
|
|
2740
|
+
}
|
|
2741
|
+
return {collider, colliderIndex, offset, position, localOffset, ...payload};
|
|
2742
|
+
});
|
|
2743
|
+
const atlas = this.terrainAtlas?.bind(
|
|
2744
|
+
replacements.map(({colliderIndex, data}) => ({collider: colliderIndex, data}))
|
|
2745
|
+
);
|
|
2746
|
+
// Stamp once per validated edit batch. On float32 counter wrap, clear old impulses
|
|
2747
|
+
// so a retained contact cannot confuse a new stamp with a very old revision.
|
|
2748
|
+
if (this.terrainRevision === 0xffffff) {
|
|
2749
|
+
this.wake();
|
|
2750
|
+
this.terrainRevision = 1;
|
|
2751
|
+
}
|
|
2752
|
+
const revision = ++this.terrainRevision;
|
|
2753
|
+
for (const {word, data} of atlas?.uploads ?? [])
|
|
2754
|
+
metadata.write(data, (this.terrainAtlasWord + word) * 4);
|
|
2755
|
+
const changedBodies = new Set<number>();
|
|
2756
|
+
const affectedInstances = new Set<number>();
|
|
2757
|
+
for (const replacement of replacements) {
|
|
2758
|
+
const {collider, colliderIndex, offset, field, position, localOffset, packed} = replacement;
|
|
2759
|
+
const base = this.count * 48 + colliderIndex * 96;
|
|
2760
|
+
if (this.terrainWake) this.wakeTerrainFootprint(colliderIndex);
|
|
2761
|
+
if (atlas) {
|
|
2762
|
+
const word = atlas.wordsByCollider.get(colliderIndex);
|
|
2763
|
+
const address =
|
|
2764
|
+
word === undefined ? 0 : (this.terrainAtlasWord - this.terrainGeometryWord + word) / 4;
|
|
2765
|
+
metadata.write(
|
|
2766
|
+
new Float32Array([
|
|
2767
|
+
word === undefined ? 0 : address + packed.nodeOffset,
|
|
2768
|
+
packed.nodeCount,
|
|
2769
|
+
address
|
|
2770
|
+
]),
|
|
2771
|
+
base + 72
|
|
2772
|
+
);
|
|
2773
|
+
} else {
|
|
2774
|
+
metadata.write(new Float32Array(packed.data), offset!);
|
|
2775
|
+
metadata.write(new Float32Array([packed.nodeCount]), base + 76);
|
|
2776
|
+
}
|
|
2777
|
+
metadata.write(new Float32Array(packed.extent), base);
|
|
2778
|
+
metadata.write(new Float32Array([revision, packed.triangleCount]), base + 88);
|
|
2779
|
+
if (position && localOffset) {
|
|
2780
|
+
metadata.write(new Float32Array(localOffset), base + 16);
|
|
2781
|
+
collider.position = [...position];
|
|
2782
|
+
}
|
|
2783
|
+
collider.shape = {type: 'height-field', field};
|
|
2784
|
+
changedBodies.add(collider.body);
|
|
2785
|
+
if (this.terrainWake) this.wakeTerrainFootprint(colliderIndex);
|
|
2786
|
+
if (this.props.ensembleBodiesPerInstance)
|
|
2787
|
+
affectedInstances.add(Math.floor(collider.body / this.props.ensembleBodiesPerInstance));
|
|
2788
|
+
}
|
|
2789
|
+
for (const body of changedBodies) this.updateColliderDefinitions(body);
|
|
2790
|
+
for (const instance of affectedInstances) this.wakeEnsembleInstance(instance);
|
|
2791
|
+
}
|
|
2792
|
+
|
|
2793
|
+
/** Shared atlas utilization, when the fused layout enabled page sharing. */
|
|
2794
|
+
getTerrainAtlasStats(): GPUPhysicsTerrainAtlasStats | undefined {
|
|
2795
|
+
return this.terrainAtlas?.getStats();
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2379
2798
|
/** Change an existing collider material between submissions, invalidating cached friction. */
|
|
2380
2799
|
setColliderMaterial(colliderIndex: number, material: GPURigidBodyMaterial): void {
|
|
2381
2800
|
const collider = this.colliders[colliderIndex];
|
|
@@ -2463,11 +2882,9 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2463
2882
|
private updateColliderDefinitions(bodyIndex: number): void {
|
|
2464
2883
|
const {shape, colliders, ...properties} = this.props.bodies[bodyIndex];
|
|
2465
2884
|
const updated = this.colliders
|
|
2466
|
-
.
|
|
2885
|
+
.slice(this.bodyColliderStarts[bodyIndex], this.bodyColliderStarts[bodyIndex + 1])
|
|
2467
2886
|
.map(({body, ...candidate}) => candidate);
|
|
2468
|
-
|
|
2469
|
-
bodies[bodyIndex] = {...properties, colliders: updated};
|
|
2470
|
-
this.props.bodies = bodies;
|
|
2887
|
+
(this.props.bodies as GPURigidBody[])[bodyIndex] = {...properties, colliders: updated};
|
|
2471
2888
|
}
|
|
2472
2889
|
|
|
2473
2890
|
getColliderMaterial(collider: number): GPURigidBodyMaterial {
|
|
@@ -2476,17 +2893,19 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2476
2893
|
return structuredClone(definition.material ?? {});
|
|
2477
2894
|
}
|
|
2478
2895
|
|
|
2479
|
-
private restoreColliderDefinitions(): void {
|
|
2480
|
-
// Body definitions are
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
const
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2896
|
+
private restoreColliderDefinitions(first = 0, end = this.count): void {
|
|
2897
|
+
// Body definitions are world-owned. Keep shared geometry identities.
|
|
2898
|
+
for (let body = first; body < end; body++) {
|
|
2899
|
+
const definition = this.props.bodies[body];
|
|
2900
|
+
const colliders =
|
|
2901
|
+
definition.colliders ?? (definition.shape ? [{shape: definition.shape}] : []);
|
|
2902
|
+
for (const [index, source] of colliders.entries()) {
|
|
2903
|
+
const collider = this.colliders[this.bodyColliderStarts[body] + index];
|
|
2904
|
+
collider.shape = source.shape;
|
|
2905
|
+
collider.material = source.material;
|
|
2906
|
+
collider.position = source.position;
|
|
2907
|
+
collider.orientation = source.orientation;
|
|
2908
|
+
}
|
|
2490
2909
|
}
|
|
2491
2910
|
}
|
|
2492
2911
|
|
|
@@ -2529,7 +2948,9 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2529
2948
|
validateRigidBodyJoints(this.props.joints, proposedBodies, this.solver);
|
|
2530
2949
|
}
|
|
2531
2950
|
const colliders = this.colliders.filter(collider => collider.body === bodyIndex);
|
|
2532
|
-
for (const collider of colliders)
|
|
2951
|
+
for (const collider of colliders) {
|
|
2952
|
+
if (collider.shape.type === 'height-field' && mode !== 'static')
|
|
2953
|
+
throw new Error('Height fields require static bodies');
|
|
2533
2954
|
if (
|
|
2534
2955
|
(collider.shape.type === 'convex-hull' || collider.shape.type === 'triangle-mesh') &&
|
|
2535
2956
|
mode !== 'static' &&
|
|
@@ -2538,6 +2959,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2538
2959
|
!(getRigidBodyShapeProperties(collider.shape).volume > 0))
|
|
2539
2960
|
)
|
|
2540
2961
|
throw new Error('Dynamic meshes require closed positive-volume geometry');
|
|
2962
|
+
}
|
|
2541
2963
|
if (
|
|
2542
2964
|
this.props.continuous?.bodies.includes(bodyIndex) &&
|
|
2543
2965
|
(mode !== 'dynamic' ||
|
|
@@ -2970,6 +3392,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2970
3392
|
let bodyDefinitions = structuredClone(this.props.bodies);
|
|
2971
3393
|
let contactCursor = 0;
|
|
2972
3394
|
let triggerCursor = 0;
|
|
3395
|
+
let terrainRevision = this.terrainRevision;
|
|
3396
|
+
let terrainAtlas = this.terrainAtlas?.snapshot();
|
|
2973
3397
|
try {
|
|
2974
3398
|
for (const buffer of checkpointBuffers)
|
|
2975
3399
|
snapshots.push(
|
|
@@ -3008,6 +3432,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3008
3432
|
publicationBounds = structuredClone(this.props.publicationBounds);
|
|
3009
3433
|
contactCursor = this.eventCursor;
|
|
3010
3434
|
triggerCursor = this.triggerCursor;
|
|
3435
|
+
terrainRevision = this.terrainRevision;
|
|
3436
|
+
terrainAtlas = this.terrainAtlas?.snapshot();
|
|
3011
3437
|
saved = true;
|
|
3012
3438
|
},
|
|
3013
3439
|
restore: () => {
|
|
@@ -3021,6 +3447,12 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3021
3447
|
this.props.publicationBounds = structuredClone(publicationBounds);
|
|
3022
3448
|
this.eventCursor = contactCursor;
|
|
3023
3449
|
this.triggerCursor = triggerCursor;
|
|
3450
|
+
this.terrainRevision = terrainRevision;
|
|
3451
|
+
if (terrainAtlas)
|
|
3452
|
+
this.terrainAtlas!.restore(
|
|
3453
|
+
terrainAtlas.leases,
|
|
3454
|
+
(_word, _words, page) => terrainAtlas!.payloads.get(page)!
|
|
3455
|
+
);
|
|
3024
3456
|
},
|
|
3025
3457
|
destroy: () => {
|
|
3026
3458
|
if (released) return;
|
|
@@ -3047,6 +3479,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3047
3479
|
colliderShapeScales: structuredClone([...this.colliderShapeScales]),
|
|
3048
3480
|
contactCursor: this.eventCursor,
|
|
3049
3481
|
triggerCursor: this.triggerCursor,
|
|
3482
|
+
terrainRevision: this.terrainRevision,
|
|
3483
|
+
terrainAtlasLeases: this.terrainAtlas?.getLeases(),
|
|
3050
3484
|
buffers: await Promise.all(
|
|
3051
3485
|
this.getSnapshotBuffers(options.includeRollbackScratch).map(async buffer => ({
|
|
3052
3486
|
name: buffer.id.slice(this.id.length + 1),
|
|
@@ -3059,6 +3493,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3059
3493
|
/** Restore between submissions on the same configuration and implementation; no implicit wake. */
|
|
3060
3494
|
restoreState(capture: GPURigidBodyCapture): void {
|
|
3061
3495
|
const checkpointBuffers = this.getSnapshotBuffers(capture.includeRollbackScratch);
|
|
3496
|
+
const terrainRevision = capture.terrainRevision ?? 1;
|
|
3062
3497
|
if (
|
|
3063
3498
|
!this.device ||
|
|
3064
3499
|
this.destroyed ||
|
|
@@ -3066,6 +3501,10 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3066
3501
|
this.eventRead ||
|
|
3067
3502
|
this.triggerRead ||
|
|
3068
3503
|
capture.version !== 1 ||
|
|
3504
|
+
Boolean(capture.terrainAtlasLeases) !== Boolean(this.terrainAtlas) ||
|
|
3505
|
+
!Number.isInteger(terrainRevision) ||
|
|
3506
|
+
terrainRevision < 1 ||
|
|
3507
|
+
terrainRevision > 0xffffff ||
|
|
3069
3508
|
(capture.origin !== undefined &&
|
|
3070
3509
|
(capture.origin.length !== 3 || !capture.origin.every(Number.isFinite))) ||
|
|
3071
3510
|
capture.buffers.length !== checkpointBuffers.length ||
|
|
@@ -3091,6 +3530,29 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3091
3530
|
)
|
|
3092
3531
|
throw new Error('Incompatible rigid-body capture storage');
|
|
3093
3532
|
}
|
|
3533
|
+
if (this.terrainAtlas && capture.terrainAtlasLeases) {
|
|
3534
|
+
const metadata = capture.buffers.find(buffer => buffer.name === 'bodies')!.data;
|
|
3535
|
+
const view = new DataView(metadata.buffer, metadata.byteOffset, metadata.byteLength);
|
|
3536
|
+
const colliderBase = this.count * 48;
|
|
3537
|
+
let active = 0;
|
|
3538
|
+
for (const collider of this.ensembleTerrainSlots)
|
|
3539
|
+
if (view.getFloat32(colliderBase + collider * 96 + 76, true) > 0) active++;
|
|
3540
|
+
if (active !== capture.terrainAtlasLeases.length)
|
|
3541
|
+
throw new Error('Incomplete captured terrain atlas leases');
|
|
3542
|
+
this.terrainAtlas.restore(
|
|
3543
|
+
capture.terrainAtlasLeases,
|
|
3544
|
+
(word, words) => {
|
|
3545
|
+
const first = (this.terrainAtlasWord + word) * 4;
|
|
3546
|
+
return new Float32Array(metadata.slice(first, first + words * 4).buffer);
|
|
3547
|
+
},
|
|
3548
|
+
(collider, word) => {
|
|
3549
|
+
const base = colliderBase + collider * 96;
|
|
3550
|
+
const address = (this.terrainAtlasWord - this.terrainGeometryWord + word) / 4;
|
|
3551
|
+
if (view.getFloat32(base + 76, true) <= 0 || view.getFloat32(base + 80, true) !== address)
|
|
3552
|
+
throw new Error('Captured terrain collider has an invalid page address');
|
|
3553
|
+
}
|
|
3554
|
+
);
|
|
3555
|
+
}
|
|
3094
3556
|
for (const [index, buffer] of checkpointBuffers.entries())
|
|
3095
3557
|
buffer.write(capture.buffers[index].data);
|
|
3096
3558
|
this.props.joints = structuredClone(capture.props.joints);
|
|
@@ -3101,6 +3563,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3101
3563
|
this.worldOrigin = [...(capture.origin ?? [0, 0, 0])];
|
|
3102
3564
|
this.eventCursor = capture.contactCursor;
|
|
3103
3565
|
this.triggerCursor = capture.triggerCursor;
|
|
3566
|
+
this.terrainRevision = terrainRevision;
|
|
3104
3567
|
}
|
|
3105
3568
|
|
|
3106
3569
|
/** Stop submissions first. Reconstruct with these accepted poses and larger budgets after rollback. */
|
|
@@ -3247,6 +3710,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
3247
3710
|
this.destroyed = true;
|
|
3248
3711
|
this.control?.kernel.destroy();
|
|
3249
3712
|
this.invalidation?.kernel.destroy();
|
|
3713
|
+
this.terrainWake?.kernel.destroy();
|
|
3250
3714
|
this.queryComputation?.kernel.destroy();
|
|
3251
3715
|
this.queryReduction?.kernel.destroy();
|
|
3252
3716
|
for (const buffer of this.ownedBuffers) buffer.destroy();
|
|
@@ -3271,7 +3735,13 @@ function serializeCaptureProps(props: GPURigidBodyWorldProps): string {
|
|
|
3271
3735
|
shape:
|
|
3272
3736
|
collider.shape?.type === 'convex-hull' || collider.shape?.type === 'triangle-mesh'
|
|
3273
3737
|
? collider.shape
|
|
3274
|
-
:
|
|
3738
|
+
: collider.shape?.type === 'height-field'
|
|
3739
|
+
? {
|
|
3740
|
+
type: collider.shape.type,
|
|
3741
|
+
width: collider.shape.field.width,
|
|
3742
|
+
height: collider.shape.field.height
|
|
3743
|
+
}
|
|
3744
|
+
: {type: collider.shape?.type},
|
|
3275
3745
|
material: undefined,
|
|
3276
3746
|
position: undefined,
|
|
3277
3747
|
orientation: undefined
|