Let’s say I have a series of particles and I want to use nearest particle to generate a vector pointing to the nearest particle, and then keep doing that in a chain. I can’t seem to figure this one out. I’ve tried using intersect ray and while I feel I may be on the right path I can’t really get there.
Another, but related, problem I’d like to solve is how to I get the position of a particle based on its ID?
You cannot do it “in a chain”. You would need an actual programming language (e.g. MAXScript) to define all the logic required to store information about the points already visited to avoid picking the same point more than once, and advancing to the next point based on the previous step’s outcome.
In Magma, there is an implicit outer loop that goes through all particles, and you cannot escape it or redefine it. So on each iteration, you can find the nearest particle to the current particle, and create a vector or even build a strut of vectors and mesh it with Frost to make it look like a lattice. But the result won’t be a single jagged line, it would be a series of “constellations” based on the proximity of particles in certain clusters. I have a scene that does that using a PRT Loader, one or more PRT Makers, and Frost that I created a few months ago:
Frost_PRTM_ConnectParticles_v001.png
In the above case, I used two PRT Makers - one to connect each point to the second closest neighbor with 30 new points, and another to do the same using the 3rd closest neighbor. The 1st closest neighbor to a position is the current particle itself, so we cannot use it.
It also had controls to remove struts if the distance was above a threshold, and to create a curved strut with bulging points at the particles by manipulating the Radius channel:
For some reason, even though I am subscribed to this topic, I didn’t get notified so apologies for the late reply.
Thanks for providing me with the example, but it won’t solve my particular issue. The issue in my case is I have saved a bunch of PRT Hairs into PRTs but forgot to include the tangent channel. Now, this was a long time ago and I can’t find the file where the splines are (there’s a 100 or so involved), and in the right positions to re-save out the PRTs with the tangent channel in tact. So I was hoping to get the vector starting from the first particle in the now chains of PRTs to the next to get my velocity channel.
Once I can get the position of the ID of the particle that’s logged as a wish, maybe I could make this doable. But lesson is to try to remember to save all the channels that you might need even if you think you don’t at the time. So I’ve succumbed to the fact that i need to redo it and not forget the tangent channel this time.
Thanks for the in-depth answer, and your example might come in handy in another scenario .
Did you save any of the other Hair-specific channels? If you have SplineID and RootDistance, you could restore the info somewhat because the particles would probably be in the correct order anyway, and you would only have to read one particle ahead, check if it is on the same SplineID and create the normalized vector from the its Position minus the current particle’s Position. You would need a second PRT Loader to load the particle with Index+1 of the current particle in your base PRT Loader.
Even without the SplineID channel, you could detect when the next particle changes position abruptly because you switched to the next spline (for example the distance to it is many times higher than the typical spacing between the hair samples).
Then again, if you are ok with the last particle of a hair strand pointing sideways to the root of the next hair, you don’t even need to check that…
Thanks for the reply (and the example). I didn’t save the RootDistance channel but I do love the thought and execution. You also answered my question about getting the next particle in line using the ID and getting the position which was easier than I thought. I don’t think I’ll forget to ever save the tangent again after this experience but this is a great example to learn from. Thanks again.