[Bf-extensions-cvs] [7a2693b] master: initial commit mesh_1D_scripts.py: T48619

meta-androcto noreply at git.blender.org
Mon Jun 13 02:08:11 CEST 2016


Commit: 7a2693bfbb125ceb45a1db948b302e899cd3f2dc
Author: meta-androcto
Date:   Mon Jun 13 10:07:39 2016 +1000
Branches: master
https://developer.blender.org/rBAC7a2693bfbb125ceb45a1db948b302e899cd3f2dc

initial commit mesh_1D_scripts.py: T48619

===================================================================

A	mesh_1D_scripts.py

===================================================================

diff --git a/mesh_1D_scripts.py b/mesh_1D_scripts.py
new file mode 100644
index 0000000..1081c8a
--- /dev/null
+++ b/mesh_1D_scripts.py
@@ -0,0 +1,6320 @@
+# -*- coding: utf-8 -*-   
+
+# ##### 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 #####  
+
+bl_info = {
+    "name": "1D_Scripts",                     
+    "author": "Alexander Nedovizin, Paul Kotelevets aka 1D_Inc (concept design), Nikitron",
+    "version": (0, 8, 8),
+    "blender": (2, 7, 5),
+    "location": "View3D > Toolbar",
+    "category": "Mesh"
+}  
+
+# http://dl.dropboxusercontent.com/u/59609328/Blender-Rus/1D_Scripts.py
+
+import bpy,bmesh, mathutils, math
+from mathutils import Vector, Matrix
+from mathutils.geometry import intersect_line_plane, intersect_point_line, intersect_line_line
+from math import sin, cos, pi, sqrt, degrees, tan, radians
+import os, urllib
+from bpy.props import (BoolProperty,
+                       FloatProperty,
+                       StringProperty,
+                       EnumProperty,
+                       IntProperty,
+                       CollectionProperty
+                       )
+from bpy_extras.io_utils import ExportHelper, ImportHelper
+from bpy.types import Operator
+import time 
+
+
+list_z = []
+mats_idx = []
+list_f = []
+maloe = 1e-5
+steps_smoose = 0
+
+
+def check_lukap(bm):
+    if hasattr(bm.verts, "ensure_lookup_table"): 
+        bm.verts.ensure_lookup_table()
+        bm.edges.ensure_lookup_table()
+        bm.faces.ensure_lookup_table()
+
+
+#----- Module: edge fillet-------
+# author this module: Zmj100
+# version 0.3.0
+# ref: 
+def a_rot(ang, rp, axis, q):
+    mtrx = Matrix.Rotation(ang, 3, axis)
+    tmp = q - rp
+    tmp1 = mtrx * tmp
+    tmp2 = tmp1 + rp
+    return tmp2
+
+# ------ ------
+class f_buf():
+    an = 0
+
+# ------ ------
+def f_edgefillet(bme, list_0, adj, n, radius, out, flip):
+    check_lukap(bme)
+
+    dict_0 = get_adj_v_(list_0)
+    list_1 = [[dict_0[i][0], i, dict_0[i][1]] for i in dict_0 if (len(dict_0[i]) == 2)][0]
+
+    list_del = [bme.verts[list_1[1]]]
+    list_2 = []
+
+    p = (bme.verts[list_1[1]].co).copy()
+    p1 = (bme.verts[list_1[0]].co).copy()
+    p2 = (bme.verts[list_1[2]].co).copy()
+
+    vec1 = p - p1
+    vec2 = p - p2
+
+    ang = vec1.angle(vec2, any)
+    f_buf.an = round(degrees(ang))
+
+    if f_buf.an == 180 or f_buf.an == 0.0:
+        pass
+    else:
+        opp = adj
+        if radius == False:
+            h = adj * (1 / cos(ang * 0.5))
+            d = adj
+        elif radius == True:
+            h = opp / sin(ang * 0.5)
+            d = opp / tan(ang * 0.5)
+
+        p3 = p - (vec1.normalized() * d)
+        p4 = p - (vec2.normalized() * d)
+
+        no = (vec1.cross(vec2)).normalized()
+        rp = a_rot(radians(90), p, (p3 - p4), (p - (no * h)))
+
+        vec3 = rp - p3
+        vec4 = rp - p4
+
+        axis = vec1.cross(vec2)
+
+        if out == False:
+            if flip == False:
+                rot_ang = vec3.angle(vec4)
+            elif flip == True:
+                rot_ang = vec1.angle(vec2)
+        elif out == True:
+            rot_ang = (2 * pi) - vec1.angle(vec2)
+
+        for j in range(n + 1):
+            if out == False:
+                if flip == False:
+                    tmp2 = a_rot(rot_ang * j / n, rp, axis, p4)
+                elif flip == True:
+                    tmp2 = a_rot(rot_ang * j / n, p, axis, p - (vec1.normalized() * opp))
+            elif out == True:
+                tmp2 = a_rot(rot_ang * j / n, p, axis, p - (vec2.normalized() * opp))
+
+            bme.verts.new(tmp2)
+            bme.verts.index_update()
+            check_lukap(bme)
+            list_2.append(bme.verts[-1].index)
+        
+        check_lukap(bme)
+        if flip == True:
+            list_1[1:2] = list_2
+        else:
+            list_2.reverse()
+            list_1[1:2] = list_2
+        list_2[:] = []
+
+        n1 = len(list_1)
+        for t in range(n1 - 1):
+            bme.edges.new([bme.verts[list_1[t]], bme.verts[list_1[(t + 1) % n1]]])
+            bme.edges.index_update()
+        
+        check_lukap(bme)
+        
+    bme.verts.remove(list_del[0])
+    bme.verts.index_update()
+    check_lukap(bme)
+
+class f_op0(bpy.types.Operator):
+    bl_idname = 'f.op0_id'
+    bl_label = 'Edge Fillet'
+    bl_options = {'REGISTER', 'UNDO'}
+
+    adj = FloatProperty( name = '', default = 0.1, min = 0.00001, max = 100.0, step = 1, precision = 3 )
+    n = IntProperty( name = '', default = 3, min = 1, max = 100, step = 1 )
+    out = BoolProperty( name = 'Outside', default = False )
+    flip = BoolProperty( name = 'Flip', default = False )
+    radius = BoolProperty( name = 'Radius', default = False )
+    
+    def draw(self, context):
+        layout = self.layout
+        if f_buf.an == 180 or f_buf.an == 0.0:
+            box = layout.box()
+            box.label('Info:')
+            box.label('Angle equal to 0 or 180,')
+            box.label('unable to fillet.')
+        else:
+            box = layout.box()
+            box.prop(self, 'radius')
+            row = box.split(0.35, align = True)
+
+            if self.radius == True:
+                row.label('Radius:')
+            elif self.radius == False:
+                row.label('Distance:')
+            row.prop(self, 'adj')
+            row1 = box.split(0.55, align = True)
+            row1.label('Number of sides:')
+            row1.prop(self, 'n', slider = True)
+
+            if self.n > 1:
+                row2 = box.split(0.50, align = True)
+                row2.prop(self, 'out')
+                if self.out == False:
+                    row2.prop(self, 'flip')
+
+    def execute(self, context):
+        adj = self.adj
+        n = self.n
+        out = self.out
+        flip = self.flip
+        radius = self.radius
+
+        edit_mode_out()
+        ob_act = context.active_object
+        bme = bmesh.new()
+        bme.from_mesh(ob_act.data)
+        check_lukap(bme)
+
+        list_0 = [[v.index for v in e.verts] for e in bme.edges if e.select and e.is_valid]
+        if not list_0:
+            list_v = [v.index for v in bme.verts if v.select and v.is_valid]
+            
+        if not list_0 and len(list_v)==1:
+            connected_edges = bme.verts[list_v[0]].link_edges
+            list_1 = [[v.index for v in e.verts ] for e in connected_edges if e.is_valid]
+            if len(list_1)!=2:
+                self.report({'INFO'}, 'Two adjacent edges or single vert must be selected.')
+                edit_mode_in()
+                return {'CANCELLED'}
+            
+            if out == True:
+                flip = False
+            f_edgefillet(bme, list_1, adj, n, radius, out, flip)
+            
+        elif len(list_0) != 2:
+            self.report({'INFO'}, 'Two adjacent edges or single vert must be selected.')
+            edit_mode_in()
+            return {'CANCELLED'}
+        else:
+            if out == True:
+                flip = False
+            f_edgefillet(bme, list_0, adj, n, radius, out, flip)
+
+        bme.to_mesh(ob_act.data)
+        edit_mode_in()
+        bpy.ops.mesh.select_all(action = 'DESELECT')
+        return {'FINISHED'}
+
+
+
+#----- Module: extrude along path -------
+# author this module: Zmj100
+# version 0.5.0.9
+# ref: http://blenderartists.org/forum/showthread.php?179375-Addon-Edge-fillet-and-other-bmesh-tools-Update-Jan-11
+
+def edit_mode_out():
+    bpy.ops.object.mode_set(mode = 'OBJECT')
+
+def edit_mode_in():
+    bpy.ops.object.mode_set(mode = 'EDIT')
+
+def get_adj_v_(list_):
+        tmp = {}
+        for i in list_:
+                try:             tmp[i[0]].append(i[1])
+                except KeyError: tmp[i[0]] = [i[1]]
+                try:             tmp[i[1]].append(i[0])
+                except KeyError: tmp[i[1]] = [i[0]]
+        return tmp
+
+def f_1(frst, list_, last):      # edge chain
+    fi = frst
+    tmp = [frst]
+    while list_ != []:
+        for i in list_:
+            if i[0] == fi:
+                tmp.append(i[1])
+                fi = i[1]
+                list_.remove(i)
+            elif i[1] == fi:
+                tmp.append(i[0])
+                fi = i[0]
+                list_.remove(i)
+        if tmp[-1] == last:
+            break
+    return tmp
+
+def f_2(frst, list_):      # edge loop
+    fi = frst
+    tmp = [frst]
+    while list_ != []:
+        for i in list_:
+            if i[0] == fi:
+                tmp.append(i[1])
+                fi = i[1]
+                list_.remove(i)
+            elif i[1] == fi:
+                tmp.append(i[0])
+                fi = i[0]
+                list_.remove(i)
+        if tmp[-1] == frst:
+            break
+    return tmp
+
+def is_loop_(list_fl):
+    return True if len(list_fl) == 0 else False
+
+def e_no_(bme, indx, p, p1):
+    if hasattr(bme.verts, "ensure_lookup_table"): 
+        bme.verts.ensure_lookup_table()
+    tmp1 = (bme.verts[indx].co).copy()
+    tmp1[0] += 0.1
+    tmp1[1] += 0.1
+    tmp1[2] += 0.1
+    ip1 = intersect_point_line( tmp1, p, p1)[0]
+    return tmp1 - ip1
+
+# ------ ------
+def f_(bme, dict_0, list_fl, loop):
+    check_lukap(bme)
+    if loop:
+        list_1 = f_2(eap_buf.list_sp[0], eap_buf.list_ek)
+        del list_1[-1]
+    else:
+        list_1 = f_1(eap_buf.list_sp[0], eap_buf.list_ek, list_fl[1] if eap_buf.list_sp[0] == list_fl[0] else list_fl[0])
+
+    list_2 = [ v.index for v in bme.verts if v.select and v.is_v

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list