Commit 6a593d2b by Kai Westerkamp

texture convert

parent 455c7bec
......@@ -63,14 +63,14 @@ void UDynamicTextureUtilities::UpdateTextureRegion(UTexture2D* Texture, int32 Mi
}
}
void UDynamicTextureUtilities::UpdateDynamicVectorTexture(const TArray<FLinearColor>& Source, UTexture2D* Texture)
void UDynamicTextureUtilities::UpdateDynamicVectorTexture(const TArray<FLinearColor>& Source, UTexture2D* Texture, bool bFreeData)
{
// Only handles 32-bit float textures
if (!Texture || Texture->GetPixelFormat() != PF_FloatRGB) return;
if (!Texture || Texture->GetPixelFormat() != PF_A32B32G32R32F) 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);
UpdateTextureRegion(Texture, 0, FUpdateTextureRegion2D(0, 0, 0, 0, Texture->GetSizeX(), Texture->GetSizeY()), Texture->GetSizeX() * sizeof(FLinearColor), sizeof(FLinearColor), (uint8*)Source.GetData(), bFreeData);
}
UTexture2D* UDynamicTextureUtilities::CreateTransientDynamicTexture(int32 Width, int32 Height, EPixelFormat PixelFormat)
......
......@@ -24,7 +24,7 @@ public:
static void UpdateTextureRegion(UTexture2D* Texture, int32 MipIndex, FUpdateTextureRegion2D Region, uint32 SrcPitch, uint32 SrcBpp, uint8* SrcData, bool bFreeData);
// Convenience wrapper for updating a dynamic texture with an array of
// FLinearColors.
static void UpdateDynamicVectorTexture(const TArray<FLinearColor>& Source, UTexture2D* Texture);
static void UpdateDynamicVectorTexture(const TArray<FLinearColor>& Source, UTexture2D* Texture, bool bFreeData = true);
// Sets up a component's material instance parameters (on all materials) for
// use with the supplied UTexture. The proper parameters (specified by
// IndexParameterName and TextureParameterName) should exist on the
......
......@@ -344,37 +344,81 @@ void ATilesetActor::parsePointCloudTile(const TArray<uint8> data, FTile * tile)
UWorld* const World = GetWorld();
if (World)
{
int32 TextureSize = FMath::FloorToInt(FMath::Sqrt(instances_length)) + 1;
int32 fill = TextureSize*TextureSize - instances_length;
if (FeatureTableJSON->HasField("POSITION")) {
// POSITION = float32[3]
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);
//TODO create wit copy
//UTexture2D* points = UDynamicTextureUtilities::CreateDynamicTextureWithData(instances_length, start);
// creat pooint texture
TArray<FLinearColor> *Points = new TArray<FLinearColor>();
uint8* pos = start;
for (size_t i = 0; i < instances_length; i+=1)
{
Points->Add(FLinearColor(*((float*) pos), *((float*)(pos+4)), *((float*)(pos +8)), 1.0f));
pos += 12;
}
for (size_t i = 0; i < fill; i += 1)
{
Points->Add(FLinearColor(0.0f, 0.0f, 0.0f, 0.0f));
}
UTexture2D* Texture = UDynamicTextureUtilities::CreateTransientDynamicTexture(TextureSize, TextureSize, PF_A32B32G32R32F);
UDynamicTextureUtilities::UpdateDynamicVectorTexture(*Points, Texture);
UE_LOG(TILES, Warning, TEXT("Created Position Texture Number Points %d, TextureSize: %d, Fill: %d, "), instances_length, TextureSize, fill);
if (TextureTest && points) {
//ass texture to mAterial
if (TextureTest) {
UMaterialInstanceDynamic *Material = UMaterialInstanceDynamic::Create(TextureTest->GetStaticMeshComponent()->GetMaterial(0), nullptr);
Material->SetTextureParameterValue(FName("DynamicTexture"), points);
Material->SetTextureParameterValue(FName("DynamicTexture"), Texture);
TextureTest->GetStaticMeshComponent()->SetMaterial(0,Material);
}
/*
TArray<FVector> positons = getAsArray<FVector>(data.GetData(), (int32)(featureTableBinaryOffset + byteOffset), instances_length);
FString outputString = "[";
}
else {
UE_LOG(TILES, Error, TEXT("Pointcloud Quantized not supported Position Required"));
}
for (FVector pos : positons)
if (FeatureTableJSON->HasField("RGB")) {
// RGB = uint8[3]
uint32 featureTableBinaryOffset = pntheader->getFeatureStart() + pntheader->featureTable.featureTableJSONByteLength;
TSharedPtr<FJsonObject> binaryBodyReference = FeatureTableJSON->GetObjectField("RGB");
int32 byteOffset = binaryBodyReference->GetIntegerField("byteOffset");
uint8* start = (uint8*)(data.GetData() + pntheader->getFeatureBinaryStart() + byteOffset);
// creat pooint texture
TArray<FLinearColor> *ColorRGB = new TArray<FLinearColor>();
uint8* pos = start;
UE_LOG(TILES, Error, TEXT("Color %s"), *FLinearColor((*pos) / 255, (*(pos + 1)) / 255, (*(pos + 2)) / 255).ToString() );
for (size_t i = 0; i < instances_length; i += 1)
{
outputString += "[" + pos.ToString() + "] ";
ColorRGB->Add(FLinearColor((*pos)/255, (*(pos + 1))/255, (*(pos + 2))/255));
pos += 3;
}
outputString += "]";
UE_LOG(TILES, Warning, TEXT("PointCloudHeader 3D Model Positions %s"), *outputString);*/
}
else {
UE_LOG(TILES, Error, TEXT("Pointcloud Quantized not supported"));
for (size_t i = 0; i < fill; i += 1)
{
ColorRGB->Add(FLinearColor(1.0f, 0.0f, 0.0f));
}
UTexture2D* Texture = UDynamicTextureUtilities::CreateTransientDynamicTexture(TextureSize, TextureSize, PF_A32B32G32R32F);
UDynamicTextureUtilities::UpdateDynamicVectorTexture(*ColorRGB, Texture);
UE_LOG(TILES, Warning, TEXT("Created Color Texture Number Points %d, TextureSize: %d, Fill: %d, "), instances_length, TextureSize, fill);
//ass texture to mAterial
if (TextureTest) {
UMaterialInstanceDynamic *Material = UMaterialInstanceDynamic::Create(TextureTest->GetStaticMeshComponent()->GetMaterial(0), nullptr);
Material->SetTextureParameterValue(FName("DynamicTexture"), Texture);
TextureTest->GetStaticMeshComponent()->SetMaterial(0, Material);
}
}
}
}
UE_LOG(TILES, Log, TEXT("PointCloudHeader: End"));
......
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