2014-12-07 19:09:38 -05:00
// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
2014-03-14 14:13:41 -04:00
# include "LandscapeEditorPrivatePCH.h"
# include "ObjectTools.h"
# include "LandscapeEdMode.h"
# include "ScopedTransaction.h"
2014-10-16 05:16:44 -04:00
# include "Landscape.h"
# include "LandscapeEdit.h"
# include "LandscapeLayerInfoObject.h"
# include "LandscapeRender.h"
# include "LandscapeDataAccess.h"
# include "LandscapeSplineProxies.h"
2014-03-14 14:13:41 -04:00
# include "LandscapeEditorModule.h"
# include "Editor/PropertyEditor/Public/PropertyEditorModule.h"
2015-01-30 08:52:33 -05:00
# include "LandscapeEdMode.h"
2014-03-14 14:13:41 -04:00
# include "LandscapeEdModeTools.h"
2015-01-14 10:26:59 -05:00
# include "InstancedFoliageActor.h"
2014-07-17 12:15:31 -04:00
# include "ComponentReregisterContext.h"
2014-11-12 04:58:53 -05:00
# include "PhysicalMaterials/PhysicalMaterial.h"
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "Landscape"
2014-09-11 12:44:16 -04:00
class FLandscapeToolStrokeSelect : public FLandscapeToolStrokeBase
2014-03-14 14:13:41 -04:00
{
bool bInitializedComponentInvert ;
bool bComponentInvert ;
public :
FLandscapeToolStrokeSelect ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
2014-09-11 12:44:16 -04:00
: bInitializedComponentInvert ( false )
2014-07-17 12:20:34 -04:00
, LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
, Cache ( InTarget )
2014-03-14 14:13:41 -04:00
{
}
2014-09-11 12:44:16 -04:00
void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( LandscapeInfo )
2014-03-14 14:13:41 -04:00
{
LandscapeInfo - > Modify ( ) ;
// Invert when holding Shift
2014-07-17 12:20:34 -04:00
bool bInvert = MousePositions [ MousePositions . Num ( ) - 1 ] . bShiftDown ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
if ( Brush - > GetBrushType ( ) = = ELandscapeBrushType : : Component )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
// TODO - only retrieve bounds as we don't need the data
const FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
{
return ;
}
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
// Shrink bounds by 1,1 to avoid GetComponentsInRegion picking up extra components on all sides due to the overlap between components
2014-03-14 14:13:41 -04:00
TSet < ULandscapeComponent * > NewComponents ;
2014-07-17 12:20:34 -04:00
LandscapeInfo - > GetComponentsInRegion ( X1 + 1 , Y1 + 1 , X2 - 1 , Y2 - 1 , NewComponents ) ;
2014-03-14 14:13:41 -04:00
if ( ! bInitializedComponentInvert )
{
// Get the component under the mouse location. Copied from FLandscapeBrushComponent::ApplyBrush()
2014-12-18 06:52:06 -05:00
const float MouseX = MousePositions [ 0 ] . Position . X ;
const float MouseY = MousePositions [ 0 ] . Position . Y ;
const int32 MouseComponentIndexX = ( MouseX > = 0.0f ) ? FMath : : FloorToInt ( MouseX / LandscapeInfo - > ComponentSizeQuads ) : FMath : : CeilToInt ( MouseX / LandscapeInfo - > ComponentSizeQuads ) ;
const int32 MouseComponentIndexY = ( MouseY > = 0.0f ) ? FMath : : FloorToInt ( MouseY / LandscapeInfo - > ComponentSizeQuads ) : FMath : : CeilToInt ( MouseY / LandscapeInfo - > ComponentSizeQuads ) ;
2014-03-14 14:13:41 -04:00
ULandscapeComponent * MouseComponent = LandscapeInfo - > XYtoComponentMap . FindRef ( FIntPoint ( MouseComponentIndexX , MouseComponentIndexY ) ) ;
2014-12-18 06:52:06 -05:00
if ( MouseComponent ! = nullptr )
2014-03-14 14:13:41 -04:00
{
bComponentInvert = LandscapeInfo - > GetSelectedComponents ( ) . Contains ( MouseComponent ) ;
}
else
{
bComponentInvert = false ;
}
bInitializedComponentInvert = true ;
}
bInvert = bComponentInvert ;
TSet < ULandscapeComponent * > NewSelection ;
if ( bInvert )
{
NewSelection = LandscapeInfo - > GetSelectedComponents ( ) . Difference ( NewComponents ) ;
}
else
{
NewSelection = LandscapeInfo - > GetSelectedComponents ( ) . Union ( NewComponents ) ;
}
LandscapeInfo - > Modify ( ) ;
LandscapeInfo - > UpdateSelectedComponents ( NewSelection ) ;
// Update Details tab with selection
TArray < UObject * > Objects ;
Objects . Reset ( NewSelection . Num ( ) ) ;
for ( auto It = NewSelection . CreateConstIterator ( ) ; It ; + + It )
{
Objects . Add ( * It ) ;
}
2014-07-17 12:20:34 -04:00
FPropertyEditorModule & PropertyModule = FModuleManager : : Get ( ) . LoadModuleChecked < FPropertyEditorModule > ( TEXT ( " PropertyEditor " ) ) ;
2014-03-14 14:13:41 -04:00
PropertyModule . UpdatePropertyViews ( Objects ) ;
}
else // Select various shape regions
{
2014-12-18 06:52:06 -05:00
const FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
{
return ;
}
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
2014-03-14 14:13:41 -04:00
// Tablet pressure
2014-12-18 06:52:06 -05:00
float Pressure = ViewportClient - > Viewport - > IsPenActive ( ) ? ViewportClient - > Viewport - > GetTabletPressure ( ) : 1.0f ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
Cache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
2014-03-14 14:13:41 -04:00
TArray < uint8 > Data ;
2014-07-17 12:20:34 -04:00
Cache . GetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
TSet < ULandscapeComponent * > NewComponents ;
2014-07-17 12:20:34 -04:00
LandscapeInfo - > GetComponentsInRegion ( X1 , Y1 , X2 , Y2 , NewComponents ) ;
2014-03-14 14:13:41 -04:00
LandscapeInfo - > UpdateSelectedComponents ( NewComponents , false ) ;
2014-12-18 06:52:06 -05:00
for ( int32 Y = BrushInfo . GetBounds ( ) . Min . Y ; Y < BrushInfo . GetBounds ( ) . Max . Y ; Y + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
const float * BrushScanline = BrushInfo . GetDataPtr ( FIntPoint ( 0 , Y ) ) ;
uint8 * DataScanline = Data . GetData ( ) + ( Y - Y1 ) * ( X2 - X1 + 1 ) + ( 0 - X1 ) ;
for ( int32 X = BrushInfo . GetBounds ( ) . Min . X ; X < BrushInfo . GetBounds ( ) . Max . X ; X + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
const FIntPoint Key = ALandscape : : MakeKey ( X , Y ) ;
const float BrushValue = BrushScanline [ X ] ;
if ( BrushValue > 0.0f & & LandscapeInfo - > IsValidPosition ( X , Y ) )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
float PaintValue = BrushValue * UISettings - > ToolStrength * Pressure ;
2015-01-16 04:47:23 -05:00
float Value = DataScanline [ X ] / 255.0f ;
checkSlow ( FMath : : IsNearlyEqual ( Value , LandscapeInfo - > SelectedRegion . FindRef ( Key ) , 1 / 255.0f ) ) ;
2014-12-18 06:52:06 -05:00
if ( bInvert )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Value = FMath : : Max ( Value - PaintValue , 0.0f ) ;
}
else
{
Value = FMath : : Min ( Value + PaintValue , 1.0f ) ;
}
if ( Value > 0.0f )
{
LandscapeInfo - > SelectedRegion . Add ( Key , Value ) ;
2014-03-14 14:13:41 -04:00
}
else
{
LandscapeInfo - > SelectedRegion . Remove ( Key ) ;
}
2014-12-18 06:52:06 -05:00
DataScanline [ X ] = FMath : : Clamp < int32 > ( FMath : : RoundToInt ( Value * 255 ) , 0 , 255 ) ;
2014-03-14 14:13:41 -04:00
}
}
}
2014-07-17 12:20:34 -04:00
Cache . SetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
Cache . Flush ( ) ;
}
}
}
protected :
2014-07-17 12:20:34 -04:00
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
FLandscapeDataCache Cache ;
} ;
//
// FLandscapeToolSelect
//
template < class TStrokeClass >
class FLandscapeToolSelect : public FLandscapeToolBase < TStrokeClass >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolSelect ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolBase < TStrokeClass > ( InEdMode )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " Select " ) ; }
2014-06-13 06:14:46 -04:00
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_Selection " , " Component Selection " ) ; } ;
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : SelectComponent | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
virtual ELandscapeToolType GetToolType ( ) override { return ELandscapeToolType : : Mask ; }
2014-03-14 14:13:41 -04:00
} ;
template < class TStrokeClass >
class FLandscapeToolMask : public FLandscapeToolSelect < TStrokeClass >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolMask ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolSelect < TStrokeClass > ( InEdMode )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " Mask " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_Mask " , " Region Selection " ) ; } ;
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : SelectRegion | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return true ; }
2014-03-14 14:13:41 -04:00
} ;
2014-09-11 12:44:16 -04:00
class FLandscapeToolStrokeVisibility : public FLandscapeToolStrokeBase
2014-03-14 14:13:41 -04:00
{
public :
2014-09-11 12:44:16 -04:00
enum { UseContinuousApply = false } ;
2014-03-14 14:13:41 -04:00
FLandscapeToolStrokeVisibility ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
2014-07-17 12:20:34 -04:00
: LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
, Cache ( InTarget )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-09-11 12:44:16 -04:00
void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( LandscapeInfo )
2014-03-14 14:13:41 -04:00
{
LandscapeInfo - > Modify ( ) ;
// Get list of verts to update
2014-12-18 06:52:06 -05:00
FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
2014-03-14 14:13:41 -04:00
{
return ;
}
2014-12-18 06:52:06 -05:00
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
2014-03-14 14:13:41 -04:00
// Invert when holding Shift
2014-07-17 12:20:34 -04:00
bool bInvert = MousePositions [ MousePositions . Num ( ) - 1 ] . bShiftDown ;
2014-03-14 14:13:41 -04:00
// Tablet pressure
2014-12-18 06:52:06 -05:00
float Pressure = ViewportClient - > Viewport - > IsPenActive ( ) ? ViewportClient - > Viewport - > GetTabletPressure ( ) : 1.0f ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
Cache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
2014-03-14 14:13:41 -04:00
TArray < uint8 > Data ;
2014-07-17 12:20:34 -04:00
Cache . GetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
for ( int32 Y = BrushInfo . GetBounds ( ) . Min . Y ; Y < BrushInfo . GetBounds ( ) . Max . Y ; Y + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
const float * BrushScanline = BrushInfo . GetDataPtr ( FIntPoint ( 0 , Y ) ) ;
uint8 * DataScanline = Data . GetData ( ) + ( Y - Y1 ) * ( X2 - X1 + 1 ) + ( 0 - X1 ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
for ( int32 X = BrushInfo . GetBounds ( ) . Min . X ; X < BrushInfo . GetBounds ( ) . Max . X ; X + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
const float BrushValue = BrushScanline [ X ] ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
if ( BrushValue > 0.0f )
{
uint8 Value = bInvert ? 0 : 255 ; // Just on and off for visibility, for masking...
DataScanline [ X ] = Value ;
}
2014-03-14 14:13:41 -04:00
}
}
2014-07-17 12:20:34 -04:00
Cache . SetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
Cache . Flush ( ) ;
}
}
protected :
2014-07-17 12:20:34 -04:00
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
FLandscapeVisCache Cache ;
} ;
//
// FLandscapeToolVisibility
//
class FLandscapeToolVisibility : public FLandscapeToolBase < FLandscapeToolStrokeVisibility >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolVisibility ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolBase < FLandscapeToolStrokeVisibility > ( InEdMode )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " Visibility " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_Visibility " , " Visibility " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : None | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
virtual ELandscapeToolTargetTypeMask : : Type GetSupportedTargetTypes ( ) override
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
return ELandscapeToolTargetTypeMask : : Visibility ;
2014-03-14 14:13:41 -04:00
}
} ;
class FLandscapeToolStrokeMoveToLevel
{
public :
2014-09-11 12:44:16 -04:00
enum { UseContinuousApply = false } ;
2014-03-14 14:13:41 -04:00
FLandscapeToolStrokeMoveToLevel ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
: LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-09-11 12:44:16 -04:00
void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
ALandscape * Landscape = LandscapeInfo ? LandscapeInfo - > LandscapeActor . Get ( ) : nullptr ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
if ( Landscape )
2014-03-14 14:13:41 -04:00
{
Landscape - > Modify ( ) ;
LandscapeInfo - > Modify ( ) ;
TArray < UObject * > RenameObjects ;
FString MsgBoxList ;
// Check the Physical Material is same package with Landscape
if ( Landscape - > DefaultPhysMaterial & & Landscape - > DefaultPhysMaterial - > GetOutermost ( ) = = Landscape - > GetOutermost ( ) )
{
//FMessageDialog::Open( EAppMsgType::Ok, NSLOCTEXT("UnrealEd", "LandscapePhyMaterial_Warning", "Landscape's DefaultPhysMaterial is in the same package as the Landscape Actor. To support streaming levels, you must move the PhysicalMaterial to another package.") );
RenameObjects . AddUnique ( Landscape - > DefaultPhysMaterial ) ;
MsgBoxList + = Landscape - > DefaultPhysMaterial - > GetPathName ( ) ;
MsgBoxList + = FString : : Printf ( TEXT ( " \n " ) ) ;
}
// Check the LayerInfoObjects are same package with Landscape
for ( int i = 0 ; i < LandscapeInfo - > Layers . Num ( ) ; + + i )
{
ULandscapeLayerInfoObject * LayerInfo = LandscapeInfo - > Layers [ i ] . LayerInfoObj ;
if ( LayerInfo & & LayerInfo - > GetOutermost ( ) = = Landscape - > GetOutermost ( ) )
{
RenameObjects . AddUnique ( LayerInfo ) ;
MsgBoxList + = LayerInfo - > GetPathName ( ) ;
MsgBoxList + = FString : : Printf ( TEXT ( " \n " ) ) ;
}
}
auto SelectedComponents = LandscapeInfo - > GetSelectedComponents ( ) ;
bool bBrush = false ;
if ( ! SelectedComponents . Num ( ) )
{
// Get list of verts to update
2014-12-18 06:52:06 -05:00
// TODO - only retrieve bounds as we don't need the data
FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
2014-03-14 14:13:41 -04:00
{
return ;
}
2014-12-18 06:52:06 -05:00
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
// Shrink bounds by 1,1 to avoid GetComponentsInRegion picking up extra components on all sides due to the overlap between components
2014-04-23 16:38:50 -04:00
LandscapeInfo - > GetComponentsInRegion ( X1 + 1 , Y1 + 1 , X2 - 1 , Y2 - 1 , SelectedComponents ) ;
2014-03-14 14:13:41 -04:00
bBrush = true ;
}
check ( ViewportClient - > GetScene ( ) ) ;
UWorld * World = ViewportClient - > GetScene ( ) - > GetWorld ( ) ;
check ( World ) ;
if ( SelectedComponents . Num ( ) )
{
bool bIsAllCurrentLevel = true ;
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : SelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
if ( Component - > GetLandscapeProxy ( ) - > GetLevel ( ) ! = World - > GetCurrentLevel ( ) )
2014-03-14 14:13:41 -04:00
{
bIsAllCurrentLevel = false ;
}
}
if ( bIsAllCurrentLevel )
{
// Need to fix double WM
if ( ! bBrush )
{
// Remove Selection
LandscapeInfo - > ClearSelectedRegion ( true ) ;
}
return ;
}
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : SelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
UMaterialInterface * LandscapeMaterial = Component - > GetLandscapeMaterial ( ) ;
if ( LandscapeMaterial & & LandscapeMaterial - > GetOutermost ( ) = = Component - > GetOutermost ( ) )
2014-03-14 14:13:41 -04:00
{
RenameObjects . AddUnique ( LandscapeMaterial ) ;
2014-12-18 06:52:06 -05:00
MsgBoxList + = Component - > GetName ( ) + TEXT ( " 's " ) + LandscapeMaterial - > GetPathName ( ) ;
2014-03-14 14:13:41 -04:00
MsgBoxList + = FString : : Printf ( TEXT ( " \n " ) ) ;
//It.RemoveCurrent();
}
}
if ( RenameObjects . Num ( ) )
{
2014-07-17 12:20:34 -04:00
if ( FMessageDialog : : Open ( EAppMsgType : : OkCancel ,
2014-03-14 14:13:41 -04:00
FText : : Format (
2014-07-17 12:20:34 -04:00
NSLOCTEXT ( " UnrealEd " , " LandscapeMoveToStreamingLevel_SharedResources " , " The following items must be moved out of the persistent level and into a package that can be shared between multiple levels: \n \n {0} " ) ,
FText : : FromString ( MsgBoxList ) ) ) )
2014-03-14 14:13:41 -04:00
{
FString Path = Landscape - > GetOutermost ( ) - > GetName ( ) + TEXT ( " _sharedassets/ " ) ;
bool bSucceed = ObjectTools : : RenameObjects ( RenameObjects , false , TEXT ( " " ) , Path ) ;
if ( ! bSucceed )
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok , NSLOCTEXT ( " UnrealEd " , " LandscapeMoveToStreamingLevel_RenameFailed " , " Move To Streaming Level did not succeed because shared resources could not be moved to a new package. " ) ) ;
2014-03-14 14:13:41 -04:00
return ;
}
}
else
{
return ;
}
}
2014-07-17 12:20:34 -04:00
GWarn - > BeginSlowTask ( LOCTEXT ( " BeginMovingLandscapeComponentsToCurrentLevelTask " , " Moving Landscape components to current level " ) , true ) ;
2014-03-14 14:13:41 -04:00
TSet < ALandscapeProxy * > SelectProxies ;
TSet < UTexture2D * > OldTextureSet ;
TSet < ULandscapeComponent * > TargetSelectedComponents ;
TArray < ULandscapeHeightfieldCollisionComponent * > TargetSelectedCollisionComponents ;
TSet < ULandscapeComponent * > HeightmapUpdateComponents ;
int32 Progress = 0 ;
LandscapeInfo - > SortSelectedComponents ( ) ;
2014-07-17 12:20:34 -04:00
int32 ComponentSizeVerts = Landscape - > NumSubsections * ( Landscape - > SubsectionSizeQuads + 1 ) ;
int32 NeedHeightmapSize = 1 < < FMath : : CeilLogTwo ( ComponentSizeVerts ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : SelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
SelectProxies . Add ( Component - > GetLandscapeProxy ( ) ) ;
if ( Component - > GetLandscapeProxy ( ) - > GetOuter ( ) ! = World - > GetCurrentLevel ( ) )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
TargetSelectedComponents . Add ( Component ) ;
2014-03-14 14:13:41 -04:00
}
2014-12-18 06:52:06 -05:00
ULandscapeHeightfieldCollisionComponent * CollisionComp = Component - > CollisionComponent . Get ( ) ;
2014-03-14 14:13:41 -04:00
SelectProxies . Add ( CollisionComp - > GetLandscapeProxy ( ) ) ;
if ( CollisionComp - > GetLandscapeProxy ( ) - > GetOuter ( ) ! = World - > GetCurrentLevel ( ) )
{
TargetSelectedCollisionComponents . Add ( CollisionComp ) ;
}
}
int32 TotalProgress = TargetSelectedComponents . Num ( ) * TargetSelectedCollisionComponents . Num ( ) ;
// Check which ones are need for height map change
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : TargetSelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Component - > Modify ( ) ;
OldTextureSet . Add ( Component - > HeightmapTexture ) ;
2014-03-14 14:13:41 -04:00
}
// Need to split all the component which share Heightmap with selected components
// Search neighbor only
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : TargetSelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
int32 SearchX = Component - > HeightmapTexture - > Source . GetSizeX ( ) / NeedHeightmapSize ;
int32 SearchY = Component - > HeightmapTexture - > Source . GetSizeY ( ) / NeedHeightmapSize ;
FIntPoint ComponentBase = Component - > GetSectionBase ( ) / Component - > ComponentSizeQuads ;
2014-03-14 14:13:41 -04:00
for ( int32 Y = 0 ; Y < SearchY ; + + Y )
{
for ( int32 X = 0 ; X < SearchX ; + + X )
{
// Search for four directions...
for ( int32 Dir = 0 ; Dir < 4 ; + + Dir )
{
2014-07-17 12:20:34 -04:00
int32 XDir = ( Dir > > 1 ) ? 1 : - 1 ;
int32 YDir = ( Dir % 2 ) ? 1 : - 1 ;
2014-03-14 14:13:41 -04:00
ULandscapeComponent * Neighbor = LandscapeInfo - > XYtoComponentMap . FindRef ( ComponentBase + FIntPoint ( XDir * X , YDir * Y ) ) ;
2014-12-18 06:52:06 -05:00
if ( Neighbor & & Neighbor - > HeightmapTexture = = Component - > HeightmapTexture & & ! HeightmapUpdateComponents . Contains ( Neighbor ) )
2014-03-14 14:13:41 -04:00
{
Neighbor - > Modify ( ) ;
if ( ! TargetSelectedComponents . Contains ( Neighbor ) )
{
2014-12-18 06:52:06 -05:00
Neighbor - > HeightmapScaleBias . X = - 1.0f ; // just mark this component is for original level, not current level
2014-03-14 14:13:41 -04:00
}
HeightmapUpdateComponents . Add ( Neighbor ) ;
}
}
}
}
}
// Changing Heightmap format for selected components
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : HeightmapUpdateComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
ALandscape : : SplitHeightmap ( Component , ( Component - > HeightmapScaleBias . X > 0.0f ) ) ;
2014-03-14 14:13:41 -04:00
}
// Delete if it is no referenced textures...
2014-12-18 06:52:06 -05:00
for ( UTexture2D * Texture : OldTextureSet )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Texture - > SetFlags ( RF_Transactional ) ;
Texture - > Modify ( ) ;
Texture - > MarkPackageDirty ( ) ;
Texture - > ClearFlags ( RF_Standalone ) ;
2014-03-14 14:13:41 -04:00
}
ALandscapeProxy * LandscapeProxy = LandscapeInfo - > GetCurrentLevelLandscapeProxy ( false ) ;
if ( ! LandscapeProxy )
{
LandscapeProxy = World - > SpawnActor < ALandscapeProxy > ( ) ;
// copy shared properties to this new proxy
LandscapeProxy - > GetSharedProperties ( Landscape ) ;
2014-07-17 12:20:34 -04:00
2014-03-14 14:13:41 -04:00
// set proxy location
// by default first component location
ULandscapeComponent * FirstComponent = * TargetSelectedComponents . CreateConstIterator ( ) ;
LandscapeProxy - > GetRootComponent ( ) - > SetWorldLocationAndRotation ( FirstComponent - > GetComponentLocation ( ) , FirstComponent - > GetComponentRotation ( ) ) ;
LandscapeProxy - > LandscapeSectionOffset = FirstComponent - > GetSectionBase ( ) ;
// Hide(unregister) the new landscape if owning level currently in hidden state
if ( LandscapeProxy - > GetLevel ( ) - > bIsVisible = = false )
{
LandscapeProxy - > UnregisterAllComponents ( ) ;
}
}
2014-12-18 06:52:06 -05:00
for ( ALandscapeProxy * Proxy : SelectProxies )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Proxy - > Modify ( ) ;
2014-03-14 14:13:41 -04:00
}
LandscapeProxy - > Modify ( ) ;
LandscapeProxy - > MarkPackageDirty ( ) ;
// Change Weight maps...
{
FLandscapeEditDataInterface LandscapeEdit ( LandscapeInfo ) ;
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : TargetSelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
int32 TotalNeededChannels = Component - > WeightmapLayerAllocations . Num ( ) ;
2014-03-14 14:13:41 -04:00
int32 CurrentLayer = 0 ;
TArray < UTexture2D * > NewWeightmapTextures ;
// Code from ULandscapeComponent::ReallocateWeightmaps
// Move to other channels left
2014-07-17 12:20:34 -04:00
while ( TotalNeededChannels > 0 )
2014-03-14 14:13:41 -04:00
{
// UE_LOG(LogLandscape, Log, TEXT("Still need %d channels"), TotalNeededChannels);
2014-12-18 06:52:06 -05:00
UTexture2D * CurrentWeightmapTexture = nullptr ;
FLandscapeWeightmapUsage * CurrentWeightmapUsage = nullptr ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
if ( TotalNeededChannels < 4 )
2014-03-14 14:13:41 -04:00
{
// UE_LOG(LogLandscape, Log, TEXT("Looking for nearest"));
// see if we can find a suitable existing weightmap texture with sufficient channels
int32 BestDistanceSquared = MAX_int32 ;
2014-12-18 06:52:06 -05:00
for ( auto & WeightmapUsagePair : LandscapeProxy - > WeightmapUsageMap )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
FLandscapeWeightmapUsage * TryWeightmapUsage = & WeightmapUsagePair . Value ;
2014-07-17 12:20:34 -04:00
if ( TryWeightmapUsage - > FreeChannelCount ( ) > = TotalNeededChannels )
2014-03-14 14:13:41 -04:00
{
// See if this candidate is closer than any others we've found
2014-07-17 12:20:34 -04:00
for ( int32 ChanIdx = 0 ; ChanIdx < 4 ; ChanIdx + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
if ( TryWeightmapUsage - > ChannelUsage [ ChanIdx ] ! = nullptr )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
int32 TryDistanceSquared = ( TryWeightmapUsage - > ChannelUsage [ ChanIdx ] - > GetSectionBase ( ) - Component - > GetSectionBase ( ) ) . SizeSquared ( ) ;
2014-07-17 12:20:34 -04:00
if ( TryDistanceSquared < BestDistanceSquared )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
CurrentWeightmapTexture = WeightmapUsagePair . Key ;
2014-03-14 14:13:41 -04:00
CurrentWeightmapUsage = TryWeightmapUsage ;
BestDistanceSquared = TryDistanceSquared ;
}
}
}
}
}
}
2014-07-17 12:20:34 -04:00
bool NeedsUpdateResource = false ;
2014-03-14 14:13:41 -04:00
// No suitable weightmap texture
2014-12-18 06:52:06 -05:00
if ( CurrentWeightmapTexture = = nullptr )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Component - > MarkPackageDirty ( ) ;
2014-03-14 14:13:41 -04:00
// Weightmap is sized the same as the component
2014-12-18 06:52:06 -05:00
int32 WeightmapSize = ( Component - > SubsectionSizeQuads + 1 ) * Component - > NumSubsections ;
2014-03-14 14:13:41 -04:00
// We need a new weightmap texture
2014-08-12 08:03:05 -04:00
CurrentWeightmapTexture = LandscapeProxy - > CreateLandscapeTexture ( WeightmapSize , WeightmapSize , TEXTUREGROUP_Terrain_Weightmap , TSF_BGRA8 ) ;
2014-03-14 14:13:41 -04:00
// Alloc dummy mips
2014-12-18 06:52:06 -05:00
Component - > CreateEmptyTextureMips ( CurrentWeightmapTexture ) ;
2014-03-14 14:13:41 -04:00
CurrentWeightmapTexture - > PostEditChange ( ) ;
// Store it in the usage map
CurrentWeightmapUsage = & LandscapeProxy - > WeightmapUsageMap . Add ( CurrentWeightmapTexture , FLandscapeWeightmapUsage ( ) ) ;
// UE_LOG(LogLandscape, Log, TEXT("Making a new texture %s"), *CurrentWeightmapTexture->GetName());
}
NewWeightmapTextures . Add ( CurrentWeightmapTexture ) ;
2014-07-17 12:20:34 -04:00
for ( int32 ChanIdx = 0 ; ChanIdx < 4 & & TotalNeededChannels > 0 ; ChanIdx + + )
2014-03-14 14:13:41 -04:00
{
// UE_LOG(LogLandscape, Log, TEXT("Finding allocation for layer %d"), CurrentLayer);
2014-12-18 06:52:06 -05:00
if ( CurrentWeightmapUsage - > ChannelUsage [ ChanIdx ] = = nullptr )
2014-03-14 14:13:41 -04:00
{
// Use this allocation
2014-12-18 06:52:06 -05:00
FWeightmapLayerAllocationInfo & AllocInfo = Component - > WeightmapLayerAllocations [ CurrentLayer ] ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
if ( AllocInfo . WeightmapTextureIndex = = 255 )
2014-03-14 14:13:41 -04:00
{
// New layer - zero out the data for this texture channel
2014-07-17 12:20:34 -04:00
LandscapeEdit . ZeroTextureChannel ( CurrentWeightmapTexture , ChanIdx ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-12-18 06:52:06 -05:00
UTexture2D * OldWeightmapTexture = Component - > WeightmapTextures [ AllocInfo . WeightmapTextureIndex ] ;
2014-03-14 14:13:41 -04:00
// Copy the data
2014-07-17 12:20:34 -04:00
LandscapeEdit . CopyTextureChannel ( CurrentWeightmapTexture , ChanIdx , OldWeightmapTexture , AllocInfo . WeightmapTextureChannel ) ;
LandscapeEdit . ZeroTextureChannel ( OldWeightmapTexture , AllocInfo . WeightmapTextureChannel ) ;
2014-03-14 14:13:41 -04:00
// Remove the old allocation
2014-12-18 06:52:06 -05:00
FLandscapeWeightmapUsage * OldWeightmapUsage = Component - > GetLandscapeProxy ( ) - > WeightmapUsageMap . Find ( OldWeightmapTexture ) ;
OldWeightmapUsage - > ChannelUsage [ AllocInfo . WeightmapTextureChannel ] = nullptr ;
2014-03-14 14:13:41 -04:00
}
// Assign the new allocation
2014-12-18 06:52:06 -05:00
CurrentWeightmapUsage - > ChannelUsage [ ChanIdx ] = Component ;
2014-07-17 12:20:34 -04:00
AllocInfo . WeightmapTextureIndex = NewWeightmapTextures . Num ( ) - 1 ;
2014-03-14 14:13:41 -04:00
AllocInfo . WeightmapTextureChannel = ChanIdx ;
CurrentLayer + + ;
TotalNeededChannels - - ;
}
}
}
// Replace the weightmap textures
2014-12-18 06:52:06 -05:00
Component - > WeightmapTextures = NewWeightmapTextures ;
2014-03-14 14:13:41 -04:00
// Update the mipmaps for the textures we edited
2014-12-18 06:52:06 -05:00
for ( UTexture2D * WeightmapTexture : Component - > WeightmapTextures )
2014-03-14 14:13:41 -04:00
{
FLandscapeTextureDataInfo * WeightmapDataInfo = LandscapeEdit . GetTextureDataInfo ( WeightmapTexture ) ;
int32 NumMips = WeightmapTexture - > Source . GetNumMips ( ) ;
TArray < FColor * > WeightmapTextureMipData ;
WeightmapTextureMipData . AddUninitialized ( NumMips ) ;
2014-07-17 12:20:34 -04:00
for ( int32 MipIdx = 0 ; MipIdx < NumMips ; MipIdx + + )
2014-03-14 14:13:41 -04:00
{
WeightmapTextureMipData [ MipIdx ] = ( FColor * ) WeightmapDataInfo - > GetMipData ( MipIdx ) ;
}
2014-12-18 06:52:06 -05:00
ULandscapeComponent : : UpdateWeightmapMips ( Component - > NumSubsections , Component - > SubsectionSizeQuads , WeightmapTexture , WeightmapTextureMipData , 0 , 0 , MAX_int32 , MAX_int32 , WeightmapDataInfo ) ;
2014-03-14 14:13:41 -04:00
}
}
// Need to Repacking all the Weight map (to make it packed well...)
Landscape - > RemoveInvalidWeightmaps ( ) ;
}
// Move the components to the Proxy actor
// This does not use the MoveSelectedActorsToCurrentLevel path as there is no support to only move certain components.
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : TargetSelectedComponents )
2014-03-14 14:13:41 -04:00
{
// Need to move or recreate all related data (Height map, Weight map, maybe collision components, allocation info)
2014-12-18 06:52:06 -05:00
Component - > GetLandscapeProxy ( ) - > LandscapeComponents . Remove ( Component ) ;
Component - > UnregisterComponent ( ) ;
Component - > DetachFromParent ( true ) ;
Component - > InvalidateLightingCache ( ) ;
Component - > Rename ( nullptr , LandscapeProxy ) ;
LandscapeProxy - > LandscapeComponents . Add ( Component ) ;
Component - > AttachTo ( LandscapeProxy - > GetRootComponent ( ) , NAME_None , EAttachLocation : : KeepWorldPosition ) ;
Component - > UpdateMaterialInstances ( ) ;
2014-03-14 14:13:41 -04:00
FFormatNamedArguments Args ;
2014-12-18 06:52:06 -05:00
Args . Add ( TEXT ( " ComponentName " ) , FText : : FromString ( Component - > GetName ( ) ) ) ;
2014-07-17 12:20:34 -04:00
GWarn - > StatusUpdate ( Progress + + , TotalProgress , FText : : Format ( LOCTEXT ( " MovingComponentStatus " , " Moving Component: {ComponentName} " ) , Args ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-12-18 06:52:06 -05:00
for ( ULandscapeHeightfieldCollisionComponent * Component : TargetSelectedCollisionComponents )
2014-03-14 14:13:41 -04:00
{
// Need to move or recreate all related data (Height map, Weight map, maybe collision components, allocation info)
// Move any foliage associated
2015-03-05 03:28:09 -05:00
AInstancedFoliageActor : : MoveInstancesForComponentToCurrentLevel ( Component ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
Component - > GetLandscapeProxy ( ) - > CollisionComponents . Remove ( Component ) ;
Component - > UnregisterComponent ( ) ;
Component - > DetachFromParent ( true ) ;
Component - > Rename ( nullptr , LandscapeProxy ) ;
LandscapeProxy - > CollisionComponents . Add ( Component ) ;
Component - > AttachTo ( LandscapeProxy - > GetRootComponent ( ) , NAME_None , EAttachLocation : : KeepWorldPosition ) ;
2014-03-14 14:13:41 -04:00
FFormatNamedArguments Args ;
2014-12-18 06:52:06 -05:00
Args . Add ( TEXT ( " ComponentName " ) , FText : : FromString ( Component - > GetName ( ) ) ) ;
2014-07-17 12:20:34 -04:00
GWarn - > StatusUpdate ( Progress + + , TotalProgress , FText : : Format ( LOCTEXT ( " MovingComponentStatus " , " Moving Component: {ComponentName} " ) , Args ) ) ;
2014-03-14 14:13:41 -04:00
}
GEditor - > SelectNone ( false , true ) ;
2014-07-17 12:20:34 -04:00
GEditor - > SelectActor ( LandscapeProxy , true , false , true ) ;
2014-03-14 14:13:41 -04:00
GEditor - > SelectNone ( false , true ) ;
// Register our new components if destination landscape is registered in scene
if ( LandscapeProxy - > GetRootComponent ( ) - > IsRegistered ( ) )
{
LandscapeProxy - > RegisterAllComponents ( ) ;
}
2014-12-18 06:52:06 -05:00
for ( ALandscapeProxy * Proxy : SelectProxies )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
if ( Proxy - > GetRootComponent ( ) - > IsRegistered ( ) )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Proxy - > RegisterAllComponents ( ) ;
2014-03-14 14:13:41 -04:00
}
}
//Landscape->bLockLocation = (LandscapeInfo->XYtoComponentMap.Num() != Landscape->LandscapeComponents.Num());
GWarn - > EndSlowTask ( ) ;
// Remove Selection
LandscapeInfo - > ClearSelectedRegion ( true ) ;
//EdMode->SetMaskEnable(Landscape->SelectedRegion.Num());
}
}
}
protected :
2014-07-17 12:20:34 -04:00
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
} ;
//
// FLandscapeToolMoveToLevel
//
class FLandscapeToolMoveToLevel : public FLandscapeToolBase < FLandscapeToolStrokeMoveToLevel >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolMoveToLevel ( FEdModeLandscape * InEdMode )
: FLandscapeToolBase < FLandscapeToolStrokeMoveToLevel > ( InEdMode )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " MoveToLevel " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_MoveToLevel " , " Move to Streaming Level " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : SelectComponent | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
} ;
2014-09-11 12:44:16 -04:00
class FLandscapeToolStrokeAddComponent : public FLandscapeToolStrokeBase
2014-03-14 14:13:41 -04:00
{
public :
FLandscapeToolStrokeAddComponent ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
2014-12-18 06:52:06 -05:00
: EdMode ( InEdMode )
, LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
, HeightCache ( InTarget )
, XYOffsetCache ( InTarget )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-08-06 11:26:29 -04:00
virtual ~ FLandscapeToolStrokeAddComponent ( )
{
// We flush here so here ~FXYOffsetmapAccessor can safely lock the heightmap data to update bounds
HeightCache . Flush ( ) ;
XYOffsetCache . Flush ( ) ;
}
2014-07-31 15:43:08 -04:00
2014-06-18 10:16:16 -04:00
virtual void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
ALandscapeProxy * Landscape = LandscapeInfo ? LandscapeInfo - > GetCurrentLevelLandscapeProxy ( true ) : nullptr ;
2014-07-17 12:20:34 -04:00
if ( Landscape & & EdMode - > LandscapeRenderAddCollision )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
check ( Brush - > GetBrushType ( ) = = ELandscapeBrushType : : Component ) ;
2014-03-14 14:13:41 -04:00
// Get list of verts to update
2014-12-18 06:52:06 -05:00
// TODO - only retrieve bounds as we don't need the data
FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
2014-03-14 14:13:41 -04:00
{
return ;
}
2014-12-18 06:52:06 -05:00
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
// Find component range for this block of data, non shared vertices
int32 ComponentIndexX1 , ComponentIndexY1 , ComponentIndexX2 , ComponentIndexY2 ;
ALandscape : : CalcComponentIndicesNoOverlap ( X1 , Y1 , X2 , Y2 , Landscape - > ComponentSizeQuads , ComponentIndexX1 , ComponentIndexY1 , ComponentIndexX2 , ComponentIndexY2 ) ;
// expand the area by one vertex in each direction to ensure normals are calculated correctly
2014-03-14 14:13:41 -04:00
X1 - = 1 ;
Y1 - = 1 ;
X2 + = 1 ;
Y2 + = 1 ;
TArray < uint16 > Data ;
2014-07-23 08:24:09 -04:00
TArray < FVector > XYOffsetData ;
2014-12-18 06:52:06 -05:00
HeightCache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
XYOffsetCache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
HeightCache . GetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-07-23 08:24:09 -04:00
bool bHasXYOffset = XYOffsetCache . GetCachedData ( X1 , Y1 , X2 , Y2 , XYOffsetData ) ;
2014-03-14 14:13:41 -04:00
TArray < ULandscapeComponent * > NewComponents ;
Landscape - > Modify ( ) ;
LandscapeInfo - > Modify ( ) ;
2014-07-17 12:20:34 -04:00
for ( int32 ComponentIndexY = ComponentIndexY1 ; ComponentIndexY < = ComponentIndexY2 ; ComponentIndexY + + )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
for ( int32 ComponentIndexX = ComponentIndexX1 ; ComponentIndexX < = ComponentIndexX2 ; ComponentIndexX + + )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
ULandscapeComponent * Component = LandscapeInfo - > XYtoComponentMap . FindRef ( FIntPoint ( ComponentIndexX , ComponentIndexY ) ) ;
if ( ! Component )
2014-03-14 14:13:41 -04:00
{
// Add New component...
FIntPoint ComponentBase = FIntPoint ( ComponentIndexX , ComponentIndexY ) * Landscape - > ComponentSizeQuads ;
2015-02-03 05:40:57 -05:00
ULandscapeComponent * LandscapeComponent = NewObject < ULandscapeComponent > ( Landscape , NAME_None , RF_Transactional ) ;
2014-03-14 14:13:41 -04:00
Landscape - > LandscapeComponents . Add ( LandscapeComponent ) ;
NewComponents . Add ( LandscapeComponent ) ;
LandscapeComponent - > Init (
2014-07-17 12:20:34 -04:00
ComponentBase . X , ComponentBase . Y ,
2014-03-14 14:13:41 -04:00
Landscape - > ComponentSizeQuads ,
Landscape - > NumSubsections ,
Landscape - > SubsectionSizeQuads
) ;
LandscapeComponent - > AttachTo ( Landscape - > GetRootComponent ( ) , NAME_None ) ;
// Assign shared properties
LandscapeComponent - > bCastStaticShadow = Landscape - > bCastStaticShadow ;
2014-06-25 02:51:23 -04:00
LandscapeComponent - > bCastShadowAsTwoSided = Landscape - > bCastShadowAsTwoSided ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
int32 ComponentVerts = ( Landscape - > SubsectionSizeQuads + 1 ) * Landscape - > NumSubsections ;
2014-03-14 14:13:41 -04:00
// Update Weightmap Scale Bias
2014-12-18 06:52:06 -05:00
LandscapeComponent - > WeightmapScaleBias = FVector4 ( 1.0f / ( float ) ComponentVerts , 1.0f / ( float ) ComponentVerts , 0.5f / ( float ) ComponentVerts , 0.5f / ( float ) ComponentVerts ) ;
2014-07-17 12:20:34 -04:00
LandscapeComponent - > WeightmapSubsectionOffset = ( float ) ( LandscapeComponent - > SubsectionSizeQuads + 1 ) / ( float ) ComponentVerts ;
2014-03-14 14:13:41 -04:00
TArray < FColor > HeightData ;
2014-07-17 12:20:34 -04:00
HeightData . Empty ( FMath : : Square ( ComponentVerts ) ) ;
HeightData . AddZeroed ( FMath : : Square ( ComponentVerts ) ) ;
2014-03-14 14:13:41 -04:00
LandscapeComponent - > InitHeightmapData ( HeightData , true ) ;
LandscapeComponent - > UpdateMaterialInstances ( ) ;
}
}
}
2014-08-01 04:21:11 -04:00
// Need to register to use general height/xyoffset data update
for ( int32 Idx = 0 ; Idx < NewComponents . Num ( ) ; Idx + + )
{
NewComponents [ Idx ] - > RegisterComponent ( ) ;
}
2014-03-14 14:13:41 -04:00
2014-07-23 08:24:09 -04:00
if ( bHasXYOffset )
{
XYOffsetCache . SetCachedData ( X1 , Y1 , X2 , Y2 , XYOffsetData ) ;
XYOffsetCache . Flush ( ) ;
}
2014-08-06 03:54:25 -04:00
2014-12-18 06:52:06 -05:00
HeightCache . SetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
HeightCache . Flush ( ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
for ( int32 Idx = 0 ; Idx < NewComponents . Num ( ) ; Idx + + )
2014-03-14 14:13:41 -04:00
{
2014-07-17 07:49:03 -04:00
// Update Collision
2014-03-14 14:13:41 -04:00
NewComponents [ Idx ] - > UpdateCachedBounds ( ) ;
NewComponents [ Idx ] - > UpdateBounds ( ) ;
NewComponents [ Idx ] - > MarkRenderStateDirty ( ) ;
ULandscapeHeightfieldCollisionComponent * CollisionComp = NewComponents [ Idx ] - > CollisionComponent . Get ( ) ;
2014-07-23 08:24:09 -04:00
if ( CollisionComp & & ! bHasXYOffset )
2014-03-14 14:13:41 -04:00
{
CollisionComp - > MarkRenderStateDirty ( ) ;
2014-07-17 12:20:34 -04:00
CollisionComp - > RecreateCollision ( ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-07-17 12:20:34 -04:00
2014-12-18 06:52:06 -05:00
EdMode - > LandscapeRenderAddCollision = nullptr ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
GEngine - > BroadcastOnActorMoved ( Landscape ) ;
2014-03-14 14:13:41 -04:00
}
}
protected :
2014-07-17 12:20:34 -04:00
FEdModeLandscape * EdMode ;
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
FLandscapeHeightCache HeightCache ;
2014-07-23 08:24:09 -04:00
FLandscapeXYOffsetCache < true > XYOffsetCache ;
2014-03-14 14:13:41 -04:00
} ;
//
// FLandscapeToolAddComponent
//
class FLandscapeToolAddComponent : public FLandscapeToolBase < FLandscapeToolStrokeAddComponent >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolAddComponent ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolBase < FLandscapeToolStrokeAddComponent > ( InEdMode )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " AddComponent " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_AddComponent " , " Add New Landscape Component " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : None | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
virtual void ExitTool ( ) override
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
FLandscapeToolBase < FLandscapeToolStrokeAddComponent > : : ExitTool ( ) ;
EdMode - > LandscapeRenderAddCollision = nullptr ;
2014-03-14 14:13:41 -04:00
}
} ;
2014-09-11 12:44:16 -04:00
class FLandscapeToolStrokeDeleteComponent : public FLandscapeToolStrokeBase
2014-03-14 14:13:41 -04:00
{
public :
FLandscapeToolStrokeDeleteComponent ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
2014-07-17 12:20:34 -04:00
: LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-09-11 12:44:16 -04:00
void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( LandscapeInfo )
2014-03-14 14:13:41 -04:00
{
LandscapeInfo - > Modify ( ) ;
2014-07-17 12:20:34 -04:00
2014-03-14 14:13:41 -04:00
auto SelectedComponents = LandscapeInfo - > GetSelectedComponents ( ) ;
if ( ! SelectedComponents . Num ( ) )
{
// Get list of verts to update
2014-12-18 06:52:06 -05:00
// TODO - only retrieve bounds as we don't need the data
FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
2014-03-14 14:13:41 -04:00
{
return ;
}
2014-12-18 06:52:06 -05:00
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
// Shrink bounds by 1,1 to avoid GetComponentsInRegion picking up extra components on all sides due to the overlap between components
2014-07-17 12:20:34 -04:00
LandscapeInfo - > GetComponentsInRegion ( X1 + 1 , Y1 + 1 , X2 - 1 , Y2 - 1 , SelectedComponents ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
int32 ComponentSizeVerts = LandscapeInfo - > ComponentNumSubsections * ( LandscapeInfo - > SubsectionSizeQuads + 1 ) ;
int32 NeedHeightmapSize = 1 < < FMath : : CeilLogTwo ( ComponentSizeVerts ) ;
2014-03-14 14:13:41 -04:00
TSet < ULandscapeComponent * > HeightmapUpdateComponents ;
// Need to split all the component which share Heightmap with selected components
// Search neighbor only
2014-12-18 06:52:06 -05:00
for ( ULandscapeComponent * Component : SelectedComponents )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
int32 SearchX = Component - > HeightmapTexture - > Source . GetSizeX ( ) / NeedHeightmapSize ;
int32 SearchY = Component - > HeightmapTexture - > Source . GetSizeY ( ) / NeedHeightmapSize ;
FIntPoint ComponentBase = Component - > GetSectionBase ( ) / Component - > ComponentSizeQuads ;
2014-03-14 14:13:41 -04:00
for ( int32 Y = 0 ; Y < SearchY ; + + Y )
{
for ( int32 X = 0 ; X < SearchX ; + + X )
{
// Search for four directions...
for ( int32 Dir = 0 ; Dir < 4 ; + + Dir )
{
2014-07-17 12:20:34 -04:00
int32 XDir = ( Dir > > 1 ) ? 1 : - 1 ;
int32 YDir = ( Dir % 2 ) ? 1 : - 1 ;
2014-03-14 14:13:41 -04:00
ULandscapeComponent * Neighbor = LandscapeInfo - > XYtoComponentMap . FindRef ( ComponentBase + FIntPoint ( XDir * X , YDir * Y ) ) ;
2014-12-18 06:52:06 -05:00
if ( Neighbor & & Neighbor - > HeightmapTexture = = Component - > HeightmapTexture & & ! HeightmapUpdateComponents . Contains ( Neighbor ) )
2014-03-14 14:13:41 -04:00
{
Neighbor - > Modify ( ) ;
HeightmapUpdateComponents . Add ( Neighbor ) ;
}
}
}
}
}
// Changing Heightmap format for selected components
2014-07-17 12:20:34 -04:00
for ( TSet < ULandscapeComponent * > : : TConstIterator It ( HeightmapUpdateComponents ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
ULandscapeComponent * Component = * It ;
ALandscape : : SplitHeightmap ( Component , false ) ;
2014-03-14 14:13:41 -04:00
}
2015-03-04 06:09:56 -05:00
// Remove attached foliage
for ( TSet < ULandscapeComponent * > : : TIterator It ( SelectedComponents ) ; It ; + + It )
{
ULandscapeHeightfieldCollisionComponent * CollisionComp = ( * It ) - > CollisionComponent . Get ( ) ;
if ( CollisionComp )
{
AInstancedFoliageActor : : DeleteInstancesForComponent ( ViewportClient - > GetWorld ( ) , CollisionComp ) ;
}
}
2014-03-14 14:13:41 -04:00
TArray < FIntPoint > DeletedNeighborKeys ;
// Check which ones are need for height map change
2014-07-17 12:20:34 -04:00
for ( TSet < ULandscapeComponent * > : : TIterator It ( SelectedComponents ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
ULandscapeComponent * Component = * It ;
ALandscapeProxy * Proxy = Component - > GetLandscapeProxy ( ) ;
2014-03-14 14:13:41 -04:00
Proxy - > Modify ( ) ;
2014-12-18 06:52:06 -05:00
//Component->Modify();
2014-03-14 14:13:41 -04:00
2014-07-17 07:49:03 -04:00
// Reset neighbors LOD information
2014-12-18 06:52:06 -05:00
FIntPoint ComponentBase = Component - > GetSectionBase ( ) / Component - > ComponentSizeQuads ;
2014-07-17 07:49:03 -04:00
FIntPoint LandscapeKey [ 8 ] =
{
ComponentBase + FIntPoint ( - 1 , - 1 ) ,
ComponentBase + FIntPoint ( + 0 , - 1 ) ,
ComponentBase + FIntPoint ( + 1 , - 1 ) ,
ComponentBase + FIntPoint ( - 1 , + 0 ) ,
ComponentBase + FIntPoint ( + 1 , + 0 ) ,
ComponentBase + FIntPoint ( - 1 , + 1 ) ,
ComponentBase + FIntPoint ( + 0 , + 1 ) ,
ComponentBase + FIntPoint ( + 1 , + 1 )
} ;
for ( int32 Idx = 0 ; Idx < 8 ; + + Idx )
{
ULandscapeComponent * NeighborComp = LandscapeInfo - > XYtoComponentMap . FindRef ( LandscapeKey [ Idx ] ) ;
if ( NeighborComp )
{
NeighborComp - > Modify ( ) ;
NeighborComp - > InvalidateLightingCache ( ) ;
FComponentReregisterContext ReregisterContext ( NeighborComp ) ;
}
}
2014-03-14 14:13:41 -04:00
// Remove Selected Region in deleted Component
2014-12-18 06:52:06 -05:00
for ( int32 Y = 0 ; Y < Component - > ComponentSizeQuads ; + + Y )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
for ( int32 X = 0 ; X < Component - > ComponentSizeQuads ; + + X )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
LandscapeInfo - > SelectedRegion . Remove ( FIntPoint ( X , Y ) + Component - > GetSectionBase ( ) ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-12-18 06:52:06 -05:00
if ( Component - > HeightmapTexture )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Component - > HeightmapTexture - > SetFlags ( RF_Transactional ) ;
Component - > HeightmapTexture - > Modify ( ) ;
Component - > HeightmapTexture - > MarkPackageDirty ( ) ;
Component - > HeightmapTexture - > ClearFlags ( RF_Standalone ) ; // Remove when there is no reference for this Heightmap...
2014-03-14 14:13:41 -04:00
}
2014-12-18 06:52:06 -05:00
for ( int32 i = 0 ; i < Component - > WeightmapTextures . Num ( ) ; + + i )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Component - > WeightmapTextures [ i ] - > SetFlags ( RF_Transactional ) ;
Component - > WeightmapTextures [ i ] - > Modify ( ) ;
Component - > WeightmapTextures [ i ] - > MarkPackageDirty ( ) ;
Component - > WeightmapTextures [ i ] - > ClearFlags ( RF_Standalone ) ;
2014-03-14 14:13:41 -04:00
}
2014-12-18 06:52:06 -05:00
if ( Component - > XYOffsetmapTexture )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
Component - > XYOffsetmapTexture - > SetFlags ( RF_Transactional ) ;
Component - > XYOffsetmapTexture - > Modify ( ) ;
Component - > XYOffsetmapTexture - > MarkPackageDirty ( ) ;
Component - > XYOffsetmapTexture - > ClearFlags ( RF_Standalone ) ;
2014-03-14 14:13:41 -04:00
}
2014-12-18 06:52:06 -05:00
FIntPoint Key = Component - > GetSectionBase ( ) / Component - > ComponentSizeQuads ;
2014-07-17 12:20:34 -04:00
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( - 1 , - 1 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( + 0 , - 1 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( + 1 , - 1 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( - 1 , + 0 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( + 1 , + 0 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( - 1 , + 1 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( + 0 , + 1 ) ) ;
DeletedNeighborKeys . AddUnique ( Key + FIntPoint ( + 1 , + 1 ) ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
ULandscapeHeightfieldCollisionComponent * CollisionComp = Component - > CollisionComponent . Get ( ) ;
2014-03-14 14:13:41 -04:00
if ( CollisionComp )
{
CollisionComp - > DestroyComponent ( ) ;
}
2014-12-18 06:52:06 -05:00
Component - > DestroyComponent ( ) ;
2014-03-14 14:13:41 -04:00
}
// Update AddCollisions...
for ( int32 i = 0 ; i < DeletedNeighborKeys . Num ( ) ; + + i )
{
LandscapeInfo - > XYtoAddCollisionMap . Remove ( DeletedNeighborKeys [ i ] ) ;
}
for ( int32 i = 0 ; i < DeletedNeighborKeys . Num ( ) ; + + i )
{
2014-12-18 06:52:06 -05:00
ULandscapeComponent * Component = LandscapeInfo - > XYtoComponentMap . FindRef ( DeletedNeighborKeys [ i ] ) ;
if ( Component )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
ULandscapeHeightfieldCollisionComponent * CollisionComp = Component - > CollisionComponent . Get ( ) ;
2014-03-14 14:13:41 -04:00
if ( CollisionComp )
{
CollisionComp - > UpdateAddCollisions ( ) ;
}
}
}
// Remove Selection
LandscapeInfo - > ClearSelectedRegion ( true ) ;
//EdMode->SetMaskEnable(Landscape->SelectedRegion.Num());
GEngine - > BroadcastLevelActorListChanged ( ) ;
}
}
protected :
2014-07-17 12:20:34 -04:00
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
} ;
//
// FLandscapeToolDeleteComponent
//
class FLandscapeToolDeleteComponent : public FLandscapeToolBase < FLandscapeToolStrokeDeleteComponent >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolDeleteComponent ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolBase < FLandscapeToolStrokeDeleteComponent > ( InEdMode )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " DeleteComponent " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_DeleteComponent " , " Delete Landscape Components " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : SelectComponent | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
} ;
template < class ToolTarget >
2014-09-11 12:44:16 -04:00
class FLandscapeToolStrokeCopy : public FLandscapeToolStrokeBase
2014-03-14 14:13:41 -04:00
{
public :
FLandscapeToolStrokeCopy ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
2014-07-17 12:20:34 -04:00
: EdMode ( InEdMode )
, LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
, Cache ( InTarget )
, HeightCache ( InTarget )
, WeightCache ( InTarget )
2014-09-11 12:44:16 -04:00
{
}
2014-07-30 14:51:27 -04:00
2014-07-17 12:20:34 -04:00
struct FGizmoPreData
2014-03-14 14:13:41 -04:00
{
float Ratio ;
float Data ;
} ;
2014-09-11 12:44:16 -04:00
void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
//ULandscapeInfo* LandscapeInfo = EdMode->CurrentToolTarget.LandscapeInfo;
ALandscapeGizmoActiveActor * Gizmo = EdMode - > CurrentGizmoActor . Get ( ) ;
if ( LandscapeInfo & & Gizmo & & Gizmo - > GizmoTexture & & Gizmo - > GetRootComponent ( ) )
{
Gizmo - > TargetLandscapeInfo = LandscapeInfo ;
// Get list of verts to update
2014-12-18 06:52:06 -05:00
// TODO - only retrieve bounds as we don't need the data
FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
2014-03-14 14:13:41 -04:00
{
return ;
}
2014-12-18 06:52:06 -05:00
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
2014-03-14 14:13:41 -04:00
//Gizmo->Modify(); // No transaction for Copied data as other tools...
//Gizmo->SelectedData.Empty();
Gizmo - > ClearGizmoData ( ) ;
// Tablet pressure
2014-12-18 06:52:06 -05:00
//float Pressure = ViewportClient->Viewport->IsPenActive() ? ViewportClient->Viewport->GetTabletPressure() : 1.0f;
2014-03-14 14:13:41 -04:00
bool bApplyToAll = EdMode - > UISettings - > bApplyToAllTargets ;
const int32 LayerNum = LandscapeInfo - > Layers . Num ( ) ;
TArray < uint16 > HeightData ;
TArray < uint8 > WeightDatas ; // Weight*Layers...
TArray < typename ToolTarget : : CacheClass : : DataType > Data ;
TSet < ULandscapeLayerInfoObject * > LayerInfoSet ;
if ( bApplyToAll )
{
2014-07-17 12:20:34 -04:00
HeightCache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
HeightCache . GetCachedData ( X1 , Y1 , X2 , Y2 , HeightData ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
WeightCache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
WeightCache . GetCachedData ( X1 , Y1 , X2 , Y2 , WeightDatas , LayerNum ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-17 12:20:34 -04:00
Cache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
Cache . GetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
}
const float ScaleXY = LandscapeInfo - > DrawScale . X ;
float Width = Gizmo - > GetWidth ( ) ;
float Height = Gizmo - > GetHeight ( ) ;
Gizmo - > CachedWidth = Width ;
Gizmo - > CachedHeight = Height ;
Gizmo - > CachedScaleXY = ScaleXY ;
// Rasterize Gizmo regions
2014-07-17 12:20:34 -04:00
int32 SizeX = FMath : : CeilToInt ( Width / ScaleXY ) ;
2014-05-06 06:26:25 -04:00
int32 SizeY = FMath : : CeilToInt ( Height / ScaleXY ) ;
2014-03-14 14:13:41 -04:00
const float W = ( Width - ScaleXY ) / ( 2 * ScaleXY ) ;
const float H = ( Height - ScaleXY ) / ( 2 * ScaleXY ) ;
2014-08-13 15:29:41 -04:00
FMatrix WToL = LandscapeInfo - > GetLandscapeProxy ( ) - > LandscapeActorToWorld ( ) . ToMatrixWithScale ( ) . InverseFast ( ) ;
2014-03-14 14:13:41 -04:00
//FMatrix LToW = Landscape->LocalToWorld();
FVector BaseLocation = WToL . TransformPosition ( Gizmo - > GetActorLocation ( ) ) ;
FMatrix GizmoLocalToLandscape = FRotationTranslationMatrix ( FRotator ( 0 , Gizmo - > GetActorRotation ( ) . Yaw , 0 ) , FVector ( BaseLocation . X , BaseLocation . Y , 0 ) ) ;
const int32 NeighborNum = 4 ;
bool bDidCopy = false ;
bool bFullCopy = ! EdMode - > UISettings - > bUseSelectedRegion | | ! LandscapeInfo - > SelectedRegion . Num ( ) ;
//bool bInverted = EdMode->UISettings->bUseSelectedRegion && EdMode->UISettings->bUseNegativeMask;
2014-11-12 05:09:02 -05:00
// TODO: This is a mess and badly needs refactoring
2014-03-14 14:13:41 -04:00
for ( int32 Y = 0 ; Y < SizeY ; + + Y )
{
for ( int32 X = 0 ; X < SizeX ; + + X )
{
2014-07-17 12:20:34 -04:00
FVector LandscapeLocal = GizmoLocalToLandscape . TransformPosition ( FVector ( - W + X , - H + Y , 0 ) ) ;
2014-05-06 06:26:25 -04:00
int32 LX = FMath : : FloorToInt ( LandscapeLocal . X ) ;
int32 LY = FMath : : FloorToInt ( LandscapeLocal . Y ) ;
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
for ( int32 i = - 1 ; ( ! bApplyToAll & & i < 0 ) | | i < LayerNum ; + + i )
2014-03-14 14:13:41 -04:00
{
2014-11-12 05:09:02 -05:00
// Don't try to copy data for null layers
2014-12-18 06:52:06 -05:00
if ( ( bApplyToAll & & i > = 0 & & ! LandscapeInfo - > Layers [ i ] . LayerInfoObj ) | |
2014-11-12 05:09:02 -05:00
( ! bApplyToAll & & ! EdMode - > CurrentToolTarget . LayerInfo . Get ( ) ) )
{
continue ;
}
2014-05-29 17:14:20 -04:00
FGizmoPreData GizmoPreData [ NeighborNum ] ;
2014-03-14 14:13:41 -04:00
for ( int32 LocalY = 0 ; LocalY < 2 ; + + LocalY )
{
for ( int32 LocalX = 0 ; LocalX < 2 ; + + LocalX )
{
int32 x = FMath : : Clamp ( LX + LocalX , X1 , X2 ) ;
int32 y = FMath : : Clamp ( LY + LocalY , Y1 , Y2 ) ;
2014-05-29 17:14:20 -04:00
GizmoPreData [ LocalX + LocalY * 2 ] . Ratio = LandscapeInfo - > SelectedRegion . FindRef ( FIntPoint ( x , y ) ) ;
2014-07-17 12:20:34 -04:00
int32 index = ( x - X1 ) + ( y - Y1 ) * ( 1 + X2 - X1 ) ;
2014-03-14 14:13:41 -04:00
if ( bApplyToAll )
{
2014-07-17 12:20:34 -04:00
if ( i < 0 )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:14:20 -04:00
GizmoPreData [ LocalX + LocalY * 2 ] . Data = Gizmo - > GetNormalizedHeight ( HeightData [ index ] ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-05-29 17:14:20 -04:00
GizmoPreData [ LocalX + LocalY * 2 ] . Data = WeightDatas [ index * LayerNum + i ] ;
2014-03-14 14:13:41 -04:00
}
}
else
{
typename ToolTarget : : CacheClass : : DataType OriginalValue = Data [ index ] ;
2014-07-17 12:20:34 -04:00
if ( EdMode - > CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Heightmap )
2014-03-14 14:13:41 -04:00
{
2014-05-29 17:14:20 -04:00
GizmoPreData [ LocalX + LocalY * 2 ] . Data = Gizmo - > GetNormalizedHeight ( OriginalValue ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-05-29 17:14:20 -04:00
GizmoPreData [ LocalX + LocalY * 2 ] . Data = OriginalValue ;
2014-03-14 14:13:41 -04:00
}
}
}
}
FGizmoPreData LerpedData ;
float FracX = LandscapeLocal . X - LX ;
float FracY = LandscapeLocal . Y - LY ;
2014-12-18 06:52:06 -05:00
LerpedData . Ratio = bFullCopy ? 1.0f :
2014-03-14 14:13:41 -04:00
FMath : : Lerp (
2014-05-29 17:14:20 -04:00
FMath : : Lerp ( GizmoPreData [ 0 ] . Ratio , GizmoPreData [ 1 ] . Ratio , FracX ) ,
FMath : : Lerp ( GizmoPreData [ 2 ] . Ratio , GizmoPreData [ 3 ] . Ratio , FracX ) ,
2014-03-14 14:13:41 -04:00
FracY
) ;
LerpedData . Data = FMath : : Lerp (
2014-05-29 17:14:20 -04:00
FMath : : Lerp ( GizmoPreData [ 0 ] . Data , GizmoPreData [ 1 ] . Data , FracX ) ,
FMath : : Lerp ( GizmoPreData [ 2 ] . Data , GizmoPreData [ 3 ] . Data , FracX ) ,
2014-03-14 14:13:41 -04:00
FracY
) ;
2014-12-18 06:52:06 -05:00
if ( ! bDidCopy & & LerpedData . Ratio > 0.0f )
2014-03-14 14:13:41 -04:00
{
bDidCopy = true ;
}
2014-12-18 06:52:06 -05:00
if ( LerpedData . Ratio > 0.0f )
2014-03-14 14:13:41 -04:00
{
// Added for LayerNames
if ( bApplyToAll )
{
if ( i > = 0 )
{
LayerInfoSet . Add ( LandscapeInfo - > Layers [ i ] . LayerInfoObj ) ;
}
}
else
{
if ( EdMode - > CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Weightmap )
{
LayerInfoSet . Add ( EdMode - > CurrentToolTarget . LayerInfo . Get ( ) ) ;
}
}
2014-05-29 17:14:20 -04:00
FGizmoSelectData * GizmoSelectData = Gizmo - > SelectedData . Find ( ALandscape : : MakeKey ( X , Y ) ) ;
if ( GizmoSelectData )
2014-03-14 14:13:41 -04:00
{
if ( bApplyToAll )
{
if ( i < 0 )
{
2014-05-29 17:14:20 -04:00
GizmoSelectData - > HeightData = LerpedData . Data ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-05-29 17:14:20 -04:00
GizmoSelectData - > WeightDataMap . Add ( LandscapeInfo - > Layers [ i ] . LayerInfoObj , LerpedData . Data ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
if ( EdMode - > CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Heightmap )
{
2014-05-29 17:14:20 -04:00
GizmoSelectData - > HeightData = LerpedData . Data ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-05-29 17:14:20 -04:00
GizmoSelectData - > WeightDataMap . Add ( EdMode - > CurrentToolTarget . LayerInfo . Get ( ) , LerpedData . Data ) ;
2014-03-14 14:13:41 -04:00
}
}
}
else
{
FGizmoSelectData NewData ;
NewData . Ratio = LerpedData . Ratio ;
if ( bApplyToAll )
{
if ( i < 0 )
{
NewData . HeightData = LerpedData . Data ;
}
else
{
NewData . WeightDataMap . Add ( LandscapeInfo - > Layers [ i ] . LayerInfoObj , LerpedData . Data ) ;
}
}
else
{
if ( EdMode - > CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Heightmap )
{
NewData . HeightData = LerpedData . Data ;
}
else
{
NewData . WeightDataMap . Add ( EdMode - > CurrentToolTarget . LayerInfo . Get ( ) , LerpedData . Data ) ;
}
}
Gizmo - > SelectedData . Add ( ALandscape : : MakeKey ( X , Y ) , NewData ) ;
}
}
}
}
}
}
if ( bDidCopy )
{
if ( ! bApplyToAll )
{
2014-07-17 12:20:34 -04:00
if ( EdMode - > CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Heightmap )
2014-03-14 14:13:41 -04:00
{
Gizmo - > DataType = ELandscapeGizmoType ( Gizmo - > DataType | LGT_Height ) ;
}
else
{
Gizmo - > DataType = ELandscapeGizmoType ( Gizmo - > DataType | LGT_Weight ) ;
}
}
else
{
2014-07-17 12:20:34 -04:00
if ( LayerNum > 0 )
2014-03-14 14:13:41 -04:00
{
Gizmo - > DataType = ELandscapeGizmoType ( Gizmo - > DataType | LGT_Height ) ;
Gizmo - > DataType = ELandscapeGizmoType ( Gizmo - > DataType | LGT_Weight ) ;
}
else
{
Gizmo - > DataType = ELandscapeGizmoType ( Gizmo - > DataType | LGT_Height ) ;
}
}
Gizmo - > SampleData ( SizeX , SizeY ) ;
// Update LayerInfos
2014-11-12 05:09:02 -05:00
for ( ULandscapeLayerInfoObject * LayerInfo : LayerInfoSet )
2014-03-14 14:13:41 -04:00
{
2014-11-12 05:09:02 -05:00
Gizmo - > LayerInfos . Add ( LayerInfo ) ;
2014-03-14 14:13:41 -04:00
}
}
//// Clean up Ratio 0 regions... (That was for sampling...)
//for ( TMap<uint64, FGizmoSelectData>::TIterator It(Gizmo->SelectedData); It; ++It )
//{
// FGizmoSelectData& Data = It.Value();
2014-12-18 06:52:06 -05:00
// if (Data.Ratio <= 0.0f)
2014-03-14 14:13:41 -04:00
// {
// Gizmo->SelectedData.Remove(It.Key());
// }
//}
Gizmo - > ExportToClipboard ( ) ;
GEngine - > BroadcastLevelActorListChanged ( ) ;
}
}
protected :
2014-07-17 12:20:34 -04:00
FEdModeLandscape * EdMode ;
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
typename ToolTarget : : CacheClass Cache ;
FLandscapeHeightCache HeightCache ;
FLandscapeFullWeightCache WeightCache ;
} ;
//
// FLandscapeToolCopy
//
template < class ToolTarget >
2014-07-17 12:20:34 -04:00
class FLandscapeToolCopy : public FLandscapeToolBase < FLandscapeToolStrokeCopy < ToolTarget > >
2014-03-14 14:13:41 -04:00
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolCopy ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolBase < FLandscapeToolStrokeCopy < ToolTarget > > ( InEdMode )
2014-12-18 06:52:06 -05:00
, BackupCurrentBrush ( nullptr )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " Copy " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_Copy " , " Copy " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override
2014-07-17 12:20:34 -04:00
{
2014-03-14 14:13:41 -04:00
GLandscapeEditRenderMode = ELandscapeEditRenderMode : : Gizmo | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ;
GLandscapeEditRenderMode | = ( this - > EdMode & & this - > EdMode - > CurrentToolTarget . LandscapeInfo . IsValid ( ) & & this - > EdMode - > CurrentToolTarget . LandscapeInfo - > SelectedRegion . Num ( ) ) ? ELandscapeEditRenderMode : : SelectRegion : ELandscapeEditRenderMode : : SelectComponent ;
}
2014-07-17 12:20:34 -04:00
virtual ELandscapeToolTargetTypeMask : : Type GetSupportedTargetTypes ( ) override
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
return ELandscapeToolTargetTypeMask : : FromType ( ToolTarget : : TargetType ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
virtual bool BeginTool ( FEditorViewportClient * ViewportClient , const FLandscapeToolTarget & InTarget , const FVector & InHitLocation ) override
2014-03-14 14:13:41 -04:00
{
this - > EdMode - > GizmoBrush - > Tick ( ViewportClient , 0.1f ) ;
2014-12-18 06:52:06 -05:00
// horrible hack
// (but avoids duplicating the code from FLandscapeToolBase)
BackupCurrentBrush = this - > EdMode - > CurrentBrush ;
this - > EdMode - > CurrentBrush = this - > EdMode - > GizmoBrush ;
2014-12-18 11:03:09 -05:00
return FLandscapeToolBase < FLandscapeToolStrokeCopy < ToolTarget > > : : BeginTool ( ViewportClient , InTarget , InHitLocation ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
virtual void EndTool ( FEditorViewportClient * ViewportClient ) override
2014-03-14 14:13:41 -04:00
{
2014-12-18 11:03:09 -05:00
FLandscapeToolBase < FLandscapeToolStrokeCopy < ToolTarget > > : : EndTool ( ViewportClient ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
this - > EdMode - > CurrentBrush = BackupCurrentBrush ;
2014-07-17 12:20:34 -04:00
}
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
protected :
FLandscapeBrush * BackupCurrentBrush ;
2014-03-14 14:13:41 -04:00
} ;
template < class ToolTarget >
2014-09-11 12:44:16 -04:00
class FLandscapeToolStrokePaste : public FLandscapeToolStrokeBase
2014-03-14 14:13:41 -04:00
{
public :
FLandscapeToolStrokePaste ( FEdModeLandscape * InEdMode , const FLandscapeToolTarget & InTarget )
2014-07-17 12:20:34 -04:00
: EdMode ( InEdMode )
, LandscapeInfo ( InTarget . LandscapeInfo . Get ( ) )
, Cache ( InTarget )
, HeightCache ( InTarget )
, WeightCache ( InTarget )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-09-11 12:44:16 -04:00
void Apply ( FEditorViewportClient * ViewportClient , FLandscapeBrush * Brush , const ULandscapeEditorObject * UISettings , const TArray < FLandscapeToolMousePosition > & MousePositions )
2014-03-14 14:13:41 -04:00
{
//ULandscapeInfo* LandscapeInfo = EdMode->CurrentToolTarget.LandscapeInfo;
ALandscapeGizmoActiveActor * Gizmo = EdMode - > CurrentGizmoActor . Get ( ) ;
// Cache and copy in Gizmo's region...
if ( LandscapeInfo & & Gizmo & & Gizmo - > GetRootComponent ( ) )
{
if ( Gizmo - > SelectedData . Num ( ) = = 0 )
{
return ;
}
2015-01-30 08:05:32 -05:00
// Automatically fill in any placeholder layers
// This gives a much better user experience when copying data to a newly created landscape
for ( ULandscapeLayerInfoObject * LayerInfo : Gizmo - > LayerInfos )
{
int32 LayerInfoIndex = LandscapeInfo - > GetLayerInfoIndex ( LayerInfo ) ;
if ( LayerInfoIndex = = INDEX_NONE )
{
LayerInfoIndex = LandscapeInfo - > GetLayerInfoIndex ( LayerInfo - > LayerName ) ;
if ( LayerInfoIndex ! = INDEX_NONE )
{
FLandscapeInfoLayerSettings & LayerSettings = LandscapeInfo - > Layers [ LayerInfoIndex ] ;
if ( LayerSettings . LayerInfoObj = = nullptr )
{
LayerSettings . Owner = LandscapeInfo - > GetLandscapeProxy ( ) ; // this isn't strictly accurate, but close enough
LayerSettings . LayerInfoObj = LayerInfo ;
LayerSettings . bValid = true ;
}
}
}
}
2014-03-14 14:13:41 -04:00
Gizmo - > TargetLandscapeInfo = LandscapeInfo ;
float ScaleXY = LandscapeInfo - > DrawScale . X ;
//LandscapeInfo->Modify();
// Get list of verts to update
2014-12-18 06:52:06 -05:00
FLandscapeBrushData BrushInfo = Brush - > ApplyBrush ( MousePositions ) ;
if ( ! BrushInfo )
2014-03-14 14:13:41 -04:00
{
return ;
}
2014-12-18 06:52:06 -05:00
int32 X1 , Y1 , X2 , Y2 ;
BrushInfo . GetInclusiveBounds ( X1 , Y1 , X2 , Y2 ) ;
2014-03-14 14:13:41 -04:00
// Tablet pressure
2014-12-18 06:52:06 -05:00
float Pressure = ( ViewportClient & & ViewportClient - > Viewport - > IsPenActive ( ) ) ? ViewportClient - > Viewport - > GetTabletPressure ( ) : 1.0f ;
2014-03-14 14:13:41 -04:00
// expand the area by one vertex in each direction to ensure normals are calculated correctly
X1 - = 1 ;
Y1 - = 1 ;
X2 + = 1 ;
Y2 + = 1 ;
const bool bApplyToAll = EdMode - > UISettings - > bApplyToAllTargets ;
const int32 LayerNum = Gizmo - > LayerInfos . Num ( ) > 0 ? LandscapeInfo - > Layers . Num ( ) : 0 ;
TArray < uint16 > HeightData ;
TArray < uint8 > WeightDatas ; // Weight*Layers...
TArray < typename ToolTarget : : CacheClass : : DataType > Data ;
if ( bApplyToAll )
{
2014-07-17 12:20:34 -04:00
HeightCache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
HeightCache . GetCachedData ( X1 , Y1 , X2 , Y2 , HeightData ) ;
2014-03-14 14:13:41 -04:00
if ( LayerNum > 0 )
{
2014-07-17 12:20:34 -04:00
WeightCache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
WeightCache . GetCachedData ( X1 , Y1 , X2 , Y2 , WeightDatas , LayerNum ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
2014-07-17 12:20:34 -04:00
Cache . CacheData ( X1 , Y1 , X2 , Y2 ) ;
Cache . GetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
}
const float Width = Gizmo - > GetWidth ( ) ;
const float Height = Gizmo - > GetHeight ( ) ;
const float W = Gizmo - > GetWidth ( ) / ( 2 * ScaleXY ) ;
const float H = Gizmo - > GetHeight ( ) / ( 2 * ScaleXY ) ;
2014-12-18 06:52:06 -05:00
const float SignX = Gizmo - > GetRootComponent ( ) - > RelativeScale3D . X > 0.0f ? 1.0f : - 1.0f ;
const float SignY = Gizmo - > GetRootComponent ( ) - > RelativeScale3D . Y > 0.0f ? 1.0f : - 1.0f ;
2014-03-14 14:13:41 -04:00
const float ScaleX = Gizmo - > CachedWidth / Width * ScaleXY / Gizmo - > CachedScaleXY ;
const float ScaleY = Gizmo - > CachedHeight / Height * ScaleXY / Gizmo - > CachedScaleXY ;
2014-08-13 15:29:41 -04:00
FMatrix WToL = LandscapeInfo - > GetLandscapeProxy ( ) - > LandscapeActorToWorld ( ) . ToMatrixWithScale ( ) . InverseFast ( ) ;
2014-03-14 14:13:41 -04:00
//FMatrix LToW = Landscape->LocalToWorld();
FVector BaseLocation = WToL . TransformPosition ( Gizmo - > GetActorLocation ( ) ) ;
//FMatrix LandscapeLocalToGizmo = FRotationTranslationMatrix(FRotator(0, Gizmo->Rotation.Yaw, 0), FVector(BaseLocation.X - W + 0.5, BaseLocation.Y - H + 0.5, 0));
2014-07-17 12:20:34 -04:00
FMatrix LandscapeToGizmoLocal =
2014-12-18 06:52:06 -05:00
( FTranslationMatrix ( FVector ( ( - W + 0.5 ) * SignX , ( - H + 0.5 ) * SignY , 0 ) ) * FScaleRotationTranslationMatrix ( FVector ( SignX , SignY , 1.0f ) , FRotator ( 0 , Gizmo - > GetActorRotation ( ) . Yaw , 0 ) , FVector ( BaseLocation . X , BaseLocation . Y , 0 ) ) ) . InverseFast ( ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
for ( int32 Y = BrushInfo . GetBounds ( ) . Min . Y ; Y < BrushInfo . GetBounds ( ) . Max . Y ; Y + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
const float * BrushScanline = BrushInfo . GetDataPtr ( FIntPoint ( 0 , Y ) ) ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
for ( int32 X = BrushInfo . GetBounds ( ) . Min . X ; X < BrushInfo . GetBounds ( ) . Max . X ; X + + )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
const float BrushValue = BrushScanline [ X ] ;
2014-03-14 14:13:41 -04:00
2014-12-18 06:52:06 -05:00
if ( BrushValue > 0.0f )
2014-03-14 14:13:41 -04:00
{
2014-12-18 06:52:06 -05:00
// TODO: This is a mess and badly needs refactoring
// Value before we apply our painting
int32 index = ( X - X1 ) + ( Y - Y1 ) * ( 1 + X2 - X1 ) ;
float PaintAmount = ( Brush - > GetBrushType ( ) = = ELandscapeBrushType : : Gizmo ) ? BrushValue : BrushValue * EdMode - > UISettings - > ToolStrength * Pressure ;
FVector GizmoLocal = LandscapeToGizmoLocal . TransformPosition ( FVector ( X , Y , 0 ) ) ;
GizmoLocal . X * = ScaleX * SignX ;
GizmoLocal . Y * = ScaleY * SignY ;
int32 LX = FMath : : FloorToInt ( GizmoLocal . X ) ;
int32 LY = FMath : : FloorToInt ( GizmoLocal . Y ) ;
float FracX = GizmoLocal . X - LX ;
float FracY = GizmoLocal . Y - LY ;
FGizmoSelectData * Data00 = Gizmo - > SelectedData . Find ( ALandscape : : MakeKey ( LX , LY ) ) ;
FGizmoSelectData * Data10 = Gizmo - > SelectedData . Find ( ALandscape : : MakeKey ( LX + 1 , LY ) ) ;
FGizmoSelectData * Data01 = Gizmo - > SelectedData . Find ( ALandscape : : MakeKey ( LX , LY + 1 ) ) ;
FGizmoSelectData * Data11 = Gizmo - > SelectedData . Find ( ALandscape : : MakeKey ( LX + 1 , LY + 1 ) ) ;
2014-07-17 12:20:34 -04:00
for ( int32 i = - 1 ; ( ! bApplyToAll & & i < 0 ) | | i < LayerNum ; + + i )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( ( bApplyToAll & & ( i < 0 ) ) | | ( ! bApplyToAll & & EdMode - > CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Heightmap ) )
2014-03-14 14:13:41 -04:00
{
float OriginalValue ;
if ( bApplyToAll )
{
OriginalValue = HeightData [ index ] ;
}
else
{
OriginalValue = Data [ index ] ;
}
float Value = LandscapeDataAccess : : GetLocalHeight ( OriginalValue ) ;
float DestValue = FLandscapeHeightCache : : ClampValue (
LandscapeDataAccess : : GetTexHeight (
FMath : : Lerp (
2014-07-17 12:20:34 -04:00
FMath : : Lerp ( Data00 ? FMath : : Lerp ( Value , Gizmo - > GetLandscapeHeight ( Data00 - > HeightData ) , Data00 - > Ratio ) : Value ,
2014-03-14 14:13:41 -04:00
Data10 ? FMath : : Lerp ( Value , Gizmo - > GetLandscapeHeight ( Data10 - > HeightData ) , Data10 - > Ratio ) : Value , FracX ) ,
2014-07-17 12:20:34 -04:00
FMath : : Lerp ( Data01 ? FMath : : Lerp ( Value , Gizmo - > GetLandscapeHeight ( Data01 - > HeightData ) , Data01 - > Ratio ) : Value ,
2014-03-14 14:13:41 -04:00
Data11 ? FMath : : Lerp ( Value , Gizmo - > GetLandscapeHeight ( Data11 - > HeightData ) , Data11 - > Ratio ) : Value , FracX ) ,
FracY
2014-07-17 12:20:34 -04:00
) )
2014-03-14 14:13:41 -04:00
) ;
2014-07-17 12:20:34 -04:00
switch ( EdMode - > UISettings - > PasteMode )
2014-03-14 14:13:41 -04:00
{
case ELandscapeToolNoiseMode : : Add :
2014-12-18 06:52:06 -05:00
PaintAmount = OriginalValue < DestValue ? PaintAmount : 0.0f ;
2014-03-14 14:13:41 -04:00
break ;
case ELandscapeToolNoiseMode : : Sub :
2014-12-18 06:52:06 -05:00
PaintAmount = OriginalValue > DestValue ? PaintAmount : 0.0f ;
2014-03-14 14:13:41 -04:00
break ;
default :
break ;
}
if ( bApplyToAll )
{
2014-07-17 12:20:34 -04:00
HeightData [ index ] = FMath : : Lerp ( OriginalValue , DestValue , PaintAmount ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-17 12:20:34 -04:00
Data [ index ] = FMath : : Lerp ( OriginalValue , DestValue , PaintAmount ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
ULandscapeLayerInfoObject * LayerInfo ;
float OriginalValue ;
if ( bApplyToAll )
{
LayerInfo = LandscapeInfo - > Layers [ i ] . LayerInfoObj ;
OriginalValue = WeightDatas [ index * LayerNum + i ] ;
}
else
{
LayerInfo = EdMode - > CurrentToolTarget . LayerInfo . Get ( ) ;
OriginalValue = Data [ index ] ;
}
float DestValue = FLandscapeAlphaCache : : ClampValue (
FMath : : Lerp (
2014-07-17 12:20:34 -04:00
FMath : : Lerp ( Data00 ? FMath : : Lerp ( OriginalValue , Data00 - > WeightDataMap . FindRef ( LayerInfo ) , Data00 - > Ratio ) : OriginalValue ,
2014-03-14 14:13:41 -04:00
Data10 ? FMath : : Lerp ( OriginalValue , Data10 - > WeightDataMap . FindRef ( LayerInfo ) , Data10 - > Ratio ) : OriginalValue , FracX ) ,
2014-07-17 12:20:34 -04:00
FMath : : Lerp ( Data01 ? FMath : : Lerp ( OriginalValue , Data01 - > WeightDataMap . FindRef ( LayerInfo ) , Data01 - > Ratio ) : OriginalValue ,
2014-03-14 14:13:41 -04:00
Data11 ? FMath : : Lerp ( OriginalValue , Data11 - > WeightDataMap . FindRef ( LayerInfo ) , Data11 - > Ratio ) : OriginalValue , FracX ) ,
FracY
) ) ;
if ( bApplyToAll )
{
2014-07-17 12:20:34 -04:00
WeightDatas [ index * LayerNum + i ] = FMath : : Lerp ( OriginalValue , DestValue , PaintAmount ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-17 12:20:34 -04:00
Data [ index ] = FMath : : Lerp ( OriginalValue , DestValue , PaintAmount ) ;
2014-03-14 14:13:41 -04:00
}
}
}
}
}
}
2015-01-30 08:05:32 -05:00
for ( ULandscapeLayerInfoObject * LayerInfo : Gizmo - > LayerInfos )
2014-03-14 14:13:41 -04:00
{
2015-01-30 08:05:32 -05:00
if ( LandscapeInfo - > GetLayerInfoIndex ( LayerInfo ) ! = INDEX_NONE )
{
WeightCache . AddDirtyLayer ( LayerInfo ) ;
}
2014-03-14 14:13:41 -04:00
}
if ( bApplyToAll )
{
2014-07-17 12:20:34 -04:00
HeightCache . SetCachedData ( X1 , Y1 , X2 , Y2 , HeightData ) ;
2014-03-14 14:13:41 -04:00
HeightCache . Flush ( ) ;
if ( WeightDatas . Num ( ) )
{
// Set the layer data, bypassing painting restrictions because it doesn't work well when altering multiple layers
2014-07-17 12:20:34 -04:00
WeightCache . SetCachedData ( X1 , Y1 , X2 , Y2 , WeightDatas , LayerNum , ELandscapeLayerPaintingRestriction : : None ) ;
2014-03-14 14:13:41 -04:00
}
WeightCache . Flush ( ) ;
}
else
{
2014-07-17 12:20:34 -04:00
Cache . SetCachedData ( X1 , Y1 , X2 , Y2 , Data ) ;
2014-03-14 14:13:41 -04:00
Cache . Flush ( ) ;
}
GEngine - > BroadcastLevelActorListChanged ( ) ;
}
}
protected :
2014-07-17 12:20:34 -04:00
FEdModeLandscape * EdMode ;
ULandscapeInfo * LandscapeInfo ;
2014-03-14 14:13:41 -04:00
typename ToolTarget : : CacheClass Cache ;
FLandscapeHeightCache HeightCache ;
FLandscapeFullWeightCache WeightCache ;
} ;
//
// FLandscapeToolPaste
//
template < class ToolTarget >
2014-07-17 12:20:34 -04:00
class FLandscapeToolPaste : public FLandscapeToolBase < FLandscapeToolStrokePaste < ToolTarget > >
2014-03-14 14:13:41 -04:00
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolPaste ( FEdModeLandscape * InEdMode )
2014-12-18 06:52:06 -05:00
: FLandscapeToolBase < FLandscapeToolStrokePaste < ToolTarget > > ( InEdMode )
2014-07-17 12:20:34 -04:00
, bUseGizmoRegion ( false )
2014-12-18 06:52:06 -05:00
, BackupCurrentBrush ( nullptr )
2014-09-11 12:44:16 -04:00
{
}
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " Paste " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_Region " , " Region Copy/Paste " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
virtual void SetEditRenderType ( ) override
{
2014-03-14 14:13:41 -04:00
GLandscapeEditRenderMode = ELandscapeEditRenderMode : : Gizmo | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ;
GLandscapeEditRenderMode | = ( this - > EdMode & & this - > EdMode - > CurrentToolTarget . LandscapeInfo . IsValid ( ) & & this - > EdMode - > CurrentToolTarget . LandscapeInfo - > SelectedRegion . Num ( ) ) ? ELandscapeEditRenderMode : : SelectRegion : ELandscapeEditRenderMode : : SelectComponent ;
}
void SetGizmoMode ( bool InbUseGizmoRegion )
{
bUseGizmoRegion = InbUseGizmoRegion ;
}
2014-07-17 12:20:34 -04:00
virtual ELandscapeToolTargetTypeMask : : Type GetSupportedTargetTypes ( ) override
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
return ELandscapeToolTargetTypeMask : : FromType ( ToolTarget : : TargetType ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
virtual bool BeginTool ( FEditorViewportClient * ViewportClient , const FLandscapeToolTarget & InTarget , const FVector & InHitLocation ) override
2014-03-14 14:13:41 -04:00
{
this - > EdMode - > GizmoBrush - > Tick ( ViewportClient , 0.1f ) ;
2014-12-18 06:52:06 -05:00
// horrible hack
// (but avoids duplicating the code from FLandscapeToolBase)
BackupCurrentBrush = this - > EdMode - > CurrentBrush ;
2014-03-14 14:13:41 -04:00
if ( bUseGizmoRegion )
{
2014-12-18 06:52:06 -05:00
this - > EdMode - > CurrentBrush = this - > EdMode - > GizmoBrush ;
2014-03-14 14:13:41 -04:00
}
2014-12-18 11:02:27 -05:00
return FLandscapeToolBase < FLandscapeToolStrokePaste < ToolTarget > > : : BeginTool ( ViewportClient , InTarget , InHitLocation ) ;
2014-03-14 14:13:41 -04:00
}
2014-06-18 10:16:16 -04:00
virtual void EndTool ( FEditorViewportClient * ViewportClient ) override
2014-03-14 14:13:41 -04:00
{
2014-12-18 11:02:27 -05:00
FLandscapeToolBase < FLandscapeToolStrokePaste < ToolTarget > > : : EndTool ( ViewportClient ) ;
2014-03-14 14:13:41 -04:00
if ( bUseGizmoRegion )
{
2014-12-18 06:52:06 -05:00
this - > EdMode - > CurrentBrush = BackupCurrentBrush ;
2014-03-14 14:13:41 -04:00
}
2014-12-18 06:52:06 -05:00
check ( this - > EdMode - > CurrentBrush = = BackupCurrentBrush ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
virtual bool MouseMove ( FEditorViewportClient * ViewportClient , FViewport * Viewport , int32 x , int32 y ) override
2014-03-14 14:13:41 -04:00
{
if ( bUseGizmoRegion )
{
return true ;
}
2014-12-18 06:52:06 -05:00
return FLandscapeToolBase < FLandscapeToolStrokePaste < ToolTarget > > : : MouseMove ( ViewportClient , Viewport , x , y ) ;
2014-07-17 12:20:34 -04:00
}
2014-12-18 06:52:06 -05:00
2014-03-14 14:13:41 -04:00
protected :
bool bUseGizmoRegion ;
2014-12-18 06:52:06 -05:00
FLandscapeBrush * BackupCurrentBrush ;
2014-03-14 14:13:41 -04:00
} ;
template < class ToolTarget >
class FLandscapeToolCopyPaste : public FLandscapeToolPaste < ToolTarget >
{
public :
2014-07-17 12:20:34 -04:00
FLandscapeToolCopyPaste ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeToolPaste < ToolTarget > ( InEdMode )
2014-07-17 12:20:34 -04:00
, CopyTool ( InEdMode )
2014-03-14 14:13:41 -04:00
{
}
// Just hybrid of Copy and Paste tool
2014-07-17 12:20:34 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " CopyPaste " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_Region " , " Region Copy/Paste " ) ; } ;
2015-04-01 07:20:55 -04:00
virtual void EnterTool ( ) override
2015-01-20 10:47:28 -05:00
{
// Make sure gizmo actor is selected
2015-01-20 14:43:57 -05:00
ALandscapeGizmoActiveActor * Gizmo = this - > EdMode - > CurrentGizmoActor . Get ( ) ;
2015-01-20 10:47:28 -05:00
if ( Gizmo )
{
GEditor - > SelectNone ( false , true ) ;
GEditor - > SelectActor ( Gizmo , true , false , true ) ;
}
}
2014-03-14 14:13:41 -04:00
// Copy tool doesn't use any view information, so just do it as one function
2014-07-17 12:20:34 -04:00
void Copy ( )
2014-03-14 14:13:41 -04:00
{
2014-09-11 12:44:16 -04:00
CopyTool . BeginTool ( nullptr , this - > EdMode - > CurrentToolTarget , FVector : : ZeroVector ) ;
CopyTool . EndTool ( nullptr ) ;
2014-07-17 12:20:34 -04:00
}
void Paste ( )
{
2014-07-17 17:20:30 -04:00
this - > SetGizmoMode ( true ) ;
this - > BeginTool ( nullptr , this - > EdMode - > CurrentToolTarget , FVector : : ZeroVector ) ;
this - > EndTool ( nullptr ) ;
this - > SetGizmoMode ( false ) ;
2014-03-14 14:13:41 -04:00
}
protected :
2014-09-11 12:44:16 -04:00
FLandscapeToolCopy < ToolTarget > CopyTool ;
2014-03-14 14:13:41 -04:00
} ;
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : CopyDataToGizmo ( )
{
// For Copy operation...
if ( CopyPasteTool /*&& CopyPasteTool == CurrentTool*/ )
{
CopyPasteTool - > Copy ( ) ;
}
if ( CurrentGizmoActor . IsValid ( ) )
{
GEditor - > SelectNone ( false , true ) ;
GEditor - > SelectActor ( CurrentGizmoActor . Get ( ) , true , true , true ) ;
}
}
void FEdModeLandscape : : PasteDataFromGizmo ( )
{
// For Paste for Gizmo Region operation...
if ( CopyPasteTool /*&& CopyPasteTool == CurrentTool*/ )
{
CopyPasteTool - > Paste ( ) ;
}
if ( CurrentGizmoActor . IsValid ( ) )
{
GEditor - > SelectNone ( false , true ) ;
GEditor - > SelectActor ( CurrentGizmoActor . Get ( ) , true , true , true ) ;
}
}
2014-03-14 14:13:41 -04:00
//
// FLandscapeToolNewLandscape
//
class FLandscapeToolNewLandscape : public FLandscapeTool
{
public :
2014-07-17 12:20:34 -04:00
FEdModeLandscape * EdMode ;
2014-03-14 14:13:41 -04:00
ENewLandscapePreviewMode : : Type NewLandscapePreviewMode ;
2014-07-17 12:20:34 -04:00
FLandscapeToolNewLandscape ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeTool ( )
, EdMode ( InEdMode )
, NewLandscapePreviewMode ( ENewLandscapePreviewMode : : NewLandscape )
{
}
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " NewLandscape " ) ; }
virtual FText GetDisplayName ( ) override { return NSLOCTEXT ( " UnrealEd " , " LandscapeMode_NewLandscape " , " New Landscape " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : None | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
2015-04-01 07:20:55 -04:00
virtual void EnterTool ( ) override
2014-03-14 14:13:41 -04:00
{
EdMode - > NewLandscapePreviewMode = NewLandscapePreviewMode ;
}
2015-04-01 07:20:55 -04:00
virtual void ExitTool ( ) override
2014-03-14 14:13:41 -04:00
{
NewLandscapePreviewMode = EdMode - > NewLandscapePreviewMode ;
EdMode - > NewLandscapePreviewMode = ENewLandscapePreviewMode : : None ;
}
2015-04-01 07:20:55 -04:00
virtual bool BeginTool ( FEditorViewportClient * ViewportClient , const FLandscapeToolTarget & Target , const FVector & InHitLocation ) override
2014-03-14 14:13:41 -04:00
{
// does nothing
return false ;
}
2015-04-01 07:20:55 -04:00
virtual void EndTool ( FEditorViewportClient * ViewportClient ) override
2014-03-14 14:13:41 -04:00
{
// does nothing
}
2015-04-01 07:20:55 -04:00
virtual bool MouseMove ( FEditorViewportClient * ViewportClient , FViewport * Viewport , int32 x , int32 y ) override
2014-03-14 14:13:41 -04:00
{
// does nothing
return false ;
}
} ;
//
// FLandscapeToolResizeLandscape
//
class FLandscapeToolResizeLandscape : public FLandscapeTool
{
public :
2014-07-17 12:20:34 -04:00
FEdModeLandscape * EdMode ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
FLandscapeToolResizeLandscape ( FEdModeLandscape * InEdMode )
2014-03-14 14:13:41 -04:00
: FLandscapeTool ( )
, EdMode ( InEdMode )
{
}
2014-06-13 06:14:46 -04:00
virtual const TCHAR * GetToolName ( ) override { return TEXT ( " ResizeLandscape " ) ; }
virtual FText GetDisplayName ( ) override { return LOCTEXT ( " LandscapeMode_ResizeLandscape " , " Change Landscape Component Size " ) ; } ;
2014-03-14 14:13:41 -04:00
2014-06-13 06:14:46 -04:00
virtual void SetEditRenderType ( ) override { GLandscapeEditRenderMode = ELandscapeEditRenderMode : : None | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ; }
virtual bool SupportsMask ( ) override { return false ; }
2014-03-14 14:13:41 -04:00
2015-04-01 07:20:55 -04:00
virtual void EnterTool ( ) override
2014-03-14 14:13:41 -04:00
{
const int32 ComponentSizeQuads = EdMode - > CurrentToolTarget . LandscapeInfo - > ComponentSizeQuads ;
int32 MinX , MinY , MaxX , MaxY ;
if ( EdMode - > CurrentToolTarget . LandscapeInfo - > GetLandscapeExtent ( MinX , MinY , MaxX , MaxY ) )
{
2014-04-02 18:09:23 -04:00
EdMode - > UISettings - > ResizeLandscape_Original_ComponentCount . X = ( MaxX - MinX ) / ComponentSizeQuads ;
EdMode - > UISettings - > ResizeLandscape_Original_ComponentCount . Y = ( MaxY - MinY ) / ComponentSizeQuads ;
EdMode - > UISettings - > ResizeLandscape_ComponentCount = EdMode - > UISettings - > ResizeLandscape_Original_ComponentCount ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-04-02 18:09:23 -04:00
EdMode - > UISettings - > ResizeLandscape_Original_ComponentCount = FIntPoint : : ZeroValue ;
2014-03-14 14:13:41 -04:00
EdMode - > UISettings - > ResizeLandscape_ComponentCount = FIntPoint : : ZeroValue ;
}
2014-07-17 12:20:34 -04:00
EdMode - > UISettings - > ResizeLandscape_Original_QuadsPerSection = EdMode - > CurrentToolTarget . LandscapeInfo - > SubsectionSizeQuads ;
2014-04-02 18:09:23 -04:00
EdMode - > UISettings - > ResizeLandscape_Original_SectionsPerComponent = EdMode - > CurrentToolTarget . LandscapeInfo - > ComponentNumSubsections ;
2014-07-17 12:20:34 -04:00
EdMode - > UISettings - > ResizeLandscape_QuadsPerSection = EdMode - > UISettings - > ResizeLandscape_Original_QuadsPerSection ;
2014-04-02 18:09:23 -04:00
EdMode - > UISettings - > ResizeLandscape_SectionsPerComponent = EdMode - > UISettings - > ResizeLandscape_Original_SectionsPerComponent ;
2014-03-14 14:13:41 -04:00
}
2015-04-01 07:20:55 -04:00
virtual void ExitTool ( ) override
2014-03-14 14:13:41 -04:00
{
}
2015-04-01 07:20:55 -04:00
virtual bool BeginTool ( FEditorViewportClient * ViewportClient , const FLandscapeToolTarget & Target , const FVector & InHitLocation ) override
2014-03-14 14:13:41 -04:00
{
// does nothing
return false ;
}
2015-04-01 07:20:55 -04:00
virtual void EndTool ( FEditorViewportClient * ViewportClient ) override
2014-03-14 14:13:41 -04:00
{
// does nothing
}
2015-04-01 07:20:55 -04:00
virtual bool MouseMove ( FEditorViewportClient * ViewportClient , FViewport * Viewport , int32 x , int32 y ) override
2014-03-14 14:13:41 -04:00
{
// does nothing
return false ;
}
} ;
//////////////////////////////////////////////////////////////////////////
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_NewLandscape ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_NewLandscape = MakeUnique < FLandscapeToolNewLandscape > ( this ) ;
Tool_NewLandscape - > ValidBrushes . Add ( " BrushSet_Dummy " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_NewLandscape ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_ResizeLandscape ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_ResizeLandscape = MakeUnique < FLandscapeToolResizeLandscape > ( this ) ;
Tool_ResizeLandscape - > ValidBrushes . Add ( " BrushSet_Dummy " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_ResizeLandscape ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_Select ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_Select = MakeUnique < FLandscapeToolSelect < FLandscapeToolStrokeSelect > > ( this ) ;
Tool_Select - > ValidBrushes . Add ( " BrushSet_Component " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_Select ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_AddComponent ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_AddComponent = MakeUnique < FLandscapeToolAddComponent > ( this ) ;
Tool_AddComponent - > ValidBrushes . Add ( " BrushSet_Component " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_AddComponent ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_DeleteComponent ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_DeleteComponent = MakeUnique < FLandscapeToolDeleteComponent > ( this ) ;
Tool_DeleteComponent - > ValidBrushes . Add ( " BrushSet_Component " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_DeleteComponent ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_MoveToLevel ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_MoveToLevel = MakeUnique < FLandscapeToolMoveToLevel > ( this ) ;
Tool_MoveToLevel - > ValidBrushes . Add ( " BrushSet_Component " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_MoveToLevel ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_Mask ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_Mask = MakeUnique < FLandscapeToolMask < FLandscapeToolStrokeSelect > > ( this ) ;
Tool_Mask - > ValidBrushes . Add ( " BrushSet_Circle " ) ;
Tool_Mask - > ValidBrushes . Add ( " BrushSet_Alpha " ) ;
Tool_Mask - > ValidBrushes . Add ( " BrushSet_Pattern " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_Mask ) ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_CopyPaste ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_CopyPaste_Heightmap = MakeUnique < FLandscapeToolCopyPaste < FHeightmapToolTarget > > ( this ) ;
Tool_CopyPaste_Heightmap - > ValidBrushes . Add ( " BrushSet_Circle " ) ;
Tool_CopyPaste_Heightmap - > ValidBrushes . Add ( " BrushSet_Alpha " ) ;
Tool_CopyPaste_Heightmap - > ValidBrushes . Add ( " BrushSet_Pattern " ) ;
Tool_CopyPaste_Heightmap - > ValidBrushes . Add ( " BrushSet_Gizmo " ) ;
CopyPasteTool = Tool_CopyPaste_Heightmap . Get ( ) ;
LandscapeTools . Add ( MoveTemp ( Tool_CopyPaste_Heightmap ) ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
//auto Tool_CopyPaste_Weightmap = MakeUnique<FLandscapeToolCopyPaste<FWeightmapToolTarget>>(this);
//Tool_CopyPaste_Weightmap->ValidBrushes.Add("BrushSet_Circle");
//Tool_CopyPaste_Weightmap->ValidBrushes.Add("BrushSet_Alpha");
//Tool_CopyPaste_Weightmap->ValidBrushes.Add("BrushSet_Pattern");
//Tool_CopyPaste_Weightmap->ValidBrushes.Add("BrushSet_Gizmo");
//LandscapeTools.Add(MoveTemp(Tool_CopyPaste_Weightmap));
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : InitializeTool_Visibility ( )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
auto Tool_Visibility = MakeUnique < FLandscapeToolVisibility > ( this ) ;
Tool_Visibility - > ValidBrushes . Add ( " BrushSet_Circle " ) ;
Tool_Visibility - > ValidBrushes . Add ( " BrushSet_Alpha " ) ;
Tool_Visibility - > ValidBrushes . Add ( " BrushSet_Pattern " ) ;
LandscapeTools . Add ( MoveTemp ( Tool_Visibility ) ) ;
2014-03-14 14:13:41 -04:00
}
2015-04-01 07:20:55 -04:00
# undef LOCTEXT_NAMESPACE