添加 Source/FLESHEditor/Private/FLESHViewportClient.cpp
This commit is contained in:
175
Source/FLESHEditor/Private/FLESHViewportClient.cpp
Normal file
175
Source/FLESHEditor/Private/FLESHViewportClient.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
#include "FLESHViewportClient.h"
|
||||
#include "FLESHEditor.h"
|
||||
#include "CanvasItem.h"
|
||||
#include "CanvasTypes.h"
|
||||
#include "Engine/SkeletalMesh.h"
|
||||
#include "Components/SkeletalMeshComponent.h"
|
||||
#include "Slate/SceneViewport.h"
|
||||
|
||||
FFLESHViewportClient::FFLESHViewportClient(FFLESHEditor* InEditor)
|
||||
: FEditorViewportClient(nullptr)
|
||||
, Viewport(nullptr)
|
||||
, Editor(InEditor)
|
||||
, bShowWireframe(false)
|
||||
, bShowBones(false)
|
||||
{
|
||||
// Create a valid viewport scene
|
||||
PreviewScene = MakeShareable(new FPreviewScene(FPreviewScene::ConstructionValues()));
|
||||
|
||||
// Set the scene for FEditorViewportClient - use constructor instead of SetPreviewScene
|
||||
FEditorViewportClient::PreviewScene = PreviewScene.Get();
|
||||
|
||||
// Set viewport type
|
||||
SetViewportType(LVT_Perspective);
|
||||
|
||||
// Enable real-time rendering
|
||||
SetRealtime(true);
|
||||
|
||||
// Set initial view position and rotation
|
||||
SetInitialViewTransform(
|
||||
LVT_Perspective,
|
||||
FVector(0.0f, 100.0f, 0.0f), // Camera position
|
||||
FRotator(0.0f, -90.0f, 0.0f), // Camera rotation
|
||||
200.0f // Camera distance
|
||||
);
|
||||
|
||||
// Enable camera controls
|
||||
EngineShowFlags.SetPostProcessing(true);
|
||||
EngineShowFlags.SetLighting(true);
|
||||
EngineShowFlags.SetIndirectLightingCache(true);
|
||||
EngineShowFlags.SetTemporalAA(true);
|
||||
|
||||
// Set default render mode
|
||||
SetViewMode(VMI_Lit);
|
||||
}
|
||||
|
||||
FFLESHViewportClient::~FFLESHViewportClient()
|
||||
{
|
||||
// Clean up resources
|
||||
}
|
||||
|
||||
void FFLESHViewportClient::Draw(const FSceneView* View, FPrimitiveDrawInterface* PDI)
|
||||
{
|
||||
FEditorViewportClient::Draw(View, PDI);
|
||||
|
||||
// Draw custom UI elements
|
||||
if (Viewport)
|
||||
{
|
||||
FCanvas* Canvas = Viewport->GetDebugCanvas();
|
||||
if (Canvas)
|
||||
{
|
||||
// Draw mode information
|
||||
FString ModeText;
|
||||
if (bShowWireframe)
|
||||
{
|
||||
ModeText += TEXT("Wireframe Mode | ");
|
||||
}
|
||||
if (bShowBones)
|
||||
{
|
||||
ModeText += TEXT("Show Bones | ");
|
||||
}
|
||||
|
||||
if (!ModeText.IsEmpty())
|
||||
{
|
||||
// Remove last separator
|
||||
ModeText.RemoveAt(ModeText.Len() - 3, 3);
|
||||
|
||||
// Draw text
|
||||
FCanvasTextItem TextItem(FVector2D(10, 10), FText::FromString(ModeText), GEngine->GetSmallFont(), FLinearColor::White);
|
||||
Canvas->DrawItem(TextItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool FFLESHViewportClient::InputKey(const FInputKeyEventArgs& EventArgs)
|
||||
{
|
||||
// Handle keyboard and mouse input
|
||||
bool bHandled = false;
|
||||
|
||||
// Add custom shortcuts
|
||||
if (EventArgs.Event == IE_Pressed)
|
||||
{
|
||||
if (EventArgs.Key == EKeys::W)
|
||||
{
|
||||
// W key toggles wireframe mode
|
||||
ToggleWireframe();
|
||||
bHandled = true;
|
||||
}
|
||||
else if (EventArgs.Key == EKeys::B)
|
||||
{
|
||||
// B key toggles bone display
|
||||
ToggleBones();
|
||||
bHandled = true;
|
||||
}
|
||||
else if (EventArgs.Key == EKeys::R)
|
||||
{
|
||||
// R key resets camera
|
||||
ResetCamera();
|
||||
bHandled = true;
|
||||
}
|
||||
else if (EventArgs.Key == EKeys::F)
|
||||
{
|
||||
// F key focuses on selected object
|
||||
// TODO: Add logic to focus on the selected object
|
||||
bHandled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If not handled, pass to base class
|
||||
if (!bHandled)
|
||||
{
|
||||
bHandled = FEditorViewportClient::InputKey(EventArgs);
|
||||
}
|
||||
|
||||
return bHandled;
|
||||
}
|
||||
|
||||
bool FFLESHViewportClient::InputKey(FViewport* InViewport, int32 ControllerId, FKey Key, EInputEvent Event, float AmountDepressed, bool bGamepad)
|
||||
{
|
||||
// Create new parameter structure and call the new version of InputKey
|
||||
FInputKeyEventArgs Args(InViewport, ControllerId, Key, Event, AmountDepressed, false);
|
||||
|
||||
// Forward to the new API version
|
||||
return InputKey(Args);
|
||||
}
|
||||
|
||||
void FFLESHViewportClient::ResetCamera()
|
||||
{
|
||||
// Reset camera position and rotation
|
||||
SetViewLocation(FVector(0.0f, 100.0f, 0.0f));
|
||||
SetViewRotation(FRotator(0.0f, -90.0f, 0.0f));
|
||||
|
||||
// Invalidate view
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void FFLESHViewportClient::ToggleWireframe()
|
||||
{
|
||||
// Toggle wireframe mode
|
||||
bShowWireframe = !bShowWireframe;
|
||||
|
||||
if (bShowWireframe)
|
||||
{
|
||||
SetViewMode(VMI_Wireframe);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetViewMode(VMI_Lit);
|
||||
}
|
||||
|
||||
// Invalidate view
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
void FFLESHViewportClient::ToggleBones()
|
||||
{
|
||||
// Toggle bone display
|
||||
bShowBones = !bShowBones;
|
||||
|
||||
// Update engine flags
|
||||
EngineShowFlags.SetBones(bShowBones);
|
||||
|
||||
// Invalidate view
|
||||
Invalidate();
|
||||
}
|
Reference in New Issue
Block a user