xatlas
xatlas copied to clipboard
Some charts are flipped after packing
Description
Using the included .obj and .mtl and changing the example_uvmesh.cpp
so it does not loop the same shape 10 times but only use input shapes. The resulting images show many instances where a chart is flipped. Issue persist even when setting xatlas chart options to fix winding.
The input mesh is a single shape, 125 arrayed triangulated boxes with unique materials. The uvs for each disconnected geometry is overlapping.
Steps to reproduce
Commenting out the lines 211, 212 & 232
//const int n = 10;
//for (int i = 0; i < n; i++) {
...
//}
Then editing line 226, so shapes[s]
instead of shapes[i]
printf("\rError adding mesh %d '%s': %s\n", s, shapes[s].name.c_str(), xatlas::StringForEnum(error));
Adding the following lines at 239,
xatlas::ChartOptions chartOptions = xatlas::ChartOptions();
chartOptions.fixWinding = true;
xatlas::ComputeCharts(atlas, chartOptions);
With the .obj and .mlt extracted to folder of example_uvmesh.exe, and running
.\example_uvmesh.exe overlapping_uvs.obj
The resulting .tga output will show that some of the charts are flipped randomly.
I have also tried changing line 125 in xatlas.cpp to
#define XA_CHECK_PARAM_WINDING 1
And to have it compile change line 9713 in xatlas.cpp from
const float area = mesh->computeFaceParametricArea(f);
to the following,
const float area = unifiedMesh->computeFaceParametricArea(f);
I might have misunderstood the purpose of fixUnwinding as I assumed it would solve the issue of charts being flipped so happy to learn of any other setting that might solve this.
Not an issue when using MeshDecl instead of UvMeshDecl
Seems I was mistaken. Issue still persists, getting the log after setting XA_CHECK_PARAM_WINDING 1
I could track down to it happening during the PackCharts, and not ComputeCharts.
Flipping is no issue if xatlas::PackOptions.rotateCharts
is set to false, but charts also seem to get skewed unless rotateChartsToAxis
also is set false in this case.
I think the flipping of the charts happens in the swap here, https://github.com/jpcy/xatlas/blob/f700c7790aaa030e794b52ba7791a05c085faf0c/source/xatlas/xatlas.cpp#L8583-L8593
I also encountered the same problem。I found that the vertex order of the flipped triangular surface is arranged counterclockwise。