载入中...
搜索中...
未找到
DeformRecording.cpp
浏览该文件的文档.
2#include <new>
3#include <utility>
6namespace eve::physics {
9 std::size_t budget;
10 std::size_t samples = 0;
11 std::vector<DeformFrame> frames;
12 Impl(const BakeRecipe& value, std::size_t limit) : recipe(value), budget(limit) {}
13};
14namespace {
15Diagnostic allocationFailure() {
16 return Diagnostic::error(DiagnosticCode::Failed, "deformation recording allocation failed", "deformRecording");
17}
18} // namespace
19DeformRecording::DeformRecording(std::unique_ptr<Impl> impl) : impl_(std::move(impl)) {}
21DeformRecording::DeformRecording(DeformRecording&&) noexcept = default;
22DeformRecording& DeformRecording::operator=(DeformRecording&&) noexcept = default;
24 if (sampleBudget == 0 || sampleBudget > 2000000)
27 "deformation recording sample budget must be in [1,2000000]", "deformRecording"));
28 try {
29 auto encoded = recipe.encode();
30 if (!encoded) return Result<DeformRecording>::failure(encoded.status());
31 return Result<DeformRecording>::success(DeformRecording(std::make_unique<Impl>(recipe, sampleBudget)));
32 } catch (const std::bad_alloc&) {
33 return Result<DeformRecording>::failure(allocationFailure());
34 }
35}
37 if (frame.positions.size() > impl_->budget - impl_->samples || impl_->frames.size() >= 2000000)
39 DiagnosticCode::InvalidArgument, "deformation recording sample budget exceeded", "deformRecording"));
40 const auto topology = impl_->frames.empty() ? frame.topology : impl_->frames.front().topology;
42 static_cast<std::uint32_t>(impl_->frames.size()),
43 impl_->frames.empty() ? -1 : impl_->frames.back().seconds);
44 if (!valid) return valid;
45 const auto count = frame.positions.size();
46 frame.topology = topology;
47 try {
48 impl_->frames.push_back(std::move(frame));
49 } catch (const std::bad_alloc&) {
50 return Result<void>::failure(allocationFailure());
51 }
52 impl_->samples += count;
53 return Result<void>::success();
54}
56 try {
57 return DeformTrack::prepare(impl_->frames, impl_->recipe);
58 } catch (const std::bad_alloc&) {
59 return Result<DeformTrack>::failure(allocationFailure());
60 }
61}
62std::size_t DeformRecording::frameCount() const noexcept { return impl_->frames.size(); }
63std::size_t DeformRecording::sampleCount() const noexcept { return impl_->samples; }
64} // namespace eve::physics
void * impl
bool valid
ssq::Object frame
BakeRecipe recipe
Topology topology
Object::Ptr value
int count
int limit
Definition TreeMesh.cpp:166
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
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
Bounded provenance builder for explicit-coordinate baked recordings. @ownership Owns names and conten...
Definition BakeRecipe.h:21
Bounded owning builder for fixed-topology deformation recordings. @ownership Owns a frozen recipe cop...
std::size_t frameCount() const noexcept
Number of successfully accepted frames.
DeformRecording(DeformRecording &&) noexcept
Result< DeformTrack > freeze() const
Freeze an independent immutable snapshot; the session remains available for further appends....
Result< void > append(DeformFrame frame)
Validate and append one owning candidate at the next recipe sample time. @ownership Consumes candidat...
std::size_t sampleCount() const noexcept
Total accepted vertex samples, excluding rejected candidates.
static Result< DeformRecording > prepare(const BakeRecipe &recipe, std::size_t sampleBudget)
Admit a complete recipe and explicit total vertex-sample budget in [1,2000000]. @cost Linear in bound...
static Result< DeformTrack > prepare(std::vector< DeformFrame > frames, const BakeRecipe &recipe)
Validate matching topology, positions, coordinates and fixed sample grid, then freeze all frames.
Result< void > validateDeformFrame(const DeformFrame &frame, const DeformTopology &topology, const BakeRecipe &recipe, std::uint32_t index, float previous)
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
Owning snapshot with actual connectivity, stable indexed positions and explicit sample time.
Definition DeformTrack.h:15
Impl(const BakeRecipe &value, std::size_t limit)
std::vector< DeformFrame > frames