How to map vertex index to material slot?

anonymous_user_0173218b
Thu, 06 Aug 2020 14:03:27 +0000
Asset Creation

I am trying to programatically paint vertices on a mesh based on their material slot. However, I have not found a method to map a vertice to its associated material slot.

I have found FStaticMeshSection:

struct FStaticMeshSection
{
	/** The index of the material with which to render this section. */
	int32 MaterialIndex;

	/** Range of vertices and indices used when rendering this section. */
	uint32 FirstIndex;
	uint32 NumTriangles;
	uint32 MinVertexIndex;
	uint32 MaxVertexIndex;

However, MinVertexIndex and MaxVertexIndex don’t seem to work. Is this the method (and I have a bug elsewhere in my code)? Or is there another method to map a vertex to material slot?

For context, this is how I am currently painting the vertices:

uint32 TotalVertices = LODModel.GetNumVertices();
			check(InstanceMeshLODInfo->OverrideVertexColors);
			check(TotalVertices <= InstanceMeshLODInfo->OverrideVertexColors->GetNumVertices());

			for (uint32 VerticeIdx = 0; VerticeIdx < TotalVertices; VerticeIdx++)
			{
                FColor ColorToSet = DefaultColor;
			    // uint32 NumOverrideVertexColors = InstanceMeshLODInfo->OverrideVertexColors->GetNumVertices();
				// uint32 NumPaintedVertices = InstanceMeshLODInfo->PaintedVertices.Num();
                if (VertexIdxToMaterialIdx.Contains(VerticeIdx) && MaterialIndexToColor.Contains(VertexIdxToMaterialIdx[VerticeIdx]))
                {
                    int MaterialIndex = VertexIdxToMaterialIdx[VerticeIdx];
                    ColorToSet = MaterialIndexToColor[MaterialIndex];
                }
				InstanceMeshLODInfo->OverrideVertexColors->VertexColor(VerticeIdx) = ColorToSet;
			}

4 posts - 1 participant