Skip to content

Provide an API for getting the full path of a file loaded by the FileAssetReader #19695

Open
@janhohenheim

Description

@janhohenheim

What problem does this solve or what need does it fill?

I use BRP to recreate parts of the client app in the server. The client app may load arbitrary glTFs, and I want to load them as well. This is not a security concern or anything, the end-user uses the BRP-server program on their own machine for their own client.

So, I need to know the path for where to load the assets from. For the moment, I'm fine with just loading plain old files from disk. No Wasm support, no android support, no processed files, just plain old models stored in the assets dir.

But how do I get there? Well, the best way I have found is

  • Use FileAssetReader::get_base_path to get the base path, like /home/hohenheim/games/grand-theft-bevy/
  • At plugin creation time, fetch the AssetsPlugin and use AssetPlugin::file_path (misleading name and misleading docs) to get the relative path from the base path to the directory where the virtual file system takes root
    • Put that in a Resource for later use
  • On SceneRoot insertion, use scene_root.path()?.path() (sic) to get the virtual filesystem path
  • Combine all of these to get the full path
  • Call fs::canonicalize on it if we are feeling fancy

What solution would you like?

Some API that returns a Result for getting the full path of an asset if and only if it was loaded from disk with a FileAssetReader.

What alternative(s) have you considered?

Just leave it, I guess?

Additional context

This will probably be important for editor development as well, if we wish to automatically load the same assets as a running program.

Also note that any solution involving fetching the AssetReader for a given asset will not currently work, as it cannot be downcast due to not being dyn compatible / object safe. We would need to add as_foo_reader methods for that to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsA-EditorGraphical tools to make Bevy gamesC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions