2019-12-27 09:26:59 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-10-01 20:41:42 -04:00
|
|
|
|
|
|
|
|
#include "Properties/MeshAnalysisProperties.h"
|
|
|
|
|
|
2021-05-22 01:32:46 -04:00
|
|
|
#include "DynamicMesh/DynamicMesh3.h"
|
2019-10-01 20:41:42 -04:00
|
|
|
#include "MeshQueries.h"
|
|
|
|
|
#include "MeshAdapter.h"
|
2021-05-22 01:32:46 -04:00
|
|
|
#include "DynamicMesh/MeshAdapterUtil.h"
|
2021-11-29 11:38:16 -05:00
|
|
|
#include "Internationalization/FastDecimalFormat.h"
|
|
|
|
|
#include "Internationalization/Text.h"
|
|
|
|
|
#include "Math/BasicMathExpressionEvaluator.h"
|
2019-10-01 20:41:42 -04:00
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "UMeshAnalysisProperites"
|
|
|
|
|
|
2021-03-09 19:33:56 -04:00
|
|
|
using namespace UE::Geometry;
|
2019-10-01 20:41:42 -04:00
|
|
|
|
2021-11-29 11:38:16 -05:00
|
|
|
/**
|
|
|
|
|
* Utility function that converts a number to a string. The precision of the fractional part can be adjusted based on
|
|
|
|
|
* the magnitude of the input number.
|
|
|
|
|
*
|
|
|
|
|
* @param Number to convert to a string
|
|
|
|
|
* @param MagnitudeToFractionalDigits Array of tuples (x, y) such that if the Number is less than x then set the fractional precision to y.
|
|
|
|
|
* @param DefaultMaxFractionalDigits Default precision if the Number doesn't fall into any range specified in MagnitudeToFractionalDigits
|
|
|
|
|
*/
|
|
|
|
|
template<typename RealType>
|
|
|
|
|
FString NumberToStringWithFractionalPrecision(const RealType Number,
|
|
|
|
|
const TArray<TTuple<RealType, int32>>& MagnitudeToFractionalDigits,
|
|
|
|
|
const int DefaultMaxFractionalDigits = 6)
|
|
|
|
|
{
|
|
|
|
|
FNumberFormattingOptions NumberFormattingOptions;
|
|
|
|
|
NumberFormattingOptions.SetUseGrouping(false);
|
|
|
|
|
NumberFormattingOptions.SetMaximumFractionalDigits(DefaultMaxFractionalDigits);
|
|
|
|
|
|
|
|
|
|
if (MagnitudeToFractionalDigits.Num() > 0)
|
|
|
|
|
{
|
|
|
|
|
TArray<TTuple<RealType, int32>> SortedMagnitudeToFractionalDigits = MagnitudeToFractionalDigits;
|
|
|
|
|
SortedMagnitudeToFractionalDigits.Sort([](const TTuple<RealType, int32>& LHS, const TTuple<RealType, int32>& RHS) { return LHS.Key < RHS.Key; });
|
|
|
|
|
|
|
|
|
|
if (Number < SortedMagnitudeToFractionalDigits.Last().Key) // First check if the number falls into any range
|
|
|
|
|
{
|
|
|
|
|
for (const TTuple<RealType, int32>& Tuple : SortedMagnitudeToFractionalDigits)
|
|
|
|
|
{
|
|
|
|
|
if (Number < Tuple.Key)
|
|
|
|
|
{
|
|
|
|
|
NumberFormattingOptions.SetMaximumFractionalDigits(Tuple.Value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FastDecimalFormat::NumberToString(Number, ExpressionParser::GetLocalizedNumberFormattingRules(), NumberFormattingOptions);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 20:41:42 -04:00
|
|
|
void UMeshAnalysisProperties::Update(const FDynamicMesh3& MeshIn, const FTransform& Transform)
|
|
|
|
|
{
|
2022-02-24 15:01:41 -05:00
|
|
|
FTriangleMeshAdapterd TransformedMesh = UE::Geometry::MakeTransformedDynamicMeshAdapter(&MeshIn, (FTransform3d)Transform);
|
2021-03-17 21:45:29 -04:00
|
|
|
FVector2d VolArea = TMeshQueries<FTriangleMeshAdapterd>::GetVolumeArea(TransformedMesh);
|
2021-11-29 11:38:16 -05:00
|
|
|
|
|
|
|
|
TArray<TTuple<double, int32>> MagnitudeToFractionalDigits;
|
|
|
|
|
MagnitudeToFractionalDigits.Add(MakeTuple(0.1, 8)); // If the number is less than 0.1 show 8 fractional digits
|
|
|
|
|
MagnitudeToFractionalDigits.Add(MakeTuple(1, 6)); // If the number is less than 1 show 6 fractional digits
|
|
|
|
|
|
|
|
|
|
const double VolInMeters = VolArea[0]/1000000;
|
|
|
|
|
const double AreaInMeters = VolArea[1]/10000;
|
|
|
|
|
|
|
|
|
|
this->Volume = NumberToStringWithFractionalPrecision(VolInMeters, MagnitudeToFractionalDigits, 4);
|
|
|
|
|
this->SurfaceArea = NumberToStringWithFractionalPrecision(AreaInMeters, MagnitudeToFractionalDigits, 4);
|
2019-10-01 20:41:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|