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

Secondary Meshes from GLb disappearing based on camera movement #11131

Open
angelorodem opened this issue Dec 29, 2023 · 9 comments
Open

Secondary Meshes from GLb disappearing based on camera movement #11131

angelorodem opened this issue Dec 29, 2023 · 9 comments
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@angelorodem
Copy link

angelorodem commented Dec 29, 2023

Bevy version

0.12.1

[Optional] Relevant system information

  • latest nightly rust
  • Windows 11
    (Issue still happens on stable rust)
`AdapterInfo { name: "NVIDIA GeForce RTX 3070", vendor: 4318, device: 9348, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "546.17", backend: Vulkan }`

What you did

Spawned two entities, from two different GLb, they contain meshes, textures and animations.
There is no mesh changes, the camera code is:

commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(CAMERA_DISTANCE, CAMERA_DISTANCE, CAMERA_DISTANCE),
        ..Default::default()
    });

extra code related to the camera just moves its transform to follow the player, and look at it.

Entity bundles:

#[derive(Bundle)]
pub struct PlayerBundle {
    model: SceneBundle,
    name: NameComponent,
    health: HealthComponent,
    tag: PlayerTag,
    movable: Movable,
    movable_animation: AnimatedCharacterMovable,
}

i just command.spawn the entities, animate them using the AnimationPlayer and move their transform around the scene, no other logic.

What went wrong

If it's not clear, break this out into:

  • what were you expecting?
    Skeleton helmet red mesh to behave normally

  • what actually happened?
    Its vanishing, as the camera moves.

Additional information

Issue seems similar to this one:
Issue
But using the component NoFrustrumCulling did not have effect as indicated in the workarounds.

  • The item that pops, seems to not cast shadow?
  • i have tried adding NoFrustumCulling to the component but it did not have effect.
Video.mp4
Video.mp4
Video.mp4
@angelorodem angelorodem added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Dec 29, 2023
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Dec 29, 2023
@alice-i-cecile
Copy link
Member

Are you able to upload a scene that you can use to reproduce this issue?

@angelorodem
Copy link
Author

angelorodem commented Dec 29, 2023

Thanks for the quick response @alice-i-cecile , its not an MVC but it should give the exact replication (project still super small).
https://github.com/angelorodem/bevy_test

Notes:
The bug still happens if

  • Msaa::Off is not specified
  • EditorPlugin, TweeningPlugin, (Diagnostics), TemporalAntiAliasPlugin are removed
  • Extra camera settings not specified in the above snipped, like bloom, SSAO, TAA are removed

@nicopap
Copy link
Contributor

nicopap commented Dec 30, 2023

Looks like a duplicate of #4971. The default pause is possibly not the "rest" pose of the mesh, moving the bounding box.

@angelorodem
Copy link
Author

angelorodem commented Dec 30, 2023

@nicopap, in the last video that i recorded, i have added NoFrustrumCulling and also turned animations off, in theory by the other issue it should "mitigate" the issue, but i had no effect, the mesh still disappeared

i initially had a theory that the culling algorithm was done by checking if the origin point of the mesh was hidden (which i think does not make much sense) and the ground plane was hidding it, but even with no ground plane or making the whole component on top of the plane did not change the behavior.

The way it flickers makes me a little lost on trying to find the root cause. i also investigated the GLb but it seems fine too.

@angelorodem
Copy link
Author

After playing a little i found that the other GLb components vanish when the skeleton character is not facing (in some degree) the camera,
all the GLb meshes origins are correctly at 0,0,0, i'm not sure why items are removed when the character is faced backwards to the camera.

Video.mp4

@angelorodem
Copy link
Author

If you need any new information to aid fixing this issue, please let me know

@PixelDoted
Copy link

Here's a hack that might fix it (it worked on https://github.com/angelorodem/bevy_test and another project)

pub fn recalculate_skinned_aabb(
    inverse_bindposes: Res<Assets<SkinnedMeshInverseBindposes>>,
    mut query: Query<(&Name, &SkinnedMesh, &mut Aabb), Added<Aabb>>,
) {
    // HACK:
    for (name, skinned_mesh, mut aabb) in query.iter_mut() {
        let Some(inverse_bindposes) = inverse_bindposes.get(&skinned_mesh.inverse_bindposes) else {
            continue;
        };

        let mut inverse_bindpose = inverse_bindposes[0]; // `0` probably won't work in all cases

        // multiplying by `inverse_bindpose` seems to be the standard (https://github.com/KhronosGroup/glTF-Blender-IO/issues/1887)
        aabb.center = (inverse_bindpose * aabb.center.extend(0.0)).into();
        aabb.half_extents = (inverse_bindpose * aabb.half_extents.extend(0.0)).into();
    }
}

@DylanRJohnston
Copy link

DylanRJohnston commented Apr 11, 2024

Hey @PixelDoted, I'm experiencing this exact same issue where animated entities in gltf scenes exported from Blender have incorrectly scaled / displaced AABBs within bevy causing culling issues. This seems like something the gltf loader should handle automatically?

Screenshot 2024-04-11 at 10 25 56 am

Those floating bounding boxes in space to the left of the scene come from the animated characters towards the center. If the camera orbits to the left, parts of the meshes of those characters are culled incorrectly.

@DylanRJohnston
Copy link

Can confirm that your system for using the inverse bindposes is correct. Screenshot 2024-04-11 at 12 51 00 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

No branches or pull requests

5 participants