[Bf-extensions-cvs] [00768b0] master: adds lookup tests to support older versions of blender too
zeffii
noreply at git.blender.org
Fri Jan 2 11:57:58 CET 2015
Commit: 00768b046daba17cdc89f238f7f13518c28bae0e
Author: zeffii
Date: Fri Jan 2 11:57:42 2015 +0100
Branches: master
https://developer.blender.org/rBAC00768b046daba17cdc89f238f7f13518c28bae0e
adds lookup tests to support older versions of blender too
===================================================================
M mesh_tinyCAD/BIX.py
A mesh_tinyCAD/CCEN.py
M mesh_tinyCAD/PERP.py
M mesh_tinyCAD/V2X.py
M mesh_tinyCAD/VTX.py
M mesh_tinyCAD/XALL.py
M mesh_tinyCAD/__init__.py
===================================================================
diff --git a/mesh_tinyCAD/BIX.py b/mesh_tinyCAD/BIX.py
index adf0e4a..47a8b17 100644
--- a/mesh_tinyCAD/BIX.py
+++ b/mesh_tinyCAD/BIX.py
@@ -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
index 0000000..e42edcf
--- /dev/null
+++ b/mesh_tinyCAD/CCEN.py
@@ -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'}
diff --git a/mesh_tinyCAD/PERP.py b/mesh_tinyCAD/PERP.py
index 2b9109f..5db8ef7 100644
--- a/mesh_tinyCAD/PERP.py
+++ b/mesh_tinyCAD/PERP.py
@@ -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:
diff --git a/mesh_tinyCAD/V2X.py b/mesh_tinyCAD/V2X.py
index 19b9940..cf4e848 100644
--- a/mesh_tinyCAD/V2X.py
+++ b/mesh_tinyCAD/V2X.py
@@ -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)
diff --git a/mesh_tinyCAD/VTX.py b/mesh_tinyCAD/VTX.py
index a0b17ac..b6e16bc 100644
--- a/mesh_tinyCAD/VTX.py
+++ b/mesh_tinyCAD/VTX.py
@@ -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)
diff --git a/mesh_tinyCAD/XALL.py b/mesh_tinyCAD/XALL.py
index 645bd82..fb7d083 100644
--- a/mesh_tinyCAD/XALL.py
+++ b/mesh_tinyCAD/XALL.py
@@ -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]
diff --git a/mesh_tinyCAD/__init__.py b/mesh_tinyCAD/__init__.py
index 11cab98..b8933d9 100644
--- a/mesh_tinyCAD/__init__.py
+++ b/mesh_tinyCAD/__init__.py
@@ -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"]
)
More information about the Bf-extensions-cvs
mailing list