Files
UnrealEngineUWP/Engine/Plugins/Runtime/MeshModelingToolset/Source/MeshModelingTools/Private/Properties/MeshUVChannelProperties.cpp
michael balzer 4a4e360ab1 MeshModelingToolset: Cleanup UV Unwrap tool
#rb ryan.schmidt
#preflight 61a6d63b6c7d8a7295f405a2, 61a92f32fc3f6823e8d2bac7

#ROBOMERGE-AUTHOR: michael.balzer
#ROBOMERGE-SOURCE: CL 18357442 in //UE5/Release-5.0/... via CL 18357499
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v895-18170469)

[CL 18357514 by michael balzer in ue5-release-engine-test branch]
2021-12-02 15:47:10 -05:00

69 lines
1.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Properties/MeshUVChannelProperties.h"
#include "DynamicMesh/DynamicMesh3.h"
#include "DynamicMesh/DynamicMeshAttributeSet.h"
#include "MeshDescription.h"
#include "StaticMeshAttributes.h"
void UMeshUVChannelProperties::Initialize(int32 NumUVChannels, bool bInitializeSelection)
{
UVChannelNamesList.Reset();
for (int32 k = 0; k < NumUVChannels; ++k)
{
UVChannelNamesList.Add(FString::Printf(TEXT("UV %d"), k));
}
if (bInitializeSelection)
{
UVChannel = (NumUVChannels > 0) ? UVChannelNamesList[0] : TEXT("");
}
}
const TArray<FString>& UMeshUVChannelProperties::GetUVChannelNamesFunc() const
{
return UVChannelNamesList;
}
void UMeshUVChannelProperties::Initialize(const FMeshDescription* MeshDescription, bool bInitializeSelection)
{
TVertexInstanceAttributesConstRef<FVector2f> InstanceUVs =
MeshDescription->VertexInstanceAttributes().GetAttributesRef<FVector2f>(MeshAttribute::VertexInstance::TextureCoordinate);
Initialize(InstanceUVs.GetNumChannels(), bInitializeSelection);
}
void UMeshUVChannelProperties::Initialize(const FDynamicMesh3* Mesh, bool bInitializeSelection)
{
int32 NumUVChannels = Mesh->HasAttributes() ? Mesh->Attributes()->NumUVLayers() : 0;
Initialize(NumUVChannels, bInitializeSelection);
}
bool UMeshUVChannelProperties::ValidateSelection(bool bUpdateIfInvalid)
{
int32 FoundIndex = UVChannelNamesList.IndexOfByKey(UVChannel);
if (FoundIndex == INDEX_NONE)
{
if (bUpdateIfInvalid)
{
UVChannel = (UVChannelNamesList.Num() > 0) ? UVChannelNamesList[0] : TEXT("");
}
return false;
}
return true;
}
int32 UMeshUVChannelProperties::GetSelectedChannelIndex(bool bForceToZeroOnFailure)
{
int32 FoundIndex = UVChannelNamesList.IndexOfByKey(UVChannel);
if (FoundIndex == INDEX_NONE)
{
return (bForceToZeroOnFailure ) ? 0 : -1;
}
return FoundIndex;
}