Commit 448885aa by Kai Westerkamp

Json to Struct

parent 3bda5499
...@@ -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", "ProceduralMeshComponent" }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ImageWrapper", "RawMesh", "Json", "JsonUtilities", "ProceduralMeshComponent" });
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange(new string[] { });
......
...@@ -7,3 +7,4 @@ IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, MasterTestProject, "Maste ...@@ -7,3 +7,4 @@ IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, MasterTestProject, "Maste
//General Log //General Log
DEFINE_LOG_CATEGORY(GLTF); DEFINE_LOG_CATEGORY(GLTF);
DEFINE_LOG_CATEGORY(TILES);
...@@ -6,3 +6,5 @@ ...@@ -6,3 +6,5 @@
//General Log //General Log
DECLARE_LOG_CATEGORY_EXTERN(GLTF, Log, All); DECLARE_LOG_CATEGORY_EXTERN(GLTF, Log, All);
DECLARE_LOG_CATEGORY_EXTERN(TILES, Log, All);
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "MasterTestProject.h" #include "MasterTestProject.h"
#include "JsonReader.h" #include "JsonReader.h"
#include "JsonObjectConverter.h"
#include "MasterTestProjectGameModeBase.h" #include "MasterTestProjectGameModeBase.h"
...@@ -13,16 +14,21 @@ void AMasterTestProjectGameModeBase::InitGame(const FString & MapName, const FSt ...@@ -13,16 +14,21 @@ void AMasterTestProjectGameModeBase::InitGame(const FString & MapName, const FSt
FString JsonRaw = ""; FString JsonRaw = "";
FFileHelper::LoadFileToString(JsonRaw, *file); FFileHelper::LoadFileToString(JsonRaw, *file);
UE_LOG(GLTF, 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);
TSharedPtr<FJsonObject> JsonParsed; //TSharedPtr<FJsonObject> JsonParsed;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonRaw); //TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonRaw);
if (FJsonSerializer::Deserialize(JsonReader, JsonParsed)) //if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
{ //{
FString ExampleString = JsonParsed->GetStringField("geometricError"); // FString ExampleString = JsonParsed->GetStringField("geometricError");
UE_LOG(GLTF, Warning, TEXT("Example: \n %s"), *ExampleString); // UE_LOG(TILES, Warning, TEXT("Example: \n %s"), *ExampleString);
} //}
FTileset tileset;
bool success = FJsonObjectConverter::JsonObjectStringToUStruct<FTileset>(JsonRaw, &tileset, 0, 0);
UE_LOG(TILES, Warning, TEXT("Parsed: Success:%s Version:\"%s\" geometricError:%f"), success ? TEXT("True") : TEXT("False"), *tileset.asset.version, tileset.geometricError);
} }
......
...@@ -6,6 +6,146 @@ ...@@ -6,6 +6,146 @@
#include "MasterTestProjectGameModeBase.generated.h" #include "MasterTestProjectGameModeBase.generated.h"
USTRUCT()
struct FAsset
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FString version;
UPROPERTY()
FString tilesetVersion;
FAsset() {
version = "";
tilesetVersion = "";
}
};
USTRUCT()
struct FProperties
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
float maximum;
UPROPERTY()
float minimum;
};
USTRUCT()
struct FPropertieDict
{
GENERATED_USTRUCT_BODY()
//FIXME should be a map or so, found no Unreal doc, values are from an example
/*"patternProperties" : {
".*": {
"$ref": "properties.schema.json"
}
}*/
UPROPERTY()
FProperties Longitude;
UPROPERTY()
FProperties Latitude;
UPROPERTY()
FProperties Height;
};
USTRUCT()
struct FBoundingVolume
{
GENERATED_USTRUCT_BODY()
//TODO only one in Unreal
UPROPERTY()
TArray<float> box; //12 Elemete
UPROPERTY()
TArray<float> region; //6 Elemete
UPROPERTY()
TArray<float> sphere; //4 Elemete
};
USTRUCT()
struct FTileContent
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FBoundingVolume boundingVolume;
UPROPERTY()
FString url;
};
USTRUCT()
struct FTile
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FBoundingVolume boundingVolume;
UPROPERTY()
FBoundingVolume viewerRequestVolume;
UPROPERTY()
float geometricError;
UPROPERTY()
FString refine; //TODO: "enum" : ["add", "replace"]
UPROPERTY()
TArray<float> transform; //16 Elemete
//TODO "default" : [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 ]
UPROPERTY()
FTileContent content;
UPROPERTY()
TArray<FTile> children;
FTile() {
float transformDefault[] = { 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
transform.Empty();
transform.Append(transformDefault, 16);
}
};
USTRUCT()
struct FTileset
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FAsset asset;
UPROPERTY()
FPropertieDict properties;
UPROPERTY()
float geometricError;
UPROPERTY()
FTile root;
FTileset() {
geometricError = -1;
}
};
/** /**
* *
*/ */
......
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