2019-12-27 09:26:59 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2019-10-01 20:41:42 -04:00
# include "PlaneCutTool.h"
# include "InteractiveToolManager.h"
# include "ToolBuilderUtil.h"
# include "ToolSetupUtil.h"
2021-06-13 00:36:02 -04:00
# include "DynamicMesh/DynamicMesh3.h"
# include "DynamicMesh/DynamicMeshTriangleAttribute.h"
2019-12-19 18:07:47 -05:00
# include "DynamicMeshEditor.h"
2019-10-01 20:41:42 -04:00
# include "Selection/SelectClickedAction.h"
# include "MeshDescriptionToDynamicMesh.h"
# include "DynamicMeshToMeshDescription.h"
# include "InteractiveGizmoManager.h"
# include "BaseGizmos/GizmoComponents.h"
2021-09-30 08:27:39 -04:00
# include "BaseGizmos/CombinedTransformGizmo.h"
2019-10-01 20:41:42 -04:00
# include "Drawing/MeshDebugDrawing.h"
2021-06-02 15:58:00 -04:00
# include "ModelingObjectsCreationAPI.h"
2019-10-01 20:41:42 -04:00
2019-12-19 18:07:47 -05:00
# include "Changes/ToolCommandChangeSequence.h"
2019-10-01 20:41:42 -04:00
# include "CuttingOps/PlaneCutOp.h"
2019-12-19 18:07:47 -05:00
# include "Misc/MessageDialog.h"
ModelingTools: add support for creating Volumes directly from DrawPolygon, DrawRevolve, DrawPolyPath, and AddPrimitive, CombineMeshes, CutMeshWithMesh, PlaneCut, BaseCreateFromSelected Tools. Improve support for Editing volumes, eg handling mesh/volume interactions, and add configurable auto-simplification for volumes to avoid painful Editor hangs.
- Move ToolTarget implementations, DynamicMeshToVolume to ModelingComponentsEditorOnly module
- move VolumeToDynamicMesh, DynamicMeshProvider/Commiter interfaces to ModelingComponents module
- Add UCreateMeshObjectTypeProperties property set to expose mesh/volume options
- Add FCreateMeshObjectParams::TypeHintClass to allow AVolume type (or other UClass hints) to be passed to creation APIs
- Add UE::ToolTarget::ConfigureCreateMeshObjectParams() util function in ModelingToolTargetUtil, tries to determine output type in a FCreateMeshObjectParams based on input ToolTarget
- Add UEditorModelingObjectsCreationAPI::CreateVolume() implementation
- Add UEditorModelingObjectsCreationAPI::FilterMaterials() that strips out any internal materials and replaces with WorldGridMaterial. This occurs when (eg) subtracting a Volume from a StaticMesh, because the temporary volume mesh gets assigned internal materials, but the Tools don't know this. Use in EditorModelingObjectsCreationAPI when creating new objects. UStaticMeshComponentToolTarget also does this filtering in ::CommitMaterialSetUpdate().
- Add ::ComponentTypeSupportsCollision() function to ComponentCollisionUtil, use to avoid checks/ensures for Volume targets
- Add support for automatic mesh simplification in DynamicMeshToVolume. Add CVar to VolumeDynamicMeshToolTarget.h to control max triangle count (default 500). Apply auto-simplify when creating or updating an AVolume. This prevents the Editor from blocking for long periods on meshes that are too high-res for volumes (even 500 is quite high).
- DynamicMeshToVolume now emits polygroup-faces that contain holes (ie multiple boundary loops) as a set of triangles, rather than emitting separate overlapping faces for each boundary loop
#rb none
#rnx
#jira none
#preflight 60ba50632c42ea0001cb54c5
[CL 16561742 by Ryan Schmidt in ue5-main branch]
2021-06-04 16:04:03 -04:00
# include "ModelingToolTargetUtil.h"
2021-03-11 11:40:03 -04:00
# include "TargetInterfaces/MaterialProvider.h"
# include "TargetInterfaces/MeshDescriptionCommitter.h"
# include "TargetInterfaces/MeshDescriptionProvider.h"
# include "TargetInterfaces/PrimitiveComponentBackedTarget.h"
2021-12-06 12:42:19 -05:00
# include "ModelingToolTargetUtil.h"
2021-03-11 11:40:03 -04:00
2021-03-09 19:33:56 -04:00
using namespace UE : : Geometry ;
2019-10-01 20:41:42 -04:00
2021-03-09 19:33:56 -04:00
# define LOCTEXT_NAMESPACE "UPlaneCutTool"
2019-10-01 20:41:42 -04:00
/*
* ToolBuilder
*/
2021-11-23 09:42:40 -05:00
UMultiSelectionMeshEditingTool * UPlaneCutToolBuilder : : CreateNewTool ( const FToolBuilderState & SceneState ) const
2021-03-11 11:40:03 -04:00
{
2021-11-23 09:42:40 -05:00
return NewObject < UPlaneCutTool > ( SceneState . ToolManager ) ;
2019-10-01 20:41:42 -04:00
}
/*
* Tool
*/
UPlaneCutTool : : UPlaneCutTool ( )
{
}
void UPlaneCutTool : : Setup ( )
{
UInteractiveTool : : Setup ( ) ;
2019-10-30 20:48:19 -04:00
// hide input StaticMeshComponents
2021-03-11 11:40:03 -04:00
for ( int32 ComponentIdx = 0 ; ComponentIdx < Targets . Num ( ) ; ComponentIdx + + )
2019-10-30 20:48:19 -04:00
{
2021-11-23 09:42:40 -05:00
UE : : ToolTarget : : HideSourceObject ( Targets [ ComponentIdx ] ) ;
2019-10-30 20:48:19 -04:00
}
2021-03-11 11:40:03 -04:00
TArray < int32 > MapToFirstOccurrences ;
bool bAnyHaveSameSource = GetMapToSharedSourceData ( MapToFirstOccurrences ) ;
2020-01-27 20:11:15 -05:00
2021-03-11 11:40:03 -04:00
if ( bAnyHaveSameSource )
2020-01-27 20:11:15 -05:00
{
GetToolManager ( ) - > DisplayMessage (
LOCTEXT ( " PlaneCutMultipleAssetWithSameSource " , " WARNING: Multiple meshes in your selection use the same source asset! Plane cuts apply to the source asset, and this tool will not duplicate assets for you, so the tool typically cannot give a correct result in this case. Please consider exiting the tool and duplicating the source assets. " ) ,
EToolMessageLevel : : UserWarning ) ;
}
2019-10-30 20:48:19 -04:00
// Convert input mesh descriptions to dynamic mesh
2021-03-11 11:40:03 -04:00
for ( int Idx = 0 ; Idx < Targets . Num ( ) ; Idx + + )
2019-10-30 20:48:19 -04:00
{
2019-12-19 18:07:47 -05:00
FDynamicMesh3 * OriginalDynamicMesh = new FDynamicMesh3 ;
2019-10-30 20:48:19 -04:00
FMeshDescriptionToDynamicMesh Converter ;
2021-11-23 09:42:40 -05:00
Converter . Convert ( UE : : ToolTarget : : GetMeshDescription ( Targets [ Idx ] ) , * OriginalDynamicMesh ) ;
2019-12-19 18:07:47 -05:00
OriginalDynamicMesh - > EnableAttributes ( ) ;
TDynamicMeshScalarTriangleAttribute < int > * SubObjectIDs = new TDynamicMeshScalarTriangleAttribute < int > ( OriginalDynamicMesh ) ;
SubObjectIDs - > Initialize ( 0 ) ;
2020-11-01 22:12:11 -04:00
OriginalDynamicMesh - > Attributes ( ) - > AttachAttribute ( FPlaneCutOp : : ObjectIndexAttribute , SubObjectIDs ) ;
2019-12-19 18:07:47 -05:00
/// fill in the MeshesToCut array
UDynamicMeshReplacementChangeTarget * Target = MeshesToCut . Add_GetRef ( NewObject < UDynamicMeshReplacementChangeTarget > ( ) ) ;
// store a UV scale based on the original mesh bounds (we don't want to recompute this between cuts b/c we want consistent UV scale)
MeshUVScaleFactor . Add ( 1.0 / OriginalDynamicMesh - > GetBounds ( ) . MaxDim ( ) ) ;
// Set callbacks so previews are invalidated on undo/redo changing the meshes
2021-02-17 11:50:23 -04:00
Target - > SetMesh ( TSharedPtr < const FDynamicMesh3 , ESPMode : : ThreadSafe > ( OriginalDynamicMesh ) ) ;
2019-12-19 18:07:47 -05:00
Target - > OnMeshChanged . AddLambda ( [ this , Idx ] ( ) { Previews [ Idx ] - > InvalidateResult ( ) ; } ) ;
2019-10-30 20:48:19 -04:00
}
2019-10-01 20:41:42 -04:00
// initialize our properties
BasicProperties = NewObject < UPlaneCutToolProperties > ( this , TEXT ( " Plane Cut Settings " ) ) ;
2020-01-27 20:11:15 -05:00
BasicProperties - > RestoreProperties ( this ) ;
2019-10-01 20:41:42 -04:00
AddToolPropertySource ( BasicProperties ) ;
2019-12-19 18:07:47 -05:00
AcceptProperties = NewObject < UAcceptOutputProperties > ( this , TEXT ( " Tool Accept Output Settings " ) ) ;
2020-01-27 20:11:15 -05:00
AcceptProperties - > RestoreProperties ( this ) ;
2019-12-19 18:07:47 -05:00
AddToolPropertySource ( AcceptProperties ) ;
2020-01-27 20:11:15 -05:00
ToolPropertyObjects . Add ( this ) ;
2019-10-01 20:41:42 -04:00
// initialize the PreviewMesh+BackgroundCompute object
2019-12-19 18:07:47 -05:00
SetupPreviews ( ) ;
2019-10-01 20:41:42 -04:00
// set initial cut plane (also attaches gizmo/proxy)
2019-10-30 20:48:19 -04:00
FBox CombinedBounds ; CombinedBounds . Init ( ) ;
2021-03-11 11:40:03 -04:00
for ( int Idx = 0 ; Idx < Targets . Num ( ) ; Idx + + )
2019-10-30 20:48:19 -04:00
{
FVector ComponentOrigin , ComponentExtents ;
2021-11-23 09:42:40 -05:00
UE : : ToolTarget : : GetTargetActor ( Targets [ Idx ] ) - > GetActorBounds ( false , ComponentOrigin , ComponentExtents ) ;
2019-10-30 20:48:19 -04:00
CombinedBounds + = FBox : : BuildAABB ( ComponentOrigin , ComponentExtents ) ;
}
2021-04-19 21:00:31 -04:00
CutPlaneWorld . Origin = ( FVector3d ) CombinedBounds . GetCenter ( ) ;
PlaneMechanic = NewObject < UConstructionPlaneMechanic > ( this ) ;
PlaneMechanic - > Setup ( this ) ;
2022-01-28 10:18:10 -05:00
PlaneMechanic - > Initialize ( GetTargetWorld ( ) , CutPlaneWorld ) ;
2021-04-19 21:00:31 -04:00
PlaneMechanic - > OnPlaneChanged . AddLambda ( [ this ] ( ) {
CutPlaneWorld = PlaneMechanic - > Plane ;
InvalidatePreviews ( ) ;
} ) ;
for ( int Idx = 0 ; Idx < Targets . Num ( ) ; Idx + + )
{
2021-11-23 09:42:40 -05:00
PlaneMechanic - > SetPlaneCtrlClickBehaviorTarget - > InvisibleComponentsToHitTest . Add ( UE : : ToolTarget : : GetTargetComponent ( Targets [ Idx ] ) ) ;
2021-04-19 21:00:31 -04:00
}
InvalidatePreviews ( ) ;
2019-10-01 20:41:42 -04:00
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
Preview - > InvalidateResult ( ) ;
}
2020-01-27 20:11:15 -05:00
2021-02-08 17:02:09 -04:00
SetToolDisplayName ( LOCTEXT ( " ToolName " , " Plane Cut " ) ) ;
2020-01-27 20:11:15 -05:00
GetToolManager ( ) - > DisplayMessage (
2021-07-23 01:35:18 -04:00
LOCTEXT ( " OnStartPlaneCutTool " , " Press 'T' or use the Cut button to cut the mesh without leaving the tool. Press 'R' to flip the plane direction. " ) ,
2020-01-27 20:11:15 -05:00
EToolMessageLevel : : UserNotification ) ;
2019-10-01 20:41:42 -04:00
}
2020-01-27 20:11:15 -05:00
void UPlaneCutTool : : RegisterActions ( FInteractiveToolActionSet & ActionSet )
{
ActionSet . RegisterAction ( this , ( int32 ) EStandardToolActions : : BaseClientDefinedActionID + 101 ,
TEXT ( " Do Plane Cut " ) ,
LOCTEXT ( " DoPlaneCut " , " Do Plane Cut " ) ,
LOCTEXT ( " DoPlaneCutTooltip " , " Cut the mesh with the current cutting plane, without exiting the tool " ) ,
2021-04-20 18:16:23 -04:00
EModifierKey : : None , EKeys : : T ,
2020-01-27 20:11:15 -05:00
[ this ] ( ) { this - > Cut ( ) ; } ) ;
2021-04-02 20:38:44 -04:00
ActionSet . RegisterAction ( this , ( int32 ) EStandardToolActions : : BaseClientDefinedActionID + 102 ,
TEXT ( " Flip Cutting Plane " ) ,
LOCTEXT ( " FlipCutPlane " , " Flip Cutting Plane " ) ,
LOCTEXT ( " FlipCutPlaneTooltip " , " Flip the cutting plane " ) ,
2021-04-20 18:16:23 -04:00
EModifierKey : : None , EKeys : : R ,
2021-04-02 20:38:44 -04:00
[ this ] ( ) { this - > FlipPlane ( ) ; } ) ;
2020-01-27 20:11:15 -05:00
}
2019-12-19 18:07:47 -05:00
void UPlaneCutTool : : SetupPreviews ( )
2019-10-01 20:41:42 -04:00
{
int32 CurrentNumPreview = Previews . Num ( ) ;
2019-12-19 18:07:47 -05:00
int32 NumSourceMeshes = MeshesToCut . Num ( ) ;
int32 TargetNumPreview = NumSourceMeshes ;
for ( int32 PreviewIdx = CurrentNumPreview ; PreviewIdx < TargetNumPreview ; PreviewIdx + + )
2019-10-01 20:41:42 -04:00
{
2019-12-19 18:07:47 -05:00
UPlaneCutOperatorFactory * CutSide = NewObject < UPlaneCutOperatorFactory > ( ) ;
CutSide - > CutTool = this ;
CutSide - > ComponentIndex = PreviewIdx ;
UMeshOpPreviewWithBackgroundCompute * Preview = Previews . Add_GetRef ( NewObject < UMeshOpPreviewWithBackgroundCompute > ( CutSide , " Preview " ) ) ;
2022-01-28 10:18:10 -05:00
Preview - > Setup ( GetTargetWorld ( ) , CutSide ) ;
2021-10-07 22:25:54 -04:00
ToolSetupUtil : : ApplyRenderingConfigurationToPreview ( Preview - > PreviewMesh , nullptr ) ;
2021-06-11 22:42:32 -04:00
Preview - > PreviewMesh - > SetTangentsMode ( EDynamicMeshComponentTangentsMode : : AutoCalculated ) ;
2019-12-19 18:07:47 -05:00
2021-11-23 09:42:40 -05:00
const FComponentMaterialSet MaterialSet = UE : : ToolTarget : : GetMaterialSet ( Targets [ PreviewIdx ] ) ;
2019-12-19 18:07:47 -05:00
Preview - > ConfigureMaterials ( MaterialSet . Materials ,
ToolSetupUtil : : GetDefaultWorkingMaterial ( GetToolManager ( ) )
) ;
// set initial preview to un-processed mesh, so stuff doesn't just disappear if the first cut takes a while
Preview - > PreviewMesh - > UpdatePreview ( MeshesToCut [ PreviewIdx ] - > GetMesh ( ) . Get ( ) ) ;
2021-11-23 09:42:40 -05:00
Preview - > PreviewMesh - > SetTransform ( ( FTransform ) UE : : ToolTarget : : GetLocalToWorldTransform ( Targets [ PreviewIdx ] ) ) ;
2019-12-19 18:07:47 -05:00
Preview - > SetVisibility ( BasicProperties - > bShowPreview ) ;
2019-10-01 20:41:42 -04:00
}
}
2021-04-15 11:12:55 -04:00
void UPlaneCutTool : : DoFlipPlane ( )
2021-04-02 20:38:44 -04:00
{
GetToolManager ( ) - > BeginUndoTransaction ( LOCTEXT ( " FlipPlaneTransactionName " , " Flip Plane " ) ) ;
2021-04-19 21:00:31 -04:00
FVector3d Origin = CutPlaneWorld . Origin ;
FVector3d Normal = CutPlaneWorld . GetAxis ( 2 ) ;
PlaneMechanic - > SetDrawPlaneFromWorldPos ( Origin , - Normal , false ) ;
2021-04-02 20:38:44 -04:00
GetToolManager ( ) - > EndUndoTransaction ( ) ;
}
2019-12-19 18:07:47 -05:00
2021-04-15 11:12:55 -04:00
void UPlaneCutTool : : DoCut ( )
2019-12-19 18:07:47 -05:00
{
if ( ! CanAccept ( ) )
{
return ;
}
TUniquePtr < FToolCommandChangeSequence > ChangeSeq = MakeUnique < FToolCommandChangeSequence > ( ) ;
TArray < FDynamicMeshOpResult > Results ;
for ( int Idx = 0 , N = MeshesToCut . Num ( ) ; Idx < N ; Idx + + )
{
UMeshOpPreviewWithBackgroundCompute * Preview = Previews [ Idx ] ;
TUniquePtr < FDynamicMesh3 > ResultMesh = Preview - > PreviewMesh - > ExtractPreviewMesh ( ) ;
ChangeSeq - > AppendChange ( MeshesToCut [ Idx ] , MeshesToCut [ Idx ] - > ReplaceMesh (
2021-02-17 11:50:23 -04:00
TSharedPtr < const FDynamicMesh3 , ESPMode : : ThreadSafe > ( ResultMesh . Release ( ) ) )
2019-12-19 18:07:47 -05:00
) ;
}
// emit combined change sequence
GetToolManager ( ) - > EmitObjectChange ( this , MoveTemp ( ChangeSeq ) , LOCTEXT ( " MeshPlaneCut " , " Cut Mesh with Plane " ) ) ;
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
Preview - > InvalidateResult ( ) ;
}
}
2022-01-28 18:40:54 -05:00
void UPlaneCutTool : : OnShutdown ( EToolShutdownType ShutdownType )
2019-10-01 20:41:42 -04:00
{
2021-04-19 21:00:31 -04:00
PlaneMechanic - > Shutdown ( ) ;
2020-01-27 20:11:15 -05:00
BasicProperties - > SaveProperties ( this ) ;
AcceptProperties - > SaveProperties ( this ) ;
2019-10-01 20:41:42 -04:00
// Restore (unhide) the source meshes
2021-03-11 11:40:03 -04:00
for ( int Idx = 0 ; Idx < Targets . Num ( ) ; Idx + + )
2019-10-30 20:48:19 -04:00
{
2021-11-23 09:42:40 -05:00
UE : : ToolTarget : : ShowSourceObject ( Targets [ Idx ] ) ;
2019-10-30 20:48:19 -04:00
}
2019-10-01 20:41:42 -04:00
2019-10-02 12:05:44 -04:00
TArray < FDynamicMeshOpResult > Results ;
2019-10-01 20:41:42 -04:00
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
Results . Emplace ( Preview - > Shutdown ( ) ) ;
}
if ( ShutdownType = = EToolShutdownType : : Accept )
{
GenerateAsset ( Results ) ;
}
}
2019-10-04 14:13:21 -04:00
TUniquePtr < FDynamicMeshOperator > UPlaneCutOperatorFactory : : MakeNewOperator ( )
2019-10-01 20:41:42 -04:00
{
2019-10-04 14:13:21 -04:00
TUniquePtr < FPlaneCutOp > CutOp = MakeUnique < FPlaneCutOp > ( ) ;
2019-10-01 20:41:42 -04:00
CutOp - > bFillCutHole = CutTool - > BasicProperties - > bFillCutHole ;
CutOp - > bFillSpans = CutTool - > BasicProperties - > bFillSpans ;
2021-11-23 09:42:40 -05:00
FTransform LocalToWorld = ( FTransform ) UE : : ToolTarget : : GetLocalToWorldTransform ( CutTool - > Targets [ ComponentIndex ] ) ;
2019-12-19 18:07:47 -05:00
CutOp - > SetTransform ( LocalToWorld ) ;
// for all plane computation, change LocalToWorld to not have any zero scale dims
FVector LocalToWorldScale = LocalToWorld . GetScale3D ( ) ;
for ( int i = 0 ; i < 3 ; i + + )
{
float DimScale = FMathf : : Abs ( LocalToWorldScale [ i ] ) ;
float Tolerance = KINDA_SMALL_NUMBER ;
if ( DimScale < Tolerance )
{
LocalToWorldScale [ i ] = Tolerance * FMathf : : SignNonZero ( LocalToWorldScale [ i ] ) ;
}
}
LocalToWorld . SetScale3D ( LocalToWorldScale ) ;
2021-04-19 21:00:31 -04:00
2022-05-12 12:08:26 -04:00
FVector LocalOrigin = LocalToWorld . InverseTransformPosition ( ( FVector ) CutTool - > CutPlaneWorld . Origin ) ;
2021-04-19 21:00:31 -04:00
FVector3d WorldNormal = CutTool - > CutPlaneWorld . GetAxis ( 2 ) ;
2022-05-12 12:08:26 -04:00
FTransformSRT3d L2WForNormal ( LocalToWorld ) ;
FVector LocalNormal = ( FVector ) L2WForNormal . InverseTransformNormal ( WorldNormal ) ;
2019-12-19 18:07:47 -05:00
FVector BackTransformed = LocalToWorld . TransformVector ( LocalNormal ) ;
2021-04-19 21:00:31 -04:00
float NormalScaleFactor = FVector : : DotProduct ( BackTransformed , ( FVector ) WorldNormal ) ;
2019-12-19 18:07:47 -05:00
if ( NormalScaleFactor > = FLT_MIN )
2019-10-01 20:41:42 -04:00
{
2019-12-19 18:07:47 -05:00
NormalScaleFactor = 1.0 / NormalScaleFactor ;
2019-10-01 20:41:42 -04:00
}
2021-03-30 21:25:22 -04:00
CutOp - > LocalPlaneOrigin = ( FVector3d ) LocalOrigin ;
CutOp - > LocalPlaneNormal = ( FVector3d ) LocalNormal ;
2019-12-19 18:07:47 -05:00
CutOp - > OriginalMesh = CutTool - > MeshesToCut [ ComponentIndex ] - > GetMesh ( ) ;
CutOp - > bKeepBothHalves = CutTool - > BasicProperties - > bKeepBothHalves ;
CutOp - > CutPlaneLocalThickness = CutTool - > BasicProperties - > SpacingBetweenHalves * NormalScaleFactor ;
CutOp - > UVScaleFactor = CutTool - > MeshUVScaleFactor [ ComponentIndex ] ;
2019-10-01 20:41:42 -04:00
return CutOp ;
}
void UPlaneCutTool : : Render ( IToolsContextRenderAPI * RenderAPI )
{
2021-04-19 21:00:31 -04:00
PlaneMechanic - > Render ( RenderAPI ) ;
2019-10-01 20:41:42 -04:00
}
2020-04-18 18:42:59 -04:00
void UPlaneCutTool : : OnTick ( float DeltaTime )
2019-10-01 20:41:42 -04:00
{
2021-04-19 21:00:31 -04:00
PlaneMechanic - > Tick ( DeltaTime ) ;
2021-04-15 11:12:55 -04:00
if ( PendingAction ! = EPlaneCutToolActions : : NoAction )
{
if ( PendingAction = = EPlaneCutToolActions : : Cut )
{
DoCut ( ) ;
}
else if ( PendingAction = = EPlaneCutToolActions : : FlipPlane )
{
DoFlipPlane ( ) ;
}
PendingAction = EPlaneCutToolActions : : NoAction ;
}
2019-10-01 20:41:42 -04:00
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
Preview - > Tick ( DeltaTime ) ;
}
}
# if WITH_EDITOR
void UPlaneCutTool : : PostEditChangeProperty ( FPropertyChangedEvent & PropertyChangedEvent )
{
2021-04-19 21:00:31 -04:00
InvalidatePreviews ( ) ;
2019-10-01 20:41:42 -04:00
}
# endif
2021-04-19 21:00:31 -04:00
2020-01-07 15:54:23 -05:00
void UPlaneCutTool : : OnPropertyModified ( UObject * PropertySet , FProperty * Property )
2019-10-01 20:41:42 -04:00
{
if ( Property & & ( Property - > GetFName ( ) = = GET_MEMBER_NAME_CHECKED ( UPlaneCutToolProperties , bShowPreview ) ) )
{
2021-03-11 11:40:03 -04:00
for ( int Idx = 0 ; Idx < Targets . Num ( ) ; Idx + + )
2019-10-30 20:48:19 -04:00
{
2021-11-23 09:42:40 -05:00
UE : : ToolTarget : : SetSourceObjectVisible ( Targets [ Idx ] , ! BasicProperties - > bShowPreview ) ;
2019-10-30 20:48:19 -04:00
}
2019-10-01 20:41:42 -04:00
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
Preview - > SetVisibility ( BasicProperties - > bShowPreview ) ;
}
}
2021-04-19 21:00:31 -04:00
InvalidatePreviews ( ) ;
2019-10-01 20:41:42 -04:00
}
2020-01-27 20:11:15 -05:00
2021-04-19 21:00:31 -04:00
void UPlaneCutTool : : InvalidatePreviews ( )
2019-10-01 20:41:42 -04:00
{
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
Preview - > InvalidateResult ( ) ;
}
}
bool UPlaneCutTool : : CanAccept ( ) const
{
for ( UMeshOpPreviewWithBackgroundCompute * Preview : Previews )
{
if ( ! Preview - > HaveValidResult ( ) )
{
return false ;
}
}
2020-11-24 18:42:39 -04:00
return Super : : CanAccept ( ) ;
2019-10-01 20:41:42 -04:00
}
2019-10-02 12:05:44 -04:00
void UPlaneCutTool : : GenerateAsset ( const TArray < FDynamicMeshOpResult > & Results )
2019-10-01 20:41:42 -04:00
{
2019-12-19 18:07:47 -05:00
if ( Results . Num ( ) = = 0 )
2019-10-29 16:59:35 -04:00
{
return ;
}
2019-10-01 20:41:42 -04:00
GetToolManager ( ) - > BeginUndoTransaction ( LOCTEXT ( " PlaneCutToolTransactionName " , " Plane Cut Tool " ) ) ;
// currently in-place replaces the first half, and adds a new actor for the second half (if it was generated)
// TODO: options to support other choices re what should be a new actor
2019-10-30 20:48:19 -04:00
ensure ( Results . Num ( ) > 0 ) ;
2019-12-19 18:07:47 -05:00
int32 NumSourceMeshes = MeshesToCut . Num ( ) ;
TArray < TArray < FDynamicMesh3 > > AllSplitMeshes ; AllSplitMeshes . SetNum ( NumSourceMeshes ) ;
2019-10-01 20:41:42 -04:00
2019-12-19 18:07:47 -05:00
// build a selection change starting w/ the original selection (used if objects are added below)
FSelectedOjectsChangeList NewSelection ;
NewSelection . ModificationType = ESelectedObjectsModificationType : : Replace ;
2019-10-30 20:48:19 -04:00
for ( int OrigMeshIdx = 0 ; OrigMeshIdx < NumSourceMeshes ; OrigMeshIdx + + )
2019-10-01 20:41:42 -04:00
{
2021-11-23 09:42:40 -05:00
NewSelection . Actors . Add ( UE : : ToolTarget : : GetTargetActor ( Targets [ OrigMeshIdx ] ) ) ;
2019-12-19 18:07:47 -05:00
}
2019-10-01 20:41:42 -04:00
2019-12-19 18:07:47 -05:00
// check if we entirely cut away any meshes
bool bWantDestroy = false ;
for ( int OrigMeshIdx = 0 ; OrigMeshIdx < NumSourceMeshes ; OrigMeshIdx + + )
{
bWantDestroy = bWantDestroy | | ( Results [ OrigMeshIdx ] . Mesh - > TriangleCount ( ) = = 0 ) ;
}
// if so ask user what to do
if ( bWantDestroy )
{
FText Title = LOCTEXT ( " PlaneCutDestroyTitle " , " Delete mesh components? " ) ;
EAppReturnType : : Type Ret = FMessageDialog : : Open ( EAppMsgType : : YesNo ,
2021-11-07 23:43:01 -05:00
LOCTEXT ( " PlaneCutDestroyQuestion " , " Plane cuts have entirely cut away at least one mesh. Do you actually want to delete these mesh components? Note that either way all actors will remain, and meshes that are not fully cut away will still be cut as normal. " ) , & Title ) ;
2021-12-01 19:33:51 -05:00
if ( Ret = = EAppReturnType : : No | | Ret = = EAppReturnType : : Cancel )
2019-10-18 18:05:52 -04:00
{
2019-12-19 18:07:47 -05:00
bWantDestroy = false ; // quell destructive urge
2019-10-18 18:05:52 -04:00
}
2019-12-19 18:07:47 -05:00
}
bool bNeedToAdd = false ; // will be set to true if any mesh will be partly split out into a new generated asset
for ( int OrigMeshIdx = 0 ; OrigMeshIdx < NumSourceMeshes ; OrigMeshIdx + + )
{
FDynamicMesh3 * UseMesh = Results [ OrigMeshIdx ] . Mesh . Get ( ) ;
check ( UseMesh ! = nullptr ) ;
if ( UseMesh - > TriangleCount ( ) = = 0 )
{
if ( bWantDestroy )
{
2021-11-23 09:42:40 -05:00
UE : : ToolTarget : : GetTargetComponent ( Targets [ OrigMeshIdx ] ) - > DestroyComponent ( ) ;
2019-12-19 18:07:47 -05:00
}
continue ;
}
2020-01-27 20:11:15 -05:00
if ( AcceptProperties - > bExportSeparatedPiecesAsNewMeshAssets )
2019-12-19 18:07:47 -05:00
{
TDynamicMeshScalarTriangleAttribute < int > * SubMeshIDs =
static_cast < TDynamicMeshScalarTriangleAttribute < int > * > ( UseMesh - > Attributes ( ) - > GetAttachedAttribute (
2020-11-01 22:12:11 -04:00
FPlaneCutOp : : ObjectIndexAttribute ) ) ;
2019-12-19 18:07:47 -05:00
TArray < FDynamicMesh3 > & SplitMeshes = AllSplitMeshes [ OrigMeshIdx ] ;
bool bWasSplit = FDynamicMeshEditor : : SplitMesh ( UseMesh , SplitMeshes , [ SubMeshIDs ] ( int TID )
{
return SubMeshIDs - > GetValue ( TID ) ;
}
) ;
if ( bWasSplit )
{
// split mesh did something but has no meshes in the output array??
if ( ! ensure ( SplitMeshes . Num ( ) > 0 ) )
{
continue ;
}
bNeedToAdd = bNeedToAdd | | ( SplitMeshes . Num ( ) > 1 ) ;
UseMesh = & SplitMeshes [ 0 ] ;
}
}
2021-12-06 12:42:19 -05:00
UE : : ToolTarget : : CommitMeshDescriptionUpdateViaDynamicMesh ( Targets [ OrigMeshIdx ] , * UseMesh , true ) ;
2019-10-30 20:48:19 -04:00
}
2019-09-12 19:45:55 -04:00
2019-12-19 18:07:47 -05:00
if ( bNeedToAdd )
2019-09-12 13:55:17 -04:00
{
2019-12-19 18:07:47 -05:00
for ( int OrigMeshIdx = 0 ; OrigMeshIdx < NumSourceMeshes ; OrigMeshIdx + + )
{
TArray < FDynamicMesh3 > & SplitMeshes = AllSplitMeshes [ OrigMeshIdx ] ;
if ( SplitMeshes . Num ( ) < 2 )
{
continue ;
}
2019-10-30 20:48:19 -04:00
2021-04-13 17:15:34 -04:00
// get materials for both the component and the asset
2021-11-23 09:42:40 -05:00
const FComponentMaterialSet ComponentMaterialSet = UE : : ToolTarget : : GetMaterialSet ( Targets [ OrigMeshIdx ] , false ) ;
const FComponentMaterialSet AssetMaterialSet = UE : : ToolTarget : : GetMaterialSet ( Targets [ OrigMeshIdx ] , true /*prefer asset materials*/ ) ;
2019-12-19 18:07:47 -05:00
// add all the additional meshes
for ( int AddMeshIdx = 1 ; AddMeshIdx < SplitMeshes . Num ( ) ; AddMeshIdx + + )
{
2021-06-02 15:58:00 -04:00
FCreateMeshObjectParams NewMeshObjectParams ;
2022-01-28 10:18:10 -05:00
NewMeshObjectParams . TargetWorld = GetTargetWorld ( ) ;
2021-06-02 15:58:00 -04:00
NewMeshObjectParams . Transform = ( FTransform ) Results [ OrigMeshIdx ] . Transform ;
NewMeshObjectParams . BaseName = TEXT ( " PlaneCutOtherPart " ) ;
NewMeshObjectParams . Materials = ComponentMaterialSet . Materials ;
NewMeshObjectParams . AssetMaterials = AssetMaterialSet . Materials ;
NewMeshObjectParams . SetMesh ( & SplitMeshes [ AddMeshIdx ] ) ;
ModelingTools: add support for creating Volumes directly from DrawPolygon, DrawRevolve, DrawPolyPath, and AddPrimitive, CombineMeshes, CutMeshWithMesh, PlaneCut, BaseCreateFromSelected Tools. Improve support for Editing volumes, eg handling mesh/volume interactions, and add configurable auto-simplification for volumes to avoid painful Editor hangs.
- Move ToolTarget implementations, DynamicMeshToVolume to ModelingComponentsEditorOnly module
- move VolumeToDynamicMesh, DynamicMeshProvider/Commiter interfaces to ModelingComponents module
- Add UCreateMeshObjectTypeProperties property set to expose mesh/volume options
- Add FCreateMeshObjectParams::TypeHintClass to allow AVolume type (or other UClass hints) to be passed to creation APIs
- Add UE::ToolTarget::ConfigureCreateMeshObjectParams() util function in ModelingToolTargetUtil, tries to determine output type in a FCreateMeshObjectParams based on input ToolTarget
- Add UEditorModelingObjectsCreationAPI::CreateVolume() implementation
- Add UEditorModelingObjectsCreationAPI::FilterMaterials() that strips out any internal materials and replaces with WorldGridMaterial. This occurs when (eg) subtracting a Volume from a StaticMesh, because the temporary volume mesh gets assigned internal materials, but the Tools don't know this. Use in EditorModelingObjectsCreationAPI when creating new objects. UStaticMeshComponentToolTarget also does this filtering in ::CommitMaterialSetUpdate().
- Add ::ComponentTypeSupportsCollision() function to ComponentCollisionUtil, use to avoid checks/ensures for Volume targets
- Add support for automatic mesh simplification in DynamicMeshToVolume. Add CVar to VolumeDynamicMeshToolTarget.h to control max triangle count (default 500). Apply auto-simplify when creating or updating an AVolume. This prevents the Editor from blocking for long periods on meshes that are too high-res for volumes (even 500 is quite high).
- DynamicMeshToVolume now emits polygroup-faces that contain holes (ie multiple boundary loops) as a set of triangles, rather than emitting separate overlapping faces for each boundary loop
#rb none
#rnx
#jira none
#preflight 60ba50632c42ea0001cb54c5
[CL 16561742 by Ryan Schmidt in ue5-main branch]
2021-06-04 16:04:03 -04:00
UE : : ToolTarget : : ConfigureCreateMeshObjectParams ( Targets [ OrigMeshIdx ] , NewMeshObjectParams ) ;
2021-06-02 15:58:00 -04:00
FCreateMeshObjectResult Result = UE : : Modeling : : CreateMeshObject ( GetToolManager ( ) , MoveTemp ( NewMeshObjectParams ) ) ;
if ( Result . IsOK ( ) & & Result . NewActor ! = nullptr )
2020-01-27 20:11:15 -05:00
{
2021-06-02 15:58:00 -04:00
NewSelection . Actors . Add ( Result . NewActor ) ;
2020-01-27 20:11:15 -05:00
}
2019-12-19 18:07:47 -05:00
}
2019-10-30 20:48:19 -04:00
}
2019-12-19 18:07:47 -05:00
2020-01-27 20:11:15 -05:00
if ( NewSelection . Actors . Num ( ) > 0 )
{
GetToolManager ( ) - > RequestSelectionChange ( NewSelection ) ;
}
2019-10-01 20:41:42 -04:00
}
2019-12-19 18:07:47 -05:00
2019-10-01 20:41:42 -04:00
GetToolManager ( ) - > EndUndoTransaction ( ) ;
}
# undef LOCTEXT_NAMESPACE