~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/ewoc_projects_tools/mesh_innerweld.py

  • Committer: Reinhard Tartler
  • Date: 2014-05-31 01:50:05 UTC
  • mfrom: (14.2.27 sid)
  • Revision ID: siretart@tauware.de-20140531015005-ml6druahuj82nsav
mergeĀ fromĀ debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ##### BEGIN GPL LICENSE BLOCK #####
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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.
 
16
#
 
17
# ##### END GPL LICENSE BLOCK #####
 
18
 
 
19
"""
 
20
InnerWeld.  This addon welds parallel connected selected edges together.
 
21
 
 
22
Documentation
 
23
 
 
24
First go to User Preferences->Addons and enable the InnerWeld addon in the Mesh category.
 
25
Go to EditMode, select some parallel edge(loop)(slices).  Handles ALL edges parallel next to each other.
 
26
These edges will be welded together when invoking addon (button in Mesh Tools panel).
 
27
Innerweld will only work when in Edge select component mode!
 
28
 
 
29
If you wish to hotkey InnerWeld:
 
30
In the Input section of User Preferences at the bottom of the 3D View > Mesh section click 'Add New' button.
 
31
In the Operator Identifier box put 'mesh.innerweld'.
 
32
Assign a hotkey.
 
33
Save as Default (Optional).
 
34
"""
 
35
 
 
36
 
 
37
bl_info = {
 
38
        "name": "InnerWeld",
 
39
        "author": "Gert De Roost",
 
40
        "version": (0, 2, 0),
 
41
        "blender": (2, 63, 0),
 
42
        "location": "View3D > Tools",
 
43
        "description": "Welding parallel edges together.",
 
44
        "warning": "",
 
45
        "wiki_url": "",
 
46
        "tracker_url": "",
 
47
        "category": "Mesh"}
 
48
 
 
49
 
 
50
 
 
51
import bpy
 
52
import bmesh
 
53
 
 
54
 
 
55
 
 
56
 
 
57
class InnerWeld(bpy.types.Operator):
 
58
        bl_idname = "mesh.innerweld"
 
59
        bl_label = "InnerWeld"
 
60
        bl_description = "Welding parallel edges together"
 
61
        bl_options = {'REGISTER', 'UNDO'}
 
62
 
 
63
 
 
64
        @classmethod
 
65
        def poll(cls, context):
 
66
                obj = context.active_object
 
67
                return (obj and obj.type == 'MESH' and context.mode == 'EDIT_MESH' and list(context.tool_settings.mesh_select_mode) == [False, True, False])
 
68
 
 
69
        def invoke(self, context, event):
 
70
 
 
71
                bpy.ops.object.editmode_toggle()
 
72
                bpy.ops.object.editmode_toggle()
 
73
 
 
74
                self.do_innerweld(context)
 
75
 
 
76
                bpy.ops.object.editmode_toggle()
 
77
                bpy.ops.object.editmode_toggle()
 
78
 
 
79
                return {'FINISHED'}
 
80
 
 
81
 
 
82
        def do_innerweld(self, context):
 
83
 
 
84
                selobj = context.active_object
 
85
                mesh = selobj.data
 
86
                bm = bmesh.from_edit_mesh(mesh)
 
87
 
 
88
                self.sellist = []
 
89
                for edge in bm.edges:
 
90
                        if edge.select:
 
91
                                self.sellist.append(edge)
 
92
 
 
93
 
 
94
                def addstart(vert, posn):
 
95
 
 
96
                        # recursive: adds to initial edgelist at start
 
97
                        for e in vert.link_edges:
 
98
                                if e in self.sellist:
 
99
                                        self.sellist.pop(self.sellist.index(e))
 
100
                                        v = e.other_vert(vert)
 
101
                                        self.vertlist[posn].insert(0, v)
 
102
                                        addstart(v, posn)
 
103
 
 
104
                def addend(vert, posn):
 
105
 
 
106
                        # recursive: adds to initial edgelist at end
 
107
                        for e in vert.link_edges:
 
108
                                if e in self.sellist:
 
109
                                        self.sellist.pop(self.sellist.index(e))
 
110
                                        v = e.other_vert(vert)
 
111
                                        self.vertlist[posn].append(v)
 
112
                                        addend(v, posn)
 
113
 
 
114
                posn = 0
 
115
                self.vertlist = []
 
116
                while len(self.sellist) > 0:
 
117
                        # initialize next edgesnake
 
118
                        self.vertlist.append([])
 
119
                        vert = self.sellist[0].verts[0]
 
120
                        self.vertlist[posn].append(vert)
 
121
                        # add to start and end of arbitrary start vert
 
122
                        addstart(vert, posn)
 
123
                        addend(vert, posn)
 
124
                        posn += 1
 
125
 
 
126
 
 
127
                found = True
 
128
                posn = 0
 
129
                mergesets = []
 
130
                while found:
 
131
                        found = False
 
132
                        for idx in range(len(self.vertlist)):
 
133
                                if len(self.vertlist[idx]) > 0:
 
134
                                        found = True
 
135
                                        vset = set([])
 
136
                                        vset.add(self.vertlist[idx].pop())
 
137
                                        mergesets.append(vset.copy())
 
138
                                        while len(vset) > 0:
 
139
                                                vert = vset.pop()
 
140
                                                for edge in vert.link_edges:
 
141
                                                        if edge.select:
 
142
                                                                continue
 
143
                                                        v1 = edge.other_vert(vert)
 
144
                                                        for vlist in self.vertlist:
 
145
                                                                if v1 in vlist and not(v1 in mergesets[posn]):
 
146
                                                                        mergesets[posn].add(v1)
 
147
                                                                        vset.add(v1)
 
148
                                                                        self.vertlist[self.vertlist.index(vlist)].pop(vlist.index(v1))
 
149
                                        posn +=1
 
150
 
 
151
                mergeverts = []
 
152
                for st in mergesets:
 
153
                        bpy.ops.mesh.select_all(action = 'DESELECT')
 
154
                        for vert in st:
 
155
                                vert.select = True
 
156
                                mergeverts.append(vert)
 
157
                        bpy.ops.mesh.merge(type='CENTER', uvs=True)
 
158
 
 
159
                for v in mergeverts:
 
160
                        try:
 
161
                                v.select = True
 
162
                        except:
 
163
                                pass
 
164
 
 
165
                bm.select_flush(1)
 
166
                bm.free()
 
167
 
 
168
 
 
169
 
 
170
 
 
171
 
 
172
def panel_func(self, context):
 
173
        self.layout.label(text="InnerWeld:")
 
174
        self.layout.operator("mesh.innerweld", text="Weld Edges")
 
175
 
 
176
 
 
177
def register():
 
178
        bpy.utils.register_module(__name__)
 
179
        bpy.types.VIEW3D_PT_tools_meshedit.append(panel_func)
 
180
 
 
181
def unregister():
 
182
        bpy.utils.unregister_module(__name__)
 
183
        bpy.types.VIEW3D_PT_tools_meshedit.remove(panel_func)
 
184
 
 
185
if __name__ == "__main__":
 
186
        register()
 
187
 
 
188
 
 
189
 
 
190
 
 
191
 
 
192