Commit 455c7bec by Kai Westerkamp

texture write

parent 3b471513
......@@ -39,24 +39,24 @@ void UDynamicTextureUtilities::UpdateTextureRegion(UTexture2D* Texture, int32 Mi
bool, bFreeData, bFreeData,
{
int32 CurrentFirstMip = RegionData->Texture2DResource->GetCurrentFirstMip();
if (RegionData->MipIndex >= CurrentFirstMip)
{
RHIUpdateTexture2D(
RegionData->Texture2DResource->GetTexture2DRHI(),
RegionData->MipIndex - CurrentFirstMip,
RegionData->Region,
RegionData->SrcPitch,
RegionData->SrcData
+ RegionData->Region.SrcY * RegionData->SrcPitch
+ RegionData->Region.SrcX * RegionData->SrcBpp
);
}
// TODO is this leaking if we never set this to true??
if (bFreeData)
{
FMemory::Free(RegionData->SrcData);
}
delete RegionData;
if (RegionData->MipIndex >= CurrentFirstMip)
{
RHIUpdateTexture2D(
RegionData->Texture2DResource->GetTexture2DRHI(),
RegionData->MipIndex - CurrentFirstMip,
RegionData->Region,
RegionData->SrcPitch,
RegionData->SrcData
+ RegionData->Region.SrcY * RegionData->SrcPitch
+ RegionData->Region.SrcX * RegionData->SrcBpp
);
}
// TODO is this leaking if we never set this to true??
if (bFreeData)
{
FMemory::Free(RegionData->SrcData);
}
delete RegionData;
});
}
......@@ -66,14 +66,14 @@ void UDynamicTextureUtilities::UpdateTextureRegion(UTexture2D* Texture, int32 Mi
void UDynamicTextureUtilities::UpdateDynamicVectorTexture(const TArray<FLinearColor>& Source, UTexture2D* Texture)
{
// Only handles 32-bit float textures
if (!Texture || Texture->GetPixelFormat() != PF_A32B32G32R32F) return;
if (!Texture || Texture->GetPixelFormat() != PF_FloatRGB) return;
// Shouldn't do anything if there's no data
if (Source.Num() < 1) return;
UpdateTextureRegion(Texture, 0, FUpdateTextureRegion2D(0, 0, 0, 0, Texture->GetSizeX(), Texture->GetSizeY()), Texture->GetSizeX() * sizeof(FLinearColor), sizeof(FLinearColor), (uint8*)Source.GetData(), false);
}
UTexture2D* UDynamicTextureUtilities::CreateTransientDynamicTexture(int32 Width, int32 Height, EPixelFormat PixelFormat /*= PF_A32B32G32R32F*/)
UTexture2D* UDynamicTextureUtilities::CreateTransientDynamicTexture(int32 Width, int32 Height, EPixelFormat PixelFormat)
{
auto* Texture = UTexture2D::CreateTransient(Width, Height, PixelFormat);
if (Texture)
......@@ -85,6 +85,32 @@ UTexture2D* UDynamicTextureUtilities::CreateTransientDynamicTexture(int32 Width,
return Texture;
}
UTexture2D* UDynamicTextureUtilities::CreateDynamicTextureWithData(int length, uint8* data)
{
int32 size = FMath::FloorToInt(FMath::Sqrt(length))+1;
UE_LOG(TILES, Error, TEXT("Texturein %d, size %d"), length, size);
auto* Texture = UTexture2D::CreateTransient(size, size, PF_FloatRGB);
if (Texture)
{
Texture->CompressionSettings = TextureCompressionSettings::TC_VectorDisplacementmap;
Texture->SRGB = 0;
Texture->UpdateResource();
}
UpdateTextureRegion(Texture, 0,
FUpdateTextureRegion2D(0, 0, 0, 0, size, size),
size * 3 * sizeof(float), 3 * sizeof(float), data, false);
return Texture;
}
/*
void UDynamicTextureUtilities::SetDynamicTextureAndIndex(class UStaticMeshComponent* Component, class UTexture2D* Texture, int32 Index, FName IndexParameterName, FName TextureParameterName)
{
......
......@@ -3,6 +3,7 @@
#pragma once
#include "UObject/NoExportTypes.h"
#include "UnrealMath.h"
#include "DynamicTextureUtilities.generated.h"
/**
......@@ -30,5 +31,7 @@ public:
// material, otherwise this will not have the proper effect.
//static void SetDynamicTextureAndIndex(class UStaticMeshComponent* Component, class UTexture2D* Texture, int32 Index, FName IndexParameterName, FName TextureParameterName);
// input rgb flaot array
static UTexture2D* UDynamicTextureUtilities::CreateDynamicTextureWithData(int length, uint8* data);
};
......@@ -348,6 +348,16 @@ void ATilesetActor::parsePointCloudTile(const TArray<uint8> data, FTile * tile)
uint32 featureTableBinaryOffset = pntheader->getFeatureStart() + pntheader->featureTable.featureTableJSONByteLength;
TSharedPtr<FJsonObject> binaryBodyReference = FeatureTableJSON->GetObjectField("POSITION");
int32 byteOffset = binaryBodyReference->GetIntegerField("byteOffset");
uint8* start = (uint8*)(data.GetData() + pntheader->getFeatureBinaryStart() + byteOffset);
UTexture2D* points = UDynamicTextureUtilities::CreateDynamicTextureWithData(instances_length, start);
if (TextureTest && points) {
UMaterialInstanceDynamic *Material = UMaterialInstanceDynamic::Create(TextureTest->GetStaticMeshComponent()->GetMaterial(0), nullptr);
Material->SetTextureParameterValue(FName("DynamicTexture"), points);
TextureTest->GetStaticMeshComponent()->SetMaterial(0,Material);
}
/*
TArray<FVector> positons = getAsArray<FVector>(data.GetData(), (int32)(featureTableBinaryOffset + byteOffset), instances_length);
......
......@@ -3,6 +3,7 @@
#pragma once
#include "UObject/NoExportTypes.h"
#include "DynamicTextureUtilities.h"
#include "Tileset.generated.h"
......@@ -295,10 +296,16 @@ struct PointCloudHeader {
return 28 /*headersize*/;
}
uint32 getFeatureBinaryStart() {
return getFeatureStart() + featureTable.featureTableJSONByteLength;
}
uint32 getBatchStart() {
return getFeatureStart() + featureTable.length();
}
FString getpartAsString(int start, int lenght) {
char *ansiiData = new char[lenght + 1];
memcpy(ansiiData, (void*)(((uint8*)this) + start), lenght); //Assumes bytesRead is always smaller than 1024 bytes
......@@ -334,6 +341,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LOD")
float LODtreshold = 0.1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Texture")
AStaticMeshActor *TextureTest = NULL;
// Called when the game starts or when spawned
virtual void BeginPlay() override;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment