Add BSN asset catalog: load, save, and labeled sub-asset registration#23648
Draft
jbuehler23 wants to merge 2 commits into
Draft
Add BSN asset catalog: load, save, and labeled sub-asset registration#23648jbuehler23 wants to merge 2 commits into
jbuehler23 wants to merge 2 commits into
Conversation
6 tasks
Contributor
I believe that's item 4 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
Addresses item 3 in #23637: BSN asset catalog loading and serialization.
Depends on #23576 (@pcwalton's dynamic BSN) - so a lot of the changes are duplicated here, and looks larger than it actually is!
Solution
Adds a BSN asset catalog module to
bevy_scene2for managing named assets in.bsnformat.What this adds!
1. Runtime loading (
load_bsn_assets)Parses BSN text containing named asset definitions and inserts them into
Assets<T>stores via reflection. Nothing triggers automatically, you call this when you need to load a catalog at runtime (ie, editor startup, level load).2. Serialization (
serialize_assets_to_bsn)Serializes named assets from the world back to BSN text. Uses default diffing so only non-default fields are written.
Handlefields are resolved to asset path strings. Nothing saves automatically - you call this when you want to persist your asset catalog (ie, on "save" in the editor).3. Automatic labeled sub-asset registration (in
DynamicBsnLoader)When a .bsn file is loaded through the asset server, named entries that are asset types (types with
ReflectAsset+ReflectDefaulttype data) are automatically registered as labeled sub-assets:The asset server loads the parent .bsn file, the
DynamicBsnLoaderscans the AST for named asset entries, creates them via reflection, and registers them as labeled sub-assets. This happens automatically.bevy_assetadditionsReflectAsset::into_loaded_asset()- convert a reflected asset value into anErasedLoadedAssetfor sub-asset registrationLoadContext::add_loaded_labeled_asset_erased()- type-erased version of add_loaded_labeled_asset for reflection-based asset creationExample
Example catalog file (assets/scenes/material_catalog.bsn)
Only non-default fields are written! (metallic: 0.0 is omitted for
RoughStonesince it's the default).Example loads four named materials from the catalog, and displays them on spheres with different PBR properties. You will see that it "loaded" the assets on startup, and then on save you will see the BSN asset catalog get written.
This is a port of
Jackdaw's shared asset catalogue in JSN, for BSN!