Edge Slide

Compiling, libraries, modules, coding guidelines and porting

Moderators: jesterKing, stiv

Post Reply
Alagarsamy
Posts: 0
Joined: Fri Aug 30, 2013 11:57 am
Location: India

Edge Slide

Post by Alagarsamy » Thu Sep 12, 2013 7:44 am

How do work the edge slide function accurately in the following code?



def edit_mode_out():
bpy.ops.object.mode_set(mode = 'OBJECT')

def edit_mode_in():
bpy.ops.object.mode_set(mode = 'EDIT')

def get_k0n_(ek, f_edge_keys):
tmp = [i for i in f_edge_keys if ek[0] in i]
if ek in tmp:
tmp.remove(ek)
tmp_ek = list(tmp[0])
if ek[0] in tmp_ek:
tmp_ek.remove(ek[0])
return tmp_ek[0]

def get_k1n_(ek, f_edge_keys):
tmp = [i for i in f_edge_keys if ek[1] in i]
if ek in tmp:
tmp.remove(ek)
tmp_ek = list(tmp[0])
if ek[1] in tmp_ek:
tmp_ek.remove(ek[1])
return tmp_ek[0]



# ------ ------
def f_(bme, e, list_1,d):

ev0_tmp = None
ev1_tmp = None




val = d
f = bme.faces[list_1[0]]
ek = tuple([v.index for v in e.verts])
f_edge_keys = [ tuple([v.index for v in e.verts]) for e in f.edges ]

for i in range(4):
if i in list_1:
print("i",i)
ev0 = (bme.verts[ek[0]].co).copy()
ev1 = (bme.verts[ek[1]].co).copy()

ev0n0 = (bme.verts[get_k0n_(ek, f_edge_keys)].co).copy()
ev1n0 = (bme.verts[get_k1n_(ek, f_edge_keys)].co).copy()

vec0 = (ev0n0 - ev0)
vec1 = (ev1n0 - ev1)
x = vec0.angle((ev1 - ev0), any)
y = vec1.angle((ev0 - ev1), any)

ev0_ang = round(x , 3)

ev1_ang = round(y , 3)

ev0_tmp = ev0 + (vec0.normalized() * d)

ev1_tmp = ev1 + (vec1.normalized() * d)



# -- -- -- --
if ev0_tmp == None:
pass
else:

bme.verts[ek[0]].co = ev0_tmp
bme.verts[ek[1]].co = ev1_tmp


class es_op0(bpy.types.Operator):
bl_idname = 'es.op0_id'
bl_label = 'Edge Slide'
bl_options = {'REGISTER', 'UNDO'}

d = FloatProperty( name = '', default = 0.1, min = -1.0, max = 1.0, step = 1, precision = 3 ) # distance
correct_uv = BoolProperty(name = "Correct uv", description ="" , default = False)
release = BoolProperty(name="release on confirm", description="release on confirm", default=False)
@classmethod
def poll(cls, context):
return (context.active_object and context.active_object.type == 'MESH' and context.mode == 'EDIT_MESH')

def draw(self,context):
layout = self.layout
layout.label("factor")
layout.prop(self, 'd',slider = True)
layout.prop(self, 'correct_uv')
layout.prop(self, 'release')

def execute(self, context):

if self.correct_uv == True:
uv = True
else:
uv = False
if self.release == True:
release = True
else:
release = False
bpy.ops.transform.edge_slide(value = self.d, mirror=False, snap=False, snap_target='CLOSEST', snap_point=(0, 0, 0), snap_align=False, snap_normal=(0, 0, 0), correct_uv= uv, release_confirm=release)

return {'FINISHED'}

def dir_1(self,offset,min,max):
global x
offset_value = offset
offset_value = round(offset_value,3)
if offset_value >= max:
offset_value = max

if offset_value <= min:
offset_value = min

return offset_value

def dir_2(self,offset,min,max):

global y
offset_value = offset
offset_value = round(offset_value,3)
if offset_value >= max:
offset_value = max
if offset_value <= min:
offset_value = min

return offset_value

def list(self,a,b):
for s,n in zip(a,b):
y = [n,s]
print(y)
return y
def modal(self, context, event):

mesh = context.object.data
bm=bmesh.from_edit_mesh(mesh)
totface = mesh.total_face_sel
#list = [ e.index for e in bm.edges if e.select and e.is_valid]

#print ("list :",list)
if event.type == 'MOUSEMOVE':
global ti, delta1, deltay1
delta = delta1 - event.mouse_x
delta1 = delta1 - delta
tot = delta - 2 * 0.2
total = tot/100
a = ti - total
min = -0.33
max = 0.33
value = 0
v = 0
if a > ti:
v += 0.01
off = self.dir_1(v,min,max)
value -= off

elif a < ti:
v -= 0.01
off = self.dir_2(v,min,max)
value -= off

self.d = off
d = self.d

edit_mode_out()
ob_act = context.active_object
bme = bmesh.new()
bme.from_mesh(ob_act.data)
a = []
b = []
list_0 = [ e.index for e in bme.edges if e.select and e.is_valid ]
#print("list0",list_0)

for ei in list_0:
e = bme.edges[ei]

list_1 = [f.index for f in e.link_faces] # list of faces (face indices) connected to this edge
#print("list",list_1)

f_(bme, e, list_1,d)
bme.to_mesh(ob_act.data)
edit_mode_in()

elif event.type == 'LEFTMOUSE':
ti = 0
delta1=0
deltay1=0
x = 0
return {'FINISHED'}

elif event.type in {'RIGHTMOUSE', 'ESC'}:
ti = 0
delta1=0
deltay1=0
x = 0
return {'FINISHED'}
return {'RUNNING_MODAL'}

def invoke(self, context, event):
if context.object:
self.first_mouse_x = event.mouse_x
self.first_mouse_y = event.mouse_y
self.operator_context = 'INVOKE_DEFAULT'
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "No active object, could not finish")
return {'CANCELLED'}
return {'FINISHED'}



Pls, Help me......
Thank you........

Post Reply