Jump to content

VEX Vector Attribute Creation Type


Recommended Posts

Is it possible to create an arbitrarily-named transformation vector attribute through VEX?

Let's say I do this in a point wrangle:

v@test = {0.5, 1, -0.2};

From what I understand the resulting attribute is what's called an arbitrary vector (indexed by 0, 1, 2). How can I have this created as a transformation vector (indexed by x, y, z)?

It seems all of the automatically-cast attributes are created as transformation vectors (@P, @accel, @center, @dPdx, @dPdy, @dPdz, @Cd, @N, @scale, @force, @rest, @torque, @up, @uv, @v), but I need to name the attribute something else.

Interestingly, if I create the same attribute with an Attribute Create SOP, with type set to vector, the resulting attribute is a transformation vector (x, y, z). However, I cannot seem to create an arbitrary vector through Attribute Create.

What I'm currently doing is first creating the attribute with an Attribute Create SOP, and then modifying it with the point wrangle. But there must be a way to do it without the wrangle?

This seems like such a common question, but I've searched all over and looked through many of the vex functions that I thought may be relevant and I can't seem to find anything. Maybe I'm just using the wrong terms.

Edited by marvolo
Link to comment
Share on other sites

You can index them all as test.x, test.r or test[0], no difference in VEX code. Maybe you confuse this with parameters? Like, depending on what kind of template you choose in Edit Parameter Interface window, resulting parameter reference could look like ch("parm1"), ch("parmx") or ch("parmr").

To turn 3-float into a normal-like attribute, for example, you need to use setattribtypeinfo() function:

setattribtypeinfo(0, "point", "test", "normal");

Another way is to add Attribute Create node, specify existing attribute, select Float type and set it's size to 3, then choose new type info and disable Write Values checkbox. There is also Vector type which is similar to Float with Vector type info specified. Probably for compatibility reasons.

Link to comment
Share on other sites

Okay so there is some further confusion.

Let's take this simple example. I have a single point at world origin (add sop), connected to a point wrangle:

vector myNormal = normalize({0.25, 0, -1});

v@mydir = myNormal;
setattribtypeinfo(0, "point", "mydir", "normal");

@N = myNormal;

This appears to create two identical attributes, they are both 3-float normal attributes according to the node information pop up. They also both appear as [x, y, z] in the geometry spreadsheet.

Now If I make another point wrangle down stream:

@P += @N;

I get the expected result. The point is translated in the expected direction a distance of 1 unit.

However If I transform the point by the other attribute (mydir) instead:

@P += @mydir;

I get a completely different result. The point moves the right amount in the x-axis, but for some reason it moves in the opposite z-direction, and it also moves in the y-axis. And the overall distance is far less than 1.

What am I missing here?? Maybe this is just my limited understanding of 3D math.

 

 

Solution:

I have to explicitly access the mydir attribute as v@.

@P += v@mydir;

I didn't realize this made a difference when accessing attributes through VEX. But I'm leaving the solution here for anyone else who gets stuck on this.

 

Edited by marvolo
  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...