PDA

View Full Version : [HELP] Why on Init executes twice?


mattjakob
02-03-2010, 07:28 PM
In an attempt to solve a tedious issue (see my previous post) about having particles instantiated with different shape nodes (and each shape made of multiple meshes/materials) I went for hardcode/bruteforce creating an array of copies of my "template" shapes and then assigning each of the copies a corresponding TM matrix based on a corresponding particle.
It works, my only problem is that the automatic duplication of my objects happens twice (so I end up having double the number of meshes... which since Im planning to use several thousands objects turns out to be problematic)


on ChannelsUsed pCont do
(
pCont.useTM = true
)

on Init pCont do
(
global theMesh = #()
theCount = $Birth01.Amount

tmp = theMesh.count

if (tmp == 0 ) then
(
for i = 1 to theCount do
(
switch = mod i 12

case of
(
(switch == 12) : theMesh[i] = snapshot $SRC_01
( (switch == 3) or (switch == 6) or (switch == 9) ) : theMesh[i] = snapshot $SRC_03
default : theMesh[i] = snapshot $SRC_02
)

)
)

)

on Proceed pCont do
(

count = pCont.NumParticles()
theMesh.pos = [0,0,-10000]

for i in 1 to count do
(
pCont.particleIndex = i
theID = pCont.particleID
theMesh[theID].transform = pCont.particleTM

)
)

on Release pCont do
(
)


the problem is with the on Init pCont that gets executed twice. Really have no idea why.

Thanks,

JohnnyRandom
02-03-2010, 07:46 PM
Have you tried deleting the snapshots of the meshes when you are finished processing them?

mattjakob
02-03-2010, 07:52 PM
the problem is that as soon as I execute the script whats inside the on Init method gets executed twice. So if I need only 10 instances (10 particles are generated), I get 20. The first 10 remain at 0,0,-1000 and the latter 10 are used correctly and positioned each on each particle.

Is there a smarter way of using instances? I only have 3 "template" shapes that have to be repeated - with different frequencies - over 20,000 particles.

Thanks,

SoLiTuDe
02-04-2010, 04:14 AM
Just curious here, is the script getting called twice because you're at half-frame interpolation?

mattjakob
02-05-2010, 09:54 AM
I thought that was a brilliant intuition... but no :( unfortunately it doesnt change anything.
I think the mechanism behind how the scripts are collected on the various callbacks is very messy. I've been playing with the pflow scripting for a while now and it's purely random for certain things.

Would be good if someone could explain the bizarre logic behind it...

HornBerger
02-08-2010, 11:19 AM
check if this helps, turn off the particle flow source create the script operator (of course modify it to your script) then turn on the particle flow source again

cheers ! :)

mattjakob
02-08-2010, 11:46 AM
thats how Im doing it... switching it on and off at each beginning of the playback but it's kind of ridiculous.

HornBerger
02-08-2010, 12:04 PM
:hmm: maybe you could keep a check if the array is undefined or not. and then use final step update to move the mesh's to the particles? something like this :

on Init pCont do
(
if themesh == undefined do
(
global themesh = #()

format "% is the particle amount \n" $birth01.amount

for index=1 to $birth01.Amount do
themesh[index] = snapshot my_sphere
)
)

mattjakob
02-08-2010, 12:51 PM
Hey.
That's what Im doing more or less.
The problem with that approach is that it runs fine in the viewport but it doesnt render.
You can download the scenefile and read a description here:
http://forums.cgsociety.org/showthread.php?f=206&t=851853

Thanks,

CGTalk Moderation
02-08-2010, 12:51 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.