Forked from JonasReich/ExtractTextureReportFromMemreport.ps1
Last active
April 16, 2023 16:50
-
-
Save moppius/78d0a52f53fbcedf9403520b884b5fda to your computer and use it in GitHub Desktop.
Extract Texture Report csv from UE5 Memreport
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright: Jonas Reich 2021 | |
# Extracts the texture report table from UE5 .memreport files and stores them as separate csv files. | |
# Uses comma delimiters and opens the extracted file with its default application | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true,ValueFromPipeline = $true)] | |
[String] | |
$SourceFile | |
) | |
$ErrorActionPreference = "Stop" | |
if(-not $SourceFile.EndsWith(".memreport")) { | |
Write-Error "'$SourceFile' does not end with memreport extension. Please only pass UE4 memreport files!" | |
} | |
$SourceFileName = [io.path]::GetFileNameWithoutExtension($SourceFile) | |
$SourceFileDir = Split-Path $SourceFile -Parent | |
$TargetFile = "$SourceFileDir\$SourceFileName.csv" | |
if(Test-Path $TargetFile){ | |
Clear-Content -Path $TargetFile | |
} else { | |
New-Item $TargetFile | |
} | |
$FileContent = Get-Content $SourceFile -Raw | |
if($FileContent -match "(?sm)Listing NONVT textures\.(?<TextureReport>.*?)Total size: ") { | |
$TextureReport = $Matches.TextureReport | |
} else { | |
Write-Error "Failed to extract texture report from memreport" | |
} | |
# Format: | |
# Cooked/OnDisk: Width x Height (Size in KB, Authored Bias), Current/InMem: Width x Height (Size in KB), Format, LODGroup, Name, Streaming, UnknownRef, VT, Usage Count, NumMips, Uncompressed | |
"disksize_x,disksize_y,disksize_kb,bias,memsize_x,memsize_y,memsize_kb,Format,Group,Path,Streaming,UnknownRef,VT,UsageCount,Mips,Uncompressed" | Add-Content $TargetFile | |
$AllLines = $TextureReport -Split [Environment]::NewLine | |
$NumLines = $AllLines.Length | |
$LineNr = 0 | |
foreach ($Line in $AllLines) { | |
if($Line.Length -eq 0) { | |
continue | |
} | |
if($Line -match "(?<disksize_x>\d+)x(?<disksize_y>\d+) \((?<disksize_kb>\d+) KB, (?<bias>.?)\), (?<memsize_x>\d+)x(?<memsize_y>\d+) \((?<memsize_kb>\d+) KB\), (?<texformat>\w+), TEXTUREGROUP_(?<texgroup>\w+), (?<path>.+?), (?<bstreaming>\w+), (?<unknownref>\w+), (?<vt>\w+), (?<usagecount>\d+), (?<nummips>\d+), (?<uncompressed>\w+)") | |
{ | |
$disksize_x = $Matches.disksize_x | |
$disksize_y = $Matches.disksize_y | |
$disksize_kb = $Matches.disksize_kb | |
$bias = $Matches.bias | |
$memsize_x = $Matches.memsize_x | |
$memsize_y = $Matches.memsize_y | |
$memsize_kb = $Matches.memsize_kb | |
$texformat = $Matches.texformat | |
$texgroup = $Matches.texgroup | |
$path = $Matches.path | |
$bstreaming = $Matches.bstreaming | |
$unknownref = $Matches.unknownref | |
$vt = $Matches.vt | |
$usagecount = $Matches.usagecount | |
$nummips = $Matches.nummips | |
$uncompressed = $Matches.uncompressed | |
$NewLine = "$disksize_x,$disksize_y,$disksize_kb,$bias,$memsize_x,$memsize_y,$memsize_kb,$texformat,$texgroup,$path,$bstreaming,$unknownref,$vt,$usagecount,$nummips,$uncompressed" | |
$NewLine | Add-Content $TargetFile | |
} | |
elseif($LineNr -ne 0) | |
{ | |
Write-Error "Could not parse line '$Line'" | |
} | |
$LineNr++ | |
$ProgressPercent = [math]::floor([decimal](($LineNr / $NumLines) * 100)) | |
Write-Progress -Activity "Extracting texture report to csv" -Status "$ProgressPercent% Complete ($LineNr / $NumLines):" -PercentComplete $ProgressPercent | |
} | |
"Saved texture report to $TargetFile" | |
Invoke-Item $TargetFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Copyright: Jonas Reich 2021 | |
:: Utility script for easier execution of main Powershell script that allows extracting a memreport by drag & drop. | |
:: Also simplifies executing the ps1 script on systems that do not regularly allow ps1 script execution. | |
@echo off | |
if "%1"=="" goto error | |
goto noerror | |
:error | |
echo error: must specify source file (drag and drop a memreport file onto the cmd script or specify it as first parameter) | |
pause | |
exit 1 | |
:noerror | |
@echo on | |
powershell -ep RemoteSigned "%~dp0ExtractTextureReportFromMemreport.ps1" "%1" | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment