--------------------------------------------------------------------------- -- Nurbs 2 Spline Script -- -- -- -- Alexander Esppeschit Bicalho -- -- Kinetix Training Specialist -- -- abicalho@origamy.com.br -- -- http://www.origamy.com.br -- --------------------------------------------------------------------------- -- -- This script converts NURBS Curves to Spline Shapes -- Options: - Convert only selected curves -- - Define the number of vertices to be created in the curve -- Known bug: Due to any rounding problems within MAXScript, the last vertex is offset 0.001 units. -- Version 2.1: -- Added a check to close the Shape if the original NURBS Curve was closed, per request of Oleg Kyrylenko macroscript Nurbs_2_Spline category:"Tools" tooltip:"NURBS 2 Spline Converter" icon:#("Bonus",1) ( global NTOSPLINE Rollout NTOSPLINE "Parameters" ( -- Function to check if the selected object is a NURBS Curve or Surface -- Compatible with MAX 2.5 and 3.0 fn check_for_nurbs obj = ( return_value = false if classof obj == CV_Curve then return_value = true -- MAX 2.5 objeccts if classof obj == Point_Curve then return_value = true if classof obj == CV_Surf then return_value = true if classof obj == Point_Surf then return_value = true if classof obj == NURBSCurveShape then return_value = true -- MAX 3.0 objects if classof obj == NURBSSurf then return_value = true return_value ) -- User Interface group "Nurbs 2 Spline Converter" ( pickbutton sobj "Pick NURBS Object" filter:check_for_nurbs checkbox sel_only "Selected Only" checked:false align:#center spinner precision "# of vertices:" type:#integer range:[3,1000,50] enabled:false ) label ab2 "Nurbs 2 Spline Script" label abt03 "Alexander Esppeschit Bicalho" label abt05 "Discreet Training Specialist" label abt02 "abicalho@origamy.com.br" label abt04 "http://www.origamy.com.br" -- Function to check if the NURBS Object is a Curve fn check_for_curves obj = ( go_on = false if (classof obj == NURBSCVCurve) then go_on = true if (classof obj == NURBSPointCurve) then go_on = true if (classof obj == NURBSBlendCurve) then go_on = true if (classof obj == NURBSOffsetCurve) then go_on = true if (classof obj == NURBSXFormCurve) then go_on = true if (classof obj == NURBSMirrorCurve) then go_on = true if (classof obj == NURBSFilletCurve) then go_on = true if (classof obj == NURBSChamferCurve) then go_on = true if (classof obj == NURBSSurfaceIntersectionCurve) then go_on = true if (classof obj == NURBSProjectVectorCurve) then go_on = true if (classof obj == NURBSProjectNormalCurve) then go_on = true if (classof obj == NURBSSurfSurfIntersectionCurve) then go_on = true if (classof obj == NURBSIsoCurve) then go_on = true if (classof obj == NURBSSurfaceNormalCurve) then go_on = true if (classof obj == NURBSCurveOnSurface) then go_on = true if (classof obj == NURBSPointCurveonsurface) then go_on = true if (classof obj == NURBSSurfaceEdgeCurve) then go_on = true go_on ) -- When a NURBS Object is picked, the script starts working on sobj picked obj do ( precision.enabled = true x = obj xrot = x.rotation xsc = x.scale xpos = x.pos -- Getnurbsset command allows the script to get sub-object information a = getnurbsset x #relational b = #() c = #() cnt = 0 n = a.numobjects cnt = 0 Progressstart "Converting curves to Splines" for j in 1 to n do ( progressupdate ((j/n*100) as integer) go_on = check_for_curves a[j] if go_on then ( if sel_only.checked then ( if a[j].selected then go_on = true else go_on = false ) ) if go_on then ( -- This is the engine of the script. Basically, the script gets the extents of the curve, -- using the parameterange properties. Then, using evalpos, it reads the XYZ coordinate of -- 50 points (the value stored in the precision spinner) through the curve. Ending, the script -- will create a spline shape with smooth interpolation. maxv = a[j].parameterrangemax minv = a[j].parameterrangemin prec = precision.value start_it = 0 if a[j].isclosed then start_it = 1 for i in start_it to prec do b[i+1] = evalpos a[j] (((maxv-minv-0.002)*i/prec)+minv+0.001) -- if the precision problem is corrected, remove the -0.002 and the +0.001 c[j] = splineshape() addnewspline c[j] for i in start_it to prec do addknot c[j] 1 #smooth #curve b[i+1] if a[j].isclosed then close c[j] 1 Updateshape c[j] cnt = cnt + 1 c[j].rotation = xrot c[j].scale = xsc c[j].pos = xpos ) ) progressend() if cnt > 0 then print ("Converted: " + cnt as string + " Objects") )--end on picked -- When the user changes the precision value, the script will repeat the steps used in the creation and -- will recreate the splines, using the new precision value. on precision changed val do ( n = a.numobjects prec = precision.value for j in 1 to n do ( go_on = check_for_curves a[j] if go_on then ( if sel_only.checked then ( if a[j].selected then go_on = true else go_on = false ) ) if go_on then ( maxv = a[j].parameterrangemax minv = a[j].parameterrangemin c[j].pos = [0,0,0] c[j].rotation = quat 0 0 0 1 c[j].scale = [1,1,1] start_it = 0 if a[j].isclosed then start_it = 1 for i in start_it to prec do b[i+1] = evalpos a[j] (((maxv-minv-0.002)*i/prec)+minv+0.001) -- if the precision problem is corrected, remove the -0.002 and the +0.001 for i in 1 to numKnots c[j] 1 do deleteKnot c[j] 1 1 for i in start_it to prec do addknot c[j] 1 #smooth #curve b[i+1] Updateshape c[j] c[j].rotation = xrot c[j].scale = xsc c[j].pos = xpos ) ) ) ) -- These commands create and open the rollout try(closerolloutfloater n_rollout) -- this option closes the previous rollout, if it exists catch() n_rollout = newrolloutfloater "NURBS 2 Spline" 200 251 addrollout ntospline n_rollout )