[Closed] Refine Splineshape usage?
It’s the end of a long day and my brain is fried but I’m hoping for one last bit of help before I’m finally finished.
I’m trying to insert vertices (knots) along a spline using the refine modifier. Yes, this is indeed an editable spline (not a line) and yet, I don’t have it selected in the viewport (because Maxscript apparently can’t modify such an object) but I can’t seem to make it work. I don’t get any errors, I can even do it interactively, but it just doesn’t add any knots.
Here’s what I’m trying (once again, on an editible spline that isn’t selected):
Myline = selectline.object
for s = 1 to (numSplines Myline) do
(
for k = 1 to (numSegments Myline s) do
(
for j = 0.0 to 1.0 by .2 do
(
refineSegment Myline s k j
) – end j
) – end k
) – end s
updateshape Myline
Anyone have any clue as to why this doesn’t work? (Or some other routine they’ve written to refine a splineshape?) I just need to get about five more vertices evenly spaced between any existing vertices without altering the shape.
Iterating through numSegments Myline s will not work, since the refineSegments function causes the number of segments to change each time you call it. This also affects the path parameter (0.0-1.0) at which a new knot should be inserted. Here’s an example function which will insert a specified number of knots at even intervals:
(
/*
RefineShape function
07-11-2007 Martijn van Herk
purpose: inserts <count> knots into each segment of shape <obj>
NOTE: for some reason, scripted shape operations cannot be undone,
so make sure you save your work before running this script.
*/
fn RefineShape obj count =
(
-- get the number of splines in this shape
local SplineCount = numSplines obj
-- loop through splines
for spl = 1 to SplineCount do
(
-- start at first segment of spline
seg = 1
-- loop through segments
while seg <= (numSegments obj spl) do
(
-- insert the knots
for j = count to 1 by -1 do
(
-- note that the path param (last parameter of refineSegment function)
-- is based on variable j (the insert counter). Using a fixed value
-- for this would insert the knots at irregular intervals.
refineSegment obj spl seg (1. / (j + 1))
-- numSegments changes each time 'refineSegment' is called!
-- so you need to make sure the same segment doesn't get divided
-- more than once.
seg += 1
) -- end j
-- next segment
seg += 1
) -- end seg
) -- end spl
-- update the shape to reflect changes
updateShape obj
)
-- insert 5 knots in all segments of $Line01
RefineShape $Line01 5
)
The attached image shows an example of a single segment being divided into 6 segments by inserting 5 knots.
Cheers,
Martijn
Hi,
This could also be done using the subdividesegment command which would avoid Martijns funky maths.
Remember, both of these methods will take into account the in and out vectors of the knots, so you may not get even length segments.
Josh.
fn dividesegment spl div=
(
for i=1 to (numsplines spl) do
(
for j=(numSegments spl i) to 1 by-1 do
subdividesegment spl i j div
)
updateshape spl
)
dividesegment $ 5
(not as nice looking as Martijns either < : )
I just started modifying Mike’s script without looking for any alternatives, which seems to be a bad habbit of mine Thanks for the heads up!
Martijn
Thanks, guys! To both of you, truly I’ve learned something very important (and both of them work a treat).
I could of kicked myself for not realizing that as I added knots the segments would increase. Duh.
Hey Martijn I like you solution! more than one way to skin a cat.
Cheers to Mike!
J. < :