PDA

View Full Version : Spline as force, SOO SLOOOOW


AroundTheFur
08-12-2010, 02:56 PM
Hey everyone,

I've made a simple script operator that uses the closest point on a spline to determine the speed vector, and while it works perfectly it is incredibly slow even with very few particles (sub 1000). I've read through the "How to make it faster" portion of the help and done all I could to optimize this, but I'm curious if you MXS masters out there have any suggestions?

on ChannelsUsed pCont do
(
pCont.useSpeed = true
)

on Init pCont do
(

)

on Proceed pCont do
(

count = pCont.NumParticles()

for i in 1 to count do
(
pCont.particleIndex = i
pCont.particleSpeed = (pathTangent $Shape10 (nearestPathParam $Shape10 pCont.particlePosition)) * ((length pCont.particleSpeed) * .95)
)
)

on Release pCont do
(

)

Much appreciated! :bowdown:

Bobo
08-12-2010, 03:57 PM
Can you define "slow"?

On my machine, with 1000 particles it takes around 120 ms per update.
With 10K particles, it takes 10 times longer, around 1200 ms per update.
So it scales linearly and given the amount of code, there isn't much that can be improved.
Replacing the $ node resolving with a global variable holding the spline improves the quality of the code, but not the speed (as far as I could measure).

So I think you will have to live with it.

AroundTheFur
08-12-2010, 04:39 PM
Oh well, if Bobo says live with it, live with it I shall. ;)

CGTalk Moderation
08-12-2010, 04:39 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.