Commit e766759e by Kai Westerkamp

Tileset.cpp

parent cc9791ea
...@@ -13,7 +13,5 @@ void UGLTFDownloader::GetGLTF(AProceduralEntity * Reference, FString & baseUrl, ...@@ -13,7 +13,5 @@ void UGLTFDownloader::GetGLTF(AProceduralEntity * Reference, FString & baseUrl,
void UGLTFDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) void UGLTFDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{ {
reference->loadModel(Response->GetContent()); reference->loadModel(Response->GetContent().GetData(), Response->GetContent().Num());
UE_LOG(GLTF, Error, TEXT("GLTF Loaded: %s "), *Request->GetURL());
//loadModel(Response);
} }
\ No newline at end of file
...@@ -12,7 +12,7 @@ void UHttpDownloader::DownloadFile(const FString &URL) ...@@ -12,7 +12,7 @@ void UHttpDownloader::DownloadFile(const FString &URL)
HttpRequest->OnProcessRequestComplete().BindUObject(this, &UHttpDownloader::OnResponseReceived); HttpRequest->OnProcessRequestComplete().BindUObject(this, &UHttpDownloader::OnResponseReceived);
// Execute the request // Execute the request
UE_LOG(TILES, Warning, TEXT("Downlaoding: %s "), *HttpRequest->GetURL()); UE_LOG(TILES, Log, TEXT("Downlaoding: %s "), *HttpRequest->GetURL());
HttpRequest->ProcessRequest(); HttpRequest->ProcessRequest();
...@@ -48,7 +48,7 @@ FString UHttpDownloader::ResolveRealativeURL(const FString &BaseUrl, const FStri ...@@ -48,7 +48,7 @@ FString UHttpDownloader::ResolveRealativeURL(const FString &BaseUrl, const FStri
FString url = basePath + "/" + RelativeUrlnormalized; FString url = basePath + "/" + RelativeUrlnormalized;
UE_LOG(TILES, Log, TEXT("Relative URl: Base:%s, Relative %s, -> %s "), *BaseUrlnormalized, *RelativeUrlnormalized, *url); //UE_LOG(TILES, Log, TEXT("Relative URl: Base:%s, Relative %s, -> %s "), *BaseUrlnormalized, *RelativeUrlnormalized, *url);
return url; return url;
......
// Fill out your copyright notice in the Description page of Project Settings. // Fill out your copyright notice in the Description page of Project Settings.
#include "MasterTestProject.h" #include "MasterTestProject.h"
#include "TileDownloader.h"
#include "MasterTestProjectGameModeBase.h" #include "MasterTestProjectGameModeBase.h"
void AMasterTestProjectGameModeBase::InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage) {
Super::InitGame(MapName, Options, ErrorMessage);
//FString file = "D:\\Dropbox\\Studium\\MasterArbeit\\3d-tiles\\examples\\tileset.json";
FString base = "file://D:\\Dropbox\\Studium\\MasterArbeit\\";
//FString base = "file://H:\\Repositories\\MasterArbeit\\";
FString file = "3d-tiles-samples\\tilesets\\TilesetWithRequestVolume\\tileset.json";
rootTileset = new FTileContent();
rootTileset->url = file;
UTileDownloader *downloader = NewObject<UTileDownloader>(UTileDownloader::StaticClass());
downloader->GetTileContent(rootTileset, base);
}
...@@ -17,8 +17,6 @@ class MASTERTESTPROJECT_API AMasterTestProjectGameModeBase : public AGameModeBas ...@@ -17,8 +17,6 @@ class MASTERTESTPROJECT_API AMasterTestProjectGameModeBase : public AGameModeBas
GENERATED_BODY() GENERATED_BODY()
public: public:
virtual void InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage);
FTileContent *rootTileset;
}; };
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
#include "TileDownloader.h" #include "TileDownloader.h"
void UTileDownloader::GetTileContent(FTileContent *Content, FString &baseUrl) void UTileDownloader::GetTileContent(ATilesetActor *Actor, FTileContent *Content, FString &baseUrl, FTile *tile)
{ {
parent = Content; parent = Content;
parentTile = tile;
actor = Actor;
DownloadFile(ResolveRealativeURL(baseUrl, *Content->url)); DownloadFile(ResolveRealativeURL(baseUrl, *Content->url));
} }
...@@ -16,13 +19,13 @@ void UTileDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponseP ...@@ -16,13 +19,13 @@ void UTileDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponseP
{ {
if (Response.IsValid()) { if (Response.IsValid()) {
if (Request->GetURL().EndsWith(TEXT(".json"))) { if (Request->GetURL().EndsWith(TEXT(".json"))) {
parent->tileset = UTilesetUtil::parseTileset(Response->GetContentAsString(), Request->GetURL()); parent->tileset = actor->parseTileset(Response->GetContentAsString(), Request->GetURL());
UE_LOG(TILES, Warning, TEXT("Parsed Tilset: %s Scucess: %s "), *Request->GetURL(), bWasSuccessful ? TEXT("True") : TEXT("False")); UE_LOG(TILES, Warning, TEXT("Parsed Tilset: %s Scucess: %s "), *Request->GetURL(), bWasSuccessful ? TEXT("True") : TEXT("False"));
} }
else { else {
UTilesetUtil::parseTile(Response->GetContent(), Request->GetURL()); actor->parseTile(Response->GetContent(), parentTile);
UE_LOG(TILES, Error, TEXT("Parsed Tile: %s Scucess: %s "), *Request->GetURL(), bWasSuccessful ? TEXT("True") : TEXT("False")); UE_LOG(TILES, Warning, TEXT("Parsed Tile: %s Scucess: %s "), *Request->GetURL(), bWasSuccessful ? TEXT("True") : TEXT("False"));
} }
} }
else { else {
......
...@@ -16,10 +16,12 @@ class MASTERTESTPROJECT_API UTileDownloader : public UHttpDownloader ...@@ -16,10 +16,12 @@ class MASTERTESTPROJECT_API UTileDownloader : public UHttpDownloader
private: private:
FTileContent *parent; FTileContent *parent;
FTile *parentTile;
ATilesetActor *actor;
public: public:
void GetTileContent(FTileContent *Content, FString &baseUrl); void GetTileContent(ATilesetActor *Actor ,FTileContent *Content, FString &baseUrl, FTile *tile = nullptr);
virtual void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful); virtual void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
......
...@@ -4,10 +4,22 @@ ...@@ -4,10 +4,22 @@
#include "JsonReader.h" #include "JsonReader.h"
#include "JsonObjectConverter.h" #include "JsonObjectConverter.h"
#include "TileDownloader.h" #include "TileDownloader.h"
#include "ue4-assimp/ProceduralEntity.h"
#include "Tileset.h" #include "Tileset.h"
FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL) void ATilesetActor::BeginPlay()
{
Super::BeginPlay();
rootTileset = new FTileContent();
rootTileset->url = relativeURL;
UTileDownloader *downloader = NewObject<UTileDownloader>(UTileDownloader::StaticClass());
downloader->GetTileContent(this, rootTileset, host);
}
FTileset* ATilesetActor::parseTileset(FString JsonString, FString BaseURL)
{ {
//TODO error Handling //TODO error Handling
TSharedPtr<FJsonObject> JsonParsed; TSharedPtr<FJsonObject> JsonParsed;
...@@ -19,7 +31,7 @@ FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL) ...@@ -19,7 +31,7 @@ FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL)
tileset->absoluteURL = BaseURL; tileset->absoluteURL = BaseURL;
TSharedPtr<FJsonObject> root = JsonParsed->GetObjectField("root"); TSharedPtr<FJsonObject> root = JsonParsed->GetObjectField("root");
UTilesetUtil::parseTile(root, &tileset->root, tileset); ATilesetActor::parseTile(root, &tileset->root, tileset);
//UE_LOG(TILES, Warning, TEXT("Parsed: Success:%s Version:\"%s\" geometricError:%f"), success ? TEXT("True") : TEXT("False"), *tileset.asset.version, tileset.geometricError); //UE_LOG(TILES, Warning, TEXT("Parsed: Success:%s Version:\"%s\" geometricError:%f"), success ? TEXT("True") : TEXT("False"), *tileset.asset.version, tileset.geometricError);
...@@ -29,7 +41,7 @@ FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL) ...@@ -29,7 +41,7 @@ FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL)
return nullptr; return nullptr;
} }
void UTilesetUtil::parseTile(const TArray<uint8> data, FString BaseURL) void ATilesetActor::parseTile(const TArray<uint8> data, FTile *tile)
{ {
TileHeader *header = (TileHeader*) data.GetData(); TileHeader *header = (TileHeader*) data.GetData();
...@@ -38,12 +50,31 @@ void UTilesetUtil::parseTile(const TArray<uint8> data, FString BaseURL) ...@@ -38,12 +50,31 @@ void UTilesetUtil::parseTile(const TArray<uint8> data, FString BaseURL)
if (header->magic[0] == 'b' && header->magic[1] == '3' && header->magic[2] == 'd' && header->magic[3] == 'm') { if (header->magic[0] == 'b' && header->magic[1] == '3' && header->magic[2] == 'd' && header->magic[3] == 'm') {
Batch3DModelHeader *b3dmheader = (Batch3DModelHeader*) data.GetData(); Batch3DModelHeader *b3dmheader = (Batch3DModelHeader*) data.GetData();
UE_LOG(TILES, Log, TEXT("Batch %d %d %d"), b3dmheader->batchtable.batchTableJSONByteLength, b3dmheader->batchtable.batchTableBinaryByteLength, b3dmheader->batchLength); UE_LOG(TILES, Log, TEXT("Batch %d %d %d"), b3dmheader->batchtable.batchTableJSONByteLength, b3dmheader->batchtable.batchTableBinaryByteLength, b3dmheader->batchLength);
}
UWorld* const World = GetWorld();
if (World)
{
AProceduralEntity *gltf = World->SpawnActor<AProceduralEntity>(AProceduralEntity::StaticClass());
if (tile) {
for (int32 b = 0; b < tile->transform.Num() && b < 20; b++)
{
UE_LOG(TILES, Log, TEXT("Transform %.2f"), tile->transform[b]);
}
}
gltf->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
int GLTFstart = b3dmheader->getGLTFStart();
gltf->loadModel(&data.GetData()[GLTFstart], (data.Num() - GLTFstart));
}
}
} }
void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FTileset* parent) { void ATilesetActor::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FTileset* parent) {
bool success = FJsonObjectConverter::JsonObjectToUStruct<FTile>(json.ToSharedRef(), targetTile, 0, 0); bool success = FJsonObjectConverter::JsonObjectToUStruct<FTile>(json.ToSharedRef(), targetTile, 0, 0);
...@@ -56,7 +87,7 @@ void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FT ...@@ -56,7 +87,7 @@ void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FT
for (TSharedPtr<FJsonValue> child : children) for (TSharedPtr<FJsonValue> child : children)
{ {
FTile newTile; FTile newTile;
UTilesetUtil::parseTile(child->AsObject(), &newTile, parent); ATilesetActor::parseTile(child->AsObject(), &newTile, parent);
targetTile->children.Add(newTile); targetTile->children.Add(newTile);
} }
} }
...@@ -66,8 +97,9 @@ void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FT ...@@ -66,8 +97,9 @@ void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FT
if (!targetTile->content.url.IsEmpty()) { if (!targetTile->content.url.IsEmpty()) {
UTileDownloader *downloader = NewObject<UTileDownloader>(UTileDownloader::StaticClass()); UTileDownloader *downloader = NewObject<UTileDownloader>(UTileDownloader::StaticClass());
downloader->GetTileContent(&targetTile->content, parent->absoluteURL); downloader->GetTileContent(this, &targetTile->content, parent->absoluteURL, targetTile);
} }
} }
...@@ -190,7 +190,9 @@ struct Batch3DModelHeader { ...@@ -190,7 +190,9 @@ struct Batch3DModelHeader {
BatchTableHeader batchtable; BatchTableHeader batchtable;
uint32 batchLength; uint32 batchLength;
uint32 getGLTFStart() {
return 24 + batchtable.batchTableJSONByteLength + batchtable.batchTableBinaryByteLength;
}
}; };
...@@ -199,16 +201,29 @@ struct Batch3DModelHeader { ...@@ -199,16 +201,29 @@ struct Batch3DModelHeader {
* *
*/ */
UCLASS() UCLASS()
class MASTERTESTPROJECT_API UTilesetUtil : public UObject class MASTERTESTPROJECT_API ATilesetActor : public AActor
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
static FTileset* parseTileset(FString JsonString, FString BaseURL); UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Generation")
static void parseTile(const TArray<uint8> data, FString BaseURL); FString host;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Generation")
FString relativeURL;
// Called when the game starts or when spawned
virtual void BeginPlay() override;
FTileset* parseTileset(FString JsonString, FString BaseURL);
void parseTile(const TArray<uint8> data, FTile *tile);
private: private:
static void parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FTileset* parent); FTileContent *rootTileset;
void parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FTileset* parent);
}; };
...@@ -25,9 +25,9 @@ AProceduralEntity::AProceduralEntity() ...@@ -25,9 +25,9 @@ AProceduralEntity::AProceduralEntity()
_mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("ProcMesh")); _mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("ProcMesh"));
if (_mesh) { if (_mesh) {
_mesh->CastShadow = true; _mesh->CastShadow = true;
_mesh->SetCollisionObjectType(ECC_WorldDynamic); //_mesh->SetCollisionObjectType(ECC_WorldDynamic);
_mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics); //_mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
_mesh->SetCollisionResponseToAllChannels(ECR_Block); //_mesh->SetCollisionResponseToAllChannels(ECR_Block);
// _mesh->UpdateCollisionProfile(); // _mesh->UpdateCollisionProfile();
RootComponent = _mesh; RootComponent = _mesh;
} }
...@@ -43,11 +43,9 @@ void AProceduralEntity::BeginPlay() ...@@ -43,11 +43,9 @@ void AProceduralEntity::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
UGLTFDownloader *downloader = NewObject<UGLTFDownloader>(UGLTFDownloader::StaticClass()); //UGLTFDownloader *downloader = NewObject<UGLTFDownloader>(UGLTFDownloader::StaticClass());
FString base = FString(TEXT("")); //FString base = FString(TEXT(""));
downloader->GetGLTF(this, base, _filePath); //downloader->GetGLTF(this, base, _filePath);
UE_LOG(GLTF, Error, TEXT("Loading Path: %s"), *_filePath);
} }
void AProceduralEntity::PostActorCreated() { void AProceduralEntity::PostActorCreated() {
...@@ -248,10 +246,10 @@ void AProceduralEntity::processNode(aiNode* node, const aiScene* scene, FMatrix ...@@ -248,10 +246,10 @@ void AProceduralEntity::processNode(aiNode* node, const aiScene* scene, FMatrix
} }
void AProceduralEntity::loadModel(TArray<uint8> data) { void AProceduralEntity::loadModel(const uint8* RawFileData, int32 lenght) {
Assimp::Importer importer; Assimp::Importer importer;
const aiScene* scene = importer.ReadFileFromMemory(data.GetData(), data.Num(), aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals); const aiScene* scene = importer.ReadFileFromMemory(RawFileData, lenght, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals, "glb");
//UE_LOG(GLTF, Warning, TEXT("START LOGGING")); //UE_LOG(GLTF, Warning, TEXT("START LOGGING"));
//const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals); //const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
......
...@@ -52,7 +52,7 @@ public: ...@@ -52,7 +52,7 @@ public:
//UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Materials") //UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Materials")
//UTexture2D* diffTexture; //UTexture2D* diffTexture;
void loadModel(TArray<uint8> data); void loadModel(const uint8* RawFileData, int32 lenght);
private: private:
int32 _selectedVertex; int32 _selectedVertex;
...@@ -68,8 +68,7 @@ private: ...@@ -68,8 +68,7 @@ private:
TArray<TArray<FVector2D>> _uvs; TArray<TArray<FVector2D>> _uvs;
TArray<TArray<FProcMeshTangent>> _tangents; TArray<TArray<FProcMeshTangent>> _tangents;
TArray<TArray<FColor>> _vertexColors; TArray<TArray<FColor>> _vertexColors;
//USceneComponent* _rootComp; //USceneComponent* _rootComp;
......
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