@series-inc/rundot-syncplay 6.0.0-rc.22 → 6.0.0-rc.24
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/MIGRATING-RC20-TO-RC22.md +133 -0
- package/core/native/physics/capsule_triangle_native.inc +32 -12
- package/core/native/physics/geometry_store.cpp +121 -0
- package/core/native/physics/geometry_store.hpp +7 -0
- package/core/native/physics/physics.cpp +126 -3
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +5 -5
- package/core/src/physics/physics-wasm-module.generated.mjs +5 -5
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +1 -1
- package/dist/physics/2d.js +2 -2
- package/package.json +3 -2
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Migrating from Syncplay 6.0.0-rc.20 to rc.22
|
|
2
|
+
|
|
3
|
+
Syncplay `6.0.0-rc.22` introduces ergonomics improvements for branded units, public state codecs for game-owned state containing `bigint` physics identifiers, generalized multi-wheel vehicle verification, and explicit guidance for Kinematic Character Controller (KCC) Revision 2.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. Branded Vector Helpers & Migration Codemod (Item 10)
|
|
8
|
+
|
|
9
|
+
### What Changed
|
|
10
|
+
In rc.20, unit branding (`Meters`, `Radians`, `Newtons`, etc.) was tightened across all physics APIs to prevent unit mismatch bugs. However, writing `{ x: meters(a), y: meters(b), z: meters(c) }` across hundreds of lines introduces substantial boilerplate.
|
|
11
|
+
|
|
12
|
+
rc.22 exports convenient vector constructors that accept both positional coordinates and existing `{ x, y, z }` record objects:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import {
|
|
16
|
+
meters3,
|
|
17
|
+
radians3,
|
|
18
|
+
metersPerSecond3,
|
|
19
|
+
metersPerSecondSquared3,
|
|
20
|
+
newtons3,
|
|
21
|
+
vec3,
|
|
22
|
+
meters2,
|
|
23
|
+
radians2,
|
|
24
|
+
metersPerSecond2,
|
|
25
|
+
vec2,
|
|
26
|
+
} from '@series-inc/rundot-syncplay/physics/3d';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Usage
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
// Positional coordinates
|
|
33
|
+
const pos = meters3(0, 1.5, -2);
|
|
34
|
+
const vel = metersPerSecond3(0, 0, 15);
|
|
35
|
+
const force = newtons3(0, 500, 0);
|
|
36
|
+
|
|
37
|
+
// Object coordinates (drop-in wrapper for legacy vector objects)
|
|
38
|
+
const legacyVec = { x: 10, y: 0, z: -5 };
|
|
39
|
+
const brandedPos = meters3(legacyVec);
|
|
40
|
+
|
|
41
|
+
// Custom brands
|
|
42
|
+
const custom = vec3(turns, 0.1, 0.2, 0.3);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Regex / Search & Replace Codemod
|
|
46
|
+
|
|
47
|
+
If your codebase has repetitive manual `{ x: meters(...), y: meters(...), z: meters(...) }` calls, you can migrate them with the following regular expressions:
|
|
48
|
+
|
|
49
|
+
- **Find:**
|
|
50
|
+
```regexp
|
|
51
|
+
\{\s*x:\s*meters\(([^)]+)\),\s*y:\s*meters\(([^)]+)\),\s*z:\s*meters\(([^)]+)\)\s*\}
|
|
52
|
+
```
|
|
53
|
+
- **Replace:**
|
|
54
|
+
```ts
|
|
55
|
+
meters3($1, $2, $3)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
- **2D Vectors Find:**
|
|
59
|
+
```regexp
|
|
60
|
+
\{\s*x:\s*meters\(([^)]+)\),\s*y:\s*meters\(([^)]+)\)\s*\}
|
|
61
|
+
```
|
|
62
|
+
- **Replace:**
|
|
63
|
+
```ts
|
|
64
|
+
meters2($1, $2)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 2. KCC Revision 2: Native Step-Up & Platform Support Persistence (Item 11)
|
|
70
|
+
|
|
71
|
+
### Native Step-Up (No Custom Raycast Hacks)
|
|
72
|
+
In Revision 1, stepping up over vertical edges (curbs, stairs, debris) often required game-side raycasts to manually nudge the character upward before stepping.
|
|
73
|
+
|
|
74
|
+
In **Revision 2 (`behaviorRevision: 2`)**, the solver natively sweeps the bottom spherical cap against vertical steps up to `stepHeight`.
|
|
75
|
+
- Author `stepHeight: 0.3` (or your desired maximum step height in meters).
|
|
76
|
+
- A 0.2 m vertical edge will be climbed smoothly and deterministically without clipping or snagging.
|
|
77
|
+
- **Action Required:** Remove any custom game-side pre-step raycasts or edge-nudging hacks; they are redundant and can interfere with the native solver's ground alignment.
|
|
78
|
+
|
|
79
|
+
### Crucial: Persist the `support` Field Across Ticks
|
|
80
|
+
Revision 2 introduces physical moving-platform carry and continuous contact resolution via the `support` property on `DeterministicKccState3D` / step result.
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
// Ticking KCC Revision 2:
|
|
84
|
+
const result = stepDeterministicKcc3D(input, {
|
|
85
|
+
...currentState,
|
|
86
|
+
// CRITICAL: Pass back the support returned from the previous tick!
|
|
87
|
+
support: lastStepResult.support,
|
|
88
|
+
}, world, options);
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
> [!IMPORTANT]
|
|
92
|
+
> If your game drops `support` or creates a fresh state object each frame without copying `lastStepResult.support`, the character controller will not inherit platform velocity or maintain stable ground contact.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## 3. Game-Owned State Codecs for BigInt Body IDs (Item 8)
|
|
97
|
+
|
|
98
|
+
### What Changed
|
|
99
|
+
`DeterministicVehicleState3D` and `DeterministicKccSupport3D` (when `kind: 'physics'`) carry native 64-bit `PhysicsBodyId3D` values represented as JavaScript `bigint` primitives.
|
|
100
|
+
|
|
101
|
+
Standard `JSON.stringify(state)` throws:
|
|
102
|
+
```
|
|
103
|
+
TypeError: Do not know how to serialize a BigInt
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Solution
|
|
107
|
+
Syncplay rc.22 exports canonical serialization and deserialization helpers that encode `bigint` without loss:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import {
|
|
111
|
+
encodeDeterministicVehicleState3D,
|
|
112
|
+
decodeDeterministicVehicleState3D,
|
|
113
|
+
encodeDeterministicVehicleState3DBytes,
|
|
114
|
+
decodeDeterministicVehicleState3DBytes,
|
|
115
|
+
encodeDeterministicKccSupport3D,
|
|
116
|
+
decodeDeterministicKccSupport3D,
|
|
117
|
+
encodeDeterministicKccSupport3DBytes,
|
|
118
|
+
decodeDeterministicKccSupport3DBytes,
|
|
119
|
+
} from '@series-inc/rundot-syncplay/physics/3d';
|
|
120
|
+
|
|
121
|
+
// Save vehicle state to JSON string or binary Uint8Array
|
|
122
|
+
const savedJson = encodeDeterministicVehicleState3D(vehicleState);
|
|
123
|
+
const savedBytes = encodeDeterministicVehicleState3DBytes(vehicleState);
|
|
124
|
+
|
|
125
|
+
// Restore vehicle state
|
|
126
|
+
const restoredState = decodeDeterministicVehicleState3D(savedJson);
|
|
127
|
+
|
|
128
|
+
// Save KCC support state
|
|
129
|
+
const savedSupportJson = encodeDeterministicKccSupport3D(kccResult.support);
|
|
130
|
+
const restoredSupport = decodeDeterministicKccSupport3D(savedSupportJson);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
These functions use canonical JSON formatting with BigInt sentinels (`{"$rdm":"bigint","value":"..."}`) ensuring bit-identical hashing and portable network snapshots across clients.
|
|
@@ -11,7 +11,7 @@ exact_dyadic::Operation& arithmetic(SolverOperation& operation){
|
|
|
11
11
|
return *operation.triangleArithmetic;
|
|
12
12
|
}
|
|
13
13
|
void work(SolverOperation& operation,std::uint64_t amount=1){if(!operation.triangleQuota.charge(amount))throw TriangleNativeFailure{tp::Failure::WorkExhausted};}
|
|
14
|
-
void stage(SolverOperation& operation,std::uint64_t bytes){if(bytes>operation.triangleStagingRemaining)throw TriangleNativeFailure{tp::Failure::ArithmeticExhausted};operation.triangleStagingRemaining-=bytes;}
|
|
14
|
+
void stage(SolverOperation& operation,std::uint64_t bytes){if(bytes>operation.triangleStagingRemaining)throw TriangleNativeFailure{tp::Failure::ArithmeticExhausted};operation.triangleStagingRemaining-=bytes;}\
|
|
15
15
|
template<class T>void append(SolverOperation& operation,std::vector<T>& list,T value){
|
|
16
16
|
work(operation);
|
|
17
17
|
if(list.size()==list.capacity()){
|
|
@@ -174,10 +174,16 @@ Collision observeGeometry(SolverOperation& operation,const Body& capsule,const B
|
|
|
174
174
|
work(operation);
|
|
175
175
|
arithmetic(operation);
|
|
176
176
|
if(!orientation_private::validUnit(capsule.orientationX,capsule.orientationY,capsule.orientationZ,capsule.orientationW)
|
|
177
|
-
||!orientation_private::validUnit(geometry.orientationX,geometry.orientationY,geometry.orientationZ,geometry.orientationW))throw TriangleNativeFailure{tp::Failure::InvalidInput}
|
|
177
|
+
||!orientation_private::validUnit(geometry.orientationX,geometry.orientationY,geometry.orientationZ,geometry.orientationW))throw TriangleNativeFailure{tp::Failure::InvalidInput};\
|
|
178
178
|
const auto payload=geometryForBody(operation,geometry);
|
|
179
|
-
if(payload.size()>12600000u||payload.size()%3)throw TriangleNativeFailure{tp::Failure::FeatureCapacity}
|
|
179
|
+
if(payload.size()>12600000u||payload.size()%3)throw TriangleNativeFailure{tp::Failure::FeatureCapacity};\
|
|
180
180
|
const auto capsuleAxis=rotateByOrientation(capsule,{0.,1.,0.});
|
|
181
|
+
const double capLatX = capsule.shape0 + axisDelta(capsuleAxis.x) * capsule.shape1;
|
|
182
|
+
const double capLatY = capsule.shape0 + axisDelta(capsuleAxis.y) * capsule.shape1;
|
|
183
|
+
const double capLatZ = capsule.shape0 + axisDelta(capsuleAxis.z) * capsule.shape1;
|
|
184
|
+
const Vec3 rotX = rotateByOrientation(geometry, {1.0, 0.0, 0.0});
|
|
185
|
+
const Vec3 rotY = rotateByOrientation(geometry, {0.0, 1.0, 0.0});
|
|
186
|
+
const Vec3 rotZ = rotateByOrientation(geometry, {0.0, 0.0, 1.0});
|
|
181
187
|
tp::Input input;input.radius=capsule.shape0;input.projection=tp::ProjectionAssessment::RoundedNativePose;
|
|
182
188
|
input.segment={tp::Point{-capsuleAxis.x*capsule.shape1,-capsuleAxis.y*capsule.shape1,-capsuleAxis.z*capsule.shape1},tp::Point{capsuleAxis.x*capsule.shape1,capsuleAxis.y*capsule.shape1,capsuleAxis.z*capsule.shape1}};
|
|
183
189
|
Collision best;
|
|
@@ -221,7 +227,7 @@ Collision observeGeometry(SolverOperation& operation,const Body& capsule,const B
|
|
|
221
227
|
triangle(candidate.points[0], candidate.points[1], candidate.points[2], candidate.ordinal);
|
|
222
228
|
}
|
|
223
229
|
}
|
|
224
|
-
}
|
|
230
|
+
};\
|
|
225
231
|
visit(visit, segment->root);
|
|
226
232
|
return true;
|
|
227
233
|
};
|
|
@@ -256,10 +262,17 @@ Collision observeGeometry(SolverOperation& operation,const Body& capsule,const B
|
|
|
256
262
|
const double cY=geometry.y+geometry.shapeOffsetY+translated.y-(capsule.y+capsule.shapeOffsetY);
|
|
257
263
|
const double cZ=geometry.z+geometry.shapeOffsetZ+translated.z-(capsule.z+capsule.shapeOffsetZ);
|
|
258
264
|
const double p0=payload[at+4],p1=payload[at+5],p2=payload[at+6];
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
265
|
+
if (kind == static_cast<std::uint32_t>(ShapeKind::Box)) {
|
|
266
|
+
const double boxHalfX = axisDelta(rotX.x) * p0 + axisDelta(rotY.x) * p1 + axisDelta(rotZ.x) * p2;
|
|
267
|
+
const double boxHalfY = axisDelta(rotX.y) * p0 + axisDelta(rotY.y) * p1 + axisDelta(rotZ.y) * p2;
|
|
268
|
+
const double boxHalfZ = axisDelta(rotX.z) * p0 + axisDelta(rotY.z) * p1 + axisDelta(rotZ.z) * p2;
|
|
269
|
+
if (std::abs(cX) > boxHalfX + capLatX || std::abs(cY) > boxHalfY + capLatY || std::abs(cZ) > boxHalfZ + capLatZ) continue;
|
|
270
|
+
} else {
|
|
271
|
+
const double childRadius=kind==static_cast<std::uint32_t>(ShapeKind::Sphere)?p0:(p0+p1);
|
|
272
|
+
const double capsuleRadius=capsule.shape0+capsule.shape1;
|
|
273
|
+
const double maxDist=childRadius+capsuleRadius;
|
|
274
|
+
if(cX*cX+cY*cY+cZ*cZ>maxDist*maxDist)continue;
|
|
275
|
+
}
|
|
263
276
|
}
|
|
264
277
|
work(operation);
|
|
265
278
|
if(child>std::uint32_t(std::numeric_limits<std::int32_t>::max()))throw TriangleNativeFailure{tp::Failure::FeatureCapacity};
|
|
@@ -273,10 +286,17 @@ Collision observeGeometry(SolverOperation& operation,const Body& capsule,const B
|
|
|
273
286
|
child.x=sum(operation,{geometry.x,geometry.shapeOffsetX,translated.x,-capsule.x,-capsule.shapeOffsetX},certified_sum::SumSite::ChildPose);child.y=sum(operation,{geometry.y,geometry.shapeOffsetY,translated.y,-capsule.y,-capsule.shapeOffsetY},certified_sum::SumSite::ChildPose);child.z=sum(operation,{geometry.z,geometry.shapeOffsetZ,translated.z,-capsule.z,-capsule.shapeOffsetZ},certified_sum::SumSite::ChildPose);
|
|
274
287
|
child.shapeOffsetX=child.shapeOffsetY=child.shapeOffsetZ=0.;
|
|
275
288
|
const double p0=child.shape0,p1=child.shape1,p2=child.shape2;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
289
|
+
if (node.kind == ShapeKind::Box) {
|
|
290
|
+
const double boxHalfX = axisDelta(rotX.x) * p0 + axisDelta(rotY.x) * p1 + axisDelta(rotZ.x) * p2;
|
|
291
|
+
const double boxHalfY = axisDelta(rotX.y) * p0 + axisDelta(rotY.y) * p1 + axisDelta(rotZ.y) * p2;
|
|
292
|
+
const double boxHalfZ = axisDelta(rotX.z) * p0 + axisDelta(rotY.z) * p1 + axisDelta(rotZ.z) * p2;
|
|
293
|
+
if (std::abs(child.x) > boxHalfX + capLatX || std::abs(child.y) > boxHalfY + capLatY || std::abs(child.z) > boxHalfZ + capLatZ) continue;
|
|
294
|
+
} else {
|
|
295
|
+
const double childRadius=child.shape==ShapeKind::Sphere?p0:(p0+p1);
|
|
296
|
+
const double capsuleRadius=capsule.shape0+capsule.shape1;
|
|
297
|
+
const double maxDist=childRadius+capsuleRadius;
|
|
298
|
+
if(child.x*child.x+child.y*child.y+child.z*child.z>maxDist*maxDist)continue;
|
|
299
|
+
}
|
|
280
300
|
auto collision=node.kind==ShapeKind::Sphere?capsuleSphere(localCapsule,child):node.kind==ShapeKind::Box?capsuleBox(localCapsule,child):capsuleCapsule(localCapsule,child);
|
|
281
301
|
if(collision.hit){if(!collision.pointCount){collision.pointCount=1;collision.points[0]={collision.pointX,collision.pointY,collision.pointZ};}
|
|
282
302
|
auto& basis=collision.coordinates.emplace<TriangleManifoldBasis>();collision.geometryChildIndex=node.outerChild;basis.anchor={capsule.x,capsule.y,capsule.z};basis.shapeOffset={capsule.shapeOffsetX,capsule.shapeOffsetY,capsule.shapeOffsetZ};
|
|
@@ -290,9 +290,130 @@ GeometryRecord::GeometryRecord(ConstructionKey, std::shared_ptr<AllocationLedger
|
|
|
290
290
|
triangleSegments_(LedgerAllocator<GeometryTriangleSegment>{std::move(ledger)}),
|
|
291
291
|
id(recordId), descriptor(shape), fingerprint(hash),
|
|
292
292
|
strongLeaf_(digestGeometryRecord(shape, values)) {
|
|
293
|
+
buildBounds();
|
|
293
294
|
buildTriangleIndex();
|
|
294
295
|
}
|
|
295
296
|
|
|
297
|
+
void GeometryRecord::buildBounds() {
|
|
298
|
+
if (values_.empty() || descriptor.count == 0) return;
|
|
299
|
+
if (descriptor.kind == ShapeKind::Compound && descriptor.format == 4) {
|
|
300
|
+
constexpr std::uint32_t childStride = 15;
|
|
301
|
+
const std::uint32_t childCount = descriptor.count / 5;
|
|
302
|
+
if (childCount == 0 || childCount * 5 != descriptor.count) return;
|
|
303
|
+
constexpr std::uint32_t first = 0;
|
|
304
|
+
if (first + 12 >= values_.size()) return;
|
|
305
|
+
minimum_[0] = values_[first + 1] + values_[first + 7];
|
|
306
|
+
minimum_[1] = values_[first + 2] + values_[first + 8];
|
|
307
|
+
minimum_[2] = values_[first + 3] + values_[first + 9];
|
|
308
|
+
maximum_[0] = values_[first + 1] + values_[first + 10];
|
|
309
|
+
maximum_[1] = values_[first + 2] + values_[first + 11];
|
|
310
|
+
maximum_[2] = values_[first + 3] + values_[first + 12];
|
|
311
|
+
for (std::uint32_t child = 1; child < childCount; child += 1) {
|
|
312
|
+
const std::uint32_t offset = first + child * childStride;
|
|
313
|
+
if (offset + 12 >= values_.size()) return;
|
|
314
|
+
minimum_[0] = std::min(minimum_[0], values_[offset + 1] + values_[offset + 7]);
|
|
315
|
+
minimum_[1] = std::min(minimum_[1], values_[offset + 2] + values_[offset + 8]);
|
|
316
|
+
minimum_[2] = std::min(minimum_[2], values_[offset + 3] + values_[offset + 9]);
|
|
317
|
+
maximum_[0] = std::max(maximum_[0], values_[offset + 1] + values_[offset + 10]);
|
|
318
|
+
maximum_[1] = std::max(maximum_[1], values_[offset + 2] + values_[offset + 11]);
|
|
319
|
+
maximum_[2] = std::max(maximum_[2], values_[offset + 3] + values_[offset + 12]);
|
|
320
|
+
}
|
|
321
|
+
hasBounds_ = true;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (descriptor.kind == ShapeKind::Compound && descriptor.format == 5) {
|
|
325
|
+
constexpr std::uint32_t childStride = 18;
|
|
326
|
+
constexpr std::uint32_t first = 0;
|
|
327
|
+
if (first + 17 >= values_.size()) return;
|
|
328
|
+
const std::uint32_t childCount = static_cast<std::uint32_t>(values_[first + 17]);
|
|
329
|
+
if (childCount == 0 || childCount * 6 > descriptor.count) return;
|
|
330
|
+
if (first + 12 >= values_.size()) return;
|
|
331
|
+
minimum_[0] = values_[first + 1] + values_[first + 7];
|
|
332
|
+
minimum_[1] = values_[first + 2] + values_[first + 8];
|
|
333
|
+
minimum_[2] = values_[first + 3] + values_[first + 9];
|
|
334
|
+
maximum_[0] = values_[first + 1] + values_[first + 10];
|
|
335
|
+
maximum_[1] = values_[first + 2] + values_[first + 11];
|
|
336
|
+
maximum_[2] = values_[first + 3] + values_[first + 12];
|
|
337
|
+
for (std::uint32_t child = 1; child < childCount; child += 1) {
|
|
338
|
+
const std::uint32_t offset = first + child * childStride;
|
|
339
|
+
if (offset + 12 >= values_.size()) return;
|
|
340
|
+
minimum_[0] = std::min(minimum_[0], values_[offset + 1] + values_[offset + 7]);
|
|
341
|
+
minimum_[1] = std::min(minimum_[1], values_[offset + 2] + values_[offset + 8]);
|
|
342
|
+
minimum_[2] = std::min(minimum_[2], values_[offset + 3] + values_[offset + 9]);
|
|
343
|
+
maximum_[0] = std::max(maximum_[0], values_[offset + 1] + values_[offset + 10]);
|
|
344
|
+
maximum_[1] = std::max(maximum_[1], values_[offset + 2] + values_[offset + 11]);
|
|
345
|
+
maximum_[2] = std::max(maximum_[2], values_[offset + 3] + values_[offset + 12]);
|
|
346
|
+
}
|
|
347
|
+
hasBounds_ = true;
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (descriptor.kind == ShapeKind::Compound && descriptor.format == 6) {
|
|
351
|
+
constexpr std::uint32_t childStride = 24;
|
|
352
|
+
constexpr std::uint32_t first = 0;
|
|
353
|
+
if (first + 21 >= values_.size()) return;
|
|
354
|
+
const std::uint32_t childCount = static_cast<std::uint32_t>(values_[first + 21]);
|
|
355
|
+
if (childCount == 0 || childCount * 8 > descriptor.count + 1) return;
|
|
356
|
+
auto calcFmt6 = [&](std::uint32_t offset, double& minX, double& minY, double& minZ, double& maxX, double& maxY, double& maxZ) {
|
|
357
|
+
if (offset + 16 >= values_.size()) return false;
|
|
358
|
+
const double px = values_[offset + 1];
|
|
359
|
+
const double py = values_[offset + 2];
|
|
360
|
+
const double pz = values_[offset + 3];
|
|
361
|
+
const double cMinX = values_[offset + 7];
|
|
362
|
+
const double cMinY = values_[offset + 8];
|
|
363
|
+
const double cMinZ = values_[offset + 9];
|
|
364
|
+
const double cMaxX = values_[offset + 10];
|
|
365
|
+
const double cMaxY = values_[offset + 11];
|
|
366
|
+
const double cMaxZ = values_[offset + 12];
|
|
367
|
+
const double qx = values_[offset + 13];
|
|
368
|
+
const double qy = values_[offset + 14];
|
|
369
|
+
const double qz = values_[offset + 15];
|
|
370
|
+
const double qw = values_[offset + 16];
|
|
371
|
+
if (qx == 0.0 && qy == 0.0 && qz == 0.0 && qw == 1.0) {
|
|
372
|
+
minX = px + cMinX; minY = py + cMinY; minZ = pz + cMinZ;
|
|
373
|
+
maxX = px + cMaxX; maxY = py + cMaxY; maxZ = pz + cMaxZ;
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
const double r00 = 1.0 - 2.0 * (qy * qy + qz * qz);
|
|
377
|
+
const double r01 = 2.0 * (qx * qy - qw * qz);
|
|
378
|
+
const double r02 = 2.0 * (qx * qz + qw * qy);
|
|
379
|
+
const double r10 = 2.0 * (qx * qy + qw * qz);
|
|
380
|
+
const double r11 = 1.0 - 2.0 * (qx * qx + qz * qz);
|
|
381
|
+
const double r12 = 2.0 * (qy * qz - qw * qx);
|
|
382
|
+
const double r20 = 2.0 * (qx * qz - qw * qy);
|
|
383
|
+
const double r21 = 2.0 * (qy * qz + qw * qx);
|
|
384
|
+
const double r22 = 1.0 - 2.0 * (qx * qx + qy * qy);
|
|
385
|
+
const double cx = 0.5 * (cMinX + cMaxX);
|
|
386
|
+
const double cy = 0.5 * (cMinY + cMaxY);
|
|
387
|
+
const double cz = 0.5 * (cMinZ + cMaxZ);
|
|
388
|
+
const double hx = 0.5 * (cMaxX - cMinX);
|
|
389
|
+
const double hy = 0.5 * (cMaxY - cMinY);
|
|
390
|
+
const double hz = 0.5 * (cMaxZ - cMinZ);
|
|
391
|
+
const double rotCx = px + r00 * cx + r01 * cy + r02 * cz;
|
|
392
|
+
const double rotCy = py + r10 * cx + r11 * cy + r12 * cz;
|
|
393
|
+
const double rotCz = pz + r20 * cx + r21 * cy + r22 * cz;
|
|
394
|
+
const double rotHx = std::abs(r00) * hx + std::abs(r01) * hy + std::abs(r02) * hz;
|
|
395
|
+
const double rotHy = std::abs(r10) * hx + std::abs(r11) * hy + std::abs(r12) * hz;
|
|
396
|
+
const double rotHz = std::abs(r20) * hx + std::abs(r21) * hy + std::abs(r22) * hz;
|
|
397
|
+
minX = rotCx - rotHx; minY = rotCy - rotHy; minZ = rotCz - rotHz;
|
|
398
|
+
maxX = rotCx + rotHx; maxY = rotCy + rotHy; maxZ = rotCz + rotHz;
|
|
399
|
+
return true;
|
|
400
|
+
};
|
|
401
|
+
if (!calcFmt6(first, minimum_[0], minimum_[1], minimum_[2], maximum_[0], maximum_[1], maximum_[2])) return;
|
|
402
|
+
for (std::uint32_t child = 1; child < childCount; child += 1) {
|
|
403
|
+
double cMinX, cMinY, cMinZ, cMaxX, cMaxY, cMaxZ;
|
|
404
|
+
if (!calcFmt6(first + child * childStride, cMinX, cMinY, cMinZ, cMaxX, cMaxY, cMaxZ)) return;
|
|
405
|
+
minimum_[0] = std::min(minimum_[0], cMinX);
|
|
406
|
+
minimum_[1] = std::min(minimum_[1], cMinY);
|
|
407
|
+
minimum_[2] = std::min(minimum_[2], cMinZ);
|
|
408
|
+
maximum_[0] = std::max(maximum_[0], cMaxX);
|
|
409
|
+
maximum_[1] = std::max(maximum_[1], cMaxY);
|
|
410
|
+
maximum_[2] = std::max(maximum_[2], cMaxZ);
|
|
411
|
+
}
|
|
412
|
+
hasBounds_ = true;
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
296
417
|
const GeometryTriangleSegment* GeometryRecord::triangleSegment(ShapeKind kind,
|
|
297
418
|
std::uint32_t offset, std::uint32_t count, std::uint32_t format) const noexcept {
|
|
298
419
|
const auto found = std::lower_bound(triangleSegments_.begin(), triangleSegments_.end(), offset,
|
|
@@ -44,6 +44,10 @@ class GeometryRecord : public std::enable_shared_from_this<GeometryRecord> {
|
|
|
44
44
|
std::vector<GeometryTriangle, LedgerAllocator<GeometryTriangle>> triangles_;
|
|
45
45
|
std::vector<GeometryTriangleNode, LedgerAllocator<GeometryTriangleNode>> triangleNodes_;
|
|
46
46
|
std::vector<GeometryTriangleSegment, LedgerAllocator<GeometryTriangleSegment>> triangleSegments_;
|
|
47
|
+
bool hasBounds_ = false;
|
|
48
|
+
std::array<double, 3> minimum_{};
|
|
49
|
+
std::array<double, 3> maximum_{};
|
|
50
|
+
void buildBounds();
|
|
47
51
|
void buildTriangleIndex();
|
|
48
52
|
std::uint32_t buildTriangleNode(std::uint32_t offset, std::uint32_t first, std::uint32_t count);
|
|
49
53
|
public:
|
|
@@ -61,6 +65,9 @@ class GeometryRecord : public std::enable_shared_from_this<GeometryRecord> {
|
|
|
61
65
|
std::span<const GeometryTriangleNode> triangleNodes() const noexcept { return triangleNodes_; }
|
|
62
66
|
const GeometryTriangleSegment* triangleSegment(ShapeKind kind, std::uint32_t offset,
|
|
63
67
|
std::uint32_t count, std::uint32_t format) const noexcept;
|
|
68
|
+
bool hasBounds() const noexcept { return hasBounds_; }
|
|
69
|
+
const std::array<double, 3>& minimum() const noexcept { return minimum_; }
|
|
70
|
+
const std::array<double, 3>& maximum() const noexcept { return maximum_; }
|
|
64
71
|
};
|
|
65
72
|
using GeometryRecordOwner = std::shared_ptr<const GeometryRecord>;
|
|
66
73
|
struct GeometryBinding {
|
|
@@ -1272,6 +1272,15 @@ inline void calculateChildBoundsFormat6(
|
|
|
1272
1272
|
}
|
|
1273
1273
|
|
|
1274
1274
|
bool geometryBounds(SolverOperation& operation, const Body& body, GeometryBounds& bounds) {
|
|
1275
|
+
if (body.geometryRecord != nullptr && body.geometryRecord->hasBounds()) {
|
|
1276
|
+
bounds.minX = body.geometryRecord->minimum()[0];
|
|
1277
|
+
bounds.minY = body.geometryRecord->minimum()[1];
|
|
1278
|
+
bounds.minZ = body.geometryRecord->minimum()[2];
|
|
1279
|
+
bounds.maxX = body.geometryRecord->maximum()[0];
|
|
1280
|
+
bounds.maxY = body.geometryRecord->maximum()[1];
|
|
1281
|
+
bounds.maxZ = body.geometryRecord->maximum()[2];
|
|
1282
|
+
return true;
|
|
1283
|
+
}
|
|
1275
1284
|
if (geometryForBody(operation, body).data() == nullptr || body.geometryCount == 0) return false;
|
|
1276
1285
|
if (body.shape == ShapeKind::Compound && body.geometryFormat == 4) {
|
|
1277
1286
|
constexpr std::uint32_t childStride = 15;
|
|
@@ -3068,6 +3077,14 @@ public:
|
|
|
3068
3077
|
return pairsReady;
|
|
3069
3078
|
}
|
|
3070
3079
|
|
|
3080
|
+
bool isInitialized() const noexcept {
|
|
3081
|
+
return initialized;
|
|
3082
|
+
}
|
|
3083
|
+
|
|
3084
|
+
std::uint32_t count() const noexcept {
|
|
3085
|
+
return bodyCount;
|
|
3086
|
+
}
|
|
3087
|
+
|
|
3071
3088
|
std::uint64_t retainedBytes() const noexcept {
|
|
3072
3089
|
return static_cast<std::uint64_t>(actualBounds.capacity()) * sizeof(BroadphaseBounds)
|
|
3073
3090
|
+ static_cast<std::uint64_t>(queryMatches.capacity()) * sizeof(std::uint32_t)
|
|
@@ -4943,6 +4960,23 @@ void solveAccumulatedPointConstraint(
|
|
|
4943
4960
|
}
|
|
4944
4961
|
}
|
|
4945
4962
|
|
|
4963
|
+
inline bool isJointActivelyDriven(const Joint& joint) noexcept {
|
|
4964
|
+
if (joint.kind == JointKind::Motor) {
|
|
4965
|
+
if ((joint.flags & 32768u) != 0) {
|
|
4966
|
+
if (joint.maxLinearMotor > 0.0 && (joint.motorLinearX != 0.0 || joint.motorLinearY != 0.0 || joint.motorLinearZ != 0.0)) return true;
|
|
4967
|
+
}
|
|
4968
|
+
if ((joint.flags & 65536u) != 0) {
|
|
4969
|
+
if (joint.maxAngularMotor > 0.0 && (joint.motorAngularX != 0.0 || joint.motorAngularY != 0.0 || joint.motorAngularZ != 0.0)) return true;
|
|
4970
|
+
}
|
|
4971
|
+
if (joint.maxMotor > 0.0 && joint.motorSpeed != 0.0) return true;
|
|
4972
|
+
}
|
|
4973
|
+
if ((joint.kind == JointKind::Revolute || joint.kind == JointKind::Prismatic) && joint.maxMotor > 0.0 && joint.motorSpeed != 0.0) return true;
|
|
4974
|
+
if (joint.kind == JointKind::Wheel && joint.maxMotor > 0.0 && joint.motorSpeed != 0.0) return true;
|
|
4975
|
+
if (joint.kind == JointKind::Spherical && (joint.flags & 65536u) != 0 && joint.maxAngularMotor > 0.0
|
|
4976
|
+
&& (joint.motorAngularX != 0.0 || joint.motorAngularY != 0.0 || joint.motorAngularZ != 0.0)) return true;
|
|
4977
|
+
return false;
|
|
4978
|
+
}
|
|
4979
|
+
|
|
4946
4980
|
void resolveJoints(SolverOperation& operation, Body* bodies, std::uint32_t bodyCount, const Joint* joints,
|
|
4947
4981
|
std::uint32_t jointCount, const StepOptions& options) {
|
|
4948
4982
|
if (jointCount == 0) return;
|
|
@@ -4960,6 +4994,11 @@ void resolveJoints(SolverOperation& operation, Body* bodies, std::uint32_t bodyC
|
|
|
4960
4994
|
if (joint.bodyA >= bodyCount || joint.bodyB >= bodyCount || joint.bodyA == joint.bodyB) continue;
|
|
4961
4995
|
Body& a = bodies[joint.bodyA];
|
|
4962
4996
|
Body& b = bodies[joint.bodyB];
|
|
4997
|
+
if (!isJointActivelyDriven(joint)
|
|
4998
|
+
&& (a.sleeping || (!a.dynamic && !a.kinematic))
|
|
4999
|
+
&& (b.sleeping || (!b.dynamic && !b.kinematic))) {
|
|
5000
|
+
continue;
|
|
5001
|
+
}
|
|
4963
5002
|
if (joint.kind == JointKind::Distance) {
|
|
4964
5003
|
const Vec3 worldA = worldJointAnchor(a, joint.anchorAX, joint.anchorAY, joint.anchorAZ);
|
|
4965
5004
|
const Vec3 worldB = worldJointAnchor(b, joint.anchorBX, joint.anchorBY, joint.anchorBZ);
|
|
@@ -6934,6 +6973,9 @@ RayHit rayBody(SolverOperation& operation, const Body& body, const Vec3& origin,
|
|
|
6934
6973
|
}
|
|
6935
6974
|
if (body.shape == ShapeKind::Compound
|
|
6936
6975
|
&& (body.geometryFormat == 4 || body.geometryFormat == 5 || body.geometryFormat == 6)) {
|
|
6976
|
+
const BroadphaseBounds bounds = queryProxyBounds(operation, body);
|
|
6977
|
+
if (!rayAabb(bounds, origin, direction, maxDistance).hit) return {};
|
|
6978
|
+
|
|
6937
6979
|
const Vec3 center{body.x + body.shapeOffsetX, body.y + body.shapeOffsetY, body.z + body.shapeOffsetZ};
|
|
6938
6980
|
const Vec3 localOrigin = inverseRotateByOrientation(body, subtractVec3(origin, center));
|
|
6939
6981
|
const Vec3 localDirection = inverseRotateByOrientation(body, direction);
|
|
@@ -6942,9 +6984,21 @@ RayHit rayBody(SolverOperation& operation, const Body& body, const Vec3& origin,
|
|
|
6942
6984
|
localParent.shapeOffsetX = localParent.shapeOffsetY = localParent.shapeOffsetZ = 0.0;
|
|
6943
6985
|
localParent.orientationX = localParent.orientationY = localParent.orientationZ = 0.0;
|
|
6944
6986
|
localParent.orientationW = 1.0;
|
|
6987
|
+
const Vec3 localEnd = addVec3(localOrigin, scaleVec3(localDirection, maxDistance));
|
|
6988
|
+
const BroadphaseBounds localRayBounds{
|
|
6989
|
+
std::min(localOrigin.x, localEnd.x),
|
|
6990
|
+
std::min(localOrigin.y, localEnd.y),
|
|
6991
|
+
std::min(localOrigin.z, localEnd.z),
|
|
6992
|
+
std::max(localOrigin.x, localEnd.x),
|
|
6993
|
+
std::max(localOrigin.y, localEnd.y),
|
|
6994
|
+
std::max(localOrigin.z, localEnd.z),
|
|
6995
|
+
};
|
|
6945
6996
|
RayHit best;
|
|
6946
6997
|
for (std::uint32_t child = 0; child < compoundChildCount(operation, body); child += 1) {
|
|
6947
|
-
|
|
6998
|
+
const Body childBody = compoundChildBody(operation, localParent, child);
|
|
6999
|
+
const BroadphaseBounds childBounds = queryProxyBounds(operation, childBody);
|
|
7000
|
+
if (!boundsOverlap(localRayBounds, childBounds)) continue;
|
|
7001
|
+
RayHit candidate = rayBody(operation, childBody, localOrigin, localDirection, maxDistance);
|
|
6948
7002
|
if (candidate.hit && (!best.hit || candidate.distance < best.distance)) {
|
|
6949
7003
|
candidate.childIndex = static_cast<std::int32_t>(child);
|
|
6950
7004
|
best = candidate;
|
|
@@ -7107,10 +7161,23 @@ std::int32_t runRaycastQuery(SolverOperation& operation,
|
|
|
7107
7161
|
const double length = solverSqrt(dotVec3(rawDirection, rawDirection));
|
|
7108
7162
|
const Vec3 direction = scaleVec3(rawDirection, 1.0 / length);
|
|
7109
7163
|
const Vec3 origin{queryData[7], queryData[8], queryData[9]};
|
|
7164
|
+
const double maxDistance = queryData[17];
|
|
7165
|
+
const Vec3 rayEnd = addVec3(origin, scaleVec3(direction, maxDistance));
|
|
7166
|
+
const BroadphaseBounds rayBounds{
|
|
7167
|
+
std::min(origin.x, rayEnd.x),
|
|
7168
|
+
std::min(origin.y, rayEnd.y),
|
|
7169
|
+
std::min(origin.z, rayEnd.z),
|
|
7170
|
+
std::max(origin.x, rayEnd.x),
|
|
7171
|
+
std::max(origin.y, rayEnd.y),
|
|
7172
|
+
std::max(origin.z, rayEnd.z),
|
|
7173
|
+
};
|
|
7110
7174
|
for (std::uint32_t index = 0; index < bodyCount; index += 1) {
|
|
7111
7175
|
if (static_cast<std::int32_t>(queryData[20]) == static_cast<std::int32_t>(index)
|
|
7112
7176
|
|| !queryBodyAllowed(operation.storage.soaBodies[index], queryData)) continue;
|
|
7113
|
-
|
|
7177
|
+
const Body& target = operation.storage.soaBodies[index];
|
|
7178
|
+
const BroadphaseBounds targetBounds = queryProxyBounds(operation, target);
|
|
7179
|
+
if (!boundsOverlap(rayBounds, targetBounds)) continue;
|
|
7180
|
+
appendQueryHit(operation, index, rayBody(operation, target, origin, direction, maxDistance));
|
|
7114
7181
|
}
|
|
7115
7182
|
finalizeQueryResults(operation, false);
|
|
7116
7183
|
return 0;
|
|
@@ -7156,7 +7223,42 @@ std::int32_t runOverlapQuery(SolverOperation& operation,
|
|
|
7156
7223
|
const bool useGeometryProxy = (isGeometryShape(queryBody.shape) && isGeometryShape(target.shape))
|
|
7157
7224
|
|| (cast && (target.shape == ShapeKind::Mesh && target.geometryCount % 3 != 0))
|
|
7158
7225
|
|| (cast && (queryBody.shape == ShapeKind::Mesh && queryBody.geometryCount % 3 != 0));
|
|
7159
|
-
|
|
7226
|
+
struct ActiveCompoundChild {
|
|
7227
|
+
std::uint32_t index;
|
|
7228
|
+
Body body;
|
|
7229
|
+
BroadphaseBounds bounds;
|
|
7230
|
+
};
|
|
7231
|
+
std::vector<ActiveCompoundChild> activeCompoundChildren;
|
|
7232
|
+
if (target.shape == ShapeKind::Compound) {
|
|
7233
|
+
for (std::uint32_t child = 0; child < compoundChildCount(operation, target); child += 1) {
|
|
7234
|
+
const Body childBody = compoundChildBody(operation, target, child);
|
|
7235
|
+
const BroadphaseBounds childBounds = queryProxyBounds(operation, childBody);
|
|
7236
|
+
if (boundsOverlap(queryBounds, childBounds)) {
|
|
7237
|
+
activeCompoundChildren.push_back({child, childBody, childBounds});
|
|
7238
|
+
}
|
|
7239
|
+
}
|
|
7240
|
+
if (activeCompoundChildren.empty()) continue;
|
|
7241
|
+
}
|
|
7242
|
+
auto collisionAt = [&](const Body& moved) -> Collision {
|
|
7243
|
+
if (target.shape == ShapeKind::Compound) {
|
|
7244
|
+
const BroadphaseBounds boundsB = queryProxyBounds(operation, moved);
|
|
7245
|
+
Collision best;
|
|
7246
|
+
std::int32_t bestChild = -1;
|
|
7247
|
+
for (const auto& item : activeCompoundChildren) {
|
|
7248
|
+
if (!boundsOverlap(item.bounds, boundsB)) continue;
|
|
7249
|
+
const Collision candidate = flipCollision(collide(operation, item.body, moved));
|
|
7250
|
+
if (candidate.hit) {
|
|
7251
|
+
if (!best.hit || candidate.penetration > best.penetration) {
|
|
7252
|
+
best = candidate;
|
|
7253
|
+
bestChild = static_cast<std::int32_t>(item.index);
|
|
7254
|
+
}
|
|
7255
|
+
}
|
|
7256
|
+
}
|
|
7257
|
+
if (best.hit && bestChild >= 0) {
|
|
7258
|
+
best.geometryChildIndex = bestChild;
|
|
7259
|
+
}
|
|
7260
|
+
return best;
|
|
7261
|
+
}
|
|
7160
7262
|
return useGeometryProxy ? queryProxyCollision(operation, moved, target) : collide(operation, moved, target);
|
|
7161
7263
|
};
|
|
7162
7264
|
if (!cast) {
|
|
@@ -8020,6 +8122,17 @@ void wakeJointComponents(SolverOperation& operation, Body* bodies,
|
|
|
8020
8122
|
operation.storage.sleepHasKinematic[sleepFind(operation, index)] = 1;
|
|
8021
8123
|
}
|
|
8022
8124
|
}
|
|
8125
|
+
for (std::uint32_t index = 0; index < jointCount; ++index) {
|
|
8126
|
+
const Joint& joint = joints[index];
|
|
8127
|
+
if (joint.bodyA < bodyCount && joint.bodyB < bodyCount && isJointActivelyDriven(joint)) {
|
|
8128
|
+
if (bodies[joint.bodyA].dynamic) {
|
|
8129
|
+
operation.storage.sleepHasKinematic[sleepFind(operation, joint.bodyA)] = 1;
|
|
8130
|
+
}
|
|
8131
|
+
if (bodies[joint.bodyB].dynamic) {
|
|
8132
|
+
operation.storage.sleepHasKinematic[sleepFind(operation, joint.bodyB)] = 1;
|
|
8133
|
+
}
|
|
8134
|
+
}
|
|
8135
|
+
}
|
|
8023
8136
|
for (std::uint32_t index = 0; index < bodyCount; ++index) {
|
|
8024
8137
|
Body& body = bodies[index];
|
|
8025
8138
|
if (body.dynamic && body.sleeping
|
|
@@ -8099,6 +8212,16 @@ void updateSleepingStates(SolverOperation& operation,
|
|
|
8099
8212
|
operation.storage.sleepHasStaticAnchor[joint.bodyB] = true;
|
|
8100
8213
|
}
|
|
8101
8214
|
}
|
|
8215
|
+
if (isJointActivelyDriven(joint)) {
|
|
8216
|
+
if (dynA) {
|
|
8217
|
+
operation.storage.sleepCanSleep[joint.bodyA] = false;
|
|
8218
|
+
bodies[joint.bodyA].sleepTime = 0.0;
|
|
8219
|
+
}
|
|
8220
|
+
if (dynB) {
|
|
8221
|
+
operation.storage.sleepCanSleep[joint.bodyB] = false;
|
|
8222
|
+
bodies[joint.bodyB].sleepTime = 0.0;
|
|
8223
|
+
}
|
|
8224
|
+
}
|
|
8102
8225
|
}
|
|
8103
8226
|
for (const auto& connection : connections) {
|
|
8104
8227
|
if (connection[0] < bodyCount && connection[1] < bodyCount) {
|