Whinarn / MeshDecimator

A mesh decimation library for .NET and Unity.
MIT License
286 stars 46 forks source link

Flat Shaded Meshes don't decimate correctly #7

Closed joshcamas closed 5 years ago

joshcamas commented 6 years ago

Here's an example of what happens when decimation is applied to a flat shaded mesh exported from blender: https://i.imgur.com/j0qlmcI.png

Here's another example. Flat shaded mesh decimated: https://i.imgur.com/kTRDzMl.png

Smooth shaded mesh decimated: https://i.imgur.com/v4I5DMo.png

Whinarn commented 6 years ago

The problem here is that the Fast Quadric Mesh Simplification algorithm that I ported from C++ to C# doesn't support these kind of meshes.

The problem is most probably that you have vertices at the same position because you need different attributes for them and they aren't connected in any way. And this algorithm doesn't take that into consideration and holes are easily created. I am aware of this issue and am working on a solution in another project that I have based on the same algorithm that I plan to move to this project as well.

There is a way to prevent holes at the moment, through enabling the KeepBorders property of the DecimationAlgorithm. But it prevents the decimation algorithm to be effective in many cases.

Please see this issue for more information and updates: https://github.com/Whinarn/UnityMeshSimplifier/issues/2

I haven't had a lot of time over lately, but I will try to get this working as soon as I can. I will leave this issue open.

Whinarn commented 6 years ago

An update is that I have improved the algorithm in the UnityMeshSimplifier repository that aims to solve the same issue as you have experienced.

I will look into merging this into this repository as well.

Whinarn commented 6 years ago

I have now implemented the new Smart Linking feature into this project, which should resolve this issue.

@joshcamas Could you please try out the latest version to see if your problem still persists https://github.com/Whinarn/MeshDecimator/tree/v0.2.0

Thanks!

joshcamas commented 6 years ago

Beautiful, it works perfectly!!! https://i.imgur.com/BFamvET.png

Looks like there is some sort of issue still though, when there is a simplification (even one with a quality of 1) the shading gets wonky. I'll look into a bit more.

EDIT: It looks like flat shading is disabled when there is a simplification applied.

Whinarn commented 6 years ago

Great to hear that it resolved your problem.

Could the shading issue be related to the normals? I can try to see if I have made a mistake with the normals somewhere. Thinking about it now (without having the code in front of me) it might be that the normals are not unit-length after simplification because of how the vertex attributes are blended.

Whinarn commented 6 years ago

@joshcamas Are you still having problems with this? Did you figure out the problem?