载入中...
搜索中...
未找到
SoftBody3DWorldBridge.cpp
浏览该文件的文档.
2
3#include "physics/Body3D.h"
4#include "physics/World3D.h"
5
6#include <memory>
7
8namespace eve::physics {
9
10namespace {
11
12class World3DSoftBodyAdapter final : public softbody::ISoftBodyCollisionWorld {
13public:
14 explicit World3DSoftBodyAdapter(World3D* world) : world_(world) {}
15
16 [[nodiscard]] bool softBodyCollisionAvailable() const noexcept override {
17 return world_ && world_->isValid();
18 }
19
20 [[nodiscard]] softbody::SoftBodyContactState probeSoftBodyParticle(
21 float x, float y, float z, float radius, softbody::SoftBodyContact& contact) const override {
22 contact = {};
23 lastBody_ = nullptr;
24 if (!world_) return softbody::SoftBodyContactState::None;
25
26 ClothContact3D rigidContact;
27 if (!world_->pointProbe(x, y, z, radius, &rigidContact) || !rigidContact.hit ||
28 !rigidContact.body || !rigidContact.body->isValid())
30
31 lastBody_ = rigidContact.body;
32 contact.hit = true;
33 contact.nx = rigidContact.nx;
34 contact.ny = rigidContact.ny;
35 contact.nz = rigidContact.nz;
36 contact.depth = rigidContact.depth;
37 contact.bodyId = lastBody_->getId();
38 contact.dynamicBody = lastBody_->getType() == "dynamic";
40 }
41
42 void applySoftBodyImpulse(int bodyId, float x, float y, float z) override {
43 if (!lastBody_ || !lastBody_->isValid() || lastBody_->getId() != bodyId ||
44 lastBody_->getType() != "dynamic")
45 return;
46 lastBody_->applyLinearImpulse(x, y, z);
47 }
48
49private:
50 World3D* world_ = nullptr;
51 mutable Body3D* lastBody_ = nullptr;
52};
53
54} // namespace
55
56// SoftBody3D is exported from the backends group (its module is physics_softbody)
57// while these two members are defined here, in the physics module's World-layer
58// bridge, because they take a World3D. MSVC therefore reports C4273 "inconsistent
59// dll linkage" for the definitions below: this translation unit sees the class as
60// dllimport and then defines a member of it. The split is deliberate (see
61// docs/dev/superpowers/specs/2026-08-18-test-suite-optimization.md section 7.16)
62// and no other link unit imports these two symbols, so the warning is scoped to
63// them rather than disabled for the build.
64#ifdef _MSC_VER
65#pragma warning(push)
66#pragma warning(disable : 4273)
67#endif
68
70 world_ = world;
71 ownedCollisionWorld_ = world ? std::make_unique<World3DSoftBodyAdapter>(world) : nullptr;
72 collisionWorld_ = ownedCollisionWorld_.get();
73}
74
75World3D* SoftBody3D::getCollideWorld() const { return world_; }
76
77#ifdef _MSC_VER
78#pragma warning(pop)
79#endif
80
81} // namespace eve::physics
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
World3D * world
float radius
World3D * getCollideWorld() const
Returns the collide world.
void setCollideWorld(World3D *world)
Borrows a rigid-body world used for particle contacts.
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
SoftBodyContactState
Strong result of a particle contact probe.
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36