From 1d6fa2377014e9bb61e298c63e72dc72dd247ec4 Mon Sep 17 00:00:00 2001 From: Blyron <53337103+Blyron@users.noreply.github.com> Date: Thu, 3 Nov 2022 16:03:17 +0100 Subject: [PATCH] Aaron/floorheightfix (#5909) * Added local frame option. Fixed inputs for NN * Add Textures * Changed texture to grayscale RGB and added check for 'air' particles * Updated 2k and 4k textures enable parameter for select res texture for deformation * Fix issue where trying to access TMap when loading * Use contains functions instead of checking num of elemnts on tmap to make a secure access * Used ParticlesHeightmap optimization and clear some log * Fixed number of particles inputs. Removed debug output. Fixed mutex creating cpu stalls * Decoupling visualization with gamethread * Make work optimisations * Disable deformation visualization * Updated collisions parameters, collisions itself are not updated * Disable Collisions vehicle with landscape * Add in pytorch output wheel normal and put them into UE4 and apply to wheels * Added factors based on distance, never negative, check if there are particles * Fix compilation error * Removed unused code and normals related code * Fixed compiling error * Fix floor height Co-authored-by: Axel --- .../Carla/Vehicle/CustomTerrainPhysicsComponent.cpp | 12 ++++-------- .../Carla/Vehicle/CustomTerrainPhysicsComponent.h | 5 ++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp index 2b758408e..89d1c245f 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.cpp @@ -184,6 +184,7 @@ void FDenseTile::InitializeTile(uint32_t TextureSize, float AffectedRadius, floa PartialHeightMapSize = TileSize * TextureSize / (2*AffectedRadius); std::string FileName = std::string(TCHAR_TO_UTF8(*( SavePath + TileOrigin.ToString() + ".tile" ) ) ); + //UE_LOG(LogCarla, Log, TEXT("Tile origin %s"), *TileOrigin.ToString() ); if( FPaths::FileExists(FString(FileName.c_str())) ) { @@ -214,7 +215,6 @@ void FDenseTile::InitializeTile(uint32_t TextureSize, float AffectedRadius, floa { FDVector ParticleLocalPosition = FDVector(i*ParticleSize, j*ParticleSize, 0.0f); FDVector ParticlePosition = TileOrigin + ParticleLocalPosition; - // UE_LOG(LogCarla, Log, TEXT(" Particle position %s"), *ParticlePosition.ToString()); float Height = HeightMap.GetHeight(ParticlePosition); for(uint32_t k = 0; k < NumParticles_Z; k++) { @@ -617,11 +617,8 @@ FDVector FSparseHighDetailMap::GetTilePosition(uint64_t TileId) FDVector FSparseHighDetailMap::GetTilePosition(uint32_t Tile_X, uint32_t Tile_Y) { - - FDVector Position = FDVector(Tile_X*TileSize, Tile_Y*TileSize, 0); + FDVector Position = FDVector(Tile_X*TileSize, Tile_Y*TileSize, FloorHeight); Position = Position + Tile0Position; - //UE_LOG(LogCarla, Log, TEXT("Getting location from id (%lu, %lu) %s"), - // (unsigned long)Tile_X, (unsigned long)Tile_Y, *(Position).ToString()); return Position; } @@ -1272,7 +1269,7 @@ void UCustomTerrainPhysicsComponent::BeginPlay() UE_LOG(LogCarla, Warning, TEXT("ParticleDiameter %f"), ParticleDiameter); - SparseMap.Init(TextureToUpdate->GetSizeX(), TextureRadius, ParticleDiameter * CMToM, TerrainDepth * CMToM); + SparseMap.Init(TextureToUpdate->GetSizeX(), TextureRadius, ParticleDiameter * CMToM, TerrainDepth * CMToM, FloorHeight * CMToM ); RootComponent = Cast(GetOwner()->GetRootComponent()); if(LargeMapManager) { @@ -1281,7 +1278,6 @@ void UCustomTerrainPhysicsComponent::BeginPlay() // UE_LOG(LogCarla, Log, // TEXT("World Size %s"), *(WorldSize.ToString())); } - Tile0Origin.Z += FloorHeight; // SparseMap.InitializeMap(HeightMap, UEFrameToSI(Tile0Origin), UEFrameToSI(WorldSize), // 1.f, MinHeight, MaxHeight, HeightMapScaleFactor.Z); if (DataAsset) @@ -1460,7 +1456,7 @@ void UCustomTerrainPhysicsComponent::TickComponent(float DeltaTime, FVector TilePosition = HeightMapOffset + LargeMapManager->GetTileLocation(CurrentLargeMapTileId) - 0.5f*FVector(LargeMapManager->GetTileSize(), -LargeMapManager->GetTileSize(), 0); UE_LOG(LogCarla, Log, TEXT("Updating height map to location %s in tile location %s"), *TilePosition.ToString(), *LargeMapManager->GetTileLocation(CurrentLargeMapTileId).ToString()); - TilePosition.Z += FloorHeight; + TilePosition.Z += UEFrameToSI(FloorHeight) ; SparseMap.UpdateHeightMap( HeightMapDataAsset, UEFrameToSI(TilePosition), UEFrameToSI(FVector( LargeMapManager->GetTileSize(),-LargeMapManager->GetTileSize(), 0)), diff --git a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h index acd12562e..ca5521a6e 100644 --- a/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h +++ b/Unreal/CarlaUE4/Plugins/Carla/Source/Carla/Vehicle/CustomTerrainPhysicsComponent.h @@ -115,12 +115,14 @@ public: FSparseHighDetailMap(float ParticleDiameter = 0.02f, float Depth = 0.4f) : ParticleSize(ParticleDiameter), TerrainDepth(Depth) {}; - void Init( uint32 NewTextureSize, float NewAffectedRadius, float ParticleDiameter, float Depth) + void Init( uint32 NewTextureSize, float NewAffectedRadius, float ParticleDiameter, + float Depth, float NewFloorHeight ) { ParticleSize = ParticleDiameter; TerrainDepth = Depth; TextureSize = NewTextureSize; AffectedRadius = NewAffectedRadius; + FloorHeight = NewFloorHeight; UE_LOG(LogCarla, Warning, TEXT("ParticleSize %f"), ParticleSize); } @@ -211,6 +213,7 @@ private: FHeightMapData Heightmap; float ParticleSize = 0.02f; float TerrainDepth = 0.4f; + float FloorHeight = 0.0f; uint32 TextureSize = 0; float AffectedRadius = 0.0f; FVector PositionToUpdate;