Cleanup: formatting using autopep8
This commit is contained in:
parent
84367c7d8e
commit
16c87dcfb5
|
@ -10,7 +10,7 @@ bl_info = {
|
|||
"blender": (3, 2, 0),
|
||||
"location": "View3D > TOOLS > Line Tool",
|
||||
"description": "Extends Blender Snap controls",
|
||||
"doc_url" : "{BLENDER_MANUAL_URL}/addons/mesh/snap_utilities_line.html",
|
||||
"doc_url": "{BLENDER_MANUAL_URL}/addons/mesh/snap_utilities_line.html",
|
||||
"category": "Mesh",
|
||||
}
|
||||
|
||||
|
@ -28,15 +28,19 @@ else:
|
|||
from . import op_line
|
||||
from . import keys
|
||||
|
||||
# autopep8: off
|
||||
import bpy
|
||||
from bpy.utils.toolsystem import ToolDef
|
||||
# autopep8: on
|
||||
|
||||
if not __package__:
|
||||
__package__ = "mesh_snap_utilities_line"
|
||||
|
||||
|
||||
@ToolDef.from_fn
|
||||
def tool_line():
|
||||
import os
|
||||
|
||||
def draw_settings(context, layout, tool):
|
||||
addon_prefs = context.preferences.addons[__package__].preferences
|
||||
|
||||
|
@ -60,7 +64,7 @@ def tool_line():
|
|||
),
|
||||
icon=os.path.join(icons_dir, "ops.mesh.snap_utilities_line"),
|
||||
widget="MESH_GGT_snap_point",
|
||||
#operator="mesh.snap_utilities_line",
|
||||
# operator="mesh.snap_utilities_line",
|
||||
keymap=keys.km_tool_snap_utilities_line,
|
||||
draw_settings=draw_settings,
|
||||
)
|
||||
|
@ -91,7 +95,7 @@ def register_snap_tools():
|
|||
def unregister_snap_tools():
|
||||
tools = get_tool_list('VIEW_3D', 'EDIT_MESH')
|
||||
|
||||
index = tools.index(tool_line) - 1 #None
|
||||
index = tools.index(tool_line) - 1 # None
|
||||
tools.pop(index)
|
||||
tools.remove(tool_line)
|
||||
|
||||
|
@ -109,11 +113,15 @@ def register_keymaps():
|
|||
|
||||
# TODO: find the user defined tool_mouse.
|
||||
from bl_keymap_utils.io import keyconfig_init_from_data
|
||||
keyconfig_init_from_data(kc_defaultconf, keys.generate_empty_snap_utilities_tools_keymaps())
|
||||
keyconfig_init_from_data(kc_addonconf, keys.generate_snap_utilities_keymaps())
|
||||
keyconfig_init_from_data(
|
||||
kc_defaultconf, keys.generate_empty_snap_utilities_tools_keymaps())
|
||||
keyconfig_init_from_data(
|
||||
kc_addonconf, keys.generate_snap_utilities_keymaps())
|
||||
|
||||
#snap_modalkeymap = kc_addonconf.keymaps.find(keys.km_snap_utilities_modal_keymap)
|
||||
#snap_modalkeymap.assign("MESH_OT_snap_utilities_line")
|
||||
# snap_modalkeymap.assign("MESH_OT_snap_utilities_line")
|
||||
|
||||
|
||||
def unregister_keymaps():
|
||||
keyconfigs = bpy.context.window_manager.keyconfigs
|
||||
defaultmap = getattr(keyconfigs.get("Blender"), "keymaps", None)
|
||||
|
@ -152,6 +160,7 @@ classes = (
|
|||
widgets.SnapPointWidgetGroup,
|
||||
)
|
||||
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
|
|
|
@ -5,14 +5,14 @@ import bpy
|
|||
from mathutils import (
|
||||
Vector,
|
||||
Matrix,
|
||||
)
|
||||
)
|
||||
from mathutils.geometry import intersect_point_line
|
||||
from .drawing_utilities import SnapDrawn
|
||||
from .common_utilities import (
|
||||
convert_distance,
|
||||
get_units_info,
|
||||
location_3d_to_region_2d,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class SnapNavigation():
|
||||
|
@ -26,7 +26,6 @@ class SnapNavigation():
|
|||
'_ndof_orbit_zoom',
|
||||
'_ndof_pan')
|
||||
|
||||
|
||||
@staticmethod
|
||||
def debug_key(key):
|
||||
for member in dir(key):
|
||||
|
@ -53,34 +52,44 @@ class SnapNavigation():
|
|||
|
||||
for key in context.window_manager.keyconfigs.user.keymaps['3D View'].keymap_items:
|
||||
if key.idname == 'view3d.rotate':
|
||||
self._rotate.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type, key.value))
|
||||
self._rotate.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), key.type, key.value))
|
||||
elif key.idname == 'view3d.move':
|
||||
self._move.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type, key.value))
|
||||
self._move.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), key.type, key.value))
|
||||
elif key.idname == 'view3d.zoom':
|
||||
if key.type == 'WHEELINMOUSE':
|
||||
self._zoom.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), 'WHEELUPMOUSE', key.value, key.properties.delta))
|
||||
self._zoom.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), 'WHEELUPMOUSE', key.value, key.properties.delta))
|
||||
elif key.type == 'WHEELOUTMOUSE':
|
||||
self._zoom.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), 'WHEELDOWNMOUSE', key.value, key.properties.delta))
|
||||
self._zoom.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), 'WHEELDOWNMOUSE', key.value, key.properties.delta))
|
||||
else:
|
||||
self._zoom.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type, key.value, key.properties.delta))
|
||||
self._zoom.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), key.type, key.value, key.properties.delta))
|
||||
|
||||
elif self.use_ndof:
|
||||
if key.idname == 'view3d.ndof_all':
|
||||
self._ndof_all.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type))
|
||||
self._ndof_all.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), key.type))
|
||||
elif key.idname == 'view3d.ndof_orbit':
|
||||
self._ndof_orbit.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type))
|
||||
self._ndof_orbit.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), key.type))
|
||||
elif key.idname == 'view3d.ndof_orbit_zoom':
|
||||
self._ndof_orbit_zoom.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type))
|
||||
self._ndof_orbit_zoom.add(
|
||||
(self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type))
|
||||
elif key.idname == 'view3d.ndof_pan':
|
||||
self._ndof_pan.add((self.convert_to_flag(key.shift, key.ctrl, key.alt), key.type))
|
||||
|
||||
self._ndof_pan.add((self.convert_to_flag(
|
||||
key.shift, key.ctrl, key.alt), key.type))
|
||||
|
||||
def run(self, context, event, snap_location):
|
||||
evkey = (self.convert_to_flag(event.shift, event.ctrl, event.alt), event.type, event.value)
|
||||
evkey = (self.convert_to_flag(event.shift, event.ctrl,
|
||||
event.alt), event.type, event.value)
|
||||
|
||||
if evkey in self._rotate:
|
||||
if snap_location:
|
||||
bpy.ops.view3d.rotate_custom_pivot('INVOKE_DEFAULT', pivot=snap_location)
|
||||
bpy.ops.view3d.rotate_custom_pivot(
|
||||
'INVOKE_DEFAULT', pivot=snap_location)
|
||||
else:
|
||||
bpy.ops.view3d.rotate('INVOKE_DEFAULT', use_cursor_init=True)
|
||||
return True
|
||||
|
@ -93,7 +102,8 @@ class SnapNavigation():
|
|||
if evkey == key[0:3]:
|
||||
if key[3]:
|
||||
if snap_location:
|
||||
bpy.ops.view3d.zoom_custom_target('INVOKE_DEFAULT', delta=key[3], target=snap_location)
|
||||
bpy.ops.view3d.zoom_custom_target(
|
||||
'INVOKE_DEFAULT', delta=key[3], target=snap_location)
|
||||
else:
|
||||
bpy.ops.view3d.zoom('INVOKE_DEFAULT', delta=key[3])
|
||||
else:
|
||||
|
@ -132,11 +142,11 @@ class CharMap:
|
|||
"c", "m", "d", "k", "h", "a",
|
||||
" ", "/", "*", "'", "\""
|
||||
# "="
|
||||
}
|
||||
}
|
||||
type = {
|
||||
'BACK_SPACE', 'DEL',
|
||||
'LEFT_ARROW', 'RIGHT_ARROW'
|
||||
}
|
||||
}
|
||||
|
||||
def __init__(self, context):
|
||||
scale = context.scene.unit_settings.scale_length
|
||||
|
@ -155,28 +165,34 @@ class CharMap:
|
|||
pos = self.line_pos
|
||||
if ascii == ",":
|
||||
ascii = "."
|
||||
self.length_entered = self.length_entered[:pos] + ascii + self.length_entered[pos:]
|
||||
self.length_entered = self.length_entered[:pos] + \
|
||||
ascii + self.length_entered[pos:]
|
||||
self.line_pos += 1
|
||||
|
||||
if self.length_entered:
|
||||
pos = self.line_pos
|
||||
if type == 'BACK_SPACE':
|
||||
self.length_entered = self.length_entered[:pos - 1] + self.length_entered[pos:]
|
||||
self.length_entered = self.length_entered[:pos -
|
||||
1] + self.length_entered[pos:]
|
||||
self.line_pos -= 1
|
||||
|
||||
elif type == 'DEL':
|
||||
self.length_entered = self.length_entered[:pos] + self.length_entered[pos + 1:]
|
||||
self.length_entered = self.length_entered[:pos] + \
|
||||
self.length_entered[pos + 1:]
|
||||
|
||||
elif type == 'LEFT_ARROW':
|
||||
self.line_pos = (pos - 1) % (len(self.length_entered) + 1)
|
||||
self.line_pos = (
|
||||
pos - 1) % (len(self.length_entered) + 1)
|
||||
|
||||
elif type == 'RIGHT_ARROW':
|
||||
self.line_pos = (pos + 1) % (len(self.length_entered) + 1)
|
||||
self.line_pos = (
|
||||
pos + 1) % (len(self.length_entered) + 1)
|
||||
|
||||
try:
|
||||
self.length_entered_value = bpy.utils.units.to_value(self.unit_system, 'LENGTH', self.length_entered)
|
||||
self.length_entered_value = bpy.utils.units.to_value(
|
||||
self.unit_system, 'LENGTH', self.length_entered)
|
||||
except: # ValueError:
|
||||
self.length_entered_value = 0.0 #invalid
|
||||
self.length_entered_value = 0.0 # invalid
|
||||
#self.report({'INFO'}, "Operation not supported yet")
|
||||
else:
|
||||
self.length_entered_value = 0.0
|
||||
|
@ -236,7 +252,7 @@ class Constrain:
|
|||
vec = self.orientation[self.orientation_id][1]
|
||||
type = 'Y'
|
||||
|
||||
else: # dot_z > dot_y and dot_z > dot_x:
|
||||
else: # dot_z > dot_y and dot_z > dot_x:
|
||||
vec = self.orientation[self.orientation_id][2]
|
||||
type = 'Z'
|
||||
|
||||
|
@ -280,7 +296,7 @@ class Constrain:
|
|||
return True
|
||||
|
||||
def toggle(self):
|
||||
self.rotMat = None # update
|
||||
self.rotMat = None # update
|
||||
if self.preferences.auto_constrain:
|
||||
self.orientation_id = (self.orientation_id + 1) % 2
|
||||
self.preferences.auto_constrain = self.orientation_id != 0
|
||||
|
@ -292,14 +308,18 @@ class Constrain:
|
|||
self.rotMat = rv3d.view_matrix.copy()
|
||||
|
||||
self.center = center.copy()
|
||||
self.center_2d = location_3d_to_region_2d(region, rv3d, self.center)
|
||||
self.center_2d = location_3d_to_region_2d(
|
||||
region, rv3d, self.center)
|
||||
|
||||
vec = self.center + self.orientation[self.orientation_id][0]
|
||||
self.projected_vecs[0] = location_3d_to_region_2d(region, rv3d, vec) - self.center_2d
|
||||
self.projected_vecs[0] = location_3d_to_region_2d(
|
||||
region, rv3d, vec) - self.center_2d
|
||||
vec = self.center + self.orientation[self.orientation_id][1]
|
||||
self.projected_vecs[1] = location_3d_to_region_2d(region, rv3d, vec) - self.center_2d
|
||||
self.projected_vecs[1] = location_3d_to_region_2d(
|
||||
region, rv3d, vec) - self.center_2d
|
||||
vec = self.center + self.orientation[self.orientation_id][2]
|
||||
self.projected_vecs[2] = location_3d_to_region_2d(region, rv3d, vec) - self.center_2d
|
||||
self.projected_vecs[2] = location_3d_to_region_2d(
|
||||
region, rv3d, vec) - self.center_2d
|
||||
|
||||
self.projected_vecs[0].normalize()
|
||||
self.projected_vecs[1].normalize()
|
||||
|
@ -331,12 +351,12 @@ class SnapUtilities:
|
|||
"""
|
||||
|
||||
constrain_keys = {
|
||||
'X': Vector((1,0,0)),
|
||||
'Y': Vector((0,1,0)),
|
||||
'Z': Vector((0,0,1)),
|
||||
'X': Vector((1, 0, 0)),
|
||||
'Y': Vector((0, 1, 0)),
|
||||
'Z': Vector((0, 0, 1)),
|
||||
'RIGHT_SHIFT': 'shift',
|
||||
'LEFT_SHIFT': 'shift',
|
||||
}
|
||||
}
|
||||
|
||||
snapwidgets = []
|
||||
constrain = None
|
||||
|
@ -364,7 +384,6 @@ class SnapUtilities:
|
|||
|
||||
SnapUtilities.constrain = key
|
||||
|
||||
|
||||
def snap_context_update_and_return_moving_objects(self, context):
|
||||
moving_objects = set()
|
||||
moving_snp_objects = set()
|
||||
|
@ -405,7 +424,6 @@ class SnapUtilities:
|
|||
del children
|
||||
return moving_objects, moving_snp_objects
|
||||
|
||||
|
||||
def snap_context_update(self, context):
|
||||
def visible_objects_and_duplis():
|
||||
if self.preferences.outer_verts:
|
||||
|
@ -425,12 +443,12 @@ class SnapUtilities:
|
|||
for obj, matrix in visible_objects_and_duplis():
|
||||
self.sctx.add_obj(obj, matrix)
|
||||
|
||||
|
||||
def snap_context_init(self, context, snap_edge_and_vert=True):
|
||||
from .snap_context_l import global_snap_context_get
|
||||
|
||||
#Create Snap Context
|
||||
self.sctx = global_snap_context_get(context.evaluated_depsgraph_get(), context.region, context.space_data)
|
||||
# Create Snap Context
|
||||
self.sctx = global_snap_context_get(
|
||||
context.evaluated_depsgraph_get(), context.region, context.space_data)
|
||||
ui_scale = context.preferences.system.ui_scale
|
||||
self.sctx.set_pixel_dist(12 * ui_scale)
|
||||
|
||||
|
@ -448,7 +466,7 @@ class SnapUtilities:
|
|||
self.normal = widget.normal
|
||||
|
||||
else:
|
||||
#init these variables to avoid errors
|
||||
# init these variables to avoid errors
|
||||
self.obj = context.active_object
|
||||
self.bm = None
|
||||
self.geom = None
|
||||
|
@ -458,7 +476,7 @@ class SnapUtilities:
|
|||
preferences = context.preferences.addons[__package__].preferences
|
||||
self.preferences = preferences
|
||||
|
||||
#Init DrawCache
|
||||
# Init DrawCache
|
||||
self.draw_cache = SnapDrawn(
|
||||
preferences.out_color,
|
||||
preferences.face_color,
|
||||
|
@ -467,26 +485,32 @@ class SnapUtilities:
|
|||
preferences.center_color,
|
||||
preferences.perpendicular_color,
|
||||
preferences.constrain_shift_color,
|
||||
tuple(context.preferences.themes[0].user_interface.axis_x) + (1.0,),
|
||||
tuple(context.preferences.themes[0].user_interface.axis_y) + (1.0,),
|
||||
tuple(context.preferences.themes[0].user_interface.axis_z) + (1.0,),
|
||||
tuple(
|
||||
context.preferences.themes[0].user_interface.axis_x) + (1.0,),
|
||||
tuple(
|
||||
context.preferences.themes[0].user_interface.axis_y) + (1.0,),
|
||||
tuple(
|
||||
context.preferences.themes[0].user_interface.axis_z) + (1.0,),
|
||||
self.sctx.rv3d,
|
||||
ui_scale)
|
||||
|
||||
self.snap_vert = self.snap_edge = snap_edge_and_vert
|
||||
|
||||
shading = context.space_data.shading
|
||||
self.snap_face = not (snap_edge_and_vert and (shading.show_xray or shading.type == 'WIREFRAME'))
|
||||
self.snap_face = not (snap_edge_and_vert and (
|
||||
shading.show_xray or shading.type == 'WIREFRAME'))
|
||||
|
||||
self.sctx.set_snap_mode(self.snap_vert, self.snap_edge, self.snap_face)
|
||||
|
||||
#Configure the unit of measure
|
||||
# Configure the unit of measure
|
||||
unit_system = context.scene.unit_settings.system
|
||||
scale = context.scene.unit_settings.scale_length
|
||||
scale /= context.space_data.overlay.grid_scale
|
||||
self.rd = bpy.utils.units.to_value(unit_system, 'LENGTH', str(1 / scale))
|
||||
self.rd = bpy.utils.units.to_value(
|
||||
unit_system, 'LENGTH', str(1 / scale))
|
||||
|
||||
self.incremental = bpy.utils.units.to_value(unit_system, 'LENGTH', str(self.preferences.incremental))
|
||||
self.incremental = bpy.utils.units.to_value(
|
||||
unit_system, 'LENGTH', str(self.preferences.incremental))
|
||||
|
||||
def snap_to_grid(self):
|
||||
if self.type == 'OUT' and self.preferences.increments_grid:
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#python tip: from-imports don't save memory.
|
||||
#They execute and cache the entire module just like a regular import.
|
||||
# python tip: from-imports don't save memory.
|
||||
# They execute and cache the entire module just like a regular import.
|
||||
|
||||
import bpy
|
||||
import bmesh
|
||||
|
||||
from mathutils import Vector
|
||||
from mathutils.geometry import (
|
||||
intersect_point_line,
|
||||
intersect_line_line,
|
||||
intersect_ray_tri,
|
||||
)
|
||||
intersect_point_line,
|
||||
intersect_line_line,
|
||||
intersect_ray_tri,
|
||||
)
|
||||
|
||||
from .snap_context_l import SnapContext
|
||||
|
||||
|
@ -19,10 +19,10 @@ from .snap_context_l import SnapContext
|
|||
def get_units_info(scale, unit_system, separate_units):
|
||||
if unit_system == 'METRIC':
|
||||
scale_steps = ((1000, 'km'), (1, 'm'), (1 / 100, 'cm'),
|
||||
(1 / 1000, 'mm'), (1 / 1000000, '\u00b5m'))
|
||||
(1 / 1000, 'mm'), (1 / 1000000, '\u00b5m'))
|
||||
elif unit_system == 'IMPERIAL':
|
||||
scale_steps = ((5280, 'mi'), (1, '\''),
|
||||
(1 / 12, '"'), (1 / 12000, 'thou'))
|
||||
(1 / 12, '"'), (1 / 12000, 'thou'))
|
||||
scale /= 0.3048 # BU to feet
|
||||
else:
|
||||
scale_steps = ((1, ' BU'),)
|
||||
|
@ -71,14 +71,17 @@ def location_3d_to_region_2d(region, rv3d, coord):
|
|||
|
||||
def out_Location(rv3d, orig, vector):
|
||||
view_matrix = rv3d.view_matrix
|
||||
v1 = (int(view_matrix[0][0]*1.5), int(view_matrix[0][1]*1.5), int(view_matrix[0][2]*1.5))
|
||||
v2 = (int(view_matrix[1][0]*1.5), int(view_matrix[1][1]*1.5), int(view_matrix[1][2]*1.5))
|
||||
v1 = (int(view_matrix[0][0]*1.5), int(view_matrix[0]
|
||||
[1]*1.5), int(view_matrix[0][2]*1.5))
|
||||
v2 = (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((1,0,0), (0,1,0), (0,0,0), (vector), (orig), False)
|
||||
hit = intersect_ray_tri((1, 0, 0), (0, 1, 0),
|
||||
(0, 0, 0), (vector), (orig), False)
|
||||
if hit is None:
|
||||
hit = intersect_ray_tri(v1, v2, (0,0,0), (vector), (orig), False)
|
||||
hit = intersect_ray_tri(v1, v2, (0, 0, 0), (vector), (orig), False)
|
||||
if hit is None:
|
||||
hit = intersect_ray_tri(v1, v2, (0,0,0), (-vector), (orig), False)
|
||||
hit = intersect_ray_tri(v1, v2, (0, 0, 0), (-vector), (orig), False)
|
||||
if hit is None:
|
||||
hit = Vector()
|
||||
return hit
|
||||
|
@ -114,7 +117,8 @@ def get_snap_bm_geom(sctx, main_snap_obj, mcursor):
|
|||
r_bm.verts[r_elem[2]],
|
||||
]
|
||||
|
||||
faces = set(tri[0].link_faces).intersection(tri[1].link_faces, tri[2].link_faces)
|
||||
faces = set(tri[0].link_faces).intersection(
|
||||
tri[1].link_faces, tri[2].link_faces)
|
||||
if len(faces) == 1:
|
||||
r_bm_geom = faces.pop()
|
||||
else:
|
||||
|
@ -162,17 +166,19 @@ class SnapCache(object):
|
|||
def clear(self):
|
||||
self.edge.snp_obj = self.face.bm_face = None
|
||||
|
||||
|
||||
_snap_cache = SnapCache()
|
||||
|
||||
|
||||
def snap_utilities(
|
||||
sctx, main_snap_obj,
|
||||
mcursor,
|
||||
constrain = None,
|
||||
previous_vert = None,
|
||||
increment = 0.0):
|
||||
constrain=None,
|
||||
previous_vert=None,
|
||||
increment=0.0):
|
||||
|
||||
snp_obj, loc, elem, elem_co, view_vector, orig, bm, bm_geom = get_snap_bm_geom(sctx, main_snap_obj, mcursor)
|
||||
snp_obj, loc, elem, elem_co, view_vector, orig, bm, bm_geom = get_snap_bm_geom(
|
||||
sctx, main_snap_obj, mcursor)
|
||||
|
||||
is_increment = False
|
||||
r_loc = None
|
||||
|
@ -209,40 +215,43 @@ def snap_utilities(
|
|||
v1 = elem_co[1]
|
||||
_snap_cache.edge.vmid = 0.5 * (v0 + v1)
|
||||
_snap_cache.edge.v2dmid = location_3d_to_region_2d(
|
||||
sctx.region, sctx.rv3d, _snap_cache.edge.vmid)
|
||||
sctx.region, sctx.rv3d, _snap_cache.edge.vmid)
|
||||
|
||||
if previous_vert and (not bm_geom or previous_vert not in bm_geom.verts):
|
||||
pvert_co = main_snap_obj.mat @ previous_vert.co
|
||||
perp_point = intersect_point_line(pvert_co, v0, v1)
|
||||
_snap_cache.edge.vperp = perp_point[0]
|
||||
#factor = point_perpendicular[1]
|
||||
_snap_cache.edge.v2dperp = location_3d_to_region_2d(sctx.region, sctx.rv3d, perp_point[0])
|
||||
_snap_cache.edge.v2dperp = location_3d_to_region_2d(
|
||||
sctx.region, sctx.rv3d, perp_point[0])
|
||||
_snap_cache.edge.is_increment = False
|
||||
else:
|
||||
_snap_cache.edge.is_increment = True
|
||||
|
||||
#else: _snap_cache.edge.v2dperp = None
|
||||
# else: _snap_cache.edge.v2dperp = None
|
||||
|
||||
if constrain:
|
||||
t_loc = intersect_line_line(constrain[0], constrain[1], elem_co[0], elem_co[1])
|
||||
t_loc = intersect_line_line(
|
||||
constrain[0], constrain[1], elem_co[0], elem_co[1])
|
||||
if t_loc is None:
|
||||
is_increment = True
|
||||
end = orig + view_vector
|
||||
t_loc = intersect_line_line(constrain[0], constrain[1], orig, end)
|
||||
t_loc = intersect_line_line(
|
||||
constrain[0], constrain[1], orig, end)
|
||||
r_loc = t_loc[0]
|
||||
|
||||
elif _snap_cache.edge.v2dperp and\
|
||||
abs(_snap_cache.edge.v2dperp[0] - mcursor[0]) < sctx._dist_px and abs(_snap_cache.edge.v2dperp[1] - mcursor[1]) < sctx._dist_px:
|
||||
r_type = 'PERPENDICULAR'
|
||||
r_loc = _snap_cache.edge.vperp
|
||||
abs(_snap_cache.edge.v2dperp[0] - mcursor[0]) < sctx._dist_px and abs(_snap_cache.edge.v2dperp[1] - mcursor[1]) < sctx._dist_px:
|
||||
r_type = 'PERPENDICULAR'
|
||||
r_loc = _snap_cache.edge.vperp
|
||||
|
||||
elif abs(_snap_cache.edge.v2dmid[0] - mcursor[0]) < sctx._dist_px and abs(_snap_cache.edge.v2dmid[1] - mcursor[1]) < sctx._dist_px:
|
||||
r_type = 'CENTER'
|
||||
r_loc = _snap_cache.edge.vmid
|
||||
r_type = 'CENTER'
|
||||
r_loc = _snap_cache.edge.vmid
|
||||
|
||||
else:
|
||||
r_loc = loc
|
||||
is_increment = _snap_cache.edge.is_increment
|
||||
r_loc = loc
|
||||
is_increment = _snap_cache.edge.is_increment
|
||||
|
||||
elif len(elem) == 3:
|
||||
r_type = 'FACE'
|
||||
|
@ -283,4 +292,5 @@ def snap_utilities(
|
|||
|
||||
return snp_obj, loc, r_loc, r_type, bm, bm_geom, r_len
|
||||
|
||||
|
||||
snap_utilities.cache = _snap_cache
|
||||
|
|
|
@ -4,7 +4,7 @@ from mathutils import Vector, Matrix
|
|||
|
||||
|
||||
class SnapDrawn():
|
||||
__slots__ = (\
|
||||
__slots__ = (
|
||||
'out_color',
|
||||
'face_color',
|
||||
'edge_color',
|
||||
|
@ -50,11 +50,14 @@ class SnapDrawn():
|
|||
self._line_width = 3 * ui_scale
|
||||
|
||||
self._format_pos = gpu.types.GPUVertFormat()
|
||||
self._format_pos.attr_add(id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
|
||||
self._format_pos.attr_add(
|
||||
id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
|
||||
|
||||
self._format_pos_and_color = gpu.types.GPUVertFormat()
|
||||
self._format_pos_and_color.attr_add(id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
|
||||
self._format_pos_and_color.attr_add(id="color", comp_type='F32', len=4, fetch_mode='FLOAT')
|
||||
self._format_pos_and_color.attr_add(
|
||||
id="pos", comp_type='F32', len=3, fetch_mode='FLOAT')
|
||||
self._format_pos_and_color.attr_add(
|
||||
id="color", comp_type='F32', len=4, fetch_mode='FLOAT')
|
||||
|
||||
self._UBO = None
|
||||
|
||||
|
@ -63,8 +66,10 @@ class SnapDrawn():
|
|||
def _gl_state_push(self, ob_mat=None):
|
||||
clip_planes = self.rv3d.clip_planes if self.rv3d.use_clip_planes else None
|
||||
config = 'CLIPPED' if clip_planes else 'DEFAULT'
|
||||
self._program_unif_col = gpu.shader.from_builtin("3D_UNIFORM_COLOR", config=config)
|
||||
self._program_smooth_col = gpu.shader.from_builtin("3D_SMOOTH_COLOR", config=config)
|
||||
self._program_unif_col = gpu.shader.from_builtin(
|
||||
"3D_UNIFORM_COLOR", config=config)
|
||||
self._program_smooth_col = gpu.shader.from_builtin(
|
||||
"3D_SMOOTH_COLOR", config=config)
|
||||
|
||||
gpu.state.program_point_size_set(False)
|
||||
gpu.state.blend_set('ALPHA')
|
||||
|
@ -76,6 +81,7 @@ class SnapDrawn():
|
|||
gpu.state.clip_distances_set(4)
|
||||
if self._UBO is None:
|
||||
import ctypes
|
||||
|
||||
class _GPUClipPlanes(ctypes.Structure):
|
||||
_pack_ = 16
|
||||
_fields_ = [
|
||||
|
@ -118,9 +124,9 @@ class SnapDrawn():
|
|||
GPUBatch,
|
||||
)
|
||||
|
||||
vbo = GPUVertBuf(self._format_pos, len = len(coords))
|
||||
vbo.attr_fill(0, data = coords)
|
||||
batch_lines = GPUBatch(type = "LINE_STRIP", buf = vbo)
|
||||
vbo = GPUVertBuf(self._format_pos, len=len(coords))
|
||||
vbo.attr_fill(0, data=coords)
|
||||
batch_lines = GPUBatch(type="LINE_STRIP", buf=vbo)
|
||||
return batch_lines
|
||||
|
||||
def batch_lines_smooth_color_create(self, coords, colors):
|
||||
|
@ -129,10 +135,10 @@ class SnapDrawn():
|
|||
GPUBatch,
|
||||
)
|
||||
|
||||
vbo = GPUVertBuf(self._format_pos_and_color, len = len(coords))
|
||||
vbo.attr_fill(0, data = coords)
|
||||
vbo.attr_fill(1, data = colors)
|
||||
batch_lines = GPUBatch(type = "LINES", buf = vbo)
|
||||
vbo = GPUVertBuf(self._format_pos_and_color, len=len(coords))
|
||||
vbo.attr_fill(0, data=coords)
|
||||
vbo.attr_fill(1, data=colors)
|
||||
batch_lines = GPUBatch(type="LINES", buf=vbo)
|
||||
return batch_lines
|
||||
|
||||
def batch_triangles_create(self, coords):
|
||||
|
@ -141,9 +147,9 @@ class SnapDrawn():
|
|||
GPUBatch,
|
||||
)
|
||||
|
||||
vbo = GPUVertBuf(self._format_pos, len = len(coords))
|
||||
vbo.attr_fill(0, data = coords)
|
||||
batch_tris = GPUBatch(type = "TRIS", buf = vbo)
|
||||
vbo = GPUVertBuf(self._format_pos, len=len(coords))
|
||||
vbo.attr_fill(0, data=coords)
|
||||
batch_tris = GPUBatch(type="TRIS", buf=vbo)
|
||||
return batch_tris
|
||||
|
||||
def batch_point_get(self):
|
||||
|
@ -152,9 +158,9 @@ class SnapDrawn():
|
|||
GPUVertBuf,
|
||||
GPUBatch,
|
||||
)
|
||||
vbo = GPUVertBuf(self._format_pos, len = 1)
|
||||
vbo = GPUVertBuf(self._format_pos, len=1)
|
||||
vbo.attr_fill(0, ((0.0, 0.0, 0.0),))
|
||||
self._batch_point = GPUBatch(type = "POINTS", buf = vbo)
|
||||
self._batch_point = GPUBatch(type="POINTS", buf=vbo)
|
||||
return self._batch_point
|
||||
|
||||
def draw(self, type, location, list_verts_co, vector_constrain, prevloc):
|
||||
|
@ -171,7 +177,8 @@ class SnapDrawn():
|
|||
gpu.matrix.load_projection_matrix(winmat)
|
||||
gpu.state.line_width_set(self._line_width)
|
||||
|
||||
batch = self.batch_line_strip_create([v.to_tuple() for v in list_verts_co] + [location.to_tuple()])
|
||||
batch = self.batch_line_strip_create(
|
||||
[v.to_tuple() for v in list_verts_co] + [location.to_tuple()])
|
||||
|
||||
self._program_unif_col.bind()
|
||||
self._program_unif_col.uniform_float("color", (1.0, 0.8, 0.0, 0.5))
|
||||
|
@ -189,7 +196,8 @@ class SnapDrawn():
|
|||
gpu.matrix.translate(prevloc)
|
||||
|
||||
self._program_unif_col.bind()
|
||||
self._program_unif_col.uniform_float("color", (1.0, 1.0, 1.0, 0.5))
|
||||
self._program_unif_col.uniform_float(
|
||||
"color", (1.0, 1.0, 1.0, 0.5))
|
||||
|
||||
point_batch.draw(self._program_unif_col)
|
||||
gpu.matrix.translate(-prevloc)
|
||||
|
@ -215,7 +223,7 @@ class SnapDrawn():
|
|||
Color4f = self.center_color
|
||||
elif type == 'PERPENDICULAR':
|
||||
Color4f = self.perpendicular_color
|
||||
else: # type == None
|
||||
else: # type == None
|
||||
Color4f = self.out_color
|
||||
|
||||
gpu.state.point_size_set(2 * self._point_size)
|
||||
|
@ -233,7 +241,7 @@ class SnapDrawn():
|
|||
self._gl_state_restore()
|
||||
|
||||
def draw_elem(self, snap_obj, bm, elem):
|
||||
#TODO: Cache coords (because antialiasing)
|
||||
# TODO: Cache coords (because antialiasing)
|
||||
import gpu
|
||||
from bmesh.types import(
|
||||
BMVert,
|
||||
|
@ -249,16 +257,19 @@ class SnapDrawn():
|
|||
import numpy as np
|
||||
|
||||
color = self.vert_color
|
||||
edges = np.empty((len(elem.link_edges), 2), [("pos", "f4", 3), ("color", "f4", 4)])
|
||||
edges = np.empty((len(elem.link_edges), 2), [
|
||||
("pos", "f4", 3), ("color", "f4", 4)])
|
||||
edges["pos"][:, 0] = elem.co
|
||||
edges["pos"][:, 1] = [e.other_vert(elem).co for e in elem.link_edges]
|
||||
edges["pos"][:, 1] = [e.other_vert(
|
||||
elem).co for e in elem.link_edges]
|
||||
edges["color"][:, 0] = color
|
||||
edges["color"][:, 1] = (color[0], color[1], color[2], 0.0)
|
||||
edges.shape = -1
|
||||
|
||||
self._program_smooth_col.bind()
|
||||
gpu.state.line_width_set(self._line_width)
|
||||
batch = self.batch_lines_smooth_color_create(edges["pos"], edges["color"])
|
||||
batch = self.batch_lines_smooth_color_create(
|
||||
edges["pos"], edges["color"])
|
||||
batch.draw(self._program_smooth_col)
|
||||
gpu.state.line_width_set(1.0)
|
||||
else:
|
||||
|
@ -267,7 +278,8 @@ class SnapDrawn():
|
|||
self._program_unif_col.uniform_float("color", self.edge_color)
|
||||
|
||||
gpu.state.line_width_set(self._line_width)
|
||||
batch = self.batch_line_strip_create([v.co for v in elem.verts])
|
||||
batch = self.batch_line_strip_create(
|
||||
[v.co for v in elem.verts])
|
||||
batch.draw(self._program_unif_col)
|
||||
gpu.state.line_width_set(1.0)
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
km_tool_snap_utilities_line = "3D View Tool: Edit Mesh, Make Line"
|
||||
|
||||
|
||||
def km_mesh_snap_utilities_operators():
|
||||
return (
|
||||
"Mesh",
|
||||
|
@ -15,6 +16,7 @@ def km_mesh_snap_utilities_operators():
|
|||
]},
|
||||
)
|
||||
|
||||
|
||||
"""
|
||||
def km_snap_utilities_modal_map():
|
||||
items = []
|
||||
|
@ -50,6 +52,7 @@ def km_snap_utilities_modal_map():
|
|||
return keymap
|
||||
"""
|
||||
|
||||
|
||||
def km_3d_view_tool_snap_utilities_line(tool_mouse):
|
||||
return (
|
||||
km_tool_snap_utilities_line,
|
||||
|
@ -60,6 +63,7 @@ def km_3d_view_tool_snap_utilities_line(tool_mouse):
|
|||
]},
|
||||
)
|
||||
|
||||
|
||||
def km_view3d_empty(km_name):
|
||||
return (
|
||||
km_name,
|
||||
|
@ -70,30 +74,34 @@ def km_view3d_empty(km_name):
|
|||
# ------------------------------------------------------------------------------
|
||||
# Full Configuration
|
||||
|
||||
|
||||
def generate_empty_snap_utilities_tools_keymaps():
|
||||
return [
|
||||
#km_view3d_empty(km_snap_utilities_modal_keymap),
|
||||
# km_view3d_empty(km_snap_utilities_modal_keymap),
|
||||
|
||||
km_view3d_empty(km_tool_snap_utilities_line),
|
||||
]
|
||||
|
||||
def generate_snap_utilities_global_keymaps(tool_mouse = 'LEFTMOUSE'):
|
||||
|
||||
def generate_snap_utilities_global_keymaps(tool_mouse='LEFTMOUSE'):
|
||||
return [
|
||||
km_mesh_snap_utilities_operators(),
|
||||
]
|
||||
|
||||
def generate_snap_utilities_tools_keymaps(tool_mouse = 'LEFTMOUSE'):
|
||||
|
||||
def generate_snap_utilities_tools_keymaps(tool_mouse='LEFTMOUSE'):
|
||||
return [
|
||||
# Tool System.
|
||||
km_3d_view_tool_snap_utilities_line(tool_mouse),
|
||||
]
|
||||
|
||||
def generate_snap_utilities_keymaps(tool_mouse = 'LEFTMOUSE'):
|
||||
|
||||
def generate_snap_utilities_keymaps(tool_mouse='LEFTMOUSE'):
|
||||
return [
|
||||
km_mesh_snap_utilities_operators(),
|
||||
|
||||
# Modal maps.
|
||||
#km_snap_utilities_modal_map(),
|
||||
# km_snap_utilities_modal_map(),
|
||||
|
||||
# Tool System.
|
||||
km_3d_view_tool_snap_utilities_line(tool_mouse),
|
||||
|
|
|
@ -11,7 +11,8 @@ class VIEW3D_OT_rotate_custom_pivot(bpy.types.Operator):
|
|||
__slots__ = 'rv3d', 'init_coord', 'pos1', 'view_rot'
|
||||
|
||||
pivot: bpy.props.FloatVectorProperty("Pivot", subtype='XYZ')
|
||||
g_up_axis: bpy.props.FloatVectorProperty("up_axis", default=(0.0, 0.0, 1.0), subtype='XYZ')
|
||||
g_up_axis: bpy.props.FloatVectorProperty(
|
||||
"up_axis", default=(0.0, 0.0, 1.0), subtype='XYZ')
|
||||
sensitivity: bpy.props.FloatProperty("sensitivity", default=0.007)
|
||||
|
||||
def modal(self, context, event):
|
||||
|
@ -19,9 +20,11 @@ class VIEW3D_OT_rotate_custom_pivot(bpy.types.Operator):
|
|||
if event.value == 'PRESS' and event.type in {'MOUSEMOVE', 'INBETWEEN_MOUSEMOVE'}:
|
||||
dx = self.init_coord[0] - event.mouse_region_x
|
||||
dy = self.init_coord[1] - event.mouse_region_y
|
||||
rot_ver = Matrix.Rotation(-dx * self.sensitivity, 3, self.g_up_axis)
|
||||
rot_hor = Matrix.Rotation(dy * self.sensitivity, 3, self.view_rot[0])
|
||||
rot_mat = rot_hor @ rot_ver
|
||||
rot_ver = Matrix.Rotation(-dx *
|
||||
self.sensitivity, 3, self.g_up_axis)
|
||||
rot_hor = Matrix.Rotation(
|
||||
dy * self.sensitivity, 3, self.view_rot[0])
|
||||
rot_mat = rot_hor @ rot_ver
|
||||
view_matrix = self.view_rot @ rot_mat
|
||||
|
||||
pos = self.pos1 @ rot_mat + self.pivot
|
||||
|
@ -64,13 +67,15 @@ class VIEW3D_OT_zoom_custom_target(bpy.types.Operator):
|
|||
self.heigt_up = context.area.height - self.init_mouse_region_y
|
||||
self.rv3d.view_location = self.target
|
||||
|
||||
fac = (event.mouse_region_y - self.init_mouse_region_y) / self.heigt_up
|
||||
fac = (event.mouse_region_y -
|
||||
self.init_mouse_region_y) / self.heigt_up
|
||||
ret = 'RUNNING_MODAL'
|
||||
else:
|
||||
fac = self.step_factor * self.delta
|
||||
ret = 'FINISHED'
|
||||
|
||||
self.rv3d.view_location = self.init_loc + (self.target - self.init_loc) * fac
|
||||
self.rv3d.view_location = self.init_loc + \
|
||||
(self.target - self.init_loc) * fac
|
||||
self.rv3d.view_distance = self.init_dist - self.init_dist * fac
|
||||
|
||||
context.area.tag_redraw()
|
||||
|
@ -82,10 +87,10 @@ class VIEW3D_OT_zoom_custom_target(bpy.types.Operator):
|
|||
self.rv3d = context.region_data
|
||||
self.init_dist = self.rv3d.view_distance
|
||||
if ((self.delta <= 0 and self.init_dist < dist_range[1]) or
|
||||
(self.delta > 0 and self.init_dist > dist_range[0])):
|
||||
self.init_loc = self.rv3d.view_location.copy()
|
||||
(self.delta > 0 and self.init_dist > dist_range[0])):
|
||||
self.init_loc = self.rv3d.view_location.copy()
|
||||
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
return {'FINISHED'}
|
||||
|
|
|
@ -12,7 +12,7 @@ from .common_classes import (
|
|||
Constrain,
|
||||
SnapNavigation,
|
||||
SnapUtilities,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if not __package__:
|
||||
|
@ -81,7 +81,8 @@ def make_line(self, bm_geom, location):
|
|||
|
||||
elif isinstance(bm_geom, bmesh.types.BMEdge):
|
||||
self.list_edges.append(bm_geom)
|
||||
ret = intersect_point_line(location, bm_geom.verts[0].co, bm_geom.verts[1].co)
|
||||
ret = intersect_point_line(
|
||||
location, bm_geom.verts[0].co, bm_geom.verts[1].co)
|
||||
|
||||
if (ret[0] - location).length_squared < .001:
|
||||
if ret[1] == 0.0:
|
||||
|
@ -89,12 +90,13 @@ def make_line(self, bm_geom, location):
|
|||
elif ret[1] == 1.0:
|
||||
vert = bm_geom.verts[1]
|
||||
else:
|
||||
edge, vert = bmesh.utils.edge_split(bm_geom, bm_geom.verts[0], ret[1])
|
||||
edge, vert = bmesh.utils.edge_split(
|
||||
bm_geom, bm_geom.verts[0], ret[1])
|
||||
update_edit_mesh = True
|
||||
|
||||
if self.list_verts == [] or self.list_verts[-1] != vert:
|
||||
self.list_verts.append(vert)
|
||||
self.geom = vert # hack to highlight in the drawing
|
||||
self.geom = vert # hack to highlight in the drawing
|
||||
# self.list_edges.append(edge)
|
||||
|
||||
else: # constrain point is near
|
||||
|
@ -113,7 +115,7 @@ def make_line(self, bm_geom, location):
|
|||
v1, v2 = self.list_verts[-2:]
|
||||
edge = bm.edges.get([v1, v2])
|
||||
if edge:
|
||||
self.list_edges.append(edge)
|
||||
self.list_edges.append(edge)
|
||||
else:
|
||||
if not v2.link_edges:
|
||||
edge = bm.edges.new([v1, v2])
|
||||
|
@ -122,7 +124,8 @@ def make_line(self, bm_geom, location):
|
|||
v1_link_faces = v1.link_faces
|
||||
v2_link_faces = v2.link_faces
|
||||
if v1_link_faces and v2_link_faces:
|
||||
split_faces.update(set(v1_link_faces).intersection(v2_link_faces))
|
||||
split_faces.update(
|
||||
set(v1_link_faces).intersection(v2_link_faces))
|
||||
|
||||
else:
|
||||
if v1_link_faces:
|
||||
|
@ -147,7 +150,8 @@ def make_line(self, bm_geom, location):
|
|||
del split_faces
|
||||
else:
|
||||
if self.intersect:
|
||||
facesp = bmesh.ops.connect_vert_pair(bm, verts=[v1, v2], verts_exclude=bm.verts)
|
||||
facesp = bmesh.ops.connect_vert_pair(
|
||||
bm, verts=[v1, v2], verts_exclude=bm.verts)
|
||||
# print(facesp)
|
||||
if not self.intersect or not facesp['edges']:
|
||||
edge = bm.edges.new([v1, v2])
|
||||
|
@ -178,7 +182,7 @@ def make_line(self, bm_geom, location):
|
|||
obj.update_tag()
|
||||
bmesh.update_edit_mesh(obj.data)
|
||||
self.sctx.tag_update_drawn_snap_object(self.main_snap_obj)
|
||||
#bm.verts.index_update()
|
||||
# bm.verts.index_update()
|
||||
|
||||
bpy.ops.ed.undo_push(message="Undo draw line*")
|
||||
|
||||
|
@ -191,10 +195,10 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
bl_label = "Line Tool"
|
||||
bl_options = {'REGISTER'}
|
||||
|
||||
wait_for_input : bpy.props.BoolProperty(name="Wait for Input", default=True)
|
||||
wait_for_input: bpy.props.BoolProperty(name="Wait for Input", default=True)
|
||||
|
||||
def _exit(self, context):
|
||||
#avoids unpredictable crashes
|
||||
# avoids unpredictable crashes
|
||||
del self.main_snap_obj
|
||||
del self.main_bm
|
||||
del self.list_edges
|
||||
|
@ -205,7 +209,7 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
context.area.header_text_set(None)
|
||||
self.snap_context_free()
|
||||
|
||||
#Restore initial state
|
||||
# Restore initial state
|
||||
context.tool_settings.mesh_select_mode = self.select_mode
|
||||
context.space_data.overlay.show_face_center = self.show_face_center
|
||||
|
||||
|
@ -222,7 +226,8 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
self.obj = context.edit_object
|
||||
self.bm = bmesh.from_edit_mesh(self.obj.data)
|
||||
|
||||
self.main_snap_obj = self.snap_obj = self.sctx._get_snap_obj_by_obj(self.obj)
|
||||
self.main_snap_obj = self.snap_obj = self.sctx._get_snap_obj_by_obj(
|
||||
self.obj)
|
||||
self.main_bm = self.bm
|
||||
|
||||
def _shift_contrain_callback(self):
|
||||
|
@ -247,7 +252,7 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
del self.main_bm
|
||||
self.charmap.clear()
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT') # just to be sure
|
||||
bpy.ops.object.mode_set(mode='EDIT') # just to be sure
|
||||
bpy.ops.mesh.select_all(action='DESELECT')
|
||||
context.tool_settings.mesh_select_mode = (True, False, True)
|
||||
context.space_data.overlay.show_face_center = True
|
||||
|
@ -271,18 +276,20 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
self.bool_update = False
|
||||
|
||||
self.snap_obj, self.prevloc, self.location, self.type, self.bm, self.geom, self.len = snap_utilities(
|
||||
self.sctx,
|
||||
self.main_snap_obj,
|
||||
mval,
|
||||
constrain=self.vector_constrain,
|
||||
previous_vert=(self.list_verts[-1] if self.list_verts else None),
|
||||
increment=self.incremental)
|
||||
self.sctx,
|
||||
self.main_snap_obj,
|
||||
mval,
|
||||
constrain=self.vector_constrain,
|
||||
previous_vert=(
|
||||
self.list_verts[-1] if self.list_verts else None),
|
||||
increment=self.incremental)
|
||||
|
||||
self.snap_to_grid()
|
||||
|
||||
if is_making_lines and self.preferences.auto_constrain:
|
||||
loc = self.list_verts_co[-1]
|
||||
vec, type = self.constrain.update(self.sctx.region, self.sctx.rv3d, mval, loc)
|
||||
vec, type = self.constrain.update(
|
||||
self.sctx.region, self.sctx.rv3d, mval, loc)
|
||||
self.vector_constrain = [loc, loc + vec, type]
|
||||
|
||||
if event.value == 'PRESS':
|
||||
|
@ -291,8 +298,10 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
|
||||
if not self.bool_update:
|
||||
text_value = self.charmap.length_entered_value
|
||||
vector = (self.location - self.list_verts_co[-1]).normalized()
|
||||
self.location = self.list_verts_co[-1] + (vector * text_value)
|
||||
vector = (self.location -
|
||||
self.list_verts_co[-1]).normalized()
|
||||
self.location = self.list_verts_co[-1] + \
|
||||
(vector * text_value)
|
||||
del vector
|
||||
|
||||
elif self.constrain.modal(event, self._shift_contrain_callback):
|
||||
|
@ -303,7 +312,8 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
else:
|
||||
loc = self.location
|
||||
|
||||
self.vector_constrain = (loc, loc + self.constrain.last_vec, self.constrain.last_type)
|
||||
self.vector_constrain = (
|
||||
loc, loc + self.constrain.last_vec, self.constrain.last_type)
|
||||
else:
|
||||
self.vector_constrain = None
|
||||
|
||||
|
@ -352,7 +362,8 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
if is_making_lines:
|
||||
a = 'length: ' + self.charmap.get_converted_length_str(self.len)
|
||||
|
||||
context.area.header_text_set(text = "hit: %.3f %.3f %.3f %s" % (*self.location, a))
|
||||
context.area.header_text_set(
|
||||
text="hit: %.3f %.3f %.3f %s" % (*self.location, a))
|
||||
|
||||
if True or is_making_lines:
|
||||
return {'RUNNING_MODAL'}
|
||||
|
@ -362,14 +373,16 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
def draw_callback_px(self):
|
||||
if self.bm:
|
||||
self.draw_cache.draw_elem(self.snap_obj, self.bm, self.geom)
|
||||
self.draw_cache.draw(self.type, self.location, self.list_verts_co, self.vector_constrain, self.prevloc)
|
||||
self.draw_cache.draw(self.type, self.location,
|
||||
self.list_verts_co, self.vector_constrain, self.prevloc)
|
||||
|
||||
def invoke(self, context, event):
|
||||
if context.space_data.type == 'VIEW_3D':
|
||||
self.snap_context_init(context)
|
||||
self.snap_context_update(context)
|
||||
|
||||
self.constrain = Constrain(self.preferences, context.scene, self.obj)
|
||||
self.constrain = Constrain(
|
||||
self.preferences, context.scene, self.obj)
|
||||
|
||||
self.intersect = self.preferences.intersect
|
||||
self.create_face = self.preferences.create_face
|
||||
|
@ -380,21 +393,21 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
|
||||
# print('name', __name__, __package__)
|
||||
|
||||
#Store current state
|
||||
# Store current state
|
||||
self.select_mode = context.tool_settings.mesh_select_mode[:]
|
||||
self.show_face_center = context.space_data.overlay.show_face_center
|
||||
|
||||
#Modify the current state
|
||||
# Modify the current state
|
||||
bpy.ops.mesh.select_all(action='DESELECT')
|
||||
context.tool_settings.mesh_select_mode = (True, False, True)
|
||||
context.space_data.overlay.show_face_center = True
|
||||
|
||||
#Store values from 3d view context
|
||||
# Store values from 3d view context
|
||||
self.rv3d = context.region_data
|
||||
self.rotMat = self.rv3d.view_matrix.copy()
|
||||
# self.obj_matrix.transposed())
|
||||
|
||||
#modals
|
||||
# modals
|
||||
context.window_manager.modal_handler_add(self)
|
||||
|
||||
if not self.wait_for_input:
|
||||
|
@ -405,7 +418,8 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
point = mat_inv @ self.location
|
||||
self.list_verts_co = make_line(self, self.geom, point)
|
||||
|
||||
self._handle = bpy.types.SpaceView3D.draw_handler_add(self.draw_callback_px, (), 'WINDOW', 'POST_VIEW')
|
||||
self._handle = bpy.types.SpaceView3D.draw_handler_add(
|
||||
self.draw_callback_px, (), 'WINDOW', 'POST_VIEW')
|
||||
|
||||
return {'RUNNING_MODAL'}
|
||||
else:
|
||||
|
@ -416,5 +430,6 @@ class SnapUtilitiesLine(SnapUtilities, bpy.types.Operator):
|
|||
def register():
|
||||
bpy.utils.register_class(SnapUtilitiesLine)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
|
|
|
@ -9,7 +9,7 @@ from bpy.props import (
|
|||
IntProperty,
|
||||
FloatVectorProperty,
|
||||
FloatProperty,
|
||||
)
|
||||
)
|
||||
|
||||
from bpy.app.translations import contexts as i18n_contexts
|
||||
|
||||
|
@ -21,94 +21,94 @@ class SnapUtilitiesPreferences(bpy.types.AddonPreferences):
|
|||
# when defining this in a submodule of a python package.
|
||||
bl_idname = __package__
|
||||
|
||||
intersect : BoolProperty(name="Intersect",
|
||||
description="intersects created line with the existing edges, even if the lines do not intersect",
|
||||
default=True)
|
||||
intersect: BoolProperty(name="Intersect",
|
||||
description="intersects created line with the existing edges, even if the lines do not intersect",
|
||||
default=True)
|
||||
|
||||
create_face : BoolProperty(name="Create faces",
|
||||
description="Create faces defined by enclosed edges",
|
||||
default=False)
|
||||
create_face: BoolProperty(name="Create faces",
|
||||
description="Create faces defined by enclosed edges",
|
||||
default=False)
|
||||
|
||||
outer_verts : BoolProperty(name="Snap to outer vertices",
|
||||
description="The vertices of the objects are not activated also snapped",
|
||||
default=True)
|
||||
outer_verts: BoolProperty(name="Snap to outer vertices",
|
||||
description="The vertices of the objects are not activated also snapped",
|
||||
default=True)
|
||||
|
||||
increments_grid : BoolProperty(name="Increments of Grid",
|
||||
description="Snap to increments of grid",
|
||||
default=False)
|
||||
increments_grid: BoolProperty(name="Increments of Grid",
|
||||
description="Snap to increments of grid",
|
||||
default=False)
|
||||
|
||||
auto_constrain : BoolProperty(name="Automatic Constraint",
|
||||
description="Detects a direction to constrain depending on the position of the mouse",
|
||||
default=False)
|
||||
auto_constrain: BoolProperty(name="Automatic Constraint",
|
||||
description="Detects a direction to constrain depending on the position of the mouse",
|
||||
default=False)
|
||||
|
||||
incremental : FloatProperty(name="Incremental",
|
||||
description="Snap in defined increments",
|
||||
default=0,
|
||||
min=0,
|
||||
step=1,
|
||||
precision=3)
|
||||
incremental: FloatProperty(name="Incremental",
|
||||
description="Snap in defined increments",
|
||||
default=0,
|
||||
min=0,
|
||||
step=1,
|
||||
precision=3)
|
||||
|
||||
relative_scale : FloatProperty(name="Relative Scale",
|
||||
description="Value that divides the global scale",
|
||||
default=1,
|
||||
min=0,
|
||||
step=1,
|
||||
precision=3)
|
||||
relative_scale: FloatProperty(name="Relative Scale",
|
||||
description="Value that divides the global scale",
|
||||
default=1,
|
||||
min=0,
|
||||
step=1,
|
||||
precision=3)
|
||||
|
||||
out_color : FloatVectorProperty(name="Floor",
|
||||
default=(0.0, 0.0, 0.0, 0.5),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
out_color: FloatVectorProperty(name="Floor",
|
||||
default=(0.0, 0.0, 0.0, 0.5),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
face_color : FloatVectorProperty(name="Face Highlighted",
|
||||
default=(1.0, 0.8, 0.0, 0.5),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
face_color: FloatVectorProperty(name="Face Highlighted",
|
||||
default=(1.0, 0.8, 0.0, 0.5),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
edge_color : FloatVectorProperty(name="Edge Highlighted",
|
||||
default=(0.0, 0.8, 1.0, 0.5),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
edge_color: FloatVectorProperty(name="Edge Highlighted",
|
||||
default=(0.0, 0.8, 1.0, 0.5),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
vert_color : FloatVectorProperty(name="Vertex Highlighted",
|
||||
default=(1.0, 0.5, 0.0, 0.5),
|
||||
size=4, subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
vert_color: FloatVectorProperty(name="Vertex Highlighted",
|
||||
default=(1.0, 0.5, 0.0, 0.5),
|
||||
size=4, subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
center_color : FloatVectorProperty(name="Middle of the Edge",
|
||||
default=(1.0, 0.0, 1.0, 1.0),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
center_color: FloatVectorProperty(name="Middle of the Edge",
|
||||
default=(1.0, 0.0, 1.0, 1.0),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
perpendicular_color : FloatVectorProperty(name="Perpendicular Point",
|
||||
default=(0.1, 0.5, 0.5, 1.0),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
perpendicular_color: FloatVectorProperty(name="Perpendicular Point",
|
||||
default=(0.1, 0.5, 0.5, 1.0),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
constrain_shift_color : FloatVectorProperty(name="Shift Constrain",
|
||||
default=(0.8, 0.5, 0.4, 1.0),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
constrain_shift_color: FloatVectorProperty(name="Shift Constrain",
|
||||
default=(0.8, 0.5, 0.4, 1.0),
|
||||
size=4,
|
||||
subtype="COLOR",
|
||||
min=0,
|
||||
max=1)
|
||||
|
||||
tabs : EnumProperty(name="Tabs",
|
||||
items = [("GENERAL", "General", ""),
|
||||
("KEYMAPS", "Keymaps", ""),
|
||||
("COLORS", "Colors", ""),
|
||||
("HELP", "Links", ""),],
|
||||
default="GENERAL")
|
||||
tabs: EnumProperty(name="Tabs",
|
||||
items=[("GENERAL", "General", ""),
|
||||
("KEYMAPS", "Keymaps", ""),
|
||||
("COLORS", "Colors", ""),
|
||||
("HELP", "Links", ""), ],
|
||||
default="GENERAL")
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
@ -152,7 +152,8 @@ class SnapUtilitiesPreferences(bpy.types.AddonPreferences):
|
|||
def draw_snap_utilities_colors(self, layout):
|
||||
layout.use_property_split = True
|
||||
|
||||
flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
|
||||
flow = layout.grid_flow(
|
||||
row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
|
||||
|
||||
flow.prop(self, "out_color")
|
||||
flow.prop(self, "constrain_shift_color")
|
||||
|
@ -165,9 +166,10 @@ class SnapUtilitiesPreferences(bpy.types.AddonPreferences):
|
|||
def draw_snap_utilities_help(self, layout):
|
||||
#layout.operator("wm.url_open", text="Gumroad Page", icon='HELP',).url = "https://gum.co/IaqQf"
|
||||
#layout.operator("wm.url_open", text="Blender Market Page", icon='HELP',).url = "https://blendermarket.com/products/snap-utilities"
|
||||
layout.operator("wm.url_open", text="Wiki", icon='HELP',).url = "https://github.com/Mano-Wii/Addon-Snap-Utilities-Line/wiki"
|
||||
layout.operator("wm.url_open", text="Forum", icon='HELP',).url = "https://blenderartists.org/t/cad-snap-utilities"
|
||||
|
||||
layout.operator("wm.url_open", text="Wiki", icon='HELP',
|
||||
).url = "https://github.com/Mano-Wii/Addon-Snap-Utilities-Line/wiki"
|
||||
layout.operator("wm.url_open", text="Forum", icon='HELP',
|
||||
).url = "https://blenderartists.org/t/cad-snap-utilities"
|
||||
|
||||
def draw_snap_utilities_keymaps(self, context, layout):
|
||||
from .keys import (
|
||||
|
@ -206,4 +208,5 @@ class SnapUtilitiesPreferences(bpy.types.AddonPreferences):
|
|||
|
||||
for kmi in km.keymap_items:
|
||||
if "snap_utilities" in kmi.idname:
|
||||
rna_keymap_ui.draw_kmi(["ADDON", "USER", "DEFAULT"], kc, km, kmi, col, 0)
|
||||
rna_keymap_ui.draw_kmi(
|
||||
["ADDON", "USER", "DEFAULT"], kc, km, kmi, col, 0)
|
||||
|
|
|
@ -6,7 +6,7 @@ from .common_classes import SnapUtilities
|
|||
from .common_utilities import snap_utilities
|
||||
|
||||
|
||||
#def mesh_runtime_batchcache_isdirty(me):
|
||||
# def mesh_runtime_batchcache_isdirty(me):
|
||||
# import ctypes
|
||||
# batch_cache = ctypes.c_void_p.from_address(me.as_pointer() + 1440)
|
||||
# if batch_cache:
|
||||
|
@ -15,7 +15,7 @@ from .common_utilities import snap_utilities
|
|||
|
||||
|
||||
class SnapWidgetCommon(SnapUtilities, bpy.types.Gizmo):
|
||||
# __slots__ = ('inited', 'mode', 'last_mval')
|
||||
# __slots__ = ('inited', 'mode', 'last_mval')
|
||||
|
||||
snap_to_update = False
|
||||
|
||||
|
@ -24,9 +24,9 @@ class SnapWidgetCommon(SnapUtilities, bpy.types.Gizmo):
|
|||
if cls.snap_to_update is False:
|
||||
last_operator = self.wm_operators[-1] if self.wm_operators else None
|
||||
if (not last_operator or
|
||||
last_operator.name not in {'Select', 'Loop Select', '(De)select All'}):
|
||||
cls.snap_to_update = depsgraph.id_type_updated('MESH') or \
|
||||
depsgraph.id_type_updated('OBJECT')
|
||||
last_operator.name not in {'Select', 'Loop Select', '(De)select All'}):
|
||||
cls.snap_to_update = depsgraph.id_type_updated('MESH') or \
|
||||
depsgraph.id_type_updated('OBJECT')
|
||||
|
||||
def draw_point_and_elem(self):
|
||||
if self.bm:
|
||||
|
@ -76,7 +76,7 @@ class SnapWidgetCommon(SnapUtilities, bpy.types.Gizmo):
|
|||
self.last_mval = mval
|
||||
|
||||
if (SnapWidgetCommon.snap_to_update):
|
||||
## Something has changed since the last time.
|
||||
# Something has changed since the last time.
|
||||
# Has the mesh been changed?
|
||||
# In the doubt lets clear the snap context.
|
||||
self.snap_context_update(context)
|
||||
|
@ -84,22 +84,24 @@ class SnapWidgetCommon(SnapUtilities, bpy.types.Gizmo):
|
|||
|
||||
#print('test_select', mval)
|
||||
space = context.space_data
|
||||
self.sctx.update_viewport_context(context.evaluated_depsgraph_get(), context.region, space, True)
|
||||
self.sctx.update_viewport_context(
|
||||
context.evaluated_depsgraph_get(), context.region, space, True)
|
||||
|
||||
shading = space.shading
|
||||
snap_face = not ((self.snap_vert or self.snap_edge) and
|
||||
(shading.show_xray or shading.type == 'WIREFRAME'))
|
||||
(shading.show_xray or shading.type == 'WIREFRAME'))
|
||||
|
||||
if snap_face != self.snap_face:
|
||||
self.snap_face = snap_face
|
||||
self.sctx.set_snap_mode(self.snap_vert, self.snap_edge, self.snap_face)
|
||||
self.sctx.set_snap_mode(
|
||||
self.snap_vert, self.snap_edge, self.snap_face)
|
||||
|
||||
snap_utilities.cache.clear()
|
||||
self.snap_obj, prev_loc, self.location, self.type, self.bm, self.geom, len = snap_utilities(
|
||||
self.sctx,
|
||||
None,
|
||||
mval,
|
||||
increment=self.incremental
|
||||
self.sctx,
|
||||
None,
|
||||
mval,
|
||||
increment=self.incremental
|
||||
)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue