bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.29k stars 3.48k forks source link

Gltf scene is not properly rendered. #6679

Closed AllenDang closed 1 year ago

AllenDang commented 1 year ago

Bevy version

0.9.0

[Optional] Relevant system information

If you cannot get Bevy to build or run on your machine, please include:

What you did

Load a gltf scene from file.

What went wrong

image

image

Additional information

Here is a minimal code to reproduce. Make sure to enable "jpeg" feature for bevy in Cargo.toml.

use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

/// set up a simple 3D scene
fn setup(mut commands: Commands, server: ResMut<AssetServer>) {
    // load asset
    commands.spawn((SceneBundle {
        scene: server.load("/Users/allen/Downloads/shu.glb#Scene0"),
        ..default()
    },));

    // camera
    commands.spawn(Camera3dBundle {
        transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
        ..default()
    });
}

Here is the gltf model to repo. shu.glb.zip

AllenDang commented 1 year ago

@alice-i-cecile I know the core dev of bevy may not have time to fix it now, I'm wondering if you or anyone could give me a hint about where should I start to look at, I could start fixing this and contribute a PR.

alice-i-cecile commented 1 year ago

This looks like a gltf file with multiple sub-scenes. Have you tried changing or removing #scene0?

AllenDang commented 1 year ago

@alice-i-cecile Removing #scene0 still the same.

alice-i-cecile commented 1 year ago

And changing it to e.g. #scene1? Does that change what's displayed? Are there multiple scenes withing the gltf file?

AllenDang commented 1 year ago

@alice-i-cecile I'm loading it directly with file path and omit #scene section like server.load(path). I think all meshes are loaded, because I can read all kind of information like face count, vertex and AABB from them, just cannot see them.

alice-i-cecile commented 1 year ago

@mockersf you've looked into 3D much more than I have; any ideas on where to look?

mockersf commented 1 year ago

after opening the glb file in blender and re-exporting it, I get something similar to the online gltf viewer:

Screenshot 2022-12-05 at 02 04 27

and when moving the camera inside the cube

Screenshot 2022-12-05 at 02 03 59

Do you know how the original gltf file was produced? Would it be possible to create a smaller file showing the same kind of issue?

AllenDang commented 1 year ago

@mockersf It is created by Blender. Here is the blender file. lowpoly_final.blend.zip

mockersf commented 1 year ago

@AllenDang there are two scenes in your blender file (and your glb too I guess)

Screenshot 2022-12-05 at 10 00 49

If in blender you delete the "Library" scene, or if you try to display the second scene in Bevy, you will get what you expect.

AllenDang commented 1 year ago

@mockersf I think we should iterate and display all models from all scenes if no scene is specified.