The new/experimental, layered `Animation` data-block is merged with the existing `bAction` data-block. The `Animation` data-block is considerably newer than `bAction`, so the supporting code that was written for it is also more modern. When moving that code into `bAction`, I chose to keep the modernity where possible, and thus some of the old code has been updated as well. Things like preferring references over pointers. The `Animation` data-block is now gone from DNA, the main database, etc. As this was still an experimental feature, there is no versioning code to convert any of that to Actions. The DNA struct `bAction` now has a C++ wrapper `animrig::Action`, that can be obtained via `some_action->wrap()`. `animrig::Action` has functions `is_empty()`, `is_action_legacy()`, and `is_action_layered()`. They **all** return `true` when the Action is empty, as in that case none of the data that makes an action either 'legacy' or 'layered' is there. The 'animation filtering' code (for showing things in the dope sheet, graph editor, etc) that I wrote for `Animation` is intentionally kept around. These types now target 'layered actions' and the already-existing ones 'legacy actions'. A future PR may merge these two together, but given how much work it was to add something new there, I'd rather wait until the dust has settled on this commit. There are plenty of variables (and some comments) named `anim` or `animation` that now are of type `animrig::Action`. I haven't renamed them all, to keep the noise level low in this commit (it's already big enough). This can be done in a followup, non-functional PR. Related task: #121355 Pull Request: https://projects.blender.org/blender/blender/pulls/121357
128 lines
4.0 KiB
Python
128 lines
4.0 KiB
Python
# 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 (
|
|
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):
|
|
return context.preferences.experimental.use_animation_baklava and context.object
|
|
|
|
def draw(self, context) -> None:
|
|
layout = self.layout
|
|
layout.use_property_split = True
|
|
layout.use_property_decorate = False
|
|
|
|
# FIXME: this should be done in response to a message-bus callback, notifier, whatnot.
|
|
adt = context.object.animation_data
|
|
with _wm_selected_action_lock:
|
|
if adt:
|
|
context.window_manager.selected_action = adt.action
|
|
else:
|
|
context.window_manager.selected_action = None
|
|
|
|
col = layout.column()
|
|
# This has to go via an auxiliary 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_action')
|
|
|
|
col = layout.column(align=False)
|
|
anim = adt and adt.action
|
|
if anim:
|
|
binding_sub = col.column(align=True)
|
|
|
|
# Binding selector.
|
|
row = binding_sub.row(align=True)
|
|
row.prop(adt, 'action_binding', text="Binding")
|
|
row.operator('anim.binding_unassign_object', text="", icon='X')
|
|
|
|
binding = anim.bindings.get(adt.action_binding, None)
|
|
if binding:
|
|
binding_sub.prop(binding, 'name_display', text="Name")
|
|
|
|
internal_sub = binding_sub.box().column(align=True)
|
|
internal_sub.active = False
|
|
internal_sub.prop(adt, 'action_binding_handle', text="handle")
|
|
if binding:
|
|
internal_sub.prop(binding, 'name', text="Internal Name")
|
|
|
|
if adt:
|
|
col.prop(adt, 'action_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="Layer {:d}:".format(layer_idx + 1))
|
|
col.prop(layer, "influence")
|
|
col.prop(layer, "mix_mode")
|
|
|
|
|
|
classes = (
|
|
VIEW3D_PT_animation_layers,
|
|
)
|
|
|
|
_wm_selected_action_lock = threading.Lock()
|
|
|
|
|
|
def _wm_selected_action_update(wm, context):
|
|
# Avoid responding to changes written by the panel above.
|
|
lock_ok = _wm_selected_action_lock.acquire(blocking=False)
|
|
if not lock_ok:
|
|
return
|
|
try:
|
|
if wm.selected_action is None and context.object.animation_data is None:
|
|
return
|
|
|
|
adt = context.object.animation_data_create()
|
|
if adt.action == wm.selected_action:
|
|
# Avoid writing to the property when the new value hasn't changed.
|
|
return
|
|
adt.action = wm.selected_action
|
|
finally:
|
|
_wm_selected_action_lock.release()
|
|
|
|
|
|
def register_props():
|
|
# Due to this hackyness, the WindowManager will increase the user count of
|
|
# the pointed-to Animation data-block.
|
|
WindowManager.selected_action = PointerProperty(
|
|
type=bpy.types.Action,
|
|
name="Action",
|
|
description="Action assigned to the active Object",
|
|
update=_wm_selected_action_update,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__": # only for live edit.
|
|
register_, _ = bpy.utils.register_classes_factory(classes)
|
|
register_()
|
|
register_props()
|