Commit e766759e by Kai Westerkamp

Tileset.cpp

parent cc9791ea
......@@ -13,7 +13,5 @@ void UGLTFDownloader::GetGLTF(AProceduralEntity * Reference, FString & baseUrl,
void UGLTFDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
reference->loadModel(Response->GetContent());
UE_LOG(GLTF, Error, TEXT("GLTF Loaded: %s "), *Request->GetURL());
//loadModel(Response);
reference->loadModel(Response->GetContent().GetData(), Response->GetContent().Num());
}
\ No newline at end of file
......@@ -12,7 +12,7 @@ void UHttpDownloader::DownloadFile(const FString &URL)
HttpRequest->OnProcessRequestComplete().BindUObject(this, &UHttpDownloader::OnResponseReceived);
// Execute the request
UE_LOG(TILES, Warning, TEXT("Downlaoding: %s "), *HttpRequest->GetURL());
UE_LOG(TILES, Log, TEXT("Downlaoding: %s "), *HttpRequest->GetURL());
HttpRequest->ProcessRequest();
......@@ -48,7 +48,7 @@ FString UHttpDownloader::ResolveRealativeURL(const FString &BaseUrl, const FStri
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;
......
// Fill out your copyright notice in the Description page of Project Settings.
#include "MasterTestProject.h"
#include "TileDownloader.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
GENERATED_BODY()
public:
virtual void InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage);
FTileContent *rootTileset;
};
......@@ -4,9 +4,12 @@
#include "TileDownloader.h"
void UTileDownloader::GetTileContent(FTileContent *Content, FString &baseUrl)
void UTileDownloader::GetTileContent(ATilesetActor *Actor, FTileContent *Content, FString &baseUrl, FTile *tile)
{
parent = Content;
parentTile = tile;
actor = Actor;
DownloadFile(ResolveRealativeURL(baseUrl, *Content->url));
}
......@@ -16,13 +19,13 @@ void UTileDownloader::OnResponseReceived(FHttpRequestPtr Request, FHttpResponseP
{
if (Response.IsValid()) {
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"));
}
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 {
......
......@@ -16,10 +16,12 @@ class MASTERTESTPROJECT_API UTileDownloader : public UHttpDownloader
private:
FTileContent *parent;
FTile *parentTile;
ATilesetActor *actor;
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);
......
......@@ -4,10 +4,22 @@
#include "JsonReader.h"
#include "JsonObjectConverter.h"
#include "TileDownloader.h"
#include "ue4-assimp/ProceduralEntity.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
TSharedPtr<FJsonObject> JsonParsed;
......@@ -19,7 +31,7 @@ FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL)
tileset->absoluteURL = BaseURL;
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);
......@@ -29,7 +41,7 @@ FTileset* UTilesetUtil::parseTileset(FString JsonString, FString BaseURL)
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();
......@@ -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') {
Batch3DModelHeader *b3dmheader = (Batch3DModelHeader*) data.GetData();
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);
......@@ -56,7 +87,7 @@ void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FT
for (TSharedPtr<FJsonValue> child : children)
{
FTile newTile;
UTilesetUtil::parseTile(child->AsObject(), &newTile, parent);
ATilesetActor::parseTile(child->AsObject(), &newTile, parent);
targetTile->children.Add(newTile);
}
}
......@@ -66,8 +97,9 @@ void UTilesetUtil::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FT
if (!targetTile->content.url.IsEmpty()) {
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 {
BatchTableHeader batchtable;
uint32 batchLength;
uint32 getGLTFStart() {
return 24 + batchtable.batchTableJSONByteLength + batchtable.batchTableBinaryByteLength;
}
};
......@@ -199,16 +201,29 @@ struct Batch3DModelHeader {
*
*/
UCLASS()
class MASTERTESTPROJECT_API UTilesetUtil : public UObject
class MASTERTESTPROJECT_API ATilesetActor : public AActor
{
GENERATED_BODY()
public:
static FTileset* parseTileset(FString JsonString, FString BaseURL);
static void parseTile(const TArray<uint8> data, FString BaseURL);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Generation")
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:
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()
_mesh = CreateDefaultSubobject<UProceduralMeshComponent>(TEXT("ProcMesh"));
if (_mesh) {
_mesh->CastShadow = true;
_mesh->SetCollisionObjectType(ECC_WorldDynamic);
_mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
_mesh->SetCollisionResponseToAllChannels(ECR_Block);
//_mesh->SetCollisionObjectType(ECC_WorldDynamic);
//_mesh->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
//_mesh->SetCollisionResponseToAllChannels(ECR_Block);
// _mesh->UpdateCollisionProfile();
RootComponent = _mesh;
}
......@@ -43,11 +43,9 @@ void AProceduralEntity::BeginPlay()
{
Super::BeginPlay();
UGLTFDownloader *downloader = NewObject<UGLTFDownloader>(UGLTFDownloader::StaticClass());
FString base = FString(TEXT(""));
downloader->GetGLTF(this, base, _filePath);
UE_LOG(GLTF, Error, TEXT("Loading Path: %s"), *_filePath);
//UGLTFDownloader *downloader = NewObject<UGLTFDownloader>(UGLTFDownloader::StaticClass());
//FString base = FString(TEXT(""));
//downloader->GetGLTF(this, base, _filePath);
}
void AProceduralEntity::PostActorCreated() {
......@@ -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;
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"));
//const aiScene* scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals);
......
......@@ -52,7 +52,7 @@ public:
//UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Materials")
//UTexture2D* diffTexture;
void loadModel(TArray<uint8> data);
void loadModel(const uint8* RawFileData, int32 lenght);
private:
int32 _selectedVertex;
......@@ -68,8 +68,7 @@ private:
TArray<TArray<FVector2D>> _uvs;
TArray<TArray<FProcMeshTangent>> _tangents;
TArray<TArray<FColor>> _vertexColors;
//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