[Closed] triangulate spline
Hi there,
a collegue of mine wants to ‘triangulate’ his splines in order to be able to use a surface modifier on them. What he needs, is a script that creates new lines between points 1 and 3, 3 and 5 and so on (basically all odd numbers). As far as i could figure out a script should more or less look like the following:
for i = 0 to numknots
(
if i % 2
()
else
(
splineOps.startcreateLine i, (i+2)
)
)
Now this script obviously doesn’t work (otherwise i wouldnt be here :D). But i cannot figure out how to actually use the startcreateLine with the knot number.
Also: How can i use the if statement to check whether “if i % 2” is NOT true or is 1 etc. (because then its an odd number) without doing the above work around? (dul question, i know)
Any help would be much appreciated.
ok, i figured it out on my own, mostly.
The Script now looks like the following:
for s = 1 to (numSplines $) do
(
for i = 1 to numKnots $ s - 2 do
(
if (mod i 2 == 1) then
(
knt1 = getKnotPoint $ s i
(
knt2 = getKnotPoint $ s (i+2)
)
--newSpline = drawLineBetweenTwoPoints knt1 knt2
splineOps.startCreateLine knt1 knt2
)
)
)
updateshape $
if I execute the script with the line “new spline = drawLine…” on and spline ops off, it Does the correct lines between the necessary points. But they are new lines.
If i use it with “splineOps.startCreateLine knt1 knt1” it gives the following message
-- Error occurred in i loop; filename: C:\Program Files\Autodesk\3ds Max Design 2011\ui\MacroScripts\; position: 273; line: 12
-- Frame:
-- i: 1
-- knt2: [-51.8349,-1.99843e-006,45.7187]
-- knt1: [49.6942,-4.61175e-007,10.5505]
-- called in s loop; filename: C:\Program Files\Autodesk\3ds Max Design 2011\ui\MacroScripts\; position: 282; line: 14
-- Frame:
-- s: 1
-- Argument count error: startCreateLine wanted 1, got 2
OK
Any ideas how I can create that spline between the points?
What about this:
num_splines = numSplines $
num_new_splines = num_splines + 1
for s = 1 to num_splines do
(
for i = 1 to numKnots $ s - 2 by 2 do
(
knt1 = getKnotPoint $ s i
knt2 = getKnotPoint $ s (i+2)
addNewSpline $
addKnot $ num_new_splines #corner #line knt1
addKnot $ num_new_splines #corner #line knt2
num_new_splines += 1
)
)
updateshape $
works perfect, thank you! the “by 2” is a nice way to get rid of the modulo operator
But to learn something from this as well: what ecactly is the num_new_splines doing?
Okay, I misunderstood once again :surprised Another try, hopefully I got it right this time:
num_splines = numSplines $
num_new_splines = num_splines + 1
for s = 1 to num_splines do
(
local first_pos = getKnotPoint $ s 1
local new_spline = SplineShape pos:first_pos
addNewSpline new_spline
addKnot new_spline 1 #corner #line first_pos
for i = 3 to numKnots $ s - 2 by 2 do
(
knt1 = getKnotPoint $ s i
knt2 = getKnotPoint $ s (i+2)
addKnot new_spline 1 #corner #line knt1
addKnot new_spline 1 #corner #line knt2
)
)
updateShape $
the first version actually worked already
it created the splines form point 1 to 3, 3 to 5. And even with a spline with more points, it worked.
In the first case it counts new splines because when you add knots to a spline you need to know its index. In the second one it shouldn’t even be there, just a remnant from the previous script – every spline that’s being accessed there is a new spline so the element index is always 1.
After rereading your post I thought you wanted to have them as new splines, just connected. Anyway, whichever you choose, I’m glad that it works for you