Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some charts are flipped after packing #121

Open
rondreas opened this issue Oct 2, 2023 · 3 comments
Open

Some charts are flipped after packing #121

rondreas opened this issue Oct 2, 2023 · 3 comments

Comments

@rondreas
Copy link

rondreas commented Oct 2, 2023

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
Copy link
Author

Not an issue when using MeshDecl instead of UvMeshDecl

@rondreas
Copy link
Author

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,

// Modify texture coordinates:
// - rotate if the chart should be rotated
// - translate to chart location
// - translate to remove padding from top and left atlas edges (unless block aligned)
for (uint32_t v = 0; v < chart->uniqueVertexCount(); v++) {
Vector2 &texcoord = chart->uniqueVertexAt(v);
Vector2 t = texcoord;
if (best_r) {
XA_DEBUG_ASSERT(options.rotateCharts);
swap(t.x, t.y);
}

@rondreas rondreas reopened this Oct 24, 2023
@lvyong1943
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants