[Bf-extensions-cvs] [3317314] master: removed superfluous functionality

Dealga McArdle noreply at git.blender.org
Wed Dec 23 20:40:32 CET 2015


Commit: 33173143c285761992a1467df31581f8a8fdbf29
Author: Dealga McArdle
Date:   Tue Dec 22 23:27:51 2015 +0100
Branches: master
https://developer.blender.org/rBAC33173143c285761992a1467df31581f8a8fdbf29

removed superfluous functionality

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

M	mesh_tinyCAD/CCEN.py
D	mesh_tinyCAD/EXM.py
D	mesh_tinyCAD/PERP.py
M	mesh_tinyCAD/VTX.py
M	mesh_tinyCAD/__init__.py

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

diff --git a/mesh_tinyCAD/CCEN.py b/mesh_tinyCAD/CCEN.py
index 28519d2..8a6e2b8 100644
--- a/mesh_tinyCAD/CCEN.py
+++ b/mesh_tinyCAD/CCEN.py
@@ -8,7 +8,7 @@ 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
+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
@@ -27,11 +27,109 @@ from mathutils import geometry
 from mathutils import Vector
 
 
-def generate_3PT_mode_1(pts, obj):
+def get_layer():
+    '''
+    this always returns a new empty layer ready for drawing to
+    '''
+
+    # get grease pencil data
+    grease_pencil_name = 'tc_circle_000'   # data
+    layer_name = "TinyCad Layer"           # layer
+
+    grease_data = bpy.data.grease_pencil
+    if grease_pencil_name not in grease_data:
+        gp = grease_data.new(grease_pencil_name)
+    else:
+        gp = grease_data[grease_pencil_name]
+
+    # get grease pencil layer
+    if not (layer_name in gp.layers):
+        layer = gp.layers.new(layer_name)
+        layer.frames.new(1)
+        layer.line_width = 1
+    else:
+        layer = gp.layers[layer_name]
+        layer.frames[0].clear()
+
+    return layer
+
+
+def generate_gp3d_stroke(layer, p1, v1, axis, mw, origin, num_verts):
+
+    '''
+        p1:     center of circle (local coordinates)
+        v1:     first vertex of circle in (local coordinates)
+        axis:   orientation matrix
+        mw:     obj.matrix_world
+        origin: obj.location
+    '''
+
+    layer.show_points = True  # is this still broken? GP bug, reported!
+
+    layer.color = bpy.context.scene.tc_gp_color
+    s = layer.frames[0].strokes.new()
+    s.draw_mode = '3DSPACE'
+
+    chain = []
+    gamma = 2 * math.pi / num_verts
+    for i in range(num_verts + 1):
+        theta = gamma * i
+        mat_rot = mathutils.Matrix.Rotation(theta, 4, axis)
+        local_point = mw * (mat_rot * (v1 - p1))  # + origin
+        world_point = local_point - (origin - (mw * p1))
+        chain.append(world_point)
+
+    s.points.add(len(chain))
+    for idx, p in enumerate(chain):
+        s.points[idx].co = p
+
+
+def generate_bmesh_repr(p1, v1, axis, num_verts):
+
+    '''
+        p1:     center of circle (local coordinates)
+        v1:     first vertex of circle in (local coordinates)
+        axis:   orientation matrix
+        origin: obj.location
+    '''
+
+    # generate geometr up front
+    chain = []
+    gamma = 2 * math.pi / num_verts
+    for i in range(num_verts + 1):
+        theta = gamma * i
+        mat_rot = mathutils.Matrix.Rotation(theta, 4, axis)
+        local_point = (mat_rot * (v1 - p1))
+        chain.append(local_point + p1)
+
+    obj = bpy.context.edit_object
+    me = obj.data
+    bm = bmesh.from_edit_mesh(me)
+
+    # add verts
+    v_refs = []
+    for p in chain:
+        v = bm.verts.new(p)
+        v.select = False  # this might be a default.. redundant?
+        v_refs.append(v)
+
+    # join verts, daisy chain
+    num_verts = len(v_refs)
+    for i in range(num_verts):
+        idx1 = i
+        idx2 = (i + 1) % num_verts
+        bm.edges.new([v_refs[idx1], v_refs[idx2]])
+
+    bmesh.update_edit_mesh(me, True)
+
+
+def generate_3PT(pts, obj, nv, mode=0):
     origin = obj.location
-    transform_matrix = obj.matrix_local
+    mw = obj.matrix_world
     V = Vector
 
+    nv = max(3, nv)
+
     # construction
     v1, v2, v3, v4 = V(pts[0]), V(pts[1]), V(pts[1]), V(pts[2])
     edge1_mid = v1.lerp(v2, 0.5)
@@ -48,14 +146,26 @@ def generate_3PT_mode_1(pts, obj):
     r = geometry.intersect_line_line(v1_, v2_, v3_, v4_)
     if r:
         p1, _ = r
-        # cp = transform_matrix * (p1 + origin)
-        cp = transform_matrix * p1
+        cp = mw * p1
         bpy.context.scene.cursor_location = cp
-        # generate_gp3d_stroke(cp, axis, obj, radius=(p1-v1).length)
+
+        if mode == 0:
+            layer = get_layer()
+            generate_gp3d_stroke(layer, p1, v1, axis, mw, origin, nv)
+
+            scn = bpy.context.scene
+            scn.grease_pencil = bpy.data.grease_pencil['tc_circle_000']
+
+        elif mode == 1:
+            generate_bmesh_repr(p1, v1, axis, nv)
+
     else:
         print('not on a circle')
 
 
+''' Shared Utils '''
+
+
 def get_three_verts_from_selection(obj):
     me = obj.data
     bm = bmesh.from_edit_mesh(me)
@@ -67,19 +177,53 @@ def get_three_verts_from_selection(obj):
     return [v.co[:] for v in bm.verts if v.select]
 
 
+def dispatch(context, mode=0):
+    obj = context.edit_object
+    pts = get_three_verts_from_selection(obj)
+    nv = context.scene.tc_num_verts
+    generate_3PT(pts, obj, nv, mode)
+
+
+''' Operators '''
+
+
 class CircleCenter(bpy.types.Operator):
 
     bl_idname = 'mesh.circlecenter'
     bl_label = 'circle center from selected'
     bl_options = {'REGISTER', 'UNDO'}
 
+    def draw(self, context):
+        scn = context.scene
+        l = self.layout
+        col = l.column()
+
+        col.prop(scn, 'tc_gp_color', text='layer color')
+        col.prop(scn, 'tc_num_verts', text='num verts')
+        col.operator('mesh.circlemake', text='Make Mesh')
+
     @classmethod
     def poll(self, context):
-        obj = context.active_object
-        return obj is not None and obj.type == 'MESH' and obj.mode == 'EDIT'
+        obj = context.edit_object
+        return obj is not None and obj.type == 'MESH'
+
+    def execute(self, context):
+        dispatch(context, mode=0)  # make gp
+        return {'FINISHED'}
+
+
+class CircleMake(bpy.types.Operator):
+
+    bl_idname = 'mesh.circlemake'
+    bl_label = 'circle mesh from selected'
+    bl_options = {'REGISTER', 'UNDO'}
+
+    def draw(self, context):
+        scn = context.scene
+        l = self.layout
+        col = l.column()
+        col.prop(scn, 'tc_num_verts', text='num verts')
 
     def execute(self, context):
-        obj = bpy.context.object
-        pts = get_three_verts_from_selection(obj)
-        generate_3PT_mode_1(pts, obj)
+        dispatch(context, mode=1)  # bake mesh
         return {'FINISHED'}
diff --git a/mesh_tinyCAD/EXM.py b/mesh_tinyCAD/EXM.py
deleted file mode 100644
index 8d3b945..0000000
--- a/mesh_tinyCAD/EXM.py
+++ /dev/null
@@ -1,228 +0,0 @@
-'''
-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 itertools
-
-import bpy
-import bgl
-import mathutils
-import bmesh
-
-from bpy_extras.view3d_utils import location_3d_to_region_2d as loc3d2d
-
-from mesh_tinyCAD import cad_module as cm
-
-
-line_colors = {
-    "prime": (0.2, 0.8, 0.9),
-    "extend": (0.9, 0.8, 0.2),
-    "projection": (0.9, 0.6, 0.5)
-}
-
-
-def restore_bgl_defaults():
-    bgl.glLineWidth(1)
-    bgl.glDisable(bgl.GL_BLEND)
-    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
-
-
-def get_projection_coords(self):
-    list2d = [val for key, val in self.xvectors.items()]
-    list2d = [[p, self.bm.verts[pidx].co] for (p, pidx) in list2d]
-    return list(itertools.chain.from_iterable(list2d))
-
-
-def get_extender_coords(self):
-    coords = []
-    for idx in self.selected_edges:
-        c = cm.coords_tuple_from_edge_idx(self.bm, idx)
-        coords.extend(c)
-    return coords
-
-
-def add_or_remove_new_edge(self, idx):
-    '''
-        - only add idx if not edge_prime
-        - and not currently present in selected_edges
-    '''
-    p_idx = self.edge_prime_idx
-
-    if idx == p_idx:
-        print(idx, 'is edge prime, not adding')
-        return
-
-    if (idx in self.selected_edges):
-        self.selected_edges.remove(idx)
-        del self.xvectors[idx]
-    else:
-        edge_prime = cm.coords_tuple_from_edge_idx(self.bm, p_idx)
-        edge2 = cm.coords_tuple_from_edge_idx(self.bm, idx)
-        p = cm.get_intersection(edge_prime, edge2)
-
-        if not cm.point_on_edge(p, edge_prime):
-            return
-
-        vert_idx_closest = cm.closest_idx(p, self.bm.edges[idx])
-        self.xvectors[idx] = [p, vert_idx_closest]
-        self.selected_edges.append(idx)
-
-
-def set_mesh_data(self):
-    history = self.bm.select_history
-    if not (len(history) > 0):
-        return
-
-    a = history[-1]
-    if not isinstance(a, bmesh.types.BMEdge):
-        return
-
-    add_or_remove_new_edge(self, a.index)
-    a.select = False
-
-
-def draw_callback_px(self, context, event):
-
-    if context.mode != "EDIT_MESH":
-        return
-
-    # get screen information
-    region = context.region
-    rv3d = context.space_data.region_3d
-    this_object = context.active_object
-    matrix_world = this_object.matrix_world
-    # scene = context.scene
-
-    def draw_gl_strip(coords, line_thickness):
-        bgl.glLineWidth(line_thickness)
-        bgl.glBegin(bgl.GL_LINES)
-        for coord in coords:
-            vector3d = matrix_world * coord
-            vector2d = loc3d2d(region, rv3d, vector3d)
-            bgl.glVertex2f(*vector2d)
-        bgl.glEnd()
-
-    def draw_edge(coords, mode, lt):
-        bgl.glColor3f(*line_colors[mode])
-        draw_gl_strip(coords, lt)
-
-    def do_single_draw_pass(self):
-
-        # draw edge prime
-        c = cm.coords_tuple_from_edge_idx(self.bm, self.edge_prime_idx)
-        draw_edge(c, "prime", 3)
-
-        # draw extender edges and projections.
-        if len(self.selected_edges) > 0:
-
-            # get and draw selected valid

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list