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>
This commit is contained in:
40
Source/OptimizerEditor/Private/OptimizerReconciler.cpp
Normal file
40
Source/OptimizerEditor/Private/OptimizerReconciler.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user