Skip to content

Commit

Permalink
Merge pull request #33 from stereolabs/ue5.2_main
Browse files Browse the repository at this point in the history
Ue5.2 main
  • Loading branch information
SLJLMacarit authored Oct 18, 2023
2 parents eefa745 + 1ca4339 commit 1b7dff0
Show file tree
Hide file tree
Showing 24 changed files with 3,235 additions and 1,846 deletions.
Binary file not shown.
Binary file modified Content/ZED/Levels/L_BodyTrackingSingle.umap
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
//);

AEnvironmentalLightingManager::AEnvironmentalLightingManager()
:
Batch(nullptr),
LeftEyeTexture(nullptr),
Light(nullptr),
EnvironmentalLightingIntensity(1.0f),
bEnableEnvironmentalLighting(true)
:
Light( nullptr ),
bEnableEnvironmentalLighting( true ),
EnvironmentalLightingIntensity( 1.0f ),
LeftEyeTexture( nullptr ),
Batch( nullptr )
{
PrimaryActorTick.bCanEverTick = true;
}
Expand Down Expand Up @@ -120,4 +120,4 @@ void AEnvironmentalLightingManager::GrabCallback(ESlErrorCode ErrorCode, const F
}

Batch->RetrieveCurrentFrame(Timestamp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

ASpatialMappingManager::ASpatialMappingManager()
:
MeshFileFormat(ESlMeshFileFormat::MFF_OBJ),
bStepFailed(false),
SpatialMappingWorker(nullptr),
UpdateTime(0.0f),
bSpatialMappingPaused(false),
bShowMesh(true)
MeshFileFormat( ESlMeshFileFormat::MFF_OBJ ),
bShowMesh( true ),
bStepFailed( false ),
SpatialMappingWorker( nullptr ),
UpdateTime( 0.0f ),
bSpatialMappingPaused( false )
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.TickGroup = ETickingGroup::TG_PrePhysics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void FSpatialMappingCubemapRunnable::GetPixels()
break;
}

FTextureRenderTargetCubeResource* CubeResource = (FTextureRenderTargetCubeResource*)static_cast<FTextureRenderTargetResource*>(CubemapProxy->TextureTarget->Resource);
FTextureRenderTargetCubeResource* CubeResource = (FTextureRenderTargetCubeResource*)static_cast<FTextureRenderTargetResource*>(CubemapProxy->TextureTarget->GetResource());

if (CubeResource && TextureFormat != TSF_Invalid)
{
Expand Down Expand Up @@ -154,26 +154,27 @@ void FSpatialMappingCubemapRunnable::ConverToTextureCube()

int32 MipSize = CalculateImageBytes(CubemapProxy->TextureTarget->SizeX, CubemapProxy->TextureTarget->SizeX, 0, PixelFormat);

if (CubemapProxy->Cubemap->PlatformData)
if (CubemapProxy->Cubemap->GetPlatformData())
{
delete CubemapProxy->Cubemap->PlatformData;
delete CubemapProxy->Cubemap->GetPlatformData();
CubemapProxy->Cubemap->SetPlatformData( nullptr );
}

CubemapProxy->Cubemap->PlatformData = new FTexturePlatformData();
CubemapProxy->Cubemap->PlatformData->SizeX = CubemapProxy->TextureTarget->SizeX;
CubemapProxy->Cubemap->PlatformData->SizeY = CubemapProxy->TextureTarget->SizeX;
CubemapProxy->Cubemap->PlatformData->PixelFormat = PixelFormat;
CubemapProxy->Cubemap->SetPlatformData( new FTexturePlatformData() );
CubemapProxy->Cubemap->GetPlatformData()->SizeX = CubemapProxy->TextureTarget->SizeX;
CubemapProxy->Cubemap->GetPlatformData()->SizeY = CubemapProxy->TextureTarget->SizeX;
CubemapProxy->Cubemap->GetPlatformData()->PixelFormat = PixelFormat;

{
FTexture2DMipMap* Mip = new(CubemapProxy->Cubemap->PlatformData->Mips) FTexture2DMipMap();
FTexture2DMipMap* Mip = new FTexture2DMipMap(CubemapProxy->Cubemap->GetPlatformData()->Mips[0]);
Mip->SizeX = CubemapProxy->TextureTarget->SizeX;
Mip->SizeY = CubemapProxy->TextureTarget->SizeX;
Mip->BulkData.Lock(LOCK_READ_WRITE);
Mip->BulkData.Realloc(Mip->SizeX * Mip->SizeY * 6 * GPixelFormats[PixelFormat].BlockBytes);
Mip->BulkData.Unlock();
}

FTexture2DMipMap& Mip = CubemapProxy->Cubemap->PlatformData->Mips[0];
FTexture2DMipMap& Mip = CubemapProxy->Cubemap->GetPlatformData()->Mips[0];
uint8* SliceData = (uint8*)Mip.BulkData.Lock(LOCK_READ_WRITE);

switch (TextureFormat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ FSlSpatialMappingParameters::FSlSpatialMappingParameters()
MaxMemoryUsage(2048),
PresetResolution(ESlSpatialMappingResolution::SMR_Medium),
PresetRange(ESlSpatialMappingRange::SMR_Auto),
bSaveTexture(false)/*,
StabilityCounter(0)/*,
bUseChunkOnly(bUseChunkOnly)*/,
StabilityCounter(0)
bSaveTexture(false)
{
MaxRange = sl::SpatialMappingParameters::get(sl::unreal::ToSlType(PresetRange));
Resolution = sl::SpatialMappingParameters::get(sl::unreal::ToSlType(PresetResolution));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ void USlCameraProxy::Internal_OpenCamera(const FSlInitParameters& InitParameters
sl_init_parameters.async_grab_camera_recovery = InitParameters.bAsyncGrabCameraRecovery;
sl_init_parameters.open_timeout_sec = InitParameters.OpenTimeoutSec;
sl_init_parameters.grab_compute_capping_fps = InitParameters.GrabComputeCappingFPS;
sl_init_parameters.enable_image_validity_check = InitParameters.bEnableImageValidityCheck;

InputType = (SL_INPUT_TYPE)InitParameters.InputType;
bool IsCameraCreated = sl_create_camera(CameraID);
Expand Down Expand Up @@ -569,6 +570,37 @@ ESlTrackingState USlCameraProxy::GetPosition(FSlPose& Pose, ESlReferenceFrame Re
SL_SCOPE_UNLOCK
}

ESlErrorCode USlCameraProxy::SetRegionOfInterest(FSlMat& Mat)
{
SL_ERROR_CODE err = (SL_ERROR_CODE)sl_set_region_of_interest(CameraID, Mat.Mat);
return sl::unreal::ToUnrealType(err);
}

ESlErrorCode USlCameraProxy::GetRegionOfInterest(FSlMat& Mat, FIntPoint& resolution)
{
if (!Mat.Mat) {
Mat.Mat = sl_mat_create_new(resolution.X, resolution.Y, SL_MAT_TYPE_U8_C1, SL_MEM_CPU);
}
SL_ERROR_CODE err = (SL_ERROR_CODE)sl_get_region_of_interest(CameraID, Mat.Mat, resolution.X, resolution.Y);
return sl::unreal::ToUnrealType(err);
}

ESlErrorCode USlCameraProxy::StartRegionOfInterestAutoDetection(FSlRegionOfInterestParameters& roiParams)
{
SL_RegionOfInterestParameters params;
params.auto_apply = roiParams.bAutoApply;
params.depth_far_threshold_meters = roiParams.depthFarThresholdMeters;
params.image_height_ratio_cutoff = roiParams.imageHeightRatioCutoff;

SL_ERROR_CODE err = (SL_ERROR_CODE)sl_start_region_of_interest_auto_detection(CameraID, &params);
return sl::unreal::ToUnrealType(err);
}

ESlRegionOfInterestAutoDetectionState USlCameraProxy::GetRegionOfInterestAutoDetectionStatus()
{
return (ESlRegionOfInterestAutoDetectionState)sl_get_region_of_interest_auto_detection_status(CameraID);
}

ESlErrorCode USlCameraProxy::GetIMUData(FSlIMUData& IMUData, ESlTimeReference TimeReference)
{
SL_ERROR_CODE ErrorCode = SL_ERROR_CODE_FAILURE;
Expand Down Expand Up @@ -846,6 +878,11 @@ FSlVideoSettings USlCameraProxy::GetCameraSettings()
return CameraSettings;
}

bool USlCameraProxy::GetCameraSetting(ESlVideoSettings CameraSetting, int& value)
{
return (sl_get_camera_settings(CameraID, (SL_VIDEO_SETTINGS)CameraSetting, &value) == SL_ERROR_CODE_SUCCESS);
}

bool USlCameraProxy::EnableSpatialMapping(const FSlSpatialMappingParameters& SpatialMappingParameters)
{
SL_ERROR_CODE ErrorCode;
Expand Down Expand Up @@ -1015,6 +1052,22 @@ bool USlCameraProxy::RetrieveMeasure(void* Mat, ESlMeasure MeasureType, ESlMemor
return (ErrorCode == SL_ERROR_CODE_SUCCESS);
}

bool USlCameraProxy::IsCameraSettingSupported(ESlVideoSettings CameraSetting)
{
return sl_is_camera_setting_supported(CameraID, (SL_VIDEO_SETTINGS)CameraSetting);
}

bool USlCameraProxy::SetCameraSetting(ESlVideoSettings NewCameraSettings, int value)
{
if (sl_is_camera_setting_supported(CameraID, (SL_VIDEO_SETTINGS)NewCameraSettings))
{
sl_set_camera_settings(CameraID, (SL_VIDEO_SETTINGS)NewCameraSettings, value);
return true;
}
return false;
}


void USlCameraProxy::SetCameraSettings(FSlVideoSettings& NewCameraSettings)
{
bool bDefault = NewCameraSettings.bDefault;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "D3D11State.h"
typedef FD3D11StateCacheBase FD3D11StateCache;
#include "D3D11Resources.h"
#include "ID3D11DynamicRHI.h"
#include "D3D11RHIPrivate.h"

#include "D3D12RHIPrivate.h"
#include "D3D12Util.h"
Expand Down Expand Up @@ -151,7 +153,7 @@ void USlTexture::UpdateTexture()

FUpdateTextureRegion2D region = FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);

FTexture2DResource* resource = (FTexture2DResource*)Texture->Resource;
FTexture2DResource* resource = (FTexture2DResource*)Texture->GetResource();
RHIUpdateTexture2D(resource->GetTexture2DRHI(), 0, region, region.Width * ByteSize, (uint8*)MatPtr);
}
else
Expand Down Expand Up @@ -185,7 +187,7 @@ void USlTexture::UpdateTexture(const FSlMat& NewMat)

FUpdateTextureRegion2D region = FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);

FTexture2DResource* resource = (FTexture2DResource*)Texture->Resource;
FTexture2DResource* resource = (FTexture2DResource*)Texture->GetResource();
RHIUpdateTexture2D(resource->GetTexture2DRHI(), 0, region, region.Width * ByteSize, (uint8*)MatPtr);
}
else
Expand Down Expand Up @@ -220,7 +222,7 @@ void USlTexture::UpdateTexture(void* NewMat)

FUpdateTextureRegion2D region = FUpdateTextureRegion2D(0, 0, 0, 0, Width, Height);

FTexture2DResource* resource = (FTexture2DResource*)Texture->Resource;
FTexture2DResource* resource = (FTexture2DResource*)Texture->GetResource();
RHIUpdateTexture2D(resource->GetTexture2DRHI(), 0, region, region.Width * ByteSize, (uint8*)MatPtr);
}
else
Expand Down Expand Up @@ -390,13 +392,19 @@ void USlTexture::InitResources(ESlTextureFormat Format, TextureCompressionSettin
cudaError_t CudaError = cudaError::cudaSuccess;

// This function has changed between 5.0 and 5.1.
#if ENGINE_MINOR_VERSION < 1
#if ENGINE_MINOR_VERSION == 0 // 5.0
FD3D11TextureBase* D3D11Texture = GetD3D11TextureFromRHITexture(Texture->Resource->TextureRHI);
#else
#elif ENGINE_MINOR_VERSION == 1 // 5.1
FD3D11Texture* D3D11Texture = GetD3D11TextureFromRHITexture(Texture->Resource->TextureRHI);
#else // 5.2
ID3D11Resource* D3D11NativeTexture = GetID3D11DynamicRHI()->RHIGetResource(Texture->GetResource()->TextureRHI);
#endif

#if ENGINE_MINOR_VERSION == 2
CudaError = cudaGraphicsD3D11RegisterResource(&CudaResource, D3D11NativeTexture, cudaGraphicsMapFlagsNone);
#else
CudaError = cudaGraphicsD3D11RegisterResource(&CudaResource, D3D11Texture->GetResource(), cudaGraphicsMapFlagsNone);
#endif

GSlCameraProxy->PopCudaContext();

Expand All @@ -409,7 +417,7 @@ void USlTexture::InitResources(ESlTextureFormat Format, TextureCompressionSettin
{
if (ID3D12Device* D3D12DevicePtr = static_cast<ID3D12Device*>(GDynamicRHI->RHIGetNativeDevice()))
{
if (ID3D12Resource* D3D12ResourcePtr = (ID3D12Resource*)(Texture->Resource->TextureRHI->GetNativeResource()))
if (ID3D12Resource* D3D12ResourcePtr = (ID3D12Resource*)(Texture->GetResource()->TextureRHI->GetNativeResource()))
{
SL_MAT_TYPE mat_type = sl::unreal::GetSlMatTypeFormatFromSlTextureFormat(Format);
int ByteSize = sl::unreal::GetSizeInBytes(mat_type);
Expand Down
Loading

0 comments on commit 1b7dff0

Please sign in to comment.