载入中...
搜索中...
未找到
Box3DWorld.cpp
浏览该文件的文档.
1// eve-hot-path
3#include <algorithm>
4#include <cfloat>
5#include <cmath>
6#include <utility>
7#include "physics/Joint3D.h"
12namespace eve::physics::box3d {
13b3WorldId Access::worldId(const World3D &world) {
14 auto *native = dynamic_cast<WorldBackend *>(world.rigidBackend_.get());
15 if (!native) throw eve::Exception("Box3D world access requires a Box3D backend");
16 return native->worldId_;
17}
18
19using namespace world3d_detail;
20namespace {
21constexpr uint64_t combineModeMask = 0x7ull;
22constexpr int frictionModeShift = 32;
23constexpr int restitutionModeShift = 35;
24
25float combineMaterialValue(float a, uint64_t materialA, float b, uint64_t materialB, int shift, bool friction) {
26 const uint64_t modeA = (materialA >> shift) & combineModeMask;
27 const uint64_t modeB = (materialB >> shift) & combineModeMask;
28 const uint64_t mode = std::max(modeA, modeB);
29 switch (mode) {
30 case 1: return 0.5f * (a + b);
31 case 2: return std::min(a, b);
32 case 3: return a * b;
33 case 4: return std::max(a, b);
34 default: return friction ? std::sqrt(a * b) : std::max(a, b);
35 }
36}
37
38float mixFriction(float a, uint64_t materialA, float b, uint64_t materialB) {
39 return combineMaterialValue(a, materialA, b, materialB, frictionModeShift, true);
40}
41
42float mixRestitution(float a, uint64_t materialA, float b, uint64_t materialB) {
43 return combineMaterialValue(a, materialA, b, materialB, restitutionModeShift, false);
44}
45
46uint64_t stablePairKey(int idA, int idB) {
47 const uint32_t low = static_cast<uint32_t>(std::min(idA, idB));
48 const uint32_t high = static_cast<uint32_t>(std::max(idA, idB));
49 return (static_cast<uint64_t>(high) << 32) | low;
50}
51
52b3BodyType parseBodyType(const std::string &type) {
53 if (type == "static") return b3_staticBody;
54 if (type == "kinematic") return b3_kinematicBody;
55 if (type == "dynamic") return b3_dynamicBody;
56 throw eve::Exception("World3D.newBody: unknown body type '%s' (use static|kinematic|dynamic)", type.c_str());
57}
58
59void stepBox3D(void *context, const eve::SimulationStep &step, const SimulationSettings &settings) noexcept {
60 auto *worldId = static_cast<b3WorldId *>(context);
61 b3World_Step(*worldId, static_cast<float>(step.delta.seconds()), settings.subStepCount);
62}
63
64
65} // namespace
66
67WorldBackend::WorldBackend(World3D &owner, float gx, float gy, float gz, bool sleep) : owner_(&owner) {
68 auto def = b3DefaultWorldDef();
69 def.gravity = {gx, gy, gz};
70 def.enableSleep = sleep;
71 owner_->contactHertz_ = def.contactHertz;
72 owner_->contactDampingRatio_ = def.contactDampingRatio;
73 owner_->contactPushOutSpeed_ = def.contactSpeed;
74 worldId_ = b3CreateWorld(&def);
75 if (!b3World_IsValid(worldId_)) throw eve::Exception("Box3D rejected world creation");
76 b3World_SetFrictionCallback(worldId_, &mixFriction);
77 b3World_SetRestitutionCallback(worldId_, &mixRestitution);
78 b3World_SetCustomFilterCallback(worldId_, &WorldBackend::do_customFilterCallback, this);
79 b3World_SetPreSolveCallback(worldId_, &WorldBackend::do_preSolveCallback, this);
80}
82bool WorldBackend::isValid() const noexcept { return b3World_IsValid(worldId_); }
83void WorldBackend::destroy() noexcept {
84 if (isValid()) b3DestroyWorld(worldId_);
85 worldId_ = {};
86}
88 return detail::selectSimulationBackend(
90 detail::makeCallbackSimulationBackend(&worldId_, &stepBox3D, SimulationBackendKind::Cpu,
92 &worldId_, true);
93}
95 auto *source = dynamic_cast<WorldBackend *>(&prepared);
96 if (!source)
98 eve::Diagnostic::error(eve::DiagnosticCode::Unsupported, "Cannot swap topology across rigid backends"));
99 std::swap(worldId_, source->worldId_);
100 b3World_SetCustomFilterCallback(worldId_, &WorldBackend::do_customFilterCallback, this);
101 b3World_SetPreSolveCallback(worldId_, &WorldBackend::do_preSolveCallback, this);
102 b3World_SetCustomFilterCallback(source->worldId_, &WorldBackend::do_customFilterCallback, source);
103 b3World_SetPreSolveCallback(source->worldId_, &WorldBackend::do_preSolveCallback, source);
105}
106uint64_t WorldBackend::shapeKey(const Shape3D &shape) const { return b3StoreShapeId(Access::shapeId(shape)); }
108 float z) {
109 return checked("physics.world3d.createBody", [&] {
111 if (!isValid())
112 return R::failure(eve::Diagnostic::error(eve::DiagnosticCode::StaleHandle, "World is no longer valid"));
113 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z))
114 return R::failure(
115 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "Body position must be finite"));
116 auto def = b3DefaultBodyDef();
117 def.type = parseBodyType(std::string(type));
118 def.position = {x, y, z};
119 auto id = b3CreateBody(worldId_, &def);
120 if (!b3Body_IsValid(id))
121 return R::failure(eve::Diagnostic::error(eve::DiagnosticCode::Failed, "Box3D rejected body creation"));
122 return R::success(adoptBody(id));
123 });
124}
125eve::Result<std::unique_ptr<IWorldBackend3D>> makeWorld(World3D &owner, float gx, float gy, float gz, bool sleep) {
126 try {
128 std::make_unique<WorldBackend>(owner, gx, gy, gz, sleep));
129 } catch (const eve::Exception &error) {
131 eve::Diagnostic::error(eve::DiagnosticCode::Failed, error.what(), "physics.world3d.create"));
132 }
133}
134
135void WorldBackend::do_setContinuousCollisionEnabled(bool enabled) {
136 if (isValid()) b3World_EnableContinuous(worldId_, enabled);
137}
138
140 return checked("physics.world3d.setContinuousCollisionEnabled", [&] {
141 do_setContinuousCollisionEnabled(enabled);
143 });
144}
145
146bool WorldBackend::do_isContinuousCollisionEnabled() const {
147 return isValid() && b3World_IsContinuousEnabled(worldId_);
148}
149
151 return checked("physics.world3d.isContinuousCollisionEnabled",
152 [&] { return eve::Result<bool>::success(do_isContinuousCollisionEnabled()); });
153}
154
155void WorldBackend::do_setRestitutionThreshold(float speed) {
156 if (!std::isfinite(speed) || speed < 0.f)
157 throw eve::Exception("World3D.setRestitutionThreshold: speed must be finite and >= 0");
158 if (isValid()) b3World_SetRestitutionThreshold(worldId_, speed);
159}
160
162 return checked("physics.world3d.setRestitutionThreshold", [&] {
163 do_setRestitutionThreshold(speed);
165 });
166}
167
168float WorldBackend::do_getRestitutionThreshold() const {
169 return isValid() ? b3World_GetRestitutionThreshold(worldId_) : 0.f;
170}
171
173 return checked("physics.world3d.getRestitutionThreshold",
174 [&] { return eve::Result<float>::success(do_getRestitutionThreshold()); });
175}
176
177void WorldBackend::do_setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) {
178 if (!std::isfinite(hertz) || !(hertz > 0.f))
179 throw eve::Exception("World3D.setContactTuning: hertz must be finite and > 0");
180 if (!std::isfinite(dampingRatio) || dampingRatio < 0.f)
181 throw eve::Exception("World3D.setContactTuning: dampingRatio must be finite and >= 0");
182 if (!std::isfinite(pushOutSpeed) || pushOutSpeed < 0.f)
183 throw eve::Exception("World3D.setContactTuning: pushOutSpeed must be finite and >= 0");
184 owner_->contactHertz_ = hertz;
185 owner_->contactDampingRatio_ = dampingRatio;
186 owner_->contactPushOutSpeed_ = pushOutSpeed;
187 if (isValid()) b3World_SetContactTuning(worldId_, hertz, dampingRatio, pushOutSpeed);
188}
189
190eve::Result<void> WorldBackend::setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) {
191 return checked("physics.world3d.setContactTuning", [&] {
192 do_setContactTuning(hertz, dampingRatio, pushOutSpeed);
194 });
195}
196
197void WorldBackend::do_setContactRecycleDistance(float distance) {
198 if (!std::isfinite(distance) || distance < 0.f)
199 throw eve::Exception("World3D.setContactRecycleDistance: distance must be finite and >= 0");
200 if (isValid()) b3World_SetContactRecycleDistance(worldId_, distance);
201}
202
204 return checked("physics.world3d.setContactRecycleDistance", [&] {
205 do_setContactRecycleDistance(distance);
207 });
208}
209
210float WorldBackend::do_getContactRecycleDistance() const {
211 return isValid() ? b3World_GetContactRecycleDistance(worldId_) : 0.f;
212}
213
215 return checked("physics.world3d.getContactRecycleDistance",
216 [&] { return eve::Result<float>::success(do_getContactRecycleDistance()); });
217}
218
219void WorldBackend::do_setMaximumLinearSpeed(float speed) {
220 if (!std::isfinite(speed) || !(speed > 0.f))
221 throw eve::Exception("World3D.setMaximumLinearSpeed: speed must be finite and > 0");
222 if (isValid()) b3World_SetMaximumLinearSpeed(worldId_, speed);
223}
224
226 return checked("physics.world3d.setMaximumLinearSpeed", [&] {
227 do_setMaximumLinearSpeed(speed);
229 });
230}
231
232float WorldBackend::do_getMaximumLinearSpeed() const {
233 return isValid() ? b3World_GetMaximumLinearSpeed(worldId_) : 0.f;
234}
235
237 return checked("physics.world3d.getMaximumLinearSpeed",
238 [&] { return eve::Result<float>::success(do_getMaximumLinearSpeed()); });
239}
240
241void WorldBackend::do_setWarmStartingEnabled(bool enabled) {
242 if (isValid()) b3World_EnableWarmStarting(worldId_, enabled);
243}
244
246 return checked("physics.world3d.setWarmStartingEnabled", [&] {
247 do_setWarmStartingEnabled(enabled);
249 });
250}
251
252bool WorldBackend::do_isWarmStartingEnabled() const { return isValid() && b3World_IsWarmStartingEnabled(worldId_); }
253
255 return checked("physics.world3d.isWarmStartingEnabled",
256 [&] { return eve::Result<bool>::success(do_isWarmStartingEnabled()); });
257}
258
259int WorldBackend::do_explode(float x, float y, float z, float radius, float falloff, float impulsePerArea,
260 int maskBits) {
261 owner_->explosionResults_.clear();
262 if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(z))
263 throw eve::Exception("World3D.explode: center must be finite");
264 if (!std::isfinite(radius) || radius < 0.f || !std::isfinite(falloff) || falloff < 0.f)
265 throw eve::Exception("World3D.explode: radius and falloff must be finite and >= 0");
266 if (!std::isfinite(impulsePerArea)) throw eve::Exception("World3D.explode: impulsePerArea must be finite");
267 if (!isValid() || impulsePerArea == 0.f) return 0;
268
269 struct Before {
270 Body3D *body = nullptr;
271 b3Vec3 linear{};
272 b3Vec3 angular{};
273 };
274 std::vector<Before> before;
275 before.reserve(owner_->bodies_.size());
276 for (Body3D *body : owner_->bodies_) {
277 if (!body || !body->isValid() || b3Body_GetType(box3d::Access::bodyId(*body)) != b3_dynamicBody) continue;
278 before.push_back({body, b3Body_GetLinearVelocity(box3d::Access::bodyId(*body)),
279 b3Body_GetAngularVelocity(box3d::Access::bodyId(*body))});
280 }
281
282 b3ExplosionDef def = b3DefaultExplosionDef();
283 def.position = b3Pos{x, y, z};
284 def.radius = radius;
285 def.falloff = falloff;
286 def.impulsePerArea = impulsePerArea;
287 def.maskBits = static_cast<uint32_t>(maskBits);
288 b3World_Explode(worldId_, &def);
289
290 for (const Before &entry : before) {
291 if (!entry.body->isValid()) continue;
292 const b3Vec3 linear = b3Body_GetLinearVelocity(box3d::Access::bodyId(*entry.body));
293 const b3Vec3 angular = b3Body_GetAngularVelocity(box3d::Access::bodyId(*entry.body));
294 const b3Vec3 dv = linear - entry.linear;
295 const b3Vec3 dw = angular - entry.angular;
296 if (b3LengthSquared(dv) <= 1e-12f && b3LengthSquared(dw) <= 1e-12f) continue;
297 owner_->explosionResults_.push_back({entry.body->getId(), dv.x, dv.y, dv.z, dw.x, dw.y, dw.z});
298 }
299 std::sort(owner_->explosionResults_.begin(), owner_->explosionResults_.end(),
300 [](const ExplosionResult &a, const ExplosionResult &b) { return a.bodyId < b.bodyId; });
301 return static_cast<int>(owner_->explosionResults_.size());
302}
303
304eve::Result<int> WorldBackend::explode(float x, float y, float z, float radius, float falloff, float impulsePerArea,
305 int maskBits) {
306 return checked("physics.world3d.explode", [&] {
307 return eve::Result<int>::success(do_explode(x, y, z, radius, falloff, impulsePerArea, maskBits));
308 });
309}
310
311float WorldBackend::do_getBoundsMinX() const {
312 return isValid() ? static_cast<float>(b3World_GetBounds(worldId_).lowerBound.x) : 0.f;
313}
314
316 return checked("physics.world3d.getBoundsMinX", [&] { return eve::Result<float>::success(do_getBoundsMinX()); });
317}
318
319float WorldBackend::do_getBoundsMinY() const {
320 return isValid() ? static_cast<float>(b3World_GetBounds(worldId_).lowerBound.y) : 0.f;
321}
322
324 return checked("physics.world3d.getBoundsMinY", [&] { return eve::Result<float>::success(do_getBoundsMinY()); });
325}
326
327float WorldBackend::do_getBoundsMinZ() const {
328 return isValid() ? static_cast<float>(b3World_GetBounds(worldId_).lowerBound.z) : 0.f;
329}
330
332 return checked("physics.world3d.getBoundsMinZ", [&] { return eve::Result<float>::success(do_getBoundsMinZ()); });
333}
334
335float WorldBackend::do_getBoundsMaxX() const {
336 return isValid() ? static_cast<float>(b3World_GetBounds(worldId_).upperBound.x) : 0.f;
337}
338
340 return checked("physics.world3d.getBoundsMaxX", [&] { return eve::Result<float>::success(do_getBoundsMaxX()); });
341}
342
343float WorldBackend::do_getBoundsMaxY() const {
344 return isValid() ? static_cast<float>(b3World_GetBounds(worldId_).upperBound.y) : 0.f;
345}
346
348 return checked("physics.world3d.getBoundsMaxY", [&] { return eve::Result<float>::success(do_getBoundsMaxY()); });
349}
350
351float WorldBackend::do_getBoundsMaxZ() const {
352 return isValid() ? static_cast<float>(b3World_GetBounds(worldId_).upperBound.z) : 0.f;
353}
354
356 return checked("physics.world3d.getBoundsMaxZ", [&] { return eve::Result<float>::success(do_getBoundsMaxZ()); });
357}
358
359int WorldBackend::do_getBodyCount() const { return isValid() ? b3World_GetCounters(worldId_).bodyCount : 0; }
360
362 return checked("physics.world3d.getBodyCount", [&] { return eve::Result<int>::success(do_getBodyCount()); });
363}
364
365int WorldBackend::do_getShapeCount() const { return isValid() ? b3World_GetCounters(worldId_).shapeCount : 0; }
366
368 return checked("physics.world3d.getShapeCount", [&] { return eve::Result<int>::success(do_getShapeCount()); });
369}
370
371int WorldBackend::do_getContactCount() const { return isValid() ? b3World_GetCounters(worldId_).contactCount : 0; }
372
374 return checked("physics.world3d.getContactCount", [&] { return eve::Result<int>::success(do_getContactCount()); });
375}
376
377int WorldBackend::do_getJointCount() const { return isValid() ? b3World_GetCounters(worldId_).jointCount : 0; }
378
380 return checked("physics.world3d.getJointCount", [&] { return eve::Result<int>::success(do_getJointCount()); });
381}
382
383int WorldBackend::do_getIslandCount() const { return isValid() ? b3World_GetCounters(worldId_).islandCount : 0; }
384
386 return checked("physics.world3d.getIslandCount", [&] { return eve::Result<int>::success(do_getIslandCount()); });
387}
388
389int WorldBackend::do_getAwakeContactCount() const {
390 return isValid() ? b3World_GetCounters(worldId_).awakeContactCount : 0;
391}
392
394 return checked("physics.world3d.getAwakeContactCount",
395 [&] { return eve::Result<int>::success(do_getAwakeContactCount()); });
396}
397
398int WorldBackend::do_getRecycledContactCount() const {
399 return isValid() ? b3World_GetCounters(worldId_).recycledContactCount : 0;
400}
401
403 return checked("physics.world3d.getRecycledContactCount",
404 [&] { return eve::Result<int>::success(do_getRecycledContactCount()); });
405}
406
407int WorldBackend::do_getStaticTreeHeight() const {
408 return isValid() ? b3World_GetCounters(worldId_).staticTreeHeight : 0;
409}
410
412 return checked("physics.world3d.getStaticTreeHeight",
413 [&] { return eve::Result<int>::success(do_getStaticTreeHeight()); });
414}
415
416int WorldBackend::do_getDynamicTreeHeight() const { return isValid() ? b3World_GetCounters(worldId_).treeHeight : 0; }
417
419 return checked("physics.world3d.getDynamicTreeHeight",
420 [&] { return eve::Result<int>::success(do_getDynamicTreeHeight()); });
421}
422
423int WorldBackend::do_getMemoryByteCount() const { return isValid() ? b3World_GetCounters(worldId_).byteCount : 0; }
424
426 return checked("physics.world3d.getMemoryByteCount",
427 [&] { return eve::Result<int>::success(do_getMemoryByteCount()); });
428}
429
430int WorldBackend::do_getAwakeBodyCount() const { return isValid() ? b3World_GetAwakeBodyCount(worldId_) : 0; }
431
433 return checked("physics.world3d.getAwakeBodyCount",
434 [&] { return eve::Result<int>::success(do_getAwakeBodyCount()); });
435}
436
437float WorldBackend::do_getProfileStepMs() const { return isValid() ? b3World_GetProfile(worldId_).step : 0; }
438
440 return checked("physics.world3d.getProfileStepMs",
441 [&] { return eve::Result<float>::success(do_getProfileStepMs()); });
442}
443
444float WorldBackend::do_getProfilePairsMs() const { return isValid() ? b3World_GetProfile(worldId_).pairs : 0; }
445
447 return checked("physics.world3d.getProfilePairsMs",
448 [&] { return eve::Result<float>::success(do_getProfilePairsMs()); });
449}
450
451float WorldBackend::do_getProfileCollideMs() const { return isValid() ? b3World_GetProfile(worldId_).collide : 0; }
452
454 return checked("physics.world3d.getProfileCollideMs",
455 [&] { return eve::Result<float>::success(do_getProfileCollideMs()); });
456}
457
458float WorldBackend::do_getProfileSolveMs() const { return isValid() ? b3World_GetProfile(worldId_).solve : 0; }
459
461 return checked("physics.world3d.getProfileSolveMs",
462 [&] { return eve::Result<float>::success(do_getProfileSolveMs()); });
463}
464
465float WorldBackend::do_getProfileBulletsMs() const { return isValid() ? b3World_GetProfile(worldId_).bullets : 0; }
466
468 return checked("physics.world3d.getProfileBulletsMs",
469 [&] { return eve::Result<float>::success(do_getProfileBulletsMs()); });
470}
471
472float WorldBackend::do_getProfileSensorsMs() const { return isValid() ? b3World_GetProfile(worldId_).sensors : 0; }
473
475 return checked("physics.world3d.getProfileSensorsMs",
476 [&] { return eve::Result<float>::success(do_getProfileSensorsMs()); });
477}
478
479void WorldBackend::do_setGravity(float gx, float gy, float gz) {
480 if (!isValid()) return;
481 b3World_SetGravity(worldId_, b3Vec3{gx, gy, gz});
482}
483
484eve::Result<void> WorldBackend::setGravity(float gx, float gy, float gz) {
485 return checked("physics.world3d.setGravity", [&] {
486 do_setGravity(gx, gy, gz);
488 });
489}
490
491float WorldBackend::do_getGravityX() const {
492 if (!isValid()) return 0.f;
493 return b3World_GetGravity(worldId_).x;
494}
495
497 return checked("physics.world3d.getGravityX", [&] { return eve::Result<float>::success(do_getGravityX()); });
498}
499
500float WorldBackend::do_getGravityY() const {
501 if (!isValid()) return 0.f;
502 return b3World_GetGravity(worldId_).y;
503}
504
506 return checked("physics.world3d.getGravityY", [&] { return eve::Result<float>::success(do_getGravityY()); });
507}
508
509float WorldBackend::do_getGravityZ() const {
510 if (!isValid()) return 0.f;
511 return b3World_GetGravity(worldId_).z;
512}
513
515 return checked("physics.world3d.getGravityZ", [&] { return eve::Result<float>::success(do_getGravityZ()); });
516}
517
518void WorldBackend::do_setHitEventThreshold(float speed) {
519 if (!std::isfinite(speed) || speed < 0.f)
520 throw eve::Exception("World3D.setHitEventThreshold: speed must be finite and >= 0");
521 if (isValid()) b3World_SetHitEventThreshold(worldId_, speed);
522}
523
525 return checked("physics.world3d.setHitEventThreshold", [&] {
526 do_setHitEventThreshold(speed);
528 });
529}
530
531float WorldBackend::do_getHitEventThreshold() const { return isValid() ? b3World_GetHitEventThreshold(worldId_) : 0.f; }
532
534 return checked("physics.world3d.getHitEventThreshold",
535 [&] { return eve::Result<float>::success(do_getHitEventThreshold()); });
536}
537
538bool WorldBackend::do_customFilterCallback(b3ShapeId shapeIdA, b3ShapeId shapeIdB, void *context) {
539 auto *world = static_cast<WorldBackend *>(context);
540 Shape3D *shapeA = shapeFromShape(shapeIdA);
541 Shape3D *shapeB = shapeFromShape(shapeIdB);
542 Body3D *bodyA = bodyFromShape(shapeIdA);
543 Body3D *bodyB = bodyFromShape(shapeIdB);
544 if (!world || !shapeA || !shapeB || !bodyA || !bodyB) return false;
545 if (world->owner_->disabledBodyPairs_.count(stablePairKey(bodyA->getId(), bodyB->getId())) != 0) return false;
546 return world->owner_->disabledShapePairs_.count(stablePairKey(shapeA->getId(), shapeB->getId())) == 0;
547}
548
549b3QueryFilter WorldBackend::do_makeQueryFilter() const {
550 b3QueryFilter filter = b3DefaultQueryFilter();
551 filter.categoryBits = owner_->queryCategoryBits_;
552 filter.maskBits = owner_->queryMaskBits_;
553 return filter;
554}
555
556bool WorldBackend::do_shouldIgnoreQueryShape(b3ShapeId shapeId) const {
557 Body3D *body = bodyFromShape(shapeId);
558 Shape3D *shape = shapeFromShape(shapeId);
559 if (!body || !shape) return true;
560 return body->getId() == owner_->queryIgnoredBodyId_ || shape->getId() == owner_->queryIgnoredShapeId_;
561}
562
563bool WorldBackend::do_preSolveCallback(b3ShapeId shapeIdA, b3ShapeId shapeIdB, b3Pos point, b3Vec3 normal,
564 void *context) {
565 auto *world = static_cast<WorldBackend *>(context);
566 if (!world) return true;
567 auto findShape = [world](b3ShapeId id) -> Shape3D * {
568 const auto raw = world->owner_->shapeRawHandles_.find(b3StoreShapeId(id));
569 if (raw == world->owner_->shapeRawHandles_.end()) return nullptr;
570 const auto found = world->owner_->shapeHandles_.find(raw->second);
571 return found == world->owner_->shapeHandles_.end() ? nullptr : found->second;
572 };
573 Shape3D *shapeA = findShape(shapeIdA);
574 Shape3D *shapeB = findShape(shapeIdB);
575 if (shapeA && shapeA->isOneWay() &&
576 !shapeA->allowsOneWayContact(point.x, point.y, point.z, normal.x, normal.y, normal.z))
577 return false;
578 if (shapeB && shapeB->isOneWay() &&
579 !shapeB->allowsOneWayContact(point.x, point.y, point.z, -normal.x, -normal.y, -normal.z))
580 return false;
581 return true;
582}
583
584} // namespace eve::physics::box3d
double z
double y
double x
b3Vec3 angular
double raw
float friction
float linear
ShaderImageInput shape
float dampingRatio
std::string id
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
Texture * normal
OceanWakeSettings settings
std::shared_ptr< OceanGpuSpectrum > owner
std::string error
Definition Package.cpp:174
std::string body
bool found
std::string filter
std::string_view source
float step
Definition TreeMesh.cpp:451
const VegetationPresetContext & context
int shapeId
glm::vec3 point
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Backend-neutral 3D rigid body in meter-space coordinates (+Y up by convention). Owned by a World3D; c...
Definition Body3D.h:31
int getId() const
Stable id used by collision events.
Definition Body3D.h:42
Complete rigid-world execution boundary, bound once to an owning World3D facade. @ownership Owns exac...
3D shape (box/sphere/capsule) attached to a Body3D with material settings. Created via Body3D::new*Sh...
Definition Shape3D.h:34
int getId() const
Stable world-local id, preserved when sensor state recreates the backend shape.
Definition Shape3D.h:48
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:47
eve::Result< int > getBodyCount() const override
getBodyCount; uses the class ownership, thread and failure contract.
eve::Result< void > setGravity(float gx, float gy, float gz) override
setGravity; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMaxZ() const override
getBoundsMaxZ; uses the class ownership, thread and failure contract.
eve::Result< void > setMaximumLinearSpeed(float speed) override
setMaximumLinearSpeed; uses the class ownership, thread and failure contract.
eve::Result< void > setContinuousCollisionEnabled(bool enabled) override
setContinuousCollisionEnabled; uses the class ownership, thread and failure contract.
eve::Result< int > getStaticTreeHeight() const override
getStaticTreeHeight; uses the class ownership, thread and failure contract.
eve::Result< float > getGravityY() const override
getGravityY; uses the class ownership, thread and failure contract.
eve::Result< float > getProfilePairsMs() const override
getProfilePairsMs; uses the class ownership, thread and failure contract.
eve::Result< float > getGravityX() const override
getGravityX; uses the class ownership, thread and failure contract.
WorldBackend(World3D &owner, float gx, float gy, float gz, bool sleep)
eve::Result< void > setWarmStartingEnabled(bool enabled) override
setWarmStartingEnabled; uses the class ownership, thread and failure contract.
bool isValid() const noexcept override
Native world liveness.
eve::Result< int > getAwakeContactCount() const override
getAwakeContactCount; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMinY() const override
getBoundsMinY; uses the class ownership, thread and failure contract.
eve::Result< float > getHitEventThreshold() const override
getHitEventThreshold; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileSolveMs() const override
getProfileSolveMs; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMaxX() const override
getBoundsMaxX; uses the class ownership, thread and failure contract.
eve::Result< float > getGravityZ() const override
getGravityZ; uses the class ownership, thread and failure contract.
eve::Result< float > getMaximumLinearSpeed() const override
getMaximumLinearSpeed; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileBulletsMs() const override
getProfileBulletsMs; uses the class ownership, thread and failure contract.
eve::Result< int > getContactCount() const override
getContactCount; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileStepMs() const override
getProfileStepMs; uses the class ownership, thread and failure contract.
eve::Result< int > getRecycledContactCount() const override
getRecycledContactCount; uses the class ownership, thread and failure contract.
eve::Result< void > setContactRecycleDistance(float distance) override
setContactRecycleDistance; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMinZ() const override
getBoundsMinZ; uses the class ownership, thread and failure contract.
eve::Result< std::unique_ptr< IBodyBackend3D > > createBody(std::string_view type, float x, float y, float z) override
Creates an owning body backend without publishing an engine wrapper. @cost One native body allocation...
eve::Result< void > setContactTuning(float hertz, float dampingRatio, float pushOutSpeed) override
setContactTuning; uses the class ownership, thread and failure contract.
void destroy() noexcept override
Idempotent native teardown after all facades have been invalidated.
eve::Result< void > setHitEventThreshold(float speed) override
setHitEventThreshold; uses the class ownership, thread and failure contract.
eve::Result< bool > isContinuousCollisionEnabled() const override
isContinuousCollisionEnabled; uses the class ownership, thread and failure contract.
eve::Result< int > getDynamicTreeHeight() const override
getDynamicTreeHeight; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMinX() const override
getBoundsMinX; uses the class ownership, thread and failure contract.
eve::Result< int > getShapeCount() const override
getShapeCount; uses the class ownership, thread and failure contract.
eve::Result< float > getRestitutionThreshold() const override
getRestitutionThreshold; uses the class ownership, thread and failure contract.
eve::Result< int > getJointCount() const override
getJointCount; uses the class ownership, thread and failure contract.
eve::Result< int > explode(float x, float y, float z, float radius, float falloff, float impulsePerArea, int maskBits) override
explode; uses the class ownership, thread and failure contract.
eve::Result< int > getIslandCount() const override
getIslandCount; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileCollideMs() const override
getProfileCollideMs; uses the class ownership, thread and failure contract.
eve::Result< float > getContactRecycleDistance() const override
getContactRecycleDistance; uses the class ownership, thread and failure contract.
eve::Result< int > getAwakeBodyCount() const override
getAwakeBodyCount; uses the class ownership, thread and failure contract.
eve::Result< float > getProfileSensorsMs() const override
getProfileSensorsMs; uses the class ownership, thread and failure contract.
eve::Result< bool > isWarmStartingEnabled() const override
isWarmStartingEnabled; uses the class ownership, thread and failure contract.
eve::Result< void > setRestitutionThreshold(float speed) override
setRestitutionThreshold; uses the class ownership, thread and failure contract.
eve::Result< void > swapTopology(IWorldBackend3D &prepared) override
Swaps prepared native topology while retaining stable step-driver contexts.
eve::Result< SimulationBackendSelection > selectSimulation() override
Builds the separate CPU/accelerator step driver; driver borrows this world's stable state.
uint64_t shapeKey(const Shape3D &shape) const override
Opaque native lookup key scoped to this world, used only by internal event history.
eve::Result< int > getMemoryByteCount() const override
getMemoryByteCount; uses the class ownership, thread and failure contract.
eve::Result< float > getBoundsMaxY() const override
getBoundsMaxY; uses the class ownership, thread and failure contract.
std::unique_ptr< IBodyBackend3D > adoptBody(b3BodyId id)
Internal native ABI adoption boundary; transfers sole body ownership, simulation thread only.
eve::Result< std::unique_ptr< IWorldBackend3D > > makeWorld(World3D &owner, float gx, float gy, float gz, bool sleep)
Native-world composition boundary; returns exclusive ownership or a structured failure....
Body3D * bodyFromShape(b3ShapeId shapeId)
Resolves a native Box3D user-data observer for an immediate internal call.
Shape3D * shapeFromShape(b3ShapeId shapeId)
Resolves a native Box3D user-data observer for an immediate internal call.
@ ToleranceBounded
Results are equivalent within a documented numeric tolerance.
bool enabled
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
static b3BodyId bodyId(const Body3D &body)
Borrows the native identifier synchronously; facade must belong to a Box3D world.
static b3WorldId worldId(const World3D &world)
Internal checked Box3D world ID; fails for another backend.
static b3ShapeId shapeId(const Shape3D &shape)
Borrows a Box3D shape identifier for a synchronous native operation.