jpcy / xatlas

Mesh parameterization / UV unwrapping library
MIT License
2.06k stars 221 forks source link

Wrong calculation with faceVertexCount? #135

Open SamuelReithmeir opened 2 months ago

SamuelReithmeir commented 2 months ago

I just stumbled over a problem with FaceVertexCount, i get an invalid memory access. A sample would be: face0: 3 vertices face1: 4 vertices face2: 5 vertices this results in a total IndexCount of 12

when adding that mesh declaration i get a invalid memory access (i use XAtlas in c# using swig). After looking at the code i found this code: https://github.com/jpcy/xatlas/blob/f700c7790aaa030e794b52ba7791a05c085faf0c/source/xatlas/xatlas.cpp#L9096

According to my understanding face * faceVertexCount + i seems to be a logic error. To explain: This seems to calculate the offset/beginning of the indices of this face and add i. But the problem is that it assumes that all faces before also have the same faceVertexCount, which destroys the entire purpose of having faceVertexCount be an array in the first place.

Please correct me if i misunderstand the logik here, but i will provide a PR, which will change the logic here to a variable which will sum up the previous faceVertexCounts.

mifth commented 6 days ago

I've created a pull request which should fix the issue. https://github.com/jpcy/xatlas/pull/138

SamuelReithmeir commented 5 days ago

Better fixed by https://github.com/jpcy/xatlas/pull/138

mifth commented 4 days ago

Thanks a lot. I'll continue this thread. I've found another one issue. NGon is gnored if it's too polygonal. If NGon has at least one zero area triangle it will be ignored.

image

A problem is here. I'm checking it. image

mifth commented 4 days ago

This has worked out. We need to calculate an area of all triangles. And then make a decision if it should be ignored. image

Now it works well even with a 10000 NGon. image image

I'll update my pull request.

mifth commented 3 days ago

Another one problem is found: XAtlas triangulates Quads/NGons and considers them as uniquee triangles. For example, 2 triangles of a quad can be in different charts.

image image image

This doesn't happen if an original mesh is triangulated: image image image

mifth commented 3 days ago

I think it can be fixed in the computeCharts() function. Looking at it.

mifth commented 1 day ago

It was pretty hard to understand what's going on there but I almos fixed quads and ngons determination by charts. Hopefully, to finish today/tomorrow.

image

image