Skip to content

Commit

Permalink
Merge pull request #60 from StartAutomating/obs-animation
Browse files Browse the repository at this point in the history
obs-powershell 0.1.5
  • Loading branch information
StartAutomating authored Jan 7, 2023
2 parents b383b55 + 48eab57 commit 3f317b3
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## obs-powershell 0.1.5:

* Adding OBS.SceneItem .Animate (Fixes #59)


---


## obs-powershell 0.1.4:

* Adding Add-OBSColorSource (Fixes #51)
Expand Down
97 changes: 97 additions & 0 deletions Types/OBS.GetSceneItemList.Response/Animate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
param(
# The set of values that you're animating from.
# Aka, the starting positions of the animation.
# Can be either a dictionary or an object.
# These take the values found in Set-OBSSceneItemTransform
$From,

# The set of values that you're animating to.
# Aka, the ending positions of the animation.
# Can be either a dictionary or an object.
# These take the values found in Set-OBSSceneItemTransform
$To,

# The timespan the animation will take.
[TimeSpan]
$TimeSpan = [timespan]::fromSeconds(1),

# The number of steps in the animation.
[int]
$StepCount
)

# If there's no step count
if (-not $StepCount) {
$StepCount = [Math]::Ceiling($TimeSpan.TotalMilliseconds / ([timespan]::fromSeconds(1/30).TotalMilliseconds)) * 2
}

# Convert -From to a dictionary
$realFrom =
if ($from -is [Collections.IDictionary]) {
[Ordered]@{} + $from
} else {
$newFrom = [Ordered]@{}
foreach ($property in $from.psobject.properties) {
$newFrom[$property.Name] = $property.Value
}
$newFrom
}

# Convert -To to a dictionary
$realTo =
if ($to -is [Collections.IDictionary]) {
[Ordered]@{} + $to
} else {
$newTo = [Ordered]@{}
foreach ($property in $to.psobject.properties) {
$newTo[$property.Name] = $property.Value
}
$newTo
}

# Compare the two sets of keys to determine the base data object
$BaseObject = [Ordered]@{}
foreach ($key in $realTo.Keys) {
if (-not $BaseObject[$key]) {
$BaseObject[$key] =
if ($realFrom[$key]) {
$realFrom[$key]
} else {
$realTo[$key]
}
}
}

# Check for properties only defined in -From
foreach ($key in $realFrom.Keys) {
if (-not $BaseObject[$key]) {
$BaseObject[$key] = $realFrom[$key]
$realTo[$key] = $realFrom[$key]
}
}

# Determine the animation change per step.
$eachStepValue = [Ordered]@{}
foreach ($key in $baseObject.Keys) {
$distance = try { $realTo[$key] - $baseObject[$key] } catch { $null }
if ($null -ne $distance) {
$eachStepValue[$key] = [float]$distance / $StepCount
}
}


# Get all of the steps
$allSteps =
foreach ($stepNumber in 0..($stepCount - 1)) {
$stepObject = [Ordered]@{}
foreach ($key in $BaseObject.Keys) {
$stepObject[$key] = $BaseObject[$key] + ($eachStepValue[$key] * $stepNumber)
}
$this | Set-OBSSceneItemTransform -SceneItemTransform $stepObject -PassThru
}

# Determine the time to wait per step.
$stepTime = [TimeSpan]::FromMilliseconds($TimeSpan.TotalMilliseconds / $StepCount)

# Send all of the steps to OBS.
$allSteps | Send-OBS -StepTime $stepTime
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## obs-powershell 0.1.5:

* Adding OBS.SceneItem .Animate (Fixes #59)


---


## obs-powershell 0.1.4:

* Adding Add-OBSColorSource (Fixes #51)
Expand Down
9 changes: 8 additions & 1 deletion obs-powershell.ps.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.1.4'
ModuleVersion = '0.1.5'
RootModule = 'obs-powershell.psm1'
Description = 'Script OBS with PowerShell'
Guid = '1417123e-a932-439f-9b68-a7313cf1e170'
Expand All @@ -16,6 +16,13 @@
ProjectURI = 'https://github.com/StartAutomating/obs-powershell'
LicenseURI = 'https://github.com/StartAutomating/obs-powershell/blob/main/LICENSE'
ReleaseNotes = @'
## obs-powershell 0.1.5:
* Adding OBS.SceneItem .Animate (Fixes #59)
---
## obs-powershell 0.1.4:
* Adding Add-OBSColorSource (Fixes #51)
Expand Down
9 changes: 8 additions & 1 deletion obs-powershell.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{
ModuleVersion = '0.1.4'
ModuleVersion = '0.1.5'
RootModule = 'obs-powershell.psm1'
Description = 'Script OBS with PowerShell'
Guid = '1417123e-a932-439f-9b68-a7313cf1e170'
Expand All @@ -16,6 +16,13 @@
ProjectURI = 'https://github.com/StartAutomating/obs-powershell'
LicenseURI = 'https://github.com/StartAutomating/obs-powershell/blob/main/LICENSE'
ReleaseNotes = @'
## obs-powershell 0.1.5:
* Adding OBS.SceneItem .Animate (Fixes #59)
---
## obs-powershell 0.1.4:
* Adding Add-OBSColorSource (Fixes #51)
Expand Down
102 changes: 102 additions & 0 deletions obs-powershell.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,108 @@
<Type>
<Name>OBS.GetSceneItemList.Response</Name>
<Members>
<ScriptMethod>
<Name>Animate</Name>
<Script>
param(
# The set of values that you're animating from.
# Aka, the starting positions of the animation.
# Can be either a dictionary or an object.
# These take the values found in Set-OBSSceneItemTransform
$From,

# The set of values that you're animating to.
# Aka, the ending positions of the animation.
# Can be either a dictionary or an object.
# These take the values found in Set-OBSSceneItemTransform
$To,

# The timespan the animation will take.
[TimeSpan]
$TimeSpan = [timespan]::fromSeconds(1),

# The number of steps in the animation.
[int]
$StepCount
)

# If there's no step count
if (-not $StepCount) {
$StepCount = [Math]::Ceiling($TimeSpan.TotalMilliseconds / ([timespan]::fromSeconds(1/30).TotalMilliseconds)) * 2
}

# Convert -From to a dictionary
$realFrom =
if ($from -is [Collections.IDictionary]) {
[Ordered]@{} + $from
} else {
$newFrom = [Ordered]@{}
foreach ($property in $from.psobject.properties) {
$newFrom[$property.Name] = $property.Value
}
$newFrom
}

# Convert -To to a dictionary
$realTo =
if ($to -is [Collections.IDictionary]) {
[Ordered]@{} + $to
} else {
$newTo = [Ordered]@{}
foreach ($property in $to.psobject.properties) {
$newTo[$property.Name] = $property.Value
}
$newTo
}

# Compare the two sets of keys to determine the base data object
$BaseObject = [Ordered]@{}
foreach ($key in $realTo.Keys) {
if (-not $BaseObject[$key]) {
$BaseObject[$key] =
if ($realFrom[$key]) {
$realFrom[$key]
} else {
$realTo[$key]
}
}
}

# Check for properties only defined in -From
foreach ($key in $realFrom.Keys) {
if (-not $BaseObject[$key]) {
$BaseObject[$key] = $realFrom[$key]
$realTo[$key] = $realFrom[$key]
}
}

# Determine the animation change per step.
$eachStepValue = [Ordered]@{}
foreach ($key in $baseObject.Keys) {
$distance = try { $realTo[$key] - $baseObject[$key] } catch { $null }
if ($null -ne $distance) {
$eachStepValue[$key] = [float]$distance / $StepCount
}
}


# Get all of the steps
$allSteps =
foreach ($stepNumber in 0..($stepCount - 1)) {
$stepObject = [Ordered]@{}
foreach ($key in $BaseObject.Keys) {
$stepObject[$key] = $BaseObject[$key] + ($eachStepValue[$key] * $stepNumber)
}
$this | Set-OBSSceneItemTransform -SceneItemTransform $stepObject -PassThru
}

# Determine the time to wait per step.
$stepTime = [TimeSpan]::FromMilliseconds($TimeSpan.TotalMilliseconds / $StepCount)

# Send all of the steps to OBS.
$allSteps | Send-OBS -StepTime $stepTime
</Script>
</ScriptMethod>
<ScriptMethod>
<Name>Blend</Name>
<Script>
Expand Down

0 comments on commit 3f317b3

Please sign in to comment.