@luma.gl/graph 10.0.0-beta.2 → 10.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.cjs +22 -9
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts +11 -2
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js +27 -10
- package/dist/arrow/gpu/arrow-gpu-analytics-adapters.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.cjs +24 -13
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts +9 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js +41 -14
- package/dist/arrow/gpu/arrow-gpu-analytics-readback.js.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.cjs +24 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts +10 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.d.ts.map +1 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js +29 -1
- package/dist/arrow/gpu/arrow-gpu-table-conversion.js.map +1 -1
- package/dist/arrow/index.cjs +2 -0
- package/dist/arrow/index.cjs.map +3 -3
- package/dist/arrow/index.d.ts +1 -1
- package/dist/arrow/index.d.ts.map +1 -1
- package/dist/arrow/index.js +1 -1
- package/dist/arrow/index.js.map +1 -1
- package/dist/gpu-core/gpu-bvh-bounds.cjs +63 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts +32 -0
- package/dist/gpu-core/gpu-bvh-bounds.d.ts.map +1 -0
- package/dist/gpu-core/gpu-bvh-bounds.js +56 -0
- package/dist/gpu-core/gpu-bvh-bounds.js.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.cjs +92 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts +41 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.d.ts.map +1 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js +85 -0
- package/dist/gpu-core/gpu-command-graph-submission-pacer.js.map +1 -0
- package/dist/gpu-core/index.cjs +6 -0
- package/dist/gpu-core/index.cjs.map +3 -3
- package/dist/gpu-core/index.d.ts +4 -0
- package/dist/gpu-core/index.d.ts.map +1 -1
- package/dist/gpu-core/index.js +2 -0
- package/dist/gpu-core/index.js.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.cjs +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js +6 -6
- package/dist/gpu-dataframe/gpu-analytics-compiler-utils.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.cjs +55 -14
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts +13 -2
- package/dist/gpu-dataframe/gpu-data-frame-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame-query.js +58 -17
- package/dist/gpu-dataframe/gpu-data-frame-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.cjs +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.d.ts +10 -0
- package/dist/gpu-dataframe/gpu-data-frame.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-data-frame.js +1 -3
- package/dist/gpu-dataframe/gpu-data-frame.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.cjs +94 -44
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts +8 -5
- package/dist/gpu-dataframe/gpu-expression-shader.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression-shader.js +110 -47
- package/dist/gpu-dataframe/gpu-expression-shader.js.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.cjs +14 -8
- package/dist/gpu-dataframe/gpu-expression.d.ts +12 -1
- package/dist/gpu-dataframe/gpu-expression.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-expression.js +11 -6
- package/dist/gpu-dataframe/gpu-expression.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.cjs +2 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-compiler.js +4 -2
- 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 +5 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js +6 -2
- package/dist/gpu-dataframe/gpu-global-aggregation-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.cjs +113 -88
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts +6 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js +111 -85
- package/dist/gpu-dataframe/gpu-global-sort-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.cjs +286 -48
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts +17 -2
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js +290 -39
- package/dist/gpu-dataframe/gpu-group-aggregation-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.cjs +8 -6
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts +7 -1
- package/dist/gpu-dataframe/gpu-group-by-query.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-group-by-query.js +9 -5
- package/dist/gpu-dataframe/gpu-group-by-query.js.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.cjs +8 -6
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-join-compiler.js +9 -7
- package/dist/gpu-dataframe/gpu-join-compiler.js.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.cjs +37 -11
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts +3 -1
- package/dist/gpu-dataframe/gpu-query-compiler.d.ts.map +1 -1
- package/dist/gpu-dataframe/gpu-query-compiler.js +36 -10
- package/dist/gpu-dataframe/gpu-query-compiler.js.map +1 -1
- package/dist/gpu-dataframe/index.cjs +4 -2
- package/dist/gpu-dataframe/index.cjs.map +3 -3
- package/dist/gpu-dataframe/index.d.ts +1 -1
- 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-physics/gpu-physics-batch.cjs +11 -10
- package/dist/gpu-physics/gpu-physics-batch.d.ts +1 -0
- package/dist/gpu-physics/gpu-physics-batch.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-batch.js +14 -10
- package/dist/gpu-physics/gpu-physics-batch.js.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.cjs +9 -4
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts +10 -1
- package/dist/gpu-physics/gpu-physics-ensemble.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-physics-ensemble.js +11 -4
- package/dist/gpu-physics/gpu-physics-ensemble.js.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.cjs +261 -68
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts +47 -2
- package/dist/gpu-physics/gpu-rigid-body-world.d.ts.map +1 -1
- package/dist/gpu-physics/gpu-rigid-body-world.js +324 -75
- package/dist/gpu-physics/gpu-rigid-body-world.js.map +1 -1
- package/dist/gpu-physics/index.cjs.map +3 -3
- package/dist/gpu-physics/index.d.ts +2 -1
- package/dist/gpu-physics/index.d.ts.map +1 -1
- package/dist/gpu-physics/index.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.cjs +10 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-cache-shaders.js +15 -6
- package/dist/gpu-physics/rigid-body-cache-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.cjs +15 -2
- package/dist/gpu-physics/rigid-body-capacity.d.ts +3 -1
- package/dist/gpu-physics/rigid-body-capacity.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-capacity.js +21 -2
- package/dist/gpu-physics/rigid-body-capacity.js.map +1 -1
- package/dist/gpu-physics/rigid-body-cast-index.cjs +192 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts +44 -0
- package/dist/gpu-physics/rigid-body-cast-index.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-cast-index.js +194 -0
- package/dist/gpu-physics/rigid-body-cast-index.js.map +1 -0
- package/dist/gpu-physics/rigid-body-ensemble-layout.cjs +4 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-layout.js +5 -2
- package/dist/gpu-physics/rigid-body-ensemble-layout.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-reset.cjs +11 -9
- 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 +13 -9
- package/dist/gpu-physics/rigid-body-ensemble-reset.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.cjs +14 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts +5 -0
- package/dist/gpu-physics/rigid-body-ensemble-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js +17 -7
- package/dist/gpu-physics/rigid-body-ensemble-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.cjs +21 -11
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts +2 -2
- package/dist/gpu-physics/rigid-body-ensemble-transaction.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js +28 -12
- package/dist/gpu-physics/rigid-body-ensemble-transaction.js.map +1 -1
- package/dist/gpu-physics/rigid-body-event-compaction.cjs +184 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts +35 -0
- package/dist/gpu-physics/rigid-body-event-compaction.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js +168 -0
- package/dist/gpu-physics/rigid-body-event-compaction.js.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.cjs +51 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts +33 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.d.ts.map +1 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js +34 -0
- package/dist/gpu-physics/rigid-body-event-snapshot.js.map +1 -0
- package/dist/gpu-physics/rigid-body-events.cjs +57 -25
- package/dist/gpu-physics/rigid-body-events.d.ts +2 -1
- package/dist/gpu-physics/rigid-body-events.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-events.js +60 -25
- package/dist/gpu-physics/rigid-body-events.js.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.cjs +8 -3
- package/dist/gpu-physics/rigid-body-joints.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-joints.js +10 -6
- package/dist/gpu-physics/rigid-body-joints.js.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.cjs +159 -16
- package/dist/gpu-physics/rigid-body-queries.d.ts +24 -1
- package/dist/gpu-physics/rigid-body-queries.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-queries.js +166 -14
- package/dist/gpu-physics/rigid-body-queries.js.map +1 -1
- package/dist/gpu-physics/rigid-body-shaders.cjs +3 -3
- 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 +3 -3
- package/dist/gpu-physics/rigid-body-shaders.js.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.cjs +53 -15
- package/dist/gpu-physics/rigid-body-triggers.d.ts +1 -0
- package/dist/gpu-physics/rigid-body-triggers.d.ts.map +1 -1
- package/dist/gpu-physics/rigid-body-triggers.js +55 -15
- package/dist/gpu-physics/rigid-body-triggers.js.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.cjs +48 -20
- package/dist/gpu-physics/sphere-world-shaders.d.ts.map +1 -1
- package/dist/gpu-physics/sphere-world-shaders.js +51 -21
- package/dist/gpu-physics/sphere-world-shaders.js.map +1 -1
- package/dist/gpu-project/benchmarks.cjs.map +2 -2
- package/dist/gpu-project/crs.cjs.map +2 -2
- package/dist/gpu-project/index.cjs.map +2 -2
- package/dist/gpu-project/projection-program.cjs +2 -9
- package/dist/gpu-project/projection-program.d.ts.map +1 -1
- package/dist/gpu-project/projection-program.js +1 -8
- package/dist/gpu-project/projection-program.js.map +1 -1
- package/dist/gpu-sql/gpu-sql.cjs +203 -59
- package/dist/gpu-sql/gpu-sql.d.ts +36 -1
- package/dist/gpu-sql/gpu-sql.d.ts.map +1 -1
- package/dist/gpu-sql/gpu-sql.js +225 -62
- package/dist/gpu-sql/gpu-sql.js.map +1 -1
- package/dist/gpu-sql/index.cjs.map +3 -3
- package/dist/gpu-sql/index.d.ts +1 -1
- package/dist/gpu-sql/index.d.ts.map +1 -1
- package/dist/utils/float32.cjs +35 -0
- package/dist/utils/float32.d.ts +3 -0
- package/dist/utils/float32.d.ts.map +1 -0
- package/dist/utils/float32.js +16 -0
- package/dist/utils/float32.js.map +1 -0
- package/package.json +4 -4
- package/src/arrow/gpu/arrow-gpu-analytics-adapters.ts +77 -25
- package/src/arrow/gpu/arrow-gpu-analytics-readback.ts +52 -16
- package/src/arrow/gpu/arrow-gpu-table-conversion.ts +46 -1
- package/src/arrow/index.ts +1 -0
- package/src/gpu-core/gpu-bvh-bounds.ts +84 -0
- package/src/gpu-core/gpu-command-graph-submission-pacer.ts +102 -0
- package/src/gpu-core/index.ts +5 -0
- package/src/gpu-dataframe/gpu-analytics-compiler-utils.ts +7 -10
- package/src/gpu-dataframe/gpu-data-frame-query.ts +106 -25
- package/src/gpu-dataframe/gpu-data-frame.ts +35 -2
- package/src/gpu-dataframe/gpu-expression-shader.ts +172 -58
- package/src/gpu-dataframe/gpu-expression.ts +62 -9
- package/src/gpu-dataframe/gpu-global-aggregation-compiler.ts +6 -2
- package/src/gpu-dataframe/gpu-global-aggregation-query.ts +12 -3
- package/src/gpu-dataframe/gpu-global-sort-compiler.ts +151 -93
- package/src/gpu-dataframe/gpu-group-aggregation-compiler.ts +469 -52
- package/src/gpu-dataframe/gpu-group-by-query.ts +24 -10
- package/src/gpu-dataframe/gpu-join-compiler.ts +12 -6
- package/src/gpu-dataframe/gpu-query-compiler.ts +60 -18
- package/src/gpu-dataframe/index.ts +1 -1
- package/src/gpu-physics/gpu-physics-batch.ts +19 -13
- package/src/gpu-physics/gpu-physics-ensemble.ts +20 -4
- package/src/gpu-physics/gpu-rigid-body-world.ts +421 -93
- package/src/gpu-physics/index.ts +9 -0
- package/src/gpu-physics/rigid-body-cache-shaders.ts +18 -6
- package/src/gpu-physics/rigid-body-capacity.ts +25 -4
- package/src/gpu-physics/rigid-body-cast-index.ts +277 -0
- package/src/gpu-physics/rigid-body-ensemble-layout.ts +6 -2
- package/src/gpu-physics/rigid-body-ensemble-reset.ts +21 -9
- package/src/gpu-physics/rigid-body-ensemble-shaders.ts +18 -7
- package/src/gpu-physics/rigid-body-ensemble-transaction.ts +31 -13
- package/src/gpu-physics/rigid-body-event-compaction.ts +252 -0
- package/src/gpu-physics/rigid-body-event-snapshot.ts +76 -0
- package/src/gpu-physics/rigid-body-events.ts +63 -25
- package/src/gpu-physics/rigid-body-joints.ts +9 -11
- package/src/gpu-physics/rigid-body-queries.ts +202 -14
- package/src/gpu-physics/rigid-body-shaders.ts +4 -3
- package/src/gpu-physics/rigid-body-triggers.ts +64 -20
- package/src/gpu-physics/sphere-world-shaders.ts +53 -21
- package/src/gpu-project/projection-program.ts +1 -9
- package/src/gpu-sql/gpu-sql.ts +405 -91
- package/src/gpu-sql/index.ts +1 -1
- package/src/utils/float32.ts +16 -0
|
@@ -45,7 +45,10 @@ var import_rigid_body_publication = require("./rigid-body-publication.cjs");
|
|
|
45
45
|
var import_rigid_body_shaders = require("./rigid-body-shaders.cjs");
|
|
46
46
|
var import_rigid_body_vehicle = require("./rigid-body-vehicle.cjs");
|
|
47
47
|
var import_rigid_body_events = require("./rigid-body-events.cjs");
|
|
48
|
+
var import_rigid_body_event_compaction = require("./rigid-body-event-compaction.cjs");
|
|
49
|
+
var import_rigid_body_event_snapshot = require("./rigid-body-event-snapshot.cjs");
|
|
48
50
|
var import_rigid_body_queries = require("./rigid-body-queries.cjs");
|
|
51
|
+
var import_rigid_body_cast_index = require("./rigid-body-cast-index.cjs");
|
|
49
52
|
class GPURigidBodyWorld {
|
|
50
53
|
worldOrigin = [0, 0, 0];
|
|
51
54
|
id;
|
|
@@ -67,6 +70,14 @@ class GPURigidBodyWorld {
|
|
|
67
70
|
sleepStates = null;
|
|
68
71
|
/** World-owned GPU event ring; present only when eventCapacity is positive. */
|
|
69
72
|
contactEvents = null;
|
|
73
|
+
/** Trigger history and authored group IDs remain stable until world destruction. */
|
|
74
|
+
triggerHistory = null;
|
|
75
|
+
/** Contact activity is recorded in pair-slot order after accepted steps. */
|
|
76
|
+
contactHistory = null;
|
|
77
|
+
/** A recovery read shares the incremental trigger cursor. */
|
|
78
|
+
triggerSnapshotRead = null;
|
|
79
|
+
/** A recovery read shares the incremental contact cursor. */
|
|
80
|
+
contactSnapshotRead = null;
|
|
70
81
|
triggerEvents = null;
|
|
71
82
|
triggerCursor = 0;
|
|
72
83
|
triggerRead = null;
|
|
@@ -74,6 +85,18 @@ class GPURigidBodyWorld {
|
|
|
74
85
|
eventRead = null;
|
|
75
86
|
queryComputation = null;
|
|
76
87
|
queryReduction = null;
|
|
88
|
+
/** Batched nearest-hit computation using the current world pose buffers. */
|
|
89
|
+
batchCast = null;
|
|
90
|
+
/** Compiled query graph that refits the world BVH and then casts. */
|
|
91
|
+
batchCastIndex = null;
|
|
92
|
+
/** Initial spatial order and stable collider ID mapping for indexed batches. */
|
|
93
|
+
batchCastOrder = null;
|
|
94
|
+
/** Query graph reservation before attachment, when the physical plan is unavailable. */
|
|
95
|
+
batchCastIndexEstimate;
|
|
96
|
+
/** Reusable storage for a bounded list of ray and sweep commands. */
|
|
97
|
+
batchCastCommands = null;
|
|
98
|
+
/** Reusable GPU output with one compact result per batch command. */
|
|
99
|
+
batchCastResults = null;
|
|
77
100
|
/** Chassis definitions in GPU storage order. */
|
|
78
101
|
vehicles;
|
|
79
102
|
/** Whether any chassis has more than one terrain candidate. */
|
|
@@ -122,6 +145,9 @@ class GPURigidBodyWorld {
|
|
|
122
145
|
broadPhaseCounters = null;
|
|
123
146
|
constructor(props) {
|
|
124
147
|
var _a, _b, _c, _d, _e, _f;
|
|
148
|
+
const queryBatchCapacity = props.queryBatchCapacity ?? 0;
|
|
149
|
+
if (!Number.isSafeInteger(queryBatchCapacity) || queryBatchCapacity < 0 || queryBatchCapacity > 65535 || queryBatchCapacity > 0 && !props.enableQueries || props.queryBatchIndex && queryBatchCapacity === 0)
|
|
150
|
+
throw new Error("Invalid collision cast batch capacity");
|
|
125
151
|
for (const damping of [props.linearDamping ?? 0, props.angularDamping ?? 0]) {
|
|
126
152
|
if (!Number.isFinite(damping) || damping < 0)
|
|
127
153
|
throw new Error("Invalid damping");
|
|
@@ -228,6 +254,9 @@ class GPURigidBodyWorld {
|
|
|
228
254
|
this.maximumPairs = this.broadPhase === "all-pairs" ? this.colliderStorageCount * this.colliderStorageCount : props.maximumPairs ?? 2 ** Math.ceil(Math.log2(Math.max(64, this.colliderStorageCount * 16)));
|
|
229
255
|
if (!["all-pairs", "hierarchical-grid"].includes(this.broadPhase) || !Number.isSafeInteger(this.maximumPairs) || this.maximumPairs < 1 || this.maximumPairs > 1073741824 || this.broadPhase === "hierarchical-grid" && (this.maximumPairs & this.maximumPairs - 1) !== 0)
|
|
230
256
|
throw new Error("Invalid rigid-body pair capacity");
|
|
257
|
+
const instancePairCapacity = props.ensemblePairsPerInstance;
|
|
258
|
+
if (instancePairCapacity !== void 0 && (!props.ensembleBodiesPerInstance || props.failurePolicy !== "rollback" || !Number.isSafeInteger(instancePairCapacity) || instancePairCapacity < 1 || instancePairCapacity * (this.count / props.ensembleBodiesPerInstance) > this.maximumPairs || (instancePairCapacity & instancePairCapacity - 1) !== 0))
|
|
259
|
+
throw new Error("Invalid ensemble instance contact capacity");
|
|
231
260
|
if (props.continuous) {
|
|
232
261
|
if (props.failurePolicy !== "rollback" || !Number.isInteger(props.continuous.maximumImpacts ?? 4) || (props.continuous.maximumImpacts ?? 4) < 1 || (props.continuous.maximumImpacts ?? 4) > 16 || !["sphere-static", "convex"].includes(props.continuous.mode ?? "sphere-static") || !Number.isSafeInteger(props.continuous.maximumCandidates ?? this.maximumPairs) || (props.continuous.maximumCandidates ?? this.maximumPairs) < 1 || (props.continuous.maximumCandidates ?? this.maximumPairs) > 1073741824 || props.continuous.mode === "convex" && (Boolean((_d = props.joints) == null ? void 0 : _d.length) || colliders.some((collider) => ["plane", "triangle-mesh", "height-field"].includes(collider.shape.type))))
|
|
233
262
|
throw new Error("Invalid continuous settings");
|
|
@@ -246,6 +275,7 @@ class GPURigidBodyWorld {
|
|
|
246
275
|
const definitions = structuredClone({ colliders, props });
|
|
247
276
|
this.props = definitions.props;
|
|
248
277
|
this.colliders = definitions.colliders;
|
|
278
|
+
this.batchCastIndexEstimate = this.props.queryBatchIndex && this.colliderCount ? (0, import_rigid_body_cast_index.estimateRigidBodyCastIndexBytes)(this.colliders.filter(import_rigid_body_cast_index.canIndexRigidBodyCastCollider).length) : 0;
|
|
249
279
|
this.ensembleTerrainSlots = new Set(this.props.ensembleTerrainSlots);
|
|
250
280
|
if (this.ensembleTerrainSlots.size && (!this.props.ensembleBodiesPerInstance || [...this.ensembleTerrainSlots].some((index) => {
|
|
251
281
|
var _a2;
|
|
@@ -317,7 +347,7 @@ class GPURigidBodyWorld {
|
|
|
317
347
|
sparse,
|
|
318
348
|
extended,
|
|
319
349
|
parallel,
|
|
320
|
-
...(0, import_rigid_body_capacity.getRigidBodyStorageLayout)(this.count, this.colliderStorageCount, this.maximumPairs, geometryWords, sparse, extended, parallel, this.props.eventCapacity ?? 0, this.props.enableQueries ?? false, this.props.failurePolicy === "rollback", Boolean(this.props.continuous), ((_b = this.props.joints) == null ? void 0 : _b.length) ?? 0, this.props.ensembleBodiesPerInstance ? this.count / this.props.ensembleBodiesPerInstance : 0)
|
|
350
|
+
...(0, import_rigid_body_capacity.getRigidBodyStorageLayout)(this.count, this.colliderStorageCount, this.maximumPairs, geometryWords, sparse, extended, parallel, this.props.eventCapacity ?? 0, this.props.enableQueries ?? false, this.props.failurePolicy === "rollback", Boolean(this.props.continuous), ((_b = this.props.joints) == null ? void 0 : _b.length) ?? 0, this.props.ensembleBodiesPerInstance ? this.count / this.props.ensembleBodiesPerInstance : 0, Boolean(this.props.ensemblePairsPerInstance), this.props.queryBatchCapacity)
|
|
321
351
|
};
|
|
322
352
|
if (this.vehicles.length) {
|
|
323
353
|
const byteLength = this.getVehicleByteLength();
|
|
@@ -374,7 +404,7 @@ class GPURigidBodyWorld {
|
|
|
374
404
|
if (!this.device || !this.ensembleBuffer || this.destroyed)
|
|
375
405
|
throw new Error("World has no ensemble scheduler");
|
|
376
406
|
this.ensembleResetOrigin ??= this.origin;
|
|
377
|
-
this.ensembleReset ??= (0, import_rigid_body_ensemble_reset.makeEnsembleReset)(this.device, this.id, this.ownedBuffers, this.count, this.props.ensembleBodiesPerInstance, this.props.collisionPartitionSize, this.maximumPairs, this.vehiclesPerInstance, this.ensembleTerrainSlots);
|
|
407
|
+
this.ensembleReset ??= (0, import_rigid_body_ensemble_reset.makeEnsembleReset)(this.device, this.id, this.ownedBuffers, this.count, this.props.ensembleBodiesPerInstance, this.props.collisionPartitionSize, this.maximumPairs, this.vehiclesPerInstance, this.ensembleTerrainSlots, this.props.ensemblePairsPerInstance);
|
|
378
408
|
return this.ensembleReset.byteLength;
|
|
379
409
|
}
|
|
380
410
|
resetEnsembleInstance(instance) {
|
|
@@ -415,7 +445,7 @@ class GPURigidBodyWorld {
|
|
|
415
445
|
metadata.write(new Float32Array((collider.position ?? [0, 0, 0]).map((value, axis) => value - center[axis])), this.count * 48 + index * 96 + 16);
|
|
416
446
|
}
|
|
417
447
|
this.ensembleReset.reset(instance, this.origin.map((value, axis) => value - this.ensembleResetOrigin[axis]));
|
|
418
|
-
this.ensembleBuffer.write(new Uint32Array([0, 0, 0, 0, 1, 1]), (16 + instance * 8 + 1) * 4);
|
|
448
|
+
this.ensembleBuffer.write(new Uint32Array([0, 0, 0, 0, 1, 1, 0]), (16 + instance * 8 + 1) * 4);
|
|
419
449
|
if (this.encodePosePublication) {
|
|
420
450
|
const encoder = this.device.createCommandEncoder();
|
|
421
451
|
this.encodePosePublication(encoder);
|
|
@@ -470,8 +500,9 @@ class GPURigidBodyWorld {
|
|
|
470
500
|
if (!this.ensembleBuffer || this.destroyed || !Number.isSafeInteger(instance) || instance < 0 || instance >= this.count / this.props.ensembleBodiesPerInstance)
|
|
471
501
|
throw new Error("Invalid ensemble instance");
|
|
472
502
|
}
|
|
473
|
-
/**
|
|
503
|
+
/** World buffer sizes and private query scratch. Simulation graph scratch and driver overhead are separate. */
|
|
474
504
|
getCapacityInfo() {
|
|
505
|
+
var _a;
|
|
475
506
|
const buffers = this.allocationPlan ? this.allocationPlan.map((buffer) => ({ ...buffer })) : this.getStorageLayout().buffers;
|
|
476
507
|
return {
|
|
477
508
|
bodyCount: this.count,
|
|
@@ -479,6 +510,7 @@ class GPURigidBodyWorld {
|
|
|
479
510
|
maximumPairs: this.maximumPairs,
|
|
480
511
|
pairWorkgroups: Math.ceil(this.maximumPairs / 64),
|
|
481
512
|
buffers,
|
|
513
|
+
queryIndexScratchBytes: ((_a = this.batchCastIndex) == null ? void 0 : _a.stats.physicalTransientResourceBytes) ?? this.batchCastIndexEstimate,
|
|
482
514
|
ownedBufferBytes: buffers.reduce((total, buffer) => total + buffer.byteLength, 0)
|
|
483
515
|
};
|
|
484
516
|
}
|
|
@@ -498,6 +530,8 @@ class GPURigidBodyWorld {
|
|
|
498
530
|
if (buffer.byteLength > Math.min(graph.device.limits.maxBufferSize, bindingLimit))
|
|
499
531
|
throw new Error(`Rigid-body ${buffer.name} storage exceeds device limits`);
|
|
500
532
|
}
|
|
533
|
+
if ((this.props.queryBatchCapacity ?? 0) > graph.device.limits.maxComputeWorkgroupsPerDimension)
|
|
534
|
+
throw new Error("Collision cast batch exceeds device dispatch limits");
|
|
501
535
|
this.allocationPlan = allocationPlan;
|
|
502
536
|
this.device = graph.device;
|
|
503
537
|
const allocate = (name, data, uniform = false) => {
|
|
@@ -614,7 +648,7 @@ class GPURigidBodyWorld {
|
|
|
614
648
|
this.velocities = allocate("velocities", velocities);
|
|
615
649
|
this.angularVelocities = allocate("angular-velocities", angular);
|
|
616
650
|
this.sleepStates = allocate("sleep", this.count * 16);
|
|
617
|
-
this.targets = allocate("targets", this.props.ensembleBodiesPerInstance ? (0, import_rigid_body_ensemble_layout.getEnsembleContactLayout)(this.count, this.count / this.props.ensembleBodiesPerInstance, this.maximumPairs).byteLength : Math.ceil((this.count * 32 + (sparse ? 32 + this.maximumPairs * 8 : 16)) / 16) * 16 + (((_c = this.props.joints) == null ? void 0 : _c.length) ?? 0) * import_rigid_body_joints.RIGID_BODY_JOINT_STATE_BYTES);
|
|
651
|
+
this.targets = allocate("targets", this.props.ensembleBodiesPerInstance ? (0, import_rigid_body_ensemble_layout.getEnsembleContactLayout)(this.count, this.count / this.props.ensembleBodiesPerInstance, this.maximumPairs, Boolean(this.props.ensemblePairsPerInstance)).byteLength : Math.ceil((this.count * 32 + (sparse ? 32 + this.maximumPairs * 8 : 16)) / 16) * 16 + (((_c = this.props.joints) == null ? void 0 : _c.length) ?? 0) * import_rigid_body_joints.RIGID_BODY_JOINT_STATE_BYTES);
|
|
618
652
|
for (const [index, joint] of (this.props.joints ?? []).entries()) {
|
|
619
653
|
this.targets.write((0, import_rigid_body_joints.packRigidBodyJointState)(joint), this.getJointStateOffset() + index * import_rigid_body_joints.RIGID_BODY_JOINT_STATE_BYTES);
|
|
620
654
|
}
|
|
@@ -701,7 +735,7 @@ class GPURigidBodyWorld {
|
|
|
701
735
|
byteLength: objectAttributes.byteLength,
|
|
702
736
|
usage: import_core.Buffer.STORAGE
|
|
703
737
|
}, objectAttributes), { format: "uint32", length: this.colliderStorageCount }) : void 0;
|
|
704
|
-
const source = (0, import_rigid_body_shaders.getRigidBodyShader)(this.count, this.props.iterations ?? 16, this.colliderStorageCount, extended, sparseLayout, parallel, this.props.maximumMeshTraversalTestsPerPair ?? 65536, (0, import_rigid_body_joints.getRigidBodyJointShader)(this.props.joints ?? [], this.props.bodies), Boolean((_d = this.props.joints) == null ? void 0 : _d.length), this.props.linearDamping ?? 0, this.props.angularDamping ?? 0, ((_e = this.props.joints) == null ? void 0 : _e.length) ?? 0, this.props.compactContacts ?? true, this.props.collisionPartitionSize, this.props.ensembleBodiesPerInstance, this.props.parallelContactSolver === "block", this.colliders.some((collider) => collider.shape.type === "height-field"));
|
|
738
|
+
const source = (0, import_rigid_body_shaders.getRigidBodyShader)(this.count, this.props.iterations ?? 16, this.colliderStorageCount, extended, sparseLayout, parallel, this.props.maximumMeshTraversalTestsPerPair ?? 65536, (0, import_rigid_body_joints.getRigidBodyJointShader)(this.props.joints ?? [], this.props.bodies), Boolean((_d = this.props.joints) == null ? void 0 : _d.length), this.props.linearDamping ?? 0, this.props.angularDamping ?? 0, ((_e = this.props.joints) == null ? void 0 : _e.length) ?? 0, this.props.compactContacts ?? true, this.props.collisionPartitionSize, this.props.ensembleBodiesPerInstance, this.props.parallelContactSolver === "block", this.colliders.some((collider) => collider.shape.type === "height-field"), this.props.ensemblePairsPerInstance);
|
|
705
739
|
const parallelBindings = {
|
|
706
740
|
parallelReset: ["parallelState"],
|
|
707
741
|
parallelResetCounters: ["parallelState"],
|
|
@@ -782,6 +816,8 @@ class GPURigidBodyWorld {
|
|
|
782
816
|
location: 18
|
|
783
817
|
}, allocate, Boolean((_i = this.props.joints) == null ? void 0 : _i.length), extended) : void 0;
|
|
784
818
|
this.triggerEvents = (triggers == null ? void 0 : triggers.events) ?? null;
|
|
819
|
+
if (triggers && triggerLayout)
|
|
820
|
+
this.triggerHistory = { buffer: triggers.history, groups: triggerLayout.groups };
|
|
785
821
|
const passDescriptions = {
|
|
786
822
|
integrate: "Apply gravity and advance body velocities and predicted poses for this timestep.",
|
|
787
823
|
prepare: "Reset broad-phase counters before generating potential collider pairs.",
|
|
@@ -936,7 +972,7 @@ class GPURigidBodyWorld {
|
|
|
936
972
|
const restoreCheckpoint = this.props.failurePolicy === "rollback" ? this.ensembleBuffer ? (0, import_rigid_body_ensemble_transaction.addEnsembleCheckpoint)(graph, this.id, checkpointStates, { buffer: this.simulationStatistics, resource: statisticsResource }, bindings.find((binding) => binding.name === "ensemble"), bindings.find((binding) => binding.name === "manifolds"), this.props.ensembleBodiesPerInstance, this.maximumPairs, allocate, vehicleResource && {
|
|
937
973
|
state: vehicleResource,
|
|
938
974
|
vehiclesPerInstance: this.vehiclesPerInstance
|
|
939
|
-
}) : (0, import_rigid_body_transaction.addRigidBodyCheckpoint)(graph, this.id, [
|
|
975
|
+
}, this.props.ensemblePairsPerInstance) : (0, import_rigid_body_transaction.addRigidBodyCheckpoint)(graph, this.id, [
|
|
940
976
|
...checkpointStates,
|
|
941
977
|
bindings.find((binding) => binding.name === "manifolds"),
|
|
942
978
|
...vehicleResource ? [vehicleResource] : []
|
|
@@ -1248,7 +1284,10 @@ class GPURigidBodyWorld {
|
|
|
1248
1284
|
});
|
|
1249
1285
|
restoreCheckpoint == null ? void 0 : restoreCheckpoint.restore();
|
|
1250
1286
|
if (this.ensembleBuffer)
|
|
1251
|
-
(0, import_rigid_body_ensemble_shaders.addEnsembleStatus)(graph, this.id, this.count / this.props.ensembleBodiesPerInstance, this.props.ensembleBodiesPerInstance, diagnosticBinding("bodies"), diagnosticBinding("sleepStates"), diagnosticBinding("ensemble"), { buffer: this.simulationStatistics, resource: statisticsResource }
|
|
1287
|
+
(0, import_rigid_body_ensemble_shaders.addEnsembleStatus)(graph, this.id, this.count / this.props.ensembleBodiesPerInstance, this.props.ensembleBodiesPerInstance, diagnosticBinding("bodies"), diagnosticBinding("sleepStates"), diagnosticBinding("ensemble"), { buffer: this.simulationStatistics, resource: statisticsResource }, this.props.ensemblePairsPerInstance ? {
|
|
1288
|
+
...diagnosticBinding("targets"),
|
|
1289
|
+
wordOffset: (0, import_rigid_body_ensemble_layout.getEnsembleContactLayout)(this.count, this.count / this.props.ensembleBodiesPerInstance, this.maximumPairs, true).failureOffset
|
|
1290
|
+
} : void 0);
|
|
1252
1291
|
triggers == null ? void 0 : triggers.publish();
|
|
1253
1292
|
if (this.props.publicationBounds || this.props.publishPoses) {
|
|
1254
1293
|
const publication = (0, import_rigid_body_publication.addRigidBodyPosePublication)(graph, this.id, this.props.bodies, this.props.publicationBounds ?? this.props.bodies.map(() => [
|
|
@@ -1261,6 +1300,7 @@ class GPURigidBodyWorld {
|
|
|
1261
1300
|
}
|
|
1262
1301
|
if (this.props.eventCapacity) {
|
|
1263
1302
|
const contactHistory = allocate("contact-history", this.maximumPairs * 16);
|
|
1303
|
+
this.contactHistory = contactHistory;
|
|
1264
1304
|
this.contactEvents = allocate("contact-events", 16 + this.props.eventCapacity * 64);
|
|
1265
1305
|
const eventBindings = [
|
|
1266
1306
|
...bindings.filter((binding) => ["bodies", "manifolds", "ensemble"].includes(binding.name)),
|
|
@@ -1284,35 +1324,21 @@ class GPURigidBodyWorld {
|
|
|
1284
1324
|
}, binding.buffer)
|
|
1285
1325
|
}))
|
|
1286
1326
|
];
|
|
1287
|
-
const
|
|
1327
|
+
const contactResources = eventBindings.map(({ name, resource, location }) => ({
|
|
1328
|
+
name,
|
|
1329
|
+
resource,
|
|
1330
|
+
location,
|
|
1331
|
+
readOnly: name === "bodies" || name === "eventStatistics"
|
|
1332
|
+
}));
|
|
1333
|
+
(0, import_rigid_body_event_compaction.addRigidBodyEventCompaction)(graph, {
|
|
1288
1334
|
id: `${this.id}-contact-events`,
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
type: ["bodies", "eventStatistics"].includes(name) ? "read-only-storage" : "storage"
|
|
1297
|
-
}))
|
|
1298
|
-
}
|
|
1299
|
-
};
|
|
1300
|
-
const executable = (computation) => ({
|
|
1301
|
-
encode: ({ computePass, getBuffer }) => {
|
|
1302
|
-
Object.assign(computation.bindings, Object.fromEntries(eventBindings.map((binding) => [binding.name, getBuffer(binding.resource)])));
|
|
1303
|
-
computation.kernel.dispatch(computePass, { bindings: computation.bindings, x: 1 });
|
|
1304
|
-
},
|
|
1305
|
-
destroy: () => computation.kernel.destroy()
|
|
1306
|
-
});
|
|
1307
|
-
graph.addComputePass({
|
|
1308
|
-
id: properties.id,
|
|
1309
|
-
description: "Compare contact history and publish contact begin, persist, and end events.",
|
|
1310
|
-
resources: eventBindings.map((binding) => ({
|
|
1311
|
-
buffer: binding.resource,
|
|
1312
|
-
usage: ["bodies", "eventStatistics"].includes(binding.name) ? "storage-read" : "storage-read-write"
|
|
1313
|
-
})),
|
|
1314
|
-
compile: () => executable((0, import_bound_kernel.createBoundKernel)(graph.device, properties)),
|
|
1315
|
-
compileAsync: async () => executable(await (0, import_bound_kernel.createBoundKernelAsync)(graph.device, properties))
|
|
1335
|
+
rowCount: this.maximumPairs,
|
|
1336
|
+
capacity: this.props.eventCapacity,
|
|
1337
|
+
ring: "contactEvents",
|
|
1338
|
+
source: source + (0, import_rigid_body_events.getRigidBodyEventShader)(this.props.eventCapacity, this.props.impactImpulseThreshold ?? 1, this.props.failurePolicy === "rollback", this.props.ensemblePairsPerInstance),
|
|
1339
|
+
classify: contactResources.filter((binding) => !["bodies", "contactEvents"].includes(binding.name)),
|
|
1340
|
+
commit: contactResources.filter((binding) => ["eventStatistics", "contactEvents"].includes(binding.name)),
|
|
1341
|
+
publish: contactResources.filter((binding) => !["eventStatistics", "ensemble"].includes(binding.name))
|
|
1316
1342
|
});
|
|
1317
1343
|
}
|
|
1318
1344
|
if (this.props.enableQueries) {
|
|
@@ -1353,6 +1379,43 @@ class GPURigidBodyWorld {
|
|
|
1353
1379
|
queryOutput: this.queryOutput
|
|
1354
1380
|
}
|
|
1355
1381
|
});
|
|
1382
|
+
if (this.props.queryBatchCapacity) {
|
|
1383
|
+
const capacity = this.props.queryBatchCapacity;
|
|
1384
|
+
this.batchCastCommands = allocate("query-batch-commands", capacity * import_rigid_body_queries.RIGID_BODY_CAST_COMMAND_BYTES);
|
|
1385
|
+
this.batchCastResults = allocate("query-batch-results", capacity * import_rigid_body_queries.RIGID_BODY_BATCH_RESULT_BYTES);
|
|
1386
|
+
const batchBindings = {
|
|
1387
|
+
positions: this.positions,
|
|
1388
|
+
orientations: this.orientations,
|
|
1389
|
+
bodies,
|
|
1390
|
+
querySelection: this.querySelection,
|
|
1391
|
+
batchCommands: this.batchCastCommands,
|
|
1392
|
+
batchResults: this.batchCastResults
|
|
1393
|
+
};
|
|
1394
|
+
const batchLayout = [
|
|
1395
|
+
...queryProperties.shaderLayout.bindings.filter((binding) => ["positions", "orientations", "bodies", "querySelection"].includes(binding.name)),
|
|
1396
|
+
{ name: "batchCommands", group: 0, location: 30, type: "read-only-storage" },
|
|
1397
|
+
{ name: "batchResults", group: 0, location: 31, type: "storage" }
|
|
1398
|
+
];
|
|
1399
|
+
this.batchCast = (0, import_bound_kernel.createBoundKernel)(graph.device, {
|
|
1400
|
+
id: `${this.id}-batched-casts`,
|
|
1401
|
+
entryPoint: "castBatch",
|
|
1402
|
+
source: queryProperties.source + (0, import_rigid_body_queries.getRigidBodyBatchCastShader)(),
|
|
1403
|
+
shaderLayout: { bindings: batchLayout },
|
|
1404
|
+
bindings: batchBindings
|
|
1405
|
+
});
|
|
1406
|
+
if (this.props.queryBatchIndex && this.colliderCount) {
|
|
1407
|
+
this.batchCastOrder = (0, import_rigid_body_cast_index.getRigidBodyCastOrder)(this.colliders, this.props.bodies);
|
|
1408
|
+
if (this.batchCastOrder.indexedCount) {
|
|
1409
|
+
this.batchCastIndex = (0, import_rigid_body_cast_index.createRigidBodyCastIndex)(graph.device, {
|
|
1410
|
+
id: `${this.id}-cast-index`,
|
|
1411
|
+
source: queryProperties.source,
|
|
1412
|
+
layout: batchLayout,
|
|
1413
|
+
buffers: batchBindings,
|
|
1414
|
+
indexedCount: this.batchCastOrder.indexedCount
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1356
1419
|
}
|
|
1357
1420
|
this.controlSettings = allocate("control-settings", 64, true);
|
|
1358
1421
|
const controlProperties = {
|
|
@@ -1491,7 +1554,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
1491
1554
|
}
|
|
1492
1555
|
/** Rebase between submissions, preserving velocities, contact impulses and sleeping state. */
|
|
1493
1556
|
shiftOrigin(shift) {
|
|
1494
|
-
if (!this.device || this.destroyed || this.queryPending || this.
|
|
1557
|
+
if (!this.device || this.destroyed || this.queryPending || this.eventReadsPending)
|
|
1495
1558
|
throw new Error("Origin shifting requires an idle attached world");
|
|
1496
1559
|
if (shift.length !== 3 || shift.some((value) => !Number.isFinite(value) || Math.fround(value) !== value))
|
|
1497
1560
|
throw new Error("Origin shift must be an exactly representable float32 vector");
|
|
@@ -1635,6 +1698,16 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
1635
1698
|
metadata.write(data);
|
|
1636
1699
|
this.props.publicationBounds = structuredClone(bounds);
|
|
1637
1700
|
}
|
|
1701
|
+
/** Read the authored collider frame relative to its body's node origin, excluding COM offset. */
|
|
1702
|
+
getColliderTransform(colliderIndex) {
|
|
1703
|
+
const collider = this.colliders[colliderIndex];
|
|
1704
|
+
if (!Number.isInteger(colliderIndex) || !collider || this.destroyed)
|
|
1705
|
+
throw new Error("Invalid collider");
|
|
1706
|
+
return {
|
|
1707
|
+
position: [...collider.position ?? [0, 0, 0]],
|
|
1708
|
+
orientation: (0, import_rigid_body_properties.normalizeRigidBodyRotation)(collider.orientation)
|
|
1709
|
+
};
|
|
1710
|
+
}
|
|
1638
1711
|
/** Applied scale relative to the initially cooked analytic shape. */
|
|
1639
1712
|
getColliderShapeScale(colliderIndex) {
|
|
1640
1713
|
this.getColliderShape(colliderIndex);
|
|
@@ -1703,7 +1776,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
1703
1776
|
if (!edits.length)
|
|
1704
1777
|
return;
|
|
1705
1778
|
const metadata = this.ownedBuffers.find((buffer) => buffer.id === `${this.id}-bodies`);
|
|
1706
|
-
if (!metadata || this.destroyed || this.queryPending || this.
|
|
1779
|
+
if (!metadata || this.destroyed || this.queryPending || this.eventReadsPending)
|
|
1707
1780
|
throw new Error("Terrain streaming requires an idle attached world");
|
|
1708
1781
|
const seen = /* @__PURE__ */ new Set();
|
|
1709
1782
|
const packedFields = this.terrainAtlas ? /* @__PURE__ */ new Map() : void 0;
|
|
@@ -2038,15 +2111,22 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2038
2111
|
readContactEvents() {
|
|
2039
2112
|
if (!this.contactEvents || this.destroyed)
|
|
2040
2113
|
return Promise.reject(new Error("Contact events are not enabled"));
|
|
2041
|
-
|
|
2042
|
-
|
|
2114
|
+
const afterSnapshot = this.contactSnapshotRead;
|
|
2115
|
+
if (this.eventRead && (!afterSnapshot || this.eventRead.afterSnapshot === afterSnapshot))
|
|
2116
|
+
return this.eventRead.result;
|
|
2117
|
+
const pending = {
|
|
2118
|
+
afterSnapshot,
|
|
2119
|
+
result: this.contactEvents.readAsync().finally(() => afterSnapshot).then((bytes) => {
|
|
2043
2120
|
const batch = (0, import_rigid_body_events.decodeRigidBodyContactEvents)(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.eventCursor);
|
|
2044
2121
|
this.eventCursor = batch.sequence;
|
|
2045
2122
|
return batch;
|
|
2046
2123
|
}).finally(() => {
|
|
2047
|
-
this.eventRead
|
|
2048
|
-
|
|
2049
|
-
|
|
2124
|
+
if (this.eventRead === pending)
|
|
2125
|
+
this.eventRead = null;
|
|
2126
|
+
})
|
|
2127
|
+
};
|
|
2128
|
+
this.eventRead = pending;
|
|
2129
|
+
return pending.result;
|
|
2050
2130
|
}
|
|
2051
2131
|
/** Nearest exact sphere/OBB hit. Origins inside a shape return distance zero and a zero normal. */
|
|
2052
2132
|
raycast(query) {
|
|
@@ -2056,6 +2136,57 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2056
2136
|
overlapSphere(query) {
|
|
2057
2137
|
return this.runQuery(query);
|
|
2058
2138
|
}
|
|
2139
|
+
/**
|
|
2140
|
+
* Query the closest hit for each ray or sphere cast with one submission and readback.
|
|
2141
|
+
* Results follow input order. This snapshots already submitted poses, using one shared collider selection.
|
|
2142
|
+
*/
|
|
2143
|
+
async castBatch(commands, options = {}) {
|
|
2144
|
+
if (!this.device || !this.batchCast || !this.querySelection || !this.batchCastCommands || !this.batchCastResults || this.destroyed || this.queryPending)
|
|
2145
|
+
throw new Error("Batched collision casts are disabled or busy");
|
|
2146
|
+
if (commands.length > this.props.queryBatchCapacity)
|
|
2147
|
+
throw new Error("Collision cast batch exceeds capacity");
|
|
2148
|
+
if (!commands.length)
|
|
2149
|
+
return [];
|
|
2150
|
+
if (options.strategy === "indexed" && !this.props.queryBatchIndex)
|
|
2151
|
+
throw new Error("Batched collision cast index is disabled");
|
|
2152
|
+
const order = options.strategy === "scan" ? null : this.batchCastOrder;
|
|
2153
|
+
const selection = options.colliderIndices ? Uint32Array.from(new Set(this.validateQueryColliders(options.colliderIndices))) : (order == null ? void 0 : order.indices) ?? Uint32Array.from({ length: this.colliderCount }, (_, index) => index);
|
|
2154
|
+
let indexedCount = (order == null ? void 0 : order.indexedCount) ?? 0;
|
|
2155
|
+
if (order && options.colliderIndices) {
|
|
2156
|
+
selection.sort((first, second) => order.ranks[first] - order.ranks[second]);
|
|
2157
|
+
const firstExtended = selection.findIndex((index) => order.ranks[index] >= order.indexedCount);
|
|
2158
|
+
indexedCount = firstExtended < 0 ? selection.length : firstExtended;
|
|
2159
|
+
}
|
|
2160
|
+
const data = (0, import_rigid_body_queries.packRigidBodyBatchCasts)(commands, this.count, selection.length, indexedCount);
|
|
2161
|
+
this.queryPending = true;
|
|
2162
|
+
try {
|
|
2163
|
+
this.batchCastCommands.write(data);
|
|
2164
|
+
if (selection.length)
|
|
2165
|
+
this.querySelection.write(selection);
|
|
2166
|
+
const encoder = this.device.createCommandEncoder();
|
|
2167
|
+
if (this.batchCastIndex && indexedCount) {
|
|
2168
|
+
this.batchCastIndex.encode(encoder, { parameters: commands.length });
|
|
2169
|
+
} else {
|
|
2170
|
+
const pass = encoder.beginComputePass();
|
|
2171
|
+
this.batchCast.kernel.dispatch(pass, {
|
|
2172
|
+
bindings: this.batchCast.bindings,
|
|
2173
|
+
x: commands.length
|
|
2174
|
+
});
|
|
2175
|
+
pass.end();
|
|
2176
|
+
}
|
|
2177
|
+
this.device.submit(encoder.finish());
|
|
2178
|
+
return (0, import_rigid_body_queries.decodeRigidBodyBatchCasts)(await this.batchCastResults.readAsync(0, commands.length * import_rigid_body_queries.RIGID_BODY_BATCH_RESULT_BYTES));
|
|
2179
|
+
} finally {
|
|
2180
|
+
this.queryPending = false;
|
|
2181
|
+
}
|
|
2182
|
+
}
|
|
2183
|
+
/** Reject invalid indices before scalar or batch query buffers are written. */
|
|
2184
|
+
validateQueryColliders(indices) {
|
|
2185
|
+
for (const index of indices)
|
|
2186
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.colliderCount)
|
|
2187
|
+
throw new Error("Invalid query collider");
|
|
2188
|
+
return indices;
|
|
2189
|
+
}
|
|
2059
2190
|
async runQuery(query) {
|
|
2060
2191
|
if (!this.device || !this.queryComputation || !this.querySettings || !this.querySelection || !this.queryOutput || this.destroyed || this.queryPending)
|
|
2061
2192
|
throw new Error("Queries are disabled or busy");
|
|
@@ -2069,9 +2200,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2069
2200
|
throw new Error("Invalid collision query");
|
|
2070
2201
|
const selected = query.colliderIndices ?? Array.from({ length: this.colliderCount }, (_, index) => index);
|
|
2071
2202
|
const selection = new Uint32Array(this.colliderStorageCount);
|
|
2072
|
-
for (const index of selected) {
|
|
2073
|
-
if (!Number.isInteger(index) || index < 0 || index >= this.colliderCount)
|
|
2074
|
-
throw new Error("Invalid query collider");
|
|
2203
|
+
for (const index of this.validateQueryColliders(selected)) {
|
|
2075
2204
|
const collider = this.colliders[index];
|
|
2076
2205
|
if (collider.body === query.excludeBody)
|
|
2077
2206
|
continue;
|
|
@@ -2101,16 +2230,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2101
2230
|
const bytes = await this.queryOutput.readAsync(0, 16 + maximumHits * 48);
|
|
2102
2231
|
const words = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
2103
2232
|
const floats = new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
2104
|
-
const hits = Array.from({ length: words[0] }, (_, index) =>
|
|
2105
|
-
const offset = 4 + index * 12;
|
|
2106
|
-
return {
|
|
2107
|
-
body: words[offset],
|
|
2108
|
-
collider: words[offset + 1],
|
|
2109
|
-
point: [floats[offset + 4], floats[offset + 5], floats[offset + 6]],
|
|
2110
|
-
distance: floats[offset + 7],
|
|
2111
|
-
normal: [floats[offset + 8], floats[offset + 9], floats[offset + 10]]
|
|
2112
|
-
};
|
|
2113
|
-
});
|
|
2233
|
+
const hits = Array.from({ length: words[0] }, (_, index) => (0, import_rigid_body_queries.decodeRigidBodyQueryHit)(words, floats, 4 + index * 12));
|
|
2114
2234
|
return {
|
|
2115
2235
|
hits,
|
|
2116
2236
|
totalHits: words[1],
|
|
@@ -2155,16 +2275,87 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2155
2275
|
readTriggerEvents() {
|
|
2156
2276
|
if (!this.triggerEvents || this.destroyed)
|
|
2157
2277
|
throw new Error("Triggers are disabled");
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2278
|
+
const afterSnapshot = this.triggerSnapshotRead;
|
|
2279
|
+
if (this.triggerRead && (!afterSnapshot || this.triggerRead.afterSnapshot === afterSnapshot))
|
|
2280
|
+
return this.triggerRead.result;
|
|
2281
|
+
const pending = {
|
|
2282
|
+
afterSnapshot,
|
|
2283
|
+
result: this.triggerEvents.readAsync().finally(() => afterSnapshot).then((bytes) => {
|
|
2284
|
+
const batch = (0, import_rigid_body_triggers.decodeRigidBodyTriggerEvents)(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4), this.triggerCursor);
|
|
2285
|
+
this.triggerCursor = batch.sequence;
|
|
2286
|
+
return batch;
|
|
2287
|
+
}).finally(() => {
|
|
2288
|
+
if (this.triggerRead === pending)
|
|
2289
|
+
this.triggerRead = null;
|
|
2290
|
+
})
|
|
2291
|
+
};
|
|
2292
|
+
this.triggerRead = pending;
|
|
2293
|
+
return pending.result;
|
|
2294
|
+
}
|
|
2295
|
+
/** Recover the active contact set and advance the incremental cursor to the snapshot. */
|
|
2296
|
+
resyncContactEvents() {
|
|
2297
|
+
var _a;
|
|
2298
|
+
if (!this.device || !this.contactEvents || !this.contactHistory || this.destroyed)
|
|
2299
|
+
return Promise.reject(new Error("Contact events are not enabled"));
|
|
2300
|
+
if (this.contactSnapshotRead)
|
|
2301
|
+
return this.contactSnapshotRead;
|
|
2302
|
+
const priorRead = (_a = this.eventRead) == null ? void 0 : _a.result.catch(() => void 0);
|
|
2303
|
+
const snapshot = (0, import_rigid_body_event_snapshot.readRigidBodyEventSnapshot)(this.device, this.contactEvents, this.contactHistory, (header, rows) => {
|
|
2304
|
+
const contacts = [];
|
|
2305
|
+
for (let offset = 0; offset < rows.length; offset += 4) {
|
|
2306
|
+
if (rows[offset + 2] === 0)
|
|
2307
|
+
continue;
|
|
2308
|
+
const first = rows[offset];
|
|
2309
|
+
const second = rows[offset + 1];
|
|
2310
|
+
contacts.push({
|
|
2311
|
+
colliders: [first, second],
|
|
2312
|
+
bodies: [this.colliders[first].body, this.colliders[second].body]
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
return { ...header, contacts };
|
|
2316
|
+
});
|
|
2317
|
+
this.contactSnapshotRead = snapshot.finally(() => priorRead).then((result) => {
|
|
2318
|
+
this.eventCursor = result.sequence;
|
|
2319
|
+
return result;
|
|
2164
2320
|
}).finally(() => {
|
|
2165
|
-
this.
|
|
2321
|
+
this.contactSnapshotRead = null;
|
|
2166
2322
|
});
|
|
2167
|
-
return this.
|
|
2323
|
+
return this.contactSnapshotRead;
|
|
2324
|
+
}
|
|
2325
|
+
/** Recover the active trigger overlap set and advance the incremental trigger cursor. */
|
|
2326
|
+
resyncTriggerEvents() {
|
|
2327
|
+
var _a;
|
|
2328
|
+
if (!this.device || !this.triggerEvents || !this.triggerHistory || this.destroyed)
|
|
2329
|
+
return Promise.reject(new Error("Triggers are disabled"));
|
|
2330
|
+
if (this.triggerSnapshotRead)
|
|
2331
|
+
return this.triggerSnapshotRead;
|
|
2332
|
+
const { buffer, groups } = this.triggerHistory;
|
|
2333
|
+
const priorRead = (_a = this.triggerRead) == null ? void 0 : _a.result.catch(() => void 0);
|
|
2334
|
+
const snapshot = (0, import_rigid_body_event_snapshot.readRigidBodyEventSnapshot)(this.device, this.triggerEvents, buffer, (header, rows) => {
|
|
2335
|
+
const overlaps = [];
|
|
2336
|
+
for (let offset = 0; offset < rows.length; offset += 4) {
|
|
2337
|
+
if ((rows[offset] & 1) === 0)
|
|
2338
|
+
continue;
|
|
2339
|
+
overlaps.push({
|
|
2340
|
+
trigger: groups[offset],
|
|
2341
|
+
body: groups[offset + 1],
|
|
2342
|
+
triggerCollider: rows[offset + 1],
|
|
2343
|
+
collider: rows[offset + 2]
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
return { ...header, overlaps };
|
|
2347
|
+
});
|
|
2348
|
+
this.triggerSnapshotRead = snapshot.finally(() => priorRead).then((result) => {
|
|
2349
|
+
this.triggerCursor = result.sequence;
|
|
2350
|
+
return result;
|
|
2351
|
+
}).finally(() => {
|
|
2352
|
+
this.triggerSnapshotRead = null;
|
|
2353
|
+
});
|
|
2354
|
+
return this.triggerSnapshotRead;
|
|
2355
|
+
}
|
|
2356
|
+
/** Reset, capture and origin operations require stable event cursors. */
|
|
2357
|
+
get eventReadsPending() {
|
|
2358
|
+
return Boolean(this.eventRead || this.triggerRead || this.contactSnapshotRead || this.triggerSnapshotRead);
|
|
2168
2359
|
}
|
|
2169
2360
|
getSnapshotBuffers(includeRollbackScratch = true) {
|
|
2170
2361
|
return this.ownedBuffers.filter((buffer) => includeRollbackScratch || !buffer.id.startsWith(`${this.id}-checkpoint-`));
|
|
@@ -2199,7 +2390,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2199
2390
|
throw error;
|
|
2200
2391
|
}
|
|
2201
2392
|
const copy = (restore) => {
|
|
2202
|
-
if (released || this.destroyed || this.queryPending || this.
|
|
2393
|
+
if (released || this.destroyed || this.queryPending || this.eventReadsPending)
|
|
2203
2394
|
throw new Error("Checkpoint requires an idle live world");
|
|
2204
2395
|
const encoder = device.createCommandEncoder();
|
|
2205
2396
|
for (const [index, buffer] of checkpointBuffers.entries())
|
|
@@ -2259,7 +2450,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2259
2450
|
/** Stop graph submissions and controls first; includes diagnostics, caches and event history. */
|
|
2260
2451
|
async captureState(options = {}) {
|
|
2261
2452
|
var _a;
|
|
2262
|
-
if (!this.device || this.destroyed || this.queryPending || this.
|
|
2453
|
+
if (!this.device || this.destroyed || this.queryPending || this.eventReadsPending)
|
|
2263
2454
|
throw new Error("Capture requires an idle attached world");
|
|
2264
2455
|
return {
|
|
2265
2456
|
version: 1,
|
|
@@ -2281,7 +2472,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2281
2472
|
restoreState(capture) {
|
|
2282
2473
|
const checkpointBuffers = this.getSnapshotBuffers(capture.includeRollbackScratch);
|
|
2283
2474
|
const terrainRevision = capture.terrainRevision ?? 1;
|
|
2284
|
-
if (!this.device || this.destroyed || this.queryPending || this.
|
|
2475
|
+
if (!this.device || this.destroyed || this.queryPending || this.eventReadsPending || capture.version !== 1 || Boolean(capture.terrainAtlasLeases) !== Boolean(this.terrainAtlas) || !Number.isInteger(terrainRevision) || terrainRevision < 1 || terrainRevision > 16777215 || capture.origin !== void 0 && (capture.origin.length !== 3 || !capture.origin.every(Number.isFinite)) || capture.buffers.length !== checkpointBuffers.length || serializeCaptureProps(capture.props) !== serializeCaptureProps(this.props) || ![capture.contactCursor, capture.triggerCursor].every((value) => Number.isInteger(value) && value >= 0 && value <= 4294967295))
|
|
2285
2476
|
throw new Error("Incompatible rigid-body capture");
|
|
2286
2477
|
const shapeScales = new Map(capture.colliderShapeScales ?? []);
|
|
2287
2478
|
for (const [index, scale] of shapeScales) {
|
|
@@ -2414,7 +2605,7 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2414
2605
|
}
|
|
2415
2606
|
/** Destroy the compiled graph and finish readbacks before destroying its world. */
|
|
2416
2607
|
destroy() {
|
|
2417
|
-
var _a, _b, _c, _d, _e, _f;
|
|
2608
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2418
2609
|
if (this.destroyed)
|
|
2419
2610
|
return;
|
|
2420
2611
|
(_a = this.ensembleReset) == null ? void 0 : _a.destroy();
|
|
@@ -2426,6 +2617,8 @@ struct Command { impulse: vec4f, point: vec4f, orientation: vec4f, bodyIndex: ve
|
|
|
2426
2617
|
(_d = this.terrainWake) == null ? void 0 : _d.kernel.destroy();
|
|
2427
2618
|
(_e = this.queryComputation) == null ? void 0 : _e.kernel.destroy();
|
|
2428
2619
|
(_f = this.queryReduction) == null ? void 0 : _f.kernel.destroy();
|
|
2620
|
+
(_g = this.batchCastIndex) == null ? void 0 : _g.destroy();
|
|
2621
|
+
(_h = this.batchCast) == null ? void 0 : _h.kernel.destroy();
|
|
2429
2622
|
for (const buffer of this.ownedBuffers)
|
|
2430
2623
|
buffer.destroy();
|
|
2431
2624
|
this.ownedBuffers.length = 0;
|