2019-12-27 09:26:59 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-10-01 20:41:42 -04:00
|
|
|
|
|
|
|
|
#include "DynamicMeshBrushTool.h"
|
|
|
|
|
#include "InteractiveToolManager.h"
|
|
|
|
|
#include "ToolBuilderUtil.h"
|
2021-10-07 22:25:54 -04:00
|
|
|
#include "ToolSetupUtil.h"
|
2021-06-11 22:42:32 -04:00
|
|
|
#include "ModelingToolTargetUtil.h"
|
2021-03-18 17:20:32 -04:00
|
|
|
|
2021-03-09 19:33:56 -04:00
|
|
|
using namespace UE::Geometry;
|
|
|
|
|
|
2019-10-01 20:41:42 -04:00
|
|
|
// localization namespace
|
|
|
|
|
#define LOCTEXT_NAMESPACE "UDynamicMeshBrushTool"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tool
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
UDynamicMeshBrushTool::UDynamicMeshBrushTool()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UDynamicMeshBrushTool::Setup()
|
|
|
|
|
{
|
|
|
|
|
PreviewMesh = NewObject<UPreviewMesh>(this);
|
|
|
|
|
PreviewMesh->bBuildSpatialDataStructure = true;
|
2022-03-30 11:06:49 -04:00
|
|
|
PreviewMesh->CreateInWorld(GetTargetWorld(), FTransform::Identity);
|
2022-01-29 14:37:53 -05:00
|
|
|
FTransformSRT3d LocalToWorldTransform = UE::ToolTarget::GetLocalToWorldTransform(Target);
|
2021-06-11 22:42:32 -04:00
|
|
|
PreviewMesh->SetTransform((FTransform)LocalToWorldTransform);
|
2021-10-07 22:25:54 -04:00
|
|
|
ToolSetupUtil::ApplyRenderingConfigurationToPreview(PreviewMesh, Target);
|
2019-12-19 18:07:47 -05:00
|
|
|
|
2021-06-11 22:42:32 -04:00
|
|
|
FComponentMaterialSet MaterialSet = UE::ToolTarget::GetMaterialSet(Target);
|
2019-12-19 18:07:47 -05:00
|
|
|
PreviewMesh->SetMaterials(MaterialSet.Materials);
|
2019-10-01 20:41:42 -04:00
|
|
|
|
2021-06-11 22:42:32 -04:00
|
|
|
PreviewMesh->ReplaceMesh(UE::ToolTarget::GetDynamicMeshCopy(Target));
|
|
|
|
|
|
2019-10-01 20:41:42 -04:00
|
|
|
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();
|
2021-06-11 22:42:32 -04:00
|
|
|
double ScaledDim = LocalToWorldTransform.TransformVector(FVector::OneVector).Size();
|
2020-10-22 19:19:16 -04:00
|
|
|
this->WorldToLocalScale = FMathd::Sqrt3 / FMathd::Max(FMathf::ZeroTolerance, ScaledDim);
|
2019-10-01 20:41:42 -04:00
|
|
|
UBaseBrushTool::Setup();
|
|
|
|
|
|
2021-06-11 22:42:32 -04:00
|
|
|
UE::ToolTarget::HideSourceObject(Target);
|
2019-10-01 20:41:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double UDynamicMeshBrushTool::EstimateMaximumTargetDimension()
|
|
|
|
|
{
|
|
|
|
|
return InputMeshBoundsLocal.MaxDim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UDynamicMeshBrushTool::Shutdown(EToolShutdownType ShutdownType)
|
|
|
|
|
{
|
|
|
|
|
UBaseBrushTool::Shutdown(ShutdownType);
|
|
|
|
|
|
2021-06-11 22:42:32 -04:00
|
|
|
UE::ToolTarget::ShowSourceObject(Target);
|
2019-10-01 20:41:42 -04:00
|
|
|
|
|
|
|
|
if (PreviewMesh != nullptr)
|
|
|
|
|
{
|
|
|
|
|
PreviewMesh->GetOnMeshChanged().Remove(OnBaseMeshComponentChangedHandle);
|
|
|
|
|
|
|
|
|
|
OnShutdown(ShutdownType);
|
|
|
|
|
|
|
|
|
|
PreviewMesh->SetVisible(false);
|
|
|
|
|
PreviewMesh->Disconnect();
|
|
|
|
|
PreviewMesh = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool UDynamicMeshBrushTool::HitTest(const FRay& Ray, FHitResult& OutHit)
|
|
|
|
|
{
|
2021-11-17 21:03:28 -05:00
|
|
|
return PreviewMesh->FindRayIntersection(FRay3d(Ray), OutHit);
|
2019-10-01 20:41:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|