bevyengine / bevyengine/bevy

Asset V2 - Error whilst loading GLTF files as dependencies

Open
#10,040 0 comments 0 reactions 0 assignees View on GitHub
A-Assets A-glTF A-Rendering C-Bug
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version

0.12-dev

## What you did

All code and assets can be found here: https://github.com/66OJ66/gltf_dependency_load_error

I'm attempting to create an AssetLoader for an asset with a GLTF dependency.
Crucically, this GLTF file has textures in separate files in a separate directory.

e.g. the file tree looks roughly like this:
- assets
- gltf
- cauldron.gltf
- cauldron.bin
- textures
- base_color.ktx2
- normal.ktx2

And the image URIs in the GLTF look like this:
`"uri":"../textures/normal.ktx2"`

(rationale for this: allows multiple GLTFs to share the same texture instead of each having their own copy)

The asset loader just converts between 2 types, and kicks-off a load for the GLTF asset
```rust
#[derive(Serialize, Deserialize)]
pub struct SerialisedItem {
id: u64,
name: String,
model_path: String,
}

#[derive(Asset, Clone, TypePath)]
pub struct Item {
pub id: u64,
pub name: String,
pub model: Handle,
}

impl AssetLoader for SerialisedItemAssetLoader {
// .....
fn load<'a>(
&'a self,
reader: &'a mut Reader,
_settings: &'a Self::Settings,
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result> {
Box::pin(async move {
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
let ron: SerialisedItem = ron::de::from_bytes(&bytes)?;

Ok(Item {
id: ron.id,
name: ron.name,
model: load_context.load(ron.model_path),
})
})
}
//.....
}
```

## What went wrong
I'm getting a 'path not found' error:
```rust
bevy_asset::server: path not found: gltf/../textures/normal.ktx2
```

The path is definitely valid though.

For example, in my repo I'm able to load the same GLTF file without any issues.
e.g.
```rust
let handle = asset_server.load("gltf/cauldron.gltf");
```

If I move the `ktx2` textures into the same folder as the GLTF (and update the URIs), the AssetLoader works without issue.

I've tried tracing through the code, the 'path not found' error originates from line 272 here:
https://github.com/bevyengine/bevy/blob/154a49044514fb21b0f83f4f077d76380e12a8a8/crates/bevy_asset/src/server/mod.rs#L271-L273

Digging deeper, the `ktx2` assets are returning `ProcessStatus::NonExistent` from line 922 here:
https://github.com/bevyengine/bevy/blob/154a49044514fb21b0f83f4f077d76380e12a8a8/crates/bevy_asset/src/processor/mod.rs#L911-L922

When I modify this code and set the assets to `ProcessStatus::Processed` instead, the code then errors out here:
https://github.com/bevyengine/bevy/blob/154a49044514fb21b0f83f4f077d76380e12a8a8/crates/bevy_asset/src/io/processor_gated.rs#L63

So for whatever reason, it seems that having '../' in the path means the `ktx2` assets aren't able to be processed/loaded.
Not sure if the dependencies of dependencies relationship is an issue?

Contributor guide

Open the contributing guide

Research direction

Start with the reproduction repository and the asset-loading paths cited in crates/bevy_asset/src/server/mod.rs, processor/mod.rs, and io/processor_gated.rs. Trace how the GLTF dependency path gltf/../textures/normal.ktx2 is processed, then verify that the reproduction loads external textures successfully without changing their directory layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.