载入中...
搜索中...
未找到
GeometryCollectionInstance.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Result.h"
5#include "common/Time.h"
10
11#include <cstdint>
12#include <memory>
13#include <vector>
14
15namespace eve::physics {
16
17class World3D;
18
20enum class BoneRuntimeState : std::uint8_t {
21 Attached = 0,
22 Detached = 1,
23 Sleeping = 2,
24};
25
28 int boneA = -1;
29 int boneB = -1;
30 std::int64_t tick = 0;
31};
32
40 int clusterA = -1;
41 int clusterB = -1;
42 int boneA = -1;
43 int boneB = -1;
44 std::int64_t tick = 0;
45};
46
54 int maxEdgeBreaksPerStep = 0;
55 int maxSleepsPerStep = 0;
56};
57
60 int edgesBroken = 0;
61 int edgesDeferred = 0;
62 int clusterBreaks = 0;
63};
64
72 BoneRuntimeState state = BoneRuntimeState::Attached;
73 float halfExtentX = 0.5f;
74 float halfExtentY = 0.5f;
75 float halfExtentZ = 0.5f;
76 float worldX = 0.f;
77 float worldY = 0.f;
78 float worldZ = 0.f;
79 float rotX = 0.f;
80 float rotY = 0.f;
81 float rotZ = 0.f;
82 float rotW = 1.f;
83 int clusterId = 0;
84 int fractureLevel = 0;
85};
86
97public:
102
115 [[nodiscard("check geometry-collection instantiation")]]
117 const GeometryCollectionAsset& asset,
118 float originX, float originY,
119 float originZ);
120
122 [[nodiscard]] bool hasLiveWorld() const noexcept;
123
125 void setStepBudget(DestructionStepBudget budget) noexcept { budget_ = budget; }
127 [[nodiscard]] DestructionStepBudget stepBudget() const noexcept { return budget_; }
128
130 [[nodiscard("check field application")]]
132
139 [[nodiscard("check geometry-collection step")]] eve::Result<DestructionStepReceipt> step(SimulationStep step);
140
141 [[nodiscard]] int boneCount() const noexcept { return static_cast<int>(bones_.size()); }
142 [[nodiscard]] int edgeCount() const noexcept { return static_cast<int>(edges_.size()); }
143 [[nodiscard]] BoneRuntimeState boneState(int boneIndex) const;
144 [[nodiscard]] int boneClusterId(int boneIndex) const;
145 [[nodiscard]] float edgeStrain(int edgeIndex) const;
147 [[nodiscard]] bool isEdgeBroken(int edgeIndex) const;
148 [[nodiscard]] int detachEventCount() const noexcept { return static_cast<int>(detachEvents_.size()); }
149 [[nodiscard]] BoneDetachEvent detachEventAt(int index) const;
150 [[nodiscard]] int clusterBreakEventCount() const noexcept {
151 return static_cast<int>(clusterBreakEvents_.size());
152 }
154 [[nodiscard]] ClusterBreakEvent clusterBreakEventAt(int index) const;
156 [[nodiscard]] int pendingEdgeBreakCount() const noexcept { return static_cast<int>(pendingEdgeBreaks_.size()); }
157
159 [[nodiscard("check bone physics-link resolution")]] eve::Result<PhysicsLink> boneLink(int boneIndex) const;
160
165 [[nodiscard("check bone presentation sampling")]]
166 eve::Result<BonePresentation> bonePresentation(int boneIndex) const;
167
169 [[nodiscard]] std::uint64_t sleepBatchRevision() const noexcept { return sleepBatchRevision_; }
170
175 [[nodiscard("check geometry-collection snapshot capture")]]
177
182 [[nodiscard("check geometry-collection snapshot restore")]]
183 eve::Result<void> restoreSnapshot(const GeometryCollectionInstanceSnapshot& snapshot);
184
186 void releaseBodies();
187
188private:
189 struct BoneRuntime {
190 BoneRuntimeState state = BoneRuntimeState::Attached;
191 bool anchored = false;
192 PhysicsLink link;
193 float halfExtentX = 0.5f;
194 float halfExtentY = 0.5f;
195 float halfExtentZ = 0.5f;
196 int clusterId = 0;
197 int fractureLevel = 0;
198 };
199 struct EdgeRuntime {
200 int boneA = 0;
201 int boneB = 0;
202 float strainThreshold = 1.f;
203 float accumulatedStrain = 0.f;
204 bool broken = false;
205 };
206
207 GeometryCollectionInstance(PhysicsWorldHandle worldHandle, float originX, float originY, float originZ);
208
209 [[nodiscard]] World3D* resolveWorld() const noexcept;
210 [[nodiscard]] eve::Result<Body3D*> resolveBoneBody(int boneIndex) const;
211 [[nodiscard]] float falloffAt(const DestructionField& field, float x, float y, float z) const;
212 void breakEdge(int edgeIndex, std::uint64_t tick, DestructionStepReceipt& receipt);
221 void syncBoneActivationFromGraph();
222 void destroyOwnedBodies(World3D& world);
223
224 PhysicsWorldHandle worldHandle_ = PhysicsWorldHandle::invalid();
225 float originX_ = 0.f;
226 float originY_ = 0.f;
227 float originZ_ = 0.f;
228 std::uint64_t lastTick_ = 0;
229 std::uint64_t sleepBatchRevision_ = 0;
230 bool orphanedPhysics_ = false;
231 DestructionStepBudget budget_{};
232 std::vector<BoneRuntime> bones_;
233 std::vector<EdgeRuntime> edges_;
234 std::vector<BoneDetachEvent> detachEvents_;
235 std::vector<ClusterBreakEvent> clusterBreakEvents_;
236 std::vector<int> pendingEdgeBreaks_;
237};
238
239} // namespace eve::physics
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_DOMAINS
Definition Export.h:110
float f
World3D * world
Move-only, checked operation results for the common layer.
SimulationTick tick
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:314
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Runtime owner of bone state, connection strain, and PhysicsLink bindings.
std::uint64_t sleepBatchRevision() const noexcept
Monotonic revision bumped when any bone enters Sleeping (for batch rebuild).
GeometryCollectionInstance(const GeometryCollectionInstance &)=delete
int pendingEdgeBreakCount() const noexcept
Edges still waiting because of the break budget.
DestructionStepBudget stepBudget() const noexcept
Return the active per-step budgets.
GeometryCollectionInstance & operator=(const GeometryCollectionInstance &)=delete
Box3D rigid-body world. Script coordinates are meters (Box3D native), unlike 2D World which uses pixe...
Definition World3D.h:63
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
BoneRuntimeState
Runtime lifecycle for one bone inside a geometry-collection instance.
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
One ordered detach event emitted during step.
Presentation snapshot for one bone (world pose + proxy extents).
Emitted when a broken edge separates two different cook clusters.
One volumetric influence applied to a geometry-collection instance.
Per-step production budgets (0 = unlimited).
Observable outcome of one checked step.
Immutable cooked/authored geometry-collection asset.
Persistent runtime snapshot for one geometry-collection instance.