Jump to content

How to accumulate a point attribute in an array attribute ?


Recommended Posts

I  have an attribute hitFrame set in a Solver that's equal to @Frame when some condition is met over time.

How do accumulate those non zero values in a list, on that same point ?
It sounds easy but I can't get it right, maybe because of  a Vex syntax problem to get the previous value, or a logic error in the Solver.

Right now the Solver computes the Velocity of a point, and is able to tell if the condition is met at the current frame.

How do I keep track of the previous values in  f[]@previousHits ?

I will rephrase this to be more clear:

I have a solver that generates, per point an attribute Hit which value is set to @Frame when something happens. Otherwise it's set to zero.

For example if at frame 3 and 10 this situation happens, I would like to have those values in an array equal to [3;10], starting from frame 10;

I want to keep track of changes made to this attribute; something like Trail SOP

accumulateAttribute.hipnc

Edited by AntoineSfx
Link to comment
Share on other sites

  • AntoineSfx changed the title to How to accumulate a point attribute in an array attribute ?
34 minutes ago, hannes603 said:

Not sure if this is what you mean.... but you can append any attrib per frame to an array if an condition is true ....

append_vector_if.hip 135.04 kB · 2 downloads

This is not what I mean.

For example, if at frame 3  and 10 there is a hit, meaning a point has an attribute hit that is equal to @Frame, later in time the attribute contains [3;10] 

So that at any point in the animation, I have a list of previous hits.

Link to comment
Share on other sites

So here is how I got it working:
Generator: one point,

in PointWrangle

if ( (int)@Frame % 10 == 0 ) f@hit=@Frame;

in Solver / pointWrangle:

i[]@hitRecord=point(1,"hitRecord",0);
if (i@hit == @Frame) 
    append(i[]@hitRecord, i@hit);

In Solver Input_1 connected to PointWrangle/Input1   (a.k.a point(0,...    )

In Solver Prev_Frame connected to PointWrangle/Input2 (a.k.a point(1,...    ) 

Result: At Frame 80: i[]@hitRecord  = [ 10, 20, 30, 40, 50, 60, 70, 80 ]

 

 

 

houdiniPW.png

houdiniSolver.png

Edited by AntoineSfx
Link to comment
Share on other sites

14 minutes ago, hannes603 said:

image.jpeg.ecd9e7f7b43466fb181ae543dcc4d860.jpeg

You can write it much simpler

simple.hip 127.35 kB · 0 downloads

No

The hits are definitely not computed at this point. They're computed in a previous node. The %10 was the simplest example I could find, but it's definitely an attribute on  a point that changes over time.

In my working workflow, if it can be improved, it can only be done after pointwrangle6 without changing it. Remember that this is just an example. I'm not trying to generate the list [ 10, 20, 30, 40, 50, 60, 70, 80 ], it just happens to be the result in this specific case. The question is about accumulating the non zero values of an attribute that changes over time. Not sure how I can simplify it even further. Hope this clarifies the situation.

Edited by AntoineSfx
Link to comment
Share on other sites

i dont see the difference between those two.. Maybe you got something wrong. Your usually dont need to load the array from the prev frame, bec thats what a solver anyway is always doing...  Maybe take a look at  'vex isnt scary'' on youtube. It helped me a lot to start :)

Link to comment
Share on other sites

22 minutes ago, hannes603 said:

image.thumb.jpeg.21bb8f96d265f1007747584123d824c5.jpeg

That example accumulates all non zero attrib values. the attrib is changing over time on all the points differently.  thats my last try to make you happy :D

accumulate_non zero_on_changing_attrib.hip 113.2 kB · 0 downloads

That's the other way to do it, compared to my working answer posted a few messages back.

As a note to future self: 

The trick is that the hitList and the hit will always be on two different branches inside the solver; so you have to copy one of them with a point() call.

In this last answer, the array ends up on the initial "Previous Frame" which is a copy of the input at frame0, so not animated any more; the array is however correct.

In this case, you can rewrite it as: (using the @opinput1 syntax)

if (f@opinput1_hit == @Frame ) {

append(f[]@hitList,@Frame);

}

Thanks.Thread is closed for me.

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