1
# ##### BEGIN GPL LICENSE BLOCK #####
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# ##### END GPL LICENSE BLOCK #####
24
class MeshSelectInteriorFaces(bpy.types.Operator):
25
'''Select faces where all edges have more then 2 face users.'''
27
bl_idname = "mesh.faces_select_interior"
28
bl_label = "Select Interior Faces"
29
bl_options = {'REGISTER', 'UNDO'}
31
def poll(self, context):
32
ob = context.active_object
33
return (ob and ob.type == 'MESH')
35
def execute(self, context):
36
ob = context.active_object
37
bpy.ops.mesh.selection_type(type='FACE')
38
is_editmode = (ob.mode == 'EDIT')
40
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
44
face_list = [face for face in mesh.faces]
45
face_edge_keys = [face.edge_keys for face in face_list]
47
edge_face_count = mesh.edge_face_count_dict
49
def test_interior(index):
50
for key in face_edge_keys[index]:
51
if edge_face_count[key] < 3:
55
for index, face in enumerate(face_list):
56
if(test_interior(index)):
62
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
66
class MeshMirrorUV(bpy.types.Operator):
67
'''Copy mirror UV coordinates on the X axis based on a mirrored mesh'''
68
bl_idname = "mesh.faces_miror_uv"
69
bl_label = "Copy Mirrored UV coords"
70
bl_options = {'REGISTER', 'UNDO'}
72
def poll(self, context):
73
ob = context.active_object
74
return (ob and ob.type == 'MESH')
76
def execute(self, context):
77
DIR = 1 # TODO, make an option
79
from mathutils import Vector
81
ob = context.active_object
82
is_editmode = (ob.mode == 'EDIT')
84
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
92
vcos = [v.co.to_tuple(5) for v in mesh.verts]
94
for i, co in enumerate(vcos):
103
#for i, v in enumerate(mesh.verts):
105
for mirror_a, mirror_b in (mirror_gt, mirror_lt), (mirror_lt, mirror_gt):
106
for co, i in mirror_a.items():
107
nco = (-co[0], co[1], co[2])
108
j = mirror_b.get(nco)
113
active_uv_layer = None
114
for lay in mesh.uv_textures:
116
active_uv_layer = lay.data
119
fuvs = [(uv.uv1, uv.uv2, uv.uv3, uv.uv4) for uv in active_uv_layer]
120
fuvs_cpy = [(uv[0].copy(), uv[1].copy(), uv[2].copy(), uv[3].copy()) for uv in fuvs]
123
faces = mesh.faces[:]
125
fuvsel = [(False not in uv.select_uv) for uv in active_uv_layer]
126
fcents = [f.center for f in faces]
130
for i, f in enumerate(faces):
137
for i, f in enumerate(faces):
138
verts = [vmap.get(j) for j in f.verts]
139
if None not in verts:
141
j = mirror_fm.get(tuple(verts))
145
done = [False] * len(faces)
146
for i, j in fmap.items():
148
if not fuvsel[i] or not fuvsel[j]:
150
elif DIR == 0 and fcents[i][0] < 0.0:
152
elif DIR == 1 and fcents[i][0] > 0.0:
159
# get the correct rotation
160
v1 = faces[j].verts[:]
161
v2 = [vmap[k] for k in faces[i].verts[:]]
164
for k in range(len(uv1)):
165
k_map = v1.index(v2[k])
166
uv1[k].x = - (uv2[k_map].x - 0.5) + 0.5
167
uv1[k].y = uv2[k_map].y
170
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
175
# Register the operator
177
MeshSelectInteriorFaces,
182
register = bpy.types.register
188
unregister = bpy.types.unregister
192
if __name__ == "__main__":