Skip to content

Support render_animation for ExtendedMaterials #49

@Szustarol

Description

@Szustarol

Hi! Thanks for the wonderful work.
I think in many cases, especially in 3D, it is not needed to create a separate material and write a custom wgsl script for each displayed element. Indeed, bevy has the MaterialExtension trait exactly for that purpose.
However, currently render_animation<MeshMaterial3d<T>> only takes T such that they implement Material. It would be great if we could also use MaterialExtension, this way we can just use standard materials for most use cases like this:

#[derive(Asset, TypePath, AsBindGroup, Debug, Clone, Default)]
pub struct WorldStandardAnimatedMaterial {
    pub base_color_texture: Option<Handle<Image>>,
}

impl MaterialExtension for WorldStandardAnimatedMaterial {}

impl RenderAnimation for WorldStandardAnimatedMaterial {
    type Extra<'e> = (Res<'e, Time>, Res<'e, Assets<TextureAtlasLayout>>);

    fn render_animation(
        &mut self,
        aseprite: &Aseprite,
        state: &AnimationState,
        extra: &mut Self::Extra<'_>,
    ) {
        let Some(atlas_layout) = extra.1.get(&aseprite.atlas_layout) else {
            return;
        };

        self.base_color_texture = Some(aseprite.atlas_image.clone());
    }
}

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