载入中...
搜索中...
未找到
VegetationSceneInstance.cpp
浏览该文件的文档.
2
3#include <algorithm>
4#include <cctype>
5#include <new>
6
7namespace eve::asset_graphics {
8namespace {
9std::string folded(std::string value) {
10 for (char& character : value) character = static_cast<char>(std::tolower(static_cast<unsigned char>(character)));
11 return value;
12}
13} // namespace
14
16 const AssetRef& sceneTemplate, const asset::EvpackCapabilities& capabilities) const {
17 auto scene = asset_scene::EvpackSceneTemplateLoader(reader_).load(sceneTemplate, capabilities);
19 if (scene.value().sourceGuid.empty())
21 DiagnosticCode::Unsupported, "legacy Scene Template has no source GUID for manager association",
22 sceneTemplate.format(), {}, "asset.graphics.vegetation-scene-instance"));
23 auto candidates = reader_.listAssets("eve.vegetation-scene/1", capabilities, 4096);
24 if (!candidates) return Result<VegetationSceneAssociation>::failure(candidates.status());
25 std::optional<LoadedVegetationScene> match;
26 const auto expected = folded(scene.value().sourceGuid);
27 for (const auto& candidate : candidates.value()) {
28 auto manager = EvpackVegetationSceneLoader(reader_).load(candidate, capabilities);
29 if (!manager) return Result<VegetationSceneAssociation>::failure(manager.status());
30 if (folded(manager.value().sourceGuid) != expected) continue;
31 if (match)
33 Diagnostic::error(DiagnosticCode::Conflict, "Scene Template matches multiple vegetation managers",
34 sceneTemplate.format(), {}, "asset.graphics.vegetation-scene-instance"));
35 match.emplace(std::move(manager).takeValue());
36 }
37 if (!match)
39 Diagnostic::error(DiagnosticCode::NotFound, "Scene Template has no vegetation manager",
40 sceneTemplate.format(), {}, "asset.graphics.vegetation-scene-instance"));
41 auto masks = loadVegetationSceneElementMasks(reader_, *match, capabilities);
42 if (!masks) return Result<VegetationSceneAssociation>::failure(masks.status());
44 {std::move(scene).takeValue(), std::move(*match), std::move(masks).takeValue()});
45}
46
49 const AssetRef& sceneTemplate, const asset::EvpackCapabilities& capabilities,
51 const VegetationSceneGpuBuild& build, std::uint64_t owner) {
52 auto association = VegetationSceneAssociationLoader(reader).load(sceneTemplate, capabilities);
53 if (!association) return Result<std::unique_ptr<VegetationSceneInstance>>::failure(association.status());
54 auto runtime = VegetationSceneGpuRuntime::create(factory, baseSurface, baseMotion, association.value().manager,
55 association.value().masks, build);
56 if (!runtime) return Result<std::unique_ptr<VegetationSceneInstance>>::failure(runtime.status());
57 auto live = VegetationSceneLiveElements::create(association.value().manager, owner);
58 if (!live) return Result<std::unique_ptr<VegetationSceneInstance>>::failure(live.status());
59 try {
60 auto result = std::unique_ptr<VegetationSceneInstance>(new VegetationSceneInstance(
61 std::move(association).takeValue(), std::move(baseSurface), std::move(baseMotion),
62 std::move(runtime).takeValue(), std::move(live).takeValue()));
63 return Result<std::unique_ptr<VegetationSceneInstance>>::success(std::move(result));
64 } catch (const std::bad_alloc&) {
66 Diagnostic::error(DiagnosticCode::Failed, "vegetation scene instance allocation failed", {}, {},
67 "asset.graphics.vegetation-scene-instance"));
68 }
69}
70
72 std::uint64_t expectedRevision, const VegetationSceneElement& element,
73 const VegetationSceneGpuBuild& build) {
74 return liveElements_->registerElement(expectedRevision, runtime_->sourceRevision(), element, *runtime_,
75 baseSurface_, baseMotion_, association_.masks, build);
76}
77
79 std::uint64_t expectedRevision, VegetationSceneElementHandle handle, const VegetationSceneGpuBuild& build) {
80 return liveElements_->withdrawElement(expectedRevision, runtime_->sourceRevision(), handle, *runtime_,
81 baseSurface_, baseMotion_, association_.masks, build);
82}
83
84} // namespace eve::asset_graphics
double value
std::weak_ptr< PrimitiveScene > scene
PrimitiveHandle handle
std::string element
Automatic Scene Template to TVE manager runtime association.
Stable asset identity backed by PersistentId.
Definition ResourceRef.h:53
std::string format() const
Return canonical asset://<uuid> text.
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
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Immutable reader retaining an admitted pack by shared ownership.
Result< std::vector< AssetRef > > listAssets(std::string_view expectedType, const EvpackCapabilities &capabilities, std::uint32_t maximumAssets=1 '000 '000) const
List stable assets providing an exact type/version for the selected runtime variant.
Strict capability-aware decoder for eve.vegetation-scene/1.
Result< LoadedVegetationScene > load(const AssetRef &asset, const asset::EvpackCapabilities &capabilities, std::uint64_t maximumDecodedBytes=1024 *1024) const
Decode and validate one complete scene state without mutating runtime objects.
Resolve a Scene Template to exactly one manager asset in the same admitted EVPACK.
Result< VegetationSceneAssociation > load(const AssetRef &sceneTemplate, const asset::EvpackCapabilities &capabilities) const
Load the template, find the unique manager with the same Unity source GUID, and decode all Element ma...
Instance-qualified handle for one dynamically registered TVE Element volume.
static Result< std::unique_ptr< VegetationSceneGpuRuntime > > create(graphics::IResourceFactory &factory, const graphics::PbrSurface &baseSurface, const graphics::VegetationMotion &baseMotion, const LoadedVegetationScene &scene, const std::map< std::string, graphics::VegetationMask > &masks, const VegetationSceneGpuBuild &build)
Bake, convert, upload and bind all field layers as one atomic candidate.
Owning executable instance coupling one Scene Template, its manager fields and live Element registry....
Result< VegetationSceneElementPublication > withdrawElement(std::uint64_t expectedRevision, VegetationSceneElementHandle handle, const VegetationSceneGpuBuild &build)
Withdraw one live Element and republish this associated instance atomically.
static Result< std::unique_ptr< VegetationSceneInstance > > create(const asset::EvpackResourceReader &reader, graphics::IResourceFactory &factory, const AssetRef &sceneTemplate, const asset::EvpackCapabilities &capabilities, graphics::PbrSurface baseSurface, graphics::VegetationMotion baseMotion, const VegetationSceneGpuBuild &build, std::uint64_t owner)
Resolve and publish the manager automatically from a Scene Template asset.
Result< VegetationSceneElementPublication > registerElement(std::uint64_t expectedRevision, const VegetationSceneElement &element, const VegetationSceneGpuBuild &build)
Register one live Element and republish this associated instance atomically.
static Result< std::unique_ptr< VegetationSceneLiveElements > > create(LoadedVegetationScene baseScene, std::uint64_t owner)
Create a registry from one validated imported scene.
Capability-aware scene-template/3 decoder with explicit scene-template/2 compatibility.
Result< LoadedSceneTemplate > load(const AssetRef &sceneTemplate, const asset::EvpackCapabilities &capabilities, const SceneTemplateLoadLimits &limits={}) const
Validate identities, hierarchy and finite TRS values before building a tree.
Texture / mesh / shader / canvas creation and release.
Result< std::map< std::string, graphics::VegetationMask > > loadVegetationSceneElementMasks(const asset::EvpackResourceReader &reader, const LoadedVegetationScene &scene, const asset::EvpackCapabilities &capabilities, std::uint64_t maximumDecodedBytes)
Decode every runtime texture used by admitted TVE Element shaders into owning linear masks.
Actual runtime device capabilities used for variant selection.
Definition Evpack.h:92
std::map< std::string, graphics::VegetationMask > masks
One normalized Unity TVEElement definition awaiting texture realization.
Explicit detached inputs for publishing all nine TVE scene-manager field layers.
Owning material parameter snapshot; texture pointers remain borrowed. Base color/metallic/roughness c...
Definition PbrSurface.h:218
Source-equivalent plant motion parameters with explicit time and texture inputs. All data is owned....