Skip to content

Swizzle property z and w for int2/float2 and w for int3/float3 #224

Open

Description

@Thaina

Please add complete swizzle property to int2 float2 int3 float3 similar to int4 and float4 and define it as 0

So that we could simply upcast vec2 and vec3 to another dimension easily as downcast vec4 to lower dimension

Such as

var screenPoint = new float2(5,3);
var groundPoint = screenPoint.xzy; // (5,0,3)
var wallPoint = screenPoint.zyx; // (0,3,5)

Alternatively it might be xy0 x0y _0xy yx0 y0x _0yx and maybe xy1 x1y _1xy yx1 y1x _1yx and so on for specific default number

Activity

  1. Cat-du-Fromage commented on Sep 8, 2022

    @Cat-du-Fromage

    +1, the number of time i wished there was a way to make point.x0z is beyond count!

  2. vertxxyz commented on Feb 28, 2023

    @vertxxyz

    I was like, ah yes, lets use assembly definition references to add this...

    public partial struct float2
    {
    	/// <summary>Swizzles the vector.</summary>
    	[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
    	public float3 xy0
    	{
    		[MethodImpl(MethodImplOptions.AggressiveInlining)]
    		get => new(x, y, 0);
    	}
    }

    But nope, as soon as it ends up in Bursted code... Burst error BC0102: Unexpected internal compiler error while processing function

    At least new float3(float2, z) exists.

  3. ltmx commented on Sep 27, 2023

    @ltmx

    Unfortunately, unity is apparently working on enabling users to extend native class, using the attribute [ExtensionsOfNativeClass], but is definitely not supported at the moment.
    In the meantime, You can do a pull request and implement it in this file : https://github.com/LTMX/Unity.mathx/blob/master/Runtime/mathx.floatx.gen.cs
    Have a nice day fellow !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions