Allow users to provide image dimensions type/layers count in `ImageLoaderSettings`
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Makes the usage of stacked 2D array (and similar) textures much much easier and less error prone.
## What solution would you like?
Adding enum specifying texture type during asset loading to `ImageLoaderSettings`:
```rust
enum ImageDimensions {
D1,
D2,
D2Array(u32),
}
struct ImageLoaderSettings {
// ...
dimensions: ImageDimensions,
}
```
So it can be used after:
```rust
#[derive(Asset, AsBindGroup, Reflect, Debug, Default, Clone)]
struct MyMaterial {
#[texture(0, dimension = "2d_array")]
#[sampler(1)]
pub textures: Handle,
}
let textures = assets.load_with_settings("assets/2d_array.png", |s: &mut ImageLoaderSettings| {
s.dimentions = ImageDimensions::D2Array(3);
});
commands.spawn((
Mesh3d(mesh),
MeshMaterial3d(materials.add(MyMaterial { textures })),
));
```
## What alternative(s) have you considered?
The only alternative so far is to track when the image was loaded and call `reinterpret_stacked_2d_as_array` manually. But this requires a lot of boiler plate code and feels like a workaround. Also if there is any delay in calling `reinterpret_stacked_2d_as_array`, program will crash because shader expects 2d-array texture, but receives 2d texture.
Contributor guide
Research direction
Start by tracing ImageLoaderSettings and the existing reinterpret_stacked_2d_as_array path in the asset loading code. Define how the requested ImageDimensions value is propagated during loading, including the D2Array layer count, and verify that a 2D-array material receives the correct texture without manual post-load reinterpretation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100