marvolo Posted April 12, 2017 Share Posted April 12, 2017 (edited) 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 April 12, 2017 by marvolo Quote Link to comment Share on other sites More sharing options...
f1480187 Posted April 12, 2017 Share Posted April 12, 2017 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. Quote Link to comment Share on other sites More sharing options...
marvolo Posted April 12, 2017 Author Share Posted April 12, 2017 Cool, setattribtypeinfo is exactly what I needed. Not sure how I missed that with google and while looking through the vex function reference, but it works. Thanks! Quote Link to comment Share on other sites More sharing options...
marvolo Posted April 13, 2017 Author Share Posted April 13, 2017 (edited) 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 April 13, 2017 by marvolo 1 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted April 13, 2017 Share Posted April 13, 2017 Here the info about it. You need to specify datatype, otherwise it will be accessed as float (get first component from vector). You don't need to specify it for float attributes, common attributes recognized by Houdini (@P, @Cd, @id, etc.) and when type was specified at least once before. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.