Hi everyone
I’m new to scripting and I got a problem when I want to make an animation with PF.
The script is base on the default birth script of PF, I just want to make the particles color change over age
And when I applied the “Krakatoa Option” to PF, nothing was rendered.(but it could be rendered when turned off the “krakatoa Option”)
So…what 's wrong with my script??
on Proceed pCont do
(
t1 = pCont.getTimeStart() as float
t2 = pCont.getTimeEnd() as float
if (t1 < 0) then (t1 = 0)
if (t2 < 100*160) do -- 100 frames
(
for i in (t1/8+1) to (t2/8) do
(
curTime = 8*i as float
pCont.AddParticle()
pCont.particleIndex = pCont.NumParticles() -- last particle that was added
pCont.particleTime = curTime/160
pCont.particleAge = 0
sh = 2*sin(5*curTime)
ang = 0.2*curTime
pCont.particlePosition = [sh*sin(ang), sh*cos(ang), 0]
pCont.particleSpeed = [0.01*tan(ang), 0.01*sin(ang), 0.001]
pCont.particleVector = [1,1,1] * (1.0 - (pCont.particleAge.frame / pCont.particleLifespan.frame))
)
)
Surprisingly, the reason your color code does not work is that it is placed in the Birth Script and not in a Script Operator as originally proposed in the fading off tutorial.
As you probably know, in order for the LifeSpan channel to be populated, a Delete Operator has to be added to provide the scheduled death of the particle. In other words, particles are not constantly checked for deletion by the Delete Operator, they are simply MARKED for deletion in the LifeSpan channel at birth and PFlow removes them whenever the Age exceeds the Lifespan.
Obviously, in order to populate the LifeSpan channel, PFlow has to evaluate the Delete Operator first. This can happen only AFTER the Birth Script has finished creating its particles, since PFlow evaluates them one by one, not out of order. So when you attempt to divide the Age by the LifeSpan inside the Birth Script, the LifeSpan value is not been initialized yet. If you would switch the VFB to show the Alpha of the rendered particles and right-click one rendered pixel, you would see an IND value (-1.#IND0) showing a division of the age through an indeterminate value for R,G and B. (Alpha is based on the Density, so if you were setting the Scripted Float channel to control the density the same way, it would have caused the same problem within the Birth Script, but here it works because you don’t try to control it via the Krakatoa Options).
When you copy your color code to a Script Operator and do the same, the Delete operator would have been evaluated already (even if it were placed AFTER the Script Operator - it has a higher priority and always gets evaluated first after birth). Then the particles are shaded correctly.
[code]
on ChannelsUsed pCont do
(
pCont.useAge = true
pCont.useLifespan = true
)
on Init pCont do ( )
on Proceed pCont do
(
count = pCont.NumParticles()
for i in 1 to count do
(
pCont.particleIndex = i
pCont.particleVector = [1,1,1] * (1.0 - (pCont.particleAge.frame / pCont.particleLifespan.frame))
)
)
I see…I just thought I would possiblily get the effect without using script operator.
It works for me now, sorry as I am a newbie
Anyway, Thank you very much!