Replies: 1 comment 6 replies
-
I definitely want us to support alternative asset servers (even though I don't think it's necessary here, see below. Unfortunately today our asset system and the asset server are somewhat coupled - namely asset handles store a bunch of stuff that is only relevant to the asset server. I would love it if we separated the AssetServer and configured it out. Pretty much all of this can be done as an asset source. I don't think this needs to be a new AssetServer. An AssetReader can internally store the pack manifest as a
There are two problems with this:
There's a reason for all these pieces. For example, the rendering folks have been loving the web asset source. I think you'd have to pry it from their cold, dead hands if you wanted to remove it. If this whole system already supports packed assets, then that's a good thing, and AFAIK it does.
You can do this with another asset source: make a new
These are not "nested files". These are subassets - assets that live in the same file as another asset. Subassets suck for a lot of reasons, but they are also kinda necessary: glTF files store a bunch of assets all in one file. It is difficult to just load one of these subassets: here's an issue for that #21641. I've tried starting a zip asset source, which would essentially be our "asset pack", but I ran into some blockers: #21641 (comment). As for composing these packs, we could also provide tooling for that. That seems fine. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've found myself having to bypass the AssetServer entirely for working with packed assets for a few reasons, and I'd like to give feedback as to why and propose some changes as to what could make a future PackedAssetServer (or something similar) work better. In general, the AssetServer is built around accessing loose raw files by name and path, which breaks almost immediately when dealing with packed assets, even when providing a custom AssetSource.
For context, these are some of the design goals for my personal implementation of asset packing:
Pack Composition. Assets can be distributed arbitrarily across multiple packs and composed later. Packs may be divided by file type, or they could be divided semantically (e.g. assets for a particular DLC). It is not necessary to know what source pack file an asset is from in order to load that asset.
Pack Compression/Encryption. The entire pack file is compressed. This is fairly straightforward. This doesn't clash with the AssetServer/AssetLoader system since you can have your AssetLoader decompress the raw bytes just fine. Packs can also be encrypted for niche cases, which follows the same flow as decompression.
Hashed Paths Only. Packs contain no string paths, only a u32 or u64 hash ID for that file. I use fnv1a because of the
const-fnv1a-hashcrate that allows me to hardcode hashes in the binary without leaking names. The ID is a hash of the loose file path of the source file. These hashes can be salted to help confound datamining.Asset Pack vs. Asset Source Directory. Loose files live in an asset source directory separate from the canonical Bevy
assetsdirectory. An offline tool crawls the asset source directory and builds the packs that then live in theassetsdirectory. A game binary then ships with the packed assets in theassetsdirectory, and no loose files.Loose File Dev Mode. The pack system can be disabled and transparently switched to load loose files at runtime for dev iteration. This is gated behind a feature flag and this functionality is stripped from retail builds. In loose loading mode, the asset loader crawls the source directory and conjures a pseudo-pack of all those files that then goes through the normal hash-access lookup approach.
I think these are relatively standard among asset packing approaches in other engines, both public and proprietary. It is unusual to ship loose files with a game in a professional engine. As a note, I'm aware of
bevy_asset_packer, and it has some similar goals, but it uses a single pack instead of multiple merged packs, and also uses memory mapping which isn't always portable (or safe). It also has no loose file mode.The AssetServer makes it difficult to accomplish this goal currently, due to having a few assumptions:
path/to/file.ext#nested). If instead there was an API that allows you to provide two hashes, one for the file path, and an optional nested file ID hash, it would alleviate this problem.async-fsto open files, process them myself inline, and dump them intoResMut<Assets<T>>handles than to do all of the work to make a customAssetSource,AssetReader,AssetLoader, etc.I'm not sure if the best approach is an alternate asset server, but it does seem appealing to have two of them. A LooseAssetServer or BasicAssetServer for dev or small games where this isn't an issue, and a PackedAssetServer for larger shipping builds. If the two were API-interchangeable for loading files, you could make the statement that the PackedAssetServer doesn't support things like asset processing or content watching/hot reloading.
Beta Was this translation helpful? Give feedback.
All reactions