载入中...
搜索中...
未找到
GeometryCollectionInstance.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Result.h"
5#include "common/Time.h"
11
12#include <cstdint>
13#include <memory>
14#include <vector>
15
16namespace eve::physics {
17
18class World3D;
19class Joint3D;
20struct FractureGeometry;
21
24 int boneA = -1;
25 int boneB = -1;
26 std::int64_t tick = 0;
27};
28
36 int clusterA = -1;
37 int clusterB = -1;
38 int boneA = -1;
39 int boneB = -1;
40 std::int64_t tick = 0;
41};
42
50 int maxEdgeBreaksPerStep = 0;
51 int maxSleepsPerStep = 0;
52};
53
56 int edgesBroken = 0;
57 int edgesDeferred = 0;
58 int clusterBreaks = 0;
59};
60
71public:
76
89 [[nodiscard("check geometry-collection instantiation")]]
91 const GeometryCollectionAsset& asset,
92 float originX, float originY,
93 float originZ);
94
102 [[nodiscard]] static eve::Result<std::unique_ptr<GeometryCollectionInstance>> createFractured(
103 World3D& world, const GeometryCollectionAsset& asset, const FractureGeometry& geometry, float originX,
104 float originY, float originZ);
109 [[nodiscard]] std::shared_ptr<const FractureGeometry> fragmentGeometry() const noexcept override;
110
112 [[nodiscard]] bool hasLiveWorld() const noexcept;
113
115 void setStepBudget(DestructionStepBudget budget) noexcept { budget_ = budget; }
117 [[nodiscard]] DestructionStepBudget stepBudget() const noexcept { return budget_; }
118
120 [[nodiscard("check field application")]]
122
129 [[nodiscard("check geometry-collection step")]] eve::Result<DestructionStepReceipt> step(SimulationStep step);
130
131 [[nodiscard]] int boneCount() const noexcept override { return static_cast<int>(bones_.size()); }
132 [[nodiscard]] int edgeCount() const noexcept { return static_cast<int>(edges_.size()); }
133 [[nodiscard]] BoneRuntimeState boneState(int boneIndex) const;
134 [[nodiscard]] int boneClusterId(int boneIndex) const;
135 [[nodiscard]] float edgeStrain(int edgeIndex) const;
137 [[nodiscard]] bool isEdgeBroken(int edgeIndex) const;
138 [[nodiscard]] int detachEventCount() const noexcept { return static_cast<int>(detachEvents_.size()); }
139 [[nodiscard]] BoneDetachEvent detachEventAt(int index) const;
140 [[nodiscard]] int clusterBreakEventCount() const noexcept {
141 return static_cast<int>(clusterBreakEvents_.size());
142 }
144 [[nodiscard]] ClusterBreakEvent clusterBreakEventAt(int index) const;
146 [[nodiscard]] int pendingEdgeBreakCount() const noexcept { return static_cast<int>(pendingEdgeBreaks_.size()); }
147
149 [[nodiscard("check bone physics-link resolution")]] eve::Result<PhysicsLink> boneLink(int boneIndex) const;
150
155 [[nodiscard("check bone presentation sampling")]]
156 eve::Result<BonePresentation> bonePresentation(int boneIndex) const override;
157
159 [[nodiscard]] std::uint64_t sleepBatchRevision() const noexcept { return sleepBatchRevision_; }
160
165 [[nodiscard("check geometry-collection snapshot capture")]]
167
172 [[nodiscard("check geometry-collection snapshot restore")]]
173 eve::Result<void> restoreSnapshot(const GeometryCollectionInstanceSnapshot& snapshot);
174
176 void releaseBodies();
177
178private:
179 [[nodiscard]] static eve::Result<std::unique_ptr<GeometryCollectionInstance>> createInternal(
180 World3D& world, const GeometryCollectionAsset& asset, std::shared_ptr<const FractureGeometry> geometry,
181 float originX, float originY, float originZ);
182 struct BoneRuntime {
183 BoneRuntimeState state = BoneRuntimeState::Attached;
184 bool anchored = false;
186 float halfExtentX = 0.5f;
187 float halfExtentY = 0.5f;
188 float halfExtentZ = 0.5f;
189 int clusterId = 0;
190 int fractureLevel = 0;
191 };
192 struct EdgeRuntime {
193 int boneA = 0;
194 int boneB = 0;
195 float strainThreshold = 1.f;
196 float accumulatedStrain = 0.f;
197 bool broken = false;
198 PhysicsJointHandle joint = PhysicsJointHandle::invalid();
199 };
200
201 GeometryCollectionInstance(PhysicsWorldHandle worldHandle, float originX, float originY, float originZ);
202
203 [[nodiscard]] World3D* resolveWorld() const noexcept;
204 [[nodiscard]] eve::Result<Body3D*> resolveBoneBody(int boneIndex) const;
205 [[nodiscard]] float falloffAt(const DestructionField& field, float x, float y, float z) const;
206 [[nodiscard]] eve::Result<std::vector<std::unique_ptr<Joint3D>>> stageConstraints(
207 const std::vector<EdgeRuntime>& edges);
208 void releaseConstraints();
209 void breakEdge(int edgeIndex, std::uint64_t tick, DestructionStepReceipt& receipt);
218 void syncBoneActivationFromGraph();
219 void destroyOwnedBodies(World3D& world);
220
221 PhysicsWorldHandle worldHandle_ = PhysicsWorldHandle::invalid();
222 float originX_ = 0.f;
223 float originY_ = 0.f;
224 float originZ_ = 0.f;
225 std::uint64_t lastTick_ = 0;
226 std::uint64_t sleepBatchRevision_ = 0;
227 bool orphanedPhysics_ = false;
228 DestructionStepBudget budget_{};
229 std::vector<BoneRuntime> bones_;
230 std::vector<EdgeRuntime> edges_;
231 std::vector<BoneDetachEvent> detachEvents_;
232 std::vector<ClusterBreakEvent> clusterBreakEvents_;
233 std::vector<int> pendingEdgeBreaks_;
234 std::shared_ptr<const FractureGeometry> geometry_;
235 std::vector<std::unique_ptr<Joint3D>> ownedJoints_;
236};
237
238} // namespace eve::physics
double z
double y
double x
#define EVENGINE_API_DOMAINS
Definition Export.h:110
PhysicsJointLink link
std::vector< Edge > edges
float f
Move-only, checked operation results for the common layer.
std::string geometry
SimulationTick tick
Common time values and an injectable deterministic simulation clock.
float step
Definition TreeMesh.cpp:451
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:176
Read-only source protocol for one atomic offline collapse sample. @ownership The caller owns the sour...
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).
int boneCount() const noexcept override
Stable positive fragment count for this sample.
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:47
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.
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.
Owning, typed mesh payload shared immutably by simulation, clip and renderer. @thread Read-only shari...
Immutable cooked/authored geometry-collection asset.
Persistent runtime snapshot for one geometry-collection instance.