载入中...
搜索中...
未找到
CollapseAnimationCapture.cpp
浏览该文件的文档.
1#include <new>
7
8namespace eve::physics {
9using namespace collapse_detail;
12 const auto sourceGeometry = source.fragmentGeometry();
13 if (!frames_.empty() && sourceGeometry != geometry_)
14 return Result<void>::failure(invalid("recording source geometry changed"));
15 const int count = source.boneCount();
16 if (!std::isfinite(seconds) || (frames_.empty() ? seconds != 0 : seconds <= duration()) || count <= 0 ||
17 (!frames_.empty() && count != boneCount()) || (frames_.size() + 1) * static_cast<size_t>(count) > MaxSamples)
18 return Result<void>::failure(invalid("invalid capture time, topology or sample budget"));
19 if (recipe_) {
20 auto timing = recipe_->validateSampleTime(static_cast<std::uint32_t>(frames_.size()), seconds);
21 if (!timing) return timing;
22 }
23 if (frames_.empty() && sourceGeometry) {
24 if (sourceGeometry->fragments.size() != static_cast<std::size_t>(count))
25 return Result<void>::failure(invalid("geometry fragment count does not match source"));
26 auto geometryValid = sourceGeometry->validate();
27 if (!geometryValid) return geometryValid;
28 }
29 Frame frame{seconds, {}};
30 frame.bones.reserve(static_cast<size_t>(count));
31 for (int i = 0; i < count; ++i) {
32 auto pose = source.bonePresentation(i);
33 if (!pose) return Result<void>::failure(pose.status());
34 if (!valid(pose.value())) return Result<void>::failure(invalid("invalid fragment pose"));
35 if (!frames_.empty()) {
36 const auto& a = frames_.front().bones[static_cast<size_t>(i)];
37 const auto& b = pose.value();
38 if (a.halfExtentX != b.halfExtentX || a.halfExtentY != b.halfExtentY || a.halfExtentZ != b.halfExtentZ ||
39 a.clusterId != b.clusterId || a.fractureLevel != b.fractureLevel)
40 return Result<void>::failure(invalid("fragment topology changed while recording"));
41 }
42 frame.bones.push_back(pose.value());
43 }
44 frames_.push_back(std::move(frame));
45 if (frames_.size() == 1) geometry_ = sourceGeometry;
46 return Result<void>::success();
47} catch (const std::bad_alloc&) {
49 Diagnostic::error(DiagnosticCode::Failed, "collapse capture allocation failed", "collapseAnimation"));
50}
51} // namespace eve::physics
eve::EntitySpatialPose pose
bool valid
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
ssq::Object frame
std::string_view source
int count
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
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
int boneCount() const noexcept
Number of fragments.
Result< void > capture(const CollapseCaptureSource &source, float seconds)
Record a complete frame at strictly increasing seconds, starting at zero. @cost Linear in fragments p...
float duration() const noexcept
Recorded duration in seconds.
Read-only source protocol for one atomic offline collapse sample. @ownership The caller owns the sour...
virtual ~CollapseCaptureSource()
Release the protocol object; does not transfer ownership to a recorder.
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36