pjackson Posted June 4, 2015 Share Posted June 4, 2015 (edited) I have some particles and I have a curve with many points. What i want it for particles to zoom to the points on the curve in order. I want to be able to have particles floating in the air and then make a dummy sphere that expands colliding with the particles. The first particle that collides with the sphere zooms to point 1 on the curve. The next point that collides with the sphere zooms to point 2 etc.. I have it set up in dop pops so that the particles change streams when they collide and I have them zooming to the curve based on thier id and it works great, but its not ordered... I think my solution would be to create and increment a global counter variable to use in a POP wrangle node? but im not sure if thats possible.. The goal that the particle chooses needs to be set at the moment of collision, and it needs to account for all the other particles that have already chosen a goal. In my head the psuedocode for this kind of thing would be something like this- //at start of simulation counter = 0; //while simulation is running if (collided == true) { @goalId = counter; counter += 1; } I just have no way of creating that counter variable.. I may be thinking of this all wrong so any ideas would be super helpful! Edited June 4, 2015 by pjackson Quote Link to comment Share on other sites More sharing options...
anim Posted June 4, 2015 Share Posted June 4, 2015 (edited) just look inside POP Source and explore 2 nodes near the end set_ID_attribute and update_next_id1 they do: update_next_id1 - simply creates detail attrib called nextid which remembers what id should be next set_ID_attribute - looks up nextid attrib value and continues with id numbers for currently sourced particles so you can do the same logic to assign goalids to your particles simply keep track of highest goal id in detail attrib and upon collision assign goalids to collided particles that continue from there Edited June 4, 2015 by anim 2 Quote Link to comment Share on other sites More sharing options...
pjackson Posted June 5, 2015 Author Share Posted June 5, 2015 Awesome thinks for your help Anim! I thought it might be something to do with detail attributes but im still learning how to manipulate them. I havent been able to read the detail from a wrangle node within dops... I can create the attribute a couple of ways and see it in the geometry spreadsheet, I can make a sop solver in dops and use an attribute create like inside the POP source. I can also create it in a POP wrangle node- adddetailattrib(geoself(), "counter", 10); I can change its value- setdetailattrib(geoself(), "counter", 50); But i cant work out how to read it from the POP wrangle... this doesnt seem to work, always returning 0- int myCounter = detail("../popsource", "counter", 0); i think because the wrangle is in dops and not sops? Quote Link to comment Share on other sites More sharing options...
anim Posted June 5, 2015 Share Posted June 5, 2015 just use int myCounter = detail(0, "counter", 0); and go to POP Wrangle/Inputs tab and change Input 1 to Myself so it will bind 0 to data that the POP Wrangle is currently processing or alternatively you can bind it to any sop or dop data 1 Quote Link to comment Share on other sites More sharing options...
pjackson Posted June 7, 2015 Author Share Posted June 7, 2015 (edited) Im getting closer but still having some issues.. It seems to be that detail() only runs once at the beggining of the frame and not again for every particle. I was using setdetailattrib() previously and it also seemed to have this problem. However, if i use setattrib() in "add" mode it seems to run for every particle. I cant avoid using detail(). This leads me to believe im not understanding how its all structured.. its like its a threading issue and the add operation is the only one thats thread safe. My wrangle POP has this code at the moment- adddetailattrib(geoself(), "counter", 0); if (@hitnum > 0 && @state == 0) { @state = 1; //changes particle to go to goal @goalId = detail(0, "counter", 0); //sets goalId for the particle setattrib(geoself(), "detail", "counter", 0, 0, 1, "add"); //increments the counter detail attribute } Ive also attatched the file im working on, its sort of working but not quite... You will notice that the particles are doubling up on their goalId attributes. for example the first few particles go 0,1,1,3,4,4,4, where i want them to go 0,1,2,3,4,5... goalTest_04.hipnc Edited June 7, 2015 by pjackson Quote Link to comment Share on other sites More sharing options...
anim Posted June 7, 2015 Share Posted June 7, 2015 (edited) that makes sense, since POP Wrangle iterates in point mode therefore executes all points in parallel and therefore all points within timestep access the same counter value and result in the same goalid there is many ways to do that and for previously mentioned method it would need to be in SOP solver as you'd need to isolate the points however you can do it in 2 wrangles at DOP level quite easily you can just mark just released points in point mode (parallel) if (@hitnum > 0) { i@state=1; i@group_justreleased = 1; } then iterate over them in detail mode (sequentially) and set the goalids addpointattrib(0, "goalId", -1); int pts[] = expandpointgroup(0, "justreleased"); foreach(int pt; pts) { setpointattrib(0, "goalId", pt, i@nextgoalid); setpointgroup(0, "justreleased", pt, 0); i@nextgoalid++; } here is the example ts_set_goalId_on_released.hipnc Edited June 7, 2015 by anim 2 Quote Link to comment Share on other sites More sharing options...
pjackson Posted June 8, 2015 Author Share Posted June 8, 2015 thanks anim that solution is simple and it works great! Using the geometry wrangle to make your own loop seems pretty useful Quote Link to comment Share on other sites More sharing options...
anim Posted June 8, 2015 Share Posted June 8, 2015 it sure is, the same way as AttribWrangle SOP in Detail mode 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.