code for growing search -backup old ops method

This commit is contained in:
pullusb
2023-12-07 17:51:12 +01:00
parent 77e3049d5d
commit 52f92ea103
7 changed files with 379 additions and 270 deletions
+62 -2
View File
@@ -133,6 +133,8 @@ def plane_on_bone(bone, arm=None, cam=None, set_rotation=True, mesh=True):
else:
## Use mid bone to better follow movement
mat.translation = arm.matrix_world @ ((bone.tail + bone.head) / 2) # Mid bone
mat_scale = Matrix.Scale(10, 4) # maybe move above mesh condition
if mesh:
# get/create collection
@@ -155,7 +157,6 @@ def plane_on_bone(bone, arm=None, cam=None, set_rotation=True, mesh=True):
return plane
plane = plane_coords()
mat_scale = Matrix.Scale(10, 4) # maybe move above mesh condition
return matrix_transform(plane, mat @ mat_scale)
def create_plane(name='Plane', collection=None):
@@ -274,4 +275,63 @@ def get_gp_draw_plane(obj=None):
plane_no.rotate(mat)
return plane_co, plane_no
return plane_co, plane_no
## --- Animation
def following_keys(forward=True, all_keys=False) -> list:# -> list[int] | list | None:
'''return a lsit 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':
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
return list(range(cur_frame, limit, settings.padding * direction))
else:
return [cur_frame + (settings.padding * direction)]
elif settings.mode == 'GPKEY':
layers = bpy.context.object.data.layers
frames = [f.frame_number for l in layers for f in l.frames]
elif settings.mode == 'RIGKEY':
col = settings.target_collection
if not col:
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:
continue
frames = [k.co.x for fc in arm.animation_data.action.fcurves for k in fc.keyframe_points]
if not frames:
return []
# Sort frames (invert if looking backward)
frames.sort(reversed=not forward)
if all_keys:
frames = list(set(frames))
if forward:
frame_list = [int(f) for f in frames if f > cur_frame]
else:
frame_list = [int(f) for f in frames if f < cur_frame]
return frame_list
if forward:
new = next((f for f in frames if f > cur_frame), None)
else:
new = next((f for f in frames if f < cur_frame), None)
if new is None:
return []
return [int(new)]