gpv3 : pick closest layer from stroke
parent
05053cff68
commit
b525cda28e
|
@ -33,8 +33,8 @@ class GP_OT_pick_closest_layer(Operator):
|
||||||
|
|
||||||
mouse_vec3 = Vector((*self.init_mouse, 0))
|
mouse_vec3 = Vector((*self.init_mouse, 0))
|
||||||
co, index, _dist = kd.find(mouse_vec3)
|
co, index, _dist = kd.find(mouse_vec3)
|
||||||
lid = self.point_pair[index][1]
|
layer = self.point_pair[index][1]
|
||||||
return lid
|
return layer
|
||||||
|
|
||||||
def invoke(self, context, event):
|
def invoke(self, context, event):
|
||||||
self.t0 = time()
|
self.t0 = time()
|
||||||
|
@ -75,10 +75,10 @@ class GP_OT_pick_closest_layer(Operator):
|
||||||
self.inv_mat = self.ob.matrix_world.inverted()
|
self.inv_mat = self.ob.matrix_world.inverted()
|
||||||
self.point_pair = []
|
self.point_pair = []
|
||||||
if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
|
if context.scene.tool_settings.use_grease_pencil_multi_frame_editing:
|
||||||
for layer_id, l in enumerate(gp.layers):
|
for layer in gp.layers:
|
||||||
if l.hide: # l.lock or
|
if layer.hide:
|
||||||
continue
|
continue
|
||||||
for f in l.frames:
|
for f in layer.frames:
|
||||||
if not f.select:
|
if not f.select:
|
||||||
continue
|
continue
|
||||||
for s in f.drawing.strokes:
|
for s in f.drawing.strokes:
|
||||||
|
@ -86,33 +86,33 @@ class GP_OT_pick_closest_layer(Operator):
|
||||||
continue
|
continue
|
||||||
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
|
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
|
||||||
continue
|
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:
|
else:
|
||||||
# [s for l in gp.layers if not l.lock and not l.hide for s in l.current_frame().stokes]
|
# [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):
|
for layer in gp.layers:
|
||||||
if l.hide or not l.current_frame(): # l.lock or
|
if layer.hide or not layer.current_frame():
|
||||||
continue
|
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:
|
if self.stroke_filter == 'STROKE' and not self.ob.data.materials[s.material_index].grease_pencil.show_stroke:
|
||||||
continue
|
continue
|
||||||
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
|
elif self.stroke_filter == 'FILL' and not self.ob.data.materials[s.material_index].grease_pencil.show_fill:
|
||||||
continue
|
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:
|
if not self.point_pair:
|
||||||
self.report({'ERROR'}, 'No stroke found, maybe layers are locked or hidden')
|
self.report({'ERROR'}, 'No stroke found, maybe layers are locked or hidden')
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
|
||||||
lid = self.filter_stroke(context)
|
layer_target = self.filter_stroke(context)
|
||||||
if isinstance(lid, str):
|
if isinstance(layer_target, str):
|
||||||
self.report({'ERROR'}, lid)
|
self.report({'ERROR'}, layer_target)
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
del self.point_pair # auto garbage collected ?
|
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
|
## debug show trigger time
|
||||||
# print(f'Trigger time {time() - self.t0:.3f}')
|
# print(f'Trigger time {time() - self.t0:.3f}')
|
||||||
|
|
Loading…
Reference in New Issue