Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
# ON-SCREEN INSTRUCTIONS:
if flag == 'BEVEL':
main = 'specify bevel amount'
else:
main = 'specify extrusion height'
region = bpy.context.region
rv3d = bpy.context.region_data
instruct = main
if flag == 'BEVEL':
keys_aff = 'LMB, ENTER - confirm, SCROLL - num of segments, M - mode, C - clamp overlap, NUMPAD - value'
keys_nav = ''
keys_neg = 'ESC, RMB - cancel bevel'
else:
keys_aff = 'CTRL - snap, LMB - confirm, ENTER - confirm without bevel, MMB - lock axis, NUMPAD - value'
keys_nav = 'SPACE - change to navigate'
keys_neg = 'ESC, RMB - cancel extrusion'
display_instructions(region, rv3d, instruct, keys_aff, keys_nav, keys_neg)
# ON-SCREEN INSTRUCTIONS:
font_id = 0
# Drawing the small badge near the cursor with the basic instructions:
mouseloc = view3d_utils.location_3d_to_region_2d(region, rv3d, endloc3d) # is this used ?
# np_print(end, endloc, mouseloc)
'''
if badge == True:
square = [[17, 30], [17, 40], [27, 40], [27, 30]]
rectangle = [[27, 30], [27, 40], [67, 40], [67, 30]]
polysymbol = copy.deepcopy(NP020FP.polysymbol)
size = 2
ipx = 29
ipy = 33
size = badge_size
for co in square:
co[0] = round((co[0] * size),0) -(size*10) + mouseloc[0]
co[1] = round((co[1] * size),0) -(size*25) + mouseloc[1]
for co in rectangle:
co[0] = round((co[0] * size),0) -(size*10) + mouseloc[0]
co[1] = round((co[1] * size),0) -(size*25) + mouseloc[1]
for co in polysymbol:
co[0] = round((co[0] * size),0) -(size*10) + mouseloc[0]
co[1] = round((co[1] * size),0) -(size*25) + mouseloc[1]
ipx = round((ipx * size),0) -(size*10) + mouseloc[0]
ipy = round((ipy * size),0) -(size*25) + mouseloc[1]
ipsize = int(6*size)
bgl.glColor4f(0.0, 0.0, 0.0, 0.0)
bgl.glBegin(bgl.GL_TRIANGLE_FAN)
for x,y in square:
bgl.glVertex2f(x,y)
bgl.glEnd()
bgl.glColor4f(1.0, 0.5, 0.0, 1.0)
bgl.glBegin(bgl.GL_TRIANGLE_FAN)
for x,y in rectangle:
bgl.glVertex2f(x,y)
bgl.glEnd()
bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
bgl.glBegin(bgl.GL_LINE_STRIP)
for x,y in polysymbol:
bgl.glVertex2f(x,y)
bgl.glEnd()
bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
blf.position(font_id,ipx,ipy,0)
blf.size(font_id,ipsize,72)
blf.draw(font_id,'CTRL+SNAP')
'''
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
# np_print('7')
np_print('10_callback_EXTRUDE_END')
class NPFPRunExtrude(bpy.types.Operator):
bl_idname = 'object.np_fp_run_extrude'
bl_label = 'NP FP Run Extrude'
bl_options = {'INTERNAL'}
np_print('10_run_EXTRUDE_START')
count = 0
def modal(self, context, event):
context.area.tag_redraw()
self.count += 1
selob = NP020FP.selob
flag = NP020FP.flag # is this used ?
polyob = NP020FP.polyob
phase = NP020FP.phase
if self.count == 1:
if phase == 3:
bpy.ops.view3d.edit_mesh_extrude_move_normal('INVOKE_DEFAULT')
else:
bpy.ops.transform.translate('INVOKE_DEFAULT',
constraint_axis=(False, False, True),
orient_type='NORMAL')
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
np_print('B')
np_print('10_run_EXTRUDE_count_1_INVOKE_DEFAULT')
elif event.type in ('LEFTMOUSE', 'NUMPAD_ENTER') and event.value == 'RELEASE':
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
polyob.select = True
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
polyob.select = False
bpy.ops.object.mode_set(mode='EDIT')
NP020FP.flag = 'BEVEL'
np_print('10_run_EXTRUDE_left_release_FINISHED')
return{'FINISHED'}
elif event.type == 'SPACE':
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
NP020FP.phase = 3.5
NP020FP.flag = 'NAVEX'
np_print('10_run_TRANS_space_FINISHED_flag_NAVIGATE')
return{'FINISHED'}
elif event.type == 'RET':
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
polyob.select = True
bpy.ops.object.transform_apply(location=False, rotation=True, scale=True)
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
bpy.ops.object.select_all(action='DESELECT')
if selob is not polyob:
for ob in selob:
else:
polyob.select = True
NP020FP.startloc3d = (0.0, 0.0, 0.0)
NP020FP.endloc3d = (0.0, 0.0, 0.0)
NP020FP.phase = 0
NP020FP.start = None
NP020FP.end = None
NP020FP.dist = None
NP020FP.polyob = None
NP020FP.flag = 'TRANSLATE'
NP020FP.snap = 'VERTEX'
bpy.context.tool_settings.use_snap = NP020FP.use_snap
bpy.context.tool_settings.snap_element = NP020FP.snap_element
bpy.context.tool_settings.snap_target = NP020FP.snap_target
bpy.context.space_data.pivot_point = NP020FP.pivot_point
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
if NP020FP.acob is not None:
bpy.context.view_layer.objects.active = NP020FP.acob
bpy.ops.object.mode_set(mode=NP020FP.edit_mode)
np_print('10_run_EXTRUDE_space_FINISHED_flag_TRANSLATE')
return{'FINISHED'}
elif event.type in ('ESC', 'RIGHTMOUSE'):
# this actually begins when user RELEASES esc or rightmouse,
# PRESS is taken by transform.translate operator
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles()
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
if selob is not polyob:
for ob in selob:
else:
polyob.select = True
NP020FP.startloc3d = (0.0, 0.0, 0.0)
NP020FP.endloc3d = (0.0, 0.0, 0.0)
NP020FP.phase = 0
NP020FP.start = None
NP020FP.end = None
NP020FP.dist = None
NP020FP.polyob = None
NP020FP.flag = 'TRANSLATE'
NP020FP.snap = 'VERTEX'
bpy.context.tool_settings.use_snap = NP020FP.use_snap
bpy.context.tool_settings.snap_element = NP020FP.snap_element
bpy.context.tool_settings.snap_target = NP020FP.snap_target
bpy.context.space_data.pivot_point = NP020FP.pivot_point
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
if NP020FP.acob is not None:
bpy.context.view_layer.objects.active = NP020FP.acob
bpy.ops.object.mode_set(mode=NP020FP.edit_mode)
np_print('10_run_EXTRUDE_space_CANCELLED_flag_TRANSLATE')
return{'CANCELLED'}
np_print('10_run_EXTRUDE_PASS_THROUGH')
return{'PASS_THROUGH'}
def invoke(self, context, event):
np_print('10_run_EXTRUDE_INVOKE_a')
selob = NP020FP.selob # is this used ?
flag = NP020FP.flag
np_print('flag = ', flag)
polyob = NP020FP.polyob
if flag == 'EXTRUDE':
if context.area.type == 'VIEW_3D':
if bpy.context.mode == 'OBJECT':
bpy.ops.object.select_all(action='DESELECT')
bpy.context.view_layer.objects.active = polyob
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
polyob.select = True
bpy.ops.object.mode_set(mode='EDIT')
polyme = polyob.data
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.remove_doubles()
i = len(polyme.vertices)
i = int(i / 2)
NP020FP.startloc3d = polyme.vertices[0].co
NP020FP.startloc3d = polyme.vertices[i].co
if bpy.context.mode == 'EDIT':
polyme = polyob.data
i = len(polyme.vertices)
i = int(i / 2)
NP020FP.startloc3d = polyme.vertices[0].co
NP020FP.startloc3d = polyme.vertices[i].co
args = (self, context)
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px_EXTRUDE, args,
'WINDOW', 'POST_PIXEL')
context.window_manager.modal_handler_add(self)
np_print('10_run_EXTRUDE_INVOKE_a_RUNNING_MODAL')
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "View3D not found, cannot run operator")
np_print('10_run_EXTRUDE_INVOKE_a_CANCELLED')
return {'CANCELLED'}
else:
np_print('10_run_EXTRUDE_INVOKE_a_FINISHED')
return {'FINISHED'}
class NPFPRunBevel(bpy.types.Operator):
bl_idname = 'object.np_fp_run_bevel'
bl_label = 'NP FP Run Bevel'
bl_options = {'INTERNAL'}
np_print('11_run_BEVEL_START')
count = 0
def modal(self, context, event):
context.area.tag_redraw()
self.count += 1
selob = NP020FP.selob
flag = NP020FP.flag # is this used ?
polyob = NP020FP.polyob
if self.count == 1:
bpy.ops.mesh.bevel('INVOKE_DEFAULT')
np_print('B')
np_print('11_run_BEVEL_count_1_INVOKE_DEFAULT')
elif event.type in ('LEFTMOUSE', 'RET', 'NUMPAD_ENTER', 'SPACE') and event.value == 'RELEASE':
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.mode_set(mode='OBJECT')
NP020FP.flag = 'TRANSLATE'
bpy.ops.object.select_all(action='DESELECT')
if selob is not polyob:
for ob in selob:
else:
polyob.select = True
NP020FP.startloc3d = (0.0, 0.0, 0.0)
NP020FP.endloc3d = (0.0, 0.0, 0.0)
NP020FP.phase = 0
NP020FP.start = None
NP020FP.end = None
NP020FP.dist = None
NP020FP.polyob = None
NP020FP.snap = 'VERTEX'
bpy.context.tool_settings.use_snap = NP020FP.use_snap
bpy.context.tool_settings.snap_element = NP020FP.snap_element
bpy.context.tool_settings.snap_target = NP020FP.snap_target
bpy.context.space_data.pivot_point = NP020FP.pivot_point
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
if NP020FP.acob is not None:
bpy.context.view_layer.objects.active = NP020FP.acob
bpy.ops.object.mode_set(mode=NP020FP.edit_mode)
np_print('10_run_EXTRUDE_left_release_FINISHED')
return{'FINISHED'}
elif event.type in ('RIGHTMOUSE', 'ESC'):
# this actually begins when user RELEASES esc or rightmouse,
# PRESS is taken by transform.translate operator
bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
if selob is not polyob:
for ob in selob:
else:
polyob.select = True
NP020FP.startloc3d = (0.0, 0.0, 0.0)
NP020FP.endloc3d = (0.0, 0.0, 0.0)
NP020FP.phase = 0
NP020FP.start = None
NP020FP.end = None
NP020FP.dist = None
NP020FP.polyob = None
NP020FP.flag = 'TRANSLATE'
NP020FP.snap = 'VERTEX'
bpy.context.tool_settings.use_snap = NP020FP.use_snap
bpy.context.tool_settings.snap_element = NP020FP.snap_element
bpy.context.tool_settings.snap_target = NP020FP.snap_target
bpy.context.space_data.pivot_point = NP020FP.pivot_point
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
if NP020FP.acob is not None:
bpy.context.view_layer.objects.active = NP020FP.acob
bpy.ops.object.mode_set(mode=NP020FP.edit_mode)
np_print('11_run_BEVEL_esc_CANCELLED')
return{'CANCELLED'}
np_print('11_run_BEVEL_PASS_THROUGH')
return{'PASS_THROUGH'}
def invoke(self, context, event):
np_print('11_run_BEVEL_INVOKE_a')
addon_prefs = context.preferences.addons[__package__].preferences
bevel = addon_prefs.npfp_bevel
selob = NP020FP.selob
flag = NP020FP.flag
np_print('flag = ', flag)
polyob = NP020FP.polyob
if flag == 'BEVEL' and bevel:
if context.area.type == 'VIEW_3D':
bpy.context.view_layer.objects.active = polyob
bpy.ops.mesh.select_all(action='SELECT')
args = (self, context)
NP020FP.main_BEVEL = 'DESIGNATE BEVEL AMOUNT'
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px_EXTRUDE,
args, 'WINDOW', 'POST_PIXEL')
context.window_manager.modal_handler_add(self)
np_print('11_run_BEVEL_INVOKE_a_RUNNING_MODAL')
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "View3D not found, cannot run operator")
np_print('11_run_BEVEL_INVOKE_a_CANCELLED')
return {'CANCELLED'}
else:
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
if selob is not polyob:
for ob in selob:
else:
polyob.select = True
NP020FP.startloc3d = (0.0, 0.0, 0.0)
NP020FP.endloc3d = (0.0, 0.0, 0.0)
NP020FP.phase = 0
NP020FP.start = None
NP020FP.end = None
NP020FP.dist = None
NP020FP.polyob = None
NP020FP.flag = 'TRANSLATE'
NP020FP.snap = 'VERTEX'
bpy.context.tool_settings.use_snap = NP020FP.use_snap
bpy.context.tool_settings.snap_element = NP020FP.snap_element
bpy.context.tool_settings.snap_target = NP020FP.snap_target
bpy.context.space_data.pivot_point = NP020FP.pivot_point
bpy.context.space_data.transform_orientation = NP020FP.trans_orient
if NP020FP.acob is not None:
bpy.context.view_layer.objects.active = NP020FP.acob
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
bpy.ops.object.mode_set(mode=NP020FP.edit_mode)
np_print('11_run_BEVEL_INVOKE_a_FINISHED')
return {'FINISHED'}
# This is the actual addon process, the algorithm that defines the order of operator activation inside the main macro:
def register():
bpy.app.handlers.scene_update_post.append(scene_update)
NP020FloatPoly.define('OBJECT_OT_np_fp_get_selection')
NP020FloatPoly.define('OBJECT_OT_np_fp_read_mouse_loc')
NP020FloatPoly.define('OBJECT_OT_np_fp_add_points')
for i in range(1, 10):
NP020FloatPoly.define('OBJECT_OT_np_fp_run_translate')
NP020FloatPoly.define('OBJECT_OT_np_fp_run_navigate')
NP020FloatPoly.define('OBJECT_OT_np_fp_change_phase')
for i in range(1, 100):
for i in range(1, 10):
NP020FloatPoly.define('OBJECT_OT_np_fp_run_translate')
NP020FloatPoly.define('OBJECT_OT_np_fp_run_navigate')
NP020FloatPoly.define('OBJECT_OT_np_fp_make_segment')
NP020FloatPoly.define('OBJECT_OT_np_fp_delete_points')
NP020FloatPoly.define('OBJECT_OT_np_fp_make_surface')
for i in range(1, 10):
NP020FloatPoly.define('OBJECT_OT_np_fp_run_extrude')
NP020FloatPoly.define('OBJECT_OT_np_fp_run_navex')
NP020FloatPoly.define('OBJECT_OT_np_fp_run_bevel')
def unregister():
# bpy.app.handlers.scene_update_post.remove(scene_update)
pass