Pages

Friday, August 13, 2010

Base tips with getKnotPoint

At the forum topic into Area.Autodesk.com I see a question related to MAXScript function getKnotPoint which return the coordinate of knot in shape. The topic start with a birth script operator but is more closer to the getKnotPoint usage, which is come in use for any operations with shapes via MAXScripts. The birth script operator itself is a modified version of the old (but nice) Bobo's example that position each particle on a vertices of poly or mesh, and the modified version intended to do the same but on knot point of a shape. So, the getKnotPoint required 3 arguments - shape, spline index, knot index. That mean here needed double loop - for each knot in each spline. If the shape has only 1 spline like the Circle for example, then the single loop is enough --
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