Last active
January 24, 2026 17:13
-
-
Save Swordslayer/990adcd091cf08b115e29241b7b4c1eb to your computer and use it in GitHub Desktop.
Select edges across vertices with multiple explicit normals. For imported CAD geometry, these usually correspond to the original iso lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn selectNormalsBorderEdges obj includeOpenEdges:on = if isKindOf obj Editable_mesh do | |
| ( | |
| local iGlobal = (dotNetClass "Autodesk.Max.GlobalInterface").Instance | |
| local mesh = (iGlobal.TriObject.Marshal (refs.getAddr obj.baseObject)).Mesh_ | |
| local edgeList = try iGlobal.AdjEdgeList.Create mesh off catch iGlobal.AdjEdgeList.Create mesh | |
| local borderEdges = #{}; borderEdges.count = 3 * mesh.NumFaces | |
| local faceVerts = meshOp.getFaces obj #all | |
| local normals = mesh.SpecifiedNormals | |
| local numEdges = edgeList.Edges.Count | |
| local edges = edgeList.Edges.Item | |
| local step = numEdges / 100 | |
| if numEdges > 1000 do progressStart "Selecting Edges" | |
| for idx = 0 to numEdges - 1 do | |
| ( | |
| if numEdges > 1000 and mod idx step == 0 do | |
| progressUpdate (idx * 100. / numEdges) | |
| local edge = edges[idx] | |
| local edgeVerts = edge.V | |
| local edgeFaces = try edge.F catch #((getProperty edge #F asDotNetObject:on).Get 0, undefined) -- may contain 0xffffffff for 'undefined' which throws when autoconverting to int | |
| local face = edgeFaces[1], reverseFace = edgeFaces[2] | |
| local faceEdgeIdx = (mesh.GetFace face).GetEdgeIndex edgeVerts[1] edgeVerts[2] | |
| local reverseFaceEdgeIdx = if reverseFace != undefined then (mesh.GetFace reverseFace).GetEdgeIndex edgeVerts[1] edgeVerts[2] | |
| if reverseFace == undefined then (if includeOpenEdges do (append borderEdges (face * 3 + faceEdgeIdx + 1))) | |
| else if normals.GetNormalIndex face faceEdgeIdx != normals.GetNormalIndex reverseFace (mod (reverseFaceEdgeIdx + 1) 3) \ | |
| and normals.GetNormalIndex face (mod (faceEdgeIdx + 1) 3) != normals.GetNormalIndex reverseFace reverseFaceEdgeIdx do | |
| ( | |
| append borderEdges (face * 3 + faceEdgeIdx + 1) | |
| append borderEdges (reverseFace * 3 + reverseFaceEdgeIdx + 1) | |
| ) | |
| ) | |
| if numEdges > 1000 do progressEnd() | |
| setEdgeSelection obj borderEdges | |
| ) | |
| selectNormalsBorderEdges $ includeOpenEdges:off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment