gpv3 : pick closest layer from stroke

master
pullusb 2024-11-14 16:18:56 +01:00
parent 05053cff68
commit b525cda28e
1 changed files with 14 additions and 14 deletions

View File

@ -33,8 +33,8 @@ class GP_OT_pick_closest_layer(Operator):
mouse_vec3 = Vector((*self.init_mouse, 0))
co, index, _dist = kd.find(mouse_vec3)
lid = self.point_pair[index][1]
return lid
layer = self.point_pair[index][1]
return layer
def invoke(self, context, event):
self.t0 = time()
@ -75,10 +75,10 @@ class GP_OT_pick_closest_layer(Operator):
self.inv_mat = self.ob.matrix_world.inverted()
self.point_pair = []
if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
for layer_id, l in enumerate(gp.layers):
if l.hide: # l.lock or
for layer in gp.layers:
if layer.hide:
continue
for f in l.frames:
for f in layer.frames:
if not f.select:
continue
for s in f.drawing.strokes:
@ -86,33 +86,33 @@ class GP_OT_pick_closest_layer(Operator):
continue
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
continue
self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer_id) for p in s.points]
self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer) for p in s.points]
else:
# [s for l in gp.layers if not l.lock and not l.hide for s in l.current_frame().stokes]
for layer_id, l in enumerate(gp.layers):
if l.hide or not l.current_frame(): # l.lock or
for layer in gp.layers:
if layer.hide or not layer.current_frame():
continue
for s in l.current_frame().drawing.strokes:
for s in layer.current_frame().drawing.strokes:
if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke:
continue
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
continue
self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer_id) for p in s.points]
self.point_pair += [(Vector((*location_to_region(mat @ p.position), 0)), layer) for p in s.points]
if not self.point_pair:
self.report({'ERROR'}, 'No stroke found, maybe layers are locked or hidden')
return {'CANCELLED'}
lid = self.filter_stroke(context)
if isinstance(lid, str):
self.report({'ERROR'}, lid)
layer_target = self.filter_stroke(context)
if isinstance(layer_target, str):
self.report({'ERROR'}, layer_target)
return {'CANCELLED'}
del self.point_pair # auto garbage collected ?
self.ob.data.layers.active_index = lid
self.ob.data.layers.active = layer_target
## debug show trigger time
# print(f'Trigger time {time() - self.t0:.3f}')