载入中...
搜索中...
未找到
World3D.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Snapshot.h"
6#include "common/Result.h"
10
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <unordered_map>
15#include <unordered_set>
16#include <utility>
17#include <vector>
18
19#include <box3d/id.h>
20#include <box3d/types.h>
21
22namespace eve::physics {
23
24namespace action_adapter {
25class ActionCollisionIgnoreState;
26}
27
28class Body3D;
29class Shape3D;
30class Joint3D;
31class Mechanism3D;
34 bool hit = false;
35 int bodyId = -1;
36 float fraction = 1.f;
37 float x = 0.f, y = 0.f, z = 0.f;
38 float nx = 0.f, ny = 0.f, nz = 0.f;
39};
40
46 bool hit = false;
47 float nx = 0.f;
48 float ny = 0.f;
49 float nz = 0.f;
50 float depth = 0.f; // radius - distance (meters); > 0 when inside
51 Body3D *body = nullptr;
52 float friction = 0.f;
53 float restitution = 0.f;
54};
55
57enum class ClothProbeStatus { Miss, Hit };
58
64public:
66 struct EventShape {
67 int bodyId = 0;
68 int shapeId = 0;
69 int shapeTag = 0;
70 };
71
77
83
85 struct HitEvent {
88 float pointX = 0.f, pointY = 0.f, pointZ = 0.f;
89 float normalX = 0.f, normalY = 0.f, normalZ = 0.f;
90 float approachSpeed = 0.f;
91 float normalImpulse = 0.f;
92 };
95 int jointId = 0;
96 int bodyAId = 0;
97 int bodyBId = 0;
98 int kind = 0;
99 float forceX = 0.f, forceY = 0.f, forceZ = 0.f;
100 float torqueX = 0.f, torqueY = 0.f, torqueZ = 0.f;
101 };
110 World3D(float gravityX, float gravityY, float gravityZ, bool sleep,
112 ~World3D();
113
114 World3D(const World3D &) = delete;
115 World3D &operator=(const World3D &) = delete;
116
118 void update(float dt);
120 void updateFull(float dt, int subStepCount);
121
129 [[nodiscard("check the physics step outcome or explicitly ignore it")]]
131
133 [[nodiscard]] SimulationObservation simulationObservation() const noexcept;
135 [[nodiscard]] SimulationBackendKind backendKind() const noexcept;
137 [[nodiscard]] SimulationDeterminism backendDeterminism() const noexcept;
139 [[nodiscard]] eve::SimulationTick simulationTick() const noexcept { return simulationTick_; }
141 [[nodiscard]] PhysicsWorldHandle runtimeHandle() const noexcept { return runtimeHandle_; }
150 [[nodiscard]] std::weak_ptr<const void> lifetimeToken() const noexcept { return queryLifetime_; }
152 [[nodiscard]] eve::PersistentId persistentId() const noexcept { return instanceId_; }
156 [[nodiscard]] static World3D* findWorld(PhysicsWorldHandle handle) noexcept;
158 [[nodiscard]] bool usedBackendFallback() const noexcept { return backendFallback_; }
160 [[nodiscard("inspect backend selection diagnostics")]]
161 eve::Status backendSelectionStatus() const;
162
169 [[nodiscard("check or persist the physics snapshot")]]
170 eve::Result<eve::SnapshotEnvelope> snapshot(const eve::SnapshotHashProvider &hashProvider) const;
171
182 [[nodiscard("check the physics snapshot restore outcome")]]
183 eve::Result<void> restore(const eve::SnapshotEnvelope &snapshot, const eve::SnapshotHashProvider &hashProvider);
184
186 void setGravity(float gx, float gy, float gz);
187 float getGravityX() const;
188 float getGravityY() const;
189 float getGravityZ() const;
191 void setContinuousCollisionEnabled(bool enabled);
193 bool isContinuousCollisionEnabled() const;
195 void setRestitutionThreshold(float speed);
197 float getRestitutionThreshold() const;
199 void setHitEventThreshold(float speed);
201 float getHitEventThreshold() const;
203 void setBodyPairCollisionEnabled(Body3D *bodyA, Body3D *bodyB, bool enabled);
205 bool isBodyPairCollisionEnabled(Body3D *bodyA, Body3D *bodyB) const;
207 void setShapePairCollisionEnabled(Shape3D *shapeA, Shape3D *shapeB, bool enabled);
209 bool isShapePairCollisionEnabled(Shape3D *shapeA, Shape3D *shapeB) const;
216 void setContactTuning(float hertz, float dampingRatio, float pushOutSpeed);
218 float getContactHertz() const { return contactHertz_; }
220 float getContactDampingRatio() const { return contactDampingRatio_; }
222 float getContactPushOutSpeed() const { return contactPushOutSpeed_; }
224 void setContactRecycleDistance(float distance);
226 float getContactRecycleDistance() const;
228 void setMaximumLinearSpeed(float speed);
230 float getMaximumLinearSpeed() const;
232 void setWarmStartingEnabled(bool enabled);
234 bool isWarmStartingEnabled() const;
246 int explode(float x, float y, float z, float radius, float falloff,
247 float impulsePerArea, int maskBits = -1);
249 int getExplosionResultCount() const { return static_cast<int>(explosionResults_.size()); }
265 float getBoundsMinX() const;
267 float getBoundsMinY() const;
269 float getBoundsMinZ() const;
271 float getBoundsMaxX() const;
273 float getBoundsMaxY() const;
275 float getBoundsMaxZ() const;
277 int getBodyCount() const;
279 int getShapeCount() const;
281 int getContactCount() const;
283 int getJointCount() const;
285 int getIslandCount() const;
287 int getAwakeBodyCount() const;
299 float getProfileStepMs() const;
301 float getProfilePairsMs() const;
303 float getProfileCollideMs() const;
305 float getProfileSolveMs() const;
307 float getProfileBulletsMs() const;
309 float getProfileSensorsMs() const;
310
320 Body3D *newBody(const std::string &bodyType, float x, float y, float z);
322 [[nodiscard]] Body3D *findBody(PhysicsBodyHandle handle) const;
324 [[nodiscard]] Body3D *findBodyById(int bodyId) const;
326 [[nodiscard]] Shape3D *findShape(PhysicsShapeHandle handle) const;
328 [[nodiscard]] Shape3D *findShapeById(int shapeId) const;
330 [[nodiscard]] Joint3D *findJoint(PhysicsJointHandle handle) const;
341 Joint3D *newDistanceJoint(Body3D *bodyA, Body3D *bodyB, float anchorAX, float anchorAY,
342 float anchorAZ, float anchorBX, float anchorBY, float anchorBZ,
343 float length, bool collideConnected = false);
354 Joint3D *newRevoluteJoint(Body3D *bodyA, Body3D *bodyB, float anchorX, float anchorY,
355 float anchorZ, float axisX, float axisY, float axisZ,
356 bool collideConnected = false);
366 Joint3D *newPrismaticJoint(Body3D *bodyA, Body3D *bodyB, float anchorX, float anchorY,
367 float anchorZ, float axisX, float axisY, float axisZ,
368 bool collideConnected = false);
378 Joint3D *newSphericalJoint(Body3D *bodyA, Body3D *bodyB, float anchorX, float anchorY,
379 float anchorZ, float axisX, float axisY, float axisZ,
380 bool collideConnected = false);
390 Joint3D *newWheelJoint(Body3D *bodyA, Body3D *bodyB, float anchorX, float anchorY,
391 float anchorZ, float suspensionAxisX, float suspensionAxisY,
392 float suspensionAxisZ, float wheelAxisX, float wheelAxisY,
393 float wheelAxisZ, bool collideConnected = false);
404 Joint3D *newWeldJoint(Body3D *bodyA, Body3D *bodyB, float anchorX, float anchorY,
405 float anchorZ, bool collideConnected = false);
416 Joint3D *newMotorJoint(Body3D *bodyA, Body3D *bodyB, bool collideConnected = false);
427 Joint3D *newParallelJoint(Body3D *bodyA, Body3D *bodyB, float axisX, float axisY, float axisZ,
428 bool collideConnected = false);
439 Joint3D *newFilterJoint(Body3D *bodyA, Body3D *bodyB);
440
449 Mechanism3D *newShaft(Body3D *support, Body3D *rotor, float anchorX, float anchorY,
450 float anchorZ, float axisX, float axisY, float axisZ,
451 bool collideConnected = false);
462 Mechanism3D *newRatchet(Body3D *frame, Body3D *wheel, float anchorX, float anchorY,
463 float anchorZ, float axisX, float axisY, float axisZ, int direction,
464 float engagementTorque, bool collideConnected = false);
474 Mechanism3D *newCrankSlider(Body3D *frame, Body3D *crank, Body3D *rod, Body3D *slider,
475 float crankAnchorX, float crankAnchorY, float crankAnchorZ,
476 float axisX, float axisY, float axisZ, float crankPinX,
477 float crankPinY, float crankPinZ, float sliderPinX,
478 float sliderPinY, float sliderPinZ, float slideAxisX,
479 float slideAxisY, float slideAxisZ, bool collideConnected = false);
480
482 void destroyBody(Body3D *body);
484 void destroy();
485
490 int rayCast(float x1, float y1, float z1, float x2, float y2, float z2);
492 int rayCastFiltered(float x1, float y1, float z1, float x2, float y2, float z2,
493 uint64_t maskBits);
503 [[nodiscard]] eve::Result<RayHit3D> rayCastOwned(float x1, float y1, float z1, float x2,
504 float y2, float z2, QueryFilter3D filter = {});
506 bool sphereCast(float x1, float y1, float z1, float x2, float y2, float z2,
507 float radius, uint64_t maskBits, int ignoredBodyId,
508 CameraSphereHit3D* out) const;
513 int rayCastAll(float x1, float y1, float z1, float x2, float y2, float z2, int maxHits);
514 bool hasRayHit() const { return rayHitBodyId_ >= 0; }
515 int getRayHitBodyId() const { return rayHitBodyId_; }
517 int getRayHitShapeId() const { return rayHitShapeId_; }
519 int getRayHitShapeTag() const { return rayHitShapeTag_; }
521 int getRayHitMaterialId() const { return rayHitMaterialId_; }
523 int getRayHitTriangleIndex() const { return rayHitTriangleIndex_; }
524 float getRayHitX() const { return rayHitX_; }
525 float getRayHitY() const { return rayHitY_; }
526 float getRayHitZ() const { return rayHitZ_; }
527 float getRayHitNormalX() const { return rayHitNormalX_; }
528 float getRayHitNormalY() const { return rayHitNormalY_; }
529 float getRayHitNormalZ() const { return rayHitNormalZ_; }
530 float getRayHitFraction() const { return rayHitFraction_; }
532 int getRayResultCount() const { return static_cast<int>(rayResults_.size()); }
534 int getRayResultBodyId(int index) const;
544 float getRayResultX(int index) const;
546 float getRayResultY(int index) const;
548 float getRayResultZ(int index) const;
550 float getRayResultNormalX(int index) const;
552 float getRayResultNormalY(int index) const;
554 float getRayResultNormalZ(int index) const;
556 float getRayResultFraction(int index) const;
557
562 int queryAABB(float minX, float minY, float minZ, float maxX, float maxY, float maxZ);
570 [[nodiscard]] eve::Result<BroadPhaseAabb3D> queryAabbBroadPhaseOwned(
571 float minX, float minY, float minZ, float maxX, float maxY, float maxZ,
572 QueryFilter3D filter = {});
573
582 int querySphere(float x, float y, float z, float radius);
583
589 int queryCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius);
597 [[nodiscard]] eve::Result<CapsuleOverlap3D> queryCapsuleOwned(
598 float ax, float ay, float az, float bx, float by, float bz, float radius,
599 QueryFilter3D filter = {});
600
612 int queryBox(float x, float y, float z, float width, float height, float depth, float qx,
613 float qy, float qz, float qw);
614
621 int castSphere(float x, float y, float z, float radius, float dx, float dy, float dz);
623 int castSphereAll(float x, float y, float z, float radius, float dx, float dy, float dz,
624 int maxHits);
625
631 int castCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius,
632 float dx, float dy, float dz);
634 int castCapsuleAll(float ax, float ay, float az, float bx, float by, float bz, float radius,
635 float dx, float dy, float dz, int maxHits);
636
641 int castBox(float x, float y, float z, float width, float height, float depth, float qx,
642 float qy, float qz, float qw, float dx, float dy, float dz);
644 int castBoxAll(float x, float y, float z, float width, float height, float depth, float qx,
645 float qy, float qz, float qw, float dx, float dy, float dz, int maxHits);
646
653 int closestPoint(float x, float y, float z, float maxDistance);
655 bool hasClosestPoint() const { return closestBodyId_ >= 0; }
657 int getClosestBodyId() const { return closestBodyId_; }
659 int getClosestShapeId() const { return closestShapeId_; }
661 int getClosestShapeTag() const { return closestShapeTag_; }
663 float getClosestX() const { return closestX_; }
665 float getClosestY() const { return closestY_; }
667 float getClosestZ() const { return closestZ_; }
669 float getClosestNormalX() const { return closestNormalX_; }
671 float getClosestNormalY() const { return closestNormalY_; }
673 float getClosestNormalZ() const { return closestNormalZ_; }
675 float getClosestDistance() const { return closestDistance_; }
676
678 bool hasShapeCastHit() const { return shapeCastBodyId_ >= 0; }
680 int getShapeCastBodyId() const { return shapeCastBodyId_; }
682 int getShapeCastShapeId() const { return shapeCastShapeId_; }
684 int getShapeCastShapeTag() const { return shapeCastShapeTag_; }
686 int getShapeCastMaterialId() const { return shapeCastMaterialId_; }
688 int getShapeCastTriangleIndex() const { return shapeCastTriangleIndex_; }
690 float getShapeCastX() const { return shapeCastX_; }
692 float getShapeCastY() const { return shapeCastY_; }
694 float getShapeCastZ() const { return shapeCastZ_; }
696 float getShapeCastNormalX() const { return shapeCastNormalX_; }
698 float getShapeCastNormalY() const { return shapeCastNormalY_; }
700 float getShapeCastNormalZ() const { return shapeCastNormalZ_; }
702 float getShapeCastFraction() const { return shapeCastFraction_; }
704 int getShapeCastResultCount() const { return static_cast<int>(shapeCastResults_.size()); }
716 float getShapeCastResultX(int index) const;
718 float getShapeCastResultY(int index) const;
720 float getShapeCastResultZ(int index) const;
729
735 bool moveCapsule(float ax, float ay, float az, float bx, float by, float bz, float radius,
736 float dx, float dy, float dz);
745 [[nodiscard]] eve::Result<CapsuleMove3D> moveCapsuleOwned(
746 float ax, float ay, float az, float bx, float by, float bz, float radius, float dx,
747 float dy, float dz, QueryFilter3D filter = {}, CapsuleMovePolicy3D policy = {});
749 float getMoverDeltaX() const { return moverDeltaX_; }
751 float getMoverDeltaY() const { return moverDeltaY_; }
753 float getMoverDeltaZ() const { return moverDeltaZ_; }
755 float getMoverNormalX() const { return moverNormalX_; }
757 float getMoverNormalY() const { return moverNormalY_; }
759 float getMoverNormalZ() const { return moverNormalZ_; }
761 int getMoverPlaneCount() const { return moverPlaneCount_; }
763 int getMoverIterations() const { return moverIterations_; }
765 void setMoverUp(float x, float y, float z);
767 void setMoverSlopeLimit(float degrees);
769 bool isMoverGrounded() const { return moverGrounded_; }
771 float getMoverGroundDot() const { return moverGroundDot_; }
772
774 int getQueryCount() const { return static_cast<int>(queryBodyIds_.size()); }
776 int getQueryBodyId(int index) const;
778 int getQueryShapeCount() const { return static_cast<int>(queryShapes_.size()); }
780 int getQueryShapeId(int index) const;
782 int getQueryShapeTag(int index) const;
783
785 int getBeginContactCount() const { return static_cast<int>(beginContacts_.size()); }
799 int getEndContactCount() const { return static_cast<int>(endContacts_.size()); }
812
814 int getBeginTriggerCount() const { return static_cast<int>(beginTriggers_.size()); }
828 int getEndTriggerCount() const { return static_cast<int>(endTriggers_.size()); }
842 void clearContactEvents();
843
850 int queryBodyContacts(int bodyId, int maxPoints);
852 int getContactPointCount() const { return static_cast<int>(contactPoints_.size()); }
864 float getContactPointX(int index) const;
866 float getContactPointY(int index) const;
868 float getContactPointZ(int index) const;
884 bool isContactPointPersisted(int index) const;
885
887 int getHitCount() const { return static_cast<int>(hits_.size()); }
889 int getHitBodyAId(int index) const;
891 int getHitBodyBId(int index) const;
893 int getHitShapeAId(int index) const;
895 int getHitShapeBId(int index) const;
897 int getHitShapeATag(int index) const;
899 int getHitShapeBTag(int index) const;
901 float getHitPointX(int index) const;
903 float getHitPointY(int index) const;
905 float getHitPointZ(int index) const;
907 float getHitNormalX(int index) const;
909 float getHitNormalY(int index) const;
911 float getHitNormalZ(int index) const;
913 float getHitApproachSpeed(int index) const;
915 float getHitNormalImpulse(int index) const;
917 int getJointStressCount() const { return static_cast<int>(jointStressEvents_.size()); }
925 int getJointStressKind(int index) const;
927 float getJointStressForceX(int index) const;
929 float getJointStressForceY(int index) const;
931 float getJointStressForceZ(int index) const;
933 float getJointStressTorqueX(int index) const;
935 float getJointStressTorqueY(int index) const;
937 float getJointStressTorqueZ(int index) const;
939 void setQueryFilter(int categoryBits, int maskBits);
941 void resetQueryFilter();
943 int getQueryCategoryBits() const { return static_cast<int>(queryCategoryBits_); }
945 int getQueryMaskBits() const { return static_cast<int>(queryMaskBits_); }
947 void setQueryIgnoredBodyId(int bodyId);
949 void setQueryIgnoredShapeId(int shapeId);
951 int getQueryIgnoredBodyId() const { return queryIgnoredBodyId_; }
953 int getQueryIgnoredShapeId() const { return queryIgnoredShapeId_; }
955 void clearQueryIgnores();
956
958 bool isValid() const;
959
964 bool pointProbe(float x, float y, float z, float radius, ClothContact3D *out) const;
966 [[nodiscard]] ClothProbeStatus pointProbeFiltered(float x, float y, float z, float radius, ClothContact3D *out,
967 uint64_t categoryBits, uint64_t maskBits) const;
969 b3WorldId raw() const { return worldId_; }
970
972 void forgetBody(Body3D *body);
973 void forgetShape(Shape3D *shape);
975 void forgetJoint(Joint3D *joint);
977 void forgetMechanism(Mechanism3D *mechanism);
979 void registerShapeHandle(Shape3D *shape);
981 void updateShapeTag(Shape3D *shape);
982
984 int nextBodyId();
986 PhysicsBodyHandle nextBodyRuntimeHandle();
988 PhysicsShapeHandle nextShapeRuntimeHandle();
990 PhysicsJointHandle nextJointRuntimeHandle();
992 int nextShapeId() { return nextShapeId_++; }
994 int nextJointId() { return nextJointId_++; }
996 int nextMechanismId();
997
999 void emitContactEvents();
1000
1001private:
1003 friend struct WorldSnapshotAccess;
1004 friend class Body3D;
1005 friend class Joint3D;
1006 friend class Mechanism3D;
1007 friend class Shape3D;
1010
1011 World3D(float gravityX, float gravityY, float gravityZ, bool sleep,
1012 eve::PersistentId instanceId, bool registerQueries);
1013
1014 b3WorldId worldId_{};
1015 std::unique_ptr<ISimulationBackend> simulation_;
1016 PhysicsWorldHandle runtimeHandle_ = PhysicsWorldHandle::invalid();
1018 std::shared_ptr<const void> queryLifetime_ = std::make_shared<int>(0);
1019 bool destroyed_ = false;
1020 int nextId_ = 1;
1021 int nextShapeId_ = 1;
1022 int nextJointId_ = 1;
1023 int nextMechanismId_ = 1;
1024 std::uint32_t nextBodyHandleIndex_ = 1u;
1025 std::uint32_t nextShapeHandleIndex_ = 1u;
1026 std::uint32_t nextJointHandleIndex_ = 1u;
1028 eve::Status backendSelectionStatus_ = eve::Status::success();
1029 bool backendFallback_ = false;
1030
1031 std::unordered_set<Body3D *> bodies_;
1032 std::unordered_set<Shape3D *> shapes_;
1033 std::unordered_set<Joint3D *> joints_;
1034 std::unordered_set<Mechanism3D *> mechanisms_;
1035 std::unordered_set<uint64_t> disabledBodyPairs_;
1036 std::unordered_set<uint64_t> disabledShapePairs_;
1037 std::unordered_map<uint64_t, EventShape> shapeRecords_;
1038 std::unordered_map<PhysicsShapeHandle, Shape3D *> shapeHandles_;
1039 std::unordered_map<uint64_t, PhysicsShapeHandle> shapeRawHandles_;
1040 std::unordered_map<PhysicsJointHandle, Joint3D *> jointHandles_;
1041 std::vector<ContactEvent> beginContacts_;
1042 std::vector<ContactEvent> endContacts_;
1043 std::vector<TriggerEvent> beginTriggers_;
1044 std::vector<TriggerEvent> endTriggers_;
1045 std::vector<HitEvent> hits_;
1046 std::vector<JointStressEvent> jointStressEvents_;
1047
1048 struct ContactPointResult {
1049 int shapeId = -1;
1050 int shapeTag = 0;
1051 int otherBodyId = -1;
1052 int otherShapeId = -1;
1053 int otherShapeTag = 0;
1054 uint32_t featureId = 0;
1055 float x = 0.f, y = 0.f, z = 0.f;
1056 float normalX = 0.f, normalY = 0.f, normalZ = 0.f;
1057 float separation = 0.f;
1058 float normalImpulse = 0.f;
1059 float totalNormalImpulse = 0.f;
1060 float normalVelocity = 0.f;
1061 bool persisted = false;
1062 };
1063 std::vector<ContactPointResult> contactPoints_;
1064 [[nodiscard]] eve::Result<void> prepareRuntimeHandleRefresh() const;
1065 void refreshRuntimeHandlesAfterRestore();
1066 void adoptPreparedTopology(World3D &prepared);
1067 const ContactPointResult &contactPointAt(int index, const char *operation) const;
1068 static bool preSolveCallback(b3ShapeId shapeIdA, b3ShapeId shapeIdB, b3Pos point,
1069 b3Vec3 normal, void *context);
1070 static bool customFilterCallback(b3ShapeId shapeIdA, b3ShapeId shapeIdB,
1071 void *context);
1072 void refreshContactFilter(Shape3D *shape);
1073 void removeCollisionOverridesForBody(int bodyId);
1074 void removeCollisionOverridesForShape(int shapeId);
1075
1076 EventShape eventShapeFrom(b3ShapeId shapeId) const;
1077 const ContactEvent &contactEventAt(const std::vector<ContactEvent> &events, int index,
1078 const char *operation) const;
1079 const TriggerEvent &triggerEventAt(const std::vector<TriggerEvent> &events, int index,
1080 const char *operation) const;
1081 const HitEvent &hitEventAt(int index, const char *operation) const;
1082 const JointStressEvent &jointStressEventAt(int index, const char *operation) const;
1083
1084 int rayHitBodyId_ = -1;
1085 int rayHitShapeId_ = -1;
1086 int rayHitShapeTag_ = 0;
1087 int rayHitMaterialId_ = 0;
1088 int rayHitTriangleIndex_ = -1;
1089 float rayHitX_ = 0.f;
1090 float rayHitY_ = 0.f;
1091 float rayHitZ_ = 0.f;
1092 float rayHitNormalX_ = 0.f;
1093 float rayHitNormalY_ = 0.f;
1094 float rayHitNormalZ_ = 0.f;
1095 float rayHitFraction_ = 0.f;
1096
1097 struct RayResult {
1098 int bodyId = -1;
1099 int shapeId = -1;
1100 int shapeTag = 0;
1101 int materialId = 0;
1102 int triangleIndex = -1;
1103 float x = 0.f, y = 0.f, z = 0.f;
1104 float normalX = 0.f, normalY = 0.f, normalZ = 0.f;
1105 float fraction = 0.f;
1106 };
1107 std::vector<RayResult> rayResults_;
1108 const RayResult &rayResultAt(int index, const char *operation) const;
1109
1110 std::vector<int> queryBodyIds_;
1111 std::vector<std::pair<int, int>> queryShapes_;
1112
1113 int overlapProxy(b3Pos origin, const b3ShapeProxy &proxy);
1114 int castProxyAll(b3Pos origin, const b3ShapeProxy &proxy, b3Vec3 translation, int maxHits);
1115 int rayCastAllInternal(float x1, float y1, float z1, float x2, float y2, float z2,
1116 int maxHits, b3QueryFilter filter);
1117 b3QueryFilter makeQueryFilter() const;
1118 bool shouldIgnoreQueryShape(b3ShapeId shapeId) const;
1119
1120 int shapeCastBodyId_ = -1;
1121 int shapeCastShapeId_ = -1;
1122 int shapeCastShapeTag_ = 0;
1123 int shapeCastMaterialId_ = 0;
1124 int shapeCastTriangleIndex_ = -1;
1125 float shapeCastX_ = 0.f, shapeCastY_ = 0.f, shapeCastZ_ = 0.f;
1126 float shapeCastNormalX_ = 0.f, shapeCastNormalY_ = 0.f, shapeCastNormalZ_ = 0.f;
1127 float shapeCastFraction_ = 0.f;
1128 struct ShapeCastResult {
1129 int bodyId = -1;
1130 int shapeId = -1;
1131 int shapeTag = 0;
1132 int materialId = 0;
1133 int triangleIndex = -1;
1134 float x = 0.f, y = 0.f, z = 0.f;
1135 float normalX = 0.f, normalY = 0.f, normalZ = 0.f;
1136 float fraction = 0.f;
1137 };
1138 std::vector<ShapeCastResult> shapeCastResults_;
1139 const ShapeCastResult &shapeCastResultAt(int index, const char *operation) const;
1140
1141 int closestBodyId_ = -1;
1142 int closestShapeId_ = -1;
1143 int closestShapeTag_ = 0;
1144 float closestX_ = 0.f, closestY_ = 0.f, closestZ_ = 0.f;
1145 float closestNormalX_ = 0.f, closestNormalY_ = 0.f, closestNormalZ_ = 0.f;
1146 float closestDistance_ = 0.f;
1147
1148 float moverDeltaX_ = 0.f, moverDeltaY_ = 0.f, moverDeltaZ_ = 0.f;
1149 float moverNormalX_ = 0.f, moverNormalY_ = 0.f, moverNormalZ_ = 0.f;
1150 int moverPlaneCount_ = 0;
1151 int moverIterations_ = 0;
1152 b3Vec3 moverUp_ = b3Vec3{0.f, 1.f, 0.f};
1153 float moverSlopeCos_ = 0.6427876f;
1154 float moverGroundDot_ = -1.f;
1155 bool moverGrounded_ = false;
1156
1157 float contactHertz_ = 30.f;
1158 float contactDampingRatio_ = 10.f;
1159 float contactPushOutSpeed_ = 3.f;
1160
1161 struct ExplosionResult {
1162 int bodyId = -1;
1163 float deltaVX = 0.f, deltaVY = 0.f, deltaVZ = 0.f;
1164 float deltaWX = 0.f, deltaWY = 0.f, deltaWZ = 0.f;
1165 };
1166 std::vector<ExplosionResult> explosionResults_;
1167 const ExplosionResult &explosionResultAt(int index, const char *operation) const;
1168
1169 uint32_t queryCategoryBits_ = 0xFFFFFFFFu;
1170 uint32_t queryMaskBits_ = 0xFFFFFFFFu;
1171 int queryIgnoredBodyId_ = -1;
1172 int queryIgnoredShapeId_ = -1;
1173};
1174
1175} // namespace eve::physics
ActionParameterOperation operation
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
float degrees
Definition CardTypes.cpp:35
int bz
Definition CaveMesh.cpp:114
int ax
Definition CaveMesh.cpp:113
int ay
Definition CaveMesh.cpp:113
int bx
Definition CaveMesh.cpp:114
float length
Definition CaveMesh.cpp:94
int az
Definition CaveMesh.cpp:113
int by
Definition CaveMesh.cpp:114
#define EVENGINE_API_WORLD
Definition Export.h:109
ShaderImageInput shape
std::uint32_t height
std::uint32_t width
void(* destroy)(void *)
TokenKind kind
float distance
Texture * normal
Owning, generation-qualified results for cross-module 3D physics queries.
World3D * world
Process-local, generation-qualified handles owned by the physics domain.
float radius
PrimitiveHandle handle
Move-only, checked operation results for the common layer.
V3 origin
Definition RoadBake.cpp:138
RoadLaneDirection direction
float axisZ
Definition RockMesh.cpp:22
float axisY
Definition RockMesh.cpp:22
float axisX
Definition RockMesh.cpp:22
std::string filter
float dz
float dy
float dx
Backend-neutral, observable fixed-step contract for physics domains.
Versioned, integrity-checked persistence envelopes.
Battle::Events events
TerrainThermalSettings settings
float separation
Definition TreeMesh.cpp:159
float step
Definition TreeMesh.cpp:314
std::string body
uint32_t index
std::uint32_t depth
const VegetationPresetContext & context
glm::vec3 point
float qy
float qx
float qw
float qz
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Structured status and zero or more diagnostics for an operation.
Definition Status.h:68
static Status success(StatusCode code=StatusCode::Ok)
Construct a successful status with an explicit non-error outcome.
Definition Status.h:81
Id128 public API.
Definition Identity.h:112
static constexpr Id128 nil() noexcept
Returns the all-zero nil value.
Definition Identity.h:142
static constexpr StrongUint64 zero() noexcept
Returns the zero value for this strong type.
3D rigid body (Box3D) in meter-space coordinates (+Y up by convention). Owned by a World3D; create pr...
Definition Body3D.h:24
Script-facing Box3D joint owned by a World3D.
Definition Joint3D.h:17
Composed mechanical assembly owned by a World3D.
Definition Mechanism3D.h:25
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:25
Read-only 3D physics implementation of sensing's LOS capability.
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
bool hasClosestPoint() const
Whether the latest closestPoint call found a shape.
Definition World3D.h:655
int getBeginTriggerVisitorShapeId(int index) const
Visitor shape ID of a begin-trigger event.
float getProfileStepMs() const
Latest complete physics step time in milliseconds.
int getBeginContactShapeAId(int index) const
Shape ID on stable side A of a begin-contact event.
float getShapeCastX() const
World-space contact point X from the last shape cast.
Definition World3D.h:690
int getEndTriggerCount() const
Number of sensor overlaps that ended during the latest step.
Definition World3D.h:828
float getJointStressForceY(int index) const
Constraint force Y of a stress event.
int getClosestShapeId() const
Stable shape id from the latest closestPoint call, or -1.
Definition World3D.h:659
float getContactPointTotalNormalImpulse(int index) const
Total normal impulse accumulated across all physics substeps.
int getRayHitTriangleIndex() const
Mesh/height-field triangle index from the last ray cast, otherwise -1.
Definition World3D.h:523
float getHitNormalX(int index) const
Hit normal X, pointing from stable side A to B.
int getDynamicTreeHeight() const
Dynamic broad-phase tree height.
bool hasRayHit() const
Definition World3D.h:514
eve::PersistentId persistentId() const noexcept
Stable non-nil identity written to snapshot envelopes.
Definition World3D.h:152
int getShapeCastResultShapeId(int index) const
Shape ID of a sorted Shape Cast result.
float getClosestY() const
Closest surface point Y.
Definition World3D.h:665
int getBeginTriggerSensorBodyId(int index) const
Sensor body ID of a begin-trigger event.
float getHitPointZ(int index) const
World-space impact point Z.
float getContactPushOutSpeed() const
Current maximum contact push-out speed in m/s.
Definition World3D.h:222
float getContactPointNormalImpulse(int index) const
Normal impulse from the final physics substep.
int getEndContactShapeBId(int index) const
Shape ID on stable side B of an end-contact event.
float getShapeCastResultFraction(int index) const
Translation fraction in [0,1] of a Shape Cast result.
int getClosestShapeTag() const
User tag of the shape from the latest closestPoint call, or zero.
Definition World3D.h:661
PhysicsWorldHandle runtimeHandle() const noexcept
Process-local identity used by PhysicsLink; invalid after destruction.
Definition World3D.h:141
int getEndContactBodyAId(int index) const
Body ID on stable side A of an end-contact event.
int getEndContactShapeATag(int index) const
Shape Tag on stable side A of an end-contact event.
int getJointCount() const
Current backend joint count.
int getShapeCastShapeId() const
Stable shape id from the last shape cast, or -1.
Definition World3D.h:682
int getRayResultTriangleIndex(int index) const
Mesh/height-field triangle index of a sorted ray result, otherwise -1.
float getRayHitX() const
Definition World3D.h:524
float getShapeCastZ() const
World-space contact point Z from the last shape cast.
Definition World3D.h:694
float getContactPointX(int index) const
World-space contact point X on the queried body.
std::weak_ptr< const void > lifetimeToken() const noexcept
Return a weak lifetime token for owner-thread runtime integrations.
Definition World3D.h:150
int getBeginContactBodyBId(int index) const
Body ID on stable side B of a begin-contact event.
float getRayHitY() const
Definition World3D.h:525
int getContactPointOtherShapeId(int index) const
Other Shape ID of a contact point.
float getContactDampingRatio() const
Current contact damping ratio.
Definition World3D.h:220
float getMoverNormalY() const
Representative blocking normal Y from the last move.
Definition World3D.h:757
int getQueryShapeCount() const
Number of individual shapes hit by the last overlap query.
Definition World3D.h:778
float getExplosionResultDeltaVelocityX(int index) const
Explosion-induced linear velocity delta X.
World3D(const World3D &)=delete
World3D & operator=(const World3D &)=delete
int getQueryCount() const
Number of bodies hit by the last overlap query.
Definition World3D.h:774
float getRayResultNormalY(int index) const
Surface normal Y of a sorted ray result.
float getProfileBulletsMs() const
Latest continuous-collision bullet time in milliseconds.
float getContactHertz() const
Current contact stiffness frequency.
Definition World3D.h:218
float getRayHitNormalX() const
Definition World3D.h:527
float getContactPointSeparation(int index) const
Signed surface separation; negative values indicate penetration.
int getHitShapeBId(int index) const
Stable Shape ID on side B of a hit.
float getClosestNormalX() const
Surface-to-target normal X, or zero for an inside/on-surface target.
Definition World3D.h:669
int getQueryMaskBits() const
Query mask bits currently in use.
Definition World3D.h:945
float getMoverDeltaZ() const
Resolved translation Z from the last moveCapsule call.
Definition World3D.h:753
float getProfileCollideMs() const
Latest narrow-phase collision time in milliseconds.
int getHitCount() const
Number of significant collision hits generated during the latest step.
Definition World3D.h:887
int getJointStressKind(int index) const
Joint kind code: 0 distance, 1 revolute, 2 prismatic, 3 spherical, 4 wheel.
int getShapeCastShapeTag() const
User tag of the shape from the last shape cast, or zero on no hit.
Definition World3D.h:684
float getRayHitNormalZ() const
Definition World3D.h:529
float getMoverDeltaY() const
Resolved translation Y from the last moveCapsule call.
Definition World3D.h:751
float getHitPointX(int index) const
World-space impact point X.
int getBeginTriggerCount() const
Number of sensor overlaps that began during the latest step.
Definition World3D.h:814
int getExplosionResultBodyId(int index) const
Stable Body ID of an affected body, sorted ascending.
int getQueryCategoryBits() const
Query category bits currently in use.
Definition World3D.h:943
float getMoverNormalZ() const
Representative blocking normal Z from the last move.
Definition World3D.h:759
int getBeginTriggerVisitorShapeTag(int index) const
Visitor Shape Tag of a begin-trigger event.
int getEndContactShapeBTag(int index) const
Shape Tag on stable side B of an end-contact event.
float getClosestDistance() const
Non-negative distance from the target to the closest shape.
Definition World3D.h:675
int getHitBodyBId(int index) const
Stable body ID on side B of a hit.
int nextJointId()
Internal: next stable joint id.
Definition World3D.h:994
int getContactPointShapeTag(int index) const
Queried-body Shape Tag of a contact point.
float getHitNormalImpulse(int index) const
Total normal impulse accumulated across all manifolds and substeps.
int getHitShapeAId(int index) const
Stable Shape ID on side A of a hit.
float getShapeCastNormalZ() const
Contact normal Z from the last shape cast.
Definition World3D.h:700
float getContactPointY(int index) const
World-space contact point Y on the queried body.
float getContactPointNormalY(int index) const
Contact normal Y from queried body toward the other body.
int getBeginContactCount() const
Number of non-sensor contacts that began during the latest step.
Definition World3D.h:785
int getJointStressBodyAId(int index) const
Stable body A ID of a stress event.
float getShapeCastResultNormalZ(int index) const
Contact normal Z of a Shape Cast result.
int getEndContactCount() const
Number of non-sensor contacts that ended during the latest step.
Definition World3D.h:799
int getRayResultShapeId(int index) const
Shape ID of a sorted ray result.
int getBeginTriggerSensorShapeId(int index) const
Sensor shape ID of a begin-trigger event.
int getJointStressCount() const
Number of joints exceeding force/torque thresholds in the latest step.
Definition World3D.h:917
float getShapeCastResultY(int index) const
World-space contact point Y of a Shape Cast result.
int getShapeCastTriangleIndex() const
Mesh/height-field triangle index from the latest shape cast, otherwise -1.
Definition World3D.h:688
float getMoverDeltaX() const
Resolved translation X from the last moveCapsule call.
Definition World3D.h:749
int getShapeCastMaterialId() const
Surface material ID at the last shape-cast intersection, or zero.
Definition World3D.h:686
float getRayResultFraction(int index) const
Segment fraction in [0,1] of a sorted ray result.
float getClosestZ() const
Closest surface point Z.
Definition World3D.h:667
int nextShapeId()
Internal: next stable shape id.
Definition World3D.h:992
int getEndTriggerSensorShapeTag(int index) const
Sensor Shape Tag of an end-trigger event.
int getIslandCount() const
Current solver-island count.
int getBeginContactShapeATag(int index) const
Shape Tag on stable side A of a begin-contact event.
int getStaticTreeHeight() const
Static broad-phase tree height.
int getContactPointOtherBodyId(int index) const
Other Body ID of a contact point.
int getEndTriggerSensorShapeId(int index) const
Sensor shape ID of an end-trigger event.
float getShapeCastResultNormalX(int index) const
Contact normal X of a Shape Cast result.
int getClosestBodyId() const
Stable body id from the latest closestPoint call, or -1.
Definition World3D.h:657
float getContactPointZ(int index) const
World-space contact point Z on the queried body.
int getBeginContactShapeBTag(int index) const
Shape Tag on stable side B of a begin-contact event.
float getExplosionResultDeltaAngularVelocityY(int index) const
Explosion-induced angular velocity delta Y.
float getExplosionResultDeltaVelocityY(int index) const
Explosion-induced linear velocity delta Y.
float getRayResultX(int index) const
World-space hit point X of a sorted ray result.
int getMemoryByteCount() const
Approximate Box3D world allocation in bytes.
int getEndTriggerVisitorShapeId(int index) const
Visitor shape ID of an end-trigger event.
int getQueryIgnoredShapeId() const
Stable Shape3D ID currently ignored by queries, or -1.
Definition World3D.h:953
int getEndTriggerVisitorShapeTag(int index) const
Visitor Shape Tag of an end-trigger event.
int getShapeCastBodyId() const
Stable body id from the last shape cast, or -1.
Definition World3D.h:680
b3WorldId raw() const
Raw Box3D world id.
Definition World3D.h:969
float getShapeCastY() const
World-space contact point Y from the last shape cast.
Definition World3D.h:692
int getContactPointShapeId(int index) const
Queried-body Shape ID of a contact point.
float getExplosionResultDeltaAngularVelocityX(int index) const
Explosion-induced angular velocity delta X.
float getShapeCastResultX(int index) const
World-space contact point X of a Shape Cast result.
int getRayHitMaterialId() const
Surface material ID at the last ray intersection, or zero.
Definition World3D.h:521
float getJointStressForceZ(int index) const
Constraint force Z of a stress event.
int getShapeCastResultTriangleIndex(int index) const
Mesh/height-field triangle index of a Shape Cast result, otherwise -1.
float getClosestNormalZ() const
Surface-to-target normal Z, or zero for an inside/on-surface target.
Definition World3D.h:673
int getExplosionResultCount() const
Number of bodies affected by the latest explosion.
Definition World3D.h:249
float getShapeCastResultZ(int index) const
World-space contact point Z of a Shape Cast result.
int getRayHitShapeTag() const
User tag of the shape from the last ray cast, or zero on no hit.
Definition World3D.h:519
float getProfileSensorsMs() const
Latest sensor processing time in milliseconds.
int getBodyCount() const
Current backend body count.
int getAwakeContactCount() const
Contacts processed by the latest collide pass.
int getHitShapeBTag(int index) const
Shape Tag on side B of a hit.
float getClosestNormalY() const
Surface-to-target normal Y, or zero for an inside/on-surface target.
Definition World3D.h:671
int getHitBodyAId(int index) const
Stable body ID on side A of a hit.
float getJointStressForceX(int index) const
Constraint force X of a stress event.
float getContactPointNormalVelocity(int index) const
Pre-solve relative normal velocity; negative means approaching.
int getRayResultShapeTag(int index) const
Shape Tag of a sorted ray result.
int getShapeCastResultShapeTag(int index) const
Shape Tag of a sorted Shape Cast result.
float getShapeCastFraction() const
Translation fraction in [0,1] at the earliest hit.
Definition World3D.h:702
int getBeginContactShapeBId(int index) const
Shape ID on stable side B of a begin-contact event.
int getEndTriggerSensorBodyId(int index) const
Sensor body ID of an end-trigger event.
int getEndTriggerVisitorBodyId(int index) const
Visitor body ID of an end-trigger event.
float getShapeCastNormalX() const
Contact normal X from the last shape cast.
Definition World3D.h:696
int getContactCount() const
Current backend contact count.
int getQueryIgnoredBodyId() const
Stable Body3D ID currently ignored by queries, or -1.
Definition World3D.h:951
int getContactPointCount() const
Number of points cached by queryBodyContacts.
Definition World3D.h:852
float getExplosionResultDeltaAngularVelocityZ(int index) const
Explosion-induced angular velocity delta Z.
float getRayResultNormalX(int index) const
Surface normal X of a sorted ray result.
float getShapeCastResultNormalY(int index) const
Contact normal Y of a Shape Cast result.
float getProfileSolveMs() const
Latest constraint solver time in milliseconds.
int getJointStressBodyBId(int index) const
Stable body B ID of a stress event.
int getEndContactShapeAId(int index) const
Shape ID on stable side A of an end-contact event.
float getRayHitZ() const
Definition World3D.h:526
float getContactPointNormalX(int index) const
Contact normal X from queried body toward the other body.
float getShapeCastNormalY() const
Contact normal Y from the last shape cast.
Definition World3D.h:698
float getHitNormalY(int index) const
Hit normal Y, pointing from stable side A to B.
float getProfilePairsMs() const
Latest broad-phase pair generation time in milliseconds.
float getHitApproachSpeed(int index) const
Positive pre-solve approach speed in m/s.
bool hasShapeCastHit() const
Whether the last sphere, capsule, or box cast hit a body.
Definition World3D.h:678
int getRayHitBodyId() const
Definition World3D.h:515
float getClosestX() const
Closest surface point X.
Definition World3D.h:663
float getMoverNormalX() const
Representative blocking normal X from the last move.
Definition World3D.h:755
int getRecycledContactCount() const
Contact points recycled during the latest step.
int getShapeCastResultMaterialId(int index) const
Surface material ID at a sorted Shape Cast intersection.
int getEndContactBodyBId(int index) const
Body ID on stable side B of an end-contact event.
int getRayResultCount() const
Number of results cached by the latest rayCast or rayCastAll call.
Definition World3D.h:532
float getExplosionResultDeltaVelocityZ(int index) const
Explosion-induced linear velocity delta Z.
bool usedBackendFallback() const noexcept
Whether optional accelerator selection fell back to CPU.
Definition World3D.h:158
float getHitNormalZ(int index) const
Hit normal Z, pointing from stable side A to B.
int getBeginTriggerSensorShapeTag(int index) const
Sensor Shape Tag of a begin-trigger event.
float getRayResultNormalZ(int index) const
Surface normal Z of a sorted ray result.
float getRayHitFraction() const
Definition World3D.h:530
int getShapeCastResultBodyId(int index) const
Body ID of a sorted Shape Cast result.
int getHitShapeATag(int index) const
Shape Tag on side A of a hit.
float getJointStressTorqueY(int index) const
Constraint torque Y of a stress event.
int getJointStressJointId(int index) const
Stable Joint3D ID of a stress event.
int getBeginContactBodyAId(int index) const
Body ID on stable side A of a begin-contact event.
int getBeginTriggerVisitorBodyId(int index) const
Visitor body ID of a begin-trigger event.
float getJointStressTorqueZ(int index) const
Constraint torque Z of a stress event.
int getMoverIterations() const
Number of outer solver passes used by the last move.
Definition World3D.h:763
float getRayResultY(int index) const
World-space hit point Y of a sorted ray result.
float getRayHitNormalY() const
Definition World3D.h:528
int getShapeCastResultCount() const
Number of results cached by the latest single or multi Shape Cast.
Definition World3D.h:704
int getMoverPlaneCount() const
Number of collision planes considered during the last move.
Definition World3D.h:761
float getJointStressTorqueX(int index) const
Constraint torque X of a stress event.
int getContactPointOtherShapeTag(int index) const
Other Shape Tag of a contact point.
int getShapeCount() const
Current backend shape count.
int getRayHitShapeId() const
Stable shape id from the last ray cast, or -1.
Definition World3D.h:517
float getHitPointY(int index) const
World-space impact point Y.
int getRayResultBodyId(int index) const
Body ID of a sorted ray result.
int getRayResultMaterialId(int index) const
Surface material ID at a sorted ray intersection.
float getContactPointNormalZ(int index) const
Contact normal Z from queried body toward the other body.
float getMoverGroundDot() const
Largest dot product between mover up and a contact normal.
Definition World3D.h:771
bool isMoverGrounded() const
True when the last move touched a walkable plane.
Definition World3D.h:769
float getRayResultZ(int index) const
World-space hit point Z of a sorted ray result.
Owns temporary body-pair collision overrides projected from Action windows.
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
SimulationBackendKind
Kind of implementation that owns a simulation step.
SimulationDeterminism
Determinism guarantee made by a simulation backend.
void registerCameraObstructionWorld(World3D *world)
Registers camera obstruction world.
ClothProbeStatus
Named outcome for a filtered cloth particle probe.
Definition World3D.h:57
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
std::function< Result< ContentId >(std::string_view canonicalInput)> SnapshotHashProvider
Injected content-digest implementation used by snapshots.
Definition Snapshot.h:36
bool enabled
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Stable outer format shared by persistence and cross-process snapshots.
Definition Snapshot.h:46
CameraSphereHit3D public API.
Definition World3D.h:33
Per-call capsule mover classification policy; never mutates persistent World3D settings.
Result of a 3D point probe: deepest non-sensor shape within radius. Normal points from the shape towa...
Definition World3D.h:45
Query filter applied atomically for one owning query operation.
Observable backend progress shared by CPU and accelerator providers.
Validated solver policy for one simulation step.
Begin/end event for two non-sensor shapes.
Definition World3D.h:73
Stable snapshot describing one side of a 3D collision event.
Definition World3D.h:66
Significant collision containing world-space feedback data.
Definition World3D.h:85
Joint whose solver force or torque exceeded a configured threshold.
Definition World3D.h:94
Begin/end overlap event with an explicit sensor and visitor side.
Definition World3D.h:79