bool FBeginModifyLandscapeCommand::Update() { //Find the landscape FEdModeLandscape* LandscapeEdMode = (FEdModeLandscape*)GLevelEditorModeTools().GetActiveMode(FBuiltinEditorModes::EM_Landscape); //Find a location on the edge of the landscape along the x axis so the default camera can see it in the distance. FVector LandscapeSizePerComponent = LandscapeEdMode->UISettings->NewLandscape_QuadsPerSection * LandscapeEdMode->UISettings->NewLandscape_SectionsPerComponent * LandscapeEdMode->UISettings->NewLandscape_Scale; FVector TargetLoctaion(0); TargetLoctaion.X = -LandscapeSizePerComponent.X * (LandscapeEdMode->UISettings->NewLandscape_ComponentCount.X / 2.f); ALandscapeProxy* Proxy = LandscapeEdMode->CurrentToolTarget.LandscapeInfo.Get()->GetCurrentLevelLandscapeProxy(true); if (Proxy) { TargetLoctaion = Proxy->LandscapeActorToWorld().InverseTransformPosition(TargetLoctaion); } //Begin using the sculpting tool FLevelEditorViewportClient* SelectedViewport = LandscapeTestUtils::FindSelectedViewport(); LandscapeEdMode->CurrentTool->BeginTool(SelectedViewport, LandscapeEdMode->CurrentToolTarget, TargetLoctaion); SelectedViewport->Invalidate(); UE_LOG(LogLandscapeAutomationTests, Display, TEXT("Modified the landscape using the sculpt tool")); return true; }
bool FLayers::RenameLayer( const FName OriginalLayerName, const FName& NewLayerName ) { // We specifically don't pass the original LayerName by reference to avoid it changing // it's original value, in case, it would be the reference of the Layer's actually FName if ( OriginalLayerName == NewLayerName ) { return false; } TWeakObjectPtr< ULayer > Layer; if( !TryGetLayer( OriginalLayerName, Layer ) ) { return false; } Layer->Modify(); Layer->LayerName = NewLayerName; Layer->ActorStats.Empty(); // Iterate over all actors, swapping layers. for( FActorIterator It(GetWorld()) ; It ; ++It ) { const TWeakObjectPtr< AActor > Actor = *It; if( !IsActorValidForLayer( Actor ) ) { continue; } if ( FLayers::RemoveActorFromLayer( Actor, OriginalLayerName ) ) { // No need to mark the actor as modified these functions take care of that AddActorToLayer( Actor, NewLayerName ); } } // update all views's hidden layers if they had this one for ( int32 ViewIndex = 0; ViewIndex < Editor->LevelViewportClients.Num(); ViewIndex++ ) { FLevelEditorViewportClient* ViewportClient = Editor->LevelViewportClients[ ViewIndex ]; if ( ViewportClient->ViewHiddenLayers.Remove( OriginalLayerName ) > 0 ) { ViewportClient->ViewHiddenLayers.AddUnique( NewLayerName ); ViewportClient->Invalidate(); } } LayersChanged.Broadcast( ELayersAction::Rename, Layer, "LayerName" ); return true; }
/** * Finds the viewport to use for the landscape tool */ static FLevelEditorViewportClient* FindSelectedViewport() { FLevelEditorViewportClient* SelectedViewport = NULL; for (int32 i = 0; i < GEditor->LevelViewportClients.Num(); i++) { FLevelEditorViewportClient* ViewportClient = GEditor->LevelViewportClients[i]; if (!ViewportClient->IsOrtho()) { SelectedViewport = ViewportClient; } } return SelectedViewport; }
/** * Returns the current flags state for the given show flag index. */ bool GetPerspectiveOriginalFlagstate(const int32& InFlagIndex, int32& OutViewportClientNumber) { // Switch the view port to perspective. FLevelEditorViewportClient* ViewportClient; for (int32 i = 0; i < GEditor->LevelViewportClients.Num(); i++) { ViewportClient = GEditor->LevelViewportClients[i]; if (ViewportClient->IsOrtho()) continue; OutViewportClientNumber = i; // Get the original show flag state for this show flag index. return ViewportClient->EngineShowFlags.GetSingleFlag(InFlagIndex); } return false; }
void FCameraCutTrackEditor::OnLockCameraClicked(ECheckBoxState CheckBoxState) { if (CheckBoxState == ECheckBoxState::Checked) { for (int32 i = 0; i < GEditor->LevelViewportClients.Num(); ++i) { FLevelEditorViewportClient* LevelVC = GEditor->LevelViewportClients[i]; if (LevelVC && LevelVC->IsPerspective() && LevelVC->AllowsCinematicPreview() && LevelVC->GetViewMode() != VMI_Unknown) { LevelVC->SetActorLock(nullptr); LevelVC->bLockedCameraView = false; LevelVC->UpdateViewForLockedActor(); LevelVC->Invalidate(); } } GetSequencer()->SetPerspectiveViewportCameraCutEnabled(true); } else { GetSequencer()->UpdateCameraCut(nullptr, nullptr); GetSequencer()->SetPerspectiveViewportCameraCutEnabled(false); } GetSequencer()->SetGlobalTime(GetSequencer()->GetGlobalTime()); }
void FThumbnailSection::PreDraw(FTrackEditorThumbnail& Thumbnail, FLevelEditorViewportClient& ViewportClient, FSceneViewport& SceneViewport) { TSharedPtr<ISequencer> Sequencer = SequencerPtr.Pin(); if (Sequencer.IsValid()) { Sequencer->EnterSilentMode(); AActor* Camera = nullptr; FDelegateHandle Handle = Sequencer->OnCameraCut().AddLambda([&](UObject* InObject, bool){ Camera = Cast<AActor>(InObject); }); SavedPlaybackStatus = Sequencer->GetPlaybackStatus(); Sequencer->SetPlaybackStatus(EMovieScenePlayerStatus::Jumping); Sequencer->SetGlobalTimeDirectly(Thumbnail.GetEvalPosition()); ViewportClient.SetActorLock(Camera); Sequencer->OnCameraCut().Remove(Handle); } }
/** * Does the update for volume actor visibility * * @param ActorsToUpdate The list of actors to update * @param ViewClient The viewport client to apply visibility changes to */ static void InternalUpdateVolumeActorVisibility( TArray<AActor*>& ActorsToUpdate, const FLevelEditorViewportClient& ViewClient, TArray<AActor*>& OutActorsThatChanged ) { for( int32 ActorIdx = 0; ActorIdx < ActorsToUpdate.Num(); ++ActorIdx ) { AVolume* VolumeToUpdate = Cast<AVolume>(ActorsToUpdate[ActorIdx]); if ( VolumeToUpdate ) { const bool bIsVisible = ViewClient.IsVolumeVisibleInViewport( *VolumeToUpdate ); uint64 OriginalViews = VolumeToUpdate->HiddenEditorViews; if( bIsVisible ) { // If the actor should be visible, unset the bit for the actor in this viewport VolumeToUpdate->HiddenEditorViews &= ~((uint64)1<<ViewClient.ViewIndex); } else { if( VolumeToUpdate->IsSelected() ) { // We are hiding the actor, make sure its not selected anymore GEditor->SelectActor( VolumeToUpdate, false, true ); } // If the actor should be hidden, set the bit for the actor in this viewport VolumeToUpdate->HiddenEditorViews |= ((uint64)1<<ViewClient.ViewIndex); } if( OriginalViews != VolumeToUpdate->HiddenEditorViews ) { // At least one actor has visibility changes OutActorsThatChanged.AddUnique( VolumeToUpdate ); } } } }
void FVertexSnappingImpl::SnapDragDelta( FVertexSnappingArgs& InArgs, const FVector& StartLocation, const FBox& AllowedSnappingBox, TSet< TWeakObjectPtr<AActor> >& ActorsToIgnore, FVector& DragDelta ) { const FSceneView* View = InArgs.SceneView; const FVector& DesiredUnsnappedLocation = InArgs.CurrentLocation; const FVector2D& MousePosition = InArgs.MousePosition; const EAxisList::Type CurrentAxis = InArgs.CurrentAxis; const FPlane ActorPlane = InArgs.ActorPlane; FLevelEditorViewportClient* ViewportClient = InArgs.ViewportClient; TArray<FSnapActor> PossibleSnapPointActors; GetPossibleSnapActors( AllowedSnappingBox, MousePosition.IntPoint(), ViewportClient, View, CurrentAxis, ActorsToIgnore, PossibleSnapPointActors ); FVector Direction = FVector( ActorPlane.X, ActorPlane.Y, ActorPlane.Z ); if( PossibleSnapPointActors.Num() > 0 ) { // Get the closest vertex to the desired location (before snapping) FVector ClosestPoint = GetClosestVertex( PossibleSnapPointActors, InArgs ).Position; FVector PrevDragDelta = DragDelta; float Distance = 0; if( CurrentAxis != EAxisList::Screen ) { // Compute a distance from the stat location to the snap point. // When not using the screen space translation we snap to the plane along the movement axis that the nearest vertex is on and not the vertex itself FPlane RealPlane( StartLocation, Direction ); Distance = RealPlane.PlaneDot( ClosestPoint ); // Snap to the plane DragDelta = Distance*Direction; } else { // Snap to the nearest vertex DragDelta = ClosestPoint-StartLocation; Distance = DragDelta.Size(); } const FVector& PreSnapLocation = StartLocation; // Compute snapped location after computing the new drag delta FVector SnappedLocation = StartLocation+DragDelta; if( ViewportClient->IsPerspective() ) { // Distance from start location to the location the actor would be in without snapping float DistFromPreSnapToDesiredUnsnapped = FVector::DistSquared( PreSnapLocation, DesiredUnsnappedLocation ); // Distance from the new location of the actor without snapping to the location with snapping float DistFromDesiredUnsnappedToSnapped = FVector::DistSquared( DesiredUnsnappedLocation, SnappedLocation ); // Only snap if the distance to the snapped location is less than the distance to the unsnapped location. // This allows the user to control the speed of snapping based on how fast they move the mouse and also avoids jerkiness when the mouse is behind the snap location if( (CurrentAxis != EAxisList::Screen && DistFromDesiredUnsnappedToSnapped >= DistFromPreSnapToDesiredUnsnapped) || ClosestPoint == DesiredUnsnappedLocation ) { DragDelta = FVector::ZeroVector; } } else { FVector2D PreSnapLocationPixel; View->WorldToPixel( PreSnapLocation, PreSnapLocationPixel ); FVector2D SnappedLocationPixel; View->WorldToPixel( SnappedLocation, SnappedLocationPixel ); FVector2D SLtoML = SnappedLocationPixel-MousePosition; FVector2D PStoML = MousePosition-PreSnapLocationPixel; // Only snap if the distance to the snapped location is less than the distance to the unsnapped location float Dist2 = PStoML.SizeSquared(); float Dist1 = SLtoML.SizeSquared(); if( Dist1 >= Dist2 || ClosestPoint == DesiredUnsnappedLocation ) { DragDelta = FVector::ZeroVector; } } } }