From a5d0ae964430ce9d51e5866ffb5e8c75232211bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 23 Feb 2024 16:11:06 +0100 Subject: [PATCH] Anim: Add a simple GUI for assigning Animation data-blocks Add a 'Baklava' panel to the 3D Viewport side-panel. It's a developer-GUI, not meant for animators (or for inclusion beyond the experimental feature, for that matter). Note that this GUI shows all layer properties, even though the data model is currently limited to a single layer. This means that things like 'influence' and 'mix mode' are irrelevant, as there is no underlying layer to mix with. Also key insertion and animation evaluation are not implemented yet (but will be in upcoming commits). For more info, see #113594. Pull Request: https://projects.blender.org/blender/blender/pulls/118677 --- scripts/startup/bl_ui/__init__.py | 2 + scripts/startup/bl_ui/temp_anim_layers.py | 120 ++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 scripts/startup/bl_ui/temp_anim_layers.py diff --git a/scripts/startup/bl_ui/__init__.py b/scripts/startup/bl_ui/__init__.py index c27739e3f5a..73439aad383 100644 --- a/scripts/startup/bl_ui/__init__.py +++ b/scripts/startup/bl_ui/__init__.py @@ -61,6 +61,7 @@ _modules = [ "properties_texture", "properties_world", "properties_collection", + "temp_anim_layers", "generic_ui_list", # Generic Space Modules @@ -121,6 +122,7 @@ def register(): register_class(cls) space_filebrowser.register_props() + temp_anim_layers.register_props() from bpy.props import ( EnumProperty, diff --git a/scripts/startup/bl_ui/temp_anim_layers.py b/scripts/startup/bl_ui/temp_anim_layers.py new file mode 100644 index 00000000000..b427d4787ca --- /dev/null +++ b/scripts/startup/bl_ui/temp_anim_layers.py @@ -0,0 +1,120 @@ +# SPDX-FileCopyrightText: 2023 Blender Authors +# +# SPDX-License-Identifier: GPL-2.0-or-later + +"""NOTE: this is temporary UI code to show animation layers. + +It is not meant for any particular use, just to have *something* in the UI. +""" + +import threading + +import bpy +from bpy.types import Context, Panel, WindowManager +from bpy.props import PointerProperty + + +class VIEW3D_PT_animation_layers(Panel): + bl_space_type = 'VIEW_3D' + bl_region_type = 'UI' + bl_category = "Animation" + bl_label = "Baklava" + + @classmethod + def poll(cls, context: Context) -> bool: + return context.preferences.experimental.use_animation_baklava and context.object + + def draw(self, context: Context) -> None: + layout = self.layout + layout.use_property_split = True + layout.use_property_decorate = False + + # FIXME: this should be done in response to a messagebus callback, notifier, whatnot. + adt = context.object.animation_data + with _wm_selected_animation_lock: + if adt: + context.window_manager.selected_animation = adt.animation + else: + context.window_manager.selected_animation = None + + col = layout.column() + # This has to go via an auxillary property, as assigning an Animation + # data-block should be possible even when `context.object.animation_data` + # is `None`, and thus its `animation` property does not exist. + col.template_ID(context.window_manager, 'selected_animation') + + col = layout.column(align=True) + anim = adt and adt.animation + if anim: + col.prop(adt, 'animation_binding_handle', text="Binding") + binding = [o for o in anim.bindings if o.handle == adt.animation_binding_handle] + if binding: + col.prop(binding[0], 'name', text="Anim Binding Name") + else: + col.label(text="AN Binding Name: -") + if adt: + col.prop(adt, 'animation_binding_name', text="ADT Binding Name") + else: + col.label(text="ADT Binding Name: -") + + layout.separator() + + if not anim: + layout.label(text="No layers") + return + + for layer_idx, layer in reversed(list(enumerate(anim.layers))): + layerbox = layout.box() + col = layerbox.column(align=True) + col.prop(layer, "name", text=f"Layer {layer_idx+1}:") + col.prop(layer, "influence") + col.prop(layer, "mix_mode") + + +classes = ( + VIEW3D_PT_animation_layers, +) + +_wm_selected_animation_lock = threading.Lock() + + +def _wm_selected_animation_update(self: WindowManager, context: Context) -> None: + # Avoid responding to changes written by the panel above. + lock_ok = _wm_selected_animation_lock.acquire(blocking=False) + if not lock_ok: + return + try: + if self.selected_animation is None and context.object.animation_data is None: + return + + adt = context.object.animation_data_create() + if adt.animation == self.selected_animation: + # Avoid writing to the property when the new value hasn't changed. + return + adt.animation = self.selected_animation + finally: + _wm_selected_animation_lock.release() + + +def register_props() -> None: + # Put behind a `try` because it won't exist when Blender is built without + # experimental features. + try: + from bpy.types import Animation + except ImportError: + return + + # Due to this hackyness, the WindowManager will increase the user count of + # the pointed-to Animation data-block. + WindowManager.selected_animation = PointerProperty( + type=Animation, + name="Animation", + description="Animation assigned to the active Object", + update=_wm_selected_animation_update, + ) + + +if __name__ == "__main__": # only for live edit. + register_, _ = bpy.utils.register_classes_factory(classes) + register_() + register_props()