Giter Club home page Giter Club logo

bevy_spritesheet_animation's Issues

3d: frame rate drops significantly with a lot of sprites possibly due to StandardMaterial not being reused

Every sprite entity gets a new material even:

commands.entity(entity).insert(materials.add(material));

I think this causes the frame rate to drop.

In a similar way to what is done in bevy_sprite3d, https://github.com/FraserLee/bevy_sprite3d/blob/ce57326ff63b1dae99cd2595422672bc82b22325/src/lib.rs#L297-L309, I think we need to use a material cache and return that handle if all of our props match.

It can be done in a separate issue, but if you do go down this path, it would be good to support unlit and alpha_mode from the outside, and so from the beginning make those part of the material key.

I haven't tried to change this locally to add a cache, so it's possible this isn't going to help, but even in other Bevy examples where I spawn identical 100 cubes and incorrectly create a new material for every cube I instantly see a frame rate drop. When I change to reuse the same material handle, the frame rate comes back up.

SpritesheetLibrary::new_clip

Had some issues with this method.

  • You cannot make marker IDs in the method because the library is borrowed as mutable to call new_clip. A reference to the library from within the closure would solve that.
  • You cannot access anything mutably in the closure since it's a Fn method. It should only need to be a FnOnce.

Thoughts on using std::time::Duration instead of u32 + "milliseconds" in docs

E.g. in

pub enum AnimationDuration {
/// Specifies the duration of each frame in milliseconds
PerFrame(u32),
/// Specifies the duration of one animation cycle in milliseconds
PerCycle(u32),
}

Callers rely on reading the docs to see that the duration needs to be milliseconds (mistakes are possibly easier to make, too).

Would it be worth using https://doc.rust-lang.org/std/time/struct.Duration.html? This would make callers look something like:

let clip_id = library.new_clip(|clip| {
    clip..set_default_duration(AnimationDuration::PerFrame(Duration::from_millis(100)));
});

(untested).

I know it's more verbose, but it takes the hard-coded millis out of the crate and (arguably) makes the crate less opinionated on the duration format.

Asset loader

By any chance have you created an asset loader that works with this crate?

It's possible that the space is too opinionated at least for this crate to provide an asset loader, but I was curious if you've been using this crate with an asset loader?

I wonder if at the very least we need serde support so we can create clips and animations from RON files, for example? Again, I guess it's possible that is something that this crate should not support and those serialization types and the loader should all be created as 3rd party to this.

Support variants / frame sets

I want to be able to create an animation which is made up of a bunch of frames, but which has a number of variants of those same frames.

This is for billboard sprites in a 3D game where each variant is for one of 8 directions.

So if you have a walk animation made up of 3 frames, you want to pick the 3 frames for the current variant.

Calling systems can set the current variant every frame (if they like). For example, a system might update the current variant to match the relative direction of the sprite to the camera^.

I don't think it's possible to use the current features of the crate for one main reason. We need to preserve the existing animation and state rather than asking callers changing the animation_id or inserting a new animation so that the animation doesn't reset. Imagine a walk animation is playing. If the camera instantaneously rotates, you want the character's same foot to remain on the ground. I.e. you want to keep playing your walk animation, you just want to switch variants.

I am not sure if there's an industry term for this, but I'm using the term variants. Frame sets may also be a term for this, I'm not sure.

Are you interested in working on a design for this with me?

^ Simplified system that updates the sprite's animation variant to correspond with the camera's transform relative to the sprite

fn update_sprite_directions(
    // ...
) {
    for (mut animation) in q.iter_mut() {
        let direction_count = animation.variant_count as f32;

        let direction = 0.0 // calculate direction ...

        // Callers just need to update the variant they want to show.
        animation.current_variant = direction.floor() as usize;
    }
}

Resetting animations

Currently it does not seem possible to reset animations on an entity (neither reset in-progress animations, nor restart animations that ended). It looks like this could be done by making SpritesheetAnimator public and adding a reset_animation(entity) method.

Ability to start an animation from a specific frame.

I am currently using this library to orchestrate a set of directional animations, and it is great at what it does.

I have one question tho, regarding the usage of the library - I'd like to not only change the animation - but also be able to change the frame the animation starts on, this is specifically important for things like bullet animations, where one would maybe want to randomize the starting sprite, or - in my case - the animation of a character rolling, changing the direction of the roll results in the whole animation restarting, which can be quite immersion breaking.

Any ideas how one might be able to solve this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.