Collisions fixed
This commit is contained in:
parent
71bb22f874
commit
3c6605ff79
Binary file not shown.
|
@ -95,6 +95,85 @@ void UMapGeneratorWidget::CookVegetationToCurrentTile(const TArray<UProceduralFo
|
||||||
*CUR_CLASS_FUNC_LINE);
|
*CUR_CLASS_FUNC_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool UMapGeneratorWidget::RecalculateCollision(FString MapPath)
|
||||||
|
{
|
||||||
|
UWorld* World = GEditor->GetEditorWorldContext().World();
|
||||||
|
// UWorld* World = GEngine->GetWorld();
|
||||||
|
if(World == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ALandscape* Landscape = (ALandscape*) UGameplayStatics::GetActorOfClass(
|
||||||
|
World,
|
||||||
|
ALandscape::StaticClass());
|
||||||
|
// LandscapePostEditEvent(Landscape);
|
||||||
|
|
||||||
|
FProperty* PropertyToUpdate = Landscape->GetClass()->FindPropertyByName(TEXT("CollisionMipLevel"));
|
||||||
|
int32* PropertyValue = PropertyToUpdate->ContainerPtrToValuePtr<int32>(Landscape);
|
||||||
|
if(!PropertyToUpdate){
|
||||||
|
UE_LOG(LogCarlaToolsMapGenerator, Warning, TEXT("%s: Could not found the specified property"),
|
||||||
|
*CUR_CLASS_FUNC_LINE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*PropertyValue += 1; // Increment
|
||||||
|
|
||||||
|
FPropertyChangedEvent LandscapeCustomPropertyChangedEvent(PropertyToUpdate);
|
||||||
|
Landscape->PostEditChangeProperty(LandscapeCustomPropertyChangedEvent);
|
||||||
|
Landscape->PostEditChange();
|
||||||
|
|
||||||
|
|
||||||
|
Landscape->RecreateCollisionComponents();
|
||||||
|
|
||||||
|
if (MapPath == "")
|
||||||
|
{
|
||||||
|
MapPath = World->GetPathName();
|
||||||
|
}
|
||||||
|
Landscape->ReregisterAllComponents();
|
||||||
|
/* bool bSaveMapSuccess = FEditorFileUtils::SaveMap(World,
|
||||||
|
World->GetPathName());*/
|
||||||
|
UEditorAssetLibrary::SaveAsset(World->GetPathName(), true);
|
||||||
|
bool bSuccess = FEditorFileUtils::SaveDirtyPackages(true, true, true, true, true, true);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UMapGeneratorWidget::CookTilesCollisions(const FMapGeneratorMetaInfo& MetaInfo)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < MetaInfo.SizeX; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < MetaInfo.SizeY; j++)
|
||||||
|
{
|
||||||
|
const FString MapName =
|
||||||
|
MetaInfo.MapName + "_Tile_" + FString::FromInt(i) + "_" + FString::FromInt(j);
|
||||||
|
const FString MapNameToLoad = MetaInfo.DestinationPath + "/" + MapName + "." + MapName;
|
||||||
|
|
||||||
|
bool bLoadedSuccess = FEditorFileUtils::LoadMap(*MapNameToLoad, false, true);
|
||||||
|
|
||||||
|
if (!bLoadedSuccess)
|
||||||
|
UE_LOG(LogCarlaToolsMapGenerator, Log, TEXT("%s: Error loading to %s tiles"),
|
||||||
|
*CUR_CLASS_FUNC_LINE, *MetaInfo.MapName);
|
||||||
|
|
||||||
|
UWorld* EditorWorld = GEditor->GetEditorWorldContext().World();
|
||||||
|
|
||||||
|
UE_LOG(LogCarlaToolsMapGenerator, Log, TEXT("%s: HERE! %s -- %s to %s tiles"),
|
||||||
|
*CUR_CLASS_FUNC_LINE, *MapNameToLoad, *GEditor->GetEditorWorldContext().World()->GetName(), *MetaInfo.MapName);
|
||||||
|
|
||||||
|
bool bRecalculateResult = RecalculateCollision(MapNameToLoad);
|
||||||
|
|
||||||
|
if (!bRecalculateResult)
|
||||||
|
UE_LOG(LogCarlaToolsMapGenerator, Error, TEXT("%s: Error recalculating to %s tiles"),
|
||||||
|
*CUR_CLASS_FUNC_LINE, *MetaInfo.MapName);
|
||||||
|
|
||||||
|
//bool bSaveMapSuccess = FEditorFileUtils::SaveMap(GEditor->GetEditorWorldContext().World(),
|
||||||
|
//MapNameToLoad);
|
||||||
|
|
||||||
|
//if(!bSaveMapSuccess)
|
||||||
|
//UE_LOG(LogCarlaToolsMapGenerator, Error, TEXT("%s: Error Saving to %s tiles"),
|
||||||
|
//*CUR_CLASS_FUNC_LINE, *MetaInfo.MapName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FString UMapGeneratorWidget::SanitizeDirectory(FString InDirectory)
|
FString UMapGeneratorWidget::SanitizeDirectory(FString InDirectory)
|
||||||
{
|
{
|
||||||
UE_LOG(LogCarlaToolsMapGenerator, Log, TEXT("%s: Sanitazing directory: %s"),
|
UE_LOG(LogCarlaToolsMapGenerator, Log, TEXT("%s: Sanitazing directory: %s"),
|
||||||
|
@ -744,6 +823,8 @@ bool UMapGeneratorWidget::CreateTilesMaps(const FMapGeneratorMetaInfo& MetaInfo)
|
||||||
// Apply material
|
// Apply material
|
||||||
AssignLandscapeMaterial(Landscape);
|
AssignLandscapeMaterial(Landscape);
|
||||||
|
|
||||||
|
Landscape->RecreateCollisionComponents();
|
||||||
|
|
||||||
const FString PackageFileName = FPackageName::LongPackageNameToFilename(
|
const FString PackageFileName = FPackageName::LongPackageNameToFilename(
|
||||||
PackageName,
|
PackageName,
|
||||||
FPackageName::GetMapPackageExtension());
|
FPackageName::GetMapPackageExtension());
|
||||||
|
@ -762,6 +843,8 @@ bool UMapGeneratorWidget::CreateTilesMaps(const FMapGeneratorMetaInfo& MetaInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CookTilesCollisions(MetaInfo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,12 @@ public:
|
||||||
UFUNCTION(Category="Map Generator", BlueprintCallable)
|
UFUNCTION(Category="Map Generator", BlueprintCallable)
|
||||||
void CookVegetationToCurrentTile(const TArray<UProceduralFoliageSpawner*> FoliageSpawners);
|
void CookVegetationToCurrentTile(const TArray<UProceduralFoliageSpawner*> FoliageSpawners);
|
||||||
|
|
||||||
|
UFUNCTION(Category="Map Generator", BlueprintCallable)
|
||||||
|
bool RecalculateCollision(FString MapPath = "");
|
||||||
|
|
||||||
|
UFUNCTION(Category = "MapGenerator", BlueprintCallable)
|
||||||
|
void CookTilesCollisions(const FMapGeneratorMetaInfo& MetaInfo);
|
||||||
|
|
||||||
/// Utils funtion to format @a InDirectory so it gets sanitized in a
|
/// Utils funtion to format @a InDirectory so it gets sanitized in a
|
||||||
/// format that unreal can access the directory, deleting unnecesary
|
/// format that unreal can access the directory, deleting unnecesary
|
||||||
/// characters such as final '/' or '\'
|
/// characters such as final '/' or '\'
|
||||||
|
@ -168,6 +174,8 @@ private:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
bool CreateTilesMaps(const FMapGeneratorMetaInfo& MetaInfo);
|
bool CreateTilesMaps(const FMapGeneratorMetaInfo& MetaInfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Searches for the specified map in the specified path in @a MetaInfo
|
/// Searches for the specified map in the specified path in @a MetaInfo
|
||||||
/// and starts the vegetation cooking process for each of the tile.
|
/// and starts the vegetation cooking process for each of the tile.
|
||||||
/// IMPORTANT: Only maps with '_Tile_' tag in it name are processed as
|
/// IMPORTANT: Only maps with '_Tile_' tag in it name are processed as
|
||||||
|
|
Loading…
Reference in New Issue