2014-03-14 14:13:41 -04:00
// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved.
# include "LandscapeEditorPrivatePCH.h"
2014-05-21 10:00:58 -04:00
# include "EditorSupportDelegates.h"
2014-03-14 14:13:41 -04:00
# include "ObjectTools.h"
# include "LandscapeEdMode.h"
# include "ScopedTransaction.h"
# include "Landscape/LandscapeEdit.h"
# include "Landscape/LandscapeRender.h"
# include "Landscape/LandscapeDataAccess.h"
# include "Landscape/LandscapeSplineProxies.h"
# include "LandscapeEditorModule.h"
# include "Editor/LevelEditor/Public/LevelEditor.h"
# include "Editor/PropertyEditor/Public/PropertyEditorModule.h"
# include "Editor/UnrealEd/Public/Toolkits/ToolkitManager.h"
# include "LandscapeEdModeTools.h"
# include "ScopedTransaction.h"
# include "ImageWrapper.h"
2014-05-29 17:36:51 -04:00
# include "DynamicMeshBuilder.h"
2014-03-14 14:13:41 -04:00
//Slate dependencies
# include "Editor/LevelEditor/Public/LevelEditor.h"
# include "Editor/LevelEditor/Public/SLevelViewport.h"
# include "SLandscapeEditor.h"
2014-05-22 07:52:43 -04:00
// Classes
# include "Landscape/Landscape.h"
2014-08-04 10:14:05 -04:00
# include "Landscape/LandscapeLayerInfoObject.h"
2014-05-22 07:52:43 -04:00
# include "Landscape/LandscapeHeightfieldCollisionComponent.h"
# include "Landscape/LandscapeMaterialInstanceConstant.h"
# include "Landscape/LandscapeSplinesComponent.h"
# include "Foliage/InstancedFoliageActor.h"
2014-06-18 07:25:31 -04:00
# include "ComponentReregisterContext.h"
2014-05-22 07:52:43 -04:00
2014-03-14 14:13:41 -04:00
# define LOCTEXT_NAMESPACE "Landscape"
DEFINE_LOG_CATEGORY ( LogLandscapeEdMode ) ;
struct HNewLandscapeGrabHandleProxy : public HHitProxy
{
2014-07-17 12:20:34 -04:00
DECLARE_HIT_PROXY ( ) ;
2014-03-14 14:13:41 -04:00
ELandscapeEdge : : Type Edge ;
HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : Type InEdge ) :
HHitProxy ( HPP_Wireframe ) ,
Edge ( InEdge )
{
}
virtual EMouseCursor : : Type GetMouseCursor ( )
{
switch ( Edge )
{
case ELandscapeEdge : : X_Negative :
case ELandscapeEdge : : X_Positive :
return EMouseCursor : : ResizeLeftRight ;
case ELandscapeEdge : : Y_Negative :
case ELandscapeEdge : : Y_Positive :
return EMouseCursor : : ResizeUpDown ;
case ELandscapeEdge : : X_Negative_Y_Negative :
case ELandscapeEdge : : X_Positive_Y_Positive :
return EMouseCursor : : ResizeSouthEast ;
case ELandscapeEdge : : X_Negative_Y_Positive :
case ELandscapeEdge : : X_Positive_Y_Negative :
return EMouseCursor : : ResizeSouthWest ;
}
return EMouseCursor : : SlashedCircle ;
}
} ;
IMPLEMENT_HIT_PROXY ( HNewLandscapeGrabHandleProxy , HHitProxy )
void ALandscape : : SplitHeightmap ( ULandscapeComponent * Comp , bool bMoveToCurrentLevel /*= false*/ )
{
ULandscapeInfo * Info = Comp - > GetLandscapeInfo ( ) ;
2014-07-17 12:20:34 -04:00
int32 ComponentSizeVerts = Comp - > NumSubsections * ( Comp - > SubsectionSizeQuads + 1 ) ;
2014-03-14 14:13:41 -04:00
// make sure the heightmap UVs are powers of two.
2014-07-17 12:20:34 -04:00
int32 HeightmapSizeU = ( 1 < < FMath : : CeilLogTwo ( ComponentSizeVerts ) ) ;
int32 HeightmapSizeV = ( 1 < < FMath : : CeilLogTwo ( ComponentSizeVerts ) ) ;
2014-03-14 14:13:41 -04:00
UTexture2D * HeightmapTexture = NULL ;
TArray < FColor * > HeightmapTextureMipData ;
// Scope for FLandscapeEditDataInterface
{
// Read old data and split
FLandscapeEditDataInterface LandscapeEdit ( Info ) ;
TArray < uint8 > HeightData ;
2014-07-17 12:20:34 -04:00
HeightData . AddZeroed ( ( 1 + Comp - > ComponentSizeQuads ) * ( 1 + Comp - > ComponentSizeQuads ) * sizeof ( uint16 ) ) ;
2014-03-14 14:13:41 -04:00
// Because of edge problem, normal would be just copy from old component data
TArray < uint8 > NormalData ;
2014-07-17 12:20:34 -04:00
NormalData . AddZeroed ( ( 1 + Comp - > ComponentSizeQuads ) * ( 1 + Comp - > ComponentSizeQuads ) * sizeof ( uint16 ) ) ;
2014-09-29 04:23:44 -04:00
LandscapeEdit . GetHeightDataFast ( Comp - > GetSectionBase ( ) . X , Comp - > GetSectionBase ( ) . Y , Comp - > GetSectionBase ( ) . X + Comp - > ComponentSizeQuads , Comp - > GetSectionBase ( ) . Y + Comp - > ComponentSizeQuads , ( uint16 * ) HeightData . GetData ( ) , 0 , ( uint16 * ) NormalData . GetData ( ) ) ;
2014-03-14 14:13:41 -04:00
// Construct the heightmap textures
2014-07-12 12:59:16 -04:00
UObject * TextureOuter = bMoveToCurrentLevel ? Comp - > GetWorld ( ) - > GetCurrentLevel ( ) - > GetOutermost ( ) : nullptr ;
2014-05-29 16:50:00 -04:00
HeightmapTexture = Comp - > GetLandscapeProxy ( ) - > CreateLandscapeTexture ( HeightmapSizeU , HeightmapSizeV , TEXTUREGROUP_Terrain_Heightmap , TSF_BGRA8 , TextureOuter ) ;
2014-03-14 14:13:41 -04:00
int32 MipSubsectionSizeQuads = Comp - > SubsectionSizeQuads ;
int32 MipSizeU = HeightmapSizeU ;
int32 MipSizeV = HeightmapSizeV ;
2014-07-17 12:20:34 -04:00
while ( MipSizeU > 1 & & MipSizeV > 1 & & MipSubsectionSizeQuads > = 1 )
2014-03-14 14:13:41 -04:00
{
FColor * HeightmapTextureData = ( FColor * ) HeightmapTexture - > Source . LockMip ( HeightmapTextureMipData . Num ( ) ) ;
2014-07-17 12:20:34 -04:00
FMemory : : Memzero ( HeightmapTextureData , MipSizeU * MipSizeV * sizeof ( FColor ) ) ;
2014-03-14 14:13:41 -04:00
HeightmapTextureMipData . Add ( HeightmapTextureData ) ;
MipSizeU > > = 1 ;
MipSizeV > > = 1 ;
MipSubsectionSizeQuads = ( ( MipSubsectionSizeQuads + 1 ) > > 1 ) - 1 ;
}
2014-07-17 12:20:34 -04:00
Comp - > HeightmapScaleBias = FVector4 ( 1.f / ( float ) HeightmapSizeU , 1.f / ( float ) HeightmapSizeV , 0.f , 0.f ) ;
2014-03-14 14:13:41 -04:00
Comp - > HeightmapTexture = HeightmapTexture ;
if ( Comp - > MaterialInstance )
{
Comp - > MaterialInstance - > SetTextureParameterValueEditorOnly ( FName ( TEXT ( " Heightmap " ) ) , HeightmapTexture ) ;
}
2014-07-17 12:20:34 -04:00
for ( int32 i = 0 ; i < HeightmapTextureMipData . Num ( ) ; i + + )
2014-03-14 14:13:41 -04:00
{
HeightmapTexture - > Source . UnlockMip ( i ) ;
}
2014-09-29 04:23:44 -04:00
LandscapeEdit . SetHeightData ( Comp - > GetSectionBase ( ) . X , Comp - > GetSectionBase ( ) . Y , Comp - > GetSectionBase ( ) . X + Comp - > ComponentSizeQuads , Comp - > GetSectionBase ( ) . Y + Comp - > ComponentSizeQuads , ( uint16 * ) HeightData . GetData ( ) , 0 , false , ( uint16 * ) NormalData . GetData ( ) ) ;
2014-03-14 14:13:41 -04:00
}
// End of LandscapeEdit interface
HeightmapTexture - > PostEditChange ( ) ;
// Reregister
FComponentReregisterContext ReregisterContext ( Comp ) ;
}
void FLandscapeTool : : SetEditRenderType ( )
{
GLandscapeEditRenderMode = ELandscapeEditRenderMode : : SelectRegion | ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : BitMaskForMask ) ;
}
//
// FEdModeLandscape
//
/** Constructor */
2014-07-17 12:20:34 -04:00
FEdModeLandscape : : FEdModeLandscape ( )
: FEdMode ( )
, NewLandscapePreviewMode ( ENewLandscapePreviewMode : : None )
, DraggingEdge ( ELandscapeEdge : : None )
, DraggingEdge_Remainder ( 0 )
2014-07-30 14:51:27 -04:00
, CurrentGizmoActor ( nullptr )
, CopyPasteTool ( nullptr )
, SplinesTool ( nullptr )
, LandscapeRenderAddCollision ( nullptr )
2014-07-17 12:20:34 -04:00
, CachedLandscapeMaterial ( nullptr )
2014-07-30 14:51:27 -04:00
, bToolActive ( false )
, GizmoMaterial ( nullptr )
2014-03-14 14:13:41 -04:00
{
GizmoMaterial = LoadObject < UMaterial > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/GizmoMaterial.GizmoMaterial " ) , NULL , LOAD_None , NULL ) ;
GLayerDebugColorMaterial = LoadObject < UMaterial > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/LayerVisMaterial.LayerVisMaterial " ) , NULL , LOAD_None , NULL ) ;
GSelectionColorMaterial = LoadObject < UMaterialInstanceConstant > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/SelectBrushMaterial_Selected.SelectBrushMaterial_Selected " ) , NULL , LOAD_None , NULL ) ;
GSelectionRegionMaterial = LoadObject < UMaterialInstanceConstant > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/SelectBrushMaterial_SelectedRegion.SelectBrushMaterial_SelectedRegion " ) , NULL , LOAD_None , NULL ) ;
GMaskRegionMaterial = LoadObject < UMaterialInstanceConstant > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/MaskBrushMaterial_MaskedRegion.MaskBrushMaterial_MaskedRegion " ) , NULL , LOAD_None , NULL ) ;
GLandscapeBlackTexture = LoadObject < UTexture2D > ( NULL , TEXT ( " /Engine/EngineResources/Black.Black " ) , NULL , LOAD_None , NULL ) ;
// Initialize modes
InitializeToolModes ( ) ;
2014-07-17 12:20:34 -04:00
CurrentToolMode = nullptr ;
2014-03-14 14:13:41 -04:00
// Initialize tools.
2014-07-17 12:20:34 -04:00
InitializeTool_Paint ( ) ;
InitializeTool_Smooth ( ) ;
InitializeTool_Flatten ( ) ;
InitializeTool_Ramp ( ) ;
InitializeTool_Erosion ( ) ;
InitializeTool_HydraErosion ( ) ;
InitializeTool_Noise ( ) ;
InitializeTool_Retopologize ( ) ;
InitializeTool_NewLandscape ( ) ;
InitializeTool_ResizeLandscape ( ) ;
InitializeTool_Select ( ) ;
InitializeTool_AddComponent ( ) ;
InitializeTool_DeleteComponent ( ) ;
InitializeTool_MoveToLevel ( ) ;
InitializeTool_Mask ( ) ;
InitializeTool_CopyPaste ( ) ;
InitializeTool_Visibility ( ) ;
InitializeTool_Splines ( ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
CurrentTool = nullptr ;
2014-03-14 14:13:41 -04:00
CurrentToolIndex = INDEX_NONE ;
// Initialize brushes
InitializeBrushes ( ) ;
CurrentBrush = LandscapeBrushSets [ 0 ] . Brushes [ 0 ] ;
CurrentBrushSetIndex = 0 ;
2014-07-17 12:20:34 -04:00
CurrentToolTarget . LandscapeInfo = nullptr ;
2014-03-14 14:13:41 -04:00
CurrentToolTarget . TargetType = ELandscapeToolTargetType : : Heightmap ;
2014-07-17 12:20:34 -04:00
CurrentToolTarget . LayerInfo = nullptr ;
2014-03-14 14:13:41 -04:00
2014-08-14 10:04:06 -04:00
UISettings = ConstructObject < ULandscapeEditorObject > ( ULandscapeEditorObject : : StaticClass ( ) , GetTransientPackage ( ) , NAME_None , RF_Transactional ) ;
2014-03-14 14:13:41 -04:00
UISettings - > SetParent ( this ) ;
}
/** Destructor */
FEdModeLandscape : : ~ FEdModeLandscape ( )
{
// Destroy tools.
2014-07-17 12:20:34 -04:00
LandscapeTools . Empty ( ) ;
2014-03-14 14:13:41 -04:00
// Destroy brushes
LandscapeBrushSets . Empty ( ) ;
// Clean up Debug Materials
FlushRenderingCommands ( ) ;
GLayerDebugColorMaterial = NULL ;
GSelectionColorMaterial = NULL ;
GSelectionRegionMaterial = NULL ;
GMaskRegionMaterial = NULL ;
GLandscapeBlackTexture = NULL ;
}
/** FGCObject interface */
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : AddReferencedObjects ( FReferenceCollector & Collector )
2014-03-14 14:13:41 -04:00
{
// Call parent implementation
2014-07-17 12:20:34 -04:00
FEdMode : : AddReferencedObjects ( Collector ) ;
2014-03-14 14:13:41 -04:00
Collector . AddReferencedObject ( UISettings ) ;
Collector . AddReferencedObject ( GizmoMaterial ) ;
Collector . AddReferencedObject ( GLayerDebugColorMaterial ) ;
Collector . AddReferencedObject ( GSelectionColorMaterial ) ;
Collector . AddReferencedObject ( GSelectionRegionMaterial ) ;
Collector . AddReferencedObject ( GMaskRegionMaterial ) ;
Collector . AddReferencedObject ( GLandscapeBlackTexture ) ;
}
void FEdModeLandscape : : InitializeToolModes ( )
{
2014-07-17 12:20:34 -04:00
FLandscapeToolMode * ToolMode_Manage = new ( LandscapeToolModes ) FLandscapeToolMode ( TEXT ( " ToolMode_Manage " ) , ELandscapeToolTargetTypeMask : : NA ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " NewLandscape " ) ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " Select " ) ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " AddComponent " ) ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " DeleteComponent " ) ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " MoveToLevel " ) ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " ResizeLandscape " ) ) ;
ToolMode_Manage - > ValidTools . Add ( TEXT ( " Splines " ) ) ;
ToolMode_Manage - > CurrentToolName = TEXT ( " Select " ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
FLandscapeToolMode * ToolMode_Sculpt = new ( LandscapeToolModes ) FLandscapeToolMode ( TEXT ( " ToolMode_Sculpt " ) , ELandscapeToolTargetTypeMask : : Heightmap | ELandscapeToolTargetTypeMask : : Visibility ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Sculpt " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Smooth " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Flatten " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Ramp " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Noise " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Erosion " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " HydraErosion " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Retopologize " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Visibility " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " Mask " ) ) ;
ToolMode_Sculpt - > ValidTools . Add ( TEXT ( " CopyPaste " ) ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
FLandscapeToolMode * ToolMode_Paint = new ( LandscapeToolModes ) FLandscapeToolMode ( TEXT ( " ToolMode_Paint " ) , ELandscapeToolTargetTypeMask : : Weightmap ) ;
ToolMode_Paint - > ValidTools . Add ( TEXT ( " Paint " ) ) ;
ToolMode_Paint - > ValidTools . Add ( TEXT ( " Smooth " ) ) ;
ToolMode_Paint - > ValidTools . Add ( TEXT ( " Flatten " ) ) ;
ToolMode_Paint - > ValidTools . Add ( TEXT ( " Noise " ) ) ;
ToolMode_Paint - > ValidTools . Add ( TEXT ( " Visibility " ) ) ;
2014-03-14 14:13:41 -04:00
}
bool FEdModeLandscape : : UsesToolkits ( ) const
{
return true ;
}
/** FEdMode: Called when the mode is entered */
void FEdModeLandscape : : Enter ( )
{
// Call parent implementation
FEdMode : : Enter ( ) ;
ALandscapeProxy * SelectedLandscape = GEditor - > GetSelectedActors ( ) - > GetTop < ALandscapeProxy > ( ) ;
if ( SelectedLandscape )
{
CurrentToolTarget . LandscapeInfo = SelectedLandscape - > GetLandscapeInfo ( ) ;
GEditor - > SelectNone ( false , true ) ;
GEditor - > SelectActor ( SelectedLandscape , true , false ) ;
}
else
{
GEditor - > SelectNone ( false , true ) ;
}
2014-09-16 16:22:01 -04:00
for ( TActorIterator < ALandscapeGizmoActiveActor > It ( GetWorld ( ) ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
2014-09-16 16:22:01 -04:00
CurrentGizmoActor = * It ;
break ;
2014-03-14 14:13:41 -04:00
}
if ( ! CurrentGizmoActor . IsValid ( ) )
{
CurrentGizmoActor = GetWorld ( ) - > SpawnActor < ALandscapeGizmoActiveActor > ( ) ;
CurrentGizmoActor - > ImportFromClipboard ( ) ;
}
// Update list of landscapes and layers
// For now depends on the SpawnActor() above in order to get the current editor world as edmodes don't get told
UpdateLandscapeList ( ) ;
UpdateTargetList ( ) ;
FEditorSupportDelegates : : WorldChange . AddRaw ( this , & FEdModeLandscape : : OnWorldChange ) ;
UMaterial : : OnMaterialCompilationFinished ( ) . AddRaw ( this , & FEdModeLandscape : : OnMaterialCompilationFinished ) ;
if ( CurrentGizmoActor . IsValid ( ) )
{
CurrentGizmoActor - > SetTargetLandscape ( CurrentToolTarget . LandscapeInfo . Get ( ) ) ;
}
CastChecked < ALandscapeGizmoActiveActor > ( CurrentGizmoActor . Get ( ) ) - > bSnapToLandscapeGrid = UISettings - > bSnapGizmo ;
int32 SquaredDataTex = ALandscapeGizmoActiveActor : : DataTexSize * ALandscapeGizmoActiveActor : : DataTexSize ;
if ( CurrentGizmoActor . IsValid ( ) & & ! CurrentGizmoActor - > GizmoTexture )
{
// Init Gizmo Texture...
CurrentGizmoActor - > GizmoTexture = ConstructObject < UTexture2D > ( UTexture2D : : StaticClass ( ) , GetTransientPackage ( ) , NAME_None , RF_Transient ) ;
if ( CurrentGizmoActor - > GizmoTexture )
{
CurrentGizmoActor - > GizmoTexture - > Source . Init (
ALandscapeGizmoActiveActor : : DataTexSize ,
ALandscapeGizmoActiveActor : : DataTexSize ,
1 ,
1 ,
TSF_G8
) ;
CurrentGizmoActor - > GizmoTexture - > SRGB = false ;
CurrentGizmoActor - > GizmoTexture - > CompressionNone = true ;
CurrentGizmoActor - > GizmoTexture - > MipGenSettings = TMGS_NoMipmaps ;
CurrentGizmoActor - > GizmoTexture - > AddressX = TA_Clamp ;
CurrentGizmoActor - > GizmoTexture - > AddressY = TA_Clamp ;
CurrentGizmoActor - > GizmoTexture - > LODGroup = TEXTUREGROUP_Terrain_Weightmap ;
uint8 * TexData = CurrentGizmoActor - > GizmoTexture - > Source . LockMip ( 0 ) ;
FMemory : : Memset ( TexData , 0 , SquaredDataTex * sizeof ( uint8 ) ) ;
// Restore Sampled Data if exist...
if ( CurrentGizmoActor - > CachedScaleXY > 0.f )
{
2014-07-17 12:20:34 -04:00
int32 SizeX = FMath : : CeilToInt ( CurrentGizmoActor - > CachedWidth / CurrentGizmoActor - > CachedScaleXY ) ;
2014-05-06 06:26:25 -04:00
int32 SizeY = FMath : : CeilToInt ( CurrentGizmoActor - > CachedHeight / CurrentGizmoActor - > CachedScaleXY ) ;
2014-03-14 14:13:41 -04:00
for ( int32 Y = 0 ; Y < CurrentGizmoActor - > SampleSizeY ; + + Y )
{
for ( int32 X = 0 ; X < CurrentGizmoActor - > SampleSizeX ; + + X )
{
float TexX = X * SizeX / CurrentGizmoActor - > SampleSizeX ;
float TexY = Y * SizeY / CurrentGizmoActor - > SampleSizeY ;
2014-05-06 06:26:25 -04:00
int32 LX = FMath : : FloorToInt ( TexX ) ;
int32 LY = FMath : : FloorToInt ( TexY ) ;
2014-03-14 14:13:41 -04:00
float FracX = TexX - LX ;
float FracY = TexY - LY ;
FGizmoSelectData * Data00 = CurrentGizmoActor - > SelectedData . Find ( ALandscape : : MakeKey ( LX , LY ) ) ;
2014-07-17 12:20:34 -04:00
FGizmoSelectData * Data10 = CurrentGizmoActor - > SelectedData . Find ( ALandscape : : MakeKey ( LX + 1 , LY ) ) ;
FGizmoSelectData * Data01 = CurrentGizmoActor - > SelectedData . Find ( ALandscape : : MakeKey ( LX , LY + 1 ) ) ;
FGizmoSelectData * Data11 = CurrentGizmoActor - > SelectedData . Find ( ALandscape : : MakeKey ( LX + 1 , LY + 1 ) ) ;
2014-03-14 14:13:41 -04:00
TexData [ X + Y * ALandscapeGizmoActiveActor : : DataTexSize ] = FMath : : Lerp (
FMath : : Lerp ( Data00 ? Data00 - > Ratio : 0 , Data10 ? Data10 - > Ratio : 0 , FracX ) ,
FMath : : Lerp ( Data01 ? Data01 - > Ratio : 0 , Data11 ? Data11 - > Ratio : 0 , FracX ) ,
FracY
) * 255 ;
}
}
}
CurrentGizmoActor - > GizmoTexture - > Source . UnlockMip ( 0 ) ;
CurrentGizmoActor - > GizmoTexture - > PostEditChange ( ) ;
FlushRenderingCommands ( ) ;
}
}
if ( CurrentGizmoActor . IsValid ( ) & & CurrentGizmoActor - > SampledHeight . Num ( ) ! = SquaredDataTex )
{
CurrentGizmoActor - > SampledHeight . Empty ( SquaredDataTex ) ;
CurrentGizmoActor - > SampledHeight . AddZeroed ( SquaredDataTex ) ;
CurrentGizmoActor - > DataType = LGT_None ;
}
if ( CurrentGizmoActor . IsValid ( ) ) // Update Scene Proxy
{
CurrentGizmoActor - > ReregisterAllComponents ( ) ;
}
GLandscapeEditRenderMode = ELandscapeEditRenderMode : : None ;
GLandscapeEditModeActive = true ;
// Load UI settings from config file
UISettings - > Load ( ) ;
2014-07-25 03:19:01 -04:00
// Initialize current tool prior to creating the landscape toolkit in case it has a dependency on it
if ( LandscapeList . Num ( ) = = 0 )
{
SetCurrentToolMode ( " ToolMode_Manage " , false ) ;
SetCurrentTool ( " NewLandscape " ) ;
}
else
{
if ( CurrentToolMode = = NULL )
{
SetCurrentToolMode ( " ToolMode_Sculpt " , false ) ;
SetCurrentTool ( " Sculpt " ) ;
}
else
{
SetCurrentTool ( CurrentToolMode - > CurrentToolName ) ;
}
}
2014-03-14 14:13:41 -04:00
// Create the landscape editor window
if ( ! Toolkit . IsValid ( ) )
{
// @todo: Remove this assumption when we make modes per level editor instead of global
2014-07-17 12:20:34 -04:00
auto ToolkitHost = FModuleManager : : LoadModuleChecked < FLevelEditorModule > ( " LevelEditor " ) . GetFirstLevelEditor ( ) ;
2014-03-14 14:13:41 -04:00
Toolkit = MakeShareable ( new FLandscapeToolKit ) ;
Toolkit - > Init ( ToolkitHost ) ;
}
// Force real-time viewports. We'll back up the current viewport state so we can restore it when the
// user exits this mode.
const bool bWantRealTime = true ;
const bool bRememberCurrentState = true ;
2014-07-17 12:20:34 -04:00
ForceRealTimeViewports ( bWantRealTime , bRememberCurrentState ) ;
2014-03-14 14:13:41 -04:00
CurrentBrush - > EnterBrush ( ) ;
if ( GizmoBrush )
{
GizmoBrush - > EnterBrush ( ) ;
}
}
/** FEdMode: Called when the mode is exited */
void FEdModeLandscape : : Exit ( )
{
FEditorSupportDelegates : : WorldChange . RemoveRaw ( this , & FEdModeLandscape : : OnWorldChange ) ;
UMaterial : : OnMaterialCompilationFinished ( ) . RemoveRaw ( this , & FEdModeLandscape : : OnMaterialCompilationFinished ) ;
// Restore real-time viewport state if we changed it
const bool bWantRealTime = false ;
const bool bRememberCurrentState = false ;
2014-07-17 12:20:34 -04:00
ForceRealTimeViewports ( bWantRealTime , bRememberCurrentState ) ;
2014-03-14 14:13:41 -04:00
if ( Toolkit . IsValid ( ) )
{
FToolkitManager : : Get ( ) . CloseToolkit ( Toolkit . ToSharedRef ( ) ) ;
Toolkit . Reset ( ) ;
}
CurrentBrush - > LeaveBrush ( ) ;
if ( GizmoBrush )
{
GizmoBrush - > LeaveBrush ( ) ;
}
2014-07-17 12:20:34 -04:00
if ( CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > PreviousBrushIndex = CurrentBrushSetIndex ;
if ( CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > ExitTool ( ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-07-17 12:20:34 -04:00
CurrentTool = NULL ;
2014-03-14 14:13:41 -04:00
// Leave CurrentToolIndex set so we can restore the active tool on re-opening the landscape editor
LandscapeList . Empty ( ) ;
LandscapeTargetList . Empty ( ) ;
// Clear any import landscape data
UISettings - > ClearImportLandscapeData ( ) ;
// Save UI settings to config file
UISettings - > Save ( ) ;
GLandscapeViewMode = ELandscapeViewMode : : Normal ;
GLandscapeEditRenderMode = ELandscapeEditRenderMode : : None ;
GLandscapeEditModeActive = false ;
CurrentGizmoActor = NULL ;
2014-07-17 12:20:34 -04:00
GEditor - > SelectNone ( false , true ) ;
2014-03-14 14:13:41 -04:00
// Clear all GizmoActors if there is no Landscape in World
bool bIsLandscapeExist = false ;
2014-09-16 16:22:01 -04:00
for ( TActorIterator < ALandscapeProxy > It ( GetWorld ( ) ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
2014-09-16 16:22:01 -04:00
bIsLandscapeExist = true ;
break ;
2014-03-14 14:13:41 -04:00
}
if ( ! bIsLandscapeExist )
{
2014-09-16 16:22:01 -04:00
for ( TActorIterator < ALandscapeGizmoActor > It ( GetWorld ( ) ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
2014-09-16 16:22:01 -04:00
GetWorld ( ) - > DestroyActor ( * It , false , false ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-05-20 10:13:41 -04:00
// Redraw one last time to remove any landscape editor stuff from view
GEditor - > RedrawLevelEditingViewports ( ) ;
2014-03-14 14:13:41 -04:00
// Call parent implementation
FEdMode : : Exit ( ) ;
}
/** FEdMode: Called once per frame */
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : Tick ( FEditorViewportClient * ViewportClient , float DeltaTime )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
FEdMode : : Tick ( ViewportClient , DeltaTime ) ;
2014-03-14 14:13:41 -04:00
if ( GEditor - > PlayWorld ! = NULL )
{
return ;
}
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
bool bStaleTargetLandscapeInfo = CurrentToolTarget . LandscapeInfo . IsStale ( ) ;
bool bStaleTargetLandscape = CurrentToolTarget . LandscapeInfo . IsValid ( ) & & CurrentToolTarget . LandscapeInfo - > LandscapeActor . IsStale ( ) ;
2014-07-17 12:20:34 -04:00
2014-03-14 14:13:41 -04:00
if ( bStaleTargetLandscapeInfo | | bStaleTargetLandscape )
{
UpdateLandscapeList ( ) ;
}
if ( CurrentToolTarget . LandscapeInfo . IsValid ( ) )
{
ALandscapeProxy * LandscapeProxy = CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) ;
2014-07-17 12:20:34 -04:00
if ( LandscapeProxy = = NULL | |
2014-03-14 14:13:41 -04:00
LandscapeProxy - > GetLandscapeMaterial ( ) ! = CachedLandscapeMaterial )
{
UpdateTargetList ( ) ;
}
}
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > Tick ( ViewportClient , DeltaTime ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
if ( CurrentBrush )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentBrush - > Tick ( ViewportClient , DeltaTime ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
if ( CurrentBrush ! = GizmoBrush & & CurrentGizmoActor . IsValid ( ) & & GizmoBrush & & ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo ) )
2014-03-14 14:13:41 -04:00
{
GizmoBrush - > Tick ( ViewportClient , DeltaTime ) ;
}
}
}
/** FEdMode: Called when the mouse is moved over the viewport */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : MouseMove ( FEditorViewportClient * ViewportClient , FViewport * Viewport , int32 MouseX , int32 MouseY )
2014-03-14 14:13:41 -04:00
{
2014-04-23 16:38:50 -04:00
if ( bToolActive & & ! Viewport - > KeyState ( EKeys : : LeftMouseButton ) )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-04-23 16:38:50 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > EndTool ( ViewportClient ) ;
2014-04-23 16:38:50 -04:00
bToolActive = false ;
}
}
2014-03-14 14:13:41 -04:00
if ( GEditor - > PlayWorld ! = NULL )
{
return false ;
}
bool Result = false ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool & & CurrentTool - > MouseMove ( ViewportClient , Viewport , MouseX , MouseY ) ;
2014-03-14 14:13:41 -04:00
//ViewportClient->Invalidate( false, false );
}
}
return Result ;
}
bool FEdModeLandscape : : DisallowMouseDeltaTracking ( ) const
{
// We never want to use the mouse delta tracker while painting
return bToolActive ;
}
/**
* Called when the mouse is moved while a window input capture is in effect
*
* @ param InViewportClient Level editor viewport client that captured the mouse input
* @ param InViewport Viewport that captured the mouse input
* @ param InMouseX New mouse cursor X coordinate
* @ param InMouseY New mouse cursor Y coordinate
*
* @ return true if input was handled
*/
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : CapturedMouseMove ( FEditorViewportClient * ViewportClient , FViewport * Viewport , int32 MouseX , int32 MouseY )
2014-03-14 14:13:41 -04:00
{
return MouseMove ( ViewportClient , Viewport , MouseX , MouseY ) ;
}
namespace
{
bool GIsGizmoDragging = false ;
}
/** FEdMode: Called when a mouse button is pressed */
2014-06-18 10:16:16 -04:00
bool FEdModeLandscape : : StartTracking ( FEditorViewportClient * InViewportClient , FViewport * InViewport )
2014-03-14 14:13:41 -04:00
{
if ( CurrentGizmoActor . IsValid ( ) & & CurrentGizmoActor - > IsSelected ( ) & & GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo )
{
GIsGizmoDragging = true ;
return true ;
}
return false ;
}
/** FEdMode: Called when the a mouse button is released */
2014-06-18 10:16:16 -04:00
bool FEdModeLandscape : : EndTracking ( FEditorViewportClient * InViewportClient , FViewport * InViewport )
2014-03-14 14:13:41 -04:00
{
if ( GIsGizmoDragging )
{
GIsGizmoDragging = false ;
return true ;
}
return false ;
}
namespace
{
2014-07-17 12:20:34 -04:00
bool RayIntersectTriangle ( const FVector & Start , const FVector & End , const FVector & A , const FVector & B , const FVector & C , FVector & IntersectPoint )
2014-03-14 14:13:41 -04:00
{
const FVector BA = A - B ;
const FVector CB = B - C ;
const FVector TriNormal = BA ^ CB ;
2014-07-17 12:20:34 -04:00
bool bCollide = FMath : : SegmentPlaneIntersection ( Start , End , FPlane ( A , TriNormal ) , IntersectPoint ) ;
2014-03-14 14:13:41 -04:00
if ( ! bCollide )
{
return false ;
}
FVector BaryCentric = FMath : : ComputeBaryCentric2D ( IntersectPoint , A , B , C ) ;
2014-07-17 12:20:34 -04:00
if ( BaryCentric . X > 0.f & & BaryCentric . Y > 0.f & & BaryCentric . Z > 0.f )
2014-03-14 14:13:41 -04:00
{
return true ;
}
return false ;
}
} ;
/** Trace under the mouse cursor and return the landscape hit and the hit location (in landscape quad space) */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : LandscapeMouseTrace ( FEditorViewportClient * ViewportClient , float & OutHitX , float & OutHitY )
2014-03-14 14:13:41 -04:00
{
int32 MouseX = ViewportClient - > Viewport - > GetMouseX ( ) ;
int32 MouseY = ViewportClient - > Viewport - > GetMouseY ( ) ;
2014-07-17 12:20:34 -04:00
return LandscapeMouseTrace ( ViewportClient , MouseX , MouseY , OutHitX , OutHitY ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : LandscapeMouseTrace ( FEditorViewportClient * ViewportClient , FVector & OutHitLocation )
2014-03-14 14:13:41 -04:00
{
int32 MouseX = ViewportClient - > Viewport - > GetMouseX ( ) ;
int32 MouseY = ViewportClient - > Viewport - > GetMouseY ( ) ;
2014-07-17 12:20:34 -04:00
return LandscapeMouseTrace ( ViewportClient , MouseX , MouseY , OutHitLocation ) ;
2014-03-14 14:13:41 -04:00
}
/** Trace under the specified coordinates and return the landscape hit and the hit location (in landscape quad space) */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : LandscapeMouseTrace ( FEditorViewportClient * ViewportClient , int32 MouseX , int32 MouseY , float & OutHitX , float & OutHitY )
2014-03-14 14:13:41 -04:00
{
FVector HitLocation ;
2014-07-17 12:20:34 -04:00
bool bResult = LandscapeMouseTrace ( ViewportClient , MouseX , MouseY , HitLocation ) ;
2014-03-14 14:13:41 -04:00
OutHitX = HitLocation . X ;
OutHitY = HitLocation . Y ;
return bResult ;
}
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : LandscapeMouseTrace ( FEditorViewportClient * ViewportClient , int32 MouseX , int32 MouseY , FVector & OutHitLocation )
2014-03-14 14:13:41 -04:00
{
// Cache a copy of the world pointer
UWorld * World = ViewportClient - > GetWorld ( ) ;
2014-07-17 12:20:34 -04:00
// Compute a world space ray from the screen space mouse coordinates
FSceneViewFamilyContext ViewFamily ( FSceneViewFamilyContext : : ConstructionValues ( ViewportClient - > Viewport , ViewportClient - > GetScene ( ) , ViewportClient - > EngineShowFlags )
. SetRealtimeUpdate ( ViewportClient - > IsRealtime ( ) ) ) ;
FSceneView * View = ViewportClient - > CalcSceneView ( & ViewFamily ) ;
FViewportCursorLocation MouseViewportRay ( View , ViewportClient , MouseX , MouseY ) ;
2014-03-14 14:13:41 -04:00
FVector Start = MouseViewportRay . GetOrigin ( ) ;
FVector End = Start + WORLD_MAX * MouseViewportRay . GetDirection ( ) ;
static FName TraceTag = FName ( TEXT ( " LandscapeMouseTrace " ) ) ;
TArray < FHitResult > Results ;
2014-04-02 18:09:23 -04:00
// Each landscape component has 2 collision shapes, 1 of them is specific to landscape editor
// Trace only ECC_Visibility channel, so we do hit only Editor specific shape
World - > LineTraceMulti ( Results , Start , End , FCollisionQueryParams ( TraceTag , true ) , FCollisionObjectQueryParams ( ECollisionChannel : : ECC_Visibility ) ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
for ( int32 i = 0 ; i < Results . Num ( ) ; i + + )
2014-03-14 14:13:41 -04:00
{
const FHitResult & Hit = Results [ i ] ;
ULandscapeHeightfieldCollisionComponent * CollisionComponent = Cast < ULandscapeHeightfieldCollisionComponent > ( Hit . Component . Get ( ) ) ;
2014-07-17 12:20:34 -04:00
if ( CollisionComponent )
2014-03-14 14:13:41 -04:00
{
ALandscapeProxy * HitLandscape = CollisionComponent - > GetLandscapeProxy ( ) ;
2014-07-17 12:20:34 -04:00
if ( HitLandscape & &
CurrentToolTarget . LandscapeInfo . IsValid ( ) & &
CurrentToolTarget . LandscapeInfo - > LandscapeGuid = = HitLandscape - > GetLandscapeGuid ( ) )
2014-03-14 14:13:41 -04:00
{
OutHitLocation = HitLandscape - > LandscapeActorToWorld ( ) . InverseTransformPosition ( Hit . Location ) ;
return true ;
}
}
}
// For Add Landscape Component Mode
2014-07-17 12:20:34 -04:00
if ( CurrentTool - > GetToolName ( ) = = FName ( " AddComponent " ) & &
2014-03-14 14:13:41 -04:00
CurrentToolTarget . LandscapeInfo . IsValid ( ) )
{
bool bCollided = false ;
FVector IntersectPoint ;
LandscapeRenderAddCollision = NULL ;
// Need to optimize collision for AddLandscapeComponent...?
2014-07-17 12:20:34 -04:00
for ( auto It = CurrentToolTarget . LandscapeInfo - > XYtoAddCollisionMap . CreateIterator ( ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
FLandscapeAddCollision & AddCollision = It . Value ( ) ;
// Triangle 1
2014-07-17 12:20:34 -04:00
bCollided = RayIntersectTriangle ( Start , End , AddCollision . Corners [ 0 ] , AddCollision . Corners [ 3 ] , AddCollision . Corners [ 1 ] , IntersectPoint ) ;
2014-03-14 14:13:41 -04:00
if ( bCollided )
{
LandscapeRenderAddCollision = & AddCollision ;
break ;
}
// Triangle 2
2014-07-17 12:20:34 -04:00
bCollided = RayIntersectTriangle ( Start , End , AddCollision . Corners [ 0 ] , AddCollision . Corners [ 2 ] , AddCollision . Corners [ 3 ] , IntersectPoint ) ;
2014-03-14 14:13:41 -04:00
if ( bCollided )
{
LandscapeRenderAddCollision = & AddCollision ;
break ;
}
}
2014-07-17 12:20:34 -04:00
if ( bCollided & &
2014-03-14 14:13:41 -04:00
CurrentToolTarget . LandscapeInfo . IsValid ( ) )
{
ALandscapeProxy * Proxy = CurrentToolTarget . LandscapeInfo . Get ( ) - > GetCurrentLevelLandscapeProxy ( true ) ;
if ( Proxy )
{
OutHitLocation = Proxy - > LandscapeActorToWorld ( ) . InverseTransformPosition ( IntersectPoint ) ;
return true ;
}
}
}
2014-07-17 12:20:34 -04:00
2014-03-14 14:13:41 -04:00
return false ;
}
2014-06-18 10:16:16 -04:00
bool FEdModeLandscape : : LandscapePlaneTrace ( FEditorViewportClient * ViewportClient , const FPlane & Plane , FVector & OutHitLocation )
2014-03-14 14:13:41 -04:00
{
int32 MouseX = ViewportClient - > Viewport - > GetMouseX ( ) ;
int32 MouseY = ViewportClient - > Viewport - > GetMouseY ( ) ;
return LandscapePlaneTrace ( ViewportClient , MouseX , MouseY , Plane , OutHitLocation ) ;
}
2014-06-18 10:16:16 -04:00
bool FEdModeLandscape : : LandscapePlaneTrace ( FEditorViewportClient * ViewportClient , int32 MouseX , int32 MouseY , const FPlane & Plane , FVector & OutHitLocation )
2014-03-14 14:13:41 -04:00
{
// Cache a copy of the world pointer
UWorld * World = ViewportClient - > GetWorld ( ) ;
// Compute a world space ray from the screen space mouse coordinates
FSceneViewFamilyContext ViewFamily ( FSceneViewFamily : : ConstructionValues (
2014-07-17 12:20:34 -04:00
ViewportClient - > Viewport ,
2014-03-14 14:13:41 -04:00
ViewportClient - > GetScene ( ) ,
2014-07-17 12:20:34 -04:00
ViewportClient - > EngineShowFlags )
. SetRealtimeUpdate ( ViewportClient - > IsRealtime ( ) ) ) ;
FSceneView * View = ViewportClient - > CalcSceneView ( & ViewFamily ) ;
FViewportCursorLocation MouseViewportRay ( View , ViewportClient , MouseX , MouseY ) ;
2014-03-14 14:13:41 -04:00
FVector Start = MouseViewportRay . GetOrigin ( ) ;
FVector End = Start + WORLD_MAX * MouseViewportRay . GetDirection ( ) ;
OutHitLocation = FMath : : LinePlaneIntersection ( Start , End , Plane ) ;
return true ;
}
namespace
{
const int32 SelectionSizeThresh = 2 * 256 * 256 ;
FORCEINLINE bool IsSlowSelect ( ULandscapeInfo * LandscapeInfo )
{
if ( LandscapeInfo )
{
int32 MinX = MAX_int32 , MinY = MAX_int32 , MaxX = MIN_int32 , MaxY = MIN_int32 ;
LandscapeInfo - > GetSelectedExtent ( MinX , MinY , MaxX , MaxY ) ;
2014-07-17 12:20:34 -04:00
return ( MinX ! = MAX_int32 & & ( ( MaxX - MinX ) * ( MaxY - MinY ) ) ) ;
2014-03-14 14:13:41 -04:00
}
return false ;
}
} ;
EEditAction : : Type FEdModeLandscape : : GetActionEditDuplicate ( )
{
EEditAction : : Type Result = EEditAction : : Skip ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > GetActionEditDuplicate ( ) ;
2014-03-14 14:13:41 -04:00
}
}
return Result ;
}
EEditAction : : Type FEdModeLandscape : : GetActionEditDelete ( )
{
EEditAction : : Type Result = EEditAction : : Skip ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > GetActionEditDelete ( ) ;
2014-03-14 14:13:41 -04:00
}
if ( Result = = EEditAction : : Skip )
{
// Prevent deleting Gizmo during LandscapeEdMode
if ( CurrentGizmoActor . IsValid ( ) )
{
if ( CurrentGizmoActor - > IsSelected ( ) )
{
if ( GEditor - > GetSelectedActors ( ) - > Num ( ) > 1 )
{
GEditor - > GetSelectedActors ( ) - > Deselect ( CurrentGizmoActor . Get ( ) ) ;
Result = EEditAction : : Skip ;
}
else
{
Result = EEditAction : : Halt ;
}
}
}
}
}
return Result ;
}
EEditAction : : Type FEdModeLandscape : : GetActionEditCut ( )
{
EEditAction : : Type Result = EEditAction : : Skip ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > GetActionEditCut ( ) ;
2014-03-14 14:13:41 -04:00
}
}
if ( Result = = EEditAction : : Skip )
{
// Special case: we don't want the 'normal' cut operation to be possible at all while in this mode,
// so we need to stop evaluating the others in-case they come back as true.
return EEditAction : : Halt ;
}
return Result ;
}
EEditAction : : Type FEdModeLandscape : : GetActionEditCopy ( )
{
EEditAction : : Type Result = EEditAction : : Skip ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > GetActionEditCopy ( ) ;
2014-03-14 14:13:41 -04:00
}
if ( Result = = EEditAction : : Skip )
{
if ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo | | GLandscapeEditRenderMode & ( ELandscapeEditRenderMode : : Select ) )
{
if ( CurrentGizmoActor . IsValid ( ) & & GizmoBrush & & CurrentGizmoActor - > TargetLandscapeInfo )
{
Result = EEditAction : : Process ;
}
}
}
}
return Result ;
}
EEditAction : : Type FEdModeLandscape : : GetActionEditPaste ( )
{
EEditAction : : Type Result = EEditAction : : Skip ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > GetActionEditPaste ( ) ;
2014-03-14 14:13:41 -04:00
}
if ( Result = = EEditAction : : Skip )
{
if ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo | | GLandscapeEditRenderMode & ( ELandscapeEditRenderMode : : Select ) )
{
if ( CurrentGizmoActor . IsValid ( ) & & GizmoBrush & & CurrentGizmoActor - > TargetLandscapeInfo )
{
Result = EEditAction : : Process ;
}
}
}
}
return Result ;
}
bool FEdModeLandscape : : ProcessEditDuplicate ( )
{
if ( GEditor - > PlayWorld ! = NULL )
{
return true ;
}
bool Result = false ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > ProcessEditDuplicate ( ) ;
2014-03-14 14:13:41 -04:00
}
}
return Result ;
}
bool FEdModeLandscape : : ProcessEditDelete ( )
{
if ( GEditor - > PlayWorld ! = NULL )
{
return true ;
}
bool Result = false ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > ProcessEditDelete ( ) ;
2014-03-14 14:13:41 -04:00
}
}
return Result ;
}
bool FEdModeLandscape : : ProcessEditCut ( )
{
if ( GEditor - > PlayWorld ! = NULL )
{
return true ;
}
bool Result = false ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > ProcessEditCut ( ) ;
2014-03-14 14:13:41 -04:00
}
}
return Result ;
}
bool FEdModeLandscape : : ProcessEditCopy ( )
{
if ( GEditor - > PlayWorld ! = NULL )
{
return true ;
}
bool Result = false ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > ProcessEditCopy ( ) ;
2014-03-14 14:13:41 -04:00
}
if ( ! Result )
{
bool IsSlowTask = IsSlowSelect ( CurrentGizmoActor - > TargetLandscapeInfo ) ;
if ( IsSlowTask )
{
2014-07-17 12:20:34 -04:00
GWarn - > BeginSlowTask ( LOCTEXT ( " BeginFitGizmoAndCopy " , " Fit Gizmo to Selected Region and Copy Data... " ) , true ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
FScopedTransaction Transaction ( LOCTEXT ( " LandscapeGizmo_Copy " , " Copy landscape data to Gizmo " ) ) ;
2014-03-14 14:13:41 -04:00
CurrentGizmoActor - > Modify ( ) ;
2014-07-17 12:20:34 -04:00
CurrentGizmoActor - > FitToSelection ( ) ;
2014-03-14 14:13:41 -04:00
CopyDataToGizmo ( ) ;
2014-07-17 12:20:34 -04:00
SetCurrentTool ( FName ( " CopyPaste " ) ) ;
2014-03-14 14:13:41 -04:00
if ( IsSlowTask )
{
GWarn - > EndSlowTask ( ) ;
}
Result = true ;
}
}
return Result ;
}
bool FEdModeLandscape : : ProcessEditPaste ( )
{
if ( GEditor - > PlayWorld ! = NULL )
{
return true ;
}
bool Result = false ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL & & CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
Result = CurrentTool - > ProcessEditPaste ( ) ;
2014-03-14 14:13:41 -04:00
}
if ( ! Result )
{
bool IsSlowTask = IsSlowSelect ( CurrentGizmoActor - > TargetLandscapeInfo ) ;
if ( IsSlowTask )
{
2014-07-17 12:20:34 -04:00
GWarn - > BeginSlowTask ( LOCTEXT ( " BeginPasteGizmoDataTask " , " Paste Gizmo Data... " ) , true ) ;
2014-03-14 14:13:41 -04:00
}
PasteDataFromGizmo ( ) ;
2014-07-17 12:20:34 -04:00
SetCurrentTool ( FName ( " CopyPaste " ) ) ;
2014-03-14 14:13:41 -04:00
if ( IsSlowTask )
{
GWarn - > EndSlowTask ( ) ;
}
Result = true ;
}
}
return Result ;
}
2014-06-18 10:16:16 -04:00
bool FEdModeLandscape : : HandleClick ( FEditorViewportClient * InViewportClient , HHitProxy * HitProxy , const FViewportClick & Click )
2014-03-14 14:13:41 -04:00
{
if ( GEditor - > PlayWorld ! = NULL )
{
return false ;
}
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
return false ;
}
// Override Click Input for Splines Tool
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & CurrentTool - > HandleClick ( HitProxy , Click ) )
2014-03-14 14:13:41 -04:00
{
return true ;
}
return false ;
}
/** FEdMode: Called when a key is pressed */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : InputKey ( FEditorViewportClient * ViewportClient , FViewport * Viewport , FKey Key , EInputEvent Event )
2014-03-14 14:13:41 -04:00
{
if ( GEditor - > PlayWorld ! = NULL )
{
return false ;
}
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
if ( Key = = EKeys : : LeftMouseButton )
{
// Press mouse button
if ( Event = = IE_Pressed & & ! IsAltDown ( Viewport ) )
{
// See if we clicked on a new landscape handle..
int32 HitX = Viewport - > GetMouseX ( ) ;
int32 HitY = Viewport - > GetMouseY ( ) ;
HHitProxy * HitProxy = Viewport - > GetHitProxy ( HitX , HitY ) ;
if ( HitProxy )
{
2014-07-17 12:20:34 -04:00
if ( HitProxy - > IsA ( HNewLandscapeGrabHandleProxy : : StaticGetType ( ) ) )
2014-03-14 14:13:41 -04:00
{
HNewLandscapeGrabHandleProxy * EdgeProxy = ( HNewLandscapeGrabHandleProxy * ) HitProxy ;
DraggingEdge = EdgeProxy - > Edge ;
DraggingEdge_Remainder = 0 ;
2014-06-18 10:16:16 -04:00
return false ; // false to let FEditorViewportClient.InputKey start mouse tracking and enable InputDelta() so we can use it
2014-03-14 14:13:41 -04:00
}
}
}
else if ( Event = = IE_Released )
{
if ( DraggingEdge )
{
DraggingEdge = ELandscapeEdge : : None ;
DraggingEdge_Remainder = 0 ;
2014-06-18 10:16:16 -04:00
return false ; // false to let FEditorViewportClient.InputKey end mouse tracking
2014-03-14 14:13:41 -04:00
}
}
}
}
else
{
// Override Key Input for Selection Brush
2014-07-17 12:20:34 -04:00
if ( CurrentBrush & & CurrentBrush - > InputKey ( ViewportClient , Viewport , Key , Event ) = = true )
2014-03-14 14:13:41 -04:00
{
return true ;
}
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & CurrentTool - > InputKey ( ViewportClient , Viewport , Key , Event ) = = true )
2014-03-14 14:13:41 -04:00
{
return true ;
}
2014-09-08 10:45:50 -04:00
if ( Key = = EKeys : : LeftMouseButton & & Event = = IE_Pressed )
2014-03-14 14:13:41 -04:00
{
2014-09-08 10:45:50 -04:00
// Only activate tool if we're not already moving the camera and we're not trying to drag a transform widget
// Not using "if (!ViewportClient->IsMovingCamera())" because it's wrong in ortho viewports :D
if ( ! Viewport - > KeyState ( EKeys : : MiddleMouseButton ) & & ! Viewport - > KeyState ( EKeys : : RightMouseButton ) & & ! IsAltDown ( Viewport ) & & ViewportClient - > GetCurrentWidgetAxis ( ) = = EAxisList : : None )
2014-03-14 14:13:41 -04:00
{
2014-07-28 05:08:15 -04:00
if ( CurrentTool & & ( CurrentTool - > GetSupportedTargetTypes ( ) = = ELandscapeToolTargetTypeMask : : NA | | CurrentToolTarget . TargetType ! = ELandscapeToolTargetType : : Invalid ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
FVector HitLocation ;
if ( LandscapeMouseTrace ( ViewportClient , HitLocation ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Weightmap & & CurrentToolTarget . LayerInfo = = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok ,
NSLOCTEXT ( " UnrealEd " , " LandscapeNeedToCreateLayerInfo " , " This layer has no layer info assigned yet. You must create or assign a layer info before you can paint this layer. " ) ) ;
// TODO: FName to LayerInfo: do we want to create the layer info here?
//if (FMessageDialog::Open(EAppMsgType::YesNo, NSLOCTEXT("UnrealEd", "LandscapeNeedToCreateLayerInfo", "This layer has no layer info assigned yet. You must create or assign a layer info before you can paint this layer.")) == EAppReturnType::Yes)
//{
// CurrentToolTarget.LandscapeInfo->LandscapeProxy->CreateLayerInfo(*CurrentToolTarget.PlaceholderLayerName.ToString());
//}
}
else
{
bToolActive = CurrentTool - > BeginTool ( ViewportClient , CurrentToolTarget , HitLocation ) ;
2014-10-01 08:18:23 -04:00
return bToolActive ;
2014-03-14 14:13:41 -04:00
}
}
}
return true ;
}
}
2014-09-08 10:45:50 -04:00
if ( Key = = EKeys : : LeftMouseButton )
2014-03-14 14:13:41 -04:00
{
2014-09-08 10:45:50 -04:00
if ( Event = = IE_Released & & CurrentTool & & bToolActive )
2014-03-14 14:13:41 -04:00
{
//Set the cursor position to that of the slate cursor so it wont snap back
Viewport - > SetPreCaptureMousePosFromSlateCursor ( ) ;
2014-07-17 12:20:34 -04:00
CurrentTool - > EndTool ( ViewportClient ) ;
2014-03-14 14:13:41 -04:00
bToolActive = false ;
2014-09-08 10:45:50 -04:00
return true ;
2014-03-14 14:13:41 -04:00
}
}
// Change Brush Size
2014-07-17 12:20:34 -04:00
if ( ( Event = = IE_Pressed | | Event = = IE_Repeat ) & & ( Key = = EKeys : : LeftBracket | | Key = = EKeys : : RightBracket ) )
2014-03-14 14:13:41 -04:00
{
if ( CurrentBrush - > GetBrushType ( ) = = FLandscapeBrush : : BT_Component )
{
int32 Radius = UISettings - > BrushComponentSize ;
if ( Key = = EKeys : : LeftBracket )
{
- - Radius ;
}
else
{
+ + Radius ;
}
Radius = ( int32 ) FMath : : Clamp ( Radius , 1 , 64 ) ;
UISettings - > BrushComponentSize = Radius ;
}
else
{
float Radius = UISettings - > BrushRadius ;
float SliderMin = 0.f ;
float SliderMax = 8192.f ;
float LogPosition = FMath : : Clamp ( Radius / SliderMax , 0.0f , 1.0f ) ;
float Diff = 0.05f ; //6.f / SliderMax;
if ( Key = = EKeys : : LeftBracket )
{
Diff = - Diff ;
}
2014-07-17 12:20:34 -04:00
float NewValue = Radius * ( 1.f + Diff ) ;
2014-03-14 14:13:41 -04:00
if ( Key = = EKeys : : LeftBracket )
{
NewValue = FMath : : Min ( NewValue , Radius - 1.f ) ;
}
else
{
NewValue = FMath : : Max ( NewValue , Radius + 1.f ) ;
}
NewValue = ( int32 ) FMath : : Clamp ( NewValue , SliderMin , SliderMax ) ;
// convert from Exp scale to linear scale
//float LinearPosition = 1.0f - FMath::Pow(1.0f - LogPosition, 1.0f / 3.0f);
//LinearPosition = FMath::Clamp(LinearPosition + Diff, 0.f, 1.f);
//float NewValue = FMath::Clamp((1.0f - FMath::Pow(1.0f - LinearPosition, 3.f)) * SliderMax, SliderMin, SliderMax);
//float NewValue = FMath::Clamp((SliderMax - SliderMin) * LinearPosition + SliderMin, SliderMin, SliderMax);
UISettings - > BrushRadius = NewValue ;
}
return true ;
}
// Prev tool
2014-07-17 12:20:34 -04:00
if ( Event = = IE_Pressed & & Key = = EKeys : : Comma )
2014-03-14 14:13:41 -04:00
{
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & bToolActive )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > EndTool ( ViewportClient ) ;
2014-03-14 14:13:41 -04:00
bToolActive = false ;
}
2014-07-17 12:20:34 -04:00
int32 OldToolIndex = CurrentToolMode - > ValidTools . Find ( CurrentTool - > GetToolName ( ) ) ;
2014-03-14 14:13:41 -04:00
int32 NewToolIndex = FMath : : Max ( OldToolIndex - 1 , 0 ) ;
2014-07-17 12:20:34 -04:00
SetCurrentTool ( CurrentToolMode - > ValidTools [ NewToolIndex ] ) ;
2014-03-14 14:13:41 -04:00
return true ;
}
// Next tool
2014-07-17 12:20:34 -04:00
if ( Event = = IE_Pressed & & Key = = EKeys : : Period )
2014-03-14 14:13:41 -04:00
{
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & bToolActive )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > EndTool ( ViewportClient ) ;
2014-03-14 14:13:41 -04:00
bToolActive = false ;
}
2014-07-17 12:20:34 -04:00
int32 OldToolIndex = CurrentToolMode - > ValidTools . Find ( CurrentTool - > GetToolName ( ) ) ;
int32 NewToolIndex = FMath : : Min ( OldToolIndex + 1 , CurrentToolMode - > ValidTools . Num ( ) - 1 ) ;
SetCurrentTool ( CurrentToolMode - > ValidTools [ NewToolIndex ] ) ;
2014-03-14 14:13:41 -04:00
return true ;
}
}
return false ;
}
/** FEdMode: Called when mouse drag input is applied */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : InputDelta ( FEditorViewportClient * InViewportClient , FViewport * InViewport , FVector & InDrag , FRotator & InRot , FVector & InScale )
2014-03-14 14:13:41 -04:00
{
if ( GEditor - > PlayWorld ! = NULL )
{
return false ;
}
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
if ( InViewportClient - > GetCurrentWidgetAxis ( ) ! = EAxisList : : None )
{
FVector DeltaScale = InScale ;
DeltaScale . X = DeltaScale . Y = ( FMath : : Abs ( InScale . X ) > FMath : : Abs ( InScale . Y ) ) ? InScale . X : InScale . Y ;
2014-08-14 10:04:06 -04:00
UISettings - > Modify ( ) ;
2014-03-14 14:13:41 -04:00
UISettings - > NewLandscape_Location + = InDrag ;
UISettings - > NewLandscape_Rotation + = InRot ;
UISettings - > NewLandscape_Scale + = DeltaScale ;
return true ;
}
else if ( DraggingEdge ! = ELandscapeEdge : : None )
{
FVector HitLocation ;
LandscapePlaneTrace ( InViewportClient , FPlane ( UISettings - > NewLandscape_Location , FVector ( 0 , 0 , 1 ) ) , HitLocation ) ;
FTransform Transform ( UISettings - > NewLandscape_Rotation , UISettings - > NewLandscape_Location , UISettings - > NewLandscape_Scale * UISettings - > NewLandscape_QuadsPerSection * UISettings - > NewLandscape_SectionsPerComponent ) ;
HitLocation = Transform . InverseTransformPosition ( HitLocation ) ;
2014-08-14 10:04:06 -04:00
UISettings - > Modify ( ) ;
2014-03-14 14:13:41 -04:00
switch ( DraggingEdge )
{
case ELandscapeEdge : : X_Negative :
case ELandscapeEdge : : X_Negative_Y_Negative :
case ELandscapeEdge : : X_Negative_Y_Positive :
2014-07-17 12:20:34 -04:00
{
const int32 InitialComponentCountX = UISettings - > NewLandscape_ComponentCount . X ;
const int32 Delta = FMath : : RoundToInt ( HitLocation . X + ( float ) InitialComponentCountX / 2 ) ;
UISettings - > NewLandscape_ComponentCount . X = InitialComponentCountX - Delta ;
UISettings - > NewLandscape_ClampSize ( ) ;
const int32 ActualDelta = UISettings - > NewLandscape_ComponentCount . X - InitialComponentCountX ;
UISettings - > NewLandscape_Location - = Transform . TransformVector ( FVector ( ( ( float ) ActualDelta / 2 ) , 0 , 0 ) ) ;
}
2014-03-14 14:13:41 -04:00
break ;
case ELandscapeEdge : : X_Positive :
case ELandscapeEdge : : X_Positive_Y_Negative :
case ELandscapeEdge : : X_Positive_Y_Positive :
2014-07-17 12:20:34 -04:00
{
const int32 InitialComponentCountX = UISettings - > NewLandscape_ComponentCount . X ;
int32 Delta = FMath : : RoundToInt ( HitLocation . X - ( float ) InitialComponentCountX / 2 ) ;
UISettings - > NewLandscape_ComponentCount . X = InitialComponentCountX + Delta ;
UISettings - > NewLandscape_ClampSize ( ) ;
const int32 ActualDelta = UISettings - > NewLandscape_ComponentCount . X - InitialComponentCountX ;
UISettings - > NewLandscape_Location + = Transform . TransformVector ( FVector ( ( ( float ) ActualDelta / 2 ) , 0 , 0 ) ) ;
}
2014-03-14 14:13:41 -04:00
break ;
}
switch ( DraggingEdge )
{
case ELandscapeEdge : : Y_Negative :
case ELandscapeEdge : : X_Negative_Y_Negative :
case ELandscapeEdge : : X_Positive_Y_Negative :
2014-07-17 12:20:34 -04:00
{
const int32 InitialComponentCountY = UISettings - > NewLandscape_ComponentCount . Y ;
int32 Delta = FMath : : RoundToInt ( HitLocation . Y + ( float ) InitialComponentCountY / 2 ) ;
UISettings - > NewLandscape_ComponentCount . Y = InitialComponentCountY - Delta ;
UISettings - > NewLandscape_ClampSize ( ) ;
const int32 ActualDelta = UISettings - > NewLandscape_ComponentCount . Y - InitialComponentCountY ;
UISettings - > NewLandscape_Location - = Transform . TransformVector ( FVector ( 0 , ( float ) ActualDelta / 2 , 0 ) ) ;
}
2014-03-14 14:13:41 -04:00
break ;
case ELandscapeEdge : : Y_Positive :
case ELandscapeEdge : : X_Negative_Y_Positive :
case ELandscapeEdge : : X_Positive_Y_Positive :
2014-07-17 12:20:34 -04:00
{
const int32 InitialComponentCountY = UISettings - > NewLandscape_ComponentCount . Y ;
int32 Delta = FMath : : RoundToInt ( HitLocation . Y - ( float ) InitialComponentCountY / 2 ) ;
UISettings - > NewLandscape_ComponentCount . Y = InitialComponentCountY + Delta ;
UISettings - > NewLandscape_ClampSize ( ) ;
const int32 ActualDelta = UISettings - > NewLandscape_ComponentCount . Y - InitialComponentCountY ;
UISettings - > NewLandscape_Location + = Transform . TransformVector ( FVector ( 0 , ( float ) ActualDelta / 2 , 0 ) ) ;
}
2014-03-14 14:13:41 -04:00
break ;
}
return true ;
}
}
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & CurrentTool - > InputDelta ( InViewportClient , InViewport , InDrag , InRot , InScale ) )
2014-03-14 14:13:41 -04:00
{
return true ;
}
return false ;
}
void FEdModeLandscape : : SetCurrentToolMode ( FName ToolModeName , bool bRestoreCurrentTool /*= true*/ )
{
if ( CurrentToolMode = = NULL | | ToolModeName ! = CurrentToolMode - > ToolModeName )
{
for ( int32 i = 0 ; i < LandscapeToolModes . Num ( ) ; + + i )
{
if ( LandscapeToolModes [ i ] . ToolModeName = = ToolModeName )
{
CurrentToolMode = & LandscapeToolModes [ i ] ;
if ( bRestoreCurrentTool )
{
2014-07-17 12:20:34 -04:00
if ( CurrentToolMode - > CurrentToolName = = NAME_None )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentToolMode - > CurrentToolName = CurrentToolMode - > ValidTools [ 0 ] ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
SetCurrentTool ( CurrentToolMode - > CurrentToolName ) ;
2014-03-14 14:13:41 -04:00
}
break ;
}
}
}
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : SetCurrentTool ( FName ToolName )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
// Several tools have identically named versions for sculpting and painting
// Prefer the one with the same target type as the current mode
int32 BackupToolIndex = INDEX_NONE ;
int32 ToolIndex = INDEX_NONE ;
for ( int32 i = 0 ; i < LandscapeTools . Num ( ) ; + + i )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
FLandscapeTool * Tool = LandscapeTools [ i ] . Get ( ) ;
if ( ToolName = = Tool - > GetToolName ( ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( ( Tool - > GetSupportedTargetTypes ( ) & CurrentToolMode - > SupportedTargetTypes ) ! = 0 )
{
ToolIndex = i ;
break ;
}
else if ( BackupToolIndex = = INDEX_NONE )
{
BackupToolIndex = i ;
}
2014-03-14 14:13:41 -04:00
}
}
2014-07-17 12:20:34 -04:00
if ( ToolIndex = = INDEX_NONE )
{
checkf ( BackupToolIndex ! = INDEX_NONE , TEXT ( " Tool '%s' not found, please check name is correct! " ) , * ToolName . ToString ( ) ) ;
ToolIndex = BackupToolIndex ;
}
check ( ToolIndex ! = INDEX_NONE ) ;
2014-03-14 14:13:41 -04:00
SetCurrentTool ( ToolIndex ) ;
}
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : SetCurrentTool ( int32 ToolIndex )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > PreviousBrushIndex = CurrentBrushSetIndex ;
if ( CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > ExitTool ( ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-07-17 12:20:34 -04:00
CurrentToolIndex = LandscapeTools . IsValidIndex ( ToolIndex ) ? ToolIndex : 0 ;
CurrentTool = LandscapeTools [ CurrentToolIndex ] . Get ( ) ;
if ( ! CurrentToolMode - > ValidTools . Contains ( CurrentTool - > GetToolName ( ) ) )
2014-03-14 14:13:41 -04:00
{
// if tool isn't valid for this mode then automatically switch modes
// this mostly happens with shortcut keys
bool bFoundValidMode = false ;
for ( int32 i = 0 ; i < LandscapeToolModes . Num ( ) ; + + i )
{
2014-07-17 12:20:34 -04:00
if ( LandscapeToolModes [ i ] . ValidTools . Contains ( CurrentTool - > GetToolName ( ) ) )
2014-03-14 14:13:41 -04:00
{
SetCurrentToolMode ( LandscapeToolModes [ i ] . ToolModeName , false ) ;
bFoundValidMode = true ;
break ;
}
}
check ( bFoundValidMode ) ;
}
2014-07-17 12:20:34 -04:00
// Set target type appropriate for tool
if ( CurrentTool - > GetSupportedTargetTypes ( ) = = ELandscapeToolTargetTypeMask : : NA )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentToolTarget . TargetType = ELandscapeToolTargetType : : Invalid ;
CurrentToolTarget . LayerInfo = nullptr ;
CurrentToolTarget . LayerName = NAME_None ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-17 12:20:34 -04:00
const uint8 TargetTypeMask = CurrentToolMode - > SupportedTargetTypes & CurrentTool - > GetSupportedTargetTypes ( ) ;
checkSlow ( TargetTypeMask ! = 0 ) ;
if ( ( TargetTypeMask & ELandscapeToolTargetTypeMask : : FromType ( CurrentToolTarget . TargetType ) ) = = 0 )
{
auto filter = [ TargetTypeMask ] ( const TSharedRef < FLandscapeTargetListInfo > & Target ) { return ( TargetTypeMask & ELandscapeToolTargetTypeMask : : FromType ( Target - > TargetType ) ) ! = 0 ; } ;
const TSharedRef < FLandscapeTargetListInfo > * Target = LandscapeTargetList . FindByPredicate ( filter ) ;
if ( Target ! = nullptr )
{
check ( CurrentToolTarget . LandscapeInfo = = ( * Target ) - > LandscapeInfo ) ;
CurrentToolTarget . TargetType = ( * Target ) - > TargetType ;
CurrentToolTarget . LayerInfo = ( * Target ) - > LayerInfoObj ;
CurrentToolTarget . LayerName = ( * Target ) - > LayerName ;
}
else // can happen with for example paint tools if there are no paint layers defined
{
CurrentToolTarget . TargetType = ELandscapeToolTargetType : : Invalid ;
CurrentToolTarget . LayerInfo = nullptr ;
CurrentToolTarget . LayerName = NAME_None ;
}
}
}
if ( CurrentTool )
{
CurrentTool - > EnterTool ( ) ;
CurrentTool - > SetEditRenderType ( ) ;
//bool MaskEnabled = CurrentTool->SupportsMask() && CurrentToolTarget.LandscapeInfo.IsValid() && CurrentToolTarget.LandscapeInfo->SelectedRegion.Num();
}
CurrentToolMode - > CurrentToolName = CurrentTool - > GetToolName ( ) ;
// Set Brush
if ( ! LandscapeBrushSets . IsValidIndex ( CurrentTool - > PreviousBrushIndex ) )
{
SetCurrentBrushSet ( CurrentTool - > ValidBrushes [ 0 ] ) ;
}
else
{
SetCurrentBrushSet ( CurrentTool - > PreviousBrushIndex ) ;
2014-03-14 14:13:41 -04:00
}
// Update GizmoActor Landscape Target (is this necessary?)
if ( CurrentGizmoActor . IsValid ( ) & & CurrentToolTarget . LandscapeInfo . IsValid ( ) )
{
CurrentGizmoActor - > SetTargetLandscape ( CurrentToolTarget . LandscapeInfo . Get ( ) ) ;
}
if ( Toolkit . IsValid ( ) )
{
StaticCastSharedPtr < FLandscapeToolKit > ( Toolkit ) - > NotifyToolChanged ( ) ;
}
}
void FEdModeLandscape : : SetCurrentBrushSet ( FName BrushSetName )
{
for ( int32 BrushIndex = 0 ; BrushIndex < LandscapeBrushSets . Num ( ) ; BrushIndex + + )
{
if ( BrushSetName = = LandscapeBrushSets [ BrushIndex ] . BrushSetName )
{
SetCurrentBrushSet ( BrushIndex ) ;
return ;
}
}
}
void FEdModeLandscape : : SetCurrentBrushSet ( int32 BrushSetIndex )
{
if ( CurrentBrushSetIndex ! = BrushSetIndex )
{
LandscapeBrushSets [ CurrentBrushSetIndex ] . PreviousBrushIndex = LandscapeBrushSets [ CurrentBrushSetIndex ] . Brushes . IndexOfByKey ( CurrentBrush ) ;
CurrentBrushSetIndex = BrushSetIndex ;
2014-07-17 12:20:34 -04:00
if ( CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > PreviousBrushIndex = BrushSetIndex ;
2014-03-14 14:13:41 -04:00
}
SetCurrentBrush ( LandscapeBrushSets [ CurrentBrushSetIndex ] . PreviousBrushIndex ) ;
}
}
void FEdModeLandscape : : SetCurrentBrush ( FName BrushName )
{
for ( int32 BrushIndex = 0 ; BrushIndex < LandscapeBrushSets [ CurrentBrushSetIndex ] . Brushes . Num ( ) ; BrushIndex + + )
{
if ( BrushName = = LandscapeBrushSets [ CurrentBrushSetIndex ] . Brushes [ BrushIndex ] - > GetBrushName ( ) )
{
SetCurrentBrush ( BrushIndex ) ;
return ;
}
}
}
void FEdModeLandscape : : SetCurrentBrush ( int32 BrushIndex )
{
if ( CurrentBrush ! = LandscapeBrushSets [ CurrentBrushSetIndex ] . Brushes [ BrushIndex ] )
{
CurrentBrush - > LeaveBrush ( ) ;
CurrentBrush = LandscapeBrushSets [ CurrentBrushSetIndex ] . Brushes [ BrushIndex ] ;
CurrentBrush - > EnterBrush ( ) ;
if ( Toolkit . IsValid ( ) )
2014-07-17 12:20:34 -04:00
{
2014-03-14 14:13:41 -04:00
StaticCastSharedPtr < FLandscapeToolKit > ( Toolkit ) - > NotifyBrushChanged ( ) ;
}
}
}
const TArray < TSharedRef < FLandscapeTargetListInfo > > & FEdModeLandscape : : GetTargetList ( )
{
return LandscapeTargetList ;
}
const TArray < FLandscapeListInfo > & FEdModeLandscape : : GetLandscapeList ( )
{
return LandscapeList ;
}
void FEdModeLandscape : : AddLayerInfo ( ULandscapeLayerInfoObject * LayerInfo )
{
if ( CurrentToolTarget . LandscapeInfo . IsValid ( ) & & CurrentToolTarget . LandscapeInfo - > GetLayerInfoIndex ( LayerInfo ) = = INDEX_NONE )
{
ALandscapeProxy * Proxy = CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) ;
CurrentToolTarget . LandscapeInfo - > Layers . Add ( FLandscapeInfoLayerSettings ( LayerInfo , Proxy ) ) ;
UpdateTargetList ( ) ;
}
}
int32 FEdModeLandscape : : UpdateLandscapeList ( )
{
LandscapeList . Empty ( ) ;
2014-07-17 12:20:34 -04:00
if ( ! CurrentGizmoActor . IsValid ( ) )
2014-03-14 14:13:41 -04:00
{
ALandscapeGizmoActiveActor * GizmoActor = NULL ;
2014-09-16 16:22:01 -04:00
for ( TActorIterator < ALandscapeGizmoActiveActor > It ( GetWorld ( ) ) ; It ; + + It )
2014-03-14 14:13:41 -04:00
{
2014-09-16 16:22:01 -04:00
GizmoActor = * It ;
break ;
2014-03-14 14:13:41 -04:00
}
}
int32 CurrentIndex = INDEX_NONE ;
if ( GetWorld ( ) )
{
int32 Index = 0 ;
for ( auto It = GetWorld ( ) - > LandscapeInfoMap . CreateIterator ( ) ; It ; + + It )
{
ULandscapeInfo * LandscapeInfo = It . Value ( ) ;
2014-07-17 12:20:34 -04:00
if ( LandscapeInfo )
2014-03-14 14:13:41 -04:00
{
if ( CurrentToolTarget . LandscapeInfo = = LandscapeInfo )
{
CurrentIndex = Index ;
// Update GizmoActor Landscape Target (is this necessary?)
if ( CurrentGizmoActor . IsValid ( ) )
{
CurrentGizmoActor - > SetTargetLandscape ( LandscapeInfo ) ;
}
}
int32 MinX , MinY , MaxX , MaxY ;
int32 Width = 0 , Height = 0 ;
if ( LandscapeInfo - > GetLandscapeExtent ( MinX , MinY , MaxX , MaxY ) )
{
Width = MaxX - MinX + 1 ;
Height = MaxY - MinY + 1 ;
}
LandscapeList . Add ( FLandscapeListInfo ( * LandscapeInfo - > GetLandscapeProxy ( ) - > GetName ( ) , LandscapeInfo ,
2014-07-17 12:20:34 -04:00
LandscapeInfo - > ComponentSizeQuads , LandscapeInfo - > ComponentNumSubsections , Width , Height ) ) ;
2014-03-14 14:13:41 -04:00
Index + + ;
}
}
}
if ( CurrentIndex = = INDEX_NONE )
{
if ( LandscapeList . Num ( ) > 0 )
{
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
CurrentBrush - > LeaveBrush ( ) ;
2014-07-17 12:20:34 -04:00
CurrentTool - > ExitTool ( ) ;
2014-03-14 14:13:41 -04:00
}
CurrentToolTarget . LandscapeInfo = LandscapeList [ 0 ] . Info ;
CurrentIndex = 0 ;
2014-07-17 12:20:34 -04:00
if ( CurrentTool ! = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > EnterTool ( ) ;
2014-03-14 14:13:41 -04:00
CurrentBrush - > EnterBrush ( ) ;
}
}
else
{
CurrentToolTarget . LandscapeInfo = NULL ;
}
}
return CurrentIndex ;
}
void FEdModeLandscape : : UpdateTargetList ( )
{
LandscapeTargetList . Empty ( ) ;
2014-07-17 12:20:34 -04:00
if ( CurrentToolTarget . LandscapeInfo . IsValid ( ) & &
CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) )
2014-03-14 14:13:41 -04:00
{
CachedLandscapeMaterial = CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) - > GetLandscapeMaterial ( ) ;
bool bFoundSelected = false ;
2014-07-17 12:20:34 -04:00
2014-03-14 14:13:41 -04:00
// Add heightmap
LandscapeTargetList . Add ( MakeShareable ( new FLandscapeTargetListInfo ( LOCTEXT ( " Heightmap " , " Heightmap " ) , ELandscapeToolTargetType : : Heightmap , CurrentToolTarget . LandscapeInfo . Get ( ) ) ) ) ;
2014-07-17 12:20:34 -04:00
if ( CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Heightmap )
{
bFoundSelected = true ;
}
// Add visibility
FLandscapeInfoLayerSettings VisibilitySettings ( ALandscapeProxy : : VisibilityLayer , CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) ) ;
LandscapeTargetList . Add ( MakeShareable ( new FLandscapeTargetListInfo ( LOCTEXT ( " Visibility " , " Visibility " ) , ELandscapeToolTargetType : : Visibility , VisibilitySettings ) ) ) ;
if ( CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Visibility )
{
bFoundSelected = true ;
}
2014-03-14 14:13:41 -04:00
// Add layers
UTexture2D * ThumbnailWeightmap = NULL ;
UTexture2D * ThumbnailHeightmap = NULL ;
for ( auto It = CurrentToolTarget . LandscapeInfo - > Layers . CreateIterator ( ) ; It ; It + + )
{
FLandscapeInfoLayerSettings & LayerSettings = * It ;
2014-07-17 12:20:34 -04:00
FName LayerName = LayerSettings . GetLayerName ( ) ;
if ( LayerSettings . LayerInfoObj = = ALandscapeProxy : : VisibilityLayer )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
// Already handled above
2014-03-14 14:13:41 -04:00
continue ;
}
2014-07-17 12:20:34 -04:00
if ( ! bFoundSelected & &
CurrentToolTarget . TargetType = = ELandscapeToolTargetType : : Weightmap & &
2014-03-14 14:13:41 -04:00
CurrentToolTarget . LayerInfo = = LayerSettings . LayerInfoObj & &
CurrentToolTarget . LayerName = = LayerSettings . LayerName )
{
bFoundSelected = true ;
}
// Ensure thumbnails are up valid
2014-07-17 12:20:34 -04:00
if ( LayerSettings . ThumbnailMIC = = NULL )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
if ( ThumbnailWeightmap = = NULL )
2014-03-14 14:13:41 -04:00
{
ThumbnailWeightmap = LoadObject < UTexture2D > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/LandscapeThumbnailWeightmap.LandscapeThumbnailWeightmap " ) , NULL , LOAD_None , NULL ) ;
}
2014-07-17 12:20:34 -04:00
if ( ThumbnailHeightmap = = NULL )
2014-03-14 14:13:41 -04:00
{
ThumbnailHeightmap = LoadObject < UTexture2D > ( NULL , TEXT ( " /Engine/EditorLandscapeResources/LandscapeThumbnailHeightmap.LandscapeThumbnailHeightmap " ) , NULL , LOAD_None , NULL ) ;
}
// Construct Thumbnail MIC
UMaterialInterface * LandscapeMaterial = LayerSettings . Owner ? LayerSettings . Owner - > GetLandscapeMaterial ( ) : UMaterial : : GetDefaultMaterial ( MD_Surface ) ;
LayerSettings . ThumbnailMIC = ALandscapeProxy : : GetLayerThumbnailMIC ( LandscapeMaterial , LayerName , ThumbnailWeightmap , ThumbnailHeightmap , LayerSettings . Owner ) ;
}
// Add the layer
LandscapeTargetList . Add ( MakeShareable ( new FLandscapeTargetListInfo ( FText : : FromName ( LayerName ) , ELandscapeToolTargetType : : Weightmap , LayerSettings ) ) ) ;
}
2014-07-17 12:20:34 -04:00
if ( ! bFoundSelected )
2014-03-14 14:13:41 -04:00
{
2014-07-28 05:08:15 -04:00
CurrentToolTarget . TargetType = ELandscapeToolTargetType : : Invalid ;
CurrentToolTarget . LayerInfo = nullptr ;
2014-07-17 12:20:34 -04:00
CurrentToolTarget . LayerName = NAME_None ;
2014-03-14 14:13:41 -04:00
}
}
TargetsListUpdated . Broadcast ( ) ;
}
FEdModeLandscape : : FTargetsListUpdated FEdModeLandscape : : TargetsListUpdated ;
void FEdModeLandscape : : OnWorldChange ( )
{
UpdateLandscapeList ( ) ;
UpdateTargetList ( ) ;
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None & &
CurrentToolTarget . LandscapeInfo = = NULL )
{
2014-06-18 10:16:16 -04:00
RequestDeletion ( ) ;
2014-03-14 14:13:41 -04:00
}
}
void FEdModeLandscape : : OnMaterialCompilationFinished ( UMaterialInterface * MaterialInterface )
{
if ( CurrentToolTarget . LandscapeInfo . IsValid ( ) & &
CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) ! = NULL & &
CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) - > GetLandscapeMaterial ( ) ! = NULL & &
CurrentToolTarget . LandscapeInfo - > GetLandscapeProxy ( ) - > GetLandscapeMaterial ( ) - > IsDependent ( MaterialInterface ) )
{
CurrentToolTarget . LandscapeInfo - > UpdateLayerInfoMap ( ) ;
UpdateTargetList ( ) ;
}
}
/** FEdMode: Render the mesh paint tool */
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : Render ( const FSceneView * View , FViewport * Viewport , FPrimitiveDrawInterface * PDI )
2014-03-14 14:13:41 -04:00
{
/** Call parent implementation */
2014-07-17 12:20:34 -04:00
FEdMode : : Render ( View , Viewport , PDI ) ;
2014-03-14 14:13:41 -04:00
if ( GEditor - > PlayWorld ! = NULL )
{
return ;
}
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
static const float CornerSize = 0.33f ;
2014-07-17 12:20:34 -04:00
static const FLinearColor CornerColour ( 1.0f , 1.0f , 0.5f ) ;
static const FLinearColor EdgeColour ( 1.0f , 1.0f , 0.0f ) ;
static const FLinearColor ComponentBorderColour ( 0.0f , 0.85f , 0.0f ) ;
static const FLinearColor SectionBorderColour ( 0.0f , 0.4f , 0.0f ) ;
static const FLinearColor InnerColour ( 0.0f , 0.25f , 0.0f ) ;
2014-03-14 14:13:41 -04:00
2014-06-18 10:16:16 -04:00
const ELevelViewportType ViewportType = ( ( FEditorViewportClient * ) Viewport - > GetClient ( ) ) - > ViewportType ;
2014-03-14 14:13:41 -04:00
const int32 ComponentCountX = UISettings - > NewLandscape_ComponentCount . X ;
const int32 ComponentCountY = UISettings - > NewLandscape_ComponentCount . Y ;
const int32 QuadsPerComponent = UISettings - > NewLandscape_SectionsPerComponent * UISettings - > NewLandscape_QuadsPerSection ;
const float ComponentSize = QuadsPerComponent ;
const FVector Offset = UISettings - > NewLandscape_Location + FTransform ( UISettings - > NewLandscape_Rotation , FVector : : ZeroVector , UISettings - > NewLandscape_Scale ) . TransformVector ( FVector ( - ComponentCountX * ComponentSize / 2 , - ComponentCountY * ComponentSize / 2 , 0 ) ) ;
const FTransform Transform = FTransform ( UISettings - > NewLandscape_Rotation , Offset , UISettings - > NewLandscape_Scale ) ;
2014-07-17 12:20:34 -04:00
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : ImportLandscape )
2014-03-14 14:13:41 -04:00
{
const TArray < uint16 > & ImportHeights = UISettings - > GetImportLandscapeData ( ) ;
2014-07-17 12:20:34 -04:00
if ( ImportHeights . Num ( ) ! = 0 )
2014-03-14 14:13:41 -04:00
{
const float InvQuadsPerComponent = 1.f / ( float ) QuadsPerComponent ;
const int32 SizeX = ComponentCountX * QuadsPerComponent + 1 ;
const int32 SizeY = ComponentCountY * QuadsPerComponent + 1 ;
const int32 ImportSizeX = UISettings - > ImportLandscape_Width ;
const int32 ImportSizeY = UISettings - > ImportLandscape_Height ;
const int32 OffsetX = ( SizeX - ImportSizeX ) / 2 ;
const int32 OffsetY = ( SizeY - ImportSizeY ) / 2 ;
2014-07-17 12:20:34 -04:00
for ( int32 ComponentY = 0 ; ComponentY < ComponentCountY ; ComponentY + + )
2014-03-14 14:13:41 -04:00
{
const int32 Y0 = ComponentY * QuadsPerComponent ;
const int32 Y1 = ( ComponentY + 1 ) * QuadsPerComponent ;
2014-07-17 12:20:34 -04:00
const int32 ImportY0 = FMath : : Clamp < int32 > ( Y0 - OffsetY , 0 , ImportSizeY - 1 ) ;
const int32 ImportY1 = FMath : : Clamp < int32 > ( Y1 - OffsetY , 0 , ImportSizeY - 1 ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
for ( int32 ComponentX = 0 ; ComponentX < ComponentCountX ; ComponentX + + )
2014-03-14 14:13:41 -04:00
{
const int32 X0 = ComponentX * QuadsPerComponent ;
const int32 X1 = ( ComponentX + 1 ) * QuadsPerComponent ;
2014-07-17 12:20:34 -04:00
const int32 ImportX0 = FMath : : Clamp < int32 > ( X0 - OffsetX , 0 , ImportSizeX - 1 ) ;
const int32 ImportX1 = FMath : : Clamp < int32 > ( X1 - OffsetX , 0 , ImportSizeX - 1 ) ;
2014-03-14 14:13:41 -04:00
const float Z00 = ( ( float ) ImportHeights [ ImportX0 + ImportY0 * ImportSizeX ] - 32768.f ) * LANDSCAPE_ZSCALE ;
const float Z01 = ( ( float ) ImportHeights [ ImportX0 + ImportY1 * ImportSizeX ] - 32768.f ) * LANDSCAPE_ZSCALE ;
const float Z10 = ( ( float ) ImportHeights [ ImportX1 + ImportY0 * ImportSizeX ] - 32768.f ) * LANDSCAPE_ZSCALE ;
const float Z11 = ( ( float ) ImportHeights [ ImportX1 + ImportY1 * ImportSizeX ] - 32768.f ) * LANDSCAPE_ZSCALE ;
if ( ComponentX = = 0 )
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X0 , Y0 , Z00 ) ) , Transform . TransformPosition ( FVector ( X0 , Y1 , Z01 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
2014-07-17 12:20:34 -04:00
if ( ComponentX = = ComponentCountX - 1 )
2014-03-14 14:13:41 -04:00
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X1 , Y0 , Z10 ) ) , Transform . TransformPosition ( FVector ( X1 , Y1 , Z11 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
else
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X1 , Y0 , Z10 ) ) , Transform . TransformPosition ( FVector ( X1 , Y1 , Z11 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
}
if ( ComponentY = = 0 )
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : Y_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X0 , Y0 , Z00 ) ) , Transform . TransformPosition ( FVector ( X1 , Y0 , Z10 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
2014-07-17 12:20:34 -04:00
if ( ComponentY = = ComponentCountY - 1 )
2014-03-14 14:13:41 -04:00
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : Y_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X0 , Y1 , Z01 ) ) , Transform . TransformPosition ( FVector ( X1 , Y1 , Z11 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
else
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X0 , Y1 , Z01 ) ) , Transform . TransformPosition ( FVector ( X1 , Y1 , Z11 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
}
2014-07-17 12:20:34 -04:00
2014-03-14 14:13:41 -04:00
// intra-component lines - too slow for big landscapes
2014-07-17 12:20:34 -04:00
/*
2014-03-14 14:13:41 -04:00
for ( int32 x = 1 ; x < QuadsPerComponent ; x + + )
{
2014-07-17 12:20:34 -04:00
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X0 + x , Y0 , FMath : : Lerp ( Z00 , Z10 , ( float ) x * InvQuadsPerComponent ) ) ) , Transform . TransformPosition ( FVector ( X0 + x , Y1 , FMath : : Lerp ( Z01 , Z11 , ( float ) x * InvQuadsPerComponent ) ) ) , ComponentBorderColour , SDPG_World ) ;
}
2014-03-14 14:13:41 -04:00
for ( int32 y = 1 ; y < QuadsPerComponent ; y + + )
{
2014-07-17 12:20:34 -04:00
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( X0 , Y0 + y , FMath : : Lerp ( Z00 , Z01 , ( float ) y * InvQuadsPerComponent ) ) ) , Transform . TransformPosition ( FVector ( X1 , Y0 + y , FMath : : Lerp ( Z10 , Z11 , ( float ) y * InvQuadsPerComponent ) ) ) , ComponentBorderColour , SDPG_World ) ;
2014-03-14 14:13:41 -04:00
}
*/
}
}
}
}
else //if (NewLandscapePreviewMode == ENewLandscapePreviewMode::NewLandscape)
{
if ( ViewportType = = LVT_Perspective | | ViewportType = = LVT_OrthoXY )
{
for ( int32 x = 0 ; x < = ComponentCountX * QuadsPerComponent ; x + + )
{
if ( x = = 0 )
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Negative_Y_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( x , CornerSize * ComponentSize , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , CornerSize * ComponentSize , 0 ) ) , Transform . TransformPosition ( FVector ( x , ( ComponentCountY - CornerSize ) * ComponentSize , 0 ) ) , EdgeColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Negative_Y_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , ( ComponentCountY - CornerSize ) * ComponentSize , 0 ) ) , Transform . TransformPosition ( FVector ( x , ComponentCountY * ComponentSize , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
else if ( x = = ComponentCountX * QuadsPerComponent )
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Positive_Y_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( x , CornerSize * ComponentSize , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , CornerSize * ComponentSize , 0 ) ) , Transform . TransformPosition ( FVector ( x , ( ComponentCountY - CornerSize ) * ComponentSize , 0 ) ) , EdgeColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Positive_Y_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , ( ComponentCountY - CornerSize ) * ComponentSize , 0 ) ) , Transform . TransformPosition ( FVector ( x , ComponentCountY * ComponentSize , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
else if ( x % QuadsPerComponent = = 0 )
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( x , ComponentCountY * ComponentSize , 0 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
}
else if ( x % UISettings - > NewLandscape_QuadsPerSection = = 0 )
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( x , ComponentCountY * ComponentSize , 0 ) ) , SectionBorderColour , SDPG_Foreground ) ;
}
else
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( x , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( x , ComponentCountY * ComponentSize , 0 ) ) , InnerColour , SDPG_World ) ;
}
}
}
else
{
// Don't allow dragging to resize in side-view
// and there's no point drawing the inner lines as only the outer is visible
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( 0 , ComponentCountY * ComponentSize , 0 ) ) , EdgeColour , SDPG_World ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( ComponentCountX * QuadsPerComponent , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * QuadsPerComponent , ComponentCountY * ComponentSize , 0 ) ) , EdgeColour , SDPG_World ) ;
}
if ( ViewportType = = LVT_Perspective | | ViewportType = = LVT_OrthoXY )
{
for ( int32 y = 0 ; y < = ComponentCountY * QuadsPerComponent ; y + + )
{
if ( y = = 0 )
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Negative_Y_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , y , 0 ) ) , Transform . TransformPosition ( FVector ( CornerSize * ComponentSize , y , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : Y_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( CornerSize * ComponentSize , y , 0 ) ) , Transform . TransformPosition ( FVector ( ( ComponentCountX - CornerSize ) * ComponentSize , y , 0 ) ) , EdgeColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Positive_Y_Negative ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( ( ComponentCountX - CornerSize ) * ComponentSize , y , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , y , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
else if ( y = = ComponentCountY * QuadsPerComponent )
{
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Negative_Y_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , y , 0 ) ) , Transform . TransformPosition ( FVector ( CornerSize * ComponentSize , y , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : Y_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( CornerSize * ComponentSize , y , 0 ) ) , Transform . TransformPosition ( FVector ( ( ComponentCountX - CornerSize ) * ComponentSize , y , 0 ) ) , EdgeColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( new HNewLandscapeGrabHandleProxy ( ELandscapeEdge : : X_Positive_Y_Positive ) ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( ( ComponentCountX - CornerSize ) * ComponentSize , y , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , y , 0 ) ) , CornerColour , SDPG_Foreground ) ;
PDI - > SetHitProxy ( NULL ) ;
}
else if ( y % QuadsPerComponent = = 0 )
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , y , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , y , 0 ) ) , ComponentBorderColour , SDPG_Foreground ) ;
}
else if ( y % UISettings - > NewLandscape_QuadsPerSection = = 0 )
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , y , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , y , 0 ) ) , SectionBorderColour , SDPG_Foreground ) ;
}
else
{
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , y , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , y , 0 ) ) , InnerColour , SDPG_World ) ;
}
}
}
else
{
// Don't allow dragging to resize in side-view
// and there's no point drawing the inner lines as only the outer is visible
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , 0 , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , 0 , 0 ) ) , EdgeColour , SDPG_World ) ;
PDI - > DrawLine ( Transform . TransformPosition ( FVector ( 0 , ComponentCountY * QuadsPerComponent , 0 ) ) , Transform . TransformPosition ( FVector ( ComponentCountX * ComponentSize , ComponentCountY * QuadsPerComponent , 0 ) ) , EdgeColour , SDPG_World ) ;
}
}
return ;
}
if ( LandscapeRenderAddCollision )
{
PDI - > DrawLine ( LandscapeRenderAddCollision - > Corners [ 0 ] , LandscapeRenderAddCollision - > Corners [ 3 ] , FColor ( 0 , 255 , 128 ) , SDPG_Foreground ) ;
PDI - > DrawLine ( LandscapeRenderAddCollision - > Corners [ 3 ] , LandscapeRenderAddCollision - > Corners [ 1 ] , FColor ( 0 , 255 , 128 ) , SDPG_Foreground ) ;
PDI - > DrawLine ( LandscapeRenderAddCollision - > Corners [ 1 ] , LandscapeRenderAddCollision - > Corners [ 0 ] , FColor ( 0 , 255 , 128 ) , SDPG_Foreground ) ;
PDI - > DrawLine ( LandscapeRenderAddCollision - > Corners [ 0 ] , LandscapeRenderAddCollision - > Corners [ 2 ] , FColor ( 0 , 255 , 128 ) , SDPG_Foreground ) ;
PDI - > DrawLine ( LandscapeRenderAddCollision - > Corners [ 2 ] , LandscapeRenderAddCollision - > Corners [ 3 ] , FColor ( 0 , 255 , 128 ) , SDPG_Foreground ) ;
PDI - > DrawLine ( LandscapeRenderAddCollision - > Corners [ 3 ] , LandscapeRenderAddCollision - > Corners [ 0 ] , FColor ( 0 , 255 , 128 ) , SDPG_Foreground ) ;
}
if ( ! GIsGizmoDragging & & GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo & & CurrentToolTarget . LandscapeInfo . IsValid ( ) & & CurrentGizmoActor . IsValid ( ) & & CurrentGizmoActor - > TargetLandscapeInfo )
{
FDynamicMeshBuilder MeshBuilder ;
for ( int32 i = 0 ; i < 8 ; + + i )
{
2014-07-17 12:20:34 -04:00
MeshBuilder . AddVertex ( CurrentGizmoActor - > FrustumVerts [ i ] , FVector2D ( 0 , 0 ) , FVector ( 1 , 0 , 0 ) , FVector ( 0 , 1 , 0 ) , FVector ( 0 , 0 , 1 ) , FColor ( 255 , 255 , 255 ) ) ;
2014-03-14 14:13:41 -04:00
}
// Upper box.
2014-07-17 12:20:34 -04:00
MeshBuilder . AddTriangle ( 0 , 2 , 1 ) ;
MeshBuilder . AddTriangle ( 0 , 3 , 2 ) ;
2014-03-14 14:13:41 -04:00
// Lower box.
2014-07-17 12:20:34 -04:00
MeshBuilder . AddTriangle ( 4 , 6 , 5 ) ;
MeshBuilder . AddTriangle ( 4 , 7 , 6 ) ;
2014-03-14 14:13:41 -04:00
// Others
2014-07-17 12:20:34 -04:00
MeshBuilder . AddTriangle ( 1 , 4 , 0 ) ;
MeshBuilder . AddTriangle ( 1 , 5 , 4 ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
MeshBuilder . AddTriangle ( 3 , 6 , 2 ) ;
MeshBuilder . AddTriangle ( 3 , 7 , 6 ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
MeshBuilder . AddTriangle ( 2 , 5 , 1 ) ;
MeshBuilder . AddTriangle ( 2 , 6 , 5 ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
MeshBuilder . AddTriangle ( 0 , 7 , 3 ) ;
MeshBuilder . AddTriangle ( 0 , 4 , 7 ) ;
2014-03-14 14:13:41 -04:00
PDI - > SetHitProxy ( new HTranslucentActor ( CurrentGizmoActor . Get ( ) , NULL ) ) ;
MeshBuilder . Draw ( PDI , FMatrix : : Identity , GizmoMaterial - > GetRenderProxy ( false ) , SDPG_World , true ) ;
PDI - > SetHitProxy ( NULL ) ;
}
// Override Rendering for Splines Tool
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
CurrentTool - > Render ( View , Viewport , PDI ) ;
2014-03-14 14:13:41 -04:00
}
}
/** FEdMode: Render HUD elements for this tool */
2014-07-17 12:20:34 -04:00
void FEdModeLandscape : : DrawHUD ( FEditorViewportClient * ViewportClient , FViewport * Viewport , const FSceneView * View , FCanvas * Canvas )
2014-03-14 14:13:41 -04:00
{
}
bool FEdModeLandscape : : UsesTransformWidget ( ) const
{
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
return true ;
}
// Override Widget for Splines Tool
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & CurrentTool - > UsesTransformWidget ( ) )
2014-03-14 14:13:41 -04:00
{
return true ;
}
2014-07-17 12:20:34 -04:00
return ( CurrentGizmoActor . IsValid ( ) & & CurrentGizmoActor - > IsSelected ( ) & & ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo ) ) ;
2014-03-14 14:13:41 -04:00
}
bool FEdModeLandscape : : ShouldDrawWidget ( ) const
{
return UsesTransformWidget ( ) ;
}
2014-07-17 12:20:34 -04:00
EAxisList : : Type FEdModeLandscape : : GetWidgetAxisToDraw ( FWidget : : EWidgetMode InWidgetMode ) const
2014-03-14 14:13:41 -04:00
{
if ( NewLandscapePreviewMode = = ENewLandscapePreviewMode : : None )
{
// Override Widget for Splines Tool
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
return CurrentTool - > GetWidgetAxisToDraw ( InWidgetMode ) ;
2014-03-14 14:13:41 -04:00
}
}
2014-07-17 12:20:34 -04:00
switch ( InWidgetMode )
2014-03-14 14:13:41 -04:00
{
case FWidget : : WM_Translate :
return EAxisList : : XYZ ;
case FWidget : : WM_Rotate :
return EAxisList : : Z ;
case FWidget : : WM_Scale :
return EAxisList : : XYZ ;
default :
return EAxisList : : None ;
}
}
FVector FEdModeLandscape : : GetWidgetLocation ( ) const
{
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
return UISettings - > NewLandscape_Location ;
}
if ( CurrentGizmoActor . IsValid ( ) & & ( GLandscapeEditRenderMode & ELandscapeEditRenderMode : : Gizmo ) & & CurrentGizmoActor - > IsSelected ( ) )
{
if ( CurrentGizmoActor - > TargetLandscapeInfo & & CurrentGizmoActor - > TargetLandscapeInfo - > GetLandscapeProxy ( ) )
{
// Apply Landscape transformation when it is available
ULandscapeInfo * Info = CurrentGizmoActor - > TargetLandscapeInfo ;
2014-07-17 12:20:34 -04:00
return CurrentGizmoActor - > GetActorLocation ( )
2014-03-14 14:13:41 -04:00
+ FRotationMatrix ( Info - > GetLandscapeProxy ( ) - > GetActorRotation ( ) ) . TransformPosition ( FVector ( 0 , 0 , CurrentGizmoActor - > GetLength ( ) ) ) ;
}
return CurrentGizmoActor - > GetActorLocation ( ) ;
}
// Override Widget for Splines Tool
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
return CurrentTool - > GetWidgetLocation ( ) ;
2014-03-14 14:13:41 -04:00
}
return FEdMode : : GetWidgetLocation ( ) ;
}
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : GetCustomDrawingCoordinateSystem ( FMatrix & InMatrix , void * InData )
2014-03-14 14:13:41 -04:00
{
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
InMatrix = FRotationMatrix ( UISettings - > NewLandscape_Rotation ) ;
return true ;
}
// Override Widget for Splines Tool
2014-07-17 12:20:34 -04:00
if ( CurrentTool & & CurrentTool )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
InMatrix = CurrentTool - > GetWidgetRotation ( ) ;
2014-03-14 14:13:41 -04:00
return true ;
}
return false ;
}
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : GetCustomInputCoordinateSystem ( FMatrix & InMatrix , void * InData )
2014-03-14 14:13:41 -04:00
{
return GetCustomDrawingCoordinateSystem ( InMatrix , InData ) ;
}
/** FEdMode: Handling SelectActor */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : Select ( AActor * InActor , bool bInSelected )
2014-03-14 14:13:41 -04:00
{
if ( GEditor - > PlayWorld ! = NULL )
{
return false ;
}
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
return false ;
}
if ( InActor - > IsA < ALandscapeProxy > ( ) & & bInSelected )
{
ALandscapeProxy * Landscape = CastChecked < ALandscapeProxy > ( InActor ) ;
if ( CurrentToolTarget . LandscapeInfo ! = Landscape - > GetLandscapeInfo ( ) )
{
CurrentToolTarget . LandscapeInfo = Landscape - > GetLandscapeInfo ( ) ;
UpdateTargetList ( ) ;
}
}
if ( IsSelectionAllowed ( InActor , bInSelected ) )
{
return false ;
}
else if ( ! bInSelected )
{
return false ;
}
return true ;
}
/** FEdMode: Check to see if an actor can be selected in this mode - no side effects */
2014-07-17 12:20:34 -04:00
bool FEdModeLandscape : : IsSelectionAllowed ( AActor * InActor , bool bInSelection ) const
2014-03-14 14:13:41 -04:00
{
if ( GEditor - > PlayWorld ! = NULL )
{
return false ;
}
if ( NewLandscapePreviewMode ! = ENewLandscapePreviewMode : : None )
{
return false ;
}
// Override Selection for Splines Tool
2014-09-08 10:45:50 -04:00
if ( CurrentTool & & CurrentTool - > OverrideSelection ( ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
return CurrentTool - > IsSelectionAllowed ( InActor , bInSelection ) ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
if ( InActor - > IsA ( ALandscapeProxy : : StaticClass ( ) ) )
2014-03-14 14:13:41 -04:00
{
return true ;
}
else if ( InActor - > IsA ( ALandscapeGizmoActor : : StaticClass ( ) ) )
{
return true ;
}
else if ( InActor - > IsA ( ALight : : StaticClass ( ) ) )
{
return true ;
}
return false ;
}
/** FEdMode: Called when the currently selected actor has changed */
void FEdModeLandscape : : ActorSelectionChangeNotify ( )
{
if ( CurrentGizmoActor . IsValid ( ) & & CurrentGizmoActor - > IsSelected ( ) )
{
GEditor - > SelectNone ( false , true ) ;
GEditor - > SelectActor ( CurrentGizmoActor . Get ( ) , true , false , true ) ;
}
2014-07-17 12:20:34 -04:00
/*
USelection * EditorSelection = GEditor - > GetSelectedActors ( ) ;
for ( FSelectionIterator Itor ( EditorSelection ) ; Itor ; + + Itor )
{
2014-03-14 14:13:41 -04:00
if ( ( ( * Itor ) - > IsA ( ALandscapeGizmoActor : : StaticClass ( ) ) ) )
{
2014-07-17 12:20:34 -04:00
bIsGizmoSelected = true ;
break ;
2014-03-14 14:13:41 -04:00
}
2014-07-17 12:20:34 -04:00
}
*/
2014-03-14 14:13:41 -04:00
}
void FEdModeLandscape : : ActorMoveNotify ( )
{
//GUnrealEd->UpdateFloatingPropertyWindows();
}
/** Forces all level editor viewports to realtime mode */
2014-05-20 10:13:41 -04:00
void FEdModeLandscape : : ForceRealTimeViewports ( const bool bEnable , const bool bStoreCurrentState )
2014-03-14 14:13:41 -04:00
{
2014-05-20 10:13:41 -04:00
FLevelEditorModule & LevelEditorModule = FModuleManager : : GetModuleChecked < FLevelEditorModule > ( " LevelEditor " ) ;
2014-03-14 14:13:41 -04:00
TSharedPtr < ILevelEditor > LevelEditor = LevelEditorModule . GetFirstLevelEditor ( ) ;
if ( LevelEditor . IsValid ( ) )
{
TArray < TSharedPtr < ILevelViewport > > Viewports = LevelEditor - > GetViewports ( ) ;
2014-07-17 12:20:34 -04:00
for ( const TSharedPtr < ILevelViewport > & ViewportWindow : Viewports )
2014-03-14 14:13:41 -04:00
{
if ( ViewportWindow . IsValid ( ) )
{
2014-06-18 10:16:16 -04:00
FEditorViewportClient & Viewport = ViewportWindow - > GetLevelViewportClient ( ) ;
2014-03-14 14:13:41 -04:00
if ( bEnable )
{
Viewport . SetRealtime ( bEnable , bStoreCurrentState ) ;
Viewport . SetGameView ( false ) ;
}
else
{
const bool bAllowDisable = true ;
Viewport . RestoreRealtime ( bAllowDisable ) ;
}
}
}
}
}
void FEdModeLandscape : : ReimportData ( const FLandscapeTargetListInfo & TargetInfo )
{
const FString & SourceFilePath = TargetInfo . ReimportFilePath ( ) ;
if ( SourceFilePath . Len ( ) )
{
ImportData ( TargetInfo , SourceFilePath ) ;
}
else
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok , NSLOCTEXT ( " UnrealEd " , " LandscapeReImport_BadFileName " , " Reimport Source Filename is invalid " ) ) ;
2014-03-14 14:13:41 -04:00
}
}
void FEdModeLandscape : : ImportData ( const FLandscapeTargetListInfo & TargetInfo , const FString & Filename )
{
ULandscapeInfo * LandscapeInfo = TargetInfo . LandscapeInfo . Get ( ) ;
if ( LandscapeInfo ! = NULL )
{
TArray < uint8 > Data ;
int32 MinX , MinY , MaxX , MaxY ;
if ( FFileHelper : : LoadFileToArray ( Data , * Filename ) & &
LandscapeInfo - > GetLandscapeExtent ( MinX , MinY , MaxX , MaxY ) )
{
if ( Filename . EndsWith ( " .png " ) )
{
IImageWrapperModule & ImageWrapperModule = FModuleManager : : LoadModuleChecked < IImageWrapperModule > ( " ImageWrapper " ) ;
IImageWrapperPtr ImageWrapper = ImageWrapperModule . CreateImageWrapper ( EImageFormat : : PNG ) ;
if ( ImageWrapper - > SetCompressed ( Data . GetData ( ) , Data . Num ( ) ) )
{
2014-07-17 12:20:34 -04:00
if ( ImageWrapper - > GetWidth ( ) ! = ( 1 + MaxX - MinX ) | | ImageWrapper - > GetHeight ( ) ! = ( 1 + MaxY - MinY ) )
2014-03-14 14:13:41 -04:00
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok ,
FText : : Format ( NSLOCTEXT ( " UnrealEd " , " LandscapeReImport_BadFileSize " , " {0}'s filesize does not match with current Landscape extent " ) , FText : : FromString ( Filename ) ) ) ;
2014-03-14 14:13:41 -04:00
return ;
}
const TArray < uint8 > * RawData = NULL ;
if ( TargetInfo . TargetType = = ELandscapeToolTargetType : : Heightmap )
{
2014-04-23 17:40:55 -04:00
if ( ImageWrapper - > GetFormat ( ) ! = ERGBFormat : : Gray )
{
2014-04-23 18:37:45 -04:00
EAppReturnType : : Type Result = FMessageDialog : : Open ( EAppMsgType : : OkCancel , NSLOCTEXT ( " LandscapeEditor.NewLandscape " , " Import_HeightmapFileColorPng " , " The Heightmap file appears to be a color png, grayscale is expected. The import *can* continue, but the result may not be what you expect... " ) ) ;
if ( Result ! = EAppReturnType : : Ok )
{
return ;
}
2014-04-23 17:40:55 -04:00
}
if ( ImageWrapper - > GetBitDepth ( ) ! = 16 )
{
2014-04-23 18:37:45 -04:00
EAppReturnType : : Type Result = FMessageDialog : : Open ( EAppMsgType : : OkCancel , NSLOCTEXT ( " LandscapeEditor.NewLandscape " , " Import_HeightmapFileLowBitDepth " , " The Heightmap file appears to be an 8-bit png, 16-bit is preferred. The import *can* continue, but the result may be lower quality than desired. " ) ) ;
if ( Result ! = EAppReturnType : : Ok )
{
return ;
}
2014-04-23 17:40:55 -04:00
}
2014-03-14 14:13:41 -04:00
if ( ImageWrapper - > GetBitDepth ( ) < = 8 )
{
ImageWrapper - > GetRaw ( ERGBFormat : : Gray , 8 , RawData ) ;
2014-04-23 17:40:55 -04:00
Data . Reset ( ) ;
2014-03-14 14:13:41 -04:00
Data . AddUninitialized ( RawData - > Num ( ) * sizeof ( uint16 ) ) ;
uint16 * DataPtr = ( uint16 * ) Data . GetData ( ) ;
for ( int32 i = 0 ; i < RawData - > Num ( ) ; i + + )
{
DataPtr [ i ] = ( * RawData ) [ i ] * 0x101 ; // Expand to 16-bit
}
}
else
{
ImageWrapper - > GetRaw ( ERGBFormat : : Gray , 16 , RawData ) ;
Data = * RawData ; // agh I want to use MoveTemp() here
}
}
else
{
2014-04-23 17:40:55 -04:00
if ( ImageWrapper - > GetFormat ( ) ! = ERGBFormat : : Gray )
{
2014-04-23 18:37:45 -04:00
EAppReturnType : : Type Result = FMessageDialog : : Open ( EAppMsgType : : OkCancel , NSLOCTEXT ( " LandscapeEditor.NewLandscape " , " Import_LayerColorPng " , " The Layer file appears to be a color png, grayscale is expected. The import *can* continue, but the result may not be what you expect... " ) ) ;
if ( Result ! = EAppReturnType : : Ok )
{
return ;
}
2014-04-23 17:40:55 -04:00
}
2014-03-14 14:13:41 -04:00
ImageWrapper - > GetRaw ( ERGBFormat : : Gray , 8 , RawData ) ;
Data = * RawData ; // agh I want to use MoveTemp() here
}
}
else
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok ,
FText : : Format ( LOCTEXT ( " ImportData_CorruptPngFile " , " Import of {0} failed (corrupt png?) " ) , FText : : FromString ( Filename ) ) ) ;
2014-03-14 14:13:41 -04:00
return ;
}
}
if ( TargetInfo . TargetType = = ELandscapeToolTargetType : : Heightmap )
{
2014-07-17 12:20:34 -04:00
if ( Data . Num ( ) = = ( 1 + MaxX - MinX ) * ( 1 + MaxY - MinY ) * 2 )
2014-03-14 14:13:41 -04:00
{
FHeightmapAccessor < false > HeightmapAccessor ( LandscapeInfo ) ;
2014-09-29 04:23:44 -04:00
HeightmapAccessor . SetData ( MinX , MinY , MaxX , MaxY , ( uint16 * ) Data . GetData ( ) ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok ,
FText : : Format ( NSLOCTEXT ( " UnrealEd " , " LandscapeReImport_BadFileSize " , " {0}'s filesize does not match with current Landscape extent " ) , FText : : FromString ( Filename ) ) ) ;
2014-03-14 14:13:41 -04:00
}
}
else
{
2014-07-17 12:20:34 -04:00
if ( Data . Num ( ) = = ( 1 + MaxX - MinX ) * ( 1 + MaxY - MinY ) )
2014-03-14 14:13:41 -04:00
{
FAlphamapAccessor < false , true > AlphamapAccessor ( LandscapeInfo , TargetInfo . LayerInfoObj . Get ( ) ) ;
2014-09-29 04:23:44 -04:00
AlphamapAccessor . SetData ( MinX , MinY , MaxX , MaxY , Data . GetData ( ) , ELandscapeLayerPaintingRestriction : : None ) ;
2014-03-14 14:13:41 -04:00
}
else
{
2014-07-17 12:20:34 -04:00
FMessageDialog : : Open ( EAppMsgType : : Ok ,
FText : : Format ( NSLOCTEXT ( " UnrealEd " , " LandscapeReImport_BadFileSize " , " {0}'s filesize does not match with current Landscape extent " ) , FText : : FromString ( Filename ) ) ) ;
2014-03-14 14:13:41 -04:00
}
}
}
}
}
2014-04-02 18:09:23 -04:00
ALandscape * FEdModeLandscape : : ChangeComponentSetting ( int32 NumComponentsX , int32 NumComponentsY , int32 NumSubsections , int32 SubsectionSizeQuads , bool bResample )
2014-03-14 14:13:41 -04:00
{
check ( NumComponentsX > 0 ) ;
check ( NumComponentsY > 0 ) ;
check ( NumSubsections > 0 ) ;
check ( SubsectionSizeQuads > 0 ) ;
ALandscape * Landscape = NULL ;
ULandscapeInfo * LandscapeInfo = CurrentToolTarget . LandscapeInfo . Get ( ) ;
if ( ensure ( LandscapeInfo ! = NULL ) )
{
2014-04-02 18:09:23 -04:00
int32 OldMinX , OldMinY , OldMaxX , OldMaxY ;
if ( LandscapeInfo - > GetLandscapeExtent ( OldMinX , OldMinY , OldMaxX , OldMaxY ) )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
ALandscapeProxy * OldLandscapeProxy = LandscapeInfo - > GetLandscapeProxy ( ) ;
2014-03-14 14:13:41 -04:00
2014-04-02 18:09:23 -04:00
const int32 OldVertsX = OldMaxX - OldMinX + 1 ;
const int32 OldVertsY = OldMaxY - OldMinY + 1 ;
const int32 NewVertsX = NumComponentsX * NumSubsections * SubsectionSizeQuads + 1 ;
const int32 NewVertsY = NumComponentsY * NumSubsections * SubsectionSizeQuads + 1 ;
2014-03-14 14:13:41 -04:00
FLandscapeEditDataInterface LandscapeEdit ( LandscapeInfo ) ;
TArray < uint16 > HeightData ;
TArray < FLandscapeImportLayerInfo > ImportLayerInfos ;
2014-04-02 18:09:23 -04:00
FVector LandscapeOffset = FVector : : ZeroVector ;
float LandscapeScaleFactor = 1.0f ;
if ( bResample )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
HeightData . AddZeroed ( OldVertsX * OldVertsY * sizeof ( uint16 ) ) ;
// GetHeightData alters its args, so make temp copies to avoid screwing things up
int32 TMinX = OldMinX , TMinY = OldMinY , TMaxX = OldMaxX , TMaxY = OldMaxY ;
LandscapeEdit . GetHeightData ( TMinX , TMinY , TMaxX , OldMaxY , HeightData . GetData ( ) , 0 ) ;
HeightData = LandscapeEditorUtils : : ResampleData ( HeightData ,
OldVertsX , OldVertsY , NewVertsX , NewVertsY ) ;
for ( const FLandscapeInfoLayerSettings & LayerSettings : LandscapeInfo - > Layers )
2014-03-14 14:13:41 -04:00
{
2014-04-02 18:09:23 -04:00
if ( LayerSettings . LayerInfoObj ! = NULL )
{
2014-07-17 12:20:34 -04:00
auto ImportLayerInfo = new ( ImportLayerInfos ) FLandscapeImportLayerInfo ( LayerSettings ) ;
2014-04-23 18:25:00 -04:00
ImportLayerInfo - > LayerData . AddZeroed ( OldVertsX * OldVertsY * sizeof ( uint8 ) ) ;
2014-07-17 12:20:34 -04:00
2014-04-02 18:09:23 -04:00
TMinX = OldMinX ; TMinY = OldMinY ; TMaxX = OldMaxX ; TMaxY = OldMaxY ;
2014-04-23 18:25:00 -04:00
LandscapeEdit . GetWeightData ( LayerSettings . LayerInfoObj , TMinX , TMinY , TMaxX , TMaxY , ImportLayerInfo - > LayerData . GetData ( ) , 0 ) ;
2014-03-14 14:13:41 -04:00
2014-04-23 18:25:00 -04:00
ImportLayerInfo - > LayerData = LandscapeEditorUtils : : ResampleData ( ImportLayerInfo - > LayerData ,
2014-04-02 18:09:23 -04:00
OldVertsX , OldVertsY ,
NewVertsX , NewVertsY ) ;
}
2014-03-14 14:13:41 -04:00
}
2014-04-02 18:09:23 -04:00
LandscapeScaleFactor = ( float ) OldLandscapeProxy - > ComponentSizeQuads / ( NumSubsections * SubsectionSizeQuads ) ;
}
else
{
const int32 NewMinX = OldMinX + ( OldVertsX - NewVertsX ) / 2 ;
const int32 NewMinY = OldMinY + ( OldVertsY - NewVertsY ) / 2 ;
const int32 NewMaxX = NewMinX + NewVertsX - 1 ;
const int32 NewMaxY = NewMinY + NewVertsY - 1 ;
const int32 RequestedMinX = FMath : : Max ( OldMinX , NewMinX ) ;
const int32 RequestedMinY = FMath : : Max ( OldMinY , NewMinY ) ;
const int32 RequestedMaxX = FMath : : Min ( OldMaxX , NewMaxX ) ;
const int32 RequestedMaxY = FMath : : Min ( OldMaxY , NewMaxY ) ;
const int32 RequestedVertsX = RequestedMaxX - RequestedMinX + 1 ;
const int32 RequestedVertsY = RequestedMaxY - RequestedMinY + 1 ;
HeightData . AddZeroed ( RequestedVertsX * RequestedVertsY * sizeof ( uint16 ) ) ;
// GetHeightData alters its args, so make temp copies to avoid screwing things up
int32 TMinX = RequestedMinX , TMinY = RequestedMinY , TMaxX = RequestedMaxX , TMaxY = RequestedMaxY ;
LandscapeEdit . GetHeightData ( TMinX , TMinY , TMaxX , OldMaxY , HeightData . GetData ( ) , 0 ) ;
HeightData = LandscapeEditorUtils : : ExpandData ( HeightData ,
RequestedMinX , RequestedMinY , RequestedMaxX , RequestedMaxY ,
NewMinX , NewMinY , NewMaxX , NewMaxY ) ;
for ( const FLandscapeInfoLayerSettings & LayerSettings : LandscapeInfo - > Layers )
{
if ( LayerSettings . LayerInfoObj ! = NULL )
{
2014-07-17 12:20:34 -04:00
auto ImportLayerInfo = new ( ImportLayerInfos ) FLandscapeImportLayerInfo ( LayerSettings ) ;
2014-04-23 18:25:00 -04:00
ImportLayerInfo - > LayerData . AddZeroed ( NewVertsX * NewVertsY * sizeof ( uint8 ) ) ;
2014-04-02 18:09:23 -04:00
TMinX = RequestedMinX ; TMinY = RequestedMinY ; TMaxX = RequestedMaxX ; TMaxY = RequestedMaxY ;
2014-04-23 18:25:00 -04:00
LandscapeEdit . GetWeightData ( LayerSettings . LayerInfoObj , TMinX , TMinY , TMaxX , TMaxY , ImportLayerInfo - > LayerData . GetData ( ) , 0 ) ;
2014-04-02 18:09:23 -04:00
2014-04-23 18:25:00 -04:00
ImportLayerInfo - > LayerData = LandscapeEditorUtils : : ExpandData ( ImportLayerInfo - > LayerData ,
2014-04-02 18:09:23 -04:00
RequestedMinX , RequestedMinY , RequestedMaxX , RequestedMaxY ,
NewMinX , NewMinY , NewMaxX , NewMaxY ) ;
}
}
LandscapeOffset = FVector ( NewMinX - OldMinX , NewMinY - OldMinY , 0 ) * OldLandscapeProxy - > GetActorScale ( ) ;
2014-03-14 14:13:41 -04:00
}
2014-04-02 18:09:23 -04:00
const FVector Location = OldLandscapeProxy - > GetActorLocation ( ) + LandscapeOffset ;
2014-03-14 14:13:41 -04:00
Landscape = OldLandscapeProxy - > GetWorld ( ) - > SpawnActor < ALandscape > ( Location , OldLandscapeProxy - > GetActorRotation ( ) ) ;
2014-04-02 18:09:23 -04:00
const FVector OldScale = OldLandscapeProxy - > GetActorScale ( ) ;
Landscape - > SetActorRelativeScale3D ( FVector ( OldScale . X * LandscapeScaleFactor , OldScale . Y * LandscapeScaleFactor , OldScale . Z ) ) ;
2014-03-14 14:13:41 -04:00
Landscape - > LandscapeMaterial = OldLandscapeProxy - > LandscapeMaterial ;
Landscape - > CollisionMipLevel = OldLandscapeProxy - > CollisionMipLevel ;
2014-04-23 18:25:00 -04:00
Landscape - > Import ( FGuid : : NewGuid ( ) , NewVertsX , NewVertsY , NumSubsections * SubsectionSizeQuads , NumSubsections , SubsectionSizeQuads , HeightData . GetData ( ) , * OldLandscapeProxy - > ReimportHeightmapFilePath , ImportLayerInfos ) ;
2014-03-14 14:13:41 -04:00
2014-07-17 12:20:34 -04:00
Landscape - > MaxLODLevel = OldLandscapeProxy - > MaxLODLevel ;
Landscape - > ExportLOD = OldLandscapeProxy - > ExportLOD ;
Landscape - > StaticLightingLOD = OldLandscapeProxy - > StaticLightingLOD ;
Landscape - > DefaultPhysMaterial = OldLandscapeProxy - > DefaultPhysMaterial ;
2014-03-14 14:13:41 -04:00
Landscape - > StreamingDistanceMultiplier = OldLandscapeProxy - > StreamingDistanceMultiplier ;
2014-07-17 12:20:34 -04:00
Landscape - > LandscapeHoleMaterial = OldLandscapeProxy - > LandscapeHoleMaterial ;
Landscape - > LODDistanceFactor = OldLandscapeProxy - > LODDistanceFactor ;
Landscape - > StaticLightingResolution = OldLandscapeProxy - > StaticLightingResolution ;
Landscape - > bCastStaticShadow = OldLandscapeProxy - > bCastStaticShadow ;
Landscape - > bCastShadowAsTwoSided = OldLandscapeProxy - > bCastShadowAsTwoSided ;
Landscape - > LightmassSettings = OldLandscapeProxy - > LightmassSettings ;
Landscape - > CollisionThickness = OldLandscapeProxy - > CollisionThickness ;
2014-03-14 14:13:41 -04:00
Landscape - > BodyInstance . SetCollisionProfileName ( OldLandscapeProxy - > BodyInstance . GetCollisionProfileName ( ) ) ;
2014-04-23 20:11:22 -04:00
if ( Landscape - > BodyInstance . DoesUseCollisionProfile ( ) = = false )
2014-03-14 14:13:41 -04:00
{
Landscape - > BodyInstance . SetCollisionEnabled ( OldLandscapeProxy - > BodyInstance . GetCollisionEnabled ( ) ) ;
Landscape - > BodyInstance . SetObjectType ( OldLandscapeProxy - > BodyInstance . GetObjectType ( ) ) ;
Landscape - > BodyInstance . SetResponseToChannels ( OldLandscapeProxy - > BodyInstance . GetResponseToChannels ( ) ) ;
}
2014-07-17 12:20:34 -04:00
Landscape - > EditorLayerSettings = OldLandscapeProxy - > EditorLayerSettings ;
Landscape - > bUsedForNavigation = OldLandscapeProxy - > bUsedForNavigation ;
2014-03-14 14:13:41 -04:00
Landscape - > MaxPaintedLayersPerComponent = OldLandscapeProxy - > MaxPaintedLayersPerComponent ;
// Clone landscape splines
2014-04-02 18:09:23 -04:00
TLazyObjectPtr < ALandscape > OldLandscapeActor = LandscapeInfo - > LandscapeActor ;
2014-03-14 14:13:41 -04:00
if ( OldLandscapeActor . IsValid ( ) & & OldLandscapeActor - > SplineComponent ! = NULL )
{
ULandscapeSplinesComponent * OldSplines = OldLandscapeActor - > SplineComponent ;
ULandscapeSplinesComponent * NewSplines = DuplicateObject < ULandscapeSplinesComponent > ( OldSplines , Landscape , * OldSplines - > GetName ( ) ) ;
NewSplines - > AttachTo ( Landscape - > GetRootComponent ( ) , NAME_None , EAttachLocation : : KeepWorldPosition ) ;
2014-04-02 18:09:23 -04:00
const FVector OldSplineScale = OldSplines - > GetRelativeTransform ( ) . GetScale3D ( ) ;
NewSplines - > SetRelativeScale3D ( FVector ( OldSplineScale . X / LandscapeScaleFactor , OldSplineScale . Y / LandscapeScaleFactor , OldSplineScale . Z ) ) ;
2014-03-14 14:13:41 -04:00
Landscape - > SplineComponent = NewSplines ;
NewSplines - > RegisterComponent ( ) ;
2014-04-02 18:09:23 -04:00
// TODO: Foliage on spline meshes
}
if ( bResample )
{
// Remap foliage to the resampled components
ULandscapeInfo * NewLandscapeInfo = Landscape - > GetLandscapeInfo ( ) ;
for ( const TPair < FIntPoint , ULandscapeComponent * > & Entry : LandscapeInfo - > XYtoComponentMap )
{
ULandscapeComponent * NewComponent = NewLandscapeInfo - > XYtoComponentMap [ Entry . Key ] ;
if ( NewComponent )
{
ULandscapeHeightfieldCollisionComponent * OldCollisionComponent = Entry . Value - > CollisionComponent . Get ( ) ;
ULandscapeHeightfieldCollisionComponent * NewCollisionComponent = NewComponent - > CollisionComponent . Get ( ) ;
if ( OldCollisionComponent & & NewCollisionComponent )
{
AInstancedFoliageActor * OldFoliageActor = AInstancedFoliageActor : : GetInstancedFoliageActorForLevel ( OldCollisionComponent - > GetLandscapeProxy ( ) - > GetLevel ( ) ) ;
if ( OldFoliageActor )
{
OldFoliageActor - > MoveInstancesToNewComponent ( OldCollisionComponent , NewCollisionComponent ) ;
AInstancedFoliageActor * NewFoliageActor = AInstancedFoliageActor : : GetInstancedFoliageActorForLevel ( NewCollisionComponent - > GetTypedOuter < ULevel > ( ) ) ;
NewFoliageActor - > SnapInstancesForLandscape ( NewCollisionComponent , FBox ( FVector ( - WORLD_MAX ) , FVector ( WORLD_MAX ) ) ) ;
}
}
}
}
2014-03-14 14:13:41 -04:00
}
// Delete the old Landscape and all its proxies
for ( TActorIterator < ALandscapeProxy > It ( OldLandscapeProxy - > GetWorld ( ) ) ; It ; + + It )
{
ALandscapeProxy * Proxy = ( * It ) ;
if ( Proxy & & Proxy - > LandscapeActor = = OldLandscapeActor )
{
Proxy - > Destroy ( ) ;
}
}
OldLandscapeProxy - > Destroy ( ) ;
}
}
return Landscape ;
}
2014-05-20 05:07:16 -04:00
bool LandscapeEditorUtils : : SetHeightmapData ( ALandscapeProxy * Landscape , const TArray < uint16 > & Data )
{
FIntRect ComponentsRect = Landscape - > GetBoundingRect ( ) + Landscape - > LandscapeSectionOffset ;
2014-07-17 12:20:34 -04:00
if ( Data . Num ( ) = = ( 1 + ComponentsRect . Width ( ) ) * ( 1 + ComponentsRect . Height ( ) ) )
2014-05-20 05:07:16 -04:00
{
FHeightmapAccessor < false > HeightmapAccessor ( Landscape - > GetLandscapeInfo ( ) ) ;
2014-09-29 04:23:44 -04:00
HeightmapAccessor . SetData ( ComponentsRect . Min . X , ComponentsRect . Min . Y , ComponentsRect . Max . X , ComponentsRect . Max . Y , Data . GetData ( ) ) ;
2014-05-20 05:07:16 -04:00
return true ;
}
return false ;
}
bool LandscapeEditorUtils : : SetWeightmapData ( ALandscapeProxy * Landscape , ULandscapeLayerInfoObject * LayerObject , const TArray < uint8 > & Data )
{
2014-07-17 12:20:34 -04:00
FIntRect ComponentsRect = Landscape - > GetBoundingRect ( ) + Landscape - > LandscapeSectionOffset ;
if ( Data . Num ( ) = = ( 1 + ComponentsRect . Width ( ) ) * ( 1 + ComponentsRect . Height ( ) ) )
2014-05-20 05:07:16 -04:00
{
FAlphamapAccessor < false , true > AlphamapAccessor ( Landscape - > GetLandscapeInfo ( ) , LayerObject ) ;
2014-09-29 04:23:44 -04:00
AlphamapAccessor . SetData ( ComponentsRect . Min . X , ComponentsRect . Min . Y , ComponentsRect . Max . X , ComponentsRect . Max . Y , Data . GetData ( ) , ELandscapeLayerPaintingRestriction : : None ) ;
2014-05-20 05:07:16 -04:00
return true ;
}
return false ;
}
2014-08-04 10:14:05 -04:00
FName FLandscapeTargetListInfo : : GetLayerName ( ) const
{
return LayerInfoObj . IsValid ( ) ? LayerInfoObj - > LayerName : LayerName ;
}
2014-03-14 14:13:41 -04:00
# undef LOCTEXT_NAMESPACE