载入中...
搜索中...
未找到
MeshVfxAsset.cpp
浏览该文件的文档.
16eve::Result<void> rejectUnknown(const eve::Value::Object& object, const std::set<std::string>& allowed,
28 if (const auto* v = value.getIf<double>()) return eve::Result<float>::success(static_cast<float>(*v));
29 if (const auto* v = value.getIf<std::int64_t>()) return eve::Result<float>::success(static_cast<float>(*v));
62 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "expected boolean", path + ".loop"));
79 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "style must be a string", path + ".style"));
83 auto parsedPlayback = parsePlayback(playback == object->end() ? nullptr : &playback->second, path + ".playback");
91 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "expected object", path + ".parameters"));
103 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "expected object", path + ".curves"));
133 auto known = rejectUnknown(*object, {"maxSamples", "lifetime", "minDistance", "teleportDistance",
150 eve::DiagnosticCode::InvalidArgument, "maxSamples must be a positive integer", "trail.maxSamples"));
162eve::Result<eve::AttachmentPoint> parseAttachmentOffset(const eve::Value* value, const std::string& path) {
187 if (root == object->end() || tip == object->end() || !root->second.isString() || !tip->second.isString())
193 auto rootOffset = parseAttachmentOffset(rootOffsetIt == object->end() ? nullptr : &rootOffsetIt->second,
195 if (!rootOffset) return eve::Result<std::optional<MeshVfxTrailBinding>>::failure(rootOffset.status());
196 auto tipOffset = parseAttachmentOffset(tipOffsetIt == object->end() ? nullptr : &tipOffsetIt->second,
198 if (!tipOffset) return eve::Result<std::optional<MeshVfxTrailBinding>>::failure(tipOffset.status());
208 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "events must be an array", "events"));
223 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "event time is required", path + ".time"));
234eve::Result<std::vector<std::string>> parseEventNames(const eve::Value* value, const std::string& path) {
245 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "animation trigger name must be a string",
256 eve::DiagnosticCode::InvalidArgument, "animationTriggers must be an object", "animationTriggers"));
260 for (const auto& [key, destination] : std::initializer_list<std::pair<const char*, std::vector<std::string>*>>{
279 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "mesh VFX root must be an object", {}));
287 auto known = rejectUnknown(*root, {"schemaVersion", "style", "playback", "parameters", "curves", "trail", "events", "animationTriggers"}, "$root");
298 auto known = rejectUnknown(*root, {"schema", "schemaVersion", "layers", "trail", "events", "animationTriggers"}, "$root");
301 if (schema == root->end() || !schema->second.isString() || schema->second.asString() != schemaId)
303 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "unsupported mesh VFX schema", "schema"));
305 const auto* array = layers == root->end() ? nullptr : layers->second.getIf<eve::Value::Array>();
308 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "layers must be an array", "layers"));
412 if (!animationTriggers.play.empty() || !animationTriggers.stop.empty() || !animationTriggers.trailBreak.empty()) {
455 if (!std::isfinite(key.time) || !std::isfinite(key.value) || key.time < 0.f || key.time > 1.f || key.time <= previous)
466 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, "invalid trail settings", "trail"));
467 if (trailBinding && (!trail || trailBinding->rootAttachment.empty() || trailBinding->tipAttachment.empty()))
473 if (!std::isfinite(event.time) || event.time < 0.f || event.time > 1.f || event.time < previousEventTime || event.name.empty())
515 const MeshVfxAsset& asset, const std::map<std::string, std::map<std::string, float>>& externalStyles) {
523 eve::Diagnostic::error(eve::DiagnosticCode::InvalidArgument, error.what(), "layers.parameters"));
538 for (const auto& [name, value] : definition.floatParameters) runtime->style().setFloat(name, value);
576 for (const auto& [name, curve] : curves_[index]) layer.style().setFloat(name, curve.evaluate(normalized));
582 const float current = cycle > 0.f ? std::clamp(layers_.front()->elapsed() / cycle, 0.f, 1.f) : 1.f;
598eve::Result<TrailAppendResult> MeshVfxAssetInstance::sampleTrail(const eve::IAttachmentPointSource& source) {
601 eve::DiagnosticCode::PreconditionViolation, "mesh VFX has no authored trail attachment binding", "trail"));
602 auto root = source.sampleAttachmentPoint(trailBinding_->rootAttachment, trailBinding_->rootOffset);
661 eve::Diagnostic::error(eve::DiagnosticCode::InvariantViolation, "mesh VFX asset revision exhausted", {}));
Owning, renderer-independent dynamic values.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Read-only cross-module view of animation events emitted by the latest simulation update....
Definition AnimationEventSource.h:14
Read-only cross-module contract for sampling named animated attachment points. @ownership Implementat...
Definition AttachmentPoint.h:22
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:67
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
Runtime state for a shader effect attached to a renderable mesh.
Definition MeshEffect.h:40
Owning runtime instantiated from one immutable MeshVfxAsset snapshot. @ownership Owns all layer runti...
Definition MeshVfxAsset.h:106
bool isFinished() const noexcept
True when every layer is Stopped or Finished.
Definition MeshVfxAsset.cpp:636
void stop(float fadeOutSeconds=-1.f)
Stop every layer using an optional fade override.
Definition MeshVfxAsset.cpp:563
TrailEmitter & trail()
Return the owned trail; throws when this asset has no trail.
Definition MeshVfxAsset.cpp:646
void update(float dtSeconds)
Advance every layer and the optional trail with caller-supplied simulation time.
Definition MeshVfxAsset.cpp:569
void bindTarget(MeshEffectTargetHandle target)
Bind every layer to the same authoritative target handle.
Definition MeshVfxAsset.cpp:550
MeshVfxAnimationDispatch processAnimationEvents(const eve::IAnimationEventSource &source)
Apply authored lifecycle mappings for events emitted by the latest animation update.
Definition MeshVfxAsset.cpp:612
std::vector< std::string > drainEvents()
Move all timeline events crossed since the previous drain.
Definition MeshVfxAsset.cpp:592
static eve::Result< std::unique_ptr< MeshVfxAssetInstance > > create(const MeshVfxAsset &asset)
Build independent runtime state for every asset layer.
Definition MeshVfxAsset.cpp:510
eve::Result< TrailAppendResult > sampleTrail(const eve::IAttachmentPointSource &source)
Sample authored root/tip attachments and append one trail segment.
Definition MeshVfxAsset.cpp:598
eve::Result< std::uint64_t > reload(std::string_view json)
Parse and atomically replace the asset on success.
Definition MeshVfxAsset.cpp:656
MeshVfxAssetSlot(MeshVfxAsset asset)
Construct a slot from an already validated asset.
Definition MeshVfxAsset.cpp:651
Deterministic CPU sampler and ribbon mesh generator for weapon trails.
Definition TrailEffect.h:55
Definition MeshVfxPackage.h:10
@ Finished
@ InvalidArgument
@ UnknownVersion
@ PreconditionViolation
@ InvariantViolation
@ Failed
Definition Container.h:602
Plain world-space point shared by animation consumers without a math-library dependency.
Definition AttachmentPoint.h:10
Summary of lifecycle actions dispatched from one animation event batch.
Definition MeshVfxAsset.h:57
std::size_t trailBreaks
Definition MeshVfxAsset.h:61
std::vector< std::string > play
Definition MeshVfxAsset.h:51
std::vector< std::string > trailBreak
Definition MeshVfxAsset.h:53
std::vector< std::string > stop
Definition MeshVfxAsset.h:52
Versioned, backend-neutral description of a real-time mesh effect.
Definition MeshVfxAsset.h:73
MeshVfxAnimationTriggers animationTriggers
Definition MeshVfxAsset.h:81
std::optional< MeshVfxTrailBinding > trailBinding
Definition MeshVfxAsset.h:79
static eve::Result< MeshVfxAsset > fromJson(std::string_view json)
Parse, migrate, and validate a JSON asset without mutating live state.
Definition MeshVfxAsset.cpp:273
eve::Result< void > validate() const
Validate all layer, playback, parameter, and trail invariants.
Definition MeshVfxAsset.cpp:428
static constexpr std::uint32_t schemaVersion
Definition MeshVfxAsset.h:75
std::vector< MeshVfxEventAsset > events
Definition MeshVfxAsset.h:80
std::vector< MeshVfxLayerAsset > layers
Definition MeshVfxAsset.h:77
static constexpr std::string_view schemaId
Definition MeshVfxAsset.h:74
eve::Result< std::string > toJson() const
Serialize this asset in canonical current-schema JSON form.
Definition MeshVfxAsset.cpp:344
float evaluate(float normalizedTime) const noexcept
Evaluate the curve at normalized time, clamped to its first and last keys.
Definition MeshVfxAsset.cpp:497
One normalized key in a deterministic float parameter curve.
Definition MeshVfxAsset.h:22