Jump to content

[SOLVED] [VEX] point() function returning "old" value


Alain2131

Recommended Posts

Hello guys !

I noticed that in vex, if you modify an attribute and then read it back using the point() function (or prim(), or anything not using the @ nomenclature), it will return the input value, not the modified one.
See this code, running over Detail

vector thePos = point(0, "P", 0); // Input point's pos is {0,0,0}
thePos += {1,2,3};
setpointattrib(0, "P", 0, thePos);

thePos = point(0, "P", 0);
printf("%d ", thePos); // Prints {0,0,0} instead of {1,2,3}

I mean, even this code doesn't work ! No input, running over Detail

addpoint(0, {1,2,3});
vector thePos = point(0, "P", 0);
printf("%d ", thePos); // Prints {0,0,0} instead of {1,2,3}

But interestingly enough, when running over Points (or prim or whatever), this happens

//Input is one point, at {0,0,0}
@P += {1,2,3};

vector thePos = point(0, "P", 0);
printf("Real pos : %d\n", @P); // Prints {1,2,3}
printf("Problem pos : %d\n\n", thePos); //Still prints {0,0,0}

Not sure what that means, but it can't be applied in my case, as I need to run over Detail. Just wanted to point it out.

I need to be able to modify some point attributes (pos and others) and then read them back when running over Detail.
How can I do that ? Is it possible ?

Thanks in advance !

point_old_value.hip

Link to comment
Share on other sites

Yeah, not sure about the technical terms but vex will only create geometry/modify attributes at the end of the code execution. 

vector thePos = point(0, "P", 0); // Input point's pos is {0,0,0}
thePos += {1,2,3};
setpointattrib(0, "P", 0, thePos);

thePos = point(0, "P", 0);
printf("%d ", thePos); // Prints {0,0,0} instead of {1,2,3}

Here you first set 'thePos' to the incoming P. You then add some values to it, and set P to be this new value. You then overwrite 'thePos' with the incoming P again, mind you the code execution isn't done yet so this will still be the original position.

Link to comment
Share on other sites

Just use two wrangles.

Wrangle #1:

vector thePos = point(0, "P", 0); // Input point's pos is {0,0,0}
thePos += {1,2,3};
setpointattrib(0, "P", 0, thePos);

Wrangle #2:

thePos = point(0, "P", 0);
printf("%d ", thePos); // Prints {0,0,0} instead of {1,2,3}

 

Link to comment
Share on other sites

Hey guys, thanks for the fast replies !

I see now, it makes sense. I was a bit confused by the @ syntax which was able to read the "correct" value.

But unfortunately I can't use two different wrangles to fix my problem. I'll explain a bit more.

I have some points, representing bones position. Those points starts with the original bones' position and rotation (with a rot attribute).
What I need, is with one node to write some position/rotation that the "bones" needs to perform in a temp attribute (tempPos & tempRot) on all the required points. No problem there.
Then, I need to apply the transformation on the points. That's where the problem is.

In the test case, I only apply some transformation on the two first bones of the chain.
I worked out how to apply the transformation to the points in local. So that works.
But each transformations gets overridden by the next one, so that only the last one gets taken into account, because of the reason mentioned above.

If I override the master loop which loops over all points and simply place two wrangles one after the other saying the first is i=0, and the second i=1, it works as intended. But that's not a viable solution in my case.

See set_point_transformation_matrices.hip

Thanks !

P.S. There is some major flaws in my math.
I just found out that any other points than the two firsts doesn't work properly. It has nothing to do with the matter at hand, it's just a forewarning.

UPDATE : I figured out the math/logic - I had the world position inside the matrices instead of the local position. Fixed that. So yeah, last problem is the one explained in this post. Hip file updated.

Edited by Alain2131
Link to comment
Share on other sites

Sorry for double-post, but I think this deserves it.
I think I figured it out.

I had three ideas to fix the problem.
1 - Don't write the positions and matrices to the geometry. Instead, generate a duplicate of all the attributes in memory using arrays 'n things, and modify those instead. Only at the end would I write the result to the points.
I ruled it out pretty fast because I was lazy (what a hassle it would have been). How to represent multiple matrices and positions while keeping the point they belong to referenced without dictionary-like features ? Can I even make an array of matrices ? Maybe, don't know, again, a hassle. Not much thought put into this one.

2 - Convert the code to work running over points, and set the attributes using the @ syntax, so that when looping the values would be correctly returned.
Ruled it out. A hassle.

3 - The problem was to loop over the points, set some attributes, read some, set the new matrix and pos, then loop again with the new geometry. A job perfectly suited for the for loop in count mode, with Fetch Feedback and Feedback Each Iteration.
I did some (small) tweaks, and it works ! Yay !

See set_point_transformation_matrices_working.hip

Edited by Alain2131
Link to comment
Share on other sites

  • Alain2131 changed the title to [SOLVED] [VEX] point() function returning "old" value

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...