better ui and modal cancel interaction

- add range in ui when animation is checked
- fix rig target collection UI
- add camera frames in rig mode
- fix animated interpolation frame range in rig mode
- add redraw timer to refresh view
master
pullusb 2024-02-08 18:27:07 +01:00
parent 539f62f3df
commit 6707d693d6
5 changed files with 246 additions and 196 deletions

View File

@ -1,7 +1,7 @@
bl_info = { bl_info = {
"name": "gp interpolate", "name": "gp interpolate",
"author": "Christophe Seux, Samuel Bernou", "author": "Christophe Seux, Samuel Bernou",
"version": (0, 7, 0), "version": (0, 7, 1),
"blender": (3, 6, 0), "blender": (3, 6, 0),
"location": "Sidebar > Gpencil Tab > Interpolate", "location": "Sidebar > Gpencil Tab > Interpolate",
"description": "Interpolate Grease pencil strokes over 3D", "description": "Interpolate Grease pencil strokes over 3D",

View File

@ -48,7 +48,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
next : bpy.props.BoolProperty(name='Next', default=True, options={'SKIP_SAVE'}) next : bpy.props.BoolProperty(name='Next', default=True, options={'SKIP_SAVE'})
def apply_and_store(self): def apply_and_store(self):
self.store = [] # self.store = []
# item = (prop, attr, [new_val]) # item = (prop, attr, [new_val])
for item in self.store_list: for item in self.store_list:
prop, attr = item[:2] prop, attr = item[:2]
@ -64,6 +64,7 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
self.debug = False self.debug = False
self.status = 'START' self.status = 'START'
self.store_list = [] self.store_list = []
self.store = []
self.loop_count = 0 self.loop_count = 0
self.start = time() self.start = time()
self.scan_time = None self.scan_time = None
@ -71,17 +72,24 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
self.toolcol = None self.toolcol = None
self.gp = context.object self.gp = context.object
self.settings = context.scene.gp_interpo_settings self.settings = context.scene.gp_interpo_settings
self.frames_to_jump = None
self.cancelled = False self.cancelled = False
self._timer = context.window_manager.event_timer_add(0.01, window=context.window)
context.window_manager.modal_handler_add(self) context.window_manager.modal_handler_add(self)
self._timer = context.window_manager.event_timer_add(0.01, window=context.window)
context.area.header_text_set('Starting interpolation | Esc: Cancel')
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
def exit_modal(self): def exit_modal(self, context, status='INFO', text=None):
bpy.context.window_manager.progress_end() # Pgs context.area.header_text_set(None)
wm = context.window_manager
wm.progress_end() # Pgs
wm.event_timer_remove(self._timer)
self.restore() self.restore()
if self.debug: if self.debug:
## show as solid ?
# if self.plane is not None:
# self.plane.display_type = 'SOLID'
if self.scan_time is not None: if self.scan_time is not None:
print(f"Paste'n'place time {time()-self.start - self.scan_time}s") print(f"Paste'n'place time {time()-self.start - self.scan_time}s")
else: else:
@ -93,208 +101,227 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
bpy.data.collections.remove(self.toolcol) bpy.data.collections.remove(self.toolcol)
cancel_state = '(Stopped!) ' if self.cancelled else '' cancel_state = '(Stopped!) ' if self.cancelled else ''
self.report({'INFO'}, f'{cancel_state}{self.loop_count} interpolated frame(s) ({time()-self.start:.3f}s)') mess = f'{cancel_state}{self.loop_count} interpolated frame(s) ({time()-self.start:.3f}s)'
if text:
print(mess)
self.report({status}, text)
else:
## report standard info
if self.loop_count > 1:
self.report({'INFO'}, mess)
def modal(self, context, event): def modal(self, context, event):
if event.type in {'RIGHTMOUSE', 'ESC'}: if event.type in {'RIGHTMOUSE', 'ESC'}:
print('Cancelling') print('Cancelling')
self.status = 'CANCELLED'
self.cancelled = True self.cancelled = True
self.exit_modal() context.area.header_text_set(f'Cancelling')
self.exit_modal(context)
return {'CANCELLED'} return {'CANCELLED'}
if event.type == 'TIMER': if self.frames_to_jump:
if self.status == 'START': frame_num = len(self.frames_to_jump)
percentage = (self.loop_count) / (frame_num) * 100
scn = bpy.context.scene context.area.header_text_set(f'Interpolation {percentage:.0f}% {self.loop_count + 1}/{frame_num} | Esc: Cancel')
# (frame: {self.frames_to_jump[self.loop_count]})
# auto_key_status = context.tool_settings.use_keyframe_insert_auto if self.status == 'START':
# context.tool_settings.use_keyframe_insert_auto = True scn = bpy.context.scene
## Determine on what key/keys to jump
self.frames_to_jump = following_keys(forward=self.next, all_keys=self.settings.use_animation)
if not len(self.frames_to_jump):
self.exit_modal(context, status='WARNING', text='No keyframe available in this direction')
return {'CANCELLED'}
# print('self.frames_to_jump: ', self.frames_to_jump)
self.gp = context.object
## Determine on what key/keys to jump # matrix = np.array(self.gp.matrix_world, dtype='float64')
self.frames_to_jump = following_keys(forward=self.next, all_keys=self.settings.use_animation) # origin = np.array(scn.camera.matrix_world.to_translation(), 'float64')
if not len(self.frames_to_jump): matrix = self.gp.matrix_world
self.report({'WARNING'}, 'No keyframe available in this direction') origin = scn.camera.matrix_world.to_translation()
return {'CANCELLED'}
# print('self.frames_to_jump: ', self.frames_to_jump) col = self.settings.target_collection
if not col:
self.gp = context.object col = scn.collection
# matrix = np.array(self.gp.matrix_world, dtype='float64') # print('----')
# origin = np.array(scn.camera.matrix_world.to_translation(), 'float64') if not self.gp.data.layers.active:
matrix = self.gp.matrix_world self.exit_modal(context, status='ERROR', text='No active layer')
origin = scn.camera.matrix_world.to_translation() return {'CANCELLED'}
if not self.gp.data.layers.active.active_frame:
col = self.settings.target_collection self.exit_modal(context, status='ERROR', text='No active frame')
if not col: return {'CANCELLED'}
col = scn.collection
# print('----') tgt_strokes = [s for s in self.gp.data.layers.active.active_frame.strokes if s.select]
## If nothing selected in sculpt/paint, Select all before triggering
if not tgt_strokes and context.mode in ('SCULPT_GPENCIL', 'PAINT_GPENCIL'):
for s in self.gp.data.layers.active.active_frame.strokes:
s.select = True
tgt_strokes = self.gp.data.layers.active.active_frame.strokes
tgt_strokes = [s for s in self.gp.data.layers.active.active_frame.strokes if s.select] if not tgt_strokes:
self.exit_modal(context, status='ERROR', text='No stroke selected !')
## If nothing selected in sculpt/paint, Select all before triggering return {'CANCELLED'}
if not tgt_strokes and context.mode in ('SCULPT_GPENCIL', 'PAINT_GPENCIL'):
for s in self.gp.data.layers.active.active_frame.strokes:
s.select = True
tgt_strokes = self.gp.data.layers.active.active_frame.strokes
if not tgt_strokes: included_cols = [c.name for c in self.gp.users_collection]
self.report({'ERROR'}, 'No stroke selected !') target_obj = None
if self.settings.method == 'BONE':
if not self.settings.target_rig or not self.settings.target_bone:
self.exit_modal(context, status='ERROR', text='No Bone selected')
return {'CANCELLED'} return {'CANCELLED'}
included_cols = [c.name for c in self.gp.users_collection] included_cols.append('interpolation_tool')
target_obj = None
## ensure collection and plane exists
# get/create collection
self.toolcol = bpy.data.collections.get('interpolation_tool')
if not self.toolcol:
self.toolcol = bpy.data.collections.new('interpolation_tool')
if self.toolcol.name not in bpy.context.scene.collection.children:
bpy.context.scene.collection.children.link(self.toolcol)
self.toolcol.hide_viewport = True # needed ?
if self.settings.method == 'BONE': # get/create meshplane
if not self.settings.target_rig or not self.settings.target_bone: self.plane = bpy.data.objects.get('interpolation_plane')
self.report({'ERROR'}, 'No Bone selected') if not self.plane:
return {'CANCELLED'} self.plane = create_plane(name='interpolation_plane')
self.plane.select_set(False)
included_cols.append('interpolation_tool') if self.plane.name not in self.toolcol.objects:
self.toolcol.objects.link(self.plane)
target_obj = self.plane
## ensure collection and plane exists elif self.settings.method == 'GEOMETRY':
# get/create collection if col != context.scene.collection:
self.toolcol = bpy.data.collections.get('interpolation_tool') included_cols.append(col.name)
if not self.toolcol: ## Maybe include a plane just behind geo ? probably bad idea
self.toolcol = bpy.data.collections.new('interpolation_tool')
elif self.settings.method == 'OBJECT':
if not self.settings.target_object:
self.exit_modal(context, status='ERROR', text='No Object selected')
return {'CANCELLED'}
col = scn.collection # Reset collection filter
target_obj = self.settings.target_object
if target_obj.library:
## Look if an override exists in scene to use instead of default object
if (override := next((o for o in scn.objects if o.name == target_obj.name and o.override_library), None)):
target_obj = override
if self.toolcol.name not in bpy.context.scene.collection.children: ## Prepare context manager
bpy.context.scene.collection.children.link(self.toolcol) self.store_list = [
self.toolcol.hide_viewport = True # needed ? # (context.view_layer.objects, 'active', self.gp),
(context.tool_settings, 'use_keyframe_insert_auto', True),
# get/create meshplane # (bpy.context.scene.render, 'simplify_subdivision', 0),
self.plane = bpy.data.objects.get('interpolation_plane') ]
if not self.plane:
self.plane = create_plane(name='interpolation_plane') # TODO: collection filter for GEOMETRY mode optimization
self.plane.select_set(False)
if self.plane.name not in self.toolcol.objects: ## Hide optimizations (safe for Bone Mode only, if no error)
self.toolcol.objects.link(self.plane) # if self.settings.method == 'BONE':
target_obj = self.plane # ## TEST: Add collections containing rig (cannot be excluded)
# # rig_parent_cols = [c.name for c in scn.collection.children_recursive if self.settings.target_rig.name in c.all_objects]
# # included_cols += rig_parent_cols
# for vlc in context.view_layer.layer_collection.children:
# self.store_list.append(
# # (vlc, 'exclude', vlc.name not in included_cols), # If excluded rig does not update !
# (vlc, 'hide_viewport', vlc.name not in included_cols), # viewport viz
# )
# print(f'Preparation {time()-start:.4f}s')
## Set everything in SETUP list
self.apply_and_store()
elif self.settings.method == 'GEOMETRY': if self.settings.method == 'BONE':
if col != context.scene.collection: ## replace plane
included_cols.append(col.name) _bone_plane = plane_on_bone(self.settings.target_rig.pose.bones.get(self.settings.target_bone),
## Maybe include a plane just behind geo ? probably bad idea arm=self.settings.target_rig,
set_rotation=self.settings.use_bone_rotation,
elif self.settings.method == 'OBJECT': mesh=True)
if not self.settings.target_object:
self.report({'ERROR'}, 'No Object selected')
return {'CANCELLED'}
col = scn.collection # Reset collection filter
target_obj = self.settings.target_object
if target_obj.library:
## Look if an override exists in scene to use instead of default object
if (override := next((o for o in scn.objects if o.name == target_obj.name and o.override_library), None)):
target_obj = override
## Prepare context manager ## Set collection visibility
self.store_list = [ intercol = bpy.data.collections.get('interpolation_tool')
# (context.view_layer.objects, 'active', self.gp), vl_col = bpy.context.view_layer.layer_collection.children.get(intercol.name)
(context.tool_settings, 'use_keyframe_insert_auto', True), intercol.hide_viewport = vl_col.exclude = vl_col.hide_viewport = False
# (bpy.context.scene.render, 'simplify_subdivision', 0),
]
# TODO: for now, the collection filter is not used at all in GEOMETRY mode
# it can be used to hide collection for faster animation mode
if self.settings.method == 'BONE': # Override collection
## TEST: Add collections containing rig (cannot be excluded) col = intercol
# rig_parent_cols = [c.name for c in scn.collection.children_recursive if self.settings.target_rig.name in c.all_objects]
# included_cols += rig_parent_cols dg = bpy.context.evaluated_depsgraph_get()
for vlc in context.view_layer.layer_collection.children: self.strokes_data = []
self.store_list.append(
# (vlc, 'exclude', vlc.name not in included_cols), # If excluded rig does not update !
(vlc, 'hide_viewport', vlc.name not in included_cols), # viewport viz
)
# print(f'Preparation {time()-start:.4f}s')
## Set everything in SETUP list
self.apply_and_store()
if self.settings.method == 'BONE': for si, stroke in enumerate(tgt_strokes):
## replace plane nb_points = len(stroke.points)
_bone_plane = plane_on_bone(self.settings.target_rig.pose.bones.get(self.settings.target_bone),
arm=self.settings.target_rig,
set_rotation=self.settings.use_bone_rotation,
mesh=True)
## Set collection visibility local_co = np.empty(nb_points * 3, dtype='float64')
intercol = bpy.data.collections.get('interpolation_tool') stroke.points.foreach_get('co', local_co)
vl_col = bpy.context.view_layer.layer_collection.children.get(intercol.name) # local_co_3d = local_co.reshape((nb_points, 3))
intercol.hide_viewport = vl_col.exclude = vl_col.hide_viewport = False world_co_3d = matrix_transform(local_co.reshape((nb_points, 3)), matrix)
# Override collection stroke_data = []
col = intercol for i, point in enumerate(stroke.points):
point_co_world = world_co_3d[i]
dg = bpy.context.evaluated_depsgraph_get() if target_obj:
self.strokes_data = [] object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, Vector(point_co_world), origin, dg)
else:
# scene raycast
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
for si, stroke in enumerate(tgt_strokes): ## Increasing search range
nb_points = len(stroke.points) if not object_hit: # or object_hit not in col.all_objects[:]:
found = False
for iteration in range(1, 6):
for square_co in search_square(point_co_world, factor=self.settings.search_range * iteration):
local_co = np.empty(nb_points * 3, dtype='float64') if target_obj:
stroke.points.foreach_get('co', local_co) object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, Vector(square_co), origin, dg)
# local_co_3d = local_co.reshape((nb_points, 3)) else:
world_co_3d = matrix_transform(local_co.reshape((nb_points, 3)), matrix) # scene raycast
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
stroke_data = [] if object_hit: # and object_hit in col.all_objects[:]:
for i, point in enumerate(stroke.points): hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
point_co_world = world_co_3d[i] found = True
if target_obj: # print(f'{si}:{i} iteration {iteration}') # Dbg
object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, Vector(point_co_world), origin, dg)
else:
# scene raycast
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
## Increasing search range
if not object_hit: # or object_hit not in col.all_objects[:]:
found = False
for iteration in range(1, 6):
for square_co in search_square(point_co_world, factor=self.settings.search_range * iteration):
if target_obj:
object_hit, hit_location, tri, tri_indices = obj_ray_cast(target_obj, Vector(square_co), origin, dg)
else:
# scene raycast
object_hit, hit_location, tri, tri_indices = ray_cast_point(point_co_world, origin, dg)
if object_hit: # and object_hit in col.all_objects[:]:
hit_location = intersect_line_plane(origin, point_co_world, tri[0], triangle_normal(*tri))
found = True
# print(f'{si}:{i} iteration {iteration}') # Dbg
break
if found:
break break
if not found: if found:
## /!\ ERROR ! No surface found! break
# For debugging, select only problematic stroke (and point)
for sid, s in enumerate(tgt_strokes):
s.select = sid == si
for ip, p in enumerate(stroke.points):
p.select = ip == i
self.report({'ERROR'}, f'Stroke {si} point {i} could not find underlying geometry')
return {'CANCELLED'}
stroke_data.append((stroke, point_co_world, object_hit, hit_location, tri, tri_indices))
self.strokes_data.append(stroke_data) if not found:
## /!\ ERROR ! No surface found!
# For debugging, select only problematic stroke (and point)
for sid, s in enumerate(tgt_strokes):
s.select = sid == si
for ip, p in enumerate(stroke.points):
p.select = ip == i
self.exit_modal(context, status='ERROR', text=f'Stroke {si} point {i} could not find underlying geometry')
return {'CANCELLED'}
stroke_data.append((stroke, point_co_world, object_hit, hit_location, tri, tri_indices))
if self.debug: self.strokes_data.append(stroke_data)
self.scan_time = time()-self.start
print(f'Scan time {self.scan_time:.4f}s')
# Copy stroke selection
bpy.ops.gpencil.copy()
# Jump frame and paste if self.debug:
bpy.context.window_manager.progress_begin(self.frames_to_jump[0], self.frames_to_jump[-1]) # Pgs self.scan_time = time()-self.start
self.status = 'LOOP' print(f'Scan time {self.scan_time:.4f}s')
# Copy stroke selection
bpy.ops.gpencil.copy()
elif self.status == 'LOOP': # Jump frame and paste
bpy.context.window_manager.progress_begin(self.frames_to_jump[0], self.frames_to_jump[-1]) # Pgs
self.status = 'LOOP'
## -- LOOPTIMER
if event.type == 'TIMER':
if self.status == 'LOOP':
f = self.frames_to_jump[self.loop_count] f = self.frames_to_jump[self.loop_count]
bpy.context.window_manager.progress_update(f) # Pgs bpy.context.window_manager.progress_update(f) # Pgs
scn = bpy.context.scene scn = bpy.context.scene
@ -385,8 +412,11 @@ class GP_OT_interpolate_stroke(bpy.types.Operator):
self.loop_count += 1 self.loop_count += 1
if self.loop_count >= len(self.frames_to_jump): if self.loop_count >= len(self.frames_to_jump):
self.exit_modal() self.exit_modal(context)
return {'FINISHED'} return {'FINISHED'}
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
# context.area.tag_redraw()
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}

View File

@ -45,7 +45,7 @@ class GP_PG_interpolate_settings(PropertyGroup):
items= ( items= (
('FRAME', 'Frame', 'prev/next scene frame depending on the padding options', 0), ('FRAME', 'Frame', 'prev/next scene frame depending on the padding options', 0),
('GPKEY', 'GP Key', 'prev/next Grease pencil key', 1) , ('GPKEY', 'GP Key', 'prev/next Grease pencil key', 1) ,
('RIGKEY', 'Rig Key', 'prev/next armatures keys in targeted collection', 2), ('RIGKEY', 'Rig Key', 'prev/next armatures keys in targeted collection (camera keys are included)', 2),
), ),
default='FRAME', default='FRAME',
description='Select how the previous or next frame should be chosen' description='Select how the previous or next frame should be chosen'
@ -59,8 +59,8 @@ class GP_PG_interpolate_settings(PropertyGroup):
target_collection : PointerProperty( target_collection : PointerProperty(
name='Collection', name='Collection',
type=bpy.types.Collection, type=bpy.types.Collection,
description='Target collection to check armature keyframes from', description='Target collection to get armature keyframes\
# placeholder='Collection' \nNothing = every armature in sccene',
) )
target_rig : PointerProperty( target_rig : PointerProperty(

25
ui.py
View File

@ -6,9 +6,9 @@ class GP_PT_interpolate(bpy.types.Panel):
bl_space_type = 'VIEW_3D' bl_space_type = 'VIEW_3D'
bl_region_type = 'UI' bl_region_type = 'UI'
@classmethod # @classmethod
def poll(cls, context): # def poll(cls, context):
return context.object # and context.object.type == 'GPENCIL' # return context.object
def draw(self, context): def draw(self, context):
settings = bpy.context.scene.gp_interpo_settings settings = bpy.context.scene.gp_interpo_settings
@ -22,10 +22,20 @@ class GP_PT_interpolate(bpy.types.Panel):
prev_icon, next_icon = 'FRAME_PREV', 'FRAME_NEXT' prev_icon, next_icon = 'FRAME_PREV', 'FRAME_NEXT'
else: else:
prev_icon, next_icon = 'PREV_KEYFRAME', 'NEXT_KEYFRAME' prev_icon, next_icon = 'PREV_KEYFRAME', 'NEXT_KEYFRAME'
prev_text = next_text = ''
scn = context.scene
if settings.use_animation:
prev_icon, next_icon = 'PLAY_REVERSE', 'PLAY'
## Show animation range:
prev_text = f'{scn.frame_preview_start if scn.use_preview_range else scn.frame_start} < {scn.frame_current}'
next_text = f'{scn.frame_current} > {scn.frame_preview_end if scn.use_preview_range else scn.frame_end}'
row = col.row(align=True) row = col.row(align=True)
row.scale_x = 3 row.scale_x = 3
row.operator("gp.interpolate_stroke", text="", icon=prev_icon).next = False row.operator("gp.interpolate_stroke", text=prev_text, icon=prev_icon).next = False
row.operator("gp.interpolate_stroke", text="", icon=next_icon).next = True row.operator("gp.interpolate_stroke", text=next_text, icon=next_icon).next = True
col.prop(settings, 'use_animation', text='Animation') col.prop(settings, 'use_animation', text='Animation')
col.prop(settings, 'method', text='Method') col.prop(settings, 'method', text='Method')
@ -39,7 +49,6 @@ class GP_PT_interpolate(bpy.types.Panel):
col.prop(settings, 'use_bone_rotation', text='Use Bone Rotation') col.prop(settings, 'use_bone_rotation', text='Use Bone Rotation')
elif settings.method == 'GEOMETRY': elif settings.method == 'GEOMETRY':
col.prop(settings, 'target_collection', text='Collection')
col.prop(settings, 'search_range') col.prop(settings, 'search_range')
col.prop(settings, 'remove_occluded') col.prop(settings, 'remove_occluded')
@ -53,7 +62,9 @@ class GP_PT_interpolate(bpy.types.Panel):
if settings.mode == 'FRAME': if settings.mode == 'FRAME':
col.prop(settings, 'padding') col.prop(settings, 'padding')
if settings.mode == 'RIGKEY':
col.prop(settings, 'target_collection', text='Collection')
## Parent still full WIP ## Parent still full WIP
# col = layout.column() # col = layout.column()
# col.label(text='Layer Parent') # col.label(text='Layer Parent')

View File

@ -191,6 +191,8 @@ def plane_on_bone(bone, arm=None, cam=None, set_rotation=True, mesh=True):
plane = bpy.data.objects.get('interpolation_plane') plane = bpy.data.objects.get('interpolation_plane')
if not plane: if not plane:
plane = create_plane(name='interpolation_plane') plane = create_plane(name='interpolation_plane')
# Display type as Wire for a discrete XP
plane.display_type = 'WIRE'
if plane.name not in col.objects: if plane.name not in col.objects:
col.objects.link(plane) col.objects.link(plane)
@ -394,18 +396,18 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
direction = 1 if forward else -1 direction = 1 if forward else -1
cur_frame = bpy.context.scene.frame_current cur_frame = bpy.context.scene.frame_current
settings = bpy.context.scene.gp_interpo_settings settings = bpy.context.scene.gp_interpo_settings
scn = bpy.context.scene
if forward:
limit = scn.frame_preview_end if scn.use_preview_range else scn.frame_end
else:
limit = scn.frame_preview_start if scn.use_preview_range else scn.frame_start
frames = []
if settings.mode == 'FRAME': if settings.mode == 'FRAME':
jump = settings.padding * direction jump = settings.padding * direction
if all_keys: if all_keys:
scn = bpy.context.scene
if forward:
limit = scn.frame_preview_end if scn.use_preview_range else scn.frame_end
else:
limit = scn.frame_preview_start if scn.use_preview_range else scn.frame_start
limit += direction # offset by one for limit to be in range limit += direction # offset by one for limit to be in range
return list(range(cur_frame + jump , limit, jump)) return list(range(cur_frame + jump , limit, jump))
else: else:
@ -419,10 +421,17 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
col = settings.target_collection col = settings.target_collection
if not col: if not col:
col = bpy.context.scene.collection col = bpy.context.scene.collection
for arm in [o for o in col.all_objects if o.type == 'ARMATURE']:
if not arm.animation_data or not arm.animation_data.action: objs = [o for o in col.all_objects if o.type == 'ARMATURE']
# Add camera moves detection
objs += [bpy.context.scene.camera]
for obj in objs:
print(obj.name)
if not obj.animation_data or not obj.animation_data.action:
continue continue
frames = [k.co.x for fc in arm.animation_data.action.fcurves for k in fc.keyframe_points] frames += [k.co.x for fc in obj.animation_data.action.fcurves for k in fc.keyframe_points]
if not frames: if not frames:
return [] return []
@ -433,9 +442,9 @@ def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list |
if all_keys: if all_keys:
frames = list(set(frames)) frames = list(set(frames))
if forward: if forward:
frame_list = [int(f) for f in frames if f > cur_frame] frame_list = [int(f) for f in frames if f > cur_frame and f <= limit]
else: else:
frame_list = [int(f) for f in frames if f < cur_frame] frame_list = [int(f) for f in frames if f < cur_frame and f >= limit]
return frame_list return frame_list
if forward: if forward: