void CPlayerRotation::SetViewRotationOnRevive( const Quat &rotation ) { SetViewRotation( rotation ); m_viewAngles.x = 0.0f; m_viewAngles.y = 0.0f; m_viewRoll = 0.0f; }
void FCascadeEdPreviewViewportClient::SetPreviewCamera(const FRotator& NewPreviewAngle, float NewPreviewDistance) { PreviewAngle = NewPreviewAngle; PreviewDistance = NewPreviewDistance; SetViewLocation( PreviewAngle.Vector() * -PreviewDistance ); SetViewRotation( PreviewAngle ); Viewport->Invalidate(); }
void FDestructibleMeshEditorViewportClient::SetPreviewComponent( UDestructibleComponent* InPreviewDestructibleComp ) { PreviewDestructibleComp = InPreviewDestructibleComp; UDestructibleMesh* DestructibleMesh = DestructibleMeshEditorPtr.Pin()->GetDestructibleMesh(); if (DestructibleMesh != NULL) { SetViewLocation( FVector(0,-DestructibleMesh->Bounds.SphereRadius / (75.0f * (float)PI / 360.0f),0.5f*DestructibleMesh->Bounds.BoxExtent.Z) ); SetViewRotation( FRotator(0,90.f,0) ); } }
void FStaticMeshEditorViewportClient::SetPreviewMesh(UStaticMesh* InStaticMesh, UStaticMeshComponent* InStaticMeshComponent) { StaticMesh = InStaticMesh; StaticMeshComponent = InStaticMeshComponent; // If we have a thumbnail transform, we will favor that over the camera position as the user may have customized this for a nice view // If we have neither a custom thumbnail nor a valid camera position, then we'll just use the default thumbnail transform const USceneThumbnailInfo* const AssetThumbnailInfo = Cast<USceneThumbnailInfo>(StaticMesh->ThumbnailInfo); const USceneThumbnailInfo* const DefaultThumbnailInfo = USceneThumbnailInfo::StaticClass()->GetDefaultObject<USceneThumbnailInfo>(); // Prefer the asset thumbnail if available const USceneThumbnailInfo* const ThumbnailInfo = (AssetThumbnailInfo) ? AssetThumbnailInfo : DefaultThumbnailInfo; check(ThumbnailInfo); FRotator ThumbnailAngle; ThumbnailAngle.Pitch = ThumbnailInfo->OrbitPitch; ThumbnailAngle.Yaw = ThumbnailInfo->OrbitYaw; ThumbnailAngle.Roll = 0; const float ThumbnailDistance = ThumbnailInfo->OrbitZoom; const float CameraY = StaticMesh->GetBounds().SphereRadius / (75.0f * PI / 360.0f); SetCameraSetup( FVector::ZeroVector, ThumbnailAngle, FVector(0.0f, CameraY + ThumbnailDistance - AutoViewportOrbitCameraTranslate, 0.0f), StaticMesh->GetBounds().Origin, -FVector(0, CameraY, 0), FRotator(0,90.f,0) ); if(!AssetThumbnailInfo && StaticMesh->EditorCameraPosition.bIsSet) { // The static mesh editor saves the camera position in terms of an orbit camera, so ensure // that orbit mode is enabled before we set the new transform information const bool bWasOrbit = bUsingOrbitCamera; ToggleOrbitCamera(true); SetViewRotation(StaticMesh->EditorCameraPosition.CamOrbitRotation); SetViewLocation(StaticMesh->EditorCameraPosition.CamOrbitPoint + StaticMesh->EditorCameraPosition.CamOrbitZoom); SetLookAtLocation(StaticMesh->EditorCameraPosition.CamOrbitPoint); ToggleOrbitCamera(bWasOrbit); } }
void FSCSEditorViewportClient::ResetCamera() { UBlueprint* Blueprint = BlueprintEditorPtr.Pin()->GetBlueprintObj(); // For now, loosely base default camera positioning on thumbnail preview settings USceneThumbnailInfo* ThumbnailInfo = Cast<USceneThumbnailInfo>(Blueprint->ThumbnailInfo); if(ThumbnailInfo) { if(PreviewActorBounds.SphereRadius + ThumbnailInfo->OrbitZoom < 0) { ThumbnailInfo->OrbitZoom = -PreviewActorBounds.SphereRadius; } } else { ThumbnailInfo = USceneThumbnailInfo::StaticClass()->GetDefaultObject<USceneThumbnailInfo>(); } ToggleOrbitCamera(true); { float TargetDistance = PreviewActorBounds.SphereRadius; if(TargetDistance <= 0.0f) { TargetDistance = AutoViewportOrbitCameraTranslate; } FRotator ThumbnailAngle(ThumbnailInfo->OrbitPitch, ThumbnailInfo->OrbitYaw, 0.0f); SetViewLocationForOrbiting(PreviewActorBounds.Origin); SetViewLocation( GetViewLocation() + FVector(0.0f, TargetDistance * 1.5f + ThumbnailInfo->OrbitZoom - AutoViewportOrbitCameraTranslate, 0.0f) ); SetViewRotation( ThumbnailAngle ); } Invalidate(); }
FCascadeEdPreviewViewportClient::FCascadeEdPreviewViewportClient(TWeakPtr<FCascade> InCascade, const TSharedRef<SCascadePreviewViewport>& InCascadeViewport) : FEditorViewportClient(nullptr, nullptr, StaticCastSharedRef<SEditorViewport>(InCascadeViewport)) , CascadePtr(InCascade) , CascadePreviewScene(FPreviewScene::ConstructionValues() .SetLightRotation(FRotator(-45.f, 180.f, 0.f)) .SetSkyBrightness(0.25f) .SetLightBrightness(1.f)) , VectorFieldHitproxyInfo(0) , LightRotSpeed(0.22f) { PreviewScene = &CascadePreviewScene; check(CascadePtr.IsValid() && EditorViewportWidget.IsValid()); UParticleSystem* ParticleSystem = CascadePtr.Pin()->GetParticleSystem(); UCascadeParticleSystemComponent* ParticleSystemComponent = CascadePtr.Pin()->GetParticleSystemComponent(); UVectorFieldComponent* LocalVectorFieldPreviewComponent = CascadePtr.Pin()->GetLocalVectorFieldComponent(); UCascadeOptions* EditorOptions = CascadePtr.Pin()->GetEditorOptions(); check(EditorOptions); // Create ParticleSystemComponent to use for preview. ParticleSystemComponent->CascadePreviewViewportPtr = this; ParticleSystemComponent->CastShadow = true; CascadePreviewScene.AddComponent(ParticleSystemComponent, FTransform::Identity); ParticleSystemComponent->SetFlags(RF_Transactional); // Create a component for previewing local vector fields. LocalVectorFieldPreviewComponent->bPreviewVectorField = true; LocalVectorFieldPreviewComponent->SetVisibility(false); CascadePreviewScene.AddComponent(LocalVectorFieldPreviewComponent,FTransform::Identity); // Use game defaults to hide emitter sprite etc., but we want to still show the Axis widget in the corner... // todo: seems this cold be done cleaner EngineShowFlags = FEngineShowFlags(ESFIM_Game); EngineShowFlags.Game = 0; EngineShowFlags.SetSnap(0); SetViewMode(VMI_Lit); EngineShowFlags.DisableAdvancedFeatures(); EngineShowFlags.SetCompositeEditorPrimitives(true); EngineShowFlags.SeparateTranslucency = true; OverrideNearClipPlane(1.0f); SetViewLocation( FVector(-200.f, 0.f, 0.f) ); SetViewRotation( FRotator::ZeroRotator ); PreviewAngle = FRotator::ZeroRotator; PreviewDistance = 0.f; bCaptureScreenShot = false; BackgroundColor = FColor::Black; WidgetAxis = EAxisList::None; WidgetMM = WMM_Translate; bManipulatingVectorField = false; DrawFlags = ParticleCounts | ParticleSystemCompleted; bUsingOrbitCamera = true; WireSphereRadius = 150.0f; FColor GridColorAxis(0, 0, 80); FColor GridColorMajor(0, 0, 72); FColor GridColorMinor(0, 0, 64); GridColorAxis = CascadePtr.Pin()->GetEditorOptions()->GridColor_Hi; GridColorMajor = CascadePtr.Pin()->GetEditorOptions()->GridColor_Low; GridColorMinor = CascadePtr.Pin()->GetEditorOptions()->GridColor_Low; DrawHelper.bDrawGrid = CascadePtr.Pin()->GetEditorOptions()->bShowGrid; DrawHelper.GridColorAxis = GridColorAxis; DrawHelper.GridColorMajor = GridColorMajor; DrawHelper.GridColorMinor = GridColorMinor; DrawHelper.bDrawKillZ = false; DrawHelper.bDrawWorldBox = false; DrawHelper.bDrawPivot = false; DrawHelper.PerspectiveGridSize = CascadePtr.Pin()->GetEditorOptions()->GridPerspectiveSize; DrawHelper.DepthPriorityGroup = SDPG_World; if (DrawHelper.bDrawGrid) { EngineShowFlags.SetGrid(true); } if (EditorOptions->FloorMesh == TEXT("")) { if (ParticleSystem != NULL) { EditorOptions->FloorMesh = ParticleSystem->FloorMesh; EditorOptions->FloorScale = ParticleSystem->FloorScale; EditorOptions->FloorScale3D = ParticleSystem->FloorScale3D; } else { EditorOptions->FloorMesh = FString::Printf(TEXT("/Engine/EditorMeshes/AnimTreeEd_PreviewFloor.AnimTreeEd_PreviewFloor")); EditorOptions->FloorScale = 1.0f; EditorOptions->FloorScale3D = FVector(1.0f, 1.0f, 1.0f); } EditorOptions->bShowFloor = false; } UStaticMesh* Mesh = NULL; FloorComponent = NULL; if (ParticleSystem) { Mesh = (UStaticMesh*)StaticLoadObject(UStaticMesh::StaticClass(),NULL, *(ParticleSystem->FloorMesh),NULL,LOAD_None,NULL); } if ((Mesh == NULL) && (EditorOptions->FloorMesh != TEXT(""))) { Mesh = (UStaticMesh*)StaticLoadObject(UStaticMesh::StaticClass(),NULL, *(EditorOptions->FloorMesh),NULL,LOAD_None,NULL); } if (Mesh == NULL) { // Safety catch... EditorOptions->FloorMesh = FString::Printf(TEXT("/Engine/EditorMeshes/AnimTreeEd_PreviewFloor.AnimTreeEd_PreviewFloor")); Mesh = (UStaticMesh*)StaticLoadObject(UStaticMesh::StaticClass(),NULL, *(EditorOptions->FloorMesh),NULL,LOAD_None,NULL); } if (Mesh) { FloorComponent = NewObject<UStaticMeshComponent>(GetTransientPackage(), TEXT("FloorComponent")); check(FloorComponent); FloorComponent->StaticMesh = Mesh; FloorComponent->DepthPriorityGroup = SDPG_World; // Hide it for now... FloorComponent->SetVisibility(EditorOptions->bShowFloor); if (ParticleSystem) { FloorComponent->RelativeLocation = ParticleSystem->FloorPosition; FloorComponent->RelativeRotation = ParticleSystem->FloorRotation; FloorComponent->SetRelativeScale3D(ParticleSystem->FloorScale3D); } else { FloorComponent->RelativeLocation = EditorOptions->FloorPosition; FloorComponent->RelativeRotation = EditorOptions->FloorRotation; FloorComponent->SetRelativeScale3D(EditorOptions->FloorScale3D); } FPhysScene* PhysScene = new FPhysScene(); CascadePreviewScene.GetWorld()->SetPhysicsScene(PhysScene); CascadePreviewScene.AddComponent(FloorComponent,FTransform::Identity); } }
FPhATEdPreviewViewportClient::FPhATEdPreviewViewportClient(TWeakPtr<FPhAT> InPhAT, TSharedPtr<FPhATSharedData> Data, const TSharedRef<SPhATPreviewViewport>& InPhATPreviewViewport) : FEditorViewportClient(nullptr, &Data->PreviewScene, StaticCastSharedRef<SEditorViewport>(InPhATPreviewViewport)) , PhATPtr(InPhAT) , SharedData(Data) , MinPrimSize(0.5f) , PhAT_TranslateSpeed(0.25f) , PhAT_RotateSpeed(1.0 * (PI / 180.0)) , PhAT_LightRotSpeed(0.22f) , SimGrabCheckDistance(5000.0f) , SimHoldDistanceChangeDelta(20.0f) , SimMinHoldDistance(10.0f) , SimGrabMoveSpeed(1.0f) { check(PhATPtr.IsValid()); ModeTools->SetWidgetMode(FWidget::EWidgetMode::WM_Translate); ModeTools->SetCoordSystem(COORD_Local); bAllowedToMoveCamera = true; // Setup defaults for the common draw helper. DrawHelper.bDrawPivot = false; DrawHelper.bDrawWorldBox = false; DrawHelper.bDrawKillZ = false; DrawHelper.GridColorAxis = FColor(80,80,80); DrawHelper.GridColorMajor = FColor(72,72,72); DrawHelper.GridColorMinor = FColor(64,64,64); DrawHelper.PerspectiveGridSize = 32767; PhATFont = GEngine->GetSmallFont(); check(PhATFont); EngineShowFlags.DisableAdvancedFeatures(); EngineShowFlags.SetSeparateTranslucency(true); EngineShowFlags.SetCompositeEditorPrimitives(true); // Get actors asset collision bounding box, and move actor so its not intersection the floor plane at Z = 0. FBox CollBox = SharedData->PhysicsAsset->CalcAABB(SharedData->EditorSkelComp, SharedData->EditorSkelComp->ComponentToWorld); FVector SkelCompLocation = FVector(0, 0, -CollBox.Min.Z + SharedData->EditorSimOptions->FloorGap); SharedData->EditorSkelComp->SetAbsolute(true, true, true); SharedData->EditorSkelComp->SetRelativeLocation(SkelCompLocation); SharedData->ResetTM = SharedData->EditorSkelComp->GetComponentToWorld(); // Get new bounding box and set view based on that. CollBox = SharedData->PhysicsAsset->CalcAABB(SharedData->EditorSkelComp, SharedData->EditorSkelComp->ComponentToWorld); FVector CollBoxExtent = CollBox.GetExtent(); // Take into account internal mesh translation/rotation/scaling etc. FTransform LocalToWorld = SharedData->EditorSkelComp->ComponentToWorld; FSphere WorldSphere = SharedData->EditorSkelMesh->GetImportedBounds().GetSphere().TransformBy(LocalToWorld); CollBoxExtent = CollBox.GetExtent(); if (CollBoxExtent.X > CollBoxExtent.Y) { SetViewLocation( FVector(WorldSphere.Center.X, WorldSphere.Center.Y - 1.5*WorldSphere.W, WorldSphere.Center.Z) ); SetViewRotation( EditorViewportDefs::DefaultPerspectiveViewRotation ); } else { SetViewLocation( FVector(WorldSphere.Center.X - 1.5*WorldSphere.W, WorldSphere.Center.Y, WorldSphere.Center.Z) ); SetViewRotation( FRotator::ZeroRotator ); } SetViewLocationForOrbiting(FVector::ZeroVector); SetViewModes(VMI_Lit, VMI_Lit); SetCameraSpeedSetting(3); bUsingOrbitCamera = true; if (!FPhAT::IsPIERunning()) { SetRealtime(true); } }