komadori / bevy_mod_outline

Apache License 2.0
123 stars 10 forks source link

Panic error when calling `generate_outline_normals()` on a `shape::UVSphere` #16

Closed noclck closed 1 year ago

noclck commented 1 year ago

Hi,

I got an error when I call the generate_outline_normals().unwrap() on a UVSphere shape.

thread 'Compute Task Pool (5)' panicked at 'called `Option::unwrap()` on a `None` value', src/generate.rs:89:41

How to reproduce

Replace the cube shape by a UVSphere shape inside the shape example

// ...

fn setup(
    mut commands: Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    // Add cube with generated outline normals
    //let mut cube_mesh = Mesh::from(Cube { size: 1.0 });
    //cube_mesh.generate_outline_normals().unwrap();

    let mut uvsphere_mesh = Mesh::from(UVSphere {
        radius: 0.5,
        ..default()
    });
    uvsphere_mesh.generate_outline_normals().unwrap();

    commands
        .spawn(PbrBundle {
            mesh: meshes.add(uvsphere_mesh),
            material: materials.add(Color::rgb(0.1, 0.1, 0.9).into()),
            transform: Transform::from_xyz(0.0, 1.0, 0.0),
            ..default()
        })
        .insert(OutlineBundle {
            outline: OutlineVolume {
                visible: true,
                colour: Color::rgba(0.0, 1.0, 0.0, 1.0),
                width: 25.0,
            },
            ..default()
        })
        .insert(Wobbles);

//...
komadori commented 1 year ago

This is caused by UVSphere generating vertices which are not referenced by the index buffer. Fixed by 5d49ad8f3cc2dee6d5e1ee65782d96a79b4ba467.

Also, I found the UVSphere outline had a visible seam caused by weighting the face normals and opposite sides of the seam having a slight numerical difference. Hence, I've tweaked the generation algorithm again to keep the face weighting but use vertex normals if available. See 3f304437cd384809fb22696bf01f90d28dbf2de7

I'll release 0.4.1 soon.

komadori commented 1 year ago

0.4.1 is released.