2019-12-27 07:44:07 -05:00
// Copyright Epic Games, Inc. All Rights Reserved.
2018-12-12 11:25:29 -05:00
# include "CollapseAllHierarchyCommand.h"
# include "IMeshEditorModeEditingContract.h"
# include "ScopedTransaction.h"
# include "Editor.h"
# include "Engine/Selection.h"
2019-10-01 20:41:42 -04:00
# include "StaticMeshAttributes.h"
2018-12-12 11:25:29 -05:00
# include "PackageTools.h"
# include "MeshFractureSettings.h"
# include "EditableMeshFactory.h"
# include "GeometryCollection/GeometryCollection.h"
# include "GeometryCollection/GeometryCollectionActor.h"
# include "GeometryCollection/GeometryCollectionComponent.h"
# include "GeometryCollection/GeometryCollectionObject.h"
# include "EditorSupportDelegates.h"
# include "GeometryCollection/GeometryCollectionConversion.h"
# include "GeometryCollection/GeometryCollectionClusteringUtility.h"
# define LOCTEXT_NAMESPACE "CollapseAllHierarchyCommand"
DEFINE_LOG_CATEGORY ( LogCollapseAllHierarchyCommand ) ;
void UCollapseAllHierarchyCommand : : RegisterUICommand ( FBindingContext * BindingContext )
{
UI_COMMAND_EXT ( BindingContext , /* Out */ UICommandInfo , " FlattenHierarchy " , " Flatten Hierarchy " , " Performs flattening of entire hierarchy at given view level. When viewing 'All Levels' it will collapse all nodes be flat under the root. " , EUserInterfaceActionType : : Button , FInputChord ( ) ) ;
}
void UCollapseAllHierarchyCommand : : Execute ( IMeshEditorModeEditingContract & MeshEditorMode )
{
if ( MeshEditorMode . GetActiveAction ( ) ! = NAME_None )
{
return ;
}
if ( MeshEditorMode . GetSelectedEditableMeshes ( ) . Num ( ) = = 0 )
{
return ;
}
FScopedTransaction Transaction ( LOCTEXT ( " Collapse All Hierarchy " , " Collapse All Hierarchy " ) ) ;
MeshEditorMode . CommitSelectedMeshes ( ) ;
TArray < UEditableMesh * > SelectedActors = MeshEditorMode . GetSelectedEditableMeshes ( ) ;
CollapseHierarchies ( MeshEditorMode , SelectedActors ) ;
2019-06-08 17:15:34 -04:00
UpdateExplodedView ( MeshEditorMode , EViewResetType : : RESET_ALL ) ;
2018-12-12 11:25:29 -05:00
}
void UCollapseAllHierarchyCommand : : CollapseHierarchies ( IMeshEditorModeEditingContract & MeshEditorMode , TArray < UEditableMesh * > & SelectedMeshes )
{
for ( UEditableMesh * EditableMesh : SelectedMeshes )
{
UGeometryCollectionComponent * GeometryCollectionComponent = GetGeometryCollectionComponent ( EditableMesh ) ;
if ( GeometryCollectionComponent ! = nullptr )
{
// scoped edit of collection
FGeometryCollectionEdit GeometryCollectionEdit = GeometryCollectionComponent - > EditRestCollection ( ) ;
if ( UGeometryCollection * GeometryCollectionObject = GeometryCollectionEdit . GetRestCollection ( ) )
{
2019-06-08 17:15:34 -04:00
TSharedPtr < FGeometryCollection , ESPMode : : ThreadSafe > GeometryCollectionPtr = GeometryCollectionObject - > GetGeometryCollection ( ) ;
2018-12-12 11:25:29 -05:00
if ( FGeometryCollection * GeometryCollection = GeometryCollectionPtr . Get ( ) )
{
AddAdditionalAttributesIfRequired ( GeometryCollectionObject ) ;
AddSingleRootNodeIfRequired ( GeometryCollectionObject ) ;
//UE_LOG(LogCollapseAllHierarchyCommand, Log, TEXT("Hierarchy Before Collapsing ..."));
//LogHierarchy(GeometryCollectionObject);
TArray < int32 > Elements ;
2019-06-08 17:15:34 -04:00
for ( int Element = 0 ; Element < GeometryCollectionObject - > NumElements ( FGeometryCollection : : TransformGroup ) ; Element + + )
2018-12-12 11:25:29 -05:00
{
2019-06-08 17:15:34 -04:00
if ( GeometryCollection - > Parent [ Element ] ! = FGeometryCollection : : Invalid )
2018-12-12 11:25:29 -05:00
{
Elements . Add ( Element ) ;
}
}
if ( Elements . Num ( ) > 0 )
{
FGeometryCollectionClusteringUtility : : ClusterBonesUnderExistingRoot ( GeometryCollection , Elements ) ;
}
FScopedColorEdit EditBoneColor = GeometryCollectionComponent - > EditBoneSelection ( ) ;
EditBoneColor . ResetBoneSelection ( ) ;
//UE_LOG(LogCollapseAllHierarchyCommand, Log, TEXT("Hierarchy After Collapsing ..."));
//LogHierarchy(GeometryCollectionObject);
GeometryCollectionComponent - > MarkRenderDynamicDataDirty ( ) ;
GeometryCollectionComponent - > MarkRenderStateDirty ( ) ;
}
}
}
}
}
# undef LOCTEXT_NAMESPACE