Hi guy this is what i got so far, this is a code i use to study a solution to a problem, i think that is’not matematically correct but logically work
this is th code in the hope that someone can get a better solution…
the main idea is to replicate the dupli extrude function.
but the problem is that some value don’t correspond to the reality, i.e the angle: when you move the mouse the angle reported is not correct, it seems out of some degree, and the second is that the angle don’t become negative in the right postion.
import bpy, mathutils
from bpy.props import IntProperty, FloatProperty
from bpy_extras.view3d_utils import region_2d_to_vector_3d, region_2d_to_location_3d
breakpoint= bpy.types.bp.bp
class ModalOperator(bpy.types.Operator):
bl_idname = "object.modal_operator"
bl_label = "Simple Modal Operator"
bl_options = {'UNDO'}
is_drawing = False
def modal(self, context, event):
if event.type == 'MOUSEMOVE' and self.is_drawing:
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
coord = event.mouse_region_x, event.mouse_region_y
region = context.region
rv3d = context.space_data.region_3d
vec = region_2d_to_vector_3d(region, rv3d, coord)
loc = region_2d_to_location_3d(region, rv3d, coord, vec)
face =bpy.context.object.data.faces.active
face_center = bpy.context.active_object.data.faces[face].center
increment = (loc - face_center).length
g = rv3d.view_matrix[2]
#print (g)
axis = mathutils.Vector((g.x,g.y,g.z))
if loc >= face_center:
print ('a')
angle = face_center.angle(loc)#*180/3.14
angle_2 = face_center.angle(loc)*180/3.14
else:
print('-a')
angle = -(face_center.angle(loc))#*180/3.14)
breakpoint(locals())
if increment >= 5 :
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.transform.rotate(value=(angle,),axis=(axis))
bpy.ops.mesh.extrude_region_move(MESH_OT_extrude={"type":'REGION'}, TRANSFORM_OT_translate={"value":(loc) })
bpy.ops.transform.translate(value =(-face_center))
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.mode_set(mode='EDIT')
if event.type == 'LEFTMOUSE':
if event.value == 'PRESS':
self.is_drawing = True
elif event.value == 'RELEASE':
self.is_drawing = False
elif event.type in {'RIGHTMOUSE', 'ESC'}:
context.object.location.x = self.first_value
return {'CANCELLED'}
return {'RUNNING_MODAL'}
def invoke(self, context, event):
if context.object:
context.window_manager.modal_handler_add(self)
self.first_mouse_x = event.mouse_x
self.first_value = context.object.location.x
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "No active object, could not finish")
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalOperator)
def unregister():
bpy.utils.unregister_class(ModalOperator)
if __name__ == "__main__":
register()
i suggest to download the breakpoint script to see how the variable change in real time. However the main idea is to get the angle between the face center and the cursor location and use it to rotate the selected face and the extrude.