144 lines
4.4 KiB
PowerShell
144 lines
4.4 KiB
PowerShell
# default map if not found map in json
|
|
$defaultmap = "/Game/RA_Project/KL_EstivaPark/Maps/KLEP_WP/L_KLEP_WP"
|
|
|
|
|
|
$editor = "C:\epic\UE_5.6\Engine\Binaries\Win64\UnrealEditor-Cmd.exe"
|
|
$project = "C:\project\EstivaParks\KL_EstivaPark.uproject"
|
|
#$config = "/Render360/ConfigPreset/360_PT_low"
|
|
$config = "/Render360/ConfigPreset/360_PT"
|
|
|
|
# 10 minutes * 60
|
|
$WarningTime = 10*60
|
|
# 15 minutes * 60
|
|
$ErrorTime = 20*60
|
|
|
|
|
|
|
|
$projectname = "Estiva"
|
|
$Uri = "http://192.168.10.33/virtual-360/api/v1"
|
|
$Headers = @{
|
|
'Content-Type' = 'application/json';
|
|
"Authorization" = "Bearer $BearerToken"
|
|
}
|
|
function Login {
|
|
$Body = @{
|
|
username = "render"
|
|
password = "Nami2009"
|
|
grant_type = "password" # Common for direct credential flow
|
|
} | ConvertTo-Json
|
|
|
|
$AuthResponse = Invoke-RestMethod -Uri "$Uri/login" -Method Post -Body $Body -ContentType 'application/json'
|
|
$Headers.Authorization = "Bearer $($AuthResponse.data.token)"
|
|
}
|
|
|
|
function Noti {
|
|
param (
|
|
$title,
|
|
$txt
|
|
)
|
|
$Body = @{
|
|
title = $title
|
|
body = $txt
|
|
} | ConvertTo-Json
|
|
$Response = Invoke-RestMethod -Uri "$Uri/noti" -Method Post -Body $Body -Headers $Headers -ContentType 'application/json'
|
|
Write-Host $Response.data
|
|
}
|
|
|
|
|
|
function Start-Render {
|
|
param (
|
|
$ProcessName,
|
|
$ArgumentsArguments,
|
|
$WarningTimeoutSec,
|
|
$KillTimeoutSec,
|
|
$ProcessLabel
|
|
)
|
|
|
|
# Start the process
|
|
$proc = Start-Process -FilePath $ProcessName -ArgumentList $Arguments -PassThru
|
|
|
|
Write-Host "Process started with ID: $($proc.Id). Monitoring..." -ForegroundColor Cyan
|
|
|
|
# Monitor loop
|
|
$StartTime = Get-Date
|
|
$WarningSent = $false
|
|
|
|
while (-not $proc.HasExited) {
|
|
$Elapsed = (Get-Date) - $StartTime
|
|
|
|
# 10 Minute Warning
|
|
if ($Elapsed.TotalSeconds -ge $WarningTimeoutSec -and -not $WarningSent) {
|
|
Write-Warning "$ProcessLabel run over warning time"
|
|
Noti $projectname "$ProcessLabel run over warning time"
|
|
$WarningSent = $true
|
|
}
|
|
|
|
# 15 Minute Kill
|
|
if ($Elapsed.TotalSeconds -ge $KillTimeoutSec) {
|
|
Write-Host "$ProcessLabel exceeded Error time. Terminating..." -ForegroundColor Red
|
|
Noti $projectname "$ProcessLabel exceeded Error time. Terminating..."
|
|
Stop-Process -Id $proc.Id -Force
|
|
break
|
|
}
|
|
|
|
# Sleep briefly to save CPU cycles
|
|
Start-Sleep -Seconds 5
|
|
}
|
|
|
|
# Final Status
|
|
if ($proc.HasExited) {
|
|
Write-Host "Process exited with code: $($proc.ExitCode)" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Process was killed by script." -ForegroundColor Yellow
|
|
}
|
|
|
|
}
|
|
|
|
function Render(){
|
|
Login
|
|
Get-ChildItem ".\Saved\MovieRenders" -Filter *.json |
|
|
Foreach-Object {
|
|
$cam = $_.BaseName
|
|
$jsonData = Get-Content -Path ".\Saved\MovieRenders\$_" -Raw | ConvertFrom-Json
|
|
$map = $jsonData.map
|
|
if (!$map){
|
|
$map = $defaultmap
|
|
}
|
|
|
|
for ($j = 0; $j -lt 36; $j++) {
|
|
$img = ".\Saved\MovieRenders\$cam\$j.png"
|
|
if (Test-Path $img){
|
|
continue
|
|
}
|
|
$arguments = @($project,$map,"-game","-MoviePipelineConfig='$config'","-LevelSequence='/Render360/Sequence/$cam/$j'","-windowed","-resx=1280","-resy=720")
|
|
Start-Render $editor $arguments $WarningTime $ErrorTime "$cam ($j/36)"
|
|
# Invoke-Expression "$editor $project $map -game -MoviePipelineConfig='$config' -LevelSequence='/Render360/Sequence/$cam/$j' -windowed -resx=1280 -resy=720"
|
|
$tmp = ".\Saved\MovieRenders\$cam\tmp.png"
|
|
if (Test-Path $tmp){
|
|
Rename-Item ".\Saved\MovieRenders\$cam\tmp.png" "$j.png"
|
|
Noti $projectname "save $cam ($j/36)"
|
|
}else{
|
|
Noti $projectname "crash $cam ($j/36)"
|
|
}
|
|
|
|
|
|
}
|
|
# Set-Location ".\Saved"
|
|
# net use M: "\\192.168.10.200\xampp5.6\htdocs\test\360"
|
|
# $pold = Test-Path ".\pano\$cam\pano.mi"
|
|
# .\ptool
|
|
# $pnew = Test-Path ".\pano\$cam\pano.mi"
|
|
|
|
# if ($pnew -and !$pold){
|
|
# robocopy "pano\$cam" "M:\pano\$cam" /s
|
|
# #robocopy "pano\$cam" "M:\pano\$($cam)_final" /s
|
|
# Noti $projectname "render final $cam finish"
|
|
# }
|
|
|
|
# net use M: /delete
|
|
# Set-Location ".."
|
|
}
|
|
|
|
}
|
|
|
|
Render |