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

Would generate outline normals differently works for non-manifold meshes? #46

Open
thmxv opened this issue Aug 29, 2024 · 4 comments
Open

Comments

@thmxv
Copy link

thmxv commented Aug 29, 2024

I am using this plugin to outline the selected objects in an editor like application. One of the issue I have is with non-manifold meshes (meshes where all the edges are not part of exactly 2 faces). I saw a related issue regarding "flat" meshes for which I assume the issue is the same, and I am not concerned with the case where edges are part of more than 2 faces. The "solutions" I saw were to add "dummy/degenerate" triangles to force the calculation of "outline normals" to produce different normals. But this would not work for me (or at least I do not think so).

My question is the following:

If I implement a function that does more of less the same thing as generate_outline_normals (at a bigger performance cost) but that generate normals pointing "outwards" for vertices that are part of the non-manifold edges. By "outward", I mean perpendicular to the edge, but tangent to the face (instead of normal) but pointing in the opposite direction of the face. And averaging those normals, for vertices that are part of more than one edge. Would this work without having to modify the mesh?

@thmxv
Copy link
Author

thmxv commented Sep 1, 2024

I tried but without success:

Screenshot from 2024-09-01 15-53-17

Replacing all the cull_mode = Some(...) with cull_mode = None in the pipeline.rs fixed some issues but the outline width is still nothing in some cases:
Screenshot from 2024-09-01 15-54-50

I also tried making the normals of the non-manifold edges being a mix of the "edge normals" and the adjoin face normals. So that the cylinder without end caps have the same normals as the cylinder with the end caps. But this only "works depending on the view camera orientation relative to the face. I suppose the only thing that would "work" is to duplicate all the faces/vertices so that every face have a duplicate that points in the opposite direction. But this is not usable for my case (unless we add an OutlineMesh that is the mesh used for the outline but separate from the "real" mesh, but this would cost a lot of RAM).

Maybe I am wrong (I hope) any help is welcome.

@thmxv
Copy link
Author

thmxv commented Sep 1, 2024

I suppose, that:

  • For each non-manifold edge
  • Duplicate the vertices
  • Create a degenerate quad face (2 tri faces) between the old vertices and the new one
  • Use the faces normal for the old vertices but the "edge normal" for the new one

Would work too (with the cull_mode hack)

Should I continue experimenting with this? If I end up with a additional fn that does what generate_outline_normals do but specific for non-manifold meshes and that modify the mesh (adding the degenerate faces) and an additional cull_mode properties in the OutlineMode to make the "hack" optional. Is is something you would consider merging in this repo?

@komadori
Copy link
Owner

komadori commented Sep 2, 2024

Have you seen the alternative outline normal generation code described in this comment: #12 (comment)

@thmxv
Copy link
Author

thmxv commented Sep 3, 2024

I saw it quite a long time ago. I do not understand all of it (yet) and it is not working for existing meshes (it only works while building a mesh fro scratch). And also only for mesh with indices for the faces and without any vertex attributes beside positions and normals.

I also saw that for each vertex, it creates 8 new vertices and 12 new faces which is not acceptable for my use case. Anyway, when I have more time I will try this code with my use case and make it so that it works with existing mesh and other vertex attribute. But I have another code that add vertices and generate normals for non-manifold meshes that works much more economically (adding just a few vertex, creating just a few faces and working for meshes with other attributes). I will publish both of those code (mine and the one existing but modified to work with real use cases) on gist when this is done and the code cleaned-up and optimized a bit.

Anyway. If adding a generic solution for this mesh modification and normal generation, for non-manifold meshes, is not acceptable for this plugin. I understand and this can easily be added with code in the project using this plugin. So it does not require to modify the code of this plugin. Although a including a generic solution easier to find for the people having this issue would be nice.

However, for the non-manifold meshes (using a material with no backface culling) to have their outline visible when view from the backside, do require a modification to this plugin's code.

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

No branches or pull requests

2 participants