Forum Groups
  All forums
    Help & Feedback
      Work in progress
      Finished Art
      Non-Max related

Featured Threads
  inspiration alert!!!
(37 replies)
  Indespensible MaxScripts, Plugins and 3rd Party Tools
(37 replies)
  The allmighty FREE Resources Thread !
(17 replies)
  spam alert!!!
(4886 replies)
  Maxforums member photo gallery index
(114 replies)
  Maxforums Member Tutorials
(89 replies)
  three cheers to maxforums...
(240 replies)
  101 Things you didnt know in Max...
(198 replies)
  A Face tutorial from MDB101 :D
(95 replies) Members Gallery
(516 replies)
(637 replies)
  Dub's Maxscript Tutorial Index
(119 replies)

Maxunderground news unavailable

Quick Question - SplineOps.Divide
show user profile  ccampbell
Kind of embarrassed to ask but.... When i try to divide to spline segments using the script below in a button it doesn't work. if i execute it as a selection it works just fine... not sure whats up. I can only get 1 of the 2 splines to divide. the script completes with no errors.

on divideSpline pressed do

Select $Shape002 -- select spline1
max modify mode -- switch to modify panel in UI
subobjectlevel = 2 -- switch to segment suboject mode
for L = 1 to numsplines $ do -- master loop script incase more than 1 spline in the shape.
for i = 1 to numsegments $ L do -- select all segments loop
SetSegSelection $ L #(i) keep:true
)--enbd loop inner scope
)--end loop master scope
updateshape $
splineops.divide $
splineops.divide $
splineops.divide $
Deselect $Shape002


Select $Shape003
max modify mode
subobjectlevel = 2
for L = 1 to numsplines $ do
for i = 1 to numsegments $ L do
SetSegSelection $ L #(i) keep:true
)--enbd loop inner scope
)--end loop master scope
updateshape $
splineops.divide $
splineops.divide $
splineops.divide $
Deselect $Shape003

$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};

read 908 times
2/1/2012 11:19:58 PM (last edit: 2/1/2012 11:22:45 PM)
show user profile  ccampbell
i suppose this is just a crappy way of doing this. i am going to try doing it manually instead of quering the UI.

Does anybody know how to interpolate segments so that i can find the center of every segment?

$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};

read 900 times
2/1/2012 11:47:03 PM (last edit: 2/2/2012 12:04:30 AM)
show user profile  Dub.
I'd say it's probably because once you divide the segment, it changes the whole count of the spline segments that you are iterating across.

You might have to work backwards.

for i=(numsegments $ L) to 1 by -1 do ( xxxxxxxxxxxxxxxxxxxxxxxxxx )

read 882 times
2/2/2012 2:52:07 AM (last edit: 2/2/2012 2:52:07 AM)
show user profile  Garp
What Dub says.
Plus use the splineShape methods - like subdivideSegment() - instead of the splineOps interface. It's way faster.

read 877 times
2/2/2012 4:34:17 AM (last edit: 2/2/2012 4:34:17 AM)
show user profile  ccampbell
@DUB - Thanks a lot definitely going to help with the issue.
@Garp - Problem is using the subdivide op or refine ops appears to change the spline path significantly. I need to keep the same spline shape without changes. Using divide i can perform the command simultaneously to all segments intern keeping the spline shape almost identical where the other 2 i have to loop through and apply the op one segment at a time which is significantly changing my spline by the time i reach the end of the loop i have a completely different shape. Ive included an image below showing all 3 operations in action.

What i have been working on in the mean time is calculating the center of each segment and creating and adding a new knot at that location in the spline. this seems to be working ok so far but I'm still having some trouble which I'm attributing to my just missing something using path interp.


$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};

read 863 times
2/2/2012 10:43:17 PM (last edit: 2/2/2012 10:47:44 PM)
show user profile  Garp
I get something different.
If the vertices are set to smooth, all three methods deform the segment in an identical way.
With verts set to bezier, there is no deformation.
In both cases, the three resulting splines are identical.

Try the following on splines with verts set to either corner or bezier. It should work fine.

read 850 times
2/2/2012 11:13:28 PM (last edit: 2/2/2012 11:16:57 PM)
show user profile  ccampbell
@Garp - Thanks for taking the time to write that up. Check out the link I posted below. The image shows the before and after effect of your script on my splines. I 1) screen capped 2)used the script and 3) screen capped again. and I copy pasted your script into my editor. I then superimposed the 2 images to show the change.

You can see that there is a change in the shape of the spline. most pronouced over larger segments and splines with fewer knots. One thing you mentioned before and i had also noticed was that the newly create points on the spline are bezier and i am using smooth knot interpolation. this could be attributing to the spline path changing shape.

I converted my spline knots to bezier and then ran the subdivideSegments and refineSegments ops and wha-La the spline maintains its shape perfectly! the spline shape is maintained.

The problem here is you cant go back to smooth splines otherwise it warps just as it did before(not sure if its an identical effect as when running the subdivide/refine segment on the spline with smooth knots). Luckily in this case i dont need to revert back to smooth after the process but it does present an interesting challenge i think.


Tested the difference between running the script on a spline with smooth knots and a spline with bezier knots.

Test:1 Smooth - Smooth knot Spline > GarpScript > convert all knots back to smooth
Result: huge deformations in spline path.

Test2 Bezier - Convertknots to Bezier before script> GarpScript > Convert all knots back to smooth
Results: Minute but still noticeable changes in path.

$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};

read 842 times
2/2/2012 11:41:04 PM (last edit: 2/2/2012 11:54:18 PM)
show user profile  Garp
The smooth state is a form of bezier. I mean internally there are the same bezier handles to define the curvature. The difference is that it's dealt with directly by max, which readjusts the handles as it sees fit. So with smooth verts, it computes the new verts (and their handles) correctly, but they screws them by 'refitting' them according to distance and curvature.
If you look at the doc, both the subdivideSegment() and refineSegmen() method are highly precise.
If you're using it to cut segments only in half, I'd recommend subdivideSegment(). I made a few mesurements on 1000 splines x 15 sub-splines x 3 segments (with bezier verts) and on average subdivideSegment() is a little more that 3 times faster than refineSegment().

read 837 times
2/2/2012 11:49:59 PM (last edit: 2/2/2012 11:51:56 PM)
show user profile  ccampbell
@Garp - Thanks a lot for the input and the time spent! I really honestly appreciate it! So i used a combined method of your input and some observation and found something that really works great. Ive included the code below. Its just raw code.

Its definately a simple solution but it took 2 day's to get to it...This is just part of a larger on going Script i'm working on at the office. So sometimes i have to have some very specific results. in this case i think it should work perfectly.

Thank you Both, Garp and Dub for all your expertise!

Refine Spline Segments
-- Get Spline knot count and Segment Count.
Knotcount = numknots $
SegCount = numsegments $ 1

--CONVERT ALL KNOTS TO BEZIER to maintain the orignal shape.
for i = 1 to knotcount do
setKnotType $ 1 i #Bezier

for i = Segcount to 1 by -1 do
SubdivideSegment $ 1 i 2
updateshape $

--CONVERT ALL POINTS BACK TO SMOOTH INTERPOLATION NOTE: spline shape may slightly differ from the original. Dependent on knot density.
for i = 1 to knotcount do
setKnotType $ 1 i #smooth
updateshape $

$Entrepreneur = if((Designer + Engineer)*Programmer){Problem Solver};

read 831 times
2/3/2012 12:53:22 AM (last edit: 2/3/2012 12:55:42 AM)
#Maxforums IRC
Open chat window