// Copyright Epic Games, Inc. All Rights Reserved. #include "WeightMapUtil.h" #include "MeshDescription.h" void UE::WeightMaps::FindVertexWeightMaps(const FMeshDescription* Mesh, TArray& PropertyNamesOut) { const TAttributesSet& VertexAttribs = Mesh->VertexAttributes(); VertexAttribs.ForEach([&](const FName AttributeName, auto AttributesRef) { if (VertexAttribs.HasAttributeOfType(AttributeName)) { PropertyNamesOut.Add(AttributeName); } }); } bool UE::WeightMaps::GetVertexWeightMap(const FMeshDescription* Mesh, FName AttributeName, FIndexedWeightMap1f& WeightMap, float DefaultValue) { WeightMap.DefaultValue = DefaultValue; TArray& Values = WeightMap.Values; int32 VertexCount = Mesh->Vertices().Num(); if (Values.Num() < VertexCount) { Values.SetNum(VertexCount); } const TAttributesSet& VertexAttribs = Mesh->VertexAttributes(); TVertexAttributesConstRef Attrib = VertexAttribs.GetAttributesRef(AttributeName); if (Attrib.IsValid()) { for (int32 k = 0; k < VertexCount; ++k) { Values[k] = Attrib.Get(FVertexID(k)); } return true; } else { for (int32 k = 0; k < VertexCount; ++k) { Values[k] = DefaultValue; } return false; } }