Skip to content

Instantly share code, notes, and snippets.

@dilne
Created February 24, 2022 20:36
Show Gist options
  • Save dilne/f2c3ee67fdf5fd66f55752b93087663c to your computer and use it in GitHub Desktop.
Save dilne/f2c3ee67fdf5fd66f55752b93087663c to your computer and use it in GitHub Desktop.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
class ASceneCapture2D; //forward declaration
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CaptureManager.generated.h"
USTRUCT()
struct FRenderRequest {
GENERATED_BODY()
TArray<FColor> Image;
FRenderCommandFence RenderFence;
bool isPNG;
FRenderRequest() {
isPNG = false;
}
};
UCLASS()
class TIMMHESS_API ACaptureManager : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ACaptureManager();
// Color Capture Components
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Capture")
ASceneCapture2D* ColorCaptureComponents;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
void SetupColorCaptureComponents(ASceneCapture2D* captureComponent);
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
protected:
// RenderRequest Queue
TQueue<FRenderRequest*> RenderRequestQueue;
public:
UFUNCTION(BlueprintCallable, Category = "ImageCapture")
void CaptureColorNonBlocking(ASceneCapture2D* CaptureComponent, bool IsSegmentation = false);
protected:
// Creates an async task that will save the captured image to disk
void RunAsyncImageSaveTask(TArray<uint8> Image, FString ImageName);
};
class AsyncSaveImageToDiskTask : public FNonAbandonableTask {
public:
AsyncSaveImageToDiskTask(TArray<uint8> Image, FString ImageName);
~AsyncSaveImageToDiskTask();
// Required by UE4!
FORCEINLINE TStatId GetStatId() const {
RETURN_QUICK_DECLARE_CYCLE_STAT(AsyncSaveImageToDiskTask, STATGROUP_ThreadPoolAsyncTasks);
}
protected:
TArray<uint8> ImageCopy;
FString FileName = "test";
public:
void DoWork();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment