|
4 | 4 | <Type> |
5 | 5 | <Name>OBS.GetSceneItemList.Response</Name> |
6 | 6 | <Members> |
| 7 | + <ScriptMethod> |
| 8 | + <Name>Animate</Name> |
| 9 | + <Script> |
| 10 | + param( |
| 11 | +# The set of values that you're animating from. |
| 12 | +# Aka, the starting positions of the animation. |
| 13 | +# Can be either a dictionary or an object. |
| 14 | +# These take the values found in Set-OBSSceneItemTransform |
| 15 | +$From, |
| 16 | + |
| 17 | +# The set of values that you're animating to. |
| 18 | +# Aka, the ending positions of the animation. |
| 19 | +# Can be either a dictionary or an object. |
| 20 | +# These take the values found in Set-OBSSceneItemTransform |
| 21 | +$To, |
| 22 | + |
| 23 | +# The timespan the animation will take. |
| 24 | +[TimeSpan] |
| 25 | +$TimeSpan = [timespan]::fromSeconds(1), |
| 26 | + |
| 27 | +# The number of steps in the animation. |
| 28 | +[int] |
| 29 | +$StepCount |
| 30 | +) |
| 31 | + |
| 32 | +# If there's no step count |
| 33 | +if (-not $StepCount) { |
| 34 | + $StepCount = [Math]::Ceiling($TimeSpan.TotalMilliseconds / ([timespan]::fromSeconds(1/30).TotalMilliseconds)) * 2 |
| 35 | +} |
| 36 | + |
| 37 | +# Convert -From to a dictionary |
| 38 | +$realFrom = |
| 39 | + if ($from -is [Collections.IDictionary]) { |
| 40 | + [Ordered]@{} + $from |
| 41 | + } else { |
| 42 | + $newFrom = [Ordered]@{} |
| 43 | + foreach ($property in $from.psobject.properties) { |
| 44 | + $newFrom[$property.Name] = $property.Value |
| 45 | + } |
| 46 | + $newFrom |
| 47 | + } |
| 48 | + |
| 49 | +# Convert -To to a dictionary |
| 50 | +$realTo = |
| 51 | + if ($to -is [Collections.IDictionary]) { |
| 52 | + [Ordered]@{} + $to |
| 53 | + } else { |
| 54 | + $newTo = [Ordered]@{} |
| 55 | + foreach ($property in $to.psobject.properties) { |
| 56 | + $newTo[$property.Name] = $property.Value |
| 57 | + } |
| 58 | + $newTo |
| 59 | + } |
| 60 | + |
| 61 | +# Compare the two sets of keys to determine the base data object |
| 62 | +$BaseObject = [Ordered]@{} |
| 63 | +foreach ($key in $realTo.Keys) { |
| 64 | + if (-not $BaseObject[$key]) { |
| 65 | + $BaseObject[$key] = |
| 66 | + if ($realFrom[$key]) { |
| 67 | + $realFrom[$key] |
| 68 | + } else { |
| 69 | + $realTo[$key] |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +# Check for properties only defined in -From |
| 75 | +foreach ($key in $realFrom.Keys) { |
| 76 | + if (-not $BaseObject[$key]) { |
| 77 | + $BaseObject[$key] = $realFrom[$key] |
| 78 | + $realTo[$key] = $realFrom[$key] |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +# Determine the animation change per step. |
| 83 | +$eachStepValue = [Ordered]@{} |
| 84 | +foreach ($key in $baseObject.Keys) { |
| 85 | + $distance = try { $realTo[$key] - $baseObject[$key] } catch { $null } |
| 86 | + if ($null -ne $distance) { |
| 87 | + $eachStepValue[$key] = [float]$distance / $StepCount |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | +# Get all of the steps |
| 93 | +$allSteps = |
| 94 | + foreach ($stepNumber in 0..($stepCount - 1)) { |
| 95 | + $stepObject = [Ordered]@{} |
| 96 | + foreach ($key in $BaseObject.Keys) { |
| 97 | + $stepObject[$key] = $BaseObject[$key] + ($eachStepValue[$key] * $stepNumber) |
| 98 | + } |
| 99 | + $this | Set-OBSSceneItemTransform -SceneItemTransform $stepObject -PassThru |
| 100 | + } |
| 101 | + |
| 102 | +# Determine the time to wait per step. |
| 103 | +$stepTime = [TimeSpan]::FromMilliseconds($TimeSpan.TotalMilliseconds / $StepCount) |
| 104 | + |
| 105 | +# Send all of the steps to OBS. |
| 106 | +$allSteps | Send-OBS -StepTime $stepTime |
| 107 | + </Script> |
| 108 | + </ScriptMethod> |
7 | 109 | <ScriptMethod> |
8 | 110 | <Name>Blend</Name> |
9 | 111 | <Script> |
|
0 commit comments