Closed PastMoments closed 2 years ago
Since the last plugin version, you can handle part of what you want with some const generics magic:
struct ColorStandardMaterial<const R: u8, const G: u8, const B: u8, const A: u8> {
pub handle: Handle<StandardMaterial>,
}
impl<const R: u8, const G: u8, const B: u8, const A: u8> FromWorld
for ColorStandardMaterial<R, G, B, A>
{
fn from_world(world: &mut World) -> Self {
let mut materials = world
.get_resource_mut::<Assets<StandardMaterial>>()
.unwrap();
ColorStandardMaterial {
handle: materials.add(StandardMaterial::from(Color::rgba_u8(R, G, B, A))),
}
}
}
Then just add that type with your color as fields on an asset collection:
#[derive(AssetCollection)]
struct MyAssets {
red_standard_material: ColorStandardMaterial<{ u8::MAX }, 0, 0, 0>,
blue_standard_material: ColorStandardMaterial<0, 0, { u8::MAX }, 0>,
}
I want to offer more possibilities to load custom assets, especially as dynamic assets. But I will probably not support cases like this with new derive attributes. That would get too much.
I opened an issue for custom dynamic assets in general #55
With that I would close this issue here, considering that the const generic approach already works. Any more complex standard material could be loaded as a dynamic asset with #55.
This plugin has been very helpful so far. However, I have a use case that is a little annoying to work around.
From what I understand, currently with StandardMaterial it is possible to do
However, I have a resource that has a combination of materials from an image, and some that are just a base colour, as well as with default. I know this plugin focuses mainly focuses on loading assets, but being able to manage assets like this without boilerplate would be immensely useful.