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(); }
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); } }