jpcy / xatlas

Mesh parameterization / UV unwrapping library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting Face Materials from Packed Mesh

AdamExley opened this issue · comments

I have a standard .obj mesh that has a couple materials.

The mesh's charts are correctly computed and packed according to material, but every resulting chart is assigned material index 0, regardless of the material that the chart is composed of.

Digging into the source code, this is deliberately done in PackCharts, but only when ctx->uvMeshInstances is empty; for uv meshes, the output materials are assigned correctly.

Here's what I'm referring to:
xatlas.cpp:9787

		for (uint32_t f = 0; f < outputChart->faceCount; f++)
			outputChart->faceArray[f] = chart->mapFaceToSourceFace(f);
	}
	outputChart->material = 0;
	meshChartIndex++;
	chartIndex++;
	firstVertex += chart->originalVertexCount();

Versus:
xatlas.cpp:9845

		outputChart->material = chart->material;
		for (uint32_t f = 0; f < outputChart->faceCount; f++)
			outputChart->faceArray[f] = chart->faces[f];
		chartIndex++;

Is there a reason for this behavior?

I understand that that UV mesh counterpart uses internal::pack::Chart, which has material data whereas I couldn't find easy access to any material data in the case for normal meshes.

The only way I have been able to avoid this is by changing line 9787 as follows, and referencing the material of the mesh faces in my meshDecl in the external code I am using.

outputChart->material = 0; // Old

outputChart->material = chart->mapFaceToSourceFace(0); // New