Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

load/link assets to handles defined in scene files. #4358

Open
oddfacade opened this issue Mar 28, 2022 · 1 comment
Open

load/link assets to handles defined in scene files. #4358

oddfacade opened this issue Mar 28, 2022 · 1 comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Scenes Serialized ECS data stored on the disk C-Feature A new feature, making something new possible

Comments

@oddfacade
Copy link
Contributor

oddfacade commented Mar 28, 2022

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

When a scene is loaded from a file, any asset handle components attached to its entities are spawned as weak references. There is no mechanism to trigger asset loads from scene files or otherwise link handles with loaded assets. This inability to define entire scenes complete with meshes, materials, etc. is a significant roadblock to developing scene editors and other such external tooling.

What solution would you like?

I see two potential ways to do this.

  1. The "proxy" approach: Define a new "proxy" handle type which contains an asset path and loads the corresponding asset when the DynamicScene is spawned, attaching the resulting Handle component in its place. This would probably necessitate a special case in DynamicScene::write_to_world that checks if each "component" (which now would not necessarily be a component) has a special "proxy component" data type registration thing.
  2. The "link" approach: Upgrade weak handles to strong handles at scene spawn. In general principle, "change all components that implement a certain trait based on world data" is something that the entity mapping step is already doing, so we could borrow from that feature, either by implementing a parallel feature that works similarly but independently or by unifying the two features behind a more abstract "spawn hook" feature. The scene file format would probably have to be extended to provide a way to declare asset dependencies, since the handles don't provide a full path to load assets with.

What alternative(s) have you considered?

  • The GLTF loader already produces strong Handles for its meshes, materials, etc., so there are workarounds involving injecting components into the entities that it loads in. I think this is roughly what @nicopap 's bevy scene hook does. This approach could potentially be aided by defining some sort of structured metadata that we look for in the GLTF file's various "extras" fields (see gltf extras component #2153).
  • @sdfgeoff 's blender bevy toolkit does something sort of like (1) the "proxy" approach above, except the "proxies" are actually components that get loaded as normal, and are queried and resolved/replaced with a handles by special systems. The benefit of this approach is that it doesn't require modifying bevy's internals at all, but since the proxy "resolution" happens after the dynamic scene is spawned, it requires a system to be loaded at runtime for each type of asset.

Additional context

@oddfacade oddfacade added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Mar 28, 2022
@sdfgeoff
Copy link
Contributor

It's worth mentioning this discussion: #3940 which means it is possible for a single asset to load/reference/link to other assets. However, as you say, the current scene format doesn't seem to support it in any way.

@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds A-Scenes Serialized ECS data stored on the disk and removed S-Needs-Triage This issue needs to be labelled labels Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Assets Load files from disk to use for things like images, models, and sounds A-Scenes Serialized ECS data stored on the disk C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

3 participants