-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
210 lines (181 loc) · 7.29 KB
/
__init__.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8-80 compliant>
bl_info = {
"name": "Mesh Healing Tools",
"author": "Tuomo Keskitalo",
"blender": (2, 80, 0),
"location": "3D View > Sidebar",
"description": "Utilities for healing arbitrary polygon surface meshes",
"warning": "Experimental",
"wiki_url": "https://github.com/tkeskita/mesh_heal",
"tracker_url": "https://github.com/tkeskita/mesh_heal/issues",
"support": 'COMMUNITY',
"category": "Mesh"
}
if "bpy" in locals():
import importlib
importlib.reload(op_norms)
importlib.reload(op_clean_mesh)
importlib.reload(op_fill_holes)
importlib.reload(op_sew)
importlib.reload(op_delete_overlap)
importlib.reload(op_merge_overlapping_edges)
else:
import bpy
from . import (
op_norms,
op_clean_mesh,
op_fill_holes,
op_sew,
op_delete_overlap,
op_merge_overlapping_edges,
)
from .op_gen import *
class MeshHealSettings(bpy.types.PropertyGroup):
vert_merge_distance: bpy.props.FloatProperty(
name="Vertex Merge Distance",
description="Maximum distance for merging closeby vertices",
default=0.001,
precision=5,
min=0.0, max=float_info.max
)
sew_ratio_threshold: bpy.props.FloatProperty(
name="Max Sew Ratio",
description="Maximum allowed distance ratio for sewing",
default=0.3,
precision=5,
min=0.001, max=1.0
)
max_abs_twist_angle: bpy.props.FloatProperty(
name="Twist Angle",
description="Maximum allowed angle (in degrees) for twisted faces",
default=3.0,
min=0.0, max=90.0
)
max_abs_edge_overlap_angle: bpy.props.FloatProperty(
name="Edge Overlap Angle",
description="Maximum allowed angle (in degrees) for determining edge overlapping",
default=1.0,
min=0.0, max=90.0
)
class MeshHeal_PT_object_mode(bpy.types.Panel):
"""Mesh Heal tool bar panel in object mode"""
bl_label = "Mesh Heal (MH)"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Mesh Heal"
bl_idname = "VIEW3D_PT_MeshHeal_Object"
bl_context = "objectmode"
@classmethod
def poll(cls, context):
obj = context.active_object
return obj and obj.type == 'MESH' and context.mode == 'OBJECT'
def draw(self, context):
mesh_heal = context.scene.mesh_heal
layout = self.layout
col = layout.column()
rowsub = col.row(align=True)
rowsub.operator("mesh.mesh_heal_simple_clean", text="Simple Clean")
rowsub.prop(mesh_heal, "vert_merge_distance", text="Distance")
row = layout.row()
row.operator("mesh.mesh_heal_delete_overlap", \
text="Delete Overlapping Neighbor Faces")
col = layout.column()
rowsub = col.row(align=True)
rowsub.operator("mesh.mesh_heal_sew", text="Sew Mesh")
rowsub.prop(mesh_heal, "sew_ratio_threshold", text="Ratio")
col = layout.column()
rowsub = col.row(align=True)
rowsub.operator("mesh.mesh_heal_triangulate_twisted", text="Triangulate Twists")
rowsub.prop(mesh_heal, "max_abs_twist_angle", text="Angle")
row = layout.row()
row.operator("mesh.mesh_heal_clean_and_patch", text="Clean and Patch")
row = layout.row()
row.operator("mesh.mesh_heal_fill_holes_sharp", text="Fill Holes (Sharp)")
col = layout.column()
rowsub = col.row(align=True)
rowsub.operator("mesh.mesh_heal_merge_overlapping_edges", text="Merge Overlapping Edges")
rowsub.prop(mesh_heal, "max_abs_edge_overlap_angle", text="Angle")
row = layout.row()
row.operator("mesh.mesh_heal_recalc_norms", text="MH Recalc Norms")
class MeshHeal_PT_edit_mode(bpy.types.Panel):
"""Mesh Heal tool bar panel in edit mode"""
bl_label = "Mesh Heal (MH)"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "Mesh Heal"
bl_idname = "VIEW3D_PT_MeshHeal_Edit"
bl_context = "mesh_edit"
@classmethod
def poll(cls, context):
obj = context.active_object
return obj and obj.type == 'MESH' and context.mode == 'EDIT_MESH'
def draw(self, context):
layout = self.layout
box = layout.box()
col = box.column(align=True)
col.label(text="TODO: Make", icon='ERROR')
col.label(text="available in edit mode")
# def mesh_heal_addition_in_edit_mode(self, context):
# """Example of addition to existing panel"""
# user_prefs = context.user_preferences
# addon_prefs = user_prefs.addons[__package__].preferences
# layout = self.layout
# box = layout.box()
# col = box.column(align=True)
# col.label("Mesh Heal is not")
# col.label("available in edit mode")
# # Then add this to register function:
# bpy.types.MESH_PT_print3d_mesh.append(mesh_heal_addition_in_edit_mode)
# Registration
classes = (
MeshHeal_PT_object_mode,
MeshHeal_PT_edit_mode,
op_norms.MeshHealRecalcNormsOperator,
op_clean_mesh.MeshHealCleanAndPatchOperator,
op_clean_mesh.MeshHealSimpleCleanOperator,
op_clean_mesh.MeshHealTriangulateTwistedFacesOperator,
op_fill_holes.MeshHealFillHolesSharpOperator,
op_sew.MeshHealSewOperator,
op_delete_overlap.MeshHealDeleteOverlapOperator,
op_merge_overlapping_edges.MergeOverlappingEdgesOperator,
MeshHealSettings,
)
def menu_func(self, context):
self.layout.operator(op_norms.MeshHealRecalcNormsOperator.bl_idname)
self.layout.operator(op_clean_mesh.MeshHealCleanAndPatchOperator.bl_idname)
self.layout.operator(op_clean_mesh.MeshHealSimpleCleanOperator.bl_idname)
self.layout.operator(op_clean_mesh.MeshHealTriangulateTwistedFacesOperator.bl_idname)
self.layout.operator(op_fill_holes.MeshHealFillHolesSharpOperator.bl_idname)
self.layout.operator(op_sew.MeshHealSewOperator.bl_idname)
self.layout.operator(op_delete_overlap.MeshHealDeleteOverlapOperator.bl_idname)
self.layout.operator(op_merge_overlapping_edges.MergeOverlappingEdgesOperator.bl_idname)
def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Scene.mesh_heal = \
bpy.props.PointerProperty(type = MeshHealSettings)
if "VIEW3D_MT_object_cleanup" in dir(bpy.types):
bpy.types.VIEW3D_MT_object_cleanup.append(menu_func)
def unregister():
if "VIEW3D_MT_object_cleanup" in dir(bpy.types):
bpy.types.VIEW3D_MT_object_cleanup.remove(menu_func)
for cls in classes:
bpy.utils.unregister_class(cls)
del bpy.types.Scene.mesh_heal