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 #####
22 from bpy.types import Operator
24 from bpy.props import EnumProperty
27 class MeshSelectInteriorFaces(Operator):
28 '''Select faces where all edges have more than 2 face users'''
30 bl_idname = "mesh.faces_select_interior"
31 bl_label = "Select Interior Faces"
32 bl_options = {'REGISTER', 'UNDO'}
35 def poll(cls, context):
36 ob = context.active_object
37 return (ob and ob.type == 'MESH')
39 def execute(self, context):
40 from bpy_extras import mesh_utils
41 ob = context.active_object
42 context.tool_settings.mesh_select_mode = False, False, True
43 is_editmode = (ob.mode == 'EDIT')
45 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
49 face_list = mesh.faces[:]
50 face_edge_keys = [face.edge_keys for face in face_list]
52 edge_face_count = mesh_utils.edge_face_count_dict(mesh)
54 def test_interior(index):
55 for key in face_edge_keys[index]:
56 if edge_face_count[key] < 3:
60 for index, face in enumerate(face_list):
61 if(test_interior(index)):
67 bpy.ops.object.mode_set(mode='EDIT', toggle=False)
71 class MeshMirrorUV(Operator):
72 '''Copy mirror UV coordinates on the X axis based on a mirrored mesh'''
73 bl_idname = "mesh.faces_mirror_uv"
74 bl_label = "Copy Mirrored UV coords"
75 bl_options = {'REGISTER', 'UNDO'}
77 direction = EnumProperty(
78 name="Axis Direction",
79 items=(('POSITIVE', "Positive", ""),
80 ('NEGATIVE', "Negative", "")),
84 def poll(cls, context):
85 obj = context.active_object
86 return (obj and obj.type == 'MESH' and obj.data.uv_textures.active)
88 def execute(self, context):
89 DIR = (self.direction == 'NEGATIVE')
91 ob = context.active_object
92 is_editmode = (ob.mode == 'EDIT')
94 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
102 vcos = [v.co.to_tuple(5) for v in mesh.vertices]
104 for i, co in enumerate(vcos):
113 #for i, v in enumerate(mesh.vertices):
115 for mirror_a, mirror_b in ((mirror_gt, mirror_lt),
116 (mirror_lt, mirror_gt)):
117 for co, i in mirror_a.items():
118 nco = (-co[0], co[1], co[2])
119 j = mirror_b.get(nco)
123 active_uv_layer = mesh.uv_textures.active.data
124 fuvs = [(uv.uv1, uv.uv2, uv.uv3, uv.uv4) for uv in active_uv_layer]
125 fuvs_cpy = [(uv[0].copy(), uv[1].copy(), uv[2].copy(), uv[3].copy())
129 faces = mesh.faces[:]
131 fuvsel = [(False not in uv.select_uv) for uv in active_uv_layer]
132 fcents = [f.center for f in faces]
136 for i, f in enumerate(faces):
137 verts = list(f.vertices)
143 for i, f in enumerate(faces):
144 verts = [vmap.get(j) for j in f.vertices]
145 if None not in verts:
147 j = mirror_fm.get(tuple(verts))
151 for i, j in fmap.items():
153 if not fuvsel[i] or not fuvsel[j]:
155 elif DIR == 0 and fcents[i][0] < 0.0:
157 elif DIR == 1 and fcents[i][0] > 0.0:
164 # get the correct rotation
165 v1 = faces[j].vertices[:]
166 v2 = [vmap[k] for k in faces[i].vertices[:]]
168 if len(v1) == len(v2):
169 for k in range(len(v1)):
170 k_map = v1.index(v2[k])
171 uv1[k].xy = - (uv2[k_map].x - 0.5) + 0.5, uv2[k_map].y
174 bpy.ops.object.mode_set(mode='EDIT', toggle=False)