-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-Vector3.ps1
More file actions
57 lines (53 loc) · 1.57 KB
/
Get-Vector3.ps1
File metadata and controls
57 lines (53 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function Get-Vector3 {
<#
.SYNOPSIS
Gets a Vector3
.DESCRIPTION
Gets any input and arguments as a Vector3
.LINK
https://learn.microsoft.com/en-us/dotnet/api/system.numerics.vector3?wt.mc_id=MVP_321542
.EXAMPLE
# Create a vector out of two numbers
Vector3 1 2 3
.EXAMPLE
(Vector3 1 2 3 ) + (Vector3 3 2 1)
.EXAMPLE
(Vector3 1 2 3 ) - (Vector3 3 2 1)
.EXAMPLE
# Create a thousand vectors
$vectors = Vector3 1..3kb
.EXAMPLE
# Create a thousand vectors in random order, using the pipeline
$vectors = 1..3kb | Get-Random -Count 3kb | Vector3
.EXAMPLE
# Create a vector from a string
$vector = Vector3 "hi"
.NOTES
This script is self contained so that it can be easily dropped into any project
#>
[Alias('Vector3','V3')]
param()
# Collect all of our input and arguments
$allIn = @($input) + @(
foreach ($arg in $args) {
$arg
}
)
# and expand them
$expandAllIn = @($allIn | Vector)
# Go over our arguments three at a time
For ($n = 0; $n -lt $expandAllIn.Length; $n+=3) {
$argSet = $expandAllIn[$n..($n+2)] -as [float[]]
switch ($argSet.Length) {
1 {
[Numerics.Vector3]::new($argSet[0])
}
2 {
[Numerics.Vector3]::new([Numerics.Vector2]::new($argSet[0],$argSet[1]), 1)
}
3 {
[Numerics.Vector3]::new($argSet)
}
}
}
}