Преглед на файлове

Delete MESH_SOLIDIFY_WIREFRAME.PY

0000OOOO0000 преди 5 години
родител
ревизия
bb712ca93a
No account linked to committer's email
променени са 1 файла, в които са добавени 0 реда и са изтрити 298 реда
  1. 0
    298
      ◯ᴥᗱᗴᗝИNᗱᗴᙁ⚭ⵙ⚭ᙁᗱᗴИNᗝᗱᗴᴥ◯/2.90/SCRIPTS/ADDONS/MESH_SOLIDIFY_WIREFRAME.PY

+ 0
- 298
◯ᴥᗱᗴᗝИNᗱᗴᙁ⚭ⵙ⚭ᙁᗱᗴИNᗝᗱᗴᴥ◯/2.90/SCRIPTS/ADDONS/MESH_SOLIDIFY_WIREFRAME.PY Целия файл

@@ -1,298 +0,0 @@
1
-#!BPY
2
-
3
-bl_info = {
4
-    "name": "Solidify Wireframe",
5
-    "author": "Yorik van Havre, Alejandro Sierra, Howard Trickey",
6
-    "description": "Turns the selected edges of a mesh into solid geometry",
7
-    "version": (2, 3),
8
-    "blender": (2, 5, 8),
9
-    "category": "Mesh",
10
-    "location": "Mesh > Solidify Wireframe",
11
-    "warning": '',
12
-    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Modeling/Solidify_Wireframe",
13
-    "tracker_url": "http://projects.blender.org/tracker/?func=detail&group_id=153&aid=26997&atid=467",
14
-    }
15
-
16
-# ***** BEGIN GPL LICENSE BLOCK *****
17
-#
18
-# This program is free software; you can redistribute it and/or
19
-# modify it under the terms of the GNU General Public License
20
-# as published by the Free Software Foundation; either version 2
21
-# of the License, or (at your option) any later version.
22
-#
23
-# This program is distributed in the hope that it will be useful,
24
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See th
26
-# GNU General Public License for more details.
27
-#
28
-# You should have received a copy of the GNU General Public License
29
-# along with this program; if not, write to the Free Software Foundation,
30
-# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31
-#
32
-# ***** END GPL LICENCE BLOCK *****
33
-
34
-import bpy, mathutils
35
-
36
-cube_faces = [ [0,3,2,1], [5,6,7,4], [0,1,5,4],
37
-               [7,6,2,3], [2,6,5,1], [0,4,7,3] ]
38
-cube_normals = [ mathutils.Vector((0,0,-1)),
39
-                 mathutils.Vector((0,0,1)),
40
-                 mathutils.Vector((0,-1,0)),
41
-                 mathutils.Vector((0,1,0)),
42
-                 mathutils.Vector((1,0,0)),
43
-                 mathutils.Vector((-1,0,0)) ]
44
-
45
-def create_cube(me, v, d):
46
-    x = v.co.x
47
-    y = v.co.y
48
-    z = v.co.z
49
-    coords=[ [x-d,y-d,z-d], [x+d,y-d,z-d], [x+d,y+d,z-d], [x-d,y+d,z-d],
50
-         [x-d,y-d,z+d], [x+d,y-d,z+d], [x+d,y+d,z+d], [x-d,y+d,z+d] ]
51
-    for coord in coords:
52
-        me.vertices.add(1)
53
-        me.vertices[-1].co = mathutils.Vector(coord)
54
-
55
-def norm_dot(e, k, fnorm, me):
56
-    v = me.vertices[e[1]].co - me.vertices[e[0]].co
57
-    if k == 1:
58
-        v = -v
59
-    v.normalize()
60
-    return v * fnorm
61
-
62
-def fill_cube_face(me, index, f):
63
-    return [index + cube_faces[f][i] for i in range(4)]
64
-
65
-# Coords of jth point of face f in cube instance i
66
-def cube_face_v(me, f, i, j):
67
-    return me.vertices[i + cube_faces[f][j]].co
68
-
69
-def cube_face_center(me, f, i):
70
-    return 0.5 * (cube_face_v(me, f, i, 0) + \
71
-                  cube_face_v(me, f, i, 2))
72
-
73
-# Return distance between points on two faces when
74
-# each point is projected onto the plane that goes through
75
-# the face center and is perpendicular to the line
76
-# through the face centers.
77
-def projected_dist(me, i1, i2, f1, f2, j1, j2):
78
-    f1center = cube_face_center(me, f1, i1)
79
-    f2center = cube_face_center(me, f2, i2)
80
-    axis_norm = (f2center - f1center).normalized()
81
-    v1 = cube_face_v(me, f1, i1, j1)
82
-    v2 = cube_face_v(me, f2, i2, j2)
83
-    v1proj = v1 - (axis_norm * (v1 - f1center)) * axis_norm
84
-    v2proj = v2 - (axis_norm * (v2 - f2center)) * axis_norm
85
-    return (v2proj - v1proj).length
86
-
87
-def skin_edges(me, i1, i2, f1, f2):
88
-    # Connect verts starting at i1 forming cube face f1
89
-    # to those starting at i2 forming cube face f2.
90
-    # Need to find best alignment to avoid a twist.
91
-    shortest_length = 1e6
92
-    f2_start_index = 0
93
-    for i in range(4):
94
-        x = projected_dist(me, i1, i2, f1, f2, 0, i)
95
-        if x < shortest_length:
96
-            shortest_length = x
97
-            f2_start_index = i
98
-    ans = []
99
-    j = f2_start_index
100
-    for i in range(4):
101
-        fdata = [i1 + cube_faces[f1][i],
102
-                 i2 + cube_faces[f2][j],
103
-                 i2 + cube_faces[f2][(j + 1) % 4],
104
-                 i1 + cube_faces[f1][(i - 1) % 4]]
105
-        if fdata[3] == 0:
106
-            fdata = [fdata[3]] + fdata[0:3]
107
-        ans.extend(fdata)
108
-        j = (j - 1) % 4
109
-    return ans
110
-            
111
-
112
-# Return map: v -> list of length len(node_normals) where
113
-# each element of the list is either None (no assignment)
114
-# or ((v0, v1), 0 or 1) giving an edge and direction that face is assigned to.
115
-def find_assignment(me, edges, vert_edges, node_normals):
116
-    nf = len(node_normals)
117
-    feasible = {}
118
-    for e in edges:
119
-        for k in (0, 1):
120
-            fds = [(f, norm_dot(e, k, node_normals[f], me)) for f in range(nf)]
121
-            feasible[(e, k)] = [fd for fd in fds if fd[1] > 0.01]
122
-    assignment = {}
123
-    for v, ves in vert_edges.items():
124
-        assignment[v] = best_assignment(ves, feasible, nf)
125
-    return assignment
126
-
127
-def best_assignment(ves, feasible, nf):
128
-    apartial = [ None ] * nf
129
-    return best_assign_help(ves, feasible, apartial, 0.0)[0]
130
-
131
-def best_assign_help(ves, feasible, apartial, sumpartial):
132
-    if len(ves) == 0:
133
-        return (apartial, sumpartial)
134
-    else:
135
-        ek0 = ves[0]
136
-        vesrest = ves[1:]
137
-        feas = feasible[ek0]
138
-        bestsum = 0
139
-        besta = None
140
-        for (f, d) in feas:
141
-            if apartial[f] is None:
142
-                ap = apartial[:]
143
-                ap[f] = ek0
144
-                # sum up d**2 to penalize smaller d's more
145
-                sp = sumpartial + d*d
146
-                (a, s) = best_assign_help(vesrest, feasible, ap, sp)
147
-                if s > bestsum:
148
-                    bestsum = s
149
-                    besta = a
150
-        if besta:
151
-            return (besta, bestsum)
152
-        else:
153
-            # not feasible to assign e0, k0; try to assign rest
154
-            return best_assign_help(vesrest, feasible, apartial, sumpartial)
155
-
156
-def assigned_face(e, assignment):
157
-    (v0, v1), dir = e
158
-    a = assignment[v1]
159
-    for j, ee in enumerate(a):
160
-        if e == ee:
161
-            return j
162
-    return -1
163
-
164
-def create_wired_mesh(me2, me, thick):
165
-    edges = []
166
-    vert_edges = {}
167
-    for be in me.edges:
168
-        if be.select and not be.hide:
169
-            e = (be.key[0], be.key[1])
170
-            edges.append(e)
171
-            for k in (0, 1):
172
-                if e[k] not in vert_edges:
173
-                    vert_edges[e[k]] = []
174
-                vert_edges[e[k]].append((e, k))
175
-
176
-    assignment = find_assignment(me, edges, vert_edges, cube_normals)
177
-
178
-    # Create the geometry
179
-    n_idx = {}   
180
-    for v in assignment:
181
-        vpos = me.vertices[v]
182
-        index = len(me2.vertices)
183
-        # We need to associate each node with the new geometry
184
-        n_idx[v] = index   
185
-        # Geometry for the nodes, each one a cube
186
-        create_cube(me2, vpos, thick)
187
-
188
-    # Skin using the new geometry 
189
-    cfaces = []  
190
-    for k, f in assignment.items():
191
-        # Skin the nodes
192
-        for i in range(len(cube_faces)):
193
-            if f[i] is None:
194
-                cfaces.extend(fill_cube_face(me2, n_idx[k], i))
195
-            else:
196
-                (v0, v1), dir = f[i]
197
-                # only skin between edges in forward direction
198
-                # to avoid making doubles
199
-                if dir == 1:
200
-                    # but first make sure other end actually assigned
201
-                    i2 = assigned_face(((v0, v1), 0), assignment)
202
-                    if i2 == -1:
203
-                        cfaces.extend(fill_cube_face(me2, n_idx[k], i))
204
-                    continue
205
-                i2 = assigned_face(((v0, v1), 1), assignment)
206
-                if i2 != -1:
207
-                    cfaces.extend(skin_edges(me2, n_idx[v0], n_idx[v1], i, i2))
208
-                else:
209
-                    # assignment failed for this edge
210
-                    cfaces.extend(fill_cube_face(me2, n_idx[k], i))
211
-
212
-    # adding faces to the mesh
213
-    me2.faces.add(len(cfaces) // 4)
214
-    me2.faces.foreach_set("vertices_raw", cfaces)
215
-    me2.update(calc_edges=True)
216
-
217
-# panel containing tools
218
-class VIEW3D_PT_tools_SolidifyWireframe(bpy.types.Panel):
219
-    bl_space_type = 'VIEW_3D'
220
-    bl_region_type = 'TOOLS'
221
-    bl_context = "mesh_edit"
222
-    bl_label = "Solidify Wireframe"
223
-
224
-    def draw(self, context):
225
-        active_obj = context.active_object
226
-        layout = self.layout
227
-        col = layout.column(align=True)
228
-        col.operator("mesh.solidify_wireframe", text="Solidify")
229
-        col.prop(context.scene, "swThickness")
230
-        col.prop(context.scene, "swSelectNew")
231
-
232
-# a class for your operator
233
-class SolidifyWireframe(bpy.types.Operator):
234
-    '''Turns the selected edges of a mesh into solid objects'''
235
-    bl_idname = "mesh.solidify_wireframe"
236
-    bl_label = "Solidify Wireframe"
237
-    bl_options = {'REGISTER', 'UNDO'}
238
-    
239
-    def invoke(self, context, event):
240
-        return self.execute(context)
241
-
242
-    @classmethod
243
-    def poll(cls, context):
244
-        ob = context.active_object
245
-        return ob and ob.type == 'MESH'
246
-
247
-    def execute(self, context):
248
-        # Get the active object
249
-        ob_act = context.active_object
250
-        # getting current edit mode
251
-        currMode = ob_act.mode
252
-        # switching to object mode
253
-        bpy.ops.object.mode_set(mode='OBJECT')
254
-        bpy.ops.object.select_all(action='DESELECT')
255
-        # getting mesh data
256
-        mymesh = ob_act.data
257
-        #getting new mesh
258
-        newmesh = bpy.data.meshes.new(mymesh.name + " wire")
259
-        obj = bpy.data.objects.new(newmesh.name,newmesh)
260
-        obj.location = ob_act.location
261
-        obj.rotation_euler = ob_act.rotation_euler
262
-        obj.scale = ob_act.scale
263
-        context.scene.objects.link(obj)
264
-        create_wired_mesh(newmesh, mymesh, context.scene.swThickness)
265
-
266
-        # restoring original editmode if needed
267
-        if context.scene.swSelectNew:
268
-            obj.select = True
269
-            context.scene.objects.active = obj
270
-        else:
271
-            bpy.ops.object.mode_set(mode=currMode)
272
-
273
-        # returning after everything is done
274
-        return {'FINISHED'}
275
-
276
-# Register the operator
277
-def solidifyWireframe_menu_func(self, context):
278
-        self.layout.operator(SolidifyWireframe.bl_idname, text="Solidify Wireframe", icon='PLUGIN')
279
-
280
-# Add "Solidify Wireframe" menu to the "Mesh" menu.
281
-def register():
282
-        bpy.utils.register_module(__name__)
283
-        bpy.types.Scene.swThickness = bpy.props.FloatProperty(name="Thickness",
284
-                                                              description="Thickness of the skinned edges",
285
-                                                              default=0.02)
286
-        bpy.types.Scene.swSelectNew = bpy.props.BoolProperty(name="Select wire",
287
-                                                             description="If checked, the wire object will be selected after creation",
288
-                                                             default=True)
289
-        bpy.types.VIEW3D_MT_edit_mesh_edges.append(solidifyWireframe_menu_func)
290
-
291
-# Remove "Solidify Wireframe" menu entry from the "Mesh" menu.
292
-def unregister():
293
-        bpy.utils.register_module(__name__)
294
-        del bpy.types.Scene.swThickness
295
-        bpy.types.VIEW3D_MT_edit_mesh_edges.remove(solidifyWireframe_menu_func)
296
-
297
-if __name__ == "__main__":
298
-        register()