Skip to content

Add conversion numerics <-> unity.mathematics #6

@psydack

Description

@psydack

I don't know if you planning to do or even it will worth, but maybe it will be to have it.
https://docs.unity3d.com/Packages/com.unity.mathematics@1.0/manual/index.html

I think you can put a define on asmdef, something like this:

"versionDefines": [
        {
            "name": "com.unity.mathematics",
            "expression": "1",
            "define": "HAS_UNITY_MATH"
        },

Edit: Maybe Color <> V4

I don't know if have some implication using this

public static Color ToColor(this System.Numerics.Vector4 v4)
{
	return new Color(v4.X, v4.Y, v4.Z, v4.W);
}

public static System.Numerics.Vector4 ToSystem(this Color c)
{
	return new System.Numerics.Vector4(c.r, c.g, c.b, c.a);
}

[StructLayout(LayoutKind.Explicit)]
private struct ColorVectorUnion
{
	[FieldOffset(0)]
	public UnityEngine.Vector4 UVector;

	[FieldOffset(0)]
	public UnityEngine.Vector4 Color;

	[FieldOffset(0)]
	public System.Numerics.Vector<float> SVector;
}

public static System.Numerics.Vector<float> ToSystemGeneric(this UnityEngine.Vector4 vector)
{
	ColorVectorUnion vectorUnionF = default;
	vectorUnionF.UVector = vector;
	return vectorUnionF.SVector;
}

public static System.Numerics.Vector<float> ToSystemGeneric(this UnityEngine.Color vector)
{
	ColorVectorUnion vectorUnionF = default;
	vectorUnionF.Color = vector;
	return vectorUnionF.SVector;
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions