jpcy / xatlas

Mesh parameterization / UV unwrapping library
MIT License
2.08k stars 220 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 3 weeks ago

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

SamuelReithmeir commented 3 weeks ago

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

mifth commented 3 weeks 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 3 weeks 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 weeks 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 weeks ago

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

mifth commented 3 weeks 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

mifth commented 2 weeks ago

Finally, I made've final changes/fixes for Quads/NGons.

My commit: https://github.com/jpcy/xatlas/pull/138/commits/22f4d644aeff61a99af10facd579d4736c5043d4 https://github.com/jpcy/xatlas/pull/138#issuecomment-2445383272

Pictures: Some pictures of a final result after a generation: image image image image image

mifth commented 2 weeks ago

Some pictures to explain a new computeBoundaryIntersection variable which I've added with the latest commit.

image image image image