[Closed] Objects to Particle Position
Hi
Been a while since i ventured into scripting so am a little rusty. I am trying to write a script for PFlow which places a geometry object in onto each particle. This is similar to the one in the hepl however I simply want the particles and geom to be aligned on the first frame.
I was going to use the base of the following code which I believe we written by Bobo or Allan MCkay. This however creates a copy of existing geom and assignd a particle to it. It also relies on the geometry already being there. What I want to do is create a point helper for each particle dynamicly.
I am sure that this is simple and I am missing the point. However each time i do it I geta new geometry object crreated on each point on each frame.
Any help would be appreciated.
Harry
on ChannelsUsed pCont do
(
pCont.useAge = true
pCont.useTM = true
pCont.useShape = true
)
on Init pCont do
(
global ChunksArray = $Box* as array
)
on Proceed pCont do
(
t = pCont.getTimeStart() as float
if t < 0 do
(
NumChunks = ChunksArray.count
for i = 1 to NumChunks do
(
pCont.AddParticle()
pCont.particleIndex = pCont.NumParticles()
pCont.particleAge = 0
pCont.particleTM = ChunksArray[i].transform
pCont.particleShape = ChunksArray[i].mesh
)
)
)
on Release pCont do
(
)
You don’t have to run the script inside a script operator to create objects out of particles.
The simplest form would be
(
thePF = $PF_Source_01 –this is the PFlow emitter
theCount = thePF.numParticles() –this is the number of particles
for p = 1 to theCount do –loop through all particles
(
thePF.particleIndex = p –set the current particle
theMesh = editable_mesh() –create a new EMesh object
theMesh.mesh = thePF.particleShape –set its triMesh to the shape of the particle
theMesh.transform = thePF.particleTM –and set its transform to the particle’s TM
)–end p loop
)–end script
If you run this script, PF_Source_01 will be baked into as many meshes as there are particles in the VIEWPORT (remember to set Viewport % to 100 to get them all)
If the count is constant, you could bake the TMs over time with animate on to bake the animation, too (minus the mesh creation which should happen just on the first frame). If the count is changing (particles being born or getting deleted), it would require a lot more code.
Hi Bobo
Thanks for that, it works perfectly. I didnt actualy need to animate the positions it was simply to be used like an advanced scatter.
I had forgotten that you could access PFlow from outside like that, made it a load simpler than what I was trying to do.
Thanks
Harry