Commit 756191bf by Kai Westerkamp

i3dm

parent bb9138ce
......@@ -71,38 +71,103 @@ void ATilesetActor::parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, F
}
}
void ATilesetActor::parse3DTile(const TArray<uint8> data, FTile *tile)
void ATilesetActor::parseBatched3DTile(const TArray<uint8> data, FTile * tile)
{
TileHeader *header = (TileHeader*) data.GetData();
Batch3DModelHeader *b3dmheader = (Batch3DModelHeader*)data.GetData();
UE_LOG(TILES, Log, TEXT("Batch3DModel Batches: %d"), b3dmheader->batchLength);
UWorld* const World = GetWorld();
if (World)
{
AProceduralEntity *gltf = World->SpawnActor<AProceduralEntity>(AProceduralEntity::StaticClass());
gltf->tile = *tile;
#if WITH_EDITOR
gltf->SetFolderPath(FName(*("SpawnedGLTF/" + this->GetName())));
#endif
gltf->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
gltf->SetActorRelativeTransform(FTransform(*tile->getAbsoluteTransform()));
int GLTFstart = b3dmheader->getGLTFStart();
UE_LOG(TILES, Warning, TEXT("Shared Tile Header: Magic: %s Version %d lenght %d, array lenght %d "), *header->getMagicAsFString(), header->version, header->byteLength, data.Num());
gltf->loadModel(&data.GetData()[GLTFstart], (data.Num() - GLTFstart));
}
}
void ATilesetActor::parseInstanced3DTile(const TArray<uint8> data, FTile * tile)
{
Instanced3DModelHeader *i3dmheader = (Instanced3DModelHeader*)data.GetData();
FString featureJSON = i3dmheader->getpartAsString(i3dmheader->getFeatureStart(), i3dmheader->featureTable.featureTableJSONByteLength);
UE_LOG(TILES, Log, TEXT("Instanced3DModelHeader GLTFFormat %s FeatureTable JSON: %s"), i3dmheader->gltfFormat == 0 ? TEXT("URL") : TEXT("Binary GLTF"), *featureJSON);
TSharedPtr<FJsonObject> JsonParsed;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(featureJSON);
if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
{
int32 instances_length = JsonParsed->GetIntegerField("INSTANCES_LENGTH");// FIXME is uint32;
if (header->isB3DM()) {
Batch3DModelHeader *b3dmheader = (Batch3DModelHeader*) data.GetData();
UE_LOG(TILES, Log, TEXT("Batch3DModel Batches: %d"), b3dmheader->batchLength);
UWorld* const World = GetWorld();
if (World)
{
AProceduralEntity *gltf = World->SpawnActor<AProceduralEntity>(AProceduralEntity::StaticClass());
gltf->tile = *tile;
if (i3dmheader->gltfFormat == 1) {
AProceduralEntity *gltf = World->SpawnActor<AProceduralEntity>(AProceduralEntity::StaticClass());
gltf->tile = *tile;
#if WITH_EDITOR
gltf->SetFolderPath(FName(*("SpawnedGLTF/"+this->GetName())));
gltf->SetFolderPath(FName(*("SpawnedGLTF/" + this->GetName())));
#endif
gltf->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
gltf->SetActorRelativeTransform(FTransform(*tile->getAbsoluteTransform()));
int GLTFstart = b3dmheader->getGLTFStart();
gltf->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
gltf->SetActorRelativeTransform(FTransform(*tile->getAbsoluteTransform()));
int GLTFstart = i3dmheader->getGLTFStart();
gltf->loadModel(&data.GetData()[GLTFstart], (data.Num() - GLTFstart));
//https://answers.unrealengine.com/questions/136562/is-there-a-way-to-clone-duplicate-an-actor-in-c.html
if (JsonParsed->HasField("POSITION")) {
uint32 featureTableBinaryOffset = i3dmheader->getFeatureStart() + i3dmheader->featureTable.featureTableJSONByteLength;
TSharedPtr<FJsonObject> binaryBodyReference = JsonParsed->GetObjectField("POSITION");
int32 byteOffset = binaryBodyReference->GetIntegerField("byteOffset");
TArray<FVector> positons = TArray<FVector>();// getAsArray<FVector>(data.GetData(), featureTableBinaryOffset + byteOffset, instances_length);
FString outputString = "[";
for (FVector pos : positons)
{
outputString += "[" + pos.ToString() +"] ";
}
outputString += "]";
UE_LOG(TILES, Warning, TEXT("InStanced 3D Model Positions %s"), *outputString);
}
else {
UE_LOG(TILES, Warning, TEXT("INStanced 3D Model Position Quantized not Supported in %s"), *tile->content.url);
}
}
gltf->loadModel(&data.GetData()[GLTFstart], (data.Num() - GLTFstart));
}
}
}
void ATilesetActor::parse3DTile(const TArray<uint8> data, FTile *tile)
{
TileHeader *header = (TileHeader*) data.GetData();
UE_LOG(TILES, Warning, TEXT("Shared Tile Header: Magic: %s Version %d lenght %d, array lenght %d "), *header->getMagicAsFString(), header->version, header->byteLength, data.Num());
if (header->isB3DM()) {
parseBatched3DTile(data, tile);
}
else if (header->isI3DM()) {
Instanced3DModelHeader *i3dmheader = (Instanced3DModelHeader* ) data.GetData();
FString featureJSON = i3dmheader->getpartAsString(i3dmheader->getFeatureStart(), i3dmheader->featureTable.featureTableJSONByteLength);
UE_LOG(TILES, Log, TEXT("Instanced3DModelHeader GLTFFormat %s FeatureTable JSON: %s"), i3dmheader->gltfFormat == 0? TEXT("URL"): TEXT("Binary GLTF") , *featureJSON);
parseInstanced3DTile(data, tile);
}
}
FMatrix * FTile::getMatrix()
{
if (realtiveTransform == nullptr) {
......
......@@ -296,8 +296,18 @@ private:
void parseTile(TSharedPtr<FJsonObject> json, FTile *targetTile, FTileset* parent);
void parseBatched3DTile(const TArray<uint8> data, FTile *tile);
void parseInstanced3DTile(const TArray<uint8> data, FTile *tile);
template <typename T> TArray<T> getAsArray(uint8* data, int32 offset, int32 numberOfElements);
};
template<typename T>
inline TArray<T> ATilesetActor::getAsArray(uint8 *data, int32 offset, int32 numberOfElements)
{
//T *ArrayPointer = (T*)(data + offset);
//TArray<T> result;
//result.Append(ArrayPointer, numberOfElements);
//return result;
return TArray<T>();
}
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