Skip to content

Commit

Permalink
LLE: StaticMeshComponent code has been simplified and had more bugs i…
Browse files Browse the repository at this point in the history
…roned out.
  • Loading branch information
SirCxyrtyx committed Sep 10, 2022
1 parent c62d9ae commit f6a6c75
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 126 deletions.
2 changes: 1 addition & 1 deletion LE2-ASI-Plugins
2 changes: 1 addition & 1 deletion LE3-ASI-Plugins
33 changes: 11 additions & 22 deletions Shared-ASI/LEXInterop/AdditionalFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,17 @@ static BOOL SetRotationWrapper(AActor* actor, const FRotator& rotation)
return actor->SetRotation(rotation);
}

static BOOL DrawDebugLine(AActor* context, const FVector& start, const FVector& end, const FLinearColor& color, const float thickness = 1.f, const bool overlay = false, const bool persistent = true)
static void DrawDebugLine(const FVector& start, const FVector& end, const FLinearColor& color, const float thickness = 1.f, const bool persistent = true)
{
//typedef void(*tDrawDebugLine)(AActor* self, FVector LineStart, FVector LineEnd, BYTE R, BYTE G, BYTE B, unsigned int bPersistentLines);
//static tDrawDebugLine actorDrawDebugLine = nullptr;
//if (static bool initialized = false; !initialized)
//{
// //variable name for use by the macro
// ISharedProxyInterface* InterfacePtr = ISharedProxyInterface::SPIInterfacePtr;

// INIT_FIND_PATTERN_POSTHOOK(actorDrawDebugLine,"48 89 6c 24 10 48 89 74 24 18 57 48 83 ec 40 83 bc 24 80 00 00 00 00");
//}
//actorDrawDebugLine(context, start, end, 1, 1, 0, persistent);
ULineBatchComponent* lineBatcher = persistent ? StaticVariables::GWorld()->PersistentLineBatcher : StaticVariables::GWorld()->LineBatcher;
lineBatcher->FPrimitiveDrawInterfaceVfTable->DrawLine(reinterpret_cast<BYTE*>(lineBatcher) + offsetof(ULineBatchComponent, FPrimitiveDrawInterfaceVfTable), start, end, color, overlay ? 2 : 1, thickness);
return true;
lineBatcher->FPrimitiveDrawInterfaceVfTable->DrawLine(reinterpret_cast<BYTE*>(lineBatcher) + offsetof(ULineBatchComponent, FPrimitiveDrawInterfaceVfTable), start, end, color, 1, thickness);
}
//static void DrawCoordinateSystem(const FVector& position, const float scale, const float thickness = 1.f)
//{
// ULineBatchComponent* lineBatcher = StaticVariables::GWorld()->PersistentLineBatcher;
// const auto DrawLine = lineBatcher->FPrimitiveDrawInterfaceVfTable->DrawLine;
// const auto self = reinterpret_cast<BYTE*>(lineBatcher) + offsetof(ULineBatchComponent, FPrimitiveDrawInterfaceVfTable);
// DrawLine(self, position, position + FVector{ scale, 0.f, 0.f }, FLinearColor{ 1, 0, 0, 1 }, 1, thickness);
// DrawLine(self, position, position + FVector{ 0.f, scale, 0.f }, FLinearColor{ 0, 1, 0, 1 }, 1, thickness);
// DrawLine(self, position, position + FVector{ 0.f, 0.f, scale }, FLinearColor{ 0, 0, 1, 1 }, 1, thickness);
//}
static void DrawCoordinateSystem(const FVector& position, const float scale, const float thickness = 1.f)
{
ULineBatchComponent* lineBatcher = StaticVariables::GWorld()->PersistentLineBatcher;
const auto DrawLine = lineBatcher->FPrimitiveDrawInterfaceVfTable->DrawLine;
const auto self = reinterpret_cast<BYTE*>(lineBatcher) + offsetof(ULineBatchComponent, FPrimitiveDrawInterfaceVfTable);
DrawLine(self, position, position + FVector{ scale, 0.f, 0.f }, FLinearColor{ 1, 0, 0, 1 }, 1, thickness);
DrawLine(self, position, position + FVector{ 0.f, scale, 0.f }, FLinearColor{ 0, 1, 0, 1 }, 1, thickness);
DrawLine(self, position, position + FVector{ 0.f, 0.f, scale }, FLinearColor{ 0, 0, 1, 1 }, 1, thickness);
}
74 changes: 34 additions & 40 deletions Shared-ASI/LEXInterop/LELiveLevelEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class LELiveLevelEditor final
static bool DrawLineToSelected;
static FLinearColor TraceLineColor;
static float TraceWidth;
static bool TraceOverlay;
static float CoordinateScale;
static std::set<FName> LevelsLoadedByLLE;

Expand All @@ -37,38 +36,43 @@ class LELiveLevelEditor final
SelectedComponentIndex = -1;
}

//puts all position data into the matrix, so edits will be consistent
//consolidates all transformation data into the properties, to simplify editing them
static void NormalizeSMC(UStaticMeshComponent* smc)
{
FVector translation;
FVector scale3D;
float pitch_rad;
float yaw_rad;
float roll_rad;
FMatrix tmp = smc->CachedParentToWorld;
smc->CachedParentToWorld = IdentityMatrix;
if (smc->AbsoluteTranslation)
{
smc->AbsoluteTranslation = false;
smc->CachedParentToWorld.WPlane = FPlane{ {0, 0, 0}, 1 };
tmp.WPlane = FPlane{ {0, 0, 0}, 1 };
}
if (smc->AbsoluteRotation || smc->AbsoluteScale)
{
FVector translation;
FVector scale3D;
float pitch_rad;
float yaw_rad;
float roll_rad;
MatrixDecompose(smc->CachedParentToWorld, translation, scale3D, pitch_rad, yaw_rad, roll_rad);
MatrixDecompose(tmp, translation, scale3D, pitch_rad, yaw_rad, roll_rad);
if (smc->AbsoluteRotation)
{
smc->AbsoluteRotation = false;
pitch_rad = yaw_rad = roll_rad = 0;
}
if (smc->AbsoluteScale)
{
smc->AbsoluteScale = false;
scale3D = FVector{ 1,1,1 };
}
smc->CachedParentToWorld = MatrixCompose(translation, scale3D, pitch_rad, yaw_rad, roll_rad);
tmp = MatrixCompose(translation, scale3D, pitch_rad, yaw_rad, roll_rad);
}
const auto pitch = UnrealRotationUnitsToRadians(smc->Rotation.Pitch);
const auto yaw = UnrealRotationUnitsToRadians(smc->Rotation.Yaw);
const auto roll = UnrealRotationUnitsToRadians(smc->Rotation.Roll);
smc->CachedParentToWorld = MatrixCompose(smc->Translation, smc->Scale3D * smc->Scale, pitch, yaw, roll);
tmp = MatrixCompose(smc->Translation, smc->Scale3D * smc->Scale, pitch, yaw, roll) * tmp;

MatrixDecompose(tmp, translation, scale3D, pitch_rad, yaw_rad, roll_rad);
smc->Translation = translation;
smc->Rotation = FRotator{ RadiansToUnrealRotationUnits(pitch_rad), RadiansToUnrealRotationUnits(yaw_rad), RadiansToUnrealRotationUnits(roll_rad) };
smc->Scale = 1;
smc->Scale3D = scale3D;
}

static void AppendActorsInLevel(std::wostringstream& ss, ULevelBase* const level)
Expand Down Expand Up @@ -242,7 +246,7 @@ class LELiveLevelEditor final
{
if (SelectedActor) {
FVector translation{};
float scale{};
float scale = 0;
FVector scale3D{};
FRotator rotation{};
if (IsA<AStaticMeshCollectionActor>(SelectedActor))
Expand All @@ -252,18 +256,11 @@ class LELiveLevelEditor final
if (compC && compC->IsA(UStaticMeshComponent::StaticClass()))
{
const auto smc = reinterpret_cast<UStaticMeshComponent*>(compC);
float pitch_rad;
float yaw_rad;
float roll_rad;
MatrixDecompose(smc->CachedParentToWorld, translation, scale3D, pitch_rad, yaw_rad, roll_rad);
rotation = FRotator{ RadiansToUnrealRotationUnits(pitch_rad),
RadiansToUnrealRotationUnits(yaw_rad),
RadiansToUnrealRotationUnits(roll_rad) };

translation = smc->Translation;
scale = smc->Scale;
if (abs(scale) >= 1e-6f)
{
scale3D /= scale;
}
scale3D = smc->Scale3D;
rotation = smc->Rotation;
}
}
else
Expand Down Expand Up @@ -360,7 +357,10 @@ class LELiveLevelEditor final
InteropActionQueue.push(new ComponentScaleAction(reinterpret_cast<UStaticMeshComponent*>(compC), scale));
}
}
InteropActionQueue.push(new ScaleAction(SelectedActor, scale));
else
{
InteropActionQueue.push(new ScaleAction(SelectedActor, scale));
}
}
}

Expand Down Expand Up @@ -428,13 +428,14 @@ class LELiveLevelEditor final
const auto comp = smca->Components(SelectedComponentIndex);
if (IsA<UStaticMeshComponent>(comp))
{
line_end = static_cast<FVector>(reinterpret_cast<UStaticMeshComponent*>(comp)->CachedParentToWorld.WPlane);
line_end = reinterpret_cast<UStaticMeshComponent*>(comp)->Translation;
}
}
DrawDebugLine(hud, SharedData::cachedPlayerPosition, line_end, TraceLineColor, TraceWidth, TraceOverlay, true);
//DrawCoordinateSystem(line_end, CoordinateScale, 3);
//hud->DrawDebugLine(SharedData::cachedPlayerPosition, line_end, 255, 255, 0, TRUE);
hud->DrawDebugCoordinateSystem(line_end, FRotator(), CoordinateScale, TRUE);
DrawDebugLine(SharedData::cachedPlayerPosition, line_end, TraceLineColor, TraceWidth);
DrawCoordinateSystem(line_end, CoordinateScale, TraceWidth);

//DO NOT DELETE! Lines of non-zero width will NOT be rendered unless a line of 0 width is also drawn.
DrawDebugLine(SharedData::cachedPlayerPosition, line_end, TraceLineColor, 0);
}
}
}
Expand Down Expand Up @@ -485,12 +486,6 @@ class LELiveLevelEditor final
return true;
}

if (IsCmd(&command, "LLE_TRACE_OVERLAY "))
{
TraceOverlay = strtol(command, &command, 10) != 0;
return true;
}

if (IsCmd(&command, "LLE_AXES_Scale "))
{
CoordinateScale = strtof(command, &command);
Expand Down Expand Up @@ -562,7 +557,6 @@ bool LELiveLevelEditor::DrawLineToSelected = true;
bool LELiveLevelEditor::IsLLEActive = false;
bool LELiveLevelEditor::IsPendingDeactivation = false;
FLinearColor LELiveLevelEditor::TraceLineColor = FLinearColor{1, 1, 0, 1};
float LELiveLevelEditor::TraceWidth = 0.f;
bool LELiveLevelEditor::TraceOverlay = false;
float LELiveLevelEditor::TraceWidth = 3.f;
float LELiveLevelEditor::CoordinateScale = 100;
std::set<FName> LELiveLevelEditor::LevelsLoadedByLLE{};
62 changes: 1 addition & 61 deletions Shared-ASI/LEXInterop/LLEActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,7 @@ struct ComponentMoveAction final : ActionBase

void Execute() override
{
FVector translation;
FVector scale3D;
float pitch;
float yaw;
float roll;
MatrixDecompose(Component->CachedParentToWorld, translation, scale3D, pitch, yaw, roll);
Component->CachedParentToWorld = IdentityMatrix;
Component->Rotation = FRotator{ RadiansToUnrealRotationUnits(pitch), RadiansToUnrealRotationUnits(yaw), RadiansToUnrealRotationUnits(roll) };
if (Component->Scale != 0)
{
Component->Scale3D = scale3D / Component->Scale;
}
Component->SetTranslation(Vector);
Component->CachedParentToWorld = MatrixCompose(Vector, scale3D, pitch, yaw, roll);
}
};

Expand All @@ -91,28 +78,7 @@ struct ComponentScaleAction final : ActionBase

void Execute() override
{
FVector translation;
FVector scale3D;
float pitch;
float yaw;
float roll;
MatrixDecompose(Component->CachedParentToWorld, translation, scale3D, pitch, yaw, roll);
Component->CachedParentToWorld = IdentityMatrix;
Component->Translation = translation;
Component->Rotation = FRotator{ RadiansToUnrealRotationUnits(pitch), RadiansToUnrealRotationUnits(yaw), RadiansToUnrealRotationUnits(roll) };
if (Component->Scale == 0)
{
Component->Scale3D = scale3D;
Component->SetScale(Scale);
}
else
{
scale3D /= Component->Scale;
Component->Scale3D = scale3D;
Component->SetScale(Scale);
scale3D *= Scale;
}
Component->CachedParentToWorld = MatrixCompose(translation, scale3D, pitch, yaw, roll);
Component->SetScale(Scale);
}
};

Expand All @@ -125,17 +91,7 @@ struct ComponentScale3DAction final : ActionBase

void Execute() override
{
FVector translation;
FVector scale;
float pitch;
float yaw;
float roll;
MatrixDecompose(Component->CachedParentToWorld, translation, scale, pitch, yaw, roll);
Component->CachedParentToWorld = IdentityMatrix;
Component->Translation = translation;
Component->Rotation = FRotator{ RadiansToUnrealRotationUnits(pitch), RadiansToUnrealRotationUnits(yaw), RadiansToUnrealRotationUnits(roll) };
Component->SetScale3D(ScaleVector);
Component->CachedParentToWorld = MatrixCompose(translation, ScaleVector * Component->Scale, pitch, yaw, roll);
}
};

Expand All @@ -148,22 +104,6 @@ struct ComponentRotateAction final : ActionBase

void Execute() override
{
FVector translation;
FVector scale3D;
float pitch;
float yaw;
float roll;
MatrixDecompose(Component->CachedParentToWorld, translation, scale3D, pitch, yaw, roll);
Component->CachedParentToWorld = IdentityMatrix;
Component->Translation = translation;
if (Component->Scale != 0)
{
Component->Scale3D = scale3D / Component->Scale;
}
Component->SetRotation(Rotator);
pitch = UnrealRotationUnitsToRadians(Rotator.Pitch);
yaw = UnrealRotationUnitsToRadians(Rotator.Yaw);
roll = UnrealRotationUnitsToRadians(Rotator.Roll);
Component->CachedParentToWorld = MatrixCompose(translation, scale3D, pitch, yaw, roll);
}
};
2 changes: 1 addition & 1 deletion Shared-ASI/ME3Tweaks/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ FMatrix MatrixCompose(FVector translation, FVector scale, float pitchRad, float
};
}

FMatrix operator* (const FMatrix& matrix1, FMatrix& matrix2)
FMatrix operator* (const FMatrix& matrix1, const FMatrix& matrix2)
{
typedef float MatrixAs2DArray[4][4];
MatrixAs2DArray& m1 = *((MatrixAs2DArray*)&matrix1);
Expand Down

0 comments on commit f6a6c75

Please sign in to comment.