7
Tooltip: 'Clean unused data from all selected meshes'
10
__author__ = "Campbell Barton"
11
__url__ = ("blender", "elysiun")
12
__version__ = "1.1 04/25/04"
15
This script cleans specific data from all selected meshes.
19
Select the meshes to be cleaned and run this script. A pop-up will ask
20
you what you want to remove:
22
- Free standing vertices;<br>
23
- Edges that are not part of any face;<br>
24
- Edges below a threshold length;<br>
25
- Faces below a threshold area;<br>
28
After choosing one of the above alternatives, if your choice requires a
29
threshold value you'll be prompted with a number pop-up to set it.
33
# $Id: clean_mesh.py,v 1.3 2004/12/01 04:49:04 ianwill Exp $
35
# --------------------------------------------------------------------------
36
# Mesh Cleaner 1.0 By Campbell Barton (AKA Ideasman)
37
# --------------------------------------------------------------------------
38
# ***** BEGIN GPL LICENSE BLOCK *****
40
# This program is free software; you can redistribute it and/or
41
# modify it under the terms of the GNU General Public License
42
# as published by the Free Software Foundation; either version 2
43
# of the License, or (at your option) any later version.
45
# This program is distributed in the hope that it will be useful,
46
# but WITHOUT ANY WARRANTY; without even the implied warranty of
47
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48
# GNU General Public License for more details.
50
# You should have received a copy of the GNU General Public License
51
# along with this program; if not, write to the Free Software Foundation,
52
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
54
# ***** END GPL LICENCE BLOCK *****
55
# --------------------------------------------------------------------------
58
# Made by Ideasman/Campbell 2004/04/25 - ideasman@linuxmail.org
64
time1 = Blender.sys.time()
66
VRemNum = ERemNum = FRemNum = 0 # Remember for statistics
72
def compare(f1, f2, limit):
73
if f1 + limit > f2 and f1 - limit < f2:
78
return Mathutils.Vector([v1[0]-v2[0], v1[1] - v2[1], v1[2] - v2[2]]).length
80
def triArea2D(v1, v2, v3):
85
return 0.25 * sqrt(p*(p-2*e1)*(p-2*e2)*(p-2*e3))
88
#=============================#
89
# Blender functions/shortcuts #
90
#=============================#
92
Draw.PupMenu('ERROR%t|'+str)
95
return Draw.PupFloatInput(text, 0.001, 0.0, 1.0, 0.1, 3)
99
return triArea2D(f.v[0].co, f.v[1].co, f.v[2].co) + triArea2D(f.v[0].co, f.v[2].co, f.v[3].co)
101
return triArea2D(f.v[0].co, f.v[1].co, f.v[2].co)
108
def delFreeVert(mesh):
110
usedList = eval('[' + ('False,' * len(mesh.verts) )+ ']')
111
# Now tag verts that areused
114
usedList[mesh.verts.index(v)] = True
116
for bool in usedList:
128
while fIdx < len(mesh.faces):
129
if len(mesh.faces[fIdx].v) == 2:
136
def delEdgeLen(mesh, limit):
139
while fIdx < len(mesh.faces):
140
if len(mesh.faces[fIdx].v) == 2:
141
if measure(mesh.faces[fIdx].v[0].co, mesh.faces[fIdx].v[1].co) <= limit:
148
def delFaceArea(mesh, limit):
151
while fIdx < len(mesh.faces):
152
if len(mesh.faces[fIdx].v) > 2:
153
if faceArea(mesh.faces[fIdx]) <= limit:
161
#====================#
163
#====================#
165
is_editmode = Window.EditMode()
166
if is_editmode: Window.EditMode(0)
169
if len(Object.GetSelected()) > 0:
170
for ob in Object.GetSelected():
171
if ob.getType() == 'Mesh':
172
meshList.append(ob.getData())
175
#====================================#
176
# Popup menu to select the functions #
177
#====================================#
178
if len(meshList) == 0:
179
error('no meshes in selection')
181
method = Draw.PupMenu(\
182
'Clean Mesh, Remove...%t|\
183
Verts: free standing|\
184
Edges: not in a face|\
185
Edges: below a length|\
186
Faces: below an area|%l|\
190
limit = getLimit('threshold: ')
193
for mesh in meshList:
199
delEdgeLen(mesh, limit)
201
delFaceArea(mesh, limit)
202
elif method == 6: # All of them
203
delFaceArea(mesh, limit)
209
print 'mesh cleanup time',Blender.sys.time() - time1
210
if is_editmode: Window.EditMode(1)
213
Draw.PupMenu('Removed from ' + str(len(meshList)) +' Mesh(es)%t|' + 'Verts:' + str(VRemNum) + ' Edges:' + str(ERemNum) + ' Faces:' + str(FRemNum))