Files
UnrealEngineUWP/Engine/Plugins/Experimental/MeshModelingToolsetExp/Source/MeshModelingToolsExp/Private/DynamicMeshBrushTool.cpp
jimmy andrews fd07763a78 remove UE::Geometry::TRay3 and replace usages with UE::Math::TRay
#rb tyson.brochu
#rnx
#preflight 6195872476668b37001d1141

#ushell-cherrypick of 18231220 by Jimmy.Andrews

#ROBOMERGE-AUTHOR: jimmy.andrews
#ROBOMERGE-SOURCE: CL 18232491 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v895-18170469)

[CL 18232527 by jimmy andrews in ue5-release-engine-test branch]
2021-11-17 21:06:46 -05:00

90 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "DynamicMeshBrushTool.h"
#include "InteractiveToolManager.h"
#include "ToolBuilderUtil.h"
#include "ToolSetupUtil.h"
#include "ModelingToolTargetUtil.h"
using namespace UE::Geometry;
// localization namespace
#define LOCTEXT_NAMESPACE "UDynamicMeshBrushTool"
/*
* Tool
*/
UDynamicMeshBrushTool::UDynamicMeshBrushTool()
{
}
void UDynamicMeshBrushTool::Setup()
{
PreviewMesh = NewObject<UPreviewMesh>(this);
PreviewMesh->bBuildSpatialDataStructure = true;
PreviewMesh->CreateInWorld(UE::ToolTarget::GetTargetActor(Target)->GetWorld(), FTransform::Identity);
UE::Geometry::FTransform3d LocalToWorldTransform = UE::ToolTarget::GetLocalToWorldTransform(Target);
PreviewMesh->SetTransform((FTransform)LocalToWorldTransform);
ToolSetupUtil::ApplyRenderingConfigurationToPreview(PreviewMesh, Target);
FComponentMaterialSet MaterialSet = UE::ToolTarget::GetMaterialSet(Target);
PreviewMesh->SetMaterials(MaterialSet.Materials);
PreviewMesh->ReplaceMesh(UE::ToolTarget::GetDynamicMeshCopy(Target));
OnBaseMeshComponentChangedHandle = PreviewMesh->GetOnMeshChanged().Add(
FSimpleMulticastDelegate::FDelegate::CreateUObject(this, &UDynamicMeshBrushTool::OnBaseMeshComponentChanged));
// call this here so that base tool can estimate target dimension
InputMeshBoundsLocal = PreviewMesh->GetPreviewDynamicMesh()->GetBounds();
double ScaledDim = LocalToWorldTransform.TransformVector(FVector::OneVector).Size();
this->WorldToLocalScale = FMathd::Sqrt3 / FMathd::Max(FMathf::ZeroTolerance, ScaledDim);
UBaseBrushTool::Setup();
UE::ToolTarget::HideSourceObject(Target);
}
double UDynamicMeshBrushTool::EstimateMaximumTargetDimension()
{
return InputMeshBoundsLocal.MaxDim();
}
void UDynamicMeshBrushTool::Shutdown(EToolShutdownType ShutdownType)
{
UBaseBrushTool::Shutdown(ShutdownType);
UE::ToolTarget::ShowSourceObject(Target);
if (PreviewMesh != nullptr)
{
PreviewMesh->GetOnMeshChanged().Remove(OnBaseMeshComponentChangedHandle);
OnShutdown(ShutdownType);
PreviewMesh->SetVisible(false);
PreviewMesh->Disconnect();
PreviewMesh = nullptr;
}
}
bool UDynamicMeshBrushTool::HitTest(const FRay& Ray, FHitResult& OutHit)
{
return PreviewMesh->FindRayIntersection(FRay3d(Ray), OutHit);
}
#undef LOCTEXT_NAMESPACE