jpcy / xatlas

Mesh parameterization / UV unwrapping library
MIT License
2.09k stars 220 forks source link

Some charts are flipped after packing #121

Open rondreas opened 1 year ago

rondreas commented 1 year ago

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.

example_uvmesh_charts00 overlapping_uvs.zip

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.

rondreas commented 1 year ago

Not an issue when using MeshDecl instead of UvMeshDecl

rondreas commented 1 year ago

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

lvyong1943 commented 4 months ago

I also encountered the same problem。I found that the vertex order of the flipped triangular surface is arranged counterclockwise。