[Bf-extensions-cvs] [a5cc80e] master: part fix for overlapping faces in inset fillet by max12345 translation of code comments for mextrude
Brendon Murphy
noreply at git.blender.org
Mon Oct 13 17:39:41 CEST 2014
Commit: a5cc80e58976aa5853a9df3acfa9b57a205266ec
Author: Brendon Murphy
Date: Tue Oct 14 02:39:18 2014 +1100
Branches: master
https://developer.blender.org/rBACa5cc80e58976aa5853a9df3acfa9b57a205266ec
part fix for overlapping faces in inset fillet by max12345
translation of code comments for mextrude
===================================================================
M mesh_extra_tools/face_inset_fillet.py
M mesh_extra_tools/mesh_mextrude_plus.py
===================================================================
diff --git a/mesh_extra_tools/face_inset_fillet.py b/mesh_extra_tools/face_inset_fillet.py
index bc4824e..4baf329 100644
--- a/mesh_extra_tools/face_inset_fillet.py
+++ b/mesh_extra_tools/face_inset_fillet.py
@@ -10,7 +10,7 @@
#
# 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
@@ -19,6 +19,7 @@
#
# ***** END GPL LICENCE BLOCK *****
# based completely on addon by zmj100
+# added some distance limits to prevent overlap - max12345
# ------ ------
import bpy
import bmesh
@@ -33,103 +34,152 @@ def edit_mode_out():
def edit_mode_in():
bpy.ops.object.mode_set(mode = 'EDIT')
-def a_rot(ang, rp, axis, q):
- return (Matrix.Rotation(ang, 3, axis) * (q - rp)) + rp
+def angle_rotation(rp,q,axis,angle):
+ """returns the vector made by the rotation of the vector q - rp by angle around axis and then adds rp"""
+ return (Matrix.Rotation(angle, 3, axis) * (q - rp)) + rp
# ------ ------
-def f_(bme, list_0, opp, adj1, n_, out, radius, en0, kp):
+def face_inset_fillet(bme, face_index_list, inset_amount, distance, number_of_sides, out, radius, type_enum, kp):
list_del = []
- for fi in list_0:
- f = bme.faces[fi]
+ for faceindex in face_index_list:
+ #loops through the faces...
+ f = bme.faces[faceindex]
f.select_set(0)
list_del.append(f)
f.normal_update()
- list_2 = [v.index for v in f.verts]
+ vertex_index_list = [v.index for v in f.verts]
dict_0 = {}
- list_1 = []
- n = len(list_2)
+ orientation_vertex_list = []
+ n = len(vertex_index_list)
for i in range(n):
+ #loops through the vertices
dict_0[i] = []
- p = (bme.verts[ list_2[i] ].co).copy()
- p1 = (bme.verts[ list_2[(i - 1) % n] ].co).copy()
- p2 = (bme.verts[ list_2[(i + 1) % n] ].co).copy()
- dict_0[i].append(bme.verts[list_2[i]])
+ p = (bme.verts[ vertex_index_list[i] ].co).copy()
+ p1 = (bme.verts[ vertex_index_list[(i - 1) % n] ].co).copy()
+ p2 = (bme.verts[ vertex_index_list[(i + 1) % n] ].co).copy()
+ #copies some vert coordinates, always the 3 around i
+ dict_0[i].append(bme.verts[vertex_index_list[i]])
+ #appends the bmesh vert of the appropriate index to the dict
vec1 = p - p1
vec2 = p - p2
- ang = vec1.angle(vec2)
- adj = opp / tan(ang * 0.5)
- h = (adj ** 2 + opp ** 2) ** 0.5
- if round(degrees(ang)) == 180 or round(degrees(ang)) == 0.0:
- p6 = a_rot(radians(90), p, vec1, p + ((f.normal).normalized() * opp) if out == True else p - ((f.normal).normalized() * opp))
- list_1.append(p6)
+ #vectors for the other corner points to the cornerpoint
+ #corresponding to i/p
+ angle = vec1.angle(vec2)
+
+ adj = inset_amount / tan(angle * 0.5)
+ h = (adj ** 2 + inset_amount ** 2) ** 0.5
+ if round(degrees(angle)) == 180 or round(degrees(angle)) == 0.0:
+ #if they corer is a straight line...
+ #I think this creates some new points...
+ if out == True:
+ val=((f.normal).normalized() * inset_amount)
+ else:
+ val=-((f.normal).normalized() * inset_amount)
+ p6 = angle_rotation(p,p + val,vec1,radians(90))
else:
- p6 = a_rot(-radians(90), p, ((p - (vec1.normalized() * adj)) - (p - (vec2.normalized() * adj))), p + ((f.normal).normalized() * h) if out == True else p - ((f.normal).normalized() * h))
- list_1.append(p6)
-
- list_2 = []
- n1_ = len(list_1)
- for j in range(n1_):
- q = list_1[j]
- q1 = list_1[(j - 1) % n1_]
- q2 = list_1[(j + 1) % n1_]
+ #if the corner is an actual corner
+ val=((f.normal).normalized() * h)
+ if out==True:
+ #this shit -(p - (vec2.normalized() * adj))) is just the freaking axis afaik...
+ p6 = angle_rotation(p,p + val, -(p - (vec2.normalized() * adj)),-radians(90))
+ else:
+ p6 = angle_rotation(p,p - val,((p - (vec1.normalized() * adj)) - (p - (vec2.normalized() * adj))),
+ -radians(90))
+
+ orientation_vertex_list.append(p6)
+
+ new_inner_face = []
+ orientation_vertex_list_length = len(orientation_vertex_list)
+ ovll=orientation_vertex_list_length
+ for j in range(ovll):
+ q = orientation_vertex_list[j]
+ q1 = orientation_vertex_list[(j - 1) % ovll]
+ q2 = orientation_vertex_list[(j + 1) % ovll]
+ #again, these are just vectors between somewhat displaced conernervertices
vec1_ = q - q1
vec2_ = q - q2
ang_ = vec1_.angle(vec2_)
+ #the angle between them
if round(degrees(ang_)) == 180 or round(degrees(ang_)) == 0.0:
+ #again... if it's really a line...
bme.verts.new(q)
bme.verts.index_update()
- list_2.append(bme.verts[-1])
+ new_inner_face.append(bme.verts[-1])
dict_0[j].append(bme.verts[-1])
else:
- opp_ = adj1
+ #s.a.
+
if radius == False:
- h_ = adj1 * (1 / cos(ang_ * 0.5))
- d = adj1
+ h_ = distance * (1 / cos(ang_ * 0.5))
+ d = distance
elif radius == True:
- h_ = opp_ / sin(ang_ * 0.5)
- d = opp_ / tan(ang_ * 0.5)
-
+ h_ = distance / sin(ang_ * 0.5)
+ d = distance / tan(ang_ * 0.5)
+ #max(d) is vec1_.magnitude*0.5
+ #or vec2_.magnitude*0.5 respectively
+
+ #only functional difference v
+
+ if d >vec1_.magnitude*0.5:
+ d=vec1_.magnitude*0.5
+ if d >vec2_.magnitude*0.5:
+ d=vec2_.magnitude*0.5
+
+ #only functional difference ^
+
q3 = q - (vec1_.normalized() * d)
q4 = q - (vec2_.normalized() * d)
+ #these are new verts somewhat offset from the coners
rp_ = q - ((q - ((q3 + q4) * 0.5)).normalized() * h_)
+ #reference point inside the curvature
axis_ = vec1_.cross(vec2_)
+ #this should really be just the face normal
vec3_ = rp_ - q3
vec4_ = rp_ - q4
rot_ang = vec3_.angle(vec4_)
- list_3 = []
+ cornerverts = []
- for o in range(n_ + 1):
- q5 = a_rot((rot_ang * o / n_), rp_, axis_, q4)
+ for o in range(number_of_sides + 1):
+
+ #this calculates the actual new vertices
+
+ q5 = angle_rotation(rp_,q4,axis_,rot_ang * o / number_of_sides)
bme.verts.new(q5)
+
+ #creates new bmesh vertices from it
+
bme.verts.index_update()
dict_0[j].append(bme.verts[-1])
- list_3.append(bme.verts[-1])
- list_3.reverse()
- list_2.extend(list_3)
+ cornerverts.append(bme.verts[-1])
+
+ cornerverts.reverse()
+ new_inner_face.extend(cornerverts)
if out == False:
- bme.faces.new(list_2)
+ bme.faces.new(new_inner_face)
bme.faces.index_update()
bme.faces[-1].select_set(1)
elif out == True and kp == True:
- bme.faces.new(list_2)
+ bme.faces.new(new_inner_face)
bme.faces.index_update()
bme.faces[-1].select_set(1)
n2_ = len(dict_0)
+ #these are the new side faces, those that don't depend on cornertype
for o in range(n2_):
list_a = dict_0[o]
list_b = dict_0[(o + 1) % n2_]
bme.faces.new( [ list_a[0], list_b[0], list_b[-1], list_a[1] ] )
bme.faces.index_update()
-
- if en0 == 'opt0':
+ #cornertype 1 - ngon faces
+ if type_enum == 'opt0':
for k in dict_0:
if len(dict_0[k]) > 2:
bme.faces.new(dict_0[k])
bme.faces.index_update()
- if en0 == 'opt1':
+ #cornertype 2 - triangulated faces
+ if type_enum == 'opt1':
for k_ in dict_0:
q_ = dict_0[k_][0]
dict_0[k_].pop(0)
@@ -149,78 +199,79 @@ class faceinfillet_op0(bpy.types.Operator):
bl_description = 'inset selected faces'
bl_options = {'REGISTER', 'UNDO'}
- opp = FloatProperty( name = '', default = 0.04, min = 0, max = 100.0, step = 1, precision = 3 ) # inset amount
- n_ = IntProperty( name = '', default = 4, min = 1, max = 100, step = 1 ) # number of sides
- adj1 = FloatProperty( name = '', default = 0.04, min = 0.00001, max = 100.0, step = 1, precision = 3 )
+ inset_amount = FloatProperty( name = '', default = 0.04, min = 0, max = 100.0, step = 1, precision = 3 ) # inset amount
+ number_of_sides = IntProperty( name = '', default = 4, min = 1, max = 100, step = 1 ) # number of sides
+ distance = FloatProperty( name = '', default = 0.04, min = 0.00001, max = 100.0, step = 1, precision
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list