param( [string]$WorkspaceRoot = (Split-Path -Parent $PSScriptRoot) ) Add-Type -AssemblyName System.Drawing $characterRoot = Join-Path $WorkspaceRoot 'assets\images\2d-game-characters\02-xinyin' $partsDirectory = Join-Path $characterRoot 'parts\front-right\v1' $partsManifestPath = Join-Path $partsDirectory 'parts-manifest.json' $correctionDirectory = Join-Path $characterRoot 'parts\front-right\rig-corrections-v1' $correctionManifestPath = Join-Path $correctionDirectory 'rig-corrections-manifest.json' $layoutPath = Join-Path $characterRoot 'assembled\front-right\assembly-layout-v4.json' $outputDirectory = Join-Path $characterRoot 'motion\front-right\v3' $previewPath = Join-Path $characterRoot 'previews\xinyin-front-right-motion-validation-v3.png' $motionManifestPath = Join-Path $outputDirectory 'motion-manifest.json' New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null $partsManifest = Get-Content -LiteralPath $partsManifestPath -Raw | ConvertFrom-Json $correctionManifest = Get-Content -LiteralPath $correctionManifestPath -Raw | ConvertFrom-Json $baseLayout = Get-Content -LiteralPath $layoutPath -Raw | ConvertFrom-Json $partByName = @{} foreach ($part in $partsManifest.parts) { $partByName[$part.name] = [pscustomobject]@{ FullPath=(Join-Path $partsDirectory $part.file) PivotX=[double]$part.pivot.outputPixels.x; PivotY=[double]$part.pivot.outputPixels.y } } foreach ($part in $correctionManifest.parts) { $partByName[$part.name] = [pscustomobject]@{ FullPath=(Join-Path $correctionDirectory $part.file) PivotX=[double]$part.rootPivot.outputPixels.x; PivotY=[double]$part.rootPivot.outputPixels.y } } $upperBody = @( 'torso-upper','neck','head-face','hair-front','ponytail-root','ponytail-middle','ponytail-tip', 'upper-arm-a','forearm-a','hand-fan-grip','upper-arm-b','forearm-b','hand-relaxed-b', 'shoulder-armor-a','shoulder-armor-b' ) $frames = @( [ordered]@{ Name='idle-inhale'; Label='IDLE · INHALE'; DurationMs=420 UpperBodyY=-3 Overrides=@{ 'torso-upper'=@{ Y=315; Scale=.94 } 'head-face'=@{ Y=191 } 'hair-front'=@{ Y=73 } 'ponytail-root'=@{ Y=59; Rotation=-1 } 'ponytail-middle'=@{ Y=91; Rotation=-13 } 'ponytail-tip'=@{ Y=254; Rotation=-7 } 'waist-guard'=@{ Y=296; Scale=.73 } 'front-drape'=@{ Y=303; Rotation=3 } 'coat-panel-01'=@{ Rotation=7 } 'coat-panel-08'=@{ Rotation=-7 } } Joints=@{ Shoulder=@(146,211); Elbow=@(130,304); Hand=@(89,211) } Note='胸腔上提;头、肩与持械手同步,后发轻微滞后。' }, [ordered]@{ Name='idle-neutral'; Label='IDLE · NEUTRAL'; DurationMs=260 UpperBodyY=0; Overrides=@{} Joints=@{ Shoulder=@(146,214); Elbow=@(130,307); Hand=@(89,214) } Note='装配 v2 中性基准。' }, [ordered]@{ Name='idle-exhale'; Label='IDLE · EXHALE'; DurationMs=420 UpperBodyY=3 Overrides=@{ 'torso-upper'=@{ Y=321; Scale=.90 } 'head-face'=@{ Y=197 } 'hair-front'=@{ Y=79 } 'ponytail-root'=@{ Y=65; Rotation=1 } 'ponytail-middle'=@{ Y=99; Rotation=-10 } 'ponytail-tip'=@{ Y=264; Rotation=-4 } 'waist-guard'=@{ Y=301; Scale=.71 } 'front-drape'=@{ Y=308; Rotation=1 } 'coat-panel-01'=@{ Rotation=5 } 'coat-panel-08'=@{ Rotation=-5 } } Joints=@{ Shoulder=@(146,217); Elbow=@(130,310); Hand=@(89,217) } Note='胸腔回落;发尾比头部多下沉 2~3 px。' }, [ordered]@{ Name='throw-ready'; Label='THROW · READY'; DurationMs=150 UpperBodyY=1 Overrides=@{ 'pelvis'=@{ Y=353 } 'torso-upper'=@{ Y=320; Rotation=1 } 'waist-guard'=@{ Y=301 } 'front-drape'=@{ Y=308 } 'thigh-a'=@{ Y=353; Rotation=9 } 'thigh-b'=@{ Y=353; Rotation=-7 } } Joints=@{ Shoulder=@(146,215); Elbow=@(130,308); Hand=@(89,215) } Note='髋部下沉 3 px,形成动作预备。' }, [ordered]@{ Name='throw-windup'; Label='THROW · WINDUP'; DurationMs=110 UpperBodyY=0 Overrides=@{ 'torso-upper'=@{ Rotation=3 } 'head-face'=@{ Rotation=1 } 'hair-front'=@{ Rotation=1 } 'ponytail-root'=@{ Rotation=2 } 'ponytail-middle'=@{ Rotation=-8 } 'ponytail-tip'=@{ Rotation=-1 } 'upper-arm-a'=@{ Rotation=8 } 'forearm-a'=@{ X=133; Y=305; Rotation=180 } 'hand-fan-grip'=@{ X=133; Y=202; Rotation=-15; Scale=.36 } 'shoulder-armor-a'=@{ Rotation=2 } 'front-drape'=@{ Rotation=-2 } 'coat-panel-01'=@{ Rotation=3 } 'coat-panel-08'=@{ Rotation=-9 } } Joints=@{ Shoulder=@(146,214); Elbow=@(133,305); Hand=@(133,202) } Note='前臂回收到面部外侧,武器不遮挡眼睛;马尾与衣摆保持惯性。' }, [ordered]@{ Name='throw-release'; Label='THROW · RELEASE'; DurationMs=90 UpperBodyY=0 Overrides=@{ 'torso-upper'=@{ Rotation=-5 } 'head-face'=@{ Rotation=-2 } 'hair-front'=@{ Rotation=-2 } 'ponytail-root'=@{ Rotation=4; X=218 } 'ponytail-middle'=@{ Rotation=-2; X=302 } 'ponytail-tip'=@{ Rotation=8; X=342 } 'upper-arm-a'=@{ Rotation=65 } 'forearm-a'=@{ X=62; Y=252; Rotation=95; Scale=.30 } 'shoulder-armor-a'=@{ Rotation=8 } 'front-drape'=@{ Rotation=7; X=207 } 'coat-panel-01'=@{ Rotation=11 } 'coat-panel-02'=@{ Rotation=7 } 'coat-panel-07'=@{ Rotation=1 } 'coat-panel-08'=@{ Rotation=-2 } } Hidden=@('hand-fan-grip') Extras=@( @{ Name='hand-throw-open'; X=-12; Y=244; Rotation=88; Scale=.30 }, @{ Name='weapon-fan-open'; X=-38; Y=220; Rotation=80; Scale=.52 } ) Joints=@{ Shoulder=@(146,214); Elbow=@(62,252); Hand=@(-12,244) } Note='肩肘形成清楚的左向伸展;武器进入脱手位置。' }, [ordered]@{ Name='throw-recover'; Label='THROW · RECOVER'; DurationMs=180 UpperBodyY=1 Overrides=@{ 'torso-upper'=@{ Rotation=1; Y=319 } 'head-face'=@{ Rotation=1; Y=195 } 'hair-front'=@{ Rotation=1; Y=77 } 'ponytail-root'=@{ Rotation=-3; Y=64 } 'ponytail-middle'=@{ Rotation=-16; Y=97 } 'ponytail-tip'=@{ Rotation=-12; Y=262 } 'upper-arm-a'=@{ Rotation=26 } 'forearm-a'=@{ X=106; Y=290; Rotation=170; Scale=.34 } 'hand-fan-grip'=@{ X=88; Y=195; Rotation=-10; Scale=.36 } 'shoulder-armor-a'=@{ Rotation=10 } 'front-drape'=@{ Rotation=-3 } 'coat-panel-01'=@{ Rotation=2 } 'coat-panel-08'=@{ Rotation=-10 } } Joints=@{ Shoulder=@(146,215); Elbow=@(106,290); Hand=@(88,195) } Note='手臂回收,软性部件反向摆动并准备回到中性。' } ) function Copy-Transform { param($Item) return [ordered]@{ Name=[string]$Item.part X=[double]$Item.targetPivot.x Y=[double]$Item.targetPivot.y Rotation=[double]$Item.rotationDegrees Scale=[double]$Item.scale Visible=$true } } function Resolve-FrameLayout { param($Frame) $result = @() $hiddenParts = @($Frame.Hidden) foreach ($item in $baseLayout.items) { $transform = Copy-Transform $item if ($transform.Name -in $upperBody) { $transform.Y += [double]$Frame.UpperBodyY } if ($Frame.Overrides.ContainsKey($transform.Name)) { $override = $Frame.Overrides[$transform.Name] foreach ($key in $override.Keys) { $transform[$key] = $override[$key] } } if ($transform.Name -in $hiddenParts) { $transform.Visible = $false } $transform.X += 50 $result += $transform } foreach ($extra in @($Frame.Extras)) { if ($null -eq $extra) { continue } $result += [ordered]@{ Name=[string]$extra.Name; X=[double]$extra.X+50; Y=[double]$extra.Y Rotation=[double]$extra.Rotation; Scale=[double]$extra.Scale; Visible=$true } } return $result } function Draw-Part { param( [Drawing.Graphics]$Graphics, [Drawing.Image]$Image, [double]$PivotX, [double]$PivotY, [double]$TargetX, [double]$TargetY, [double]$Rotation, [double]$Scale ) $state = $Graphics.Save() $Graphics.TranslateTransform([single]$TargetX, [single]$TargetY) $Graphics.RotateTransform([single]$Rotation) $Graphics.ScaleTransform([single]$Scale, [single]$Scale) $Graphics.DrawImageUnscaled($Image, [int][Math]::Round(-$PivotX), [int][Math]::Round(-$PivotY)) $Graphics.Restore($state) } $images = @{} $renderedFrames = @() $manifestFrames = @() try { foreach ($frame in $frames) { $resolved = Resolve-FrameLayout $frame $canvas = [Drawing.Bitmap]::new(600, 760, [Drawing.Imaging.PixelFormat]::Format32bppArgb) $graphics = [Drawing.Graphics]::FromImage($canvas) $graphics.SmoothingMode = [Drawing.Drawing2D.SmoothingMode]::AntiAlias $graphics.InterpolationMode = [Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic $graphics.PixelOffsetMode = [Drawing.Drawing2D.PixelOffsetMode]::HighQuality $graphics.Clear([Drawing.Color]::Transparent) foreach ($transform in $resolved) { if (-not $transform.Visible) { continue } $part = $partByName[$transform.Name] if (-not $images.ContainsKey($transform.Name)) { $images[$transform.Name] = [Drawing.Bitmap]::new($part.FullPath) } Draw-Part -Graphics $graphics -Image $images[$transform.Name] ` -PivotX $part.PivotX -PivotY $part.PivotY ` -TargetX $transform.X -TargetY $transform.Y -Rotation $transform.Rotation -Scale $transform.Scale } $fileName = "$($frame.Name).png" $filePath = Join-Path $outputDirectory $fileName $canvas.Save($filePath, [Drawing.Imaging.ImageFormat]::Png) $graphics.Dispose() $renderedFrames += [ordered]@{ Definition=$frame; Image=$canvas; Layout=$resolved; File=$fileName } $manifestFrames += [ordered]@{ name=$frame.Name; label=$frame.Label; file=$fileName; durationMs=$frame.DurationMs note=$frame.Note; joints=$frame.Joints; transforms=$resolved } } [ordered]@{ characterId='02-xinyin' direction='front-right' version=3 status='art-motion-validation' canvas=[ordered]@{ width=600; height=760; origin='top-left'; units='pixels'; assemblyOffsetX=50 } baseLayout='assets/images/2d-game-characters/02-xinyin/assembled/front-right/assembly-layout-v4.json' sequence=@('idle-inhale','idle-neutral','idle-exhale','idle-neutral','throw-ready','throw-windup','throw-release','throw-recover','idle-neutral') loopNotes=[ordered]@{ idle='inhale → neutral → exhale → neutral'; throw='ready → windup → release → recover' } frames=$manifestFrames } | ConvertTo-Json -Depth 9 | Set-Content -LiteralPath $motionManifestPath -Encoding utf8 $board = [Drawing.Bitmap]::new(2100, 1390, [Drawing.Imaging.PixelFormat]::Format32bppArgb) $g = [Drawing.Graphics]::FromImage($board) $g.SmoothingMode = [Drawing.Drawing2D.SmoothingMode]::AntiAlias $g.InterpolationMode = [Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic $g.PixelOffsetMode = [Drawing.Drawing2D.PixelOffsetMode]::HighQuality $g.Clear([Drawing.Color]::FromArgb(255, 16, 20, 29)) $titleBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(255, 241, 245, 252)) $mutedBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(255, 151, 171, 201)) $panelBrush = [Drawing.SolidBrush]::new([Drawing.Color]::FromArgb(255, 24, 30, 42)) $panelPen = [Drawing.Pen]::new([Drawing.Color]::FromArgb(255, 65, 82, 112), 2) $bonePen = [Drawing.Pen]::new([Drawing.Color]::FromArgb(230, 71, 210, 255), 4) $jointPen = [Drawing.Pen]::new([Drawing.Color]::FromArgb(255, 255, 86, 116), 3) $fontTitle = [Drawing.Font]::new('Segoe UI Semibold', 28) $fontLabel = [Drawing.Font]::new('Segoe UI Semibold', 16) $fontText = [Drawing.Font]::new('Segoe UI', 11) $g.DrawString('XIN YIN — FRONT-RIGHT MOTION VALIDATION V3', $fontTitle, $titleBrush, 48, 28) $g.DrawString('idle breathing + throw joint-range test | cyan: arm chain | red: pivots', $fontText, $mutedBrush, 51, 73) $cellWidth=490; $cellHeight=590; $startX=45; $startY=112; $gapX=20; $gapY=28; $scale=.62 for ($i=0; $i -lt $renderedFrames.Count; $i++) { $row = [Math]::Floor($i / 4); $col = $i % 4 $x = $startX + $col * ($cellWidth + $gapX) $y = $startY + $row * ($cellHeight + $gapY) $g.FillRectangle($panelBrush, $x, $y, $cellWidth, $cellHeight) $g.DrawRectangle($panelPen, $x, $y, $cellWidth, $cellHeight) $g.DrawString($renderedFrames[$i].Definition.Label, $fontLabel, $titleBrush, $x+18, $y+14) $g.DrawString("$($renderedFrames[$i].Definition.DurationMs) ms", $fontText, $mutedBrush, $x+18, $y+43) $drawX = $x + [int](($cellWidth - 600*$scale)/2) $drawY = $y + 65 $g.DrawImage($renderedFrames[$i].Image, $drawX, $drawY, [int](600*$scale), [int](760*$scale)) $joints = $renderedFrames[$i].Definition.Joints $points = @($joints.Shoulder,$joints.Elbow,$joints.Hand) for ($p=0; $p -lt 2; $p++) { $g.DrawLine($bonePen, $drawX + [single](($points[$p][0]+50)*$scale), $drawY + [single]($points[$p][1]*$scale), $drawX + [single](($points[$p+1][0]+50)*$scale), $drawY + [single]($points[$p+1][1]*$scale)) } foreach ($point in $points) { $px=$drawX+[single](($point[0]+50)*$scale); $py=$drawY+[single]($point[1]*$scale) $g.DrawEllipse($jointPen,$px-5,$py-5,10,10) } $g.DrawString($renderedFrames[$i].Definition.Note, $fontText, $mutedBrush, [Drawing.RectangleF]::new($x+16,$y+542,$cellWidth-32,40)) } $g.DrawString('Validation target: silhouette stability, shoulder/elbow overlap, hair and coat secondary motion. No VFX or engine interpolation.', $fontText, $mutedBrush, 48, 1354) $board.Save($previewPath, [Drawing.Imaging.ImageFormat]::Png) $fontText.Dispose(); $fontLabel.Dispose(); $fontTitle.Dispose() $jointPen.Dispose(); $bonePen.Dispose(); $panelPen.Dispose() $panelBrush.Dispose(); $mutedBrush.Dispose(); $titleBrush.Dispose() $g.Dispose(); $board.Dispose() } finally { foreach ($frame in $renderedFrames) { if ($null -ne $frame.Image) { $frame.Image.Dispose() } } foreach ($image in $images.Values) { $image.Dispose() } } Write-Output "Rendered $($frames.Count) motion keyframes." Write-Output $outputDirectory Write-Output $motionManifestPath Write-Output $previewPath