Skip to content

Async-friendly layer loading (let the host provide the bytes) #105

Description

@bresilla

Now that so much has moved into openusd, I want to restructure bevy_openusd properly and get it integrated way tighter with Bevy's AssetLoader / asset system. One thing's worth sorting out first.

Bevy reads files through its own async asset layer (folder, zip, remote, cache - whatever the app sets up), not straight off disk. Right now I dump the bytes into a tempfile just so Stage::open has a real path. It works but it's ugly, and openusd ends up reading every sublayer/reference/texture off disk itself instead of through Bevy, so I lose hot-reload, dedup, and loading from non-disk sources.

The ar::Resolver is already almost what I need, I can plug one in. The problem is it's sync and my bytes arrive async, so I'd have to block_on inside the loader, which I don't love.

What I'd want is some async way to drive layer collection where the host hands openusd the bytes, so it never reads from disk itself and doesn't tie in a specific async runtime.

Useful beyond just me too - anything reading from somewhere that isn't the local filesystem (an editor with unsaved layers in memory, a networked store, a custom resolver). And it's the same idea as the task-queue indexer you're doing, just on the I/O side: keep the logic pure, let something outside drive it.

Doesn't look like a big change either. open_layer already reads the whole file into memory and parses from a Cursor, so the async part only has to cover "get me the bytes for this layer" - no seeking, and pcp doesn't change since it runs on the layers after they're loaded. collect could split into a pure part, the current sync path as a thin driver, plus an async one for cases like mine.

Does this seem reasonable @mxpv? And does it clash with #103 at all? Based on quick view, it seems not, this is quite isolated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions