From a586fd4e3d54a4fc1b079fb53d6e1634b3414c1b Mon Sep 17 00:00:00 2001 From: Wayde Moss Date: Wed, 25 Nov 2020 16:46:32 -0500 Subject: - WIP add nla alignment UI in python --- release/scripts/startup/bl_ui/__init__.py | 1 + release/scripts/startup/bl_ui/properties_nla.py | 113 ++++++++++++++++++++++++ source/blender/blenkernel/intern/anim_sys.c | 12 +++ source/blender/blenkernel/nla_private.h | 8 -- 4 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 release/scripts/startup/bl_ui/properties_nla.py diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py index 7d3ecceca41..e782ff7bfe3 100644 --- a/release/scripts/startup/bl_ui/__init__.py +++ b/release/scripts/startup/bl_ui/__init__.py @@ -49,6 +49,7 @@ _modules = [ "properties_mask_common", "properties_material", "properties_material_gpencil", + "properties_nla", "properties_object", "properties_paint_common", "properties_grease_pencil_common", diff --git a/release/scripts/startup/bl_ui/properties_nla.py b/release/scripts/startup/bl_ui/properties_nla.py new file mode 100644 index 00000000000..88040a5f671 --- /dev/null +++ b/release/scripts/startup/bl_ui/properties_nla.py @@ -0,0 +1,113 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# +from bpy.types import Panel +from bpy.props import (StringProperty, + BoolProperty, + IntProperty, + FloatProperty, + EnumProperty, + PointerProperty, + CollectionProperty, + FloatVectorProperty, + IntVectorProperty, + ) +def get_active_strip(context): + return next([strip for strip in context.selected_nla_strips if strip.active],None) + +class OBJECT_OT_nla_preblend_add_bone(bpy.types.Operator): + bl_idname = "pose.null_op" + bl_label = "NULL OP" + bl_options = {'REGISTER', 'UNDO'} + + preblend_index : IntProperty() + + @classmethod + def poll(cls,context): + return context.selected_nla_strips + + def execute(self, context): + active_strip = get_active_strip() + preblend = active_strip.preblend_transforms[self.preblend_index] + preblend.bones.add() + + return {'FINISHED'} +class OBJECT_OT_nla_preblend_remove_bone(bpy.types.Operator): + bl_idname = "pose.null_op" + bl_label = "NULL OP" + bl_options = {'REGISTER', 'UNDO'} + + preblend_index : IntProperty() + bone_index : IntProperty() + + @classmethod + def poll(cls,context): + return context.selected_nla_strips + + def execute(self, context): + active_strip = get_active_strip() + preblend = active_strip.preblend_transforms[self.preblend_index] + preblend.bones.remove(self.bone_index) + + return {'FINISHED'} +class OBJECT_PT_nla_alignment(Panel): + bl_space_type = 'NLA_EDITOR' + bl_region_type = 'UI' + bl_label = "Alignment" + + + def draw(self, context): + #Q: not in a poll() so it doesnt disappear on nla strip deselection (annoying) + if not context.selected_nla_strips: + return + + layout = self.layout + active_strip = get_active_strip() + + + box = layout.box() + for i,preblend in enumerate(active_strip.preblend_transforms): + box.prop(preblend,"location") + box.prop(preblend,"euler") + box.prop(preblend,"scale") + + col = box.column(align=True) + row = col.row(align=True) + #todo: support for objects? + row.label(text="Bones") + row.operator(OBJECT_OT_nla_preblend_add_bone.bl_idname,text='',icon='ADD').preblend_index = i + for j,bone in enumerate(preblend.bones): + row = box.row(align=True) + row.prop_search(bone,"name",context.active_object.data,"bones",text='') + op = row.operator(OBJECT_OT_nla_preblend_remove_bone.bl_idname,text='',icon='REMOVE') + op.preblend_index = i + op.bone_index = j + + +classes = ( + # Object Panels + OBJECT_PT_nla_alignment, + OBJECT_OT_nla_preblend_remove_bone, + OBJECT_OT_nla_preblend_add_bone, +) + +if __name__ == "__main__": # only for live edit. + from bpy.utils import register_class + for cls in classes: + register_class(cls) diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index a1d577259f7..3d709a41657 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -2996,6 +2996,18 @@ void nlastrip_evaluate(PointerRNA *ptr, /* Apply preblend transforms to each bone's raw snapshot values. */ Object *object = (Object *)ptr->owner_id; bPose *pose = object->pose; + /** + * Assumes preblend xformed bones are root bones with no parents. ( I think that would affect + * conversion to bone local space?). If it has an animated parent, then preblend xforms generally + * won't make sense anyways (not a usecase situation). + * + * Q: maybe the preblend xform should be stored per bone and already in local space? + * + * todo: make preblend xform UI in python... alot easier. + * todo: if strip has cycled, then apply preblend xform based on how far each bone moves per + * cycle. Probably need a toggle per preblend xform for whether cyclic offset if applied (no need + * to be per bone). + */ LISTBASE_FOREACH (NlaStripPreBlendTransform *, preblend, &nes->strip->preblend_transforms) { float world[4][4]; loc_eul_size_to_mat4(world, preblend->location, preblend->rotation_euler, preblend->scale); diff --git a/source/blender/blenkernel/nla_private.h b/source/blender/blenkernel/nla_private.h index b8c0dd5d9f1..420411b12f3 100644 --- a/source/blender/blenkernel/nla_private.h +++ b/source/blender/blenkernel/nla_private.h @@ -154,14 +154,6 @@ typedef struct NlaEvalData { NlaEvalSnapshot eval_snapshot; } NlaEvalData; -typedef struct NlaPoseChannelPreBlend { - // char *bone_name; - NlaEvalChannel *location; - NlaEvalChannel *rotation; - NlaEvalChannel *scale; - -} NlaPoseChannelPreBlend; - /* Information about the currently edited strip and ones below it for keyframing. */ typedef struct NlaKeyframingContext { struct NlaKeyframingContext *next, *prev; -- cgit v1.2.3