Files
UnrealEngineUWP/Engine/Plugins/Editor/MeshEditor/Source/PolygonModeling/CollapseSelectedHierarchyCommand.cpp
Ryan Durand 28d3d740dd (Integrating from Dev-EngineMerge to Main)
Second batch of remaining Engine copyright updates.

#rnx
#rb none
#jira none

[CL 10871196 by Ryan Durand in Main branch]
2019-12-27 07:44:07 -05:00

92 lines
3.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "CollapseSelectedHierarchyCommand.h"
#include "IMeshEditorModeEditingContract.h"
#include "ScopedTransaction.h"
#include "Editor.h"
#include "Engine/Selection.h"
#include "StaticMeshAttributes.h"
#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 "CollapseSelectedHierarchyCommand"
DEFINE_LOG_CATEGORY(LogCollapseSelectedHierarchyCommand);
void UCollapseSelectedHierarchyCommand::RegisterUICommand( FBindingContext* BindingContext )
{
UI_COMMAND_EXT( BindingContext, /* Out */ UICommandInfo, "CollapseSelectedHierarchy", "Uncluster", "Performs collpase of hierarchy at selected nodes.", EUserInterfaceActionType::Button, FInputChord() );
}
void UCollapseSelectedHierarchyCommand::Execute(IMeshEditorModeEditingContract& MeshEditorMode)
{
if (MeshEditorMode.GetActiveAction() != NAME_None)
{
return;
}
if (MeshEditorMode.GetSelectedEditableMeshes().Num() == 0)
{
return;
}
FScopedTransaction Transaction(LOCTEXT("CollapseSelectedHierarchy", "Uncluster"));
MeshEditorMode.CommitSelectedMeshes();
TArray<UEditableMesh*> SelectedActors = MeshEditorMode.GetSelectedEditableMeshes();
CollapseHierarchies(MeshEditorMode, SelectedActors);
UpdateExplodedView(MeshEditorMode, EViewResetType::RESET_ALL);
}
void UCollapseSelectedHierarchyCommand::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())
{
TSharedPtr<FGeometryCollection, ESPMode::ThreadSafe> GeometryCollectionPtr = GeometryCollectionObject->GetGeometryCollection();
if (FGeometryCollection* GeometryCollection = GeometryCollectionPtr.Get())
{
AddAdditionalAttributesIfRequired(GeometryCollectionObject);
UE_LOG(LogCollapseSelectedHierarchyCommand, Log, TEXT("Hierarchy Before Collapsing ..."));
LogHierarchy(GeometryCollectionObject);
const UMeshFractureSettings* FratureSettings = MeshEditorMode.GetFractureSettings();
int8 FractureLevel = FratureSettings->CommonSettings->GetFractureLevelNumber();
FGeometryCollectionClusteringUtility::CollapseSelectedHierarchy(FractureLevel, GeometryCollectionComponent->GetSelectedBones(), GeometryCollection);
FScopedColorEdit EditBoneColor = GeometryCollectionComponent->EditBoneSelection();
EditBoneColor.ResetBoneSelection();
UE_LOG(LogCollapseSelectedHierarchyCommand, Log, TEXT("Hierarchy After Collapsing ..."));
LogHierarchy(GeometryCollectionObject);
GeometryCollectionComponent->MarkRenderDynamicDataDirty();
GeometryCollectionComponent->MarkRenderStateDirty();
}
}
}
}
}
#undef LOCTEXT_NAMESPACE