@series-inc/rundot-syncplay 6.0.0-rc.73 → 6.0.0-rc.76
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/core/native/physics/physics.cpp +300 -154
- package/core/src/physics/physics-profile-wasm-module.generated.mjs +4 -4
- package/core/src/physics/physics-profile.wasm +0 -0
- package/core/src/physics/physics-wasm-module.generated.mjs +4 -4
- package/core/src/physics/physics.wasm +0 -0
- package/core/src/physics2d/physics2d-wasm-module.generated.mjs +1 -1
- package/dist/authority-room.d.ts +25 -0
- package/dist/authority-room.js +34 -6
- package/dist/canonical.d.ts +2 -0
- package/dist/canonical.js +22 -0
- package/dist/input-authority.d.ts +15 -0
- package/dist/input-authority.js +110 -1
- package/package.json +1 -1
|
@@ -535,7 +535,7 @@ struct Collision {
|
|
|
535
535
|
bool geometryEndpointTracked=false;
|
|
536
536
|
};
|
|
537
537
|
|
|
538
|
-
double axisDelta(double value) {
|
|
538
|
+
inline double axisDelta(double value) {
|
|
539
539
|
return value < 0.0 ? -value : value;
|
|
540
540
|
}
|
|
541
541
|
|
|
@@ -551,23 +551,23 @@ std::array<Vec3, 2> sweptContactLevers(SolverOperation&, const RelativeContactBa
|
|
|
551
551
|
std::array<Vec3, 2> materialCollisionLevers(SolverOperation&, const Collision&, unsigned, const Body&, const Body&);
|
|
552
552
|
RelativeContactBasis materialRetainedBasis(SolverOperation&, const ContactConstraintBlock&, const Collision&, unsigned);
|
|
553
553
|
|
|
554
|
-
Vec3 addVec3(const Vec3& left, const Vec3& right) {
|
|
554
|
+
inline Vec3 addVec3(const Vec3& left, const Vec3& right) {
|
|
555
555
|
return {left.x + right.x, left.y + right.y, left.z + right.z};
|
|
556
556
|
}
|
|
557
557
|
|
|
558
|
-
Vec3 subtractVec3(const Vec3& left, const Vec3& right) {
|
|
558
|
+
inline Vec3 subtractVec3(const Vec3& left, const Vec3& right) {
|
|
559
559
|
return {left.x - right.x, left.y - right.y, left.z - right.z};
|
|
560
560
|
}
|
|
561
561
|
|
|
562
|
-
Vec3 scaleVec3(const Vec3& value, double scale) {
|
|
562
|
+
inline Vec3 scaleVec3(const Vec3& value, double scale) {
|
|
563
563
|
return {value.x * scale, value.y * scale, value.z * scale};
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
-
double dotVec3(const Vec3& left, const Vec3& right) {
|
|
566
|
+
inline double dotVec3(const Vec3& left, const Vec3& right) {
|
|
567
567
|
return left.x * right.x + left.y * right.y + left.z * right.z;
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
-
Vec3 crossVec3(const Vec3& left, const Vec3& right) {
|
|
570
|
+
inline Vec3 crossVec3(const Vec3& left, const Vec3& right) {
|
|
571
571
|
return {
|
|
572
572
|
left.y * right.z - left.z * right.y,
|
|
573
573
|
left.z * right.x - left.x * right.z,
|
|
@@ -575,19 +575,19 @@ Vec3 crossVec3(const Vec3& left, const Vec3& right) {
|
|
|
575
575
|
};
|
|
576
576
|
}
|
|
577
577
|
|
|
578
|
-
Vec3 rotateByQuaternion(double qx, double qy, double qz, double qw, const Vec3& value) {
|
|
578
|
+
inline Vec3 rotateByQuaternion(double qx, double qy, double qz, double qw, const Vec3& value) {
|
|
579
579
|
const Vec3 q{qx, qy, qz};
|
|
580
580
|
const Vec3 uv = crossVec3(q, value);
|
|
581
581
|
const Vec3 uuv = crossVec3(q, uv);
|
|
582
582
|
return addVec3(value, addVec3(scaleVec3(uv, 2.0 * qw), scaleVec3(uuv, 2.0)));
|
|
583
583
|
}
|
|
584
584
|
|
|
585
|
-
Vec3 rotateByOrientation(const Body& body, const Vec3& value) {
|
|
585
|
+
inline Vec3 rotateByOrientation(const Body& body, const Vec3& value) {
|
|
586
586
|
return rotateByQuaternion(
|
|
587
587
|
body.orientationX, body.orientationY, body.orientationZ, body.orientationW, value);
|
|
588
588
|
}
|
|
589
589
|
|
|
590
|
-
Vec3 inverseRotateByOrientation(const Body& body, const Vec3& value) {
|
|
590
|
+
inline Vec3 inverseRotateByOrientation(const Body& body, const Vec3& value) {
|
|
591
591
|
return rotateByQuaternion(
|
|
592
592
|
-body.orientationX, -body.orientationY, -body.orientationZ, body.orientationW, value);
|
|
593
593
|
}
|
|
@@ -783,20 +783,19 @@ Collision boxBoxAxisAligned(const Body& a, const Body& b, bool isLargeStackWorld
|
|
|
783
783
|
return result;
|
|
784
784
|
}
|
|
785
785
|
|
|
786
|
-
Vec3 boxAxis(const Body& body, std::uint32_t axis) {
|
|
786
|
+
inline Vec3 boxAxis(const Body& body, std::uint32_t axis) {
|
|
787
787
|
if (axis == 0) return rotateByOrientation(body, {1.0, 0.0, 0.0});
|
|
788
788
|
if (axis == 1) return rotateByOrientation(body, {0.0, 1.0, 0.0});
|
|
789
789
|
return rotateByOrientation(body, {0.0, 0.0, 1.0});
|
|
790
790
|
}
|
|
791
791
|
|
|
792
|
-
double boxHalfExtentOnAxis(const Body& body, const std::array<Vec3, 3>& localAxes, const Vec3& axis) {
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
+
|
|
796
|
-
+ half[2] * axisDelta(dotVec3(localAxes[2], axis));
|
|
792
|
+
inline double boxHalfExtentOnAxis(const Body& body, const std::array<Vec3, 3>& localAxes, const Vec3& axis) {
|
|
793
|
+
return body.shape0 * axisDelta(dotVec3(localAxes[0], axis))
|
|
794
|
+
+ body.shape1 * axisDelta(dotVec3(localAxes[1], axis))
|
|
795
|
+
+ body.shape2 * axisDelta(dotVec3(localAxes[2], axis));
|
|
797
796
|
}
|
|
798
797
|
|
|
799
|
-
double boxHalfExtentOnAxis(const Body& body, const Vec3& axis) {
|
|
798
|
+
inline double boxHalfExtentOnAxis(const Body& body, const Vec3& axis) {
|
|
800
799
|
const std::array<Vec3, 3> localAxes{boxAxis(body, 0), boxAxis(body, 1), boxAxis(body, 2)};
|
|
801
800
|
return boxHalfExtentOnAxis(body, localAxes, axis);
|
|
802
801
|
}
|
|
@@ -1115,10 +1114,14 @@ Collision boxBoxOriented(const Body& a, const Body& b, const std::array<Vec3, 3>
|
|
|
1115
1114
|
}
|
|
1116
1115
|
}
|
|
1117
1116
|
};
|
|
1118
|
-
for (const Vec3& axis : axesA)
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1117
|
+
for (const Vec3& axis : axesA) {
|
|
1118
|
+
testAxis(axis, false);
|
|
1119
|
+
if (separated) return {};
|
|
1120
|
+
}
|
|
1121
|
+
for (const Vec3& axis : axesB) {
|
|
1122
|
+
testAxis(axis, false);
|
|
1123
|
+
if (separated) return {};
|
|
1124
|
+
}
|
|
1122
1125
|
for (const Vec3& axisA : axesA) {
|
|
1123
1126
|
for (const Vec3& axisB : axesB) {
|
|
1124
1127
|
testAxis(crossVec3(axisA, axisB), true);
|
|
@@ -1419,48 +1422,49 @@ bool geometryBounds(SolverOperation& operation, const Body& body, GeometryBounds
|
|
|
1419
1422
|
bounds.maxZ = body.geometryRecord->pointMaximum()[2];
|
|
1420
1423
|
return true;
|
|
1421
1424
|
}
|
|
1422
|
-
|
|
1425
|
+
const auto geo = geometryForBody(operation, body);
|
|
1426
|
+
if (geo.data() == nullptr || body.geometryCount == 0) return false;
|
|
1423
1427
|
if (body.shape == ShapeKind::Compound && body.geometryFormat == 4) {
|
|
1424
1428
|
constexpr std::uint32_t childStride = 15;
|
|
1425
1429
|
const std::uint32_t childCount = body.geometryCount / 5;
|
|
1426
1430
|
if (childCount == 0 || childCount * 5 != body.geometryCount) return false;
|
|
1427
1431
|
const std::uint32_t first = body.geometryOffset * 3;
|
|
1428
|
-
bounds.minX =
|
|
1429
|
-
bounds.minY =
|
|
1430
|
-
bounds.minZ =
|
|
1431
|
-
bounds.maxX =
|
|
1432
|
-
bounds.maxY =
|
|
1433
|
-
bounds.maxZ =
|
|
1432
|
+
bounds.minX = geo[first + 1] + geo[first + 7];
|
|
1433
|
+
bounds.minY = geo[first + 2] + geo[first + 8];
|
|
1434
|
+
bounds.minZ = geo[first + 3] + geo[first + 9];
|
|
1435
|
+
bounds.maxX = geo[first + 1] + geo[first + 10];
|
|
1436
|
+
bounds.maxY = geo[first + 2] + geo[first + 11];
|
|
1437
|
+
bounds.maxZ = geo[first + 3] + geo[first + 12];
|
|
1434
1438
|
for (std::uint32_t child = 1; child < childCount; child += 1) {
|
|
1435
1439
|
const std::uint32_t offset = first + child * childStride;
|
|
1436
|
-
bounds.minX = std::min(bounds.minX,
|
|
1437
|
-
bounds.minY = std::min(bounds.minY,
|
|
1438
|
-
bounds.minZ = std::min(bounds.minZ,
|
|
1439
|
-
bounds.maxX = std::max(bounds.maxX,
|
|
1440
|
-
bounds.maxY = std::max(bounds.maxY,
|
|
1441
|
-
bounds.maxZ = std::max(bounds.maxZ,
|
|
1440
|
+
bounds.minX = std::min(bounds.minX, geo[offset + 1] + geo[offset + 7]);
|
|
1441
|
+
bounds.minY = std::min(bounds.minY, geo[offset + 2] + geo[offset + 8]);
|
|
1442
|
+
bounds.minZ = std::min(bounds.minZ, geo[offset + 3] + geo[offset + 9]);
|
|
1443
|
+
bounds.maxX = std::max(bounds.maxX, geo[offset + 1] + geo[offset + 10]);
|
|
1444
|
+
bounds.maxY = std::max(bounds.maxY, geo[offset + 2] + geo[offset + 11]);
|
|
1445
|
+
bounds.maxZ = std::max(bounds.maxZ, geo[offset + 3] + geo[offset + 12]);
|
|
1442
1446
|
}
|
|
1443
1447
|
return true;
|
|
1444
1448
|
}
|
|
1445
1449
|
if (body.shape == ShapeKind::Compound && body.geometryFormat == 5) {
|
|
1446
1450
|
constexpr std::uint32_t childStride = 18;
|
|
1447
1451
|
const std::uint32_t first = body.geometryOffset * 3;
|
|
1448
|
-
const std::uint32_t childCount = static_cast<std::uint32_t>(
|
|
1452
|
+
const std::uint32_t childCount = static_cast<std::uint32_t>(geo[first + 17]);
|
|
1449
1453
|
if (childCount == 0 || childCount * 6 > body.geometryCount) return false;
|
|
1450
|
-
bounds.minX =
|
|
1451
|
-
bounds.minY =
|
|
1452
|
-
bounds.minZ =
|
|
1453
|
-
bounds.maxX =
|
|
1454
|
-
bounds.maxY =
|
|
1455
|
-
bounds.maxZ =
|
|
1454
|
+
bounds.minX = geo[first + 1] + geo[first + 7];
|
|
1455
|
+
bounds.minY = geo[first + 2] + geo[first + 8];
|
|
1456
|
+
bounds.minZ = geo[first + 3] + geo[first + 9];
|
|
1457
|
+
bounds.maxX = geo[first + 1] + geo[first + 10];
|
|
1458
|
+
bounds.maxY = geo[first + 2] + geo[first + 11];
|
|
1459
|
+
bounds.maxZ = geo[first + 3] + geo[first + 12];
|
|
1456
1460
|
for (std::uint32_t child = 1; child < childCount; child += 1) {
|
|
1457
1461
|
const std::uint32_t offset = first + child * childStride;
|
|
1458
|
-
bounds.minX = std::min(bounds.minX,
|
|
1459
|
-
bounds.minY = std::min(bounds.minY,
|
|
1460
|
-
bounds.minZ = std::min(bounds.minZ,
|
|
1461
|
-
bounds.maxX = std::max(bounds.maxX,
|
|
1462
|
-
bounds.maxY = std::max(bounds.maxY,
|
|
1463
|
-
bounds.maxZ = std::max(bounds.maxZ,
|
|
1462
|
+
bounds.minX = std::min(bounds.minX, geo[offset + 1] + geo[offset + 7]);
|
|
1463
|
+
bounds.minY = std::min(bounds.minY, geo[offset + 2] + geo[offset + 8]);
|
|
1464
|
+
bounds.minZ = std::min(bounds.minZ, geo[offset + 3] + geo[offset + 9]);
|
|
1465
|
+
bounds.maxX = std::max(bounds.maxX, geo[offset + 1] + geo[offset + 10]);
|
|
1466
|
+
bounds.maxY = std::max(bounds.maxY, geo[offset + 2] + geo[offset + 11]);
|
|
1467
|
+
bounds.maxZ = std::max(bounds.maxZ, geo[offset + 3] + geo[offset + 12]);
|
|
1464
1468
|
}
|
|
1465
1469
|
return true;
|
|
1466
1470
|
}
|
|
@@ -1613,13 +1617,14 @@ Body compoundChildBody(SolverOperation& operation, const Body& body, std::uint32
|
|
|
1613
1617
|
child.geometryCount = 0;
|
|
1614
1618
|
child.geometryFormat = 0;
|
|
1615
1619
|
if (body.geometryFormat == 4) {
|
|
1620
|
+
const auto geo = geometryForBody(operation, body);
|
|
1616
1621
|
const std::uint32_t first = body.geometryOffset * 3 + childIndex * 15;
|
|
1617
|
-
const std::uint32_t kind = static_cast<std::uint32_t>(
|
|
1622
|
+
const std::uint32_t kind = static_cast<std::uint32_t>(geo[first]);
|
|
1618
1623
|
child.shape = static_cast<ShapeKind>(kind);
|
|
1619
|
-
child.shape0 =
|
|
1620
|
-
child.shape1 =
|
|
1621
|
-
child.shape2 =
|
|
1622
|
-
const Vec3 localOffset{
|
|
1624
|
+
child.shape0 = geo[first + 4];
|
|
1625
|
+
child.shape1 = geo[first + 5];
|
|
1626
|
+
child.shape2 = geo[first + 6];
|
|
1627
|
+
const Vec3 localOffset{geo[first + 1], geo[first + 2], geo[first + 3]};
|
|
1623
1628
|
const Vec3 rotatedOffset = rotateByOrientation(body, localOffset);
|
|
1624
1629
|
child.x = body.x + body.shapeOffsetX + rotatedOffset.x;
|
|
1625
1630
|
child.y = body.y + body.shapeOffsetY + rotatedOffset.y;
|
|
@@ -1646,16 +1651,17 @@ Body compoundChildBody(SolverOperation& operation, const Body& body, std::uint32
|
|
|
1646
1651
|
return child;
|
|
1647
1652
|
}
|
|
1648
1653
|
if (body.geometryFormat == 5) {
|
|
1654
|
+
const auto geo = geometryForBody(operation, body);
|
|
1649
1655
|
const std::uint32_t first = body.geometryOffset * 3 + childIndex * 18;
|
|
1650
|
-
const std::uint32_t kind = static_cast<std::uint32_t>(
|
|
1656
|
+
const std::uint32_t kind = static_cast<std::uint32_t>(geo[first]);
|
|
1651
1657
|
child.shape = static_cast<ShapeKind>(kind);
|
|
1652
|
-
child.shape0 =
|
|
1653
|
-
child.shape1 =
|
|
1654
|
-
child.shape2 =
|
|
1655
|
-
child.geometryOffset = body.geometryOffset + static_cast<std::uint32_t>(
|
|
1656
|
-
child.geometryCount = static_cast<std::uint32_t>(
|
|
1657
|
-
child.geometryFormat = static_cast<std::uint32_t>(
|
|
1658
|
-
const Vec3 localOffset{
|
|
1658
|
+
child.shape0 = geo[first + 4];
|
|
1659
|
+
child.shape1 = geo[first + 5];
|
|
1660
|
+
child.shape2 = geo[first + 6];
|
|
1661
|
+
child.geometryOffset = body.geometryOffset + static_cast<std::uint32_t>(geo[first + 13]);
|
|
1662
|
+
child.geometryCount = static_cast<std::uint32_t>(geo[first + 14]);
|
|
1663
|
+
child.geometryFormat = static_cast<std::uint32_t>(geo[first + 15]);
|
|
1664
|
+
const Vec3 localOffset{geo[first + 1], geo[first + 2], geo[first + 3]};
|
|
1659
1665
|
const Vec3 rotatedOffset = rotateByOrientation(body, localOffset);
|
|
1660
1666
|
child.x = body.x + body.shapeOffsetX + rotatedOffset.x;
|
|
1661
1667
|
child.y = body.y + body.shapeOffsetY + rotatedOffset.y;
|
|
@@ -1663,24 +1669,25 @@ Body compoundChildBody(SolverOperation& operation, const Body& body, std::uint32
|
|
|
1663
1669
|
return child;
|
|
1664
1670
|
}
|
|
1665
1671
|
if (body.geometryFormat == 6) {
|
|
1672
|
+
const auto geo = geometryForBody(operation, body);
|
|
1666
1673
|
const std::uint32_t first = body.geometryOffset * 3 + childIndex * 24;
|
|
1667
|
-
const std::uint32_t kind = static_cast<std::uint32_t>(
|
|
1674
|
+
const std::uint32_t kind = static_cast<std::uint32_t>(geo[first]);
|
|
1668
1675
|
child.shape = static_cast<ShapeKind>(kind);
|
|
1669
|
-
child.shape0 =
|
|
1670
|
-
child.shape1 =
|
|
1671
|
-
child.shape2 =
|
|
1672
|
-
const double qx =
|
|
1673
|
-
const double qy =
|
|
1674
|
-
const double qz =
|
|
1675
|
-
const double qw =
|
|
1676
|
+
child.shape0 = geo[first + 4];
|
|
1677
|
+
child.shape1 = geo[first + 5];
|
|
1678
|
+
child.shape2 = geo[first + 6];
|
|
1679
|
+
const double qx = geo[first + 13];
|
|
1680
|
+
const double qy = geo[first + 14];
|
|
1681
|
+
const double qz = geo[first + 15];
|
|
1682
|
+
const double qw = geo[first + 16];
|
|
1676
1683
|
multiplyQuaternions(
|
|
1677
1684
|
body.orientationX, body.orientationY, body.orientationZ, body.orientationW,
|
|
1678
1685
|
qx, qy, qz, qw,
|
|
1679
1686
|
child.orientationX, child.orientationY, child.orientationZ, child.orientationW);
|
|
1680
|
-
child.geometryOffset = body.geometryOffset + static_cast<std::uint32_t>(
|
|
1681
|
-
child.geometryCount = static_cast<std::uint32_t>(
|
|
1682
|
-
child.geometryFormat = static_cast<std::uint32_t>(
|
|
1683
|
-
const Vec3 localOffset{
|
|
1687
|
+
child.geometryOffset = body.geometryOffset + static_cast<std::uint32_t>(geo[first + 17]);
|
|
1688
|
+
child.geometryCount = static_cast<std::uint32_t>(geo[first + 18]);
|
|
1689
|
+
child.geometryFormat = static_cast<std::uint32_t>(geo[first + 19]);
|
|
1690
|
+
const Vec3 localOffset{geo[first + 1], geo[first + 2], geo[first + 3]};
|
|
1684
1691
|
const Vec3 rotatedOffset = rotateByOrientation(body, localOffset);
|
|
1685
1692
|
child.x = body.x + body.shapeOffsetX + rotatedOffset.x;
|
|
1686
1693
|
child.y = body.y + body.shapeOffsetY + rotatedOffset.y;
|
|
@@ -4507,6 +4514,16 @@ struct SolverStorage {
|
|
|
4507
4514
|
std::vector<std::uint32_t> contactSolvePairEnd;
|
|
4508
4515
|
std::vector<std::uint32_t> contactSolveTelemetryIndex;
|
|
4509
4516
|
std::vector<std::uint32_t> contactSolveOutputIndex;
|
|
4517
|
+
struct ActiveSolvePair {
|
|
4518
|
+
std::uint32_t first = 0;
|
|
4519
|
+
std::uint32_t second = 0;
|
|
4520
|
+
std::uint32_t begin = 0;
|
|
4521
|
+
std::uint32_t end = 0;
|
|
4522
|
+
};
|
|
4523
|
+
std::vector<ActiveSolvePair> supportedSolvePairs;
|
|
4524
|
+
std::vector<ActiveSolvePair> cylinderSolvePairs;
|
|
4525
|
+
std::uint32_t supportedSolvePairCount = 0;
|
|
4526
|
+
std::uint32_t cylinderSolvePairCount = 0;
|
|
4510
4527
|
// Logical limits for the grow-on-write buffers above. Overflow checks use these, never a
|
|
4511
4528
|
// vector size, so on-demand growth cannot change when an overflow triggers.
|
|
4512
4529
|
std::uint32_t pairLogicalCapacity = 0;
|
|
@@ -4581,7 +4598,7 @@ constexpr double kBoundsInfinity = std::numeric_limits<double>::infinity();
|
|
|
4581
4598
|
// Return the adjacent binary64 value. FP status flags are not preserved.
|
|
4582
4599
|
// Interval callers handle NaNs before rounding. Keep their result bits here
|
|
4583
4600
|
// for direct calls too.
|
|
4584
|
-
double adjacentBoundsValue(double value, bool upward) {
|
|
4601
|
+
inline double adjacentBoundsValue(double value, bool upward) {
|
|
4585
4602
|
constexpr std::uint64_t sign = std::uint64_t{1} << 63;
|
|
4586
4603
|
constexpr std::uint64_t infinity = 0x7ff0000000000000ULL;
|
|
4587
4604
|
auto bits = std::bit_cast<std::uint64_t>(value);
|
|
@@ -4595,8 +4612,8 @@ double adjacentBoundsValue(double value, bool upward) {
|
|
|
4595
4612
|
return std::bit_cast<double>(bits);
|
|
4596
4613
|
}
|
|
4597
4614
|
|
|
4598
|
-
BoundsInterval boundsPoint(double value) { return {value, value}; }
|
|
4599
|
-
BoundsInterval boundsAdd(BoundsInterval a, BoundsInterval b) {
|
|
4615
|
+
inline BoundsInterval boundsPoint(double value) { return {value, value}; }
|
|
4616
|
+
inline BoundsInterval boundsAdd(BoundsInterval a, BoundsInterval b) {
|
|
4600
4617
|
if (a.low == 0.0 && a.high == 0.0) return b;
|
|
4601
4618
|
if (b.low == 0.0 && b.high == 0.0) return a;
|
|
4602
4619
|
const double low = a.low + b.low;
|
|
@@ -4604,10 +4621,31 @@ BoundsInterval boundsAdd(BoundsInterval a, BoundsInterval b) {
|
|
|
4604
4621
|
if (std::isnan(low) || std::isnan(high)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4605
4622
|
return {adjacentBoundsValue(low, false), adjacentBoundsValue(high, true)};
|
|
4606
4623
|
}
|
|
4607
|
-
BoundsInterval boundsNegate(BoundsInterval a) { return {-a.high, -a.low}; }
|
|
4608
|
-
BoundsInterval boundsSubtract(BoundsInterval a, BoundsInterval b) { return boundsAdd(a, boundsNegate(b)); }
|
|
4609
|
-
BoundsInterval boundsMultiply(BoundsInterval a, BoundsInterval b) {
|
|
4624
|
+
inline BoundsInterval boundsNegate(BoundsInterval a) { return {-a.high, -a.low}; }
|
|
4625
|
+
inline BoundsInterval boundsSubtract(BoundsInterval a, BoundsInterval b) { return boundsAdd(a, boundsNegate(b)); }
|
|
4626
|
+
inline BoundsInterval boundsMultiply(BoundsInterval a, BoundsInterval b) {
|
|
4610
4627
|
if ((a.low == 0.0 && a.high == 0.0) || (b.low == 0.0 && b.high == 0.0)) return {0.0, 0.0};
|
|
4628
|
+
if (a.low == a.high) {
|
|
4629
|
+
if (b.low == b.high) {
|
|
4630
|
+
const double p = a.low * b.low;
|
|
4631
|
+
if (std::isnan(p)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4632
|
+
return {adjacentBoundsValue(p, false), adjacentBoundsValue(p, true)};
|
|
4633
|
+
}
|
|
4634
|
+
const double p0 = a.low * b.low;
|
|
4635
|
+
const double p1 = a.low * b.high;
|
|
4636
|
+
if (std::isnan(p0) || std::isnan(p1)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4637
|
+
const double low = std::min(p0, p1);
|
|
4638
|
+
const double high = std::max(p0, p1);
|
|
4639
|
+
return {adjacentBoundsValue(low, false), adjacentBoundsValue(high, true)};
|
|
4640
|
+
}
|
|
4641
|
+
if (b.low == b.high) {
|
|
4642
|
+
const double p0 = a.low * b.low;
|
|
4643
|
+
const double p1 = a.high * b.low;
|
|
4644
|
+
if (std::isnan(p0) || std::isnan(p1)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4645
|
+
const double low = std::min(p0, p1);
|
|
4646
|
+
const double high = std::max(p0, p1);
|
|
4647
|
+
return {adjacentBoundsValue(low, false), adjacentBoundsValue(high, true)};
|
|
4648
|
+
}
|
|
4611
4649
|
const std::array<double, 4> products{a.low * b.low, a.low * b.high, a.high * b.low, a.high * b.high};
|
|
4612
4650
|
double low = kBoundsInfinity;
|
|
4613
4651
|
double high = -kBoundsInfinity;
|
|
@@ -4618,44 +4656,70 @@ BoundsInterval boundsMultiply(BoundsInterval a, BoundsInterval b) {
|
|
|
4618
4656
|
}
|
|
4619
4657
|
return {adjacentBoundsValue(low, false), adjacentBoundsValue(high, true)};
|
|
4620
4658
|
}
|
|
4621
|
-
|
|
4659
|
+
inline BoundsInterval boundsPointMultiply(double a, double b) {
|
|
4660
|
+
if (a == 0.0 || b == 0.0) return {0.0, 0.0};
|
|
4661
|
+
const double p = a * b;
|
|
4662
|
+
if (std::isnan(p)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4663
|
+
return {adjacentBoundsValue(p, false), adjacentBoundsValue(p, true)};
|
|
4664
|
+
}
|
|
4665
|
+
inline BoundsInterval boundsTwice(BoundsInterval a) {
|
|
4666
|
+
if (a.low == 0.0 && a.high == 0.0) return {0.0, 0.0};
|
|
4667
|
+
const double p0 = 2.0 * a.low;
|
|
4668
|
+
const double p1 = 2.0 * a.high;
|
|
4669
|
+
if (std::isnan(p0) || std::isnan(p1)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4670
|
+
return {adjacentBoundsValue(p0, false), adjacentBoundsValue(p1, true)};
|
|
4671
|
+
}
|
|
4672
|
+
inline BoundsInterval boundsSymmetricMultiply(double scalar, double half) {
|
|
4673
|
+
if (scalar == 0.0 || half == 0.0) return {0.0, 0.0};
|
|
4674
|
+
const double p = std::abs(scalar) * half;
|
|
4675
|
+
if (std::isnan(p)) return {-kBoundsInfinity, kBoundsInfinity};
|
|
4676
|
+
const double h = adjacentBoundsValue(p, true);
|
|
4677
|
+
return {-h, h};
|
|
4678
|
+
}
|
|
4679
|
+
inline BoundsVector boundsAdd(BoundsVector a, BoundsVector b) {
|
|
4622
4680
|
return {boundsAdd(a[0], b[0]), boundsAdd(a[1], b[1]), boundsAdd(a[2], b[2])};
|
|
4623
4681
|
}
|
|
4624
|
-
BoundsVector boundsCross(BoundsVector a, BoundsVector b) {
|
|
4682
|
+
inline BoundsVector boundsCross(BoundsVector a, BoundsVector b) {
|
|
4625
4683
|
return {boundsSubtract(boundsMultiply(a[1], b[2]), boundsMultiply(a[2], b[1])),
|
|
4626
4684
|
boundsSubtract(boundsMultiply(a[2], b[0]), boundsMultiply(a[0], b[2])),
|
|
4627
4685
|
boundsSubtract(boundsMultiply(a[0], b[1]), boundsMultiply(a[1], b[0]))};
|
|
4628
4686
|
}
|
|
4629
|
-
BoundsVector boundsScale(BoundsVector a, BoundsInterval scale) {
|
|
4687
|
+
inline BoundsVector boundsScale(BoundsVector a, BoundsInterval scale) {
|
|
4630
4688
|
return {boundsMultiply(a[0], scale), boundsMultiply(a[1], scale), boundsMultiply(a[2], scale)};
|
|
4631
4689
|
}
|
|
4632
|
-
BoundsVector
|
|
4690
|
+
inline BoundsVector boundsTwice(BoundsVector a) {
|
|
4691
|
+
return {boundsTwice(a[0]), boundsTwice(a[1]), boundsTwice(a[2])};
|
|
4692
|
+
}
|
|
4693
|
+
inline BoundsVector boundsRotate(const Body& body, BoundsVector value) {
|
|
4633
4694
|
if (body.orientationX == 0.0 && body.orientationY == 0.0 && body.orientationZ == 0.0)
|
|
4634
4695
|
return boundsAdd(value, BoundsVector{});
|
|
4635
4696
|
const BoundsVector q{boundsPoint(body.orientationX), boundsPoint(body.orientationY), boundsPoint(body.orientationZ)};
|
|
4636
4697
|
const auto uv = boundsCross(q, value);
|
|
4637
4698
|
const auto uuv = boundsCross(q, uv);
|
|
4638
|
-
return boundsAdd(value, boundsAdd(boundsScale(uv,
|
|
4639
|
-
|
|
4699
|
+
return boundsAdd(value, boundsAdd(boundsScale(uv, boundsPointMultiply(2.0, body.orientationW)),
|
|
4700
|
+
boundsTwice(uuv)));
|
|
4640
4701
|
}
|
|
4641
|
-
BoundsVector boundsBox(double x, double y, double z) { return {{{-x, x}, {-y, y}, {-z, z}}}; }
|
|
4702
|
+
inline BoundsVector boundsBox(double x, double y, double z) { return {{{-x, x}, {-y, y}, {-z, z}}}; }
|
|
4642
4703
|
// This extent covers the exact linear image and the rounded corner rotation.
|
|
4643
4704
|
// The support reader has a separate operation order in nativePrimitiveBounds.
|
|
4644
4705
|
using NativeBoxQuaternionRows = std::array<BoundsVector, 3>;
|
|
4645
|
-
NativeBoxQuaternionRows nativeBoxQuaternionRows(const Body& body) {
|
|
4646
|
-
const auto
|
|
4647
|
-
const auto
|
|
4648
|
-
const auto
|
|
4649
|
-
const auto xy =
|
|
4650
|
-
const auto
|
|
4651
|
-
const auto
|
|
4706
|
+
inline NativeBoxQuaternionRows nativeBoxQuaternionRows(const Body& body) {
|
|
4707
|
+
const auto xx = boundsPointMultiply(body.orientationX, body.orientationX);
|
|
4708
|
+
const auto yy = boundsPointMultiply(body.orientationY, body.orientationY);
|
|
4709
|
+
const auto zz = boundsPointMultiply(body.orientationZ, body.orientationZ);
|
|
4710
|
+
const auto xy = boundsPointMultiply(body.orientationX, body.orientationY);
|
|
4711
|
+
const auto xz = boundsPointMultiply(body.orientationX, body.orientationZ);
|
|
4712
|
+
const auto yz = boundsPointMultiply(body.orientationY, body.orientationZ);
|
|
4713
|
+
const auto wx = boundsPointMultiply(body.orientationW, body.orientationX);
|
|
4714
|
+
const auto wy = boundsPointMultiply(body.orientationW, body.orientationY);
|
|
4715
|
+
const auto wz = boundsPointMultiply(body.orientationW, body.orientationZ);
|
|
4652
4716
|
const auto diagonal = [&](BoundsInterval a, BoundsInterval b) {
|
|
4653
|
-
return boundsSubtract(boundsPoint(1.0),
|
|
4717
|
+
return boundsSubtract(boundsPoint(1.0), boundsTwice(boundsAdd(a, b)));
|
|
4654
4718
|
};
|
|
4655
4719
|
return NativeBoxQuaternionRows{{
|
|
4656
|
-
{diagonal(yy, zz),
|
|
4657
|
-
{
|
|
4658
|
-
{
|
|
4720
|
+
{diagonal(yy, zz), boundsTwice(boundsSubtract(xy, wz)), boundsTwice(boundsAdd(xz, wy))},
|
|
4721
|
+
{boundsTwice(boundsAdd(xy, wz)), diagonal(xx, zz), boundsTwice(boundsSubtract(yz, wx))},
|
|
4722
|
+
{boundsTwice(boundsSubtract(xz, wy)), boundsTwice(boundsAdd(yz, wx)), diagonal(xx, yy)}
|
|
4659
4723
|
}};
|
|
4660
4724
|
}
|
|
4661
4725
|
|
|
@@ -4688,7 +4752,7 @@ struct NativeCompoundBoxCoefficients {
|
|
|
4688
4752
|
void invalidate() { valid = false; axesReady = false; }
|
|
4689
4753
|
};
|
|
4690
4754
|
|
|
4691
|
-
BoundsVector nativeBoxVertexExtent(const Body& body, NativeCompoundBoxCoefficients* reuse = nullptr) {
|
|
4755
|
+
inline BoundsVector nativeBoxVertexExtent(const Body& body, NativeCompoundBoxCoefficients* reuse = nullptr) {
|
|
4692
4756
|
const auto oldExtent = [&] {
|
|
4693
4757
|
if (reuse != nullptr) reuse->invalidate();
|
|
4694
4758
|
return boundsRotate(body, boundsBox(body.shape0, body.shape1, body.shape2));
|
|
@@ -4701,14 +4765,14 @@ BoundsVector nativeBoxVertexExtent(const Body& body, NativeCompoundBoxCoefficien
|
|
|
4701
4765
|
const auto fromRows = [&](const NativeBoxQuaternionRows& rows) {
|
|
4702
4766
|
// u = 2^-53 and eta = 2^-1074. The no-FMA DAG error is below
|
|
4703
4767
|
// 128*u*h + 64*eta, including gradual underflow.
|
|
4704
|
-
const auto error = boundsAdd(
|
|
4768
|
+
const auto error = boundsAdd(boundsPointMultiply(h, 0x1p-46), boundsPoint(0x1p-1068));
|
|
4705
4769
|
const double half[]{body.shape0, body.shape1, body.shape2};
|
|
4706
4770
|
BoundsVector result;
|
|
4707
4771
|
for (unsigned i = 0; i < 3; ++i) {
|
|
4708
4772
|
auto extent = error;
|
|
4709
4773
|
for (unsigned j = 0; j < 3; ++j) {
|
|
4710
4774
|
const double magnitude = std::max(std::abs(rows[i][j].low), std::abs(rows[i][j].high));
|
|
4711
|
-
extent = boundsAdd(extent,
|
|
4775
|
+
extent = boundsAdd(extent, boundsPointMultiply(magnitude, half[j]));
|
|
4712
4776
|
}
|
|
4713
4777
|
result[i] = {-extent.high, extent.high};
|
|
4714
4778
|
}
|
|
@@ -4717,7 +4781,7 @@ BoundsVector nativeBoxVertexExtent(const Body& body, NativeCompoundBoxCoefficien
|
|
|
4717
4781
|
if (reuse != nullptr) return fromRows(reuse->readRows(body));
|
|
4718
4782
|
return fromRows(nativeBoxQuaternionRows(body));
|
|
4719
4783
|
}
|
|
4720
|
-
BoundsVector nativePrimitiveExtent(const Body& body, NativeCompoundBoxCoefficients* reuse = nullptr) {
|
|
4784
|
+
inline BoundsVector nativePrimitiveExtent(const Body& body, NativeCompoundBoxCoefficients* reuse = nullptr) {
|
|
4721
4785
|
if (body.shape == ShapeKind::Box) return nativeBoxVertexExtent(body, reuse);
|
|
4722
4786
|
if (body.shape == ShapeKind::Sphere) return boundsBox(body.shape0, body.shape0, body.shape0);
|
|
4723
4787
|
if (body.shape == ShapeKind::Capsule || body.shape == ShapeKind::Cylinder
|
|
@@ -4730,7 +4794,7 @@ BoundsVector nativePrimitiveExtent(const Body& body, NativeCompoundBoxCoefficien
|
|
|
4730
4794
|
const std::array<double, 3> components{axis.x, axis.y, axis.z};
|
|
4731
4795
|
BoundsVector result;
|
|
4732
4796
|
for (unsigned i = 0; i < 3; ++i) {
|
|
4733
|
-
const auto extent = boundsAdd(boundsPoint(radius),
|
|
4797
|
+
const auto extent = boundsAdd(boundsPoint(radius), boundsPointMultiply(std::abs(components[i]), body.shape1));
|
|
4734
4798
|
result[i] = {-extent.high, extent.high};
|
|
4735
4799
|
}
|
|
4736
4800
|
return result;
|
|
@@ -4738,7 +4802,7 @@ BoundsVector nativePrimitiveExtent(const Body& body, NativeCompoundBoxCoefficien
|
|
|
4738
4802
|
return boundsRotate(body, boundsBox(body.shape0, body.shape1, body.shape2));
|
|
4739
4803
|
}
|
|
4740
4804
|
// Enclose each support accumulation in its actual world-coordinate order.
|
|
4741
|
-
BoundsVector nativePrimitiveBounds(const Body& body, BoundsVector center, BoundsVector extent,
|
|
4805
|
+
inline BoundsVector nativePrimitiveBounds(const Body& body, BoundsVector center, BoundsVector extent,
|
|
4742
4806
|
NativeCompoundBoxCoefficients* reuse = nullptr) {
|
|
4743
4807
|
auto result = boundsAdd(center, extent);
|
|
4744
4808
|
if (body.shape != ShapeKind::Box
|
|
@@ -4754,7 +4818,7 @@ BoundsVector nativePrimitiveBounds(const Body& body, BoundsVector center, Bounds
|
|
|
4754
4818
|
if (reuseAxes && !reuse->axesReady) reuse->axes[axis] = value;
|
|
4755
4819
|
const double components[]{value.x, value.y, value.z};
|
|
4756
4820
|
for (unsigned i = 0; i < 3; ++i)
|
|
4757
|
-
support[i] = boundsAdd(support[i],
|
|
4821
|
+
support[i] = boundsAdd(support[i], boundsSymmetricMultiply(components[i], half[axis]));
|
|
4758
4822
|
}
|
|
4759
4823
|
for (unsigned i = 0; i < 3; ++i) {
|
|
4760
4824
|
result[i].low = std::min({result[i].low, projectedVertices[i].low, support[i].low});
|
|
@@ -4769,8 +4833,10 @@ std::optional<std::array<double, 6>> nativeBoundsChartKey(SolverOperation& opera
|
|
|
4769
4833
|
return std::array<double, 6>{chart->anchor[0], chart->anchor[1], chart->anchor[2],
|
|
4770
4834
|
chart->displacement[0], chart->displacement[1], chart->displacement[2]};
|
|
4771
4835
|
}
|
|
4772
|
-
BroadphaseBounds nativeChartBounds(SolverOperation& operation, const Body& body
|
|
4773
|
-
|
|
4836
|
+
BroadphaseBounds nativeChartBounds(SolverOperation& operation, const Body& body,
|
|
4837
|
+
const NativeTickChart* chart = nullptr,
|
|
4838
|
+
NativeCompoundBoxCoefficients* boxCoefficients = nullptr) {
|
|
4839
|
+
if (chart == nullptr) chart = nativeTickChartFor(operation, body);
|
|
4774
4840
|
BoundsVector center{boundsPoint(body.x), boundsPoint(body.y), boundsPoint(body.z)};
|
|
4775
4841
|
if (chart != nullptr) {
|
|
4776
4842
|
for (unsigned i = 0; i < 3; ++i) center[i] = boundsAdd(boundsPoint(chart->anchor[i]), boundsPoint(chart->displacement[i]));
|
|
@@ -4778,7 +4844,9 @@ BroadphaseBounds nativeChartBounds(SolverOperation& operation, const Body& body)
|
|
|
4778
4844
|
center = boundsAdd(center, {boundsPoint(body.shapeOffsetX), boundsPoint(body.shapeOffsetY), boundsPoint(body.shapeOffsetZ)});
|
|
4779
4845
|
BoundsVector result;
|
|
4780
4846
|
if (!isGeometryShape(body.shape)) {
|
|
4781
|
-
|
|
4847
|
+
NativeCompoundBoxCoefficients localCoefficients;
|
|
4848
|
+
auto* coeff = boxCoefficients != nullptr ? boxCoefficients : &localCoefficients;
|
|
4849
|
+
result = nativePrimitiveBounds(body, center, nativePrimitiveExtent(body, coeff), coeff);
|
|
4782
4850
|
} else if (body.shape == ShapeKind::Compound && body.geometryFormat >= 4 && body.geometryFormat <= 6) {
|
|
4783
4851
|
const auto values = geometryForBody(operation, body);
|
|
4784
4852
|
const unsigned count = compoundChildCount(operation, body);
|
|
@@ -4851,8 +4919,10 @@ BroadphaseBounds nativeChartBounds(SolverOperation& operation, const Body& body)
|
|
|
4851
4919
|
return {result[0].low, result[1].low, result[2].low, result[0].high, result[1].high, result[2].high};
|
|
4852
4920
|
}
|
|
4853
4921
|
|
|
4854
|
-
BroadphaseBounds bodyBounds(SolverOperation& operation, const Body& body
|
|
4855
|
-
|
|
4922
|
+
BroadphaseBounds bodyBounds(SolverOperation& operation, const Body& body,
|
|
4923
|
+
const NativeTickChart* chart = nullptr,
|
|
4924
|
+
NativeCompoundBoxCoefficients* boxCoefficients = nullptr) {
|
|
4925
|
+
if (!operation.tickCharts.empty()) return nativeChartBounds(operation, body, chart, boxCoefficients);
|
|
4856
4926
|
if (body.shape == ShapeKind::Box) {
|
|
4857
4927
|
return orientedBounds(body, {0.0, 0.0, 0.0}, {body.shape0, body.shape1, body.shape2});
|
|
4858
4928
|
}
|
|
@@ -4900,7 +4970,8 @@ BroadphaseBounds bodyBounds(SolverOperation& operation, const Body& body) {
|
|
|
4900
4970
|
(geometry.maxZ - geometry.minZ) / 2.0});
|
|
4901
4971
|
}
|
|
4902
4972
|
|
|
4903
|
-
BroadphaseBounds queryProxyBounds(SolverOperation& operation, const Body& body
|
|
4973
|
+
BroadphaseBounds queryProxyBounds(SolverOperation& operation, const Body& body,
|
|
4974
|
+
NativeCompoundBoxCoefficients* boxCoefficients = nullptr);
|
|
4904
4975
|
|
|
4905
4976
|
bool boundsOverlap(const BroadphaseBounds& left, const BroadphaseBounds& right) {
|
|
4906
4977
|
return left.minX <= right.maxX && right.minX <= left.maxX
|
|
@@ -4990,7 +5061,20 @@ std::optional<std::size_t> denseBodyIndex(const SolverOperation& operation, cons
|
|
|
4990
5061
|
return offset / sizeof(Body);
|
|
4991
5062
|
}
|
|
4992
5063
|
|
|
4993
|
-
|
|
5064
|
+
inline const NativeTickChart* nativeTickChartAt(const SolverOperation& operation, std::uint32_t index) {
|
|
5065
|
+
if (index >= operation.tickCharts.size()) return nullptr;
|
|
5066
|
+
return &operation.tickCharts[index];
|
|
5067
|
+
}
|
|
5068
|
+
|
|
5069
|
+
inline std::optional<std::array<double, 6>> nativeBoundsChartKeyAt(const SolverOperation& operation, std::uint32_t index) {
|
|
5070
|
+
const auto* chart = nativeTickChartAt(operation, index);
|
|
5071
|
+
if (chart == nullptr) return std::nullopt;
|
|
5072
|
+
return std::array<double, 6>{chart->anchor[0], chart->anchor[1], chart->anchor[2],
|
|
5073
|
+
chart->displacement[0], chart->displacement[1], chart->displacement[2]};
|
|
5074
|
+
}
|
|
5075
|
+
|
|
5076
|
+
bool matchingBodyBounds(const CachedBodyBoundsState& cache, SolverOperation& operation, const Body& b,
|
|
5077
|
+
const std::optional<std::array<double, 6>>& chart) {
|
|
4994
5078
|
if (!cache.valid) return false;
|
|
4995
5079
|
if (isGeometryShape(b.shape)) {
|
|
4996
5080
|
if (b.geometryRecord == nullptr || b.geometrySource != GeometryInputSource::OwnedRecord) return false;
|
|
@@ -5000,7 +5084,6 @@ bool matchingBodyBounds(const CachedBodyBoundsState& cache, SolverOperation& ope
|
|
|
5000
5084
|
|| b.geometryOffset != 0 || b.shape != descriptor.kind || b.geometryCount != descriptor.count
|
|
5001
5085
|
|| b.geometryFormat != descriptor.format || b.geometryFeatureOffset != descriptor.featureOffset) return false;
|
|
5002
5086
|
}
|
|
5003
|
-
const auto chart = nativeBoundsChartKey(operation, b);
|
|
5004
5087
|
const auto same = [](double a, double b) {
|
|
5005
5088
|
return std::bit_cast<std::uint64_t>(a) == std::bit_cast<std::uint64_t>(b);
|
|
5006
5089
|
};
|
|
@@ -5018,26 +5101,36 @@ bool matchingBodyBounds(const CachedBodyBoundsState& cache, SolverOperation& ope
|
|
|
5018
5101
|
&& cache.geometryCount == b.geometryCount && cache.geometryFormat == b.geometryFormat;
|
|
5019
5102
|
}
|
|
5020
5103
|
|
|
5104
|
+
inline bool matchingBodyBounds(const CachedBodyBoundsState& cache, SolverOperation& operation, const Body& b) {
|
|
5105
|
+
return matchingBodyBounds(cache, operation, b, nativeBoundsChartKey(operation, b));
|
|
5106
|
+
}
|
|
5107
|
+
|
|
5021
5108
|
class FixedDynamicAabbTree {
|
|
5022
5109
|
public:
|
|
5023
5110
|
const BroadphaseBounds* readBounds(SolverOperation& operation, const Body& body) const {
|
|
5024
5111
|
const auto index = denseBodyIndex(operation, body);
|
|
5025
|
-
if (!index || *index >= cachedBounds.size() || *index >= actualBounds.size()
|
|
5026
|
-
|
|
5112
|
+
if (!index || *index >= cachedBounds.size() || *index >= actualBounds.size()) return nullptr;
|
|
5113
|
+
const auto chart = nativeBoundsChartKeyAt(operation, static_cast<std::uint32_t>(*index));
|
|
5114
|
+
if (!matchingBodyBounds(cachedBounds[*index], operation, body, chart)) return nullptr;
|
|
5027
5115
|
return &actualBounds[*index];
|
|
5028
5116
|
}
|
|
5029
5117
|
|
|
5030
5118
|
const BroadphaseBounds& computeOrReadBounds(SolverOperation& operation, const Body& b, std::uint32_t index) {
|
|
5031
5119
|
CachedBodyBoundsState& cache = cachedBounds[index];
|
|
5032
|
-
const auto
|
|
5120
|
+
const auto* chartPtr = nativeTickChartAt(operation, index);
|
|
5121
|
+
const auto chart = chartPtr != nullptr ? std::optional<std::array<double, 6>>{{
|
|
5122
|
+
chartPtr->anchor[0], chartPtr->anchor[1], chartPtr->anchor[2],
|
|
5123
|
+
chartPtr->displacement[0], chartPtr->displacement[1], chartPtr->displacement[2]
|
|
5124
|
+
}} : std::nullopt;
|
|
5033
5125
|
const double x = chart ? (*chart)[0] : b.x;
|
|
5034
5126
|
const double y = chart ? (*chart)[1] : b.y;
|
|
5035
5127
|
const double z = chart ? (*chart)[2] : b.z;
|
|
5036
5128
|
const std::array<double, 3> displacement = chart
|
|
5037
5129
|
? std::array<double, 3>{(*chart)[3], (*chart)[4], (*chart)[5]} : std::array<double, 3>{};
|
|
5038
5130
|
const bool nonStatic = b.dynamic || b.kinematic;
|
|
5039
|
-
if (matchingBodyBounds(cache, operation, b)) return actualBounds[index];
|
|
5040
|
-
|
|
5131
|
+
if (matchingBodyBounds(cache, operation, b, chart)) return actualBounds[index];
|
|
5132
|
+
NativeCompoundBoxCoefficients* coeff = index < cachedCoefficients.size() ? &cachedCoefficients[index] : nullptr;
|
|
5133
|
+
const BroadphaseBounds actual = bodyBounds(operation, b, chartPtr, coeff);
|
|
5041
5134
|
actualBounds[index] = actual;
|
|
5042
5135
|
cache.charted = chart.has_value();
|
|
5043
5136
|
cache.displacement = displacement;
|
|
@@ -5067,6 +5160,7 @@ public:
|
|
|
5067
5160
|
void prepare(std::uint32_t count, std::span<std::uint32_t> first, std::span<std::uint32_t> second) {
|
|
5068
5161
|
if (actualBounds.size() < count) actualBounds.resize(count);
|
|
5069
5162
|
if (cachedBounds.size() < count) cachedBounds.resize(count);
|
|
5163
|
+
if (cachedCoefficients.size() < count) cachedCoefficients.resize(count);
|
|
5070
5164
|
if (queryMatches.size() < count) queryMatches.resize(count);
|
|
5071
5165
|
if (nodes.size() < static_cast<std::size_t>(count) * 2) nodes.resize(static_cast<std::size_t>(count) * 2);
|
|
5072
5166
|
if (leafNodes.size() < count) leafNodes.resize(count);
|
|
@@ -5088,6 +5182,9 @@ public:
|
|
|
5088
5182
|
for (std::uint32_t index = 0; index < count && index < cachedBounds.size(); ++index) {
|
|
5089
5183
|
cachedBounds[index].valid = false;
|
|
5090
5184
|
}
|
|
5185
|
+
for (std::uint32_t index = 0; index < count && index < cachedCoefficients.size(); ++index) {
|
|
5186
|
+
cachedCoefficients[index].invalidate();
|
|
5187
|
+
}
|
|
5091
5188
|
}
|
|
5092
5189
|
|
|
5093
5190
|
void rebuild(std::span<const BroadphaseBounds> bounds) {
|
|
@@ -5140,14 +5237,19 @@ public:
|
|
|
5140
5237
|
for (std::uint32_t index = 0; index < count; index += 1) {
|
|
5141
5238
|
const Body& b = bodies[index];
|
|
5142
5239
|
CachedBodyBoundsState& cache = cachedBounds[index];
|
|
5143
|
-
const auto
|
|
5240
|
+
const auto* chartPtr = nativeTickChartAt(operation, index);
|
|
5241
|
+
const auto chart = chartPtr != nullptr ? std::optional<std::array<double, 6>>{{
|
|
5242
|
+
chartPtr->anchor[0], chartPtr->anchor[1], chartPtr->anchor[2],
|
|
5243
|
+
chartPtr->displacement[0], chartPtr->displacement[1], chartPtr->displacement[2]
|
|
5244
|
+
}} : std::nullopt;
|
|
5144
5245
|
const double x = chart ? (*chart)[0] : b.x;
|
|
5145
5246
|
const double y = chart ? (*chart)[1] : b.y;
|
|
5146
5247
|
const double z = chart ? (*chart)[2] : b.z;
|
|
5147
5248
|
const std::array<double, 3> displacement = chart
|
|
5148
5249
|
? std::array<double, 3>{(*chart)[3], (*chart)[4], (*chart)[5]} : std::array<double, 3>{};
|
|
5149
|
-
if (matchingBodyBounds(cache, operation, b)) continue;
|
|
5150
|
-
|
|
5250
|
+
if (matchingBodyBounds(cache, operation, b, chart)) continue;
|
|
5251
|
+
NativeCompoundBoxCoefficients* coeff = index < cachedCoefficients.size() ? &cachedCoefficients[index] : nullptr;
|
|
5252
|
+
const BroadphaseBounds actual = bodyBounds(operation, b, chartPtr, coeff);
|
|
5151
5253
|
actualBounds[index] = actual;
|
|
5152
5254
|
cache.charted = chart.has_value();
|
|
5153
5255
|
cache.displacement = displacement;
|
|
@@ -5182,9 +5284,14 @@ public:
|
|
|
5182
5284
|
for (std::uint32_t index = 0; index < count; index += 1) {
|
|
5183
5285
|
const Body& b = bodies[index];
|
|
5184
5286
|
const bool nonStatic = b.dynamic || b.kinematic;
|
|
5185
|
-
const
|
|
5287
|
+
const auto* chartPtr = nativeTickChartAt(operation, index);
|
|
5288
|
+
NativeCompoundBoxCoefficients* coeff = index < cachedCoefficients.size() ? &cachedCoefficients[index] : nullptr;
|
|
5289
|
+
const BroadphaseBounds actual = bodyBounds(operation, b, chartPtr, coeff);
|
|
5186
5290
|
actualBounds[index] = actual;
|
|
5187
|
-
const auto chart =
|
|
5291
|
+
const auto chart = chartPtr != nullptr ? std::optional<std::array<double, 6>>{{
|
|
5292
|
+
chartPtr->anchor[0], chartPtr->anchor[1], chartPtr->anchor[2],
|
|
5293
|
+
chartPtr->displacement[0], chartPtr->displacement[1], chartPtr->displacement[2]
|
|
5294
|
+
}} : std::nullopt;
|
|
5188
5295
|
cachedBounds[index] = {
|
|
5189
5296
|
chart ? std::array<double, 3>{(*chart)[3], (*chart)[4], (*chart)[5]} : std::array<double, 3>{},
|
|
5190
5297
|
chart ? (*chart)[0] : b.x, chart ? (*chart)[1] : b.y, chart ? (*chart)[2] : b.z,
|
|
@@ -5618,6 +5725,7 @@ private:
|
|
|
5618
5725
|
|
|
5619
5726
|
std::vector<BroadphaseBounds> actualBounds;
|
|
5620
5727
|
std::vector<CachedBodyBoundsState> cachedBounds;
|
|
5728
|
+
std::vector<NativeCompoundBoxCoefficients> cachedCoefficients;
|
|
5621
5729
|
std::vector<std::uint32_t> queryMatches;
|
|
5622
5730
|
std::vector<DynamicAabbTreeNode> nodes;
|
|
5623
5731
|
std::vector<std::int32_t> leafNodes;
|
|
@@ -5741,6 +5849,8 @@ void SolverStorage::invalidate(bool keepBroadphaseTree) noexcept {
|
|
|
5741
5849
|
componentHasJoint.clear();
|
|
5742
5850
|
componentHasActive.clear();
|
|
5743
5851
|
contactSolvePairCount = 0;
|
|
5852
|
+
supportedSolvePairCount = 0;
|
|
5853
|
+
cylinderSolvePairCount = 0;
|
|
5744
5854
|
contactConstraintOverflow = false;
|
|
5745
5855
|
jointTelemetryCount = 0;
|
|
5746
5856
|
fluidInteractions.clear();
|
|
@@ -5809,6 +5919,8 @@ std::uint64_t SolverStorage::retainedBytes() const noexcept {
|
|
|
5809
5919
|
+ retainedVectorBytes(contactSolvePairEnd)
|
|
5810
5920
|
+ retainedVectorBytes(contactSolveTelemetryIndex)
|
|
5811
5921
|
+ retainedVectorBytes(contactSolveOutputIndex)
|
|
5922
|
+
+ retainedVectorBytes(supportedSolvePairs)
|
|
5923
|
+
+ retainedVectorBytes(cylinderSolvePairs)
|
|
5812
5924
|
+ retainedVectorBytes(queryHits)
|
|
5813
5925
|
+ retainedVectorBytes(queryResultData)
|
|
5814
5926
|
+ retainedVectorBytes(sleepPairFirst)
|
|
@@ -5867,6 +5979,8 @@ void growContactSolvePairs(SolverStorage& storage, std::uint32_t needed) {
|
|
|
5867
5979
|
growToCover(storage.contactSolvePairEnd, needed, limit);
|
|
5868
5980
|
growToCover(storage.contactSolveTelemetryIndex, needed, limit);
|
|
5869
5981
|
growToCover(storage.contactSolveOutputIndex, needed, limit);
|
|
5982
|
+
growToCover(storage.supportedSolvePairs, needed, limit);
|
|
5983
|
+
growToCover(storage.cylinderSolvePairs, needed, limit);
|
|
5870
5984
|
}
|
|
5871
5985
|
|
|
5872
5986
|
void growWorldContactOutput(SolverStorage& storage, std::uint32_t neededEntries) {
|
|
@@ -7333,9 +7447,10 @@ Collision collideFeatures(SolverOperation& operation, const Body& a, const Body&
|
|
|
7333
7447
|
Collision best;
|
|
7334
7448
|
std::int32_t bestChild = -1;
|
|
7335
7449
|
|
|
7450
|
+
NativeCompoundBoxCoefficients aBoxCoefficients;
|
|
7336
7451
|
for (std::uint32_t child = 0; child < aChildCount; child += 1) {
|
|
7337
7452
|
const Body childBody = compoundChildBody(operation, a, child);
|
|
7338
|
-
const BroadphaseBounds childBounds = queryProxyBounds(operation, childBody);
|
|
7453
|
+
const BroadphaseBounds childBounds = queryProxyBounds(operation, childBody, &aBoxCoefficients);
|
|
7339
7454
|
if (!boundsOverlap(childBounds, boundsB)) continue;
|
|
7340
7455
|
|
|
7341
7456
|
Collision candidate;
|
|
@@ -7345,9 +7460,10 @@ Collision collideFeatures(SolverOperation& operation, const Body& a, const Body&
|
|
|
7345
7460
|
&& !(childBody.shape == ShapeKind::Capsule && b.geometryFormat == 5)) {
|
|
7346
7461
|
if (!bChildrenMaterialized) {
|
|
7347
7462
|
if (bChildrenOnHeap) bHeapChildren.reserve(bChildCount);
|
|
7463
|
+
NativeCompoundBoxCoefficients bBoxCoefficients;
|
|
7348
7464
|
for (std::uint32_t childB = 0; childB < bChildCount; childB += 1) {
|
|
7349
7465
|
const Body childBodyB = compoundChildBody(operation, b, childB);
|
|
7350
|
-
const BroadphaseBounds childBoundsB = queryProxyBounds(operation, childBodyB);
|
|
7466
|
+
const BroadphaseBounds childBoundsB = queryProxyBounds(operation, childBodyB, &bBoxCoefficients);
|
|
7351
7467
|
const PrecomputedCompoundChild entry{childBodyB, childBoundsB, boundsOverlap(childBoundsB, boundsA)};
|
|
7352
7468
|
if (bChildrenOnHeap) bHeapChildren.push_back(entry);
|
|
7353
7469
|
else bStackChildren.push_back(entry);
|
|
@@ -11537,7 +11653,8 @@ RayHit rayGeometry(SolverOperation& operation, const Body& body, const Vec3& ori
|
|
|
11537
11653
|
return {};
|
|
11538
11654
|
}
|
|
11539
11655
|
|
|
11540
|
-
BroadphaseBounds queryProxyBounds(SolverOperation& operation, const Body& body
|
|
11656
|
+
BroadphaseBounds queryProxyBounds(SolverOperation& operation, const Body& body,
|
|
11657
|
+
NativeCompoundBoxCoefficients* boxCoefficients);
|
|
11541
11658
|
|
|
11542
11659
|
RayHit rayBody(SolverOperation& operation, const Body& body, const Vec3& origin, const Vec3& direction, double maxDistance) {
|
|
11543
11660
|
if (body.shape == ShapeKind::Sphere) return raySphere(body, origin, direction, maxDistance);
|
|
@@ -11646,13 +11763,15 @@ bool queryBodyAllowed(const Body& body, const double* queryData) {
|
|
|
11646
11763
|
return true;
|
|
11647
11764
|
}
|
|
11648
11765
|
|
|
11649
|
-
BroadphaseBounds readRawBodyBounds(SolverOperation& operation, const Body& body
|
|
11766
|
+
BroadphaseBounds readRawBodyBounds(SolverOperation& operation, const Body& body,
|
|
11767
|
+
NativeCompoundBoxCoefficients* boxCoefficients = nullptr) {
|
|
11650
11768
|
const auto* cached = operation.storage.broadphaseTree->readBounds(operation, body);
|
|
11651
|
-
return cached == nullptr ? bodyBounds(operation, body) : *cached;
|
|
11769
|
+
return cached == nullptr ? bodyBounds(operation, body, nullptr, boxCoefficients) : *cached;
|
|
11652
11770
|
}
|
|
11653
11771
|
|
|
11654
|
-
BroadphaseBounds queryProxyBounds(SolverOperation& operation, const Body& body
|
|
11655
|
-
|
|
11772
|
+
BroadphaseBounds queryProxyBounds(SolverOperation& operation, const Body& body,
|
|
11773
|
+
NativeCompoundBoxCoefficients* boxCoefficients) {
|
|
11774
|
+
BroadphaseBounds bounds = readRawBodyBounds(operation, body, boxCoefficients);
|
|
11656
11775
|
constexpr double minimumHalfExtent = 1e-9;
|
|
11657
11776
|
const auto expand = [](double& low, double& high) {
|
|
11658
11777
|
if (high - low < minimumHalfExtent * 2.0) {
|
|
@@ -12591,7 +12710,7 @@ PeriodicImageRange periodicImageRange(const PeriodicQueryShape& query, std::size
|
|
|
12591
12710
|
// outside fails and inside holds. Returns the holding image next to the boundary.
|
|
12592
12711
|
const auto boundary = [](std::int64_t outside, std::int64_t inside, const auto& holds) {
|
|
12593
12712
|
for (int step = 0; outside - inside != 1 && inside - outside != 1; step += 1) {
|
|
12594
|
-
if (step == kPeriodicSearchStepLimit)
|
|
12713
|
+
if (step == kPeriodicSearchStepLimit) failPeriodicQuery(PeriodicQueryStatus::ImageCountExceeded);
|
|
12595
12714
|
const std::int64_t low = std::min(outside, inside);
|
|
12596
12715
|
const std::int64_t middle = low + (std::max(outside, inside) - low) / 2;
|
|
12597
12716
|
(holds(middle) ? inside : outside) = middle;
|
|
@@ -12604,7 +12723,7 @@ PeriodicImageRange periodicImageRange(const PeriodicQueryShape& query, std::size
|
|
|
12604
12723
|
if (first > last) return {};
|
|
12605
12724
|
if (last - first + 1 > kPeriodicMaxImagesPerAxis) failPeriodicQuery(PeriodicQueryStatus::ImageCountExceeded);
|
|
12606
12725
|
if (first < std::numeric_limits<std::int32_t>::min() || last > std::numeric_limits<std::int32_t>::max()) {
|
|
12607
|
-
|
|
12726
|
+
failPeriodicQuery(PeriodicQueryStatus::ImageRangeExceedsInt32);
|
|
12608
12727
|
}
|
|
12609
12728
|
return {first, last};
|
|
12610
12729
|
}
|
|
@@ -14539,11 +14658,11 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
|
|
|
14539
14658
|
std::uint32_t constraintCount) {
|
|
14540
14659
|
auto begin = operation.storage.contactConstraints.begin();
|
|
14541
14660
|
auto end = begin + constraintCount;
|
|
14542
|
-
const auto found = std::lower_bound(begin, end,
|
|
14543
|
-
|
|
14544
|
-
|
|
14545
|
-
|
|
14546
|
-
return
|
|
14661
|
+
const auto found = std::lower_bound(begin, end, 0,
|
|
14662
|
+
[&](const ContactConstraintBlock& block, int) {
|
|
14663
|
+
if (block.bodyA != first) return block.bodyA < first;
|
|
14664
|
+
if (block.bodyB != second) return block.bodyB < second;
|
|
14665
|
+
return block.featureId < featureId;
|
|
14547
14666
|
});
|
|
14548
14667
|
return found != end && found->bodyA == first && found->bodyB == second
|
|
14549
14668
|
&& found->featureId == featureId
|
|
@@ -14558,10 +14677,11 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
|
|
|
14558
14677
|
const Vec3& point, std::uint32_t constraintCount) {
|
|
14559
14678
|
auto begin = operation.storage.contactConstraints.begin();
|
|
14560
14679
|
auto end = begin + constraintCount;
|
|
14561
|
-
auto found = std::lower_bound(begin, end,
|
|
14562
|
-
[](const ContactConstraintBlock& block,
|
|
14563
|
-
|
|
14564
|
-
|
|
14680
|
+
auto found = std::lower_bound(begin, end, 0,
|
|
14681
|
+
[&](const ContactConstraintBlock& block, int) {
|
|
14682
|
+
if (block.bodyA != first) return block.bodyA < first;
|
|
14683
|
+
if (block.bodyB != second) return block.bodyB < second;
|
|
14684
|
+
return block.featureId < 0u;
|
|
14565
14685
|
});
|
|
14566
14686
|
double bestDistanceSquared = std::numeric_limits<double>::infinity();
|
|
14567
14687
|
ContactConstraintBlock* best = nullptr;
|
|
@@ -15473,23 +15593,47 @@ void resolveSoAContacts(SolverOperation& operation, Body* bodies, std::uint32_t
|
|
|
15473
15593
|
// pairs of an earlier one, so the loop can stop there.
|
|
15474
15594
|
const auto solvePreparedCylinderConstraints = [&](std::uint32_t extra) {
|
|
15475
15595
|
const bool supportedPass = extra < supportedExtraVelocityIterations;
|
|
15476
|
-
|
|
15477
|
-
|
|
15478
|
-
|
|
15479
|
-
|
|
15480
|
-
|
|
15481
|
-
|
|
15482
|
-
|
|
15483
|
-
|
|
15484
|
-
operation.storage.
|
|
15485
|
-
|
|
15486
|
-
|
|
15487
|
-
|
|
15488
|
-
|
|
15489
|
-
|
|
15490
|
-
|
|
15596
|
+
if (extra == 0) {
|
|
15597
|
+
operation.storage.supportedSolvePairCount = 0;
|
|
15598
|
+
operation.storage.cylinderSolvePairCount = 0;
|
|
15599
|
+
growContactSolvePairs(operation.storage, operation.storage.contactSolvePairCount);
|
|
15600
|
+
propagateContactSupport();
|
|
15601
|
+
for (std::uint32_t order = operation.storage.contactSolvePairCount;
|
|
15602
|
+
order > 0; order -= 1) {
|
|
15603
|
+
const std::uint32_t begin = operation.storage.contactSolvePairBegin[order - 1];
|
|
15604
|
+
const std::uint32_t end = operation.storage.contactSolvePairEnd[order - 1];
|
|
15605
|
+
if (begin == end) continue;
|
|
15606
|
+
const ContactConstraintBlock& firstConstraint =
|
|
15607
|
+
operation.storage.contactConstraints[begin];
|
|
15608
|
+
const std::uint32_t first = firstConstraint.bodyA;
|
|
15609
|
+
const std::uint32_t second = firstConstraint.bodyB;
|
|
15610
|
+
const bool isCylinder = bodies[first].shape == ShapeKind::Cylinder
|
|
15611
|
+
|| bodies[second].shape == ShapeKind::Cylinder;
|
|
15612
|
+
if (isCylinder) {
|
|
15613
|
+
operation.storage.cylinderSolvePairs[operation.storage.cylinderSolvePairCount++] =
|
|
15614
|
+
{first, second, begin, end};
|
|
15615
|
+
operation.storage.supportedSolvePairs[operation.storage.supportedSolvePairCount++] =
|
|
15616
|
+
{first, second, begin, end};
|
|
15617
|
+
} else if (isSupportPair(first, second)) {
|
|
15618
|
+
operation.storage.supportedSolvePairs[operation.storage.supportedSolvePairCount++] =
|
|
15619
|
+
{first, second, begin, end};
|
|
15620
|
+
}
|
|
15621
|
+
}
|
|
15491
15622
|
}
|
|
15492
|
-
|
|
15623
|
+
if (supportedPass) {
|
|
15624
|
+
if (operation.storage.supportedSolvePairCount == 0) return false;
|
|
15625
|
+
for (std::uint32_t i = 0; i < operation.storage.supportedSolvePairCount; ++i) {
|
|
15626
|
+
const auto& pair = operation.storage.supportedSolvePairs[i];
|
|
15627
|
+
solvePair(pair.first, pair.second, false, pair.begin, pair.end);
|
|
15628
|
+
}
|
|
15629
|
+
return true;
|
|
15630
|
+
}
|
|
15631
|
+
if (operation.storage.cylinderSolvePairCount == 0) return false;
|
|
15632
|
+
for (std::uint32_t i = 0; i < operation.storage.cylinderSolvePairCount; ++i) {
|
|
15633
|
+
const auto& pair = operation.storage.cylinderSolvePairs[i];
|
|
15634
|
+
solvePair(pair.first, pair.second, false, pair.begin, pair.end);
|
|
15635
|
+
}
|
|
15636
|
+
return true;
|
|
15493
15637
|
};
|
|
15494
15638
|
// In tree mode (N >= 256) the collecting iteration solves the contacts with a static or kinematic
|
|
15495
15639
|
// body first, then the contacts between dynamic bodies, each group in broadphase order; later
|
|
@@ -29253,6 +29397,8 @@ PeriodicQueryStatus periodicQuerySoA(
|
|
|
29253
29397
|
return failed(static_cast<PeriodicQueryStatus>(triangleFailureCode(failure.reason)));
|
|
29254
29398
|
} catch (const std::bad_alloc&) {
|
|
29255
29399
|
return failed(PeriodicQueryStatus::CountLimit);
|
|
29400
|
+
} catch (const std::exception&) {
|
|
29401
|
+
return failed(PeriodicQueryStatus::ImageCountExceeded);
|
|
29256
29402
|
}
|
|
29257
29403
|
}
|
|
29258
29404
|
|