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