komadori / bevy_mod_outline

Apache License 2.0
123 stars 10 forks source link

Outline broken for some models #4

Closed Shatur closed 2 years ago

Shatur commented 2 years ago

For my stone outline looks like this:

изображение

Here is a minimal example to reproduce the issue: Example.zip It uses https://github.com/nicopap/bevy-scene-hook to attach OutlineBundle to the loaded mesh (GLTF in Bevy spawned as scenes) and https://github.com/sburris0/bevy_flycam (see controls) to move the camera.

Shatur commented 2 years ago

I talked with the author in Discord and it turns out the behavior is expected and happens because of hard-edges: https://docs.rs/bevy_mod_outline/0.2.2/bevy_mod_outline/trait.OutlineMeshExt.html

Possible workarounds within the domain of vertex-extrusion (current algorithm):

Or use some algorithm other than vertex extrusion, like jump-flood or edge detection.

komadori commented 2 years ago

image

I'm not sure if I was entirely clear in our discussion, that it is possible to generate outline normals dynamically using the library as is. I modified your example to call generate_outline_normals() (below) and as you can see from the screenshot (above), the result renders more or less as you would expect.

I think it would too invasive to do this automatically by default, but perhaps I could add an optional plugin with a system like the one below. I will keep this issue open to consider that.

--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
 use bevy_flycam::PlayerPlugin;
 use bevy::prelude::*;
-use bevy_mod_outline::{OutlineBundle, Outline, OutlinePlugin};
+use bevy_mod_outline::{OutlineBundle, Outline, OutlineMeshExt, OutlinePlugin};
 use bevy_scene_hook::{HookedSceneBundle, SceneHook, HookPlugin};

 fn main() {
@@ -10,6 +10,7 @@ fn main() {
         .add_plugin(OutlinePlugin)
         .add_plugin(PlayerPlugin)
         .add_startup_system(setup)
+        .add_system(gen_outlines)
         .run();
 }

@@ -58,3 +59,12 @@ fn setup(
         ..Default::default()
     });
 }
+
+fn gen_outlines(
+    mut meshes: ResMut<Assets<Mesh>>,
+    query: Query<&Handle<Mesh>, Changed<Handle<Mesh>>>,
+) {
+    for mesh in query.iter() {
+        meshes.get_mut(mesh).unwrap().generate_outline_normals().unwrap();
+    }
+}
Shatur commented 2 years ago

Oh, now I get it, thank a lot :) Closing the issue as it's not a bug.

komadori commented 2 years ago

Released 0.2.3 with: https://docs.rs/bevy_mod_outline/0.2.3/bevy_mod_outline/struct.AutoGenerateOutlineNormalsPlugin.html