| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory = $true)] | |
| [ValidatePattern('^[a-z0-9][a-z0-9-]*$')] | |
| [string]$RepositoryId, | |
| [Parameter(Mandatory = $true)] | |
| [string]$InputFolder, | |
| [ValidateSet('Preview', 'Normal', 'High')] | |
| [string]$Detail = 'Normal', | |
| [switch]$ValidateOnly | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $realityCapture = 'C:\Program Files\Capturing Reality\RealityCapture\RealityCapture.exe' | |
| $scriptRoot = Split-Path -Parent $PSScriptRoot | |
| $outputRoot = Join-Path $scriptRoot 'Output' | |
| $repositoryOutput = Join-Path $outputRoot $RepositoryId | |
| $projectFile = Join-Path $repositoryOutput ($RepositoryId + '.rcproj') | |
| $modelFile = Join-Path $repositoryOutput ($RepositoryId + '.fbx') | |
| if (-not (Test-Path -LiteralPath $realityCapture -PathType Leaf)) { | |
| throw "RealityCapture 1.5 executable not found at $realityCapture" | |
| } | |
| if (-not (Test-Path -LiteralPath $InputFolder -PathType Container)) { | |
| throw "Capture folder not found: $InputFolder" | |
| } | |
| $imageExtensions = @('.jpg', '.jpeg', '.png', '.tif', '.tiff', '.webp') | |
| $images = @(Get-ChildItem -LiteralPath $InputFolder -File -Recurse | Where-Object { | |
| $imageExtensions -contains $_.Extension.ToLowerInvariant() | |
| }) | |
| if ($images.Count -lt 3) { | |
| throw "RealityCapture needs at least 3 overlapping image files; found $($images.Count) in $InputFolder" | |
| } | |
| New-Item -ItemType Directory -Path $repositoryOutput -Force | Out-Null | |
| if ($ValidateOnly) { | |
| Write-Output "RealityCapture input PASS: $($images.Count) image files for $RepositoryId" | |
| exit 0 | |
| } | |
| $modelCommand = switch ($Detail) { | |
| 'Preview' { '-calculatePreviewModel' } | |
| 'High' { '-calculateHighModel' } | |
| default { '-calculateNormalModel' } | |
| } | |
| $arguments = @( | |
| '-newScene', | |
| '-addFolder', $InputFolder, | |
| '-align', | |
| '-selectMaximalComponent', | |
| '-setReconstructionRegionAuto', | |
| $modelCommand, | |
| '-calculateTexture', | |
| '-exportSelectedModel', $modelFile, | |
| '-save', $projectFile, | |
| '-quit' | |
| ) | |
| Write-Output "Starting RealityCapture 1.5 reconstruction for $RepositoryId with $($images.Count) images..." | |
| & $realityCapture @arguments | |
| if ($LASTEXITCODE -ne 0) { | |
| throw "RealityCapture exited with code $LASTEXITCODE" | |
| } | |
| if (-not (Test-Path -LiteralPath $modelFile -PathType Leaf)) { | |
| throw "RealityCapture completed without producing $modelFile" | |
| } | |
| Write-Output "Reality scene ready: $modelFile" | |