-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathue-rebuild-lightmaps.ps1
More file actions
152 lines (127 loc) · 5.43 KB
/
Copy pathue-rebuild-lightmaps.ps1
File metadata and controls
152 lines (127 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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
# Include Git tools locking
. $PSScriptRoot\GitScripts\inc\locking.ps1
function Write-Usage {
Write-Output "Steve's Unreal lightmap rebuilding tool"
Write-Output "Usage:"
Write-Output " ue-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:"
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 " "
}
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 }
Write-Output "~-~-~ Unreal Lightmap Rebuild Start ~-~-~"
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 })"
}
} 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
}
if ($foundmaps.BaseNames.Count -eq 0) {
throw "No maps found to rebuild"
}
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)"
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 }
}
$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
$ueEditorCmd = Get-UEEditorCmd $ueVersion $ueinstall
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 -PassThru -NoNewWindow | Wait-Process -PassThru
if ($proc.ExitCode -ne 0) {
throw "Lightmap build failed!"
}
}
} catch {
Write-Output $_.Exception.Message
Write-Output "~-~-~ Unreal Lightmap Rebuild FAILED ~-~-~"
Exit 9
}
Write-Output "~-~-~ Unreal Lightmap Rebuild OK ~-~-~"
Write-Output "Reminder: You may need to commit and unlock map files"