AntoineSfx Posted November 10, 2023 Share Posted November 10, 2023 (edited) 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 November 10, 2023 by AntoineSfx Quote Link to comment Share on other sites More sharing options...
hannes603 Posted November 10, 2023 Share Posted November 10, 2023 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 Quote Link to comment Share on other sites More sharing options...
AntoineSfx Posted November 10, 2023 Author Share Posted November 10, 2023 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. Quote Link to comment Share on other sites More sharing options...
hannes603 Posted November 10, 2023 Share Posted November 10, 2023 You can use a find function. Hope thats what you mean! find_function_array_value_matching.hip Quote Link to comment Share on other sites More sharing options...
AntoineSfx Posted November 10, 2023 Author Share Posted November 10, 2023 6 minutes ago, hannes603 said: You can use a find function. Hope thats what you mean! find_function_array_value_matching.hip 100.02 kB · 0 downloads No the Quote Link to comment Share on other sites More sharing options...
AntoineSfx Posted November 10, 2023 Author Share Posted November 10, 2023 No this is not what I mean. Also this is not how find works, the behavior is weird,it looks like it's cast as strings at some point. I have rephrased my problem in the initial question if you need to rethink it. 1 Quote Link to comment Share on other sites More sharing options...
AntoineSfx Posted November 10, 2023 Author Share Posted November 10, 2023 (edited) 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 ] Edited November 10, 2023 by AntoineSfx Quote Link to comment Share on other sites More sharing options...
hannes603 Posted November 11, 2023 Share Posted November 11, 2023 You can write it much simpler simple.hip Quote Link to comment Share on other sites More sharing options...
AntoineSfx Posted November 11, 2023 Author Share Posted November 11, 2023 (edited) 14 minutes ago, hannes603 said: 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 November 11, 2023 by AntoineSfx Quote Link to comment Share on other sites More sharing options...
hannes603 Posted November 11, 2023 Share Posted November 11, 2023 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 Quote Link to comment Share on other sites More sharing options...
hannes603 Posted November 11, 2023 Share Posted November 11, 2023 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 accumulate_non zero_on_changing_attrib.hip 1 Quote Link to comment Share on other sites More sharing options...
AntoineSfx Posted November 11, 2023 Author Share Posted November 11, 2023 22 minutes ago, hannes603 said: 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 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. Quote Link to comment Share on other sites More sharing options...
hannes603 Posted November 11, 2023 Share Posted November 11, 2023 On animated points is no problem with my setup too... Hope i could helped you a bit accumulate_non zero_on_changing_attrib_animation.hip 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.