FMaterialEditorViewportClient::FMaterialEditorViewportClient(TWeakPtr<IMaterialEditor> InMaterialEditor, FPreviewScene& InPreviewScene, const TSharedRef<SMaterialEditorViewport>& InMaterialEditorViewport)
	: FEditorViewportClient(nullptr, &InPreviewScene, StaticCastSharedRef<SEditorViewport>(InMaterialEditorViewport))
	, MaterialEditorPtr(InMaterialEditor)
{
	// Setup defaults for the common draw helper.
	DrawHelper.bDrawPivot = false;
	DrawHelper.bDrawWorldBox = false;
	DrawHelper.bDrawKillZ = false;
	DrawHelper.bDrawGrid = false;
	DrawHelper.GridColorAxis = FColor(80,80,80);
	DrawHelper.GridColorMajor = FColor(72,72,72);
	DrawHelper.GridColorMinor = FColor(64,64,64);
	DrawHelper.PerspectiveGridSize = HALF_WORLD_MAX1;
	
	SetViewMode(VMI_Lit);
	
	EngineShowFlags.DisableAdvancedFeatures();
	EngineShowFlags.SetSnap(0);

	OverrideNearClipPlane(1.0f);
	bUsingOrbitCamera = true;

	// Don't want to display the widget in this viewport
	Widget->SetDefaultVisibility(false);
}
FStaticMeshEditorViewportClient::FStaticMeshEditorViewportClient(TWeakPtr<IStaticMeshEditor> InStaticMeshEditor, TWeakPtr<SStaticMeshEditorViewport> InStaticMeshEditorViewport, FPreviewScene& InPreviewScene, UStaticMesh* InPreviewStaticMesh, UStaticMeshComponent* InPreviewStaticMeshComponent)
	: FEditorViewportClient(GLevelEditorModeTools(), &InPreviewScene)
	, StaticMeshEditorPtr(InStaticMeshEditor)
	, StaticMeshEditorViewportPtr(InStaticMeshEditorViewport)
{
	SimplygonLogo = LoadObject<UTexture2D>(NULL, TEXT("/Engine/EditorResources/SimplygonLogo.SimplygonLogo"), NULL, LOAD_None, NULL);

	// Setup defaults for the common draw helper.
	DrawHelper.bDrawPivot = false;
	DrawHelper.bDrawWorldBox = false;
	DrawHelper.bDrawKillZ = false;
	DrawHelper.bDrawGrid = true;
	DrawHelper.GridColorAxis = FColor(160,160,160);
	DrawHelper.GridColorMajor = FColor(144,144,144);
	DrawHelper.GridColorMinor = FColor(128,128,128);
	DrawHelper.PerspectiveGridSize = GridSize;
	DrawHelper.NumCells = DrawHelper.PerspectiveGridSize / (CellSize * 2);

	SetViewMode(VMI_Lit);

	WidgetMode = FWidget::WM_None;

	EngineShowFlags.DisableAdvancedFeatures();
	EngineShowFlags.SetSnap(0);
	EngineShowFlags.CompositeEditorPrimitives = true;
	OverrideNearClipPlane(1.0f);
	bUsingOrbitCamera = true;

	bShowCollision = true;
	bShowSockets = true;
	bDrawUVs = false;
	bDrawNormals = false;
	bDrawTangents = false;
	bDrawBinormals = false;
	bShowPivot = false;
	bDrawAdditionalData = true;

	bManipulating = false;

	SetPreviewMesh(InPreviewStaticMesh, InPreviewStaticMeshComponent);
}
FDestructibleMeshEditorViewportClient::FDestructibleMeshEditorViewportClient(TWeakPtr<IDestructibleMeshEditor> InDestructibleMeshEditor, FPreviewScene& InPreviewScene, const TSharedRef<SDestructibleMeshEditorViewport>& InDestructibleMeshEditorViewport)
	: FEditorViewportClient(nullptr, &InPreviewScene, StaticCastSharedRef<SEditorViewport>(InDestructibleMeshEditorViewport))
	, DestructibleMeshEditorPtr(InDestructibleMeshEditor)
{
	SetViewMode(VMI_Lit);

	OverrideNearClipPlane(1.0f);
	bUsingOrbitCamera = true;

	UpdateLighting();

	// Setup defaults for the common draw helper.
	DrawHelper.bDrawPivot = false;
	DrawHelper.bDrawWorldBox = false;
	DrawHelper.bDrawKillZ = false;
	DrawHelper.bDrawGrid = true;
	DrawHelper.GridColorAxis = FColor(70, 70, 70);
	DrawHelper.GridColorMajor = FColor(40, 40, 40);
	DrawHelper.GridColorMinor =  FColor(20, 20, 20);
	DrawHelper.PerspectiveGridSize = HALF_WORLD_MAX1;
}
FNiagaraEffectEditorViewportClient::FNiagaraEffectEditorViewportClient(TWeakPtr<INiagaraEffectEditor> InEffectEditor, FPreviewScene& InPreviewScene, const TSharedRef<SNiagaraEffectEditorViewport>& InNiagaraEditorViewport)
	: FEditorViewportClient(nullptr, &InPreviewScene, StaticCastSharedRef<SEditorViewport>(InNiagaraEditorViewport))
	, EffectEditorPtr(InEffectEditor)
{
	// Setup defaults for the common draw helper.
	DrawHelper.bDrawPivot = false;
	DrawHelper.bDrawWorldBox = false;
	DrawHelper.bDrawKillZ = false;
	DrawHelper.bDrawGrid = false;
	DrawHelper.GridColorAxis = FColor(80,80,80);
	DrawHelper.GridColorMajor = FColor(72,72,72);
	DrawHelper.GridColorMinor = FColor(64,64,64);
	DrawHelper.PerspectiveGridSize = HALF_WORLD_MAX1;
	
	SetViewMode(VMI_Lit);
	
	EngineShowFlags.DisableAdvancedFeatures();
	EngineShowFlags.SetSnap(0);
	
	OverrideNearClipPlane(1.0f);
	bUsingOrbitCamera = true;
}
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);
	}
}