[Bf-extensions-cvs] [08de0de] master: Snap Utilities Line: New arrangement for the properties panel
Germano Cavalcante
noreply at git.blender.org
Mon Apr 10 01:54:30 CEST 2017
Commit: 08de0de45e902114a085a47e03fdfed95e24d994
Author: Germano Cavalcante
Date: Sun Apr 9 20:53:52 2017 -0300
Branches: master
https://developer.blender.org/rBA08de0de45e902114a085a47e03fdfed95e24d994
Snap Utilities Line: New arrangement for the properties panel
And also adapted to pep8.
Patch of lijenstina. Thanks :)
===================================================================
M mesh_snap_utilities_line.py
===================================================================
diff --git a/mesh_snap_utilities_line.py b/mesh_snap_utilities_line.py
index 2e07fa8..749c5e1 100644
--- a/mesh_snap_utilities_line.py
+++ b/mesh_snap_utilities_line.py
@@ -1,4 +1,4 @@
-### BEGIN GPL LICENSE BLOCK #####
+# ##### 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
@@ -20,23 +20,38 @@
# Twitter: wii_mano @mano_wii
bl_info = {
- "name": "Snap_Utilities_Line",
+ "name": "Snap Utilities Line",
"author": "Germano Cavalcante",
- "version": (5, 7, 1),
+ "version": (5, 7, 2),
"blender": (2, 75, 0),
"location": "View3D > TOOLS > Snap Utilities > snap utilities",
"description": "Extends Blender Snap controls",
- "wiki_url" : "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities",
+ "wiki_url": "http://blenderartists.org/forum/showthread.php?363859-Addon-CAD-Snap-Utilities",
"tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
"category": "Mesh"}
-import bpy, bgl, bmesh
+import bpy
+import bgl
+import bmesh
from mathutils import Vector
from mathutils.geometry import (
- intersect_point_line,
- intersect_line_line,
- intersect_line_plane,
- intersect_ray_tri)
+ intersect_point_line,
+ intersect_line_line,
+ intersect_line_plane,
+ intersect_ray_tri
+ )
+from bpy.types import (
+ Operator,
+ Panel,
+ AddonPreferences,
+ )
+from bpy.props import (
+ BoolProperty,
+ FloatProperty,
+ FloatVectorProperty,
+ StringProperty,
+ )
+
def get_units_info(scale, unit_system, separate_units):
if unit_system == 'METRIC':
@@ -52,7 +67,8 @@ def get_units_info(scale, unit_system, separate_units):
return (scale, scale_steps, separate_units)
-def convert_distance(val, units_info, precision = 5):
+
+def convert_distance(val, units_info, precision=5):
scale, scale_steps, separate_units = units_info
sval = val * scale
idx = 0
@@ -79,6 +95,7 @@ def convert_distance(val, units_info, precision = 5):
idx += 1
return dval
+
def location_3d_to_region_2d(region, rv3d, coord):
prj = rv3d.perspective_matrix * Vector((coord[0], coord[1], coord[2], 1.0))
width_half = region.width / 2.0
@@ -88,11 +105,13 @@ def location_3d_to_region_2d(region, rv3d, coord):
prj.z / prj.w
))
+
def fac_nearest_to_segment_2d(co2v, v2d0, v2d1):
u = v2d1.xy - v2d0.xy
h = co2v.xy - v2d0.xy
return u.dot(h) / u.length_squared
+
def region_2d_to_orig_and_view_vector(region, rv3d, coord, clamp=None):
viewinv = rv3d.view_matrix.inverted()
persinv = rv3d.perspective_matrix.inverted()
@@ -131,20 +150,22 @@ def region_2d_to_orig_and_view_vector(region, rv3d, coord, clamp=None):
view_vector.normalize()
return origin_start, view_vector
+
def out_Location(rv3d, region, orig, vector):
view_matrix = rv3d.view_matrix
- v1 = Vector((int(view_matrix[0][0]*1.5),int(view_matrix[0][1]*1.5),int(view_matrix[0][2]*1.5)))
- v2 = Vector((int(view_matrix[1][0]*1.5),int(view_matrix[1][1]*1.5),int(view_matrix[1][2]*1.5)))
+ v1 = Vector((int(view_matrix[0][0] * 1.5), int(view_matrix[0][1] * 1.5), int(view_matrix[0][2] * 1.5)))
+ v2 = Vector((int(view_matrix[1][0] * 1.5), int(view_matrix[1][1] * 1.5), int(view_matrix[1][2] * 1.5)))
- hit = intersect_ray_tri(Vector((1,0,0)), Vector((0,1,0)), Vector(), (vector), (orig), False)
- if hit == None:
+ hit = intersect_ray_tri(Vector((1, 0, 0)), Vector((0, 1, 0)), Vector(), (vector), (orig), False)
+ if hit is None:
hit = intersect_ray_tri(v1, v2, Vector(), (vector), (orig), False)
- if hit == None:
+ if hit is None:
hit = intersect_ray_tri(v1, v2, Vector(), (-vector), (orig), False)
- if hit == None:
+ if hit is None:
hit = Vector()
return hit
+
class SnapCache():
bvert = None
vco = None
@@ -169,13 +190,13 @@ class SnapCache():
def snap_utilities(
- cache, context, obj_matrix_world,
- bm, mcursor,
- outer_verts = False,
- constrain = None,
- previous_vert = None,
- ignore_obj = None,
- increment = 0.0):
+ cache, context, obj_matrix_world,
+ bm, mcursor,
+ outer_verts=False,
+ constrain=None,
+ previous_vert=None,
+ ignore_obj=None,
+ increment=0.0):
rv3d = context.region_data
region = context.region
@@ -190,7 +211,7 @@ def snap_utilities(
bm.select_history[0].select = False
bm.select_history.clear()
- bpy.ops.view3d.select(location = (int(mcursor.x), int(mcursor.y)))
+ bpy.ops.view3d.select(location=(int(mcursor.x), int(mcursor.y)))
if bm.select_history:
bm_geom = bm.select_history[0]
@@ -201,11 +222,11 @@ def snap_utilities(
if cache.bvert != bm_geom:
cache.bvert = bm_geom
cache.vco = obj_matrix_world * cache.bvert.co
- #cache.v2d = location_3d_to_region_2d(region, rv3d, cache.vco)
+ # cache.v2d = location_3d_to_region_2d(region, rv3d, cache.vco)
if constrain:
location = intersect_point_line(cache.vco, constrain[0], constrain[1])
- #factor = location[1]
+ # factor = location[1]
r_loc = location[0]
else:
r_loc = cache.vco
@@ -224,24 +245,24 @@ def snap_utilities(
pvert_co = obj_matrix_world * previous_vert.co
perp_point = intersect_point_line(pvert_co, cache.v0, cache.v1)
cache.vperp = perp_point[0]
- #factor = point_perpendicular[1]
+ # factor = point_perpendicular[1]
cache.v2dperp = location_3d_to_region_2d(region, rv3d, perp_point[0])
- #else: cache.v2dperp = None
+ # else: cache.v2dperp = None
if constrain:
location = intersect_line_line(constrain[0], constrain[1], cache.v0, cache.v1)
- if location == None:
+ if location is None:
is_increment = True
orig, view_vector = region_2d_to_orig_and_view_vector(region, rv3d, mcursor)
end = orig + view_vector
location = intersect_line_line(constrain[0], constrain[1], orig, end)
r_loc = location[0]
- elif cache.v2dperp and\
- abs(cache.v2dperp[0] - mcursor[0]) < 10 and abs(cache.v2dperp[1] - mcursor[1]) < 10:
- r_type = 'PERPENDICULAR'
- r_loc = cache.vperp
+ elif cache.v2dperp and \
+ abs(cache.v2dperp[0] - mcursor[0]) < 10 and abs(cache.v2dperp[1] - mcursor[1]) < 10:
+ r_type = 'PERPENDICULAR'
+ r_loc = cache.vperp
elif abs(cache.v2dmid[0] - mcursor[0]) < 10 and abs(cache.v2dmid[1] - mcursor[1]) < 10:
r_type = 'CENTER'
@@ -253,7 +274,7 @@ def snap_utilities(
r_type = 'EDGE'
fac = fac_nearest_to_segment_2d(mcursor, cache.v2d0, cache.v2d1)
- fac *= cache.v2d0.z / cache.v2d1.z #convert to fac3d
+ fac *= cache.v2d0.z / cache.v2d1.z # convert to fac3d
r_loc = cache.v0 + fac * (cache.v1 - cache.v0)
elif isinstance(bm_geom, bmesh.types.BMFace):
@@ -262,8 +283,8 @@ def snap_utilities(
if cache.bface != bm_geom:
cache.bface = bm_geom
- cache.fmid = obj_matrix_world*bm_geom.calc_center_median()
- cache.fnor = bm_geom.normal*obj_matrix_world.inverted()
+ cache.fmid = obj_matrix_world * bm_geom.calc_center_median()
+ cache.fnor = bm_geom.normal * obj_matrix_world.inverted()
orig, view_vector = region_2d_to_orig_and_view_vector(region, rv3d, mcursor)
end = orig + view_vector
@@ -273,14 +294,14 @@ def snap_utilities(
is_increment = False
r_loc = intersect_point_line(r_loc, constrain[0], constrain[1])[0]
- else: #OUT
+ else: # OUT
is_increment = True
r_type = 'OUT'
orig, view_vector = region_2d_to_orig_and_view_vector(region, rv3d, mcursor)
face_index = -1
- if cache.out_obj == None:
+ if cache.out_obj is None:
result, r_loc, normal, face_index, cache.out_obj, cache.out_obmat = scene.ray_cast(orig, view_vector)
if result:
r_type = 'FACE'
@@ -349,12 +370,14 @@ def snap_utilities(
return r_loc, r_type, bm_geom, r_len
+
def get_isolated_edges(bmvert):
linked = [e for e in bmvert.link_edges if not e.link_faces]
for e in linked:
linked += [le for v in e.verts if not v.link_faces for le in v.link_edges if le not in linked]
return linked
+
def draw_line(self, obj, Bmesh, bm_geom, location):
if not hasattr(self, 'list_verts'):
self.list_verts = []
@@ -365,7 +388,7 @@ def draw_line(self, obj, Bmesh, bm_geom, location):
if not hasattr(self, 'list_faces'):
self.list_faces = []
- if bm_geom == None:
+ if bm_geom is None:
vertices = (bmesh.ops.create_vert(Bmesh, co=(location)))
self.list_verts.append(vertices['vert'][0])
@@ -379,17 +402,17 @@ def draw_line(self, obj, Bmesh, bm_geom, location):
elif isinstance(bm_geom, bmesh.types.BMEdge):
self.list_edges.append(bm_geom)
- vector_p0_l = (bm_geom.verts[0].co-location)
- vector_p1_l = (bm_geom.verts[1].co-location)
- cross = vector_p0_l.cross(vector_p1_l)/bm_geom.calc_length()
+ vector_p0_l = (bm_geom.verts[0].co - location)
+ vector_p1_l = (bm_geom.verts[1].co - location)
+ cross = vector_p0_l.cross(vector_p1_l) / bm_geom.calc_length()
- if cross < Vector((0.001,0,0)): # or round(vector_p0_l.angle(vector_p1_l), 2) == 3.14:
- factor = vector_p0_l.length/bm_geom.calc_length()
+ if cross < Vector((0.001, 0, 0)): # or round(vector_p0_l.angle(vector_p1_l), 2) == 3.14:
+ factor = vector_p0_l
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list