c = Circle()
convertToSplineShape c
theKnots = for k = 1 to 4 collect (getKnotPoint c 1 k)
For a shape with more than 1 spline we need to know the number of the splines, which we get with numSplines function. Before make our double loop, I need to note that NumKnots function has a second argument which is optional, but is important for our case. If we not supply the second argument the NumKnots will return the number of all knots in the shape. But to write compatible with getKnotPoint loop, we need to get knots count per spline! So, lets see this with simple example using Donut (it has 2 splines with 4 knots on each of them):
dn = Donut()
convertToSplineShape dn
theKnots = #()
for Sp = 1 to (numSplines dn) do
for k = 1 to (NumKnots dn Sp) do
append theKnots (getKnotPoint dn Sp k)
And just for reference - here is how the mentioned birth operator w'd like:
on ChannelsUsed pCont do
(
pCont.useposition = true
pCont.useTime = true
)
on Init pCont do
(
global pflowguide = $guide
)
on Proceed pCont do
(
if pflowguide != undefined do
(
t = pCont.getTimeStart() as float
theKnots = #()
if t <= 0 do
(
for Sp = 1 to (numSplines pflowguide) do
for k = 1 to (NumKnots pflowguide Sp) do
append theKnots (getKnotPoint pflowguide Sp k)
for i = 1 to theKnots.count do
(
pCont.AddParticle()
pCont.particleIndex = pCont.NumParticles()
pCont.particleposition = theKnots[i]
)
)
)
)
Note that the script is written for an existing shape named "guide", that mean if you wish to use this script then (A) you need to rename your shape to "guide" or (B) you need to edit this line in the script:
global pflowguide = $guide
That's all. Cheers!
No comments:
Post a Comment
Thanks for your comment