Can you determine if an attrib is 2float or 3float in vex?

   1304   2   0
User Avatar
Member
35 posts
Joined: April 2015
Offline
I am trying to set Cd to the value of an attribute in vex but I do not know the attribute type ahead of time. Assuming the attr is an int, float, 2float, or 3float I want Cd to become:

int -> {int,int,int}
float -> {float,float,float}
float2 -> {float2.x,float2.y,0}
float3 -> {float3.x,float3.y,float3.z}

So I am doing something like (vertex wrangle in this case):

v@Cd = vertex(0,"st",i@vtxnum);

if st is a 2float then this does not evaluate st correctly. How do I handle setting Cd when st could be any of int, float, vector(3float), vector(2float) ?

If I can determine 2float vs 3float then I can do:

v@Cd = vector2(vertex(0,"st",i@vtxnum));
or
v@Cd = vector(vertex(0,"st",i@vtxnum));

as needed to get the correct result.

the functions attribtype() or vertexattribtype() group float and vector types into one return value.. So they don't really help.
Edited by cruiserandmax - Nov. 4, 2021 22:27:49
User Avatar
Member
7814 posts
Joined: Sept. 2011
Offline
You can use attribsize to get the length of the attribute.
Something like this should work for the case of int, float, float2, or float3:

string attrib = chs('attrib');
int l = attribsize(0, "point", attrib);
if (l==2)
{
    v@Cd = vector2(point(0, attrib, 0));
}
else
{
    v@Cd = vector(point(0, attrib, 0));
}
User Avatar
Member
35 posts
Joined: April 2015
Offline
That is perfect! Thanks!!
  • Quick Links