Commit 2906199f by wester

started Bounding Boxes

parent 6e1ee0e8
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "TileDownloader.h" #include "TileDownloader.h"
#include "ue4-assimp/ProceduralEntity.h" #include "ue4-assimp/ProceduralEntity.h"
#include "Tileset.h" #include "Tileset.h"
#include "Kismet/KismetMathLibrary.h"
ATilesetActor::ATilesetActor(const FObjectInitializer& ObjectInitializer) { ATilesetActor::ATilesetActor(const FObjectInitializer& ObjectInitializer) {
...@@ -75,8 +76,19 @@ void ATilesetActor::Tick(float DeltaSeconds) ...@@ -75,8 +76,19 @@ void ATilesetActor::Tick(float DeltaSeconds)
double FTile::getScreenSpaceError(double lambda, FVector CamLocation) double FTile::getScreenSpaceError(double lambda, FVector CamLocation)
{ {
FMatrix matrix = FMatrix();
if (content.absoluteTileTranforms.Num() > 0) {
matrix = content.absoluteTileTranforms[0];
}
else {
matrix = *getAbsoluteTransform();
}
FVector ActorPos = FTransform(*this->getAbsoluteTransform()).GetTranslation(); FVector ActorPos = FTransform(*this->getAbsoluteTransform()).GetTranslation();
double dist = (CamLocation - ActorPos).Size(); double dist = boundingVolume.getDistanceTo(CamLocation, matrix);
(CamLocation - ActorPos).Size();
if (content.url.EndsWith("i3d")) { if (content.url.EndsWith("i3d")) {
...@@ -227,11 +239,13 @@ void ATilesetActor::parseBatched3DTile(const TArray<uint8> data, FTile * tile) ...@@ -227,11 +239,13 @@ void ATilesetActor::parseBatched3DTile(const TArray<uint8> data, FTile * tile)
#endif #endif
gltf->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform); gltf->AttachToActor(this, FAttachmentTransformRules::KeepWorldTransform);
FMatrix leftToRight(FVector(-1, 0, 0), FVector(0, 0, 1), FVector(0, 1, 0), FVector(0, 0, 0)); FMatrix leftToRight(FVector(-1, 0, 0), FVector(0, 0, 1), FVector(0, 1, 0), FVector(0, 0, 0));
gltf->SetActorRelativeTransform(FTransform(leftToRight * *tile->getAbsoluteTransform())); FMatrix globalTielTransform = leftToRight * *tile->getAbsoluteTransform();
gltf->SetActorRelativeTransform(FTransform(globalTielTransform));
int GLTFstart = b3dmheader->getGLTFStart(); int GLTFstart = b3dmheader->getGLTFStart();
gltf->loadModel(&data.GetData()[GLTFstart], (data.Num() - GLTFstart)); gltf->loadModel(&data.GetData()[GLTFstart], (data.Num() - GLTFstart));
tile->content.tiles.Add(gltf); tile->content.tiles.Add(gltf);
tile->content.absoluteTileTranforms.Add(globalTielTransform);
tile->setVisible(false); tile->setVisible(false);
} }
} }
...@@ -277,7 +291,8 @@ void ATilesetActor::parseInstanced3DTile(const TArray<uint8> data, FTile * tile) ...@@ -277,7 +291,8 @@ void ATilesetActor::parseInstanced3DTile(const TArray<uint8> data, FTile * tile)
for (FVector pos : positons) for (FVector pos : positons)
{ {
outputString += "[" + pos.ToString() +"] "; outputString += "[" + pos.ToString() +"] ";
AProceduralEntity* clone = gltf->clone(pos); AProceduralEntity* clone = gltf->clone();
FMatrix instanceTranform = FMatrix();
if (JsonParsed->GetBoolField("EAST_NORTH_UP")) { if (JsonParsed->GetBoolField("EAST_NORTH_UP")) {
FVector up(pos); FVector up(pos);
...@@ -286,15 +301,22 @@ void ATilesetActor::parseInstanced3DTile(const TArray<uint8> data, FTile * tile) ...@@ -286,15 +301,22 @@ void ATilesetActor::parseInstanced3DTile(const TArray<uint8> data, FTile * tile)
FVector east = FVector::CrossProduct( Z, up ); FVector east = FVector::CrossProduct( Z, up );
FVector north = FVector::CrossProduct(east, up); FVector north = FVector::CrossProduct(east, up);
FMatrix NEU(north, up, east, pos); FMatrix NEU(north, up, east, pos);
clone->SetActorTransform(FTransform(NEU)); instanceTranform = NEU;
}
else {
FTransform trans = FTransform(pos);
instanceTranform = trans.ToMatrixWithScale();
//TODO add rotation and ransform gltf -> tiles
} }
clone->SetActorTransform(FTransform(instanceTranform));
tile->content.absoluteTileTranforms.Add(instanceTranform);
tile->content.tiles.Add(clone); tile->content.tiles.Add(clone);
} }
tile->content.tiles.Add(gltf); tile->content.tiles.Add(gltf);
gltf->SetActorTransform(FTransform(positons[0])); FTransform trans = FTransform(positons[0]);
tile->content.absoluteTileTranforms.Add(trans.ToMatrixWithScale());
gltf->SetActorTransform(trans);
outputString += "]"; outputString += "]";
UE_LOG(TILES, Warning, TEXT("InStanced 3D Model Positions %s"), *outputString); UE_LOG(TILES, Warning, TEXT("InStanced 3D Model Positions %s"), *outputString);
} }
...@@ -370,3 +392,41 @@ FMatrix * FTile::getAbsoluteTransform() ...@@ -370,3 +392,41 @@ FMatrix * FTile::getAbsoluteTransform()
return absoluteTransform; return absoluteTransform;
} }
float FBoundingVolume::getDistanceTo(FVector Position, FMatrix bouindingTransformation)
{
FVector localPos = bouindingTransformation.Inverse().TransformFVector4(FVector4(Position,1));
float distance = 0.0f;
if (box.Num() == 12) {
FVector Center = FVector(box[0], box[1], box[2]);
//implicit Halflength
FVector XAxis = FVector(box[3], box[4], box[5]);
FVector YAxis = FVector(box[6], box[7], box[8]);
FVector ZAxis = FVector(box[9], box[10], box[11]);
//TODO FIXME is currently spher distance
UE_LOG(TILES, Error, TEXT("Box distance is not implemented"));
double dist = (localPos - Center).Size();
distance = dist - FMath::Max3(XAxis.Size(), YAxis.Size(), ZAxis.Size());
}
else if (region.Num() == 6) {
// WGS84
//TODO FIXME is currently spher distance
UE_LOG(TILES, Error, TEXT("Region distance is not implemented"));
FVector Center = FVector(0, 0, 6378137);
double dist = (Position - Center).Size();
distance = dist;
}else if (sphere.Num() == 4) {
double dist = (localPos - FVector(sphere[0], sphere[1], sphere[2])).Size();
distance = dist - sphere[3];
}
else {
UE_LOG(TILES, Error, TEXT("Not Allowed Tranformation"));
}
return distance;
}
...@@ -77,6 +77,8 @@ struct FBoundingVolume ...@@ -77,6 +77,8 @@ struct FBoundingVolume
UPROPERTY() UPROPERTY()
TArray<float> sphere; //4 Elemete TArray<float> sphere; //4 Elemete
float getDistanceTo(FVector LocalPosition, FMatrix bouindingTransformation);
}; };
USTRUCT() USTRUCT()
...@@ -94,6 +96,7 @@ struct FTileContent ...@@ -94,6 +96,7 @@ struct FTileContent
TArray<uint8> content; TArray<uint8> content;
struct FTileset *tileset; struct FTileset *tileset;
TArray<class AProceduralEntity*> tiles; TArray<class AProceduralEntity*> tiles;
TArray<FMatrix> absoluteTileTranforms;
FTileContent() { FTileContent() {
tileset = nullptr; tileset = nullptr;
......
...@@ -288,7 +288,7 @@ void AProceduralEntity::loadModel(const uint8* RawFileData, int32 lenght) { ...@@ -288,7 +288,7 @@ void AProceduralEntity::loadModel(const uint8* RawFileData, int32 lenght) {
UE_LOG(GLTF, Log, TEXT("GLTF loaded: %i Vertecies in %f seconds"), _numVertecies, end - start); UE_LOG(GLTF, Log, TEXT("GLTF loaded: %i Vertecies in %f seconds"), _numVertecies, end - start);
} }
AProceduralEntity* AProceduralEntity::clone(const FVector position) AProceduralEntity* AProceduralEntity::clone()
{ {
FActorSpawnParameters Parameters; FActorSpawnParameters Parameters;
Parameters.Template = this; Parameters.Template = this;
...@@ -298,8 +298,6 @@ AProceduralEntity* AProceduralEntity::clone(const FVector position) ...@@ -298,8 +298,6 @@ AProceduralEntity* AProceduralEntity::clone(const FVector position)
#if WITH_EDITOR #if WITH_EDITOR
New->SetFolderPath(this->GetFolderPath()); New->SetFolderPath(this->GetFolderPath());
#endif #endif
FTransform trans = FTransform(position);
New->SetActorTransform(trans);
return New; return New;
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void loadModel(const uint8* RawFileData, int32 lenght); void loadModel(const uint8* RawFileData, int32 lenght);
AProceduralEntity* clone(FVector position); AProceduralEntity* clone();
void setActorDisabled(bool disabled); void setActorDisabled(bool disabled);
......
Subproject commit 63485bdd265729d2ae8c65ef0bc4c6bfe4c4df73 Subproject commit 1ab85f16ff687c214ebe61a1f598b3de60fe2487
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