Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FColor UYourBPLibrary::GetVertexPaintData(UStaticMeshComponent* StaticMeshComp, FVector Position, int32 LODIndex)
- {
- // Make sure user doesn't pass nullptr
- if (StaticMeshComp == nullptr)
- {
- UE_LOG(LogTemp, Error, TEXT("Passed Static Mesh Component is not valid!"));
- }
- else if (StaticMeshComp->LODData.IsValidIndex(LODIndex)) // And a valid LODIndex
- {
- // Get the painted Vertices from the passed StaticMeshComponent's LODData
- TArray<FPaintedVertex> PaintedVertices = StaticMeshComp->LODData[LODIndex].PaintedVertices;
- // Make sure we have PaintedVertices
- if (PaintedVertices.Num() > 0)
- {
- // Find the closest Vertex Position to the passed Position (local space!)
- float ClosestDistance;
- FVector EmptyDir; // No use, just for the Function below
- (PaintedVertices[0].Position - Position).ToDirectionAndLength(EmptyDir, ClosestDistance);
- FColor ClosestColor = PaintedVertices[0].Color;
- // Simple "if smaller, than use smaller one" algorithm
- for (int32 i = 1; i < PaintedVertices.Num(); i++)
- {
- float TempDistance;
- (PaintedVertices[i].Position - Position).ToDirectionAndLength(EmptyDir, TempDistance);
- if (TempDistance < ClosestDistance)
- {
- ClosestDistance = TempDistance;
- ClosestColor = PaintedVertices[i].Color;
- }
- }
- return ClosestColor;
- }
- else
- {
- UE_LOG(LogTemp, Error, TEXT("No painted vertices found!"));
- }
- }
- else
- {
- UE_LOG(LogTemp, Error, TEXT("Please provide a valid LODIndex. LODIndex: %d is out of bounds."), LODIndex);
- }
- // Return generic White Color if any error occurred
- return FColor::White;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement