Skip to content

Commit 3f317b3

Browse files
Merge pull request #60 from StartAutomating/obs-animation
obs-powershell 0.1.5
2 parents b383b55 + 48eab57 commit 3f317b3

File tree

6 files changed

+231
-2
lines changed

6 files changed

+231
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## obs-powershell 0.1.5:
2+
3+
* Adding OBS.SceneItem .Animate (Fixes #59)
4+
5+
6+
---
7+
8+
19
## obs-powershell 0.1.4:
210

311
* Adding Add-OBSColorSource (Fixes #51)
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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

docs/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## obs-powershell 0.1.5:
2+
3+
* Adding OBS.SceneItem .Animate (Fixes #59)
4+
5+
6+
---
7+
8+
19
## obs-powershell 0.1.4:
210

311
* Adding Add-OBSColorSource (Fixes #51)

obs-powershell.ps.psd1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.1.4'
2+
ModuleVersion = '0.1.5'
33
RootModule = 'obs-powershell.psm1'
44
Description = 'Script OBS with PowerShell'
55
Guid = '1417123e-a932-439f-9b68-a7313cf1e170'
@@ -16,6 +16,13 @@
1616
ProjectURI = 'https://github.com/StartAutomating/obs-powershell'
1717
LicenseURI = 'https://github.com/StartAutomating/obs-powershell/blob/main/LICENSE'
1818
ReleaseNotes = @'
19+
## obs-powershell 0.1.5:
20+
21+
* Adding OBS.SceneItem .Animate (Fixes #59)
22+
23+
24+
---
25+
1926
## obs-powershell 0.1.4:
2027
2128
* Adding Add-OBSColorSource (Fixes #51)

obs-powershell.psd1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '0.1.4'
2+
ModuleVersion = '0.1.5'
33
RootModule = 'obs-powershell.psm1'
44
Description = 'Script OBS with PowerShell'
55
Guid = '1417123e-a932-439f-9b68-a7313cf1e170'
@@ -16,6 +16,13 @@
1616
ProjectURI = 'https://github.com/StartAutomating/obs-powershell'
1717
LicenseURI = 'https://github.com/StartAutomating/obs-powershell/blob/main/LICENSE'
1818
ReleaseNotes = @'
19+
## obs-powershell 0.1.5:
20+
21+
* Adding OBS.SceneItem .Animate (Fixes #59)
22+
23+
24+
---
25+
1926
## obs-powershell 0.1.4:
2027
2128
* Adding Add-OBSColorSource (Fixes #51)

obs-powershell.types.ps1xml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,108 @@
44
<Type>
55
<Name>OBS.GetSceneItemList.Response</Name>
66
<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>
7109
<ScriptMethod>
8110
<Name>Blend</Name>
9111
<Script>

0 commit comments

Comments
 (0)