Skip to content

Conversion methods between Unity vector types and System.Numerics.Vector

License

Notifications You must be signed in to change notification settings

KuraiAndras/NumericsConverter

Repository files navigation

NumericsConverter openupm

Conversion methods between Unity vectory types and System.Numerics.Vector as extension methods

Getting Started

The recommended way of installation is through OpenUPM.

openupm add com.kuraiandras.numericsconverter

Or you can add it with a git dependency:

// For latest always
"com.kuraiandras.numericsconverter": "https://github.com/KuraiAndras/NumericsConverter.git?path=/NumericsConverter/Assets/NumericsConverter"

// For specific version
"com.kuraiandras.numericsconverter": "https://github.com/KuraiAndras/NumericsConverter.git?path=/NumericsConverter/Assets/NumericsConverter#2.0.1"
using NumericsConverter; // use this namespace for the exentsion methods

Special thanks for TheZombieKiller from the unity forum for the help with removing unnecessary allocations.

Available conversions

From To
UnityEngine.Vector2 System.Numerics.Vector2
UnityEngine.Vector2 System.Numerics.Vector
System.Numerics.Vector2 UnityEngine.Vector2
UnityEngine.Vector3 System.Numerics.Vector3
UnityEngine.Vector3 System.Numerics.Vector
System.Numerics.Vector3 UnityEngine.Vector3
UnityEngine.Vector4 System.Numerics.Vector4
UnityEngine.Vector4 System.Numerics.Vector
System.Numerics.Vector4 UnityEngine.Vector4
UnityEngine.Vector2Int System.Numerics.Vecto
System.Numerics.Vector UnityEngine.Vector2Int
UnityEngine.Vector3Int System.Numerics.Vector
System.Numerics.Vector UnityEngine.Vector3Int
UnityEngine.Quaternion System.Numerics.Quaternion
System.Numerics.Quaternion UnityEngine.Quaternion
UnityEngine.Plane System.Numerics.Plane
System.Numerics.Plane UnityEngine.Plane
UnityEngine.Matrix4x4 System.Numerics.Matrix4x4
System.Numerics.Matrix4x4 UnityEngine.Matrix4x4

Allocation benchmarks

Doing 100000 conversions from UnityEngine.Vector4 to System.Numerics.Vector

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
AMD Ryzen 5 1600X, 1 CPU, 12 logical and 6 physical cores
  [Host]     : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT
  .NET 4.7.2 : .NET Framework 4.8 (4.8.4300.0), X64 RyuJIT

Job=.NET 4.7.2  Runtime=.NET 4.7.2  
Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
Alloc 2.276 ms 0.0012 ms 0.0011 ms 5839.8438 - - 5616878 B
NoAlloc 1.503 ms 0.0266 ms 0.0249 ms - - - -

About

Conversion methods between Unity vector types and System.Numerics.Vector

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages