Files
mesh-project-duplicate-remover/Source/OptimizerEditor/Private/OptimizerReconciler.cpp
Bonchellon a95b299680 Mesh Optimizer: sibling StaticMesh duplicate remover (UE 5.7)
Editor plugin that detects geometrically-identical sibling StaticMeshes across a
level, rebases each placement onto one canonical mesh with a corrected transform
(W' = D * W, verified by exact vertex matching), and can collapse groups into HISM.
Native Slate tool panel + BlueprintCallable UOptimizerSubsystem.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 18:26:45 +03:00

41 lines
1.3 KiB
C++

// Copyright IHY.
#include "OptimizerReconciler.h"
namespace OptimizerReconciler
{
bool ComputeCorrectedWorld(
const FMatrix& CanonToMember,
const FTransform& W,
const FBox& CanonLocalBounds,
double ShearTol,
FTransform& OutWprime,
double& OutMaxCornerDev)
{
// Exact corrected world matrix: apply D first (canon-local -> sibling-local), then W.
const FMatrix Exact = CanonToMember * W.ToMatrixWithScale();
OutWprime.SetFromMatrix(Exact);
// Compare the FTransform reconstruction against the exact matrix at the canonical bbox corners.
// Any gap means the exact matrix had shear that FTransform discarded -> not representable.
const FVector Mn = CanonLocalBounds.Min;
const FVector Mx = CanonLocalBounds.Max;
const FVector Corners[8] =
{
FVector(Mn.X, Mn.Y, Mn.Z), FVector(Mx.X, Mn.Y, Mn.Z),
FVector(Mn.X, Mx.Y, Mn.Z), FVector(Mx.X, Mx.Y, Mn.Z),
FVector(Mn.X, Mn.Y, Mx.Z), FVector(Mx.X, Mn.Y, Mx.Z),
FVector(Mn.X, Mx.Y, Mx.Z), FVector(Mx.X, Mx.Y, Mx.Z)
};
double MaxDev = 0.0;
for (const FVector& C : Corners)
{
const FVector ExactPt = Exact.TransformPosition(C);
const FVector ViaTransform = OutWprime.TransformPosition(C);
MaxDev = FMath::Max(MaxDev, FVector::Dist(ExactPt, ViaTransform));
}
OutMaxCornerDev = MaxDev;
return MaxDev <= ShearTol;
}
}