Commit 9e1d7880 by wester

DownloadFile

parent bd810866
...@@ -76,3 +76,12 @@ AppliedTargetedHardwareClass=Mobile ...@@ -76,3 +76,12 @@ AppliedTargetedHardwareClass=Mobile
DefaultGraphicsPerformance=Scalable DefaultGraphicsPerformance=Scalable
AppliedDefaultGraphicsPerformance=Scalable AppliedDefaultGraphicsPerformance=Scalable
[HTTP]
HttpTimeout=300
HttpConnectionTimeout=-1
HttpReceiveTimeout=-1
HttpSendTimeout=-1
HttpMaxConnectionsPerServer=16
bEnableHttp=true
bUseNullHttp=false
HttpDelayTime=0
...@@ -49,12 +49,6 @@ void UStaticGLTFComponent::OnRegister() ...@@ -49,12 +49,6 @@ void UStaticGLTFComponent::OnRegister()
else { else {
ImportNodes( Scene->scenes[Scene->defaultScene], newrawmesh, FMatrix()); ImportNodes( Scene->scenes[Scene->defaultScene], newrawmesh, FMatrix());
} }
} }
......
...@@ -20,7 +20,7 @@ public class MasterTestProject : ModuleRules ...@@ -20,7 +20,7 @@ public class MasterTestProject : ModuleRules
public MasterTestProject(TargetInfo Target) public MasterTestProject(TargetInfo Target)
{ {
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ImageWrapper", "RawMesh", "Json", "JsonUtilities", "ProceduralMeshComponent" }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ImageWrapper", "RawMesh", "HTTP", "Json", "JsonUtilities", "ProceduralMeshComponent" });
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange(new string[] { });
......
...@@ -10,31 +10,43 @@ void AMasterTestProjectGameModeBase::InitGame(const FString & MapName, const FSt ...@@ -10,31 +10,43 @@ void AMasterTestProjectGameModeBase::InitGame(const FString & MapName, const FSt
Super::InitGame(MapName, Options, ErrorMessage); Super::InitGame(MapName, Options, ErrorMessage);
//FString file = "D:\\Dropbox\\Studium\\MasterArbeit\\3d-tiles\\examples\\tileset.json"; //FString file = "D:\\Dropbox\\Studium\\MasterArbeit\\3d-tiles\\examples\\tileset.json";
FString file = "D:\\Dropbox\\Studium\\MasterArbeit\\3d-tiles-samples\\tilesets\\TilesetWithDiscreteLOD\\tileset.json"; //FString base = "D:\\Dropbox\\Studium\\MasterArbeit\\";
FString base = "file:/H:\\Repositories\\MasterArbeit\\";
FString file = base+"3d-tiles-samples\\tilesets\\..\\tilesets\\TilesetWithRequestVolume\\tileset.json";
rootTileset = nullptr;
DownloadFile(file);
FString JsonRaw = ""; FString JsonRaw = "";
FFileHelper::LoadFileToString(JsonRaw, *file); // FFileHelper::LoadFileToString(JsonRaw, *file);
UE_LOG(TILES, Log, TEXT("Loading file %s"), *file); // UE_LOG(TILES, Log, TEXT("Loading file %s"), *file);
//UE_LOG(GLTF, Warning, TEXT("LangFile: \n %s"), *JsonRaw); //UE_LOG(GLTF, Warning, TEXT("LangFile: \n %s"), *JsonRaw);
//FTileset* tileset = parseTileset(JsonRaw);
//DownloadFile(file, tileset->root.children[0].content.url);
}
FTileset* AMasterTestProjectGameModeBase::parseTileset(FString JsonString)
{
//TODO error Handling
TSharedPtr<FJsonObject> JsonParsed; TSharedPtr<FJsonObject> JsonParsed;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonRaw); TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonString);
if (FJsonSerializer::Deserialize(JsonReader, JsonParsed)) if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
{ {
FString ExampleString = JsonParsed->GetStringField("geometricError"); FTileset *tileset = new FTileset();
UE_LOG(TILES, Warning, TEXT("Example: \n %s"), *ExampleString); bool success = FJsonObjectConverter::JsonObjectToUStruct<FTileset>(JsonParsed.ToSharedRef(), tileset, 0, 0);
FTileset tileset;
bool success = FJsonObjectConverter::JsonObjectToUStruct<FTileset>(JsonParsed.ToSharedRef() , &tileset, 0, 0);
//bool success = FJsonObjectConverter::JsonObjectStringToUStruct<FTileset>(JsonRaw, &tileset, 0, 0);
TSharedPtr<FJsonObject> root = JsonParsed->GetObjectField("root"); TSharedPtr<FJsonObject> root = JsonParsed->GetObjectField("root");
parseTile(root, &tileset.root); parseTile(root, &tileset->root);
//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); return tileset;
} }
return nullptr;
} }
void AMasterTestProjectGameModeBase::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile) { void AMasterTestProjectGameModeBase::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile) {
...@@ -56,5 +68,64 @@ void AMasterTestProjectGameModeBase::parseTile(TSharedPtr<FJsonObject> json, FTi ...@@ -56,5 +68,64 @@ void AMasterTestProjectGameModeBase::parseTile(TSharedPtr<FJsonObject> json, FTi
UE_LOG(TILES, Warning, TEXT("Tile: Success:%s Version:\"%s\" no Childs "), success ? TEXT("True") : TEXT("False"), *targetTile->content.url); UE_LOG(TILES, Warning, TEXT("Tile: Success:%s Version:\"%s\" no Childs "), success ? TEXT("True") : TEXT("False"), *targetTile->content.url);
} }
if (!targetTile->content.url.IsEmpty()) {
TSharedRef<IHttpRequest> request = DownloadFile(/*base url*/, targetTile->content.url);
}
}
TSharedRef<IHttpRequest> AMasterTestProjectGameModeBase::DownloadFile(const FString & BaseUrl, const FString & RelativeUrl)
{
FString Path, Filename, Extension;
FPaths::Split(BaseUrl, Path, Filename, Extension);
FString url = Path + "/" + RelativeUrl;
UE_LOG(TILES, Warning, TEXT("Downlaoding: BAse:%s, Relative %s "), *BaseUrl, *RelativeUrl);
return DownloadFile(url);
//DownloadFile(TEXT("http://ipv4.download.thinkbroadband.com/20MB.zip"));
}
TSharedRef<IHttpRequest> AMasterTestProjectGameModeBase::DownloadFile(const FString & Url)
{
TSharedRef< IHttpRequest > HttpRequest = FHttpModule::Get().CreateRequest();
HttpRequest->SetVerb("GET");
HttpRequest->SetURL(Url);
HttpRequest->OnProcessRequestComplete().BindUObject(this, &AMasterTestProjectGameModeBase::OnReady);
HttpRequest->OnRequestProgress().BindUObject(this, &AMasterTestProjectGameModeBase::OnProgress_Internal);
// Execute the request
UE_LOG(TILES, Warning, TEXT("Downlaoding: %s "), *HttpRequest->GetURL());
HttpRequest->ProcessRequest();
return HttpRequest;
}
void AMasterTestProjectGameModeBase::OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
if (Response.IsValid()) {
// UE_LOG(TILES, Warning, TEXT("Downlaod Finished: %s Scucess: %s \"%s\""), *Request->GetURL(), bWasSuccessful ? TEXT("True") : TEXT("False"), *Response->GetContentAsString());
if (Request->GetURL().EndsWith(TEXT(".json"))) {
FTileset* tileset = parseTileset(Response->GetContentAsString());
if (rootTileset == nullptr) {
rootTileset = tileset;
}
Response->GetContent();
}
}
else {
UE_LOG(TILES, Warning, TEXT("Downlaod Finished: %s Scucess: %s not Valid"), *Request->GetURL(), bWasSuccessful ? TEXT("True") : TEXT("False"));
}
}
void AMasterTestProjectGameModeBase::OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived)
{
UE_LOG(TILES, Warning, TEXT("Downlaod Progress: %s Sent:%d, Received:%d "), *Request->GetURL(), BytesSent, BytesReceived);
} }
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#pragma once #pragma once
#include "GameFramework/GameModeBase.h" #include "GameFramework/GameModeBase.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "MasterTestProjectGameModeBase.generated.h" #include "MasterTestProjectGameModeBase.generated.h"
...@@ -86,6 +88,10 @@ struct FTileContent ...@@ -86,6 +88,10 @@ struct FTileContent
UPROPERTY() UPROPERTY()
FString url; FString url;
TArray<uint8> content;
// FTileset tileset;
}; };
...@@ -158,8 +164,20 @@ class MASTERTESTPROJECT_API AMasterTestProjectGameModeBase : public AGameModeBas ...@@ -158,8 +164,20 @@ class MASTERTESTPROJECT_API AMasterTestProjectGameModeBase : public AGameModeBas
public: public:
virtual void InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage); virtual void InitGame(const FString & MapName, const FString & Options, FString & ErrorMessage);
void parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile); FTileset* parseTileset(FString JsonString);
TSharedRef<IHttpRequest> DownloadFile(const FString &BaseUrl, const FString &RelativeUrl);
TSharedRef<IHttpRequest> DownloadFile(const FString &Url);
FTileset *rootTileset;
TMap<FHttpRequestPtr, FTileContent> activeRequests;
private:
void parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile);
void OnReady(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void OnProgress_Internal(FHttpRequestPtr Request, int32 BytesSent, int32 BytesReceived);
}; };
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