How to get the number of vertices of the SkeletalMesh in C++

How to get the number of vertices of the SkeletalMesh in C++

Hello! You can take a look at this code

			LODVertexNumber = 0;
			LODTriNumber = 0;
			const FSkeletalMeshLODModel& LODModel = GetImportedModel()->LODModels[LODIndex];
			//We can take the vertices and triangles count from the source model
			for (int32 SectionIndex = 0; SectionIndex < LODModel.Sections.Num(); ++SectionIndex)
			{
				const FSkelMeshSection& Section = LODModel.Sections[SectionIndex];

				//Make sure the count fit in a uint32
				LODVertexNumber += Section.NumVertices < 0 ? 0 : Section.NumVertices;
				LODTriNumber += Section.NumTriangles;
			}

Thank you!

thank you

How can I make a blueprint node out of it?

.h

UFUNCTION(BlueprintCallable)
int32 GetVertNum(USkeletalMesh* SkelMesh, int LODIndex);

cpp
needed includes

#include "Engine/SkeletalMesh.h" 
#include "Rendering/SkeletalMeshModel.h" 
int32 AMyExampleActorClass::GetVertNum(USkeletalMesh* SkelMesh, int LODIndex) {
	int32 LODVertexNumber = 0;
	int32 LODTriNumber = 0;
	const FSkeletalMeshLODModel& LODModel = SkelMesh->GetImportedModel()->LODModels[LODIndex];
	//We can take the vertices and triangles count from the source model
	for (int32 SectionIndex = 0; SectionIndex < LODModel.Sections.Num(); ++SectionIndex)
	{
		const FSkelMeshSection& Section = LODModel.Sections[SectionIndex];

		//Make sure the count fit in a uint32
		LODVertexNumber += Section.NumVertices < 0 ? 0 : Section.NumVertices;
		LODTriNumber += Section.NumTriangles;
	}

	return LODVertexNumber;
}

You could also move this to a static function in a blueprint library.

1 Like