adds lookup tests to support older versions of blender too
authorzeffii <tetha.z@gmail.com>
Fri, 2 Jan 2015 10:57:42 +0000 (11:57 +0100)
committerzeffii <tetha.z@gmail.com>
Fri, 2 Jan 2015 10:57:42 +0000 (11:57 +0100)
mesh_tinyCAD/BIX.py
mesh_tinyCAD/CCEN.py [new file with mode: 0644]
mesh_tinyCAD/PERP.py
mesh_tinyCAD/V2X.py
mesh_tinyCAD/VTX.py
mesh_tinyCAD/XALL.py
mesh_tinyCAD/__init__.py

index adf0e4a..47a8b17 100644 (file)
@@ -30,6 +30,10 @@ def add_line_to_bisection(self):
     me = obj.data
     bm = bmesh.from_edit_mesh(me)
 
+    if hasattr(bm.verts, "ensure_lookup_table"):
+        bm.verts.ensure_lookup_table()
+        bm.edges.ensure_lookup_table()
+
     edges = [e for e in bm.edges if (e.select and not e.hide)]
 
     if not len(edges) == 2:
diff --git a/mesh_tinyCAD/CCEN.py b/mesh_tinyCAD/CCEN.py
new file mode 100644 (file)
index 0000000..e42edcf
--- /dev/null
@@ -0,0 +1,81 @@
+'''
+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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+END GPL LICENCE BLOCK
+'''
+
+import math
+
+import bpy
+import bmesh
+import mathutils
+from mathutils import geometry
+from mathutils import Vector
+
+
+def generate_3PT_mode_1(pts=[]):
+    V = Vector
+
+    # construction
+    v1, v2, v3, v4 = V(pts[0]), V(pts[1]), V(pts[1]), V(pts[2])
+    edge1_mid = v1.lerp(v2, 0.5)
+    edge2_mid = v3.lerp(v4, 0.5)
+    axis = geometry.normal(v1, v2, v4)
+    mat_rot = mathutils.Matrix.Rotation(math.radians(90.0), 4, axis)
+
+    # triangle edges
+    v1_ = ((v1 - edge1_mid) * mat_rot) + edge1_mid
+    v2_ = ((v2 - edge1_mid) * mat_rot) + edge1_mid
+    v3_ = ((v3 - edge2_mid) * mat_rot) + edge2_mid
+    v4_ = ((v4 - edge2_mid) * mat_rot) + edge2_mid
+
+    r = geometry.intersect_line_line(v1_, v2_, v3_, v4_)
+    if r:
+        p1, _ = r
+        bpy.context.scene.cursor_location = p1
+
+    else:
+        print('not on a circle')
+
+
+def get_three_verts_from_selection(obj):
+    me = obj.data
+    bm = bmesh.from_edit_mesh(me)
+
+    if hasattr(bm.verts, "ensure_lookup_table"):
+        bm.verts.ensure_lookup_table()
+        bm.edges.ensure_lookup_table()
+
+    return [v.co[:] for v in bm.verts if v.select]
+
+
+class CircleCenter(bpy.types.Operator):
+
+    bl_idname = 'mesh.circlecenter'
+    bl_label = 'circle center from selected'
+    bl_options = {'REGISTER', 'UNDO'}
+
+    @classmethod
+    def poll(self, context):
+        obj = context.active_object
+        return obj is not None and obj.type == 'MESH' and obj.mode == 'EDIT'
+
+    def execute(self, context):
+        obj = bpy.context.object
+        pts = get_three_verts_from_selection(obj)
+        generate_3PT_mode_1(pts)
+        return {'FINISHED'}
index 2b9109f..5db8ef7 100644 (file)
@@ -31,6 +31,11 @@ def cut_visible_by_perpendicular(self):
     me = obj.data
     bm = bmesh.from_edit_mesh(me)
 
+    if hasattr(bm.verts, "ensure_lookup_table"):
+        bm.verts.ensure_lookup_table()
+        bm.edges.ensure_lookup_table()    
+        bm.faces.ensure_lookup_table()
+
     verts = [v for v in bm.verts if (v.select and not v.hide)]
 
     if not len(verts) == 2:
index 19b9940..cf4e848 100644 (file)
@@ -37,6 +37,12 @@ def add_vertex_to_intersection():
         iv = geometry.intersect_line_line(v1, v2, v3, v4)
         iv = (iv[0] + iv[1]) / 2
         bm.verts.new(iv)
+
+        # precaution?
+        if hasattr(bm.verts, "ensure_lookup_table"):
+            bm.verts.ensure_lookup_table()
+            # bm.edges.ensure_lookup_table()
+
         bm.verts[-1].select = True
         bmesh.update_edit_mesh(me)
 
index a0b17ac..b6e16bc 100644 (file)
@@ -18,6 +18,12 @@ def getVTX(self):
 
 
 def add_edges(self, idxs):
+
+    # precaution?
+    if hasattr(self.bm.verts, "ensure_lookup_table"):
+        self.bm.verts.ensure_lookup_table()
+        self.bm.edges.ensure_lookup_table()
+
     for e in idxs:
         v1 = self.bm.verts[-1]
         v2 = self.bm.verts[e]
@@ -35,17 +41,22 @@ def checkVTX(self, context):
     - remembers edges attached to current selection, for later.
     '''
 
-    # [x] if either of these edges share a vertex, return early.
+    # precaution?
+    if hasattr(self.bm.verts, "ensure_lookup_table"):
+        self.bm.verts.ensure_lookup_table()
+        self.bm.edges.ensure_lookup_table()
+
+    # if either of these edges share a vertex, return early.
     indices = cm.vertex_indices_from_edges_tuple(self.bm, self.selected_edges)
     if cm.duplicates(indices):
         msg = "edges share a vertex, degenerate case, returning early"
         self.report({"WARNING"}, msg)
         return False
 
-    # [x] find which edges intersect
+    # find which edges intersect
     getVTX(self)
 
-    # [x] check coplanar, or parallel.
+    # check coplanar, or parallel.
     if [] == self.edges:
         coplanar = cm.test_coplanar(self.edge1, self.edge2)
         if not coplanar:
@@ -117,7 +128,11 @@ class AutoVTX(bpy.types.Operator):
         obj = context.active_object
         self.me = obj.data
         self.bm = bmesh.from_edit_mesh(self.me)
-        self.me.update()
+
+        # self.me.update()
+        if hasattr(self.bm.verts, "ensure_lookup_table"):
+            self.bm.verts.ensure_lookup_table()
+            self.bm.edges.ensure_lookup_table()
 
         if obj is not None and obj.type == 'MESH':
             edges = self.bm.edges
@@ -128,6 +143,7 @@ class AutoVTX(bpy.types.Operator):
                 return True
 
     def execute(self, context):
+
         self.me.update()
         if checkVTX(self, context):
             doVTX(self)
index 645bd82..fb7d083 100644 (file)
@@ -76,6 +76,11 @@ def can_skip(closest_points, vert_vectors):
 
 
 def get_intersection_dictionary(bm, edge_indices):
+
+    if hasattr(bm.verts, "ensure_lookup_table"):
+        bm.verts.ensure_lookup_table()
+        bm.edges.ensure_lookup_table()
+
     permutations = get_valid_permutations(bm, edge_indices)
 
     k = defaultdict(list)
@@ -123,6 +128,11 @@ def update_mesh(obj, d):
         for i in range(num_edges_to_add):
             oe.add(1)
             ov.add(2)
+
+            # if hasattr(bm.verts, "ensure_lookup_table"):
+            #     bm.verts.ensure_lookup_table()
+            #     bm.edges.ensure_lookup_table()
+
             ov[vert_count].co = point_list[i]
             ov[vert_count+1].co = point_list[i+1]
 
index 11cab98..b8933d9 100644 (file)
@@ -21,14 +21,15 @@ END GPL LICENCE BLOCK
 bl_info = {
     "name": "tinyCAD Mesh tools",
     "author": "zeffii (aka Dealga McArdle)",
-    "version": (1, 0, 6),
-    "blender": (2, 7, 1),
+    "version": (1, 0, 7),
+    "blender": (2, 7, 3),
     "category": "Mesh",
     "location": "View3D > EditMode > (w) Specials",
     "wiki_url": "",
     "tracker_url": ""
 }
 
+## implemented lookup table for bmesh changes in 2.73
 
 if "bpy" in locals():
     import imp
@@ -36,18 +37,21 @@ if "bpy" in locals():
 import bpy
 from mesh_tinyCAD.VTX import AutoVTX
 from mesh_tinyCAD.V2X import Vert2Intersection
-from mesh_tinyCAD.EXM import ExtendEdgesMulti
+from mesh_tinyCAD.EXM import ExtendEdgesMulti
 from mesh_tinyCAD.XALL import IntersectAllEdges
 from mesh_tinyCAD.BIX import LineOnBisection
 from mesh_tinyCAD.PERP import CutOnPerpendicular
+from mesh_tinyCAD.CCEN import CircleCenter
+
 
 vtx_classes = (
     [AutoVTX, "tinyCAD autoVTX"],
     [Vert2Intersection, "tinyCAD V2X"],
     [IntersectAllEdges, "tinyCAD XALL"],
-    [ExtendEdgesMulti, "tinyCAD EXM"],
+    # [ExtendEdgesMulti, "tinyCAD EXM"],      # this is buggy
     [LineOnBisection, "tinyCAD BIX"],
-    [CutOnPerpendicular, "tinyCAD PERP CUT"]
+    [CutOnPerpendicular, "tinyCAD PERP CUT"],
+    [CircleCenter, "tC Circle Center"]
 )