From 23811bf752e630d1a3d7193109d576b8ad1c764c Mon Sep 17 00:00:00 2001 From: pullusb Date: Thu, 11 Jan 2024 11:49:10 +0100 Subject: [PATCH] fix initial frame offset - remove bone place after use - add debug flag in operator --- __init__.py | 2 +- interpolate_strokes/operators.py | 36 +++++++++++++++++++------------- utils.py | 7 ++++--- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/__init__.py b/__init__.py index e800dcc..aaa781f 100755 --- a/__init__.py +++ b/__init__.py @@ -1,7 +1,7 @@ bl_info = { "name": "gp interpolate", "author": "Christophe Seux, Samuel Bernou", - "version": (0, 2, 1), + "version": (0, 3, 0), "blender": (3, 6, 0), "location": "Sidebar > Gpencil Tab > Interpolate", "description": "Interpolate Grease pencil strokes over 3D", diff --git a/interpolate_strokes/operators.py b/interpolate_strokes/operators.py index b2dd5e1..89bac60 100644 --- a/interpolate_strokes/operators.py +++ b/interpolate_strokes/operators.py @@ -47,6 +47,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator): next : bpy.props.BoolProperty(name='Next', default=True, options={'SKIP_SAVE'}) def execute(self, context): + debug=False settings = context.scene.gp_interpo_settings scn = bpy.context.scene @@ -126,15 +127,14 @@ class GP_OT_interpolate_stroke(bpy.types.Operator): # (bpy.context.scene.render, 'simplify_subdivision', 0), ] - # FIXME : Fix below filter so it does not exclude collections containing rig - # Also: Use in Bone mode only - - ## Exclude other collection for faster animation (PROBLEM) - # for vlc in context.view_layer.layer_collection.children: - # store_list.append( - # (vlc, 'exclude', vlc.name not in included_cols), - # # (vlc, 'hide_viewport', vlc.name not in included_cols), # viewport viz - # ) + # TODO : Customize below filter to use in geo mode as well + # so it does not exclude collections containing rig + if settings.method == 'BONE': + for vlc in context.view_layer.layer_collection.children: + store_list.append( + (vlc, 'exclude', vlc.name not in included_cols), + # (vlc, 'hide_viewport', vlc.name not in included_cols), # viewport viz + ) # print(f'Preparation {time()-start:.4f}s') @@ -221,8 +221,9 @@ class GP_OT_interpolate_stroke(bpy.types.Operator): strokes_data.append(stroke_data) - scan_time = time()-start - print(f'Scan time {scan_time:.4f}s') + if debug: + scan_time = time()-start + print(f'Scan time {scan_time:.4f}s') # Copy stroke selection bpy.ops.gpencil.copy() @@ -277,11 +278,18 @@ class GP_OT_interpolate_stroke(bpy.types.Operator): wm.progress_end() # Pgs - ## TODO: Remove plane on the fly - print(f"Paste'n'place time {time()-start - scan_time}s") + if debug: + print(f"Paste'n'place time {time()-start - scan_time}s") + else: + if settings.method == 'BONE': + ## Remove Plane and it's collection after use + bpy.data.objects.remove(plane) + bpy.data.collections.remove(col) + if len(frames_to_jump) > 1: self.report({'INFO'}, f'{len(frames_to_jump)} interpolated frame(s) ({time()-start:.3f}s)') - print('Done') + + # print('Done') return {'FINISHED'} diff --git a/utils.py b/utils.py index b2fae40..29f56a8 100644 --- a/utils.py +++ b/utils.py @@ -368,12 +368,13 @@ def get_gp_draw_plane(obj=None): ## --- Animation def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list | None: - '''return a lsit of int or an empty list''' + '''Return a list of int or an empty list''' direction = 1 if forward else -1 cur_frame = bpy.context.scene.frame_current settings = bpy.context.scene.gp_interpo_settings if settings.mode == 'FRAME': + jump = settings.padding * direction if all_keys: scn = bpy.context.scene if forward: @@ -383,10 +384,10 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list | limit += direction # offset by one for limit to be in range - return list(range(cur_frame + direction , limit, settings.padding * direction)) + return list(range(cur_frame + jump , limit, jump)) else: - return [cur_frame + (settings.padding * direction)] + return [cur_frame + jump] elif settings.mode == 'GPKEY': layers = bpy.context.object.data.layers