Files
UnrealEngineUWP/Engine/Source/Editor/MeshPaint/Private/MeshPaintSplineMeshAdapter.cpp
fred kimberley 7fbfaf57c8 Require explicit constructors/casts when converting between FVector, FVector3d, and FVector3f.
#jira UE-122078
#rb Andrew.Davidson, Colin.McGinley
#preflight standard build

#ROBOMERGE-AUTHOR: fred.kimberley
#ROBOMERGE-SOURCE: CL 18817999 in //UE5/Release-5.0/... via CL 18818012 via CL 18822871
#ROBOMERGE-BOT: UE5 (Release-Engine-Test -> Main) (v910-18824042)

[CL 18824721 by fred kimberley in ue5-main branch]
2022-02-02 07:59:31 -05:00

69 lines
2.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "MeshPaintSplineMeshAdapter.h"
#include "StaticMeshResources.h"
#include "Components/SplineMeshComponent.h"
//////////////////////////////////////////////////////////////////////////
// FMeshPaintGeometryAdapterForSplineMeshes
bool FMeshPaintGeometryAdapterForSplineMeshes::InitializeVertexData()
{
// Cache deformed spline mesh vertices for quick lookup during painting / previewing
USplineMeshComponent* SplineMeshComponent = Cast<USplineMeshComponent>(StaticMeshComponent);
check(SplineMeshComponent);
bool bValid = false;
if (LODModel)
{
// Retrieve vertex and index data
const int32 NumVertices = LODModel->VertexBuffers.PositionVertexBuffer.GetNumVertices();
MeshVertices.Reset();
MeshVertices.AddDefaulted(NumVertices);
// Apply spline vertex deformation to each vertex
for (int32 Index = 0; Index < NumVertices; Index++)
{
FVector Position = (FVector)LODModel->VertexBuffers.PositionVertexBuffer.VertexPosition(Index);
const FTransform SliceTransform = SplineMeshComponent->CalcSliceTransform(USplineMeshComponent::GetAxisValue(Position, SplineMeshComponent->ForwardAxis));
USplineMeshComponent::GetAxisValue(Position, SplineMeshComponent->ForwardAxis) = 0;
MeshVertices[Index] = SliceTransform.TransformPosition(Position);
}
const int32 NumIndices = LODModel->IndexBuffer.GetNumIndices();
MeshIndices.Reset();
MeshIndices.AddDefaulted(NumIndices);
const FIndexArrayView ArrayView = LODModel->IndexBuffer.GetArrayView();
for (int32 Index = 0; Index < NumIndices; Index++)
{
MeshIndices[Index] = ArrayView[Index];
}
bValid = (MeshVertices.Num() > 0 && MeshIndices.Num() > 0);
}
return bValid;
}
//////////////////////////////////////////////////////////////////////////
// FMeshPaintGeometryAdapterForSplineMeshesFactory
TSharedPtr<IMeshPaintGeometryAdapter> FMeshPaintGeometryAdapterForSplineMeshesFactory::Construct(class UMeshComponent* InComponent, int32 MeshLODIndex) const
{
if (USplineMeshComponent* SplineMeshComponent = Cast<USplineMeshComponent>(InComponent))
{
if (SplineMeshComponent->GetStaticMesh() != nullptr)
{
TSharedRef<FMeshPaintGeometryAdapterForSplineMeshes> Result = MakeShareable(new FMeshPaintGeometryAdapterForSplineMeshes());
if (Result->Construct(InComponent, MeshLODIndex))
{
return Result;
}
}
}
return nullptr;
}