Skip to content

Commit

Permalink
-Removed NLA warning
Browse files Browse the repository at this point in the history
-AnimOffset seems to be working fine with NLA now
-AnimOffset color bar and message get removed when opening a new scene.
-Fixed error message when deleting key types
-Addressed an issue when moving unselected keys in KeyManager
-Addressed an error when it could not split a bone data_path to fint its name.
  • Loading branch information
aresdevo committed Feb 16, 2022
1 parent 34d774c commit 28d09be
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*Tested on Blender 2.92 and up.*


> **Warning: Not working well with NLA at the moment**
> **Seems to be working fine with NLA now**
![Shortcut Troubleshoot](images/animaide.jpg)

Expand Down
14 changes: 13 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"name": "AnimAide",
"description": "Helpful tools to manipulate keys on f-curves",
"author": "Ares Deveaux",
"version": (1, 0, 37_1),
"version": (1, 0, 38),
"blender": (2, 92, 0),
"location": "Graph Editor - Dope Sheet - Timeline - 3D View - sidebar and menu bar",
"warning": "This addon is still in development.",
Expand All @@ -36,6 +36,7 @@
import bpy
import atexit
from . import ui, curve_tools, anim_offset, key_manager, prefe, utils
from bpy.app.handlers import persistent
from bpy.props import BoolProperty, EnumProperty, PointerProperty, CollectionProperty, StringProperty
from bpy.types import AddonPreferences, PropertyGroup, Operator

Expand All @@ -58,12 +59,21 @@ class AnimAideScene(PropertyGroup):
prefe.classes + \
(AnimAideScene,)

@persistent
def load_post_handler(scene):
# if support.magnet_handlers in bpy.app.handlers.depsgraph_update_post:
# bpy.app.handlers.depsgraph_update_post.remove(support.magnet_handlers)
utils.remove_message()
print('init')


def register():

for cls in classes:
bpy.utils.register_class(cls)

bpy.app.handlers.load_post.append(load_post_handler)

bpy.types.Scene.animaide = PointerProperty(type=AnimAideScene)

preferences = bpy.context.preferences
Expand Down Expand Up @@ -103,6 +113,8 @@ def unregister():

pref = preferences.addons[prefe.addon_name].preferences

bpy.app.handlers.load_post.remove(load_post_handler)

# bpy.types.TIME_MT_editor_menus.remove(curve_tools.ui.draw_bookmarks)

bpy.types.DOPESHEET_MT_editor_menus.remove(ui.draw_menu)
Expand Down
2 changes: 2 additions & 0 deletions anim_offset/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def execute(self, context):

if support.magnet_handlers not in bpy.app.handlers.depsgraph_update_post:
bpy.app.handlers.depsgraph_update_post.append(support.magnet_handlers)
utils.set_bar_color(0.5, 0.3, 0.2, 1)
utils.add_message(self.message)

# anim_offset_info = bpy.types.SpaceView3D.draw_handler_add(
Expand Down Expand Up @@ -422,6 +423,7 @@ def invoke(self, context, event):
anim_offset.user_scene_auto = scene.tool_settings.use_keyframe_insert_auto
support.store_user_timeline_ranges(context)
bpy.app.handlers.depsgraph_update_post.append(support.magnet_handlers)
utils.set_bar_color(0.5, 0.3, 0.2, 1)
utils.add_message(self.message)

scene.tool_settings.use_keyframe_insert_auto = False
Expand Down
5 changes: 4 additions & 1 deletion anim_offset/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def magnet(context, obj, fcurve):
delta_y = get_delta(context, obj, fcurve)

for k in fcurve.keyframe_points:

if not context.scene.animaide.anim_offset.mask_in_use:
factor = 1
elif scene.frame_start <= k.co.x <= scene.frame_end:
Expand All @@ -172,7 +173,9 @@ def get_delta(context, obj, fcurve):
"""Determine the transformation change by the user of the current object"""

cur_frame = bpy.context.scene.frame_current
curve_value = fcurve.evaluate(cur_frame)
nla_frame = int(context.object.animation_data.nla_tweak_strip_time_to_scene(cur_frame))
nla_dif = nla_frame - cur_frame
curve_value = fcurve.evaluate(cur_frame-nla_dif)

try:
prop = obj.path_resolve(fcurve.data_path)
Expand Down
22 changes: 13 additions & 9 deletions key_manager/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def can_move(l_neighbor, r_neighbor, l_key, r_key):
fcurve.update()
# context.scene.frame_current += amount
frames = amount
else:
if direction == 'LEFT' and right_neighbor:
right_neighbor.co.x = context.scene.frame_current
elif direction == 'RIGHT' and left_neighbor:
left_neighbor.co.x = context.scene.frame_current
frames = 0
# else:
# if direction == 'LEFT' and right_neighbor:
# right_neighbor.co.x = context.scene.frame_current
# elif direction == 'RIGHT' and left_neighbor:
# left_neighbor.co.x = context.scene.frame_current
# frames = 0
fcurve.update()

context.scene.frame_current += frames
Expand Down Expand Up @@ -400,10 +400,14 @@ def delete_by_type(context, key_type):
continue

while key.type == key_type and key.select_control_point:
print('fcurve.data_path: ', fcurve.data_path)
print('fcurve.array_index: ', fcurve.array_index)
print('key.co_ui.x: ', key.co_ui.x)
print('fcurve.group.name: ', fcurve.group.name)
obj.keyframe_delete(fcurve.data_path,
fcurve.array_index,
key.co_ui.x,
fcurve.group.name)
index=fcurve.array_index,
frame=key.co_ui.x,
group=fcurve.group.name)

fcurve.update()

Expand Down
7 changes: 5 additions & 2 deletions utils/curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,11 @@ def valid_fcurve(context, obj, fcurve, check_ui=True):
# return

split_data_path = fcurve.data_path.split(sep='"')
bone_name = split_data_path[1]
bone = obj.data.bones.get(bone_name)
if len(split_data_path) > 1:
bone_name = split_data_path[1]
bone = obj.data.bones.get(bone_name)
else:
bone = None

if not bone:
return False
Expand Down
19 changes: 11 additions & 8 deletions utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,21 @@ def get_items(context, any_mode=False):


text_handle = None
bar_color = None
pref_autosave = None
dopesheet_color = None
graph_color = None
nla_color = None


def set_bar_color(r, g, b, a):
global dopesheet_color, graph_color, nla_color, pref_autosave
# if text_handle is None:
pref_autosave = bpy.context.preferences.use_preferences_save
dopesheet_color = bpy.context.preferences.themes[0].dopesheet_editor.space.header[:]
graph_color = bpy.context.preferences.themes[0].graph_editor.space.header[:]
nla_color = bpy.context.preferences.themes[0].nla_editor.space.header[:]
global bar_color, dopesheet_color, graph_color, nla_color, pref_autosave
if bar_color is None:
bar_color = True
pref_autosave = bpy.context.preferences.use_preferences_save
dopesheet_color = bpy.context.preferences.themes[0].dopesheet_editor.space.header[:]
graph_color = bpy.context.preferences.themes[0].graph_editor.space.header[:]
nla_color = bpy.context.preferences.themes[0].nla_editor.space.header[:]

bpy.context.preferences.use_preferences_save = False
bpy.context.preferences.themes[0].dopesheet_editor.space.header = (r, g, b, a)
Expand Down Expand Up @@ -204,7 +206,7 @@ def draw_text_callback(info):
blf.draw(font_id, info)

if text_handle is None:
set_bar_color(0.5, 0.3, 0.2, 1)
# set_bar_color(0.5, 0.3, 0.2, 1)
text_handle = bpy.types.SpaceView3D.draw_handler_add(
draw_text_callback, (message,),
'WINDOW', 'POST_PIXEL')
Expand All @@ -214,5 +216,6 @@ def remove_message():
global text_handle

reset_bar_color()
bpy.types.SpaceView3D.draw_handler_remove(text_handle, 'WINDOW')
if text_handle:
bpy.types.SpaceView3D.draw_handler_remove(text_handle, 'WINDOW')
text_handle = None

0 comments on commit 28d09be

Please sign in to comment.