ultimate-unreal-engine-mcp 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
#include "HAL/FileManager.h"
|
|
34
34
|
#include "Misc/FileHelper.h"
|
|
35
35
|
#include "ImageUtils.h"
|
|
36
|
+
#include "RenderingThread.h"
|
|
36
37
|
#include "Engine/World.h"
|
|
37
38
|
#include "GameFramework/Actor.h"
|
|
38
39
|
#include "EngineUtils.h"
|
|
@@ -207,50 +208,24 @@ static FString TakeScreenshotToFile(int32 Width, int32 Height)
|
|
|
207
208
|
return FString();
|
|
208
209
|
}
|
|
209
210
|
|
|
210
|
-
// Enable realtime rendering so the viewport
|
|
211
|
+
// Enable realtime rendering so the viewport continuously renders frames.
|
|
211
212
|
// Without this, the editor viewport only renders when "dirty" and
|
|
212
|
-
//
|
|
213
|
-
const bool bWasRealtime = ViewportClient->IsRealtime();
|
|
213
|
+
// FScreenshotRequest never gets picked up on subsequent calls.
|
|
214
214
|
ViewportClient->SetRealtime(true);
|
|
215
215
|
|
|
216
|
-
// Force a full viewport redraw. Invalidate marks it dirty,
|
|
217
|
-
// then Draw executes the render pipeline synchronously.
|
|
218
|
-
ViewportClient->Viewport->Invalidate();
|
|
219
|
-
ViewportClient->Viewport->Draw();
|
|
220
|
-
|
|
221
|
-
// Read pixels from the viewport framebuffer.
|
|
222
|
-
TArray<FColor> Pixels;
|
|
223
|
-
const bool bReadOk = ViewportClient->Viewport->ReadPixels(Pixels);
|
|
224
|
-
|
|
225
|
-
// Restore previous realtime state.
|
|
226
|
-
if (!bWasRealtime)
|
|
227
|
-
{
|
|
228
|
-
ViewportClient->SetRealtime(false);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
if (!bReadOk)
|
|
232
|
-
{
|
|
233
|
-
return FString();
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const int32 VPWidth = ViewportClient->Viewport->GetSizeXY().X;
|
|
237
|
-
const int32 VPHeight = ViewportClient->Viewport->GetSizeXY().Y;
|
|
238
|
-
|
|
239
|
-
if (Pixels.Num() != VPWidth * VPHeight || VPWidth == 0 || VPHeight == 0)
|
|
240
|
-
{
|
|
241
|
-
return FString();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Compress to PNG.
|
|
245
|
-
TArray64<uint8> PngData;
|
|
246
|
-
FImageUtils::PNGCompressImageArray(VPWidth, VPHeight, Pixels, PngData);
|
|
247
|
-
|
|
248
|
-
// Write to file.
|
|
249
216
|
const FString Timestamp = FDateTime::Now().ToString(TEXT("%Y%m%d_%H%M%S_%s"));
|
|
250
217
|
const FString FileName = FString::Printf(TEXT("mcp_screenshot_%s.png"), *Timestamp);
|
|
251
218
|
const FString FilePath = FPaths::Combine(GetMCPScreenshotDir(), FileName);
|
|
252
219
|
|
|
253
|
-
|
|
220
|
+
GScreenshotResolutionX = Width;
|
|
221
|
+
GScreenshotResolutionY = Height;
|
|
222
|
+
|
|
223
|
+
// Invalidate to ensure the viewport redraws with current camera state.
|
|
224
|
+
ViewportClient->Viewport->Invalidate();
|
|
225
|
+
|
|
226
|
+
// Request screenshot to a specific file path. With realtime enabled,
|
|
227
|
+
// the renderer will process this on the next frame.
|
|
228
|
+
FScreenshotRequest::RequestScreenshot(FilePath, false /* bShowUI */, false /* bAddFilenameSuffix */);
|
|
254
229
|
|
|
255
230
|
return FilePath;
|
|
256
231
|
}
|
|
@@ -359,7 +334,7 @@ void RegisterViewportCommands(FMCPCommandRouter& Router)
|
|
|
359
334
|
Data->SetStringField(TEXT("file_path"), FilePath);
|
|
360
335
|
Data->SetNumberField(TEXT("width"), static_cast<double>(Width));
|
|
361
336
|
Data->SetNumberField(TEXT("height"), static_cast<double>(Height));
|
|
362
|
-
Data->SetBoolField(TEXT("
|
|
337
|
+
Data->SetBoolField(TEXT("async"), true);
|
|
363
338
|
|
|
364
339
|
SendResponse(BuildViewportSuccessResponse(CorrId, Data) + TEXT("\n"));
|
|
365
340
|
});
|