macroScript patchSmooth category:"Comet Cartoons" toolTip:"patchSmooth: Select Editable Patch object(s), and tangents go smooth" Icon:#("Max_Edit_Modifiers",2) ( -- patchSmooth.mcr -- Given an Editable Patch object in the current selection, -- this will take all the tangent vector handles and smooth them -- to be nice. -- -- Michael B. Comet - comet@comet-cartoons.com - http://www.comet-cartoons.com/ -- -- Version 1.00 - 09/20/01 - comet@comet-cartoons.com -- -- -- undo on ( setWaitCursor(); for obj in selection do ( if (classOf obj != Editable_Patch) then ( format "patchSmooth WARNING: Skipping: %, not an Editable Patch object!\n" obj.name; continue; ) format "patchSmooth: Smoothing %\n" obj.name; numVerts = patch.getNumVerts obj; for i in 1 to numVerts do ( -- which vectors are used? vecArray = patch.getVertVecs obj i; -- format "i=% vecArray[]=%\n" i vecArray; -- Now get vert position vPos = patch.getVert obj i; patch.changeVertType obj i #corner; -- Get edges attached to this vert edges = patch.getVertEdges obj i; -- Get patches attached to this vert vPats = patch.getVertPatches obj i; n = [0,0,0]; -- reset Normal vector for p in 1 to vPats.count do ( pN = patch.patchNormal obj vPats[p]; n = n + pN; ) -- end of patch loop n = normalize n; for e = 1 to edges.count do ( -- get the other vert along this edge... vi2 = patch.getEdgeVert1 obj edges[e]; if ((vi2+1) == i) then -- make sure it's not the one we're looking at! vi2 = patch.getEdgeVert2 obj edges[e]; vi2 += 1; -- BUG IN MAX...increment by one so it is 1 based not 0 based! vPos2 = patch.getVert obj vi2; -- format "e=% vi2=% vPos2=%\n" e vi2 vPos2; -- Now get vector index based on the edge.... -- Make sure it's really for this vtx, and not -- one pointing the opposite way down the edge -- for the other vert on the edge. veci = patch.getEdgeVec12 obj edges[e]; if (findItem vecArray (veci+1) == 0) then veci = patch.getEdgeVec21 obj edges[e]; veci += 1; -- BUG IN MAX...increment by one so it is 1 based not 0 based! -- At this point we have the normal for the point, -- the vector pointing down an edge and the point on that edge -- and the position of that point. v2 = vPos2 - vPos; len = length v2; v2 = normalize v2; c = cross n v2; -- get a vector perp to both the normal and the edge. newV = cross c n; -- now get one back towards the point but now along that -- normal plane... newV = normalize newV; -- normalize newV = newV * (len*0.33); -- and set length to smaller than dist to point on edge newV = vPos + newV; patch.setVec obj veci newV; -- and store vector! ) -- end of Edge loop -- Now do "smooth" version patch.changeVertTYpe obj i #coplanar; -- Back to nice and linked ) -- end of num verts -- make sure topo changes are kept! patch.updatePatchNormals obj; patch.update obj; update obj.mesh; ) -- end of obj loop setArrowCursor(); ) -- end of undo ) -- end of Macroscript