Whinarn / UnityMeshSimplifier

Mesh simplification for Unity.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

several triangles turn black when this mesh is decimated

delzrm opened this issue · comments

https://drive.google.com/file/d/1PgrIRS4AE_ekia7p29VeiRp77NEGZgpR/view?usp=sharing

Describe the bug
Decimating meshes like this with submeshes and colour data seems make several of the triangles black in colour, the mesh appears to have been decimated perfectly fine, its just the colour data that is broken...

To Reproduce
import this unity package (unity 2019.3.13f1)

https://drive.google.com/file/d/1PgrIRS4AE_ekia7p29VeiRp77NEGZgpR/view?usp=sharing

decimate the mesh (use lossless, or whatever settings you like)
notice some triangles look like they are missing, infact, they aren't missing, their colour data has just been set to black.

Expected behavior

Colour data would be retained!

Screenshots
image
image

Image1 (before decimate)
Image2 (after decimate) - notice a few black polygons...

Environment (please complete the following information):
Windows10 - unity 2019.3.13f1

Additional context
This mesh is made out of many submeshes, it only contains Verts,Normals and Colours.
DecimateBug.zip

image

^^
further investigation reveals this:

InterpolateVertexAttributes seems to be getting called with indexes being duplicated (degenerate triangles?)

putting this at the start of InterpolateVertexAttributes() fixes the issue.
if (i0 == i1 || i0 == i2 || i1 == i2)
{
Debug.Log("degenerate!");
Debug.Log("i0: " + i0.ToString() + " i1: " + i1.ToString() + " i2: " + i2.ToString());
return;
}

it would appear that my mesh had a couple of degenerate triangles in! whoops!!