Files
UnrealEngineUWP/Engine/Plugins/Experimental/GeometryProcessing/Source/DynamicMesh/Private/Sampling/MeshResampleImageBaker.cpp
Ryan Schmidt 31317aefbd GeometryProcessing improvements/additions
- new correspondence-finding strategy in FMeshImageBakingCache. Added a global Thickness parameter, and now preferentially uses the ray-hit found by casting inwards from Point+Thickness*Normal. This handles the cases where a greeble/etc is just layered on top of base mesh. These kind of mesh elements are only intended to show up in the normal map, so they aren't stitched in.
  - expose Thickness and World-Space options in BakeMeshAttributeMapsTool
  - initialize image in Normal and ResampleImage Bakers, otherwise initial value is garbage
- add TSampledScalarField2::BilinearSampleGradientClamped and fix typo in BilinearSampleClamped() that resulted in incorrect interpolation
- add Texture2DUtil, contains functions for reading a TImageBuilder from a UTexture2D. Can read from source data if available.
- ColorConstants now returns white for group 0
- add double version of FMeshDescriptionToDynamicMesh::CopyTangents()
- add support for computing on subset of vertiecs in FMeshConvexHull
- fix up template export in TMeshTangents
- make mesh const in TImplicitMorphology, TImplicitSolidify
- accessor/etc additions in TDenseGrid2, TImageBuilder, TSampledScalarField2, TIndexedWeightMap
- add source UStaticMesh reference in FPhysicsDataCollection, function to initialize from a UStaticMesh
  - update Tools affected by above changes
- add TSampleSetStatisticBuilder::ComputeMultiPass() helper function to compute stats for iterable collections in one line
- remove dead code in UVLayoutOp.cpp

#rb tyson.brochu
#rnx
#jira none

[CL 14769759 by Ryan Schmidt in ue5-main branch]
2020-11-17 22:32:38 -04:00

47 lines
1.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "Sampling/MeshResampleImageBaker.h"
void FMeshResampleImageBaker::Bake()
{
const FMeshImageBakingCache* BakeCache = GetCache();
check(BakeCache);
const FDynamicMesh3* DetailMesh = BakeCache->GetDetailMesh();
check(DetailUVOverlay);
FVector4f DefaultValue(0, 0, 0, 1.0);
auto PropertySampleFunction = [&](const FMeshImageBakingCache::FCorrespondenceSample& SampleData)
{
FVector4f Color = DefaultValue;
int32 DetailTriID = SampleData.DetailTriID;
if (DetailMesh->IsTriangle(SampleData.DetailTriID) && DetailUVOverlay)
{
FVector2d DetailUV;
DetailUVOverlay->GetTriBaryInterpolate<double>(DetailTriID, &SampleData.DetailBaryCoords[0], &DetailUV.X);
Color = SampleFunction(DetailUV);
}
return Color;
};
ResultBuilder = MakeUnique<TImageBuilder<FVector4f>>();
ResultBuilder->SetDimensions(BakeCache->GetDimensions());
ResultBuilder->Clear(DefaultColor);
BakeCache->EvaluateSamples([&](const FVector2i& Coords, const FMeshImageBakingCache::FCorrespondenceSample& Sample)
{
FVector4f Color = PropertySampleFunction(Sample);
ResultBuilder->SetPixel(Coords, Color);
});
const FImageOccupancyMap& Occupancy = *BakeCache->GetOccupancyMap();
for (int64 k = 0; k < Occupancy.GutterTexels.Num(); k++)
{
TPair<int64, int64> GutterTexel = Occupancy.GutterTexels[k];
ResultBuilder->CopyPixel(GutterTexel.Value, GutterTexel.Key);
}
}