UEScripts/ue4-rebuild-lightmaps.ps1

153 lines
5.4 KiB
PowerShell
Raw Permalink Normal View History

2020-10-06 15:57:54 +01:00
# Lightmap rebuild helper
[CmdletBinding()] # Fail on unknown args
param (
# Optional source folder, assumed current folder
[string]$src,
# quality level (Preview, Medium, High, Production), default = Production
[string]$quality,
# Explicit list of maps, if not supplied will use cooked maps in packageconfig.json
[array]$maps,
# Dry-run; does nothing but report what *would* have happened
[switch]$dryrun = $false,
[switch]$help = $false
)
. $PSScriptRoot\inc\platform.ps1
. $PSScriptRoot\inc\packageconfig.ps1
. $PSScriptRoot\inc\projectversion.ps1
. $PSScriptRoot\inc\uproject.ps1
. $PSScriptRoot\inc\filetools.ps1
2020-10-06 15:57:54 +01:00
# Include Git tools locking
. $PSScriptRoot\GitScripts\inc\locking.ps1
2020-10-06 15:57:54 +01:00
function Write-Usage {
2022-04-19 12:07:09 +01:00
Write-Output "Steve's Unreal lightmap rebuilding tool"
2020-10-06 15:57:54 +01:00
Write-Output "Usage:"
Write-Output " ue4-rebuild-lightmaps.ps1 [-src:sourcefolder] [-quality:(preview|medium|high|production)] [-maps Map1,Map2,Map3] [-dryrun]"
Write-Output " "
Write-Output " -src : Source folder (current folder if omitted)"
Write-Output " -quality : Lightmap quality, preview/medium/high/production"
Write-Output " : (Default: production)"
Write-Output " -maps : List of maps to rebuild. If omitted, will derive which ones to"
Write-Output " rebuild based on cooked maps in packageconfig.json"
Write-Output " -dryrun : Don't perform any actual actions, just report on what you would do"
Write-Output " -help : Print this help"
Write-Output " "
Write-Output "Environment Variables:"
2022-04-19 12:07:09 +01:00
Write-Output " UEINSTALL : Use a specific Unreal install."
Write-Output " : Default is to find one based on project version, under UEROOT"
Write-Output " UEROOT : Parent folder of all binary Unreal installs (detects version). "
Write-Output " : Default C:\Program Files\Epic Games"
Write-Output " "
2020-10-06 15:57:54 +01:00
}
if ($src.Length -eq 0) {
$src = "."
Write-Verbose "-src not specified, assuming current directory"
}
$ErrorActionPreference = "Stop"
if ($help) {
Write-Usage
Exit 0
}
# Detect Git
if ($src -ne ".") { Push-Location $src }
$isGit = Test-Path ".git"
if ($src -ne ".") { Pop-Location }
2022-04-19 12:07:09 +01:00
Write-Output "~-~-~ Unreal Lightmap Rebuild Start ~-~-~"
2020-10-06 15:57:54 +01:00
try {
$config = Read-Package-Config -srcfolder:$src
$projfile = Get-Uproject-Filename -srcfolder:$src -config:$config
$proj = Read-Uproject $projfile
$ueVersion = Get-UE-Version $proj
$ueinstall = Get-UE-Install $ueVersion
if ($maps) {
# Explicit list of maps provided on command line
$foundmaps = Find-File-Set -startDir:$(Join-Path $src "Content") -pattern:*.umap -includeByDefault:$false -includeBaseNames:$maps
if ($mapsToRebuild.Count -ne $maps.Count) {
Write-Warning "Ignoring missing map(s): $($maps | Where-Object { $_ -notin $mapsToRebuild })"
}
2020-10-06 15:57:54 +01:00
} else {
# Derive maps from cook settings
$foundmaps = Find-Files -startDir:$(Join-Path $src "Content") -pattern:*.umap -includeByDefault:$config.CookAllMaps -includeBaseNames:$config.MapsIncluded -excludeBaseNames:$config.MapsExcluded
2020-10-06 15:57:54 +01:00
}
if ($foundmaps.BaseNames.Count -eq 0) {
throw "No maps found to rebuild"
}
2020-10-06 15:57:54 +01:00
if (-not $quality) {
$quality = "Production"
}
if ($quality -notin @("Preview", "Medium", "High", "Production")) {
throw "Invalid quality level: $quality"
}
Write-Output ""
Write-Output "Project File : $projfile"
Write-Output "UE Version : $ueVersion"
Write-Output "UE Install : $ueinstall"
Write-Output ""
Write-Output "Maps : $($foundmaps.BaseNames)"
2020-10-06 15:57:54 +01:00
Write-Output "Quality : $quality"
Write-Output ""
# lock map files if read-only
if ($isGit -and -not $dryrun) {
if ($src -ne ".") { Push-Location $src }
foreach ($mapfullname in $foundmaps.FullNames) {
$relativepath = Resolve-Path $mapfullname -Relative
Lock-If-Required $relativepath
Lock-If-Required $($relativepath -replace ".uasset","_BuiltData.uasset")
}
if ($src -ne ".") { Pop-Location }
}
2020-10-06 15:57:54 +01:00
$argList = [System.Collections.ArrayList]@()
$argList.Add("`"$projfile`"") > $null
$argList.Add("-run=ResavePackages") > $null
$argList.Add("-buildtexturestreaming") > $null
$argList.Add("-buildlighting") > $null
$argList.Add("-buildreflectioncaptures") > $null
$argList.Add("-MapsOnly") > $null
$argList.Add("-ProjectOnly") > $null
$argList.Add("-AllowCommandletRendering") > $null
$argList.Add("-SkipSkinVerify") > $null
$argList.Add("-Quality=$quality") > $null
$argList.Add("-Map=$($foundmaps.BaseNames -join "+")") > $null
2020-10-06 15:57:54 +01:00
2022-04-19 12:07:09 +01:00
$ueEditorCmd = Get-UEEditorCmd $ueVersion $ueinstall
2020-10-06 15:57:54 +01:00
if ($dryrun) {
Write-Output "Would have run:"
Write-Output "> $ueEditorCmd $($argList -join " ")"
} else {
Write-Output "Starting lighting build; see Swarm Agent for full progress monitoring..."
$proc = Start-Process $ueEditorCmd $argList -Wait -PassThru -NoNewWindow
2020-10-06 15:57:54 +01:00
if ($proc.ExitCode -ne 0) {
throw "Lightmap build failed!"
}
}
} catch {
Write-Output $_.Exception.Message
2022-04-19 12:07:09 +01:00
Write-Output "~-~-~ Unreal Lightmap Rebuild FAILED ~-~-~"
2020-10-06 15:57:54 +01:00
Exit 9
}
2022-04-19 12:07:09 +01:00
Write-Output "~-~-~ Unreal Lightmap Rebuild OK ~-~-~"
Write-Output "Reminder: You may need to commit and unlock map files"