-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTest_RemovePlannarVerts.ms
More file actions
88 lines (84 loc) · 2.46 KB
/
Copy pathTest_RemovePlannarVerts.ms
File metadata and controls
88 lines (84 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
fn VertIsOnBoundary obj v testMatIDs:false=
(
edges = polyop.GetEdgesUsingVert obj v
--format "vert % has % edges\n" v edges.numberSet
isBoundary = false
for e in edges while isBoundary == false do
(
faces = polyop.GetFacesUsingEdge obj e
--format "edge % has % faces\n" e faces.numberSet
if faces.numberSet == 1 then isBoundary = true
else
(
matIDs = #{}
for f in faces do
(
matIDs[polyop.GetFaceMatID obj f] = true
--format "\tface % has matID of %\n" f (polyop.GetFaceMatID obj f)
)
if matIDs.numberSet > 1 then isBoundary = true
)
)
if testMatIDs then
(
local vToFind = v-- (for v in (polyop.GetVertSelection obj) collect v)[1]
if classof v == bitarray then vToFind = (v as array)[1]
local mapVerts = #{}
for f in (polyop.getFacesUsingVert obj vToFind) do
(
local polyFace = polyOp.getFaceVerts obj f
local mapFace = polyOp.getMapFace obj 1 f
local mapVert = mapFace[finditem polyFace vToFind]
mapVerts[mapVert] = true
)
if mapVerts.numberSet > 1 then isBoundary = true
)
--format "vert % of % has % edges with % reverse edges\n" v obj.name edges.numberSet reverseEdges.numberSet
return isBoundary
)
fn CleanUpPlanarVerts obj vertList threshold:1=
(
numVerts = getNumVerts obj
vertsToRemove = #{}
--format "Cleaning up % from % to %\n" obj.name startVert endVert
for v in vertList do
(
facesUsingVert = polyop.getFacesUsingVert obj v
if facesUsingVert.numberSet < 3 or (VertIsOnBoundary obj v) then
(
bndry = "not on bounday"
if VertIsOnBoundary obj v then bndry = "on boundary"
--format "Vert % used by % faces and is %\n" v facesUsingVert.numberSet bndry
continue
)
--format "vert: %\n" v
normalsDot = 0
faceCount = 0
lastNormal = undefined
for f in facesUsingVert do
(
faceCount += 1
normal = polyop.getFaceNormal obj f
--format "\tf#%:\t\tnormal %\n" f normal
if lastNormal != undefined then
(
currentDot = dot lastNormal normal
--format "\t\t\tnDotln %\n" currentDot
normalsDot += currentDot
)
lastNormal = normal
)
normalsDot = normalsDot / (faceCount-1)
--format "average dot: %\n=========================\n" normalsDot
if normalsDot >= threshold then vertsToRemove[v] = true
)
polyop.setVertSelection obj vertsToRemove
select obj
subobjectlevel = 1
obj.Remove()
)
fn CleanUpPlannerVertsFromSelectedFaces obj threshold:1 =
(
verts = polyop.getVertsUsingFace obj (polyop.getFaceSelection obj)
CleanUpPlanarVerts obj verts threshold:threshold
)