Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat BVH animation data as an asset and create an asset loader for it #16

Closed
nixon-voxell opened this issue Apr 8, 2024 · 1 comment · Fixed by #21
Closed

Treat BVH animation data as an asset and create an asset loader for it #16

nixon-voxell opened this issue Apr 8, 2024 · 1 comment · Fixed by #21
Assignees
Labels
Milestone

Comments

@nixon-voxell
Copy link
Collaborator

nixon-voxell commented Apr 8, 2024

The Idea

At the moment, BVH data is loaded and stored inside a Bevy resource struct as a list:

#[derive(Resource)]
pub struct BvhData {
    pub bvh_animation: Vec<Bvh>,
}

This approach left developers unable to reference a unique Bvh animation without risking the chances of it being removed or moved as the only approach right now is to store the index of that Bvh animation.

Example

During runtime, an index might be used to reference a specific Bvh animation in the bvh_animation list:

let index = None;
for i in 0..bvh_animation.len() {
    // find specific bvh animation
    if xxx == yyy {
        index = Some(i);
        break;
    }
}

The specific index that is being extracted might not stay true if something like this happen during runtime:

bvh_animation.insert(0, new_bvh);

This is a hypothetical situation that may or may not happen for whatever reason, but knowing that such a simple innocent insert operation might cause a seemingly untraceable bug is mind-boggling!

Proposed Solution

We treat every Bvh animation as an asset (a simplified sample). Instead of storing indices pointing to a specific animation, we use Bevy's asset Handle<T> system.

This will guarantee us a unique pointer towards the Bvh animation asset and tell us when it is missing.

Bevy Handle<T> doc: https://docs.rs/bevy/latest/bevy/prelude/enum.Handle.html
Bevy Assets doc:

@nixon-voxell nixon-voxell added the good first issue Good for newcomers label Apr 8, 2024
@nixon-voxell nixon-voxell changed the title Treat BVH animation data as an asset and create and asset loader for it Treat BVH animation data as an asset and create an asset loader for it Apr 8, 2024
@ConquerorFY
Copy link
Collaborator

ConquerorFY commented Apr 13, 2024

Can check out branch and see @nixon-voxell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
2 participants