Jump to content
ikoon

wrangle / run over class, set attrib value to another class?

Recommended Posts

Please, can I run Attribute Wrangle:

- over primitives (e.g. evaluate myvector), create array of myvectors and save it to the detail attribute?
- over detail and access some attribute in the primitive class? or point class?
 

I could use the Attribute Promote, but sometimes I am using Time Shift and the "primnum" or "ptnum" doesnt match.

Also, please ... can I set attribute to some other SOP, analogous to the read "detail" from other SOP function, please?
Or even ... can I have some global repository, for example on the global OBJ level or OBJ/GEO?

Thank you very much.

Share this post


Link to post
Share on other sites

Btw I have tried the "Set Attribute" inside the Attribute VOP but unfortunately I did not succeed. It sets only the first vector value, not all the three. See the attached file, please.

Wow, when I try to open my file now (attached setattrib.hipnc), it works.

When I try to fiddle with the parameters, it seems to be "stuck" in the wrong settings sometimes ... is it because of some memory allocation? Because I set the signature once to float, instead of vector?
 

I dont understand it :( sorry for my confusions, but could somebody help me?

setattrib.hipnc

Share this post


Link to post
Share on other sites

I don't think you can save an array as a detail attribute, but you can save a long string, i.e "3 1243 221 342", using spaces to separate each element. Then when you read than in Vex, you can use the split() function to put it back into an array. Depending on your data type, you might need to convert the string back to an int or float.

Your second question is much easier! When you are in detail mode and want to access primitive or point attributes, use VEX prim() or point() functions

If you specifically want to grab detail data from other SOPS, use the detail() expression. However, if theres data I want to use alot, I often set up null nodes to act as master control nodes, and add custom channels to it. Then I can path to it to retrieve the data. You can set global attributes, but I don't find that as flexible as having a master control node. To retrieve the data from it, use the ch() expression. I've added a file to help illustrate this with a couple of stickys. Ive also added an example to show how to bring that data into VEX.

global_data.hip

Edited by rich_lord
  • Like 2

Share this post


Link to post
Share on other sites

Thank you very much! Odforce should have a donate next to the Like button :D


As regards the array stored in the detail, I have succeeded with this inside the Attribute Wrangle, run over Detail:
matrix3 mat = {1,2,3,4,5,6,7,8,9}; //OK
3[]@myMatrixarray[0] = mat; //OK

You can also use:
f[]@myFarray = {0,1,2,3,4,5,6} ;//OK
i[]@myIarray = {0,1,2,3,4,5,6} ;//OK
v[]@myVarray = {{1,2,3},{4,5,6}};//OK
v@readvect = @myVarray[1];//OK
3[]@myMatrixarray = { {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}}; // OK

 

I need an array of matrices somewhere in the "global" or detail ... so I will explore some more. If anybody could help here more, I will be grateful :)

Share this post


Link to post
Share on other sites

Holy crap! You are right, you can assign array to attributes like that, also works on points, prims and verts! I dont know if I missed that or if its new, but ive made elaborate workarounds for this in the past.

Im still a bit crap with matrices, but, based on your code, this seems to work to create a detail attribute of an array of matrices

matrix3 mata = {1,2,3,4,5,6,7,8,9};
matrix3 matb = {1,2,3,4,5,6,7,8,9};
matrix3 matc = {1,2,3,4,5,6,7,8,9};

3[]@matrix_array[0] = mata;
3[]@matrix_array[1] = matb;
3[]@matrix_array[2] = matc;

 

  • Like 2

Share this post


Link to post
Share on other sites

1. You can, but in wrangle you access input's values, not current array being processed, so, they won't accumulate.

// Point wrangle.
float xs[] = detail(0, "xs");
append(xs, @P.x);
setdetailattrib(0, "xs", xs);

This will set detail attribute ps to something like [ -0.980194 ] regardless of number of points being processed. Since it is limited, this kind of tasks should be done from opposite end. Run Detail wrangle instead. As side note, it seems that adding attributes with adddetailattrib function works only with arrays of atomic types: floats and integers and also for strings.

2. You could access and set attributes, but you need to compute entity numbers. It is usually sufficient to simply run for loop in range of 0..numpt to iterate over all points.

for (int i = 0; i < @numpt; i++)
{
    vector pos = point(0, "P", i);
    append(f[]@xs, pos.x);
}

You could use functions like primpoint to get ith point of a primitive (or primpoints, to get all of them in array), there are many of them in "Geometry" section, also a specific page for converting between numbers.

3. You cannot write attributes to anything other than first input. It was stated, that in future Houdini maybe will write in another inputs of the node. I doubt there will be possibility of set something in external geometry, but you can do work in opposite way and access attributes normally from any external node using string path argument instead of an integer input number. Also read this: http://www.sidefx.com/forum/topic/42999/

 

detail_array.hipnc

Edited by f1480187
  • Like 2

Share this post


Link to post
Share on other sites

Thank you very much F1! Now I understand it much better.

As regards your sidenote about the adddetailattrib ... should I add attrib before setting a value? Do I run into troubles if I dont? For instance, this works even without the adddetailattrib:

 

matrix3 myMat = {1,2,3,4,5,6,7,8,9};
for (int i = 0; i < @numpt; i++)
{
    append(3[]@myMats, myMat);
}

Later, I can for example setattribtypeinfo(0,"detail","myVector","vector") if I need. Btw setattribtypeinfo doesnt offer matrix3 or array as typeinfo, but that probably is not needed.

Another two questions, please:

- I am a newbie and sometimes, when I am learning and setting some VOP, I set wrong signature (float instead of vector3). Houdini then seems to "allocate memory" as a float, and then, even if I fix that VOP signature to vector3, or disconnect/reconnect, it is "stuck" and sets only vector[0] and sets zero values to vector[1] and [2]. It happened inside the For Loop. Am I right? Then, when I debug ... can I somehow reset Houdini? It helps to reload the file. Or maybe I am wrong even more, and the problem is somewhere else. Please somebody give me a clue.

- how did you post such a nice formatted code :) I should learn it to make my posts better arranged.

Share this post


Link to post
Share on other sites

1. Sorry, I meant all four (?) functions adding attributes, not adddetailattrib only. Such adding is useful when you want to do everything in one VEX program, and you want to add point attribute within primitive wrangle, for example. @-syntax automatically adds attributes for current entities, no need to use add function there. It can be used in first code example to add detail attribute, but for some reason it works only for subset of types, so, you can't add matrix array attribute, there is no signature taking matrix array argument.

2. Type info is for "types of types". Like: normal, position, vector or simply 3-float for what we create as vectors. Difference is that you need your normals to rotate when you rotate geometry with transform node, but you don't want any numerical changes for color values at the same time. You can't change type with it: convert vector array to matrix or convert vector to float array.

3. Yes, nodes "remembers" input and then may behave strange. Try one of this:

  • Delete the problem node and undo.
  • Go up one level and return back.
  • Go up to SOP level, delete Attribute VOP and undo.
  • Go up to SOP level and press "Force Recompile" button on Attribute VOP.

4. Here the button:

code_button.png

Edited by f1480187
  • Like 1

Share this post


Link to post
Share on other sites

Oh I see. Affirmative! Thank you very very much!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×