[Bf-extensions-cvs] [2adbf3e] master: convert dir to alternative new version
zeffii
noreply at git.blender.org
Wed Jul 13 19:42:22 CEST 2016
Commit: 2adbf3e6aec8f99002fe21e200b0bd2e4a079068
Author: zeffii
Date: Wed Jul 13 19:39:17 2016 +0200
Branches: master
https://developer.blender.org/rBAC2adbf3e6aec8f99002fe21e200b0bd2e4a079068
convert dir to alternative new version
===================================================================
M mesh_tinyCAD/CCEN.py
M mesh_tinyCAD/CFG.py
M mesh_tinyCAD/V2X.py
M mesh_tinyCAD/VTX.py
M mesh_tinyCAD/XALL.py
M mesh_tinyCAD/__init__.py
M mesh_tinyCAD/cad_module.py
===================================================================
diff --git a/mesh_tinyCAD/CCEN.py b/mesh_tinyCAD/CCEN.py
index 7672c88..67a47ab 100644
--- a/mesh_tinyCAD/CCEN.py
+++ b/mesh_tinyCAD/CCEN.py
@@ -27,66 +27,6 @@ from mathutils import geometry
from mathutils import Vector
-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!
-
- props = bpy.context.scene.tinycad_props
- layer.color = props.gp_color
- rescale = props.rescale
-
- 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) * rescale)) # + 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):
'''
@@ -128,7 +68,7 @@ def generate_bmesh_repr(p1, v1, axis, num_verts):
bmesh.update_edit_mesh(me, True)
-def generate_3PT(pts, obj, nv, mode=0):
+def generate_3PT(pts, obj, nv, mode=1):
origin = obj.location
mw = obj.matrix_world
V = Vector
@@ -155,11 +95,7 @@ def generate_3PT(pts, obj, nv, mode=0):
bpy.context.scene.cursor_location = cp
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']
+ pass
elif mode == 1:
generate_bmesh_repr(p1, v1, axis, nv)
@@ -175,22 +111,31 @@ 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()
+ bm.verts.ensure_lookup_table()
+ bm.edges.ensure_lookup_table()
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)
- props = context.scene.tinycad_props
- generate_3PT(pts, obj, props.num_verts, mode)
-
+ try:
+ obj = context.edit_object
+ pts = get_three_verts_from_selection(obj)
+ props = context.scene.tinycad_props
+ generate_3PT(pts, obj, props.num_verts, mode)
+ except:
+ print('oops, dispatch failed', mode)
''' Operators '''
+class TCCallBackCCEN(bpy.types.Operator):
+ bl_idname = 'tinycad.reset_circlescale'
+ bl_label = 'CCEN circle reset'
+ bl_options = {'REGISTER'}
+
+ def execute(self, context):
+ context.scene.tinycad_props.rescale = 1
+ return {'FINISHED'}
class TCCircleCenter(bpy.types.Operator):
@@ -203,41 +148,24 @@ class TCCircleCenter(bpy.types.Operator):
l = self.layout
col = l.column()
- col.prop(scn.tinycad_props, 'gp_color', text='layer color')
col.prop(scn.tinycad_props, 'num_verts', text='num verts')
- col.prop(scn.tinycad_props, 'rescale', text='rescale')
- col.operator('tinycad.circlemake', text='Make Mesh')
+ row = col.row(align=True)
+ row.prop(scn.tinycad_props, 'rescale', text='rescale')
+ row.operator('tinycad.reset_circlescale', text="", icon="LINK")
+
@classmethod
- def poll(self, context):
+ def poll(cls, context):
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 TCCircleMake(bpy.types.Operator):
- """this is a private op, used by the TCCircleCenter Op only"""
- bl_idname = 'tinycad.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.tinycad_props, 'num_verts', text='num verts')
-
- def execute(self, context):
- dispatch(context, mode=1) # bake mesh
+ dispatch(context, mode=1)
return {'FINISHED'}
def register():
bpy.utils.register_module(__name__)
-
def unregister():
bpy.utils.unregister_module(__name__)
diff --git a/mesh_tinyCAD/CFG.py b/mesh_tinyCAD/CFG.py
index 07f36dd..ddd2630 100644
--- a/mesh_tinyCAD/CFG.py
+++ b/mesh_tinyCAD/CFG.py
@@ -1,12 +1,11 @@
import bpy
+import os
+ICONS = 'BIX CCEN V2X VTX XALL E2F'.split(' ')
+icon_collection = {}
-class TinyCADProperties(bpy.types.PropertyGroup):
- gp_color = bpy.props.FloatVectorProperty(
- default=(0.2, 0.90, .2),
- subtype='COLOR',
- min=0.0, max=1.0)
+class TinyCADProperties(bpy.types.PropertyGroup):
num_verts = bpy.props.IntProperty(
min=3, max=60, default=12)
@@ -24,14 +23,35 @@ class VIEW3D_MT_edit_mesh_tinycad(bpy.types.Menu):
def poll(cls, context):
return bool(context.object)
+
def draw(self, context):
- operator = self.layout.operator
- operator('tinycad.autovtx', text='VTX | AUTO')
- operator('tinycad.vertintersect', text='V2X | Vertex at intersection')
- operator('tinycad.intersectall', text='XALL | Intersect selected edges')
- operator('tinycad.linetobisect', text='BIX | Bisector of 2 planar edges')
- operator('tinycad.circlecenter', text='CCEN | Resurrect circle center')
- operator('tinycad.edge_to_face', text='E2F | Extend Edge to Face')
+
+ pcoll = icon_collection["main"]
+ def cicon(name):
+ return pcoll[name].icon_id
+
+ op = self.layout.operator
+ op('tinycad.autovtx', text='VTX | AUTO', icon_value=cicon('VTX'))
+ op('tinycad.vertintersect', text='V2X | Vertex at intersection', icon_value=cicon('V2X'))
+ op('tinycad.intersectall', text='XALL | Intersect selected edges', icon_value=cicon('XALL'))
+ op('tinycad.linetobisect', text='BIX | Bisector of 2 planar edges', icon_value=cicon('BIX'))
+ op('tinycad.circlecenter', text='CCEN | Resurrect circle center', icon_value=cicon('CCEN'))
+ op('tinycad.edge_to_face', text='E2F | Extend Edge to Face', icon_value=cicon('E2F'))
+
+
+def register_icons():
+ import bpy.utils.previews
+ pcoll = bpy.utils.previews.new()
+ icons_dir = os.path.join(os.path.dirname(__file__), "icons")
+ for icon_name in ICONS:
+ pcoll.load(icon_name, os.path.join(icons_dir, icon_name + '.png'), 'IMAGE')
+
+ icon_collection["main"] = pcoll
+
+def unregister_icons():
+ for pcoll in icon_collection.values():
+ bpy.utils.previews.remove(pcoll)
+ icon_collection.clear()
def register():
diff --git a/mesh_tinyCAD/V2X.py b/mesh_tinyCAD/V2X.py
index 6d62989..55d2d8c 100644
--- a/mesh_tinyCAD/V2X.py
+++ b/mesh_tinyCAD/V2X.py
@@ -35,16 +35,17 @@ def add_vertex_to_intersection():
[[v1, v2], [v3, v4]] = [[v.co for v in e.verts] for e in edges]
iv = geometry.intersect_line_line(v1, v2, v3, v4)
- iv = (iv[0] + iv[1]) / 2
- bm.verts.new(iv)
+ if iv:
+ 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()
+ # 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)
+ bm.verts[-1].select = True
+ bmesh.update_edit_mesh(me)
class TCVert2Intersection(bpy.types.Operator):
diff --git a/mesh_tinyCAD/VTX.py b/mesh_tinyCAD/VTX.py
index 214e3aa..754d2ce 100644
--- a/mesh_tinyCAD/VTX.py
+++ b/mesh_tinyCAD/VTX.py
@@ -1,147 +1,142 @@
import bpy
-import sys
import bmesh
-from mathutils import Vector
-from mathutils.geometry import intersect_line_line as LineIntersect
-from mathutils.geometry import intersect_point_line as PtLineIntersect
+import sys
from . import cad_module as cm
+messages = {
+ 'SHARED_VERTEX': 'Shared Vertex, no intersection possible',
+ 'PARALLEL_EDGES': 'Edges Parallel, no intersection possible',
+ 'NON_PLANAR_EDGES': 'Non Planar Edges, no clean intersection point'
+}
+
+def add_edges(bm, pt, idxs, fdp):
+ '''
+ this function is a disaster --
+ index updates and ensure_lookup_table() are called before this function
+ and after, and i've tried doing this less verbose but results tend to be
+ less predictable. I'm obviously a terrible coder, but can only spend so
+ much time figuring out this stuff.
+ '''
-def getVTX(self):
- self.idx1, self.idx2 = self.selected_edges
- self.edge1 = cm.coords_tuple_from_edge_idx(self.bm, self.idx1)
- self.edge2 = cm.coords_tuple_from_edge_idx(self.bm, self.idx2)
- self.point = cm.get_intersection(self.edge1, self.edge2)
- self.edges = cm.find_intersecting_edges(
- self.bm, self.point, self.idx1, s
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list