Notifications
Clear all

[Closed] Pflow script – 'turn' objects to particles

Hello guys,

            Here is what I want to do : I want to have the particles of a Pflow system be created by a script that 
            1/ place each of them at the place of a pre-existing object
            2/ give the exact shape, material of the object
            3/ eventually hide the original object.
            
            Here is the script I have made so far : (event with just birth script, speed and display operators)

– On birth script
on ChannelsUsed pCont do
( pCont.useTime = true
pCont.useAge = true
pCont.usePosition = true
pCont.useShape = true
)

on Init pCont do (global My_box = $Box*) – where Box01 to Box12 are the preexisting objects (turned to editable meshes)

on Proceed pCont do
(
ti = currentTime
if (ti == 5) do (
for i = 1 to 12 do (
pCont.AddParticle()
pCont.particleIndex = pCont.NumParticles()
pCont.particleTime = ti/192 – ??? not sure why this is for… I left it from the original script I copied… just changed to 25(192) fps
pCont.particleAge = 0
pCont.particlePosition = My_box.transform.pos [i] – I should also copy the rotation and scale
pCont.particleShape = My_box[i].mesh
)
)
)
[b] on Release pCont do /b

It worked fine for the placement part (the particles shows as ticks), but not for the geometry – they don’t show at all. So I tried to put the shape part in a script operator

– On a script operator

on ChannelsUsed pCont do ( pCont.useShape = true )
on Init pCont do (global My_box = $Box*)
on Proceed pCont do (
for i = 1 to 12 do (
pCont.particleIndex = i
pCont.particleShape = My_box[i].mesh
)
)
on Release pCont do ()

            But it was the same thing (no geometry appearing at all)

I wrote this by copying exemples in the documentation. But I am very aware that I still don’t fully undertand the “Proceed Pcont” process. Also I’m not sure of the mesh part … so that is why any tips are welcome !

            Thank you in advance !
            
            Jerome

PS : also, if any one has some pointer to give to me as how to have each of these particles start “around” frame 5 (+/- n frames for each particle)

3 Replies

This might be obvious, but are you sure you have turned on Geometry in the Display operator?

The full (and rather simple) tutorial is here:

http://www.scriptspot.com/bobo/mxs5/pflow/pflow__Chunks_Basics.htm

As for the time, you should NEVER use the currentTime variable because it is not set correctly when rendering. Use
t = pCont.getTimeStart() as float
or
t = pCont.getTimeEnd() as float

as shown in the example (this is the start or end time of the particle container’s evaluation time at which the proceed handler is called – sometimes multiple times per frame, depending on the Integration settings!)

You can add a print t line to your script and watch the values. At 25 fps, 5 frames means 192*5 = 960 ticks. 192 is the number of Ticks in a frame at 25 fps (4800/25).
Instead of hard-coding with 192, you can use TicksPerFrame like

(TicksPerFrame * 5)

where 5 is the number of frames you want to wait before creating the particles, and TicksPerFrame varies depending on your FPS settings in the Time Config. dialog…

So your code would look something like

[b] 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.getTimeEnd() as float

 if t == TicksPerFrame * 5  do 
 (
     NumChunks = ChunksArray.count[/b]

[b] 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
(

)[/b]

And don’t forget to set the Display to Geometry!

Yes I am, I have spent all the day turning it in and off ! But you’re right to ask, I should have specified it the particles showed correctly as ticks and disapeared when I turned the display as geometry. They were not ‘hidden’ by the geometry either (I could see them moving as ticks after creation, but not as geometry.
I had also problems with the transform/TM, so I had tried with only the position first.

I’ll try your code this morning. Thanks a lot for answering, you’re really helpfull (as usual )

Jerome.

It works perfectly fine !
thanks a lot Bobo.

I think the trouble was that I used only the position part of the transform matrix. I guess it needed also the rotation and mainly the scale factor, and the geometry showed, but as 0,0,0 scale factor!
I have to go back to study transform matrice. I was quite OK with that 15 years ago so that shouldn’t be too hard. :rolleyes: