2025-07-01
This commit is contained in:
@@ -0,0 +1,299 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
bl_info = {
|
||||
"name": "Animation Layers",
|
||||
"author": "Tal Hershkovich",
|
||||
"version" : (2, 1, 8, 8),
|
||||
"blender" : (3, 2, 0),
|
||||
"location": "View3D - Properties - Animation Panel",
|
||||
"description": "Simplifying the NLA editor into an animation layers UI and workflow",
|
||||
#"warning": "New Branch of Animation Layers, Do not use below Blender v3.2",
|
||||
"wiki_url": "",
|
||||
"category": "Animation"}
|
||||
|
||||
if "bpy" in locals():
|
||||
import importlib
|
||||
if "bake_ops" in locals():
|
||||
importlib.reload(bake_ops)
|
||||
if "anim_layers" in locals():
|
||||
importlib.reload(anim_layers)
|
||||
if "subscriptions" in locals():
|
||||
importlib.reload(subscriptions)
|
||||
if "multikey" in locals():
|
||||
importlib.reload(multikey)
|
||||
if "addon_updater_ops" in locals():
|
||||
importlib.reload(addon_updater_ops)
|
||||
|
||||
import bpy
|
||||
from . import addon_updater_ops
|
||||
from . import anim_layers
|
||||
from . import bake_ops
|
||||
from . import subscriptions
|
||||
from . import multikey
|
||||
from bpy.utils import register_class
|
||||
from bpy.utils import unregister_class
|
||||
|
||||
class AnimLayersSceneSettings(bpy.types.PropertyGroup):
|
||||
bake_range_type: bpy.props.EnumProperty(name = 'Bake Range', description="Use either scene, actions length or custom frame range", default = 'SCENE', update = bake_ops.bake_range_type,
|
||||
items = [('SCENE', 'Scene Range', 'Bake to the scene range'), ('KEYFRAMES', 'Keyframes Range', 'Bake all the keyframes in the layers'), ('CUSTOM', 'Custom', 'Enter a custom frame range')], override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
bake_range: bpy.props.IntVectorProperty(name='Frame Range', description='Bake to a custom frame range', size = 2)
|
||||
handles_type: bpy.props.EnumProperty(name="Handle Types", description="Select handle type before recalculating the handle values", override = {'LIBRARY_OVERRIDABLE'}, default = 'FREE',
|
||||
items = [
|
||||
('PRESERVE', 'Preserve', 'Preserves previous Bezier handlers types before recalculation', 0),
|
||||
( 'FREE', 'Free', 'Bezier handlers get Free handle types before recalculation', 1),
|
||||
('ALIGNED', 'Aligned', 'Bezier handlers get Aligned handle types before recalculation', 2),
|
||||
('VECTOR','Vector', 'Bezier handlers get Vector handle types', 3),
|
||||
('AUTO', 'Auto', 'Bezier handlers get Auto handle types before recalculation',4),
|
||||
('AUTO_CLAMPED', 'Auto Clamped', 'Bezier handlers get Free handle types before recalculation', 5)
|
||||
]
|
||||
)
|
||||
|
||||
viewlayer_objects: bpy.props.IntProperty(name='View Layer Objects', description='checking if objects were turned on or off from the view Layers', default=0)
|
||||
|
||||
class AnimLayersSettings(bpy.types.PropertyGroup):
|
||||
turn_on: bpy.props.BoolProperty(name="Turn Animation Layers On", description="Turn on and start Animation Layers", default=False, options={'HIDDEN'}, update = anim_layers.turn_animlayers_on, override = {'LIBRARY_OVERRIDABLE'})
|
||||
layer_index: bpy.props.IntProperty(update = anim_layers.update_layer_index, options={'LIBRARY_EDITABLE'}, default = 0, override = {'LIBRARY_OVERRIDABLE'})
|
||||
linked: bpy.props.BoolProperty(name="Linked", description="Duplicate a layer with a linked action", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
#Bake settings
|
||||
smartbake: bpy.props.BoolProperty(name="Smart Bake", description="Stay with the same amount of keyframes after merging and baking", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
onlyselected: bpy.props.BoolProperty(name="Only selected Bones", description="Bake only selected Armature controls", default=True, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
clearconstraints: bpy.props.BoolProperty(name="Clear constraints", description="Clear constraints during bake", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mergefcurves: bpy.props.BoolProperty(name="Merge Cyclic & Fcurve modifiers", description="Include Fcurve modifiers in the bake", default = True, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
view_all_keyframes: bpy.props.BoolProperty(name="View", description="View keyframes from multiple layers, use lock and mute to exclude layers", default=False, update = anim_layers.view_all_keyframes, override = {'LIBRARY_OVERRIDABLE'})
|
||||
edit_all_keyframes: bpy.props.BoolProperty(name="Edit", description="Edit keyframes from multiple layers", default=False, update = anim_layers.unlock_edit_keyframes, override = {'LIBRARY_OVERRIDABLE'})
|
||||
only_selected_bones: bpy.props.BoolProperty(name="Only Selected Bones", description="Edit and view only selected bones", default=True, update = anim_layers.only_selected_bones, override = {'LIBRARY_OVERRIDABLE'})
|
||||
view_all_type: bpy.props.EnumProperty(name="Type", description="Select visibiltiy type of keyframes", update = anim_layers.view_all_keyframes, override = {'LIBRARY_OVERRIDABLE'}, default = '2',
|
||||
items = [
|
||||
('0', 'Breakdown', 'select Breakdown visibility'),
|
||||
('1', 'Jitter', 'select Jitter visibility'),
|
||||
('2', 'Moving Hold', 'select Moving Hold visibility'),
|
||||
('3', 'Extreme', 'select Extreme visibility'),
|
||||
('4', 'Keyframe', 'select Keyframe visibility')
|
||||
]
|
||||
)
|
||||
baketype : bpy.props.EnumProperty(name = '', description="Type of Bake", items = [('AL', 'Anim Layers','Use Animation Layers Bake',0), ('NLA', 'NLA Bake', 'Use Blender internal NLA Bake',1)], override = {'LIBRARY_OVERRIDABLE'})
|
||||
direction: bpy.props.EnumProperty(name = '', description="Select direction of merge", items = [('UP', 'Up','Merge upwards','TRIA_UP',1), ('DOWN', 'Down', 'Merge downwards','TRIA_DOWN',0), ('ALL', 'All', 'Merge all layers')], override = {'LIBRARY_OVERRIDABLE'})
|
||||
operator : bpy.props.EnumProperty(name = '', description="Type of bake", items = [('NEW', 'New Baked Layer','Bake into a New Layer','NLA',1), ('MERGE', 'Merge', 'Merge Layers','NLA_PUSHDOWN',0)], override = {'LIBRARY_OVERRIDABLE'})
|
||||
blend_type : bpy.props.EnumProperty(name = 'Blend Type', description="Blend Type",
|
||||
items = [('REPLACE', 'Replace', 'Use as a Base Layer'), ('ADD', 'Add', 'Use as an Additive Layer'), ('SUBTRACT', 'Subtract', 'Use as an Subtract Layer')], update = anim_layers.blend_type_update , override = {'LIBRARY_OVERRIDABLE'})
|
||||
data_type : bpy.props.EnumProperty(name = 'Data Type', description="Select type of action data", default = 'OBJECT', update = anim_layers.data_type_update,
|
||||
items = [('KEY', 'Shapekey', 'Switch to shapekey animation layers'), ('OBJECT', 'Object', 'Switch to object animation')], override = {'LIBRARY_OVERRIDABLE'})#, update = anim_layers.blend_type_update
|
||||
auto_rename: bpy.props.BoolProperty(name="Auto Rename Layer", description="Rename layer to match to selected action", default = True, update = anim_layers.auto_rename, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
auto_blend: bpy.props.BoolProperty(name="Auto Blend", description="Apply blend type automatically based on scale and rotation values", default = False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
fcurves: bpy.props.IntProperty(name='fcurves', description='helper to check if fcurves are changed', default=0, override = {'LIBRARY_OVERRIDABLE'})
|
||||
upper_stack : bpy.props.BoolProperty(name="Upper Stack Evaluation", description="Checks if tweak mode uses upper stack", default=False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
viewlayer : bpy.props.BoolProperty(name="View Layer Exclusion", description="Check if the object was added or removed from the view layer", default=True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
#tools
|
||||
inbetweener : bpy.props.FloatProperty(name='Inbetween Keyframe', description="Adds an inbetween Keyframe between the Layer's neighbor keyframes", soft_min = 0, soft_max = 1, default=0.5, options = set(), override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.add_inbetween_key)
|
||||
share_layer_keys: bpy.props.EnumProperty(name = 'Share Layer Keys', description="Share keyframes positions between layers", items = anim_layers.share_layerkeys_items, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class AnimLayersItems(bpy.types.PropertyGroup):
|
||||
name: bpy.props.StringProperty(name="AnimLayer", override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_name_update)
|
||||
mute: bpy.props.BoolProperty(name="Mute", description="Mute Animation Layer", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_mute)
|
||||
lock: bpy.props.BoolProperty(name="Lock", description="Lock Animation Layer", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_lock)
|
||||
solo: bpy.props.BoolProperty(name="Solo", description="Solo Animation Layer", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_solo)
|
||||
influence: bpy.props.FloatProperty(name="Layer Influence", description="Layer Influence", min = 0.0, options={'ANIMATABLE'}, max = 1.0, default = 1.0, precision = 3, update = anim_layers.influence_update, override = {'LIBRARY_OVERRIDABLE'})
|
||||
influence_mute: bpy.props.BoolProperty(name="Animated Influence", description="Turn Animated influence On/Off", default=False, options={'HIDDEN'}, update = anim_layers.influence_mute_update, override = {'LIBRARY_OVERRIDABLE'})
|
||||
#action_list: bpy.props.EnumProperty(name = 'Actions', description = "Select action", update = anim_layers.load_action, items = anim_layers.action_items, override = {'LIBRARY_OVERRIDABLE'})
|
||||
action: bpy.props.PointerProperty(name = 'action', description = "Select action", type=bpy.types.Action, update = anim_layers.load_action, override = {'LIBRARY_OVERRIDABLE'})
|
||||
action_range: bpy.props.FloatVectorProperty(name='action range', description="used to check if layer needs to update frame range", override = {'LIBRARY_OVERRIDABLE'}, size = 2)
|
||||
frame_range: bpy.props.BoolProperty(name="Custom Frame Range", description="Use a custom frame range per layer instead of the scene frame range", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_frame_range)
|
||||
frame_start: bpy.props.FloatProperty(name='Action Start Frame', description="First frame of the layer's action",min = 0, default=0, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_frame_start)
|
||||
frame_end: bpy.props.FloatProperty(name='Action End Frame', description="End frame of the layer's action", default=0, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_frame_end)
|
||||
speed: bpy.props.FloatProperty(name='Speed of the action', description="Speed of the action strip", default = 1, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_speed)
|
||||
offset: bpy.props.FloatProperty(name='Offset when the action starts', description="Offseting the whole layer animation", default = 0, precision = 2, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_offset)
|
||||
repeat: bpy.props.FloatProperty(name="Repeat", description="Repeat the action", min = 0.1, default = 1, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_repeat)
|
||||
|
||||
|
||||
class AnimLayersObjects(bpy.types.PropertyGroup):
|
||||
|
||||
object: bpy.props.PointerProperty(name = "object", description = "objects with animation layers turned on", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
|
||||
# Add-ons Preferences Update Panel
|
||||
# Define Panel classes for updating
|
||||
panels = (anim_layers.ANIMLAYERS_PT_List, anim_layers.ANIMLAYERS_PT_Ops, anim_layers.ANIMLAYERS_PT_Tools, anim_layers.ANIMLAYERS_PT_Settings) #anim_layers.ANIMLAYERS_PT_Panel, anim_layers.ANIMLAYERS_PT_Multikey,
|
||||
|
||||
def update_panel(self, context):
|
||||
message = "AnimationLayers: Updating Panel locations has failed"
|
||||
try:
|
||||
for panel in panels:
|
||||
if "bl_rna" in panel.__dict__:
|
||||
bpy.utils.unregister_class(panel)
|
||||
|
||||
for panel in panels:
|
||||
#print (panel.bl_category)
|
||||
panel.bl_category = context.preferences.addons[__name__].preferences.category
|
||||
bpy.utils.register_class(panel)
|
||||
|
||||
except Exception as e:
|
||||
print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
|
||||
pass
|
||||
|
||||
@addon_updater_ops.make_annotations
|
||||
class AnimLayersAddonPreferences(bpy.types.AddonPreferences):
|
||||
# this must match the addon name, use '__package__'
|
||||
# when defining this in a submodule of a python package.
|
||||
bl_idname = __package__
|
||||
|
||||
auto_rename: bpy.props.BoolProperty(name="Sync Layer/Action Names", description="Rename layer to match to selected action", default = True)
|
||||
blend_type : bpy.props.EnumProperty(name = 'Default Blend Type', description="Default Blend Type when adding layers", default = 'COMBINE',
|
||||
items = [('COMBINE', 'Combine', 'Use Combine as the default blend type'), ('ADD', 'Add', 'Use Add as the default blend type'), ('REPLACE', 'Replace', 'Use Replace as the default blend type'),
|
||||
('SUBTRACT', 'Subtract', 'Use as an Subtract Layer')])
|
||||
|
||||
frame_range_settings : bpy.props.EnumProperty(name = 'Frame Range Settings', description="Use Either Anim Layers Custom Frame Range Settings or NLA Settings", default = 'ANIMLAYERS',
|
||||
items = [('ANIMLAYERS', 'Anim Layers Settings', 'Use Anim Layers properties to adjust custom frame range'),
|
||||
('NLA', 'NLA Settings', 'Use the nla properties to adjust custom frame range')])
|
||||
|
||||
#Property for ClearActiveAction
|
||||
proceed: bpy.props.EnumProperty(name="Choose how to proceed", description="Select an option how to proceed with Anim Layers", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [
|
||||
('REMOVE_LAYERS', 'Remove old layers and continue with the current action', 'Remove previous Layers and continue with current action in the base layer', 0),
|
||||
( 'REMOVE_ACTION', 'Remove current action and reload older Layers', 'Remove current action and continue with the previous layers', 1),
|
||||
('ADD_ACTION', 'Add the current action as a new Layer', 'Keep previous Anim Layers and Add the active action as a new layer', 2),])
|
||||
|
||||
category: bpy.props.StringProperty(
|
||||
name="Tab Category",
|
||||
description="Choose a name for the category of the panel",
|
||||
default="Animation",
|
||||
update=update_panel
|
||||
)
|
||||
|
||||
# addon updater preferences from `__init__`, be sure to copy all of them
|
||||
auto_check_update: bpy.props.BoolProperty(
|
||||
name = "Auto-check for Update",
|
||||
description = "If enabled, auto-check for updates using an interval",
|
||||
default = False,
|
||||
)
|
||||
|
||||
updater_interval_months: bpy.props.IntProperty(
|
||||
name='Months',
|
||||
description = "Number of months between checking for updates",
|
||||
default=0,
|
||||
min=0
|
||||
)
|
||||
updater_interval_days: bpy.props.IntProperty(
|
||||
name='Days',
|
||||
description = "Number of days between checking for updates",
|
||||
default=7,
|
||||
min=0,
|
||||
|
||||
)
|
||||
updater_interval_hours: bpy.props.IntProperty(
|
||||
name='Hours',
|
||||
description = "Number of hours between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=23
|
||||
)
|
||||
updater_interval_minutes: bpy.props.IntProperty(
|
||||
name='Minutes',
|
||||
description = "Number of minutes between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=59
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
addon_updater_ops.update_settings_ui(self, context)
|
||||
|
||||
col = layout.column()
|
||||
|
||||
col.label(text="Tab Category:")
|
||||
col.prop(self, "category", text="")
|
||||
col.separator(factor = 1)
|
||||
col = col.box()
|
||||
col.label(text="Defaults:")
|
||||
#row = layout.row()
|
||||
split = col.split(factor=0.5, align = True)
|
||||
split.prop(self, "auto_rename")
|
||||
#row.prop(self, "blend_type")
|
||||
#split = row.split(factor=0.7, align = True)
|
||||
|
||||
split.label(text="Default Blend Type: ")
|
||||
split.prop(self,'blend_type', text = '')
|
||||
|
||||
row = col.row()
|
||||
row.label(text = "Custom Frame Range Settings")
|
||||
row.prop(self, "frame_range_settings", text = '')
|
||||
#row = layout.row(align = True)
|
||||
#col = layout.row(bpy.context.scene.als,'blend_type', text = '')
|
||||
|
||||
classes = (AnimLayersSettings, AnimLayersSceneSettings, AnimLayersItems, AnimLayersObjects)
|
||||
|
||||
addon_keymaps = []
|
||||
|
||||
def register():
|
||||
addon_updater_ops.register(bl_info)
|
||||
register_class(AnimLayersAddonPreferences)
|
||||
addon_updater_ops.make_annotations(AnimLayersAddonPreferences) # to avoid blender 2.8 warnings
|
||||
if bpy.app.version < (3, 2, 0):
|
||||
return
|
||||
|
||||
bake_ops.register()
|
||||
anim_layers.register()
|
||||
multikey.register()
|
||||
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.Object.als = bpy.props.PointerProperty(type = AnimLayersSettings, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Scene.als = bpy.props.PointerProperty(type = AnimLayersSceneSettings, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Object.Anim_Layers = bpy.props.CollectionProperty(type = AnimLayersItems, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
bpy.types.Scene.AL_objects = bpy.props.CollectionProperty(type = AnimLayersObjects, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
|
||||
update_panel(None, bpy.context)
|
||||
#update_tweak_keymap()
|
||||
|
||||
#Make sure TAB hotkey in the NLA goes into full stack mode
|
||||
wm = bpy.context.window_manager
|
||||
kc = wm.keyconfigs.addon
|
||||
km = kc.keymaps.new(name= 'NLA Generic', space_type= 'NLA_EDITOR')
|
||||
if 'nla.tweakmode_enter' not in km.keymap_items:
|
||||
kmi = km.keymap_items.new('nla.tweakmode_enter', type= 'TAB', value= 'PRESS')
|
||||
kmi.properties.use_upper_stack_evaluation = True
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
|
||||
def unregister():
|
||||
addon_updater_ops.unregister()
|
||||
unregister_class(AnimLayersAddonPreferences)
|
||||
if bpy.app.version < (3, 2, 0):
|
||||
return
|
||||
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
bake_ops.unregister()
|
||||
anim_layers.unregister()
|
||||
multikey.unregister()
|
||||
del bpy.types.Object.als
|
||||
del bpy.types.Object.Anim_Layers
|
||||
del bpy.types.Scene.AL_objects
|
||||
#removing keymaps
|
||||
for km, kmi in addon_keymaps:
|
||||
km.keymap_items.remove(kmi)
|
||||
addon_keymaps.clear()
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"last_check": "2025-05-28 13:56:15.908215",
|
||||
"backup_date": "",
|
||||
"update_ready": false,
|
||||
"ignore": false,
|
||||
"just_restored": false,
|
||||
"just_updated": false,
|
||||
"version_text": {}
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
bl_info = {
|
||||
"name": "Animation Layers",
|
||||
"author": "Tal Hershkovich",
|
||||
"version" : (2, 1, 9, 7),
|
||||
"blender" : (3, 2, 0),
|
||||
"location": "View3D - Properties - Animation Panel",
|
||||
"description": "Simplifying the NLA editor into an animation layers UI and workflow",
|
||||
"wiki_url": "",
|
||||
"category": "Animation"}
|
||||
|
||||
if "bpy" in locals():
|
||||
import importlib
|
||||
if "bake_ops" in locals():
|
||||
importlib.reload(bake_ops)
|
||||
if "anim_layers" in locals():
|
||||
print('reloading anim layers')
|
||||
importlib.reload(anim_layers)
|
||||
if "subscriptions" in locals():
|
||||
importlib.reload(subscriptions)
|
||||
if "multikey" in locals():
|
||||
importlib.reload(multikey)
|
||||
if "addon_updater_ops" in locals():
|
||||
importlib.reload(addon_updater_ops)
|
||||
|
||||
import bpy
|
||||
from . import addon_updater_ops
|
||||
from . import anim_layers
|
||||
from . import bake_ops
|
||||
from . import subscriptions
|
||||
from . import multikey
|
||||
from bpy.utils import register_class
|
||||
from bpy.utils import unregister_class
|
||||
|
||||
class AnimLayersSceneSettings(bpy.types.PropertyGroup):
|
||||
bake_range_type: bpy.props.EnumProperty(name = 'Bake Range', description="Use either scene, actions length or custom frame range", default = 'SCENE', update = bake_ops.bake_range_type,
|
||||
items = [('SCENE', 'Scene Range', 'Bake to the scene range'), ('KEYFRAMES', 'Keyframes Range', 'Bake all the keyframes in the layers'), ('CUSTOM', 'Custom', 'Enter a custom frame range')], override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
bake_range: bpy.props.IntVectorProperty(name='Frame Range', description='Bake to a custom frame range', size = 2)
|
||||
handles_type: bpy.props.EnumProperty(name="Handle Types", description="Select handle type before recalculating the handle values", override = {'LIBRARY_OVERRIDABLE'}, default = 'FREE',
|
||||
items = [
|
||||
('PRESERVE', 'Preserve', 'Preserves previous Bezier handlers types before recalculation', 0),
|
||||
( 'FREE', 'Free', 'Bezier handlers get Free handle types before recalculation', 1),
|
||||
('ALIGNED', 'Aligned', 'Bezier handlers get Aligned handle types before recalculation', 2),
|
||||
('VECTOR','Vector', 'Bezier handlers get Vector handle types', 3),
|
||||
('AUTO', 'Auto', 'Bezier handlers get Auto handle types before recalculation',4),
|
||||
('AUTO_CLAMPED', 'Auto Clamped', 'Bezier handlers get Free handle types before recalculation', 5)
|
||||
]
|
||||
)
|
||||
|
||||
class AnimLayersSettings(bpy.types.PropertyGroup):
|
||||
turn_on: bpy.props.BoolProperty(name="Turn Animation Layers On", description="Turn on and start Animation Layers", default=False, options={'HIDDEN'}, update = anim_layers.turn_animlayers_on, override = {'LIBRARY_OVERRIDABLE'})
|
||||
layer_index: bpy.props.IntProperty(update = anim_layers.update_layer_index, options={'LIBRARY_EDITABLE'}, default = 0, override = {'LIBRARY_OVERRIDABLE'})
|
||||
linked: bpy.props.BoolProperty(name="Linked", description="Duplicate a layer with a linked action", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
#Bake settings
|
||||
smartbake: bpy.props.BoolProperty(name="Smart Bake", description="Stay with the same amount of keyframes after merging and baking", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
onlyselected: bpy.props.BoolProperty(name="Only selected Bones", description="Bake only selected Armature controls", default=True, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
clearconstraints: bpy.props.BoolProperty(name="Clear constraints", description="Clear constraints during bake", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mergefcurves: bpy.props.BoolProperty(name="Merge Cyclic & Fcurve modifiers", description="Include Fcurve modifiers in the bake", default = True, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
view_all_keyframes: bpy.props.BoolProperty(name="View", description="View keyframes from multiple layers, use lock and mute to exclude layers", default=False, update = anim_layers.view_all_keyframes, override = {'LIBRARY_OVERRIDABLE'})
|
||||
edit_all_keyframes: bpy.props.BoolProperty(name="Edit", description="Edit keyframes from multiple layers", default=False, update = anim_layers.unlock_edit_keyframes, override = {'LIBRARY_OVERRIDABLE'})
|
||||
only_selected_bones: bpy.props.BoolProperty(name="Only Selected Bones", description="Edit and view only selected bones", default=True, update = anim_layers.only_selected_bones, override = {'LIBRARY_OVERRIDABLE'})
|
||||
view_all_type: bpy.props.EnumProperty(name="Type", description="Select visibiltiy type of keyframes", update = anim_layers.view_all_keyframes, override = {'LIBRARY_OVERRIDABLE'}, default = '2',
|
||||
items = [
|
||||
('0', 'Breakdown', 'select Breakdown visibility'),
|
||||
('1', 'Jitter', 'select Jitter visibility'),
|
||||
('2', 'Moving Hold', 'select Moving Hold visibility'),
|
||||
('3', 'Extreme', 'select Extreme visibility'),
|
||||
('4', 'Keyframe', 'select Keyframe visibility')
|
||||
]
|
||||
)
|
||||
baketype : bpy.props.EnumProperty(name = '', description="Type of Bake", items = [('AL', 'Anim Layers','Use Animation Layers Bake',0), ('NLA', 'NLA Bake', 'Use Blender internal NLA Bake',1)], override = {'LIBRARY_OVERRIDABLE'})
|
||||
direction: bpy.props.EnumProperty(name = '', description="Select direction of merge", items = [('UP', 'Up','Merge upwards','TRIA_UP',1), ('DOWN', 'Down', 'Merge downwards','TRIA_DOWN',0), ('ALL', 'All', 'Merge all layers')], override = {'LIBRARY_OVERRIDABLE'})
|
||||
operator : bpy.props.EnumProperty(name = '', description="Type of bake", items = [('NEW', 'New Baked Layer','Bake into a New Layer','NLA',1), ('MERGE', 'Merge', 'Merge Layers','NLA_PUSHDOWN',0)], override = {'LIBRARY_OVERRIDABLE'})
|
||||
blend_type : bpy.props.EnumProperty(name = 'Blend Type', description="Blend Type",
|
||||
items = [('REPLACE', 'Replace', 'Use as a Base Layer'), ('ADD', 'Add', 'Use as an Additive Layer'), ('SUBTRACT', 'Subtract', 'Use as an Subtract Layer')], update = anim_layers.blend_type_update , override = {'LIBRARY_OVERRIDABLE'})
|
||||
data_type : bpy.props.EnumProperty(name = 'Data Type', description="Select type of action data", default = 'OBJECT', update = anim_layers.data_type_update,
|
||||
items = [('KEY', 'Shapekey', 'Switch to shapekey animation layers'), ('OBJECT', 'Object', 'Switch to object animation')], override = {'LIBRARY_OVERRIDABLE'})#, update = anim_layers.blend_type_update
|
||||
auto_rename: bpy.props.BoolProperty(name="Auto Rename Layer", description="Rename layer to match to selected action", default = True, update = anim_layers.auto_rename, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
auto_blend: bpy.props.BoolProperty(name="Auto Blend", description="Apply blend type automatically based on scale and rotation values", default = False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
fcurves: bpy.props.IntProperty(name='fcurves', description='helper to check if fcurves are changed', default=0, override = {'LIBRARY_OVERRIDABLE'})
|
||||
upper_stack : bpy.props.BoolProperty(name="Upper Stack Evaluation", description="Checks if tweak mode uses upper stack", default=False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
#Tools
|
||||
inbetweener : bpy.props.FloatProperty(name='Inbetween Keyframe', description="Adds an inbetween Keyframe between the Layer's neighbor keyframes", soft_min = 0, soft_max = 1, default=0.5, options = set(), override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.add_inbetween_key)
|
||||
share_layer_keys: bpy.props.EnumProperty(name = 'Share Layer Keys', description="Share keyframes positions between layers", items = anim_layers.share_layerkeys_items, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class AnimLayersItems(bpy.types.PropertyGroup):
|
||||
name: bpy.props.StringProperty(name="AnimLayer", override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_name_update)
|
||||
mute: bpy.props.BoolProperty(name="Mute", description="Mute Animation Layer", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_mute)
|
||||
lock: bpy.props.BoolProperty(name="Lock", description="Lock Animation Layer", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_lock)
|
||||
solo: bpy.props.BoolProperty(name="Solo", description="Solo Animation Layer", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_solo)
|
||||
influence: bpy.props.FloatProperty(name="Layer Influence", description="Layer Influence", min = 0.0, options={'ANIMATABLE'}, max = 1.0, default = 1.0, precision = 3, update = anim_layers.influence_update, override = {'LIBRARY_OVERRIDABLE'})
|
||||
influence_mute: bpy.props.BoolProperty(name="Animated Influence", description="Turn Animated influence On/Off", default=False, options={'HIDDEN'}, update = anim_layers.influence_mute_update, override = {'LIBRARY_OVERRIDABLE'})
|
||||
#action_list: bpy.props.EnumProperty(name = 'Actions', description = "Select action", update = anim_layers.load_action, items = anim_layers.action_items, override = {'LIBRARY_OVERRIDABLE'})
|
||||
action: bpy.props.PointerProperty(name = 'action', description = "Select action", type=bpy.types.Action, update = anim_layers.load_action, override = {'LIBRARY_OVERRIDABLE'})
|
||||
action_range: bpy.props.FloatVectorProperty(name='action range', description="used to check if layer needs to update frame range", override = {'LIBRARY_OVERRIDABLE'}, size = 2)
|
||||
frame_range: bpy.props.BoolProperty(name="Custom Frame Range", description="Use a custom frame range per layer instead of the scene frame range", default=False, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_frame_range)
|
||||
frame_start: bpy.props.FloatProperty(name='Action Start Frame', description="First frame of the layer's action",min = 0, default=0, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_frame_start)
|
||||
frame_end: bpy.props.FloatProperty(name='Action End Frame', description="End frame of the layer's action", default=0, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_frame_end)
|
||||
speed: bpy.props.FloatProperty(name='Speed of the action', description="Speed of the action strip", default = 1, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_speed)
|
||||
offset: bpy.props.FloatProperty(name='Offset when the action starts', description="Offseting the whole layer animation", default = 0, precision = 2, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_offset)
|
||||
repeat: bpy.props.FloatProperty(name="Repeat", description="Repeat the action", min = 0.1, default = 1, options={'HIDDEN'}, override = {'LIBRARY_OVERRIDABLE'}, update = anim_layers.layer_repeat)
|
||||
|
||||
|
||||
class AnimLayersObjects(bpy.types.PropertyGroup):
|
||||
|
||||
object: bpy.props.PointerProperty(name = "object", description = "objects with animation layers turned on", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
|
||||
# Add-ons Preferences Update Panel
|
||||
# Define Panel classes for updating
|
||||
panels = anim_layers.panel_classes
|
||||
def update_panel(self, context):
|
||||
anim_layers.unregister_panels()
|
||||
anim_layers.register_panels()
|
||||
|
||||
message = "AnimationLayers: Updating Panel locations has failed"
|
||||
try:
|
||||
for panel in panels:
|
||||
if "bl_rna" in panel.__dict__:
|
||||
bpy.utils.unregister_class(panel)
|
||||
|
||||
for panel in panels:
|
||||
#print (panel.bl_category)
|
||||
panel.bl_category = context.preferences.addons[__name__].preferences.category
|
||||
bpy.utils.register_class(panel)
|
||||
|
||||
except Exception as e:
|
||||
print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
|
||||
pass
|
||||
|
||||
@addon_updater_ops.make_annotations
|
||||
class AnimLayersAddonPreferences(bpy.types.AddonPreferences):
|
||||
# this must match the addon name, use '__package__'
|
||||
# when defining this in a submodule of a python package.
|
||||
bl_idname = __package__
|
||||
|
||||
auto_rename: bpy.props.BoolProperty(name="Sync Layer/Action Names", description="Rename layer to match to selected action", default = True)
|
||||
blend_type : bpy.props.EnumProperty(name = 'Default Blend Type', description="Default Blend Type when adding layers", default = 'COMBINE',
|
||||
items = [('COMBINE', 'Combine', 'Use Combine as the default blend type'), ('ADD', 'Add', 'Use Add as the default blend type'), ('REPLACE', 'Replace', 'Use Replace as the default blend type'),
|
||||
('SUBTRACT', 'Subtract', 'Use as an Subtract Layer')])
|
||||
|
||||
frame_range_settings : bpy.props.EnumProperty(name = 'Frame Range Settings', description="Use Either Anim Layers Custom Frame Range Settings or NLA Settings", default = 'ANIMLAYERS',
|
||||
items = [('ANIMLAYERS', 'Anim Layers Settings', 'Use Anim Layers properties to adjust custom frame range'),
|
||||
('NLA', 'NLA Settings', 'Use the nla properties to adjust custom frame range')])
|
||||
|
||||
#Property for ClearActiveAction
|
||||
proceed: bpy.props.EnumProperty(name="Choose how to proceed", description="Select an option how to proceed with Anim Layers", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [
|
||||
('REMOVE_LAYERS', 'Remove old layers and continue with the current action', 'Remove previous Layers and continue with current action in the base layer', 0),
|
||||
( 'REMOVE_ACTION', 'Remove current action and reload older Layers', 'Remove current action and continue with the previous layers', 1),
|
||||
('ADD_ACTION', 'Add the current action as a new Layer', 'Keep previous Anim Layers and Add the active action as a new layer', 2),])
|
||||
|
||||
enabled_editors: bpy.props.EnumProperty(
|
||||
name="Enabled Editors",
|
||||
description="Select which editors should show animation layers panels",
|
||||
items=[('VIEW_3D', "3D View", ""), ('GRAPH_EDITOR', "Graph Editor", ""), ('DOPESHEET_EDITOR', "Dope Sheet", ""),('NLA_EDITOR', "NLA Editor", ""),],
|
||||
options={'ENUM_FLAG'},
|
||||
default={'VIEW_3D', 'NLA_EDITOR'},
|
||||
update=update_panel
|
||||
)
|
||||
|
||||
category: bpy.props.StringProperty(
|
||||
name="Tab Category",
|
||||
description="Choose a name for the category of the panel",
|
||||
default="Animation",
|
||||
update=update_panel
|
||||
)
|
||||
|
||||
# addon updater preferences from `__init__`, be sure to copy all of them
|
||||
auto_check_update: bpy.props.BoolProperty(
|
||||
name = "Auto-check for Update",
|
||||
description = "If enabled, auto-check for updates using an interval",
|
||||
default = False,
|
||||
)
|
||||
|
||||
updater_interval_months: bpy.props.IntProperty(
|
||||
name='Months',
|
||||
description = "Number of months between checking for updates",
|
||||
default=0,
|
||||
min=0
|
||||
)
|
||||
updater_interval_days: bpy.props.IntProperty(
|
||||
name='Days',
|
||||
description = "Number of days between checking for updates",
|
||||
default=7,
|
||||
min=0,
|
||||
|
||||
)
|
||||
updater_interval_hours: bpy.props.IntProperty(
|
||||
name='Hours',
|
||||
description = "Number of hours between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=23
|
||||
)
|
||||
updater_interval_minutes: bpy.props.IntProperty(
|
||||
name='Minutes',
|
||||
description = "Number of minutes between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=59
|
||||
)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
addon_updater_ops.update_settings_ui(self, context)
|
||||
|
||||
col = layout.column()
|
||||
|
||||
col.label(text="Tab Category:")
|
||||
col.prop(self, "category", text="")
|
||||
row = layout.row()
|
||||
row.prop(self, "enabled_editors")
|
||||
col = layout.column()
|
||||
col.separator(factor = 1)
|
||||
col = col.box()
|
||||
col.label(text="Defaults:")
|
||||
#row = layout.row()
|
||||
split = col.split(factor=0.5, align = True)
|
||||
split.prop(self, "auto_rename")
|
||||
#row.prop(self, "blend_type")
|
||||
#split = row.split(factor=0.7, align = True)
|
||||
|
||||
split.label(text="Default Blend Type: ")
|
||||
split.prop(self,'blend_type', text = '')
|
||||
|
||||
row = col.row()
|
||||
row.label(text = "Custom Frame Range Settings")
|
||||
row.prop(self, "frame_range_settings", text = '')
|
||||
#row = layout.row(align = True)
|
||||
#col = layout.row(bpy.context.scene.als,'blend_type', text = '')
|
||||
|
||||
classes = (AnimLayersSettings, AnimLayersSceneSettings, AnimLayersItems, AnimLayersObjects)
|
||||
|
||||
addon_keymaps = []
|
||||
|
||||
def register():
|
||||
addon_updater_ops.register(bl_info)
|
||||
register_class(AnimLayersAddonPreferences)
|
||||
addon_updater_ops.make_annotations(AnimLayersAddonPreferences) # to avoid blender 2.8 warnings
|
||||
if bpy.app.version < (3, 2, 0):
|
||||
return
|
||||
|
||||
bake_ops.register()
|
||||
anim_layers.register()
|
||||
multikey.register()
|
||||
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.Object.als = bpy.props.PointerProperty(type = AnimLayersSettings, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Scene.als = bpy.props.PointerProperty(type = AnimLayersSceneSettings, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Object.Anim_Layers = bpy.props.CollectionProperty(type = AnimLayersItems, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
bpy.types.Scene.AL_objects = bpy.props.CollectionProperty(type = AnimLayersObjects, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
|
||||
update_panel(None, bpy.context)
|
||||
#update_tweak_keymap()
|
||||
|
||||
#Make sure TAB hotkey in the NLA goes into full stack mode
|
||||
wm = bpy.context.window_manager
|
||||
kc = wm.keyconfigs.addon
|
||||
km = kc.keymaps.new(name= 'NLA Generic', space_type= 'NLA_EDITOR')
|
||||
if 'nla.tweakmode_enter' not in km.keymap_items:
|
||||
kmi = km.keymap_items.new('nla.tweakmode_enter', type= 'TAB', value= 'PRESS')
|
||||
kmi.properties.use_upper_stack_evaluation = True
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
|
||||
def unregister():
|
||||
addon_updater_ops.unregister()
|
||||
unregister_class(AnimLayersAddonPreferences)
|
||||
if bpy.app.version < (3, 2, 0):
|
||||
return
|
||||
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
bake_ops.unregister()
|
||||
anim_layers.unregister()
|
||||
multikey.unregister()
|
||||
del bpy.types.Object.als
|
||||
del bpy.types.Object.Anim_Layers
|
||||
del bpy.types.Scene.AL_objects
|
||||
#removing keymaps
|
||||
for km, kmi in addon_keymaps:
|
||||
km.keymap_items.remove(kmi)
|
||||
addon_keymaps.clear()
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
File diff suppressed because it is too large
Load Diff
+1560
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"last_check": "2025-06-04 16:35:52.082677",
|
||||
"backup_date": "May-6-2025",
|
||||
"update_ready": true,
|
||||
"ignore": false,
|
||||
"just_restored": false,
|
||||
"just_updated": false,
|
||||
"version_text": {
|
||||
"link": "https://gitlab.com/api/v4/projects/22294607/repository/archive.zip?sha=d8a2bbe2878233bf807b592e59fd534918d2dabf",
|
||||
"version": [
|
||||
2,
|
||||
1,
|
||||
9,
|
||||
8
|
||||
]
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,510 @@
|
||||
# if "bpy" in locals():
|
||||
# import importlib
|
||||
# if "multikey" in locals():
|
||||
# importlib.reload()
|
||||
|
||||
import bpy
|
||||
import random
|
||||
import numpy as np
|
||||
from mathutils import Quaternion
|
||||
from . import bake_ops
|
||||
from . import anim_layers
|
||||
|
||||
def attr_default(obj, fcu_key):
|
||||
#check if the fcurve source belongs to a bone or obj
|
||||
if fcu_key[0][:10] == 'pose.bones':
|
||||
transform = fcu_key[0].split('.')[-1]
|
||||
attr = fcu_key[0].split('"')[-2]
|
||||
bone = fcu_key[0].split('"')[1]
|
||||
source = obj.pose.bones[bone]
|
||||
|
||||
#in case of shapekey animation
|
||||
elif fcu_key[0][:10] == 'key_blocks':
|
||||
attr = fcu_key[0].split('"')[1]
|
||||
shapekey = obj.data.shape_keys.key_blocks[attr]
|
||||
return 0 if shapekey.slider_min <= 0 else shapekey.slider_min
|
||||
#in case of transforms in object mode
|
||||
else:# fcu_key[0] in transform_types:
|
||||
source = obj
|
||||
transform = fcu_key[0]
|
||||
|
||||
#check when it's transform property of Blender
|
||||
if transform in source.bl_rna.properties.keys():
|
||||
if hasattr(source.bl_rna.properties[transform], 'default_array'):
|
||||
if len(source.bl_rna.properties[transform].default_array) > fcu_key[1]:
|
||||
attrvalue = source.bl_rna.properties[transform].default_array[fcu_key[1]]
|
||||
return attrvalue
|
||||
|
||||
#in case of property on object
|
||||
elif fcu_key[0].split('"')[1] in obj.keys():
|
||||
attr = fcu_key[0].split('"')[1]
|
||||
|
||||
if 'attr' not in locals():
|
||||
return 0
|
||||
|
||||
#since blender 3 access to custom property settings changed
|
||||
if attr in source:
|
||||
id_attr = source.id_properties_ui(attr).as_dict()
|
||||
attrvalue = id_attr['default']
|
||||
return attrvalue
|
||||
|
||||
return 0
|
||||
|
||||
def store_handles(key):
|
||||
#storing the distance between the handles bezier to the key value
|
||||
handle_r = key.handle_right[1] - key.co[1]
|
||||
handle_l = key.handle_left[1] - key.co[1]
|
||||
|
||||
return handle_r, handle_l
|
||||
|
||||
def apply_handles(key, handle_r, handle_l):
|
||||
key.handle_right[1] = key.co[1] + handle_r
|
||||
key.handle_left[1] = key.co[1] + handle_l
|
||||
|
||||
def filter_properties(obj, fcu):
|
||||
'Filter the W X Y Z attributes of the transform properties'
|
||||
|
||||
transformations = ["rotation_quaternion","rotation_euler", "location", "scale"]
|
||||
#check if the fcurve data path ends with any of the transformations
|
||||
if not any(fcu.data_path.endswith(transform) for transform in transformations):
|
||||
return True
|
||||
transform = fcu.data_path.split('"].')[1] if obj.mode == 'POSE' else fcu.data_path
|
||||
index = fcu.array_index
|
||||
if 'rotation' in transform:
|
||||
if transform == 'rotation_euler':
|
||||
index -= 1
|
||||
transform = 'rotation'
|
||||
transform = 'filter_' + transform
|
||||
#in case of channels like bbone_scalein that are no included then return
|
||||
if not hasattr(bpy.context.scene.multikey, transform):
|
||||
return True
|
||||
attr = getattr(bpy.context.scene.multikey, transform)
|
||||
return True if attr[index] else False
|
||||
|
||||
def add_value(key, value):
|
||||
if key.select_control_point:
|
||||
#store handle values in relative to the keyframe value
|
||||
handle_r, handle_l = store_handles(key)
|
||||
|
||||
key.co[1] += value
|
||||
apply_handles(key, handle_r, handle_l)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
def add_diff(obj, fcurves, path, current_value, eval_array):
|
||||
'''Get the difference value and add it to all selected keyframes'''
|
||||
array_value = current_value - eval_array
|
||||
|
||||
if not any(array_value):
|
||||
return
|
||||
for i, value in enumerate(array_value):
|
||||
fcu = fcurves.find(path, index = i)
|
||||
if fcu is None or not filter_properties(obj, fcu):
|
||||
continue
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value)
|
||||
fcu.update()
|
||||
|
||||
class ScaleValuesOp(bpy.types.Operator):
|
||||
"""Modal operator used while scale value is running before release"""
|
||||
bl_idname = "anim.multikey_scale_value"
|
||||
bl_label = "Scale Values"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
#reset the values for dragging
|
||||
self.stop = False
|
||||
scene = context.scene
|
||||
global is_dragging
|
||||
is_dragging = True
|
||||
|
||||
self.avg_value = dict()
|
||||
#dictionary of the keyframes and their original INITIAL values
|
||||
self.keyframes_values = dict()
|
||||
self.keyframes_handle_right = dict()
|
||||
self.keyframes_handle_left = dict()
|
||||
|
||||
#the average value for each fcurve
|
||||
self.keyframes_avg_value = dict()
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
action = obj.animation_data.action
|
||||
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
for fcu in fcurves:
|
||||
if anim_layers.selected_bones_filter(obj, fcu):
|
||||
continue
|
||||
if not filter_properties(obj, fcu):
|
||||
continue
|
||||
|
||||
#avg and value list per fcurve
|
||||
avg_value = []
|
||||
value_list = []
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
value_list.append(key.co[1])
|
||||
self.keyframes_values.update({key : key.co[1]})
|
||||
self.keyframes_handle_right.update({key : key.handle_right[1]})
|
||||
self.keyframes_handle_left.update({key : key.handle_left[1]})
|
||||
|
||||
if len(value_list)>1:
|
||||
#the average value with the scale property added to it
|
||||
avg_value = sum(value_list) / len(value_list)
|
||||
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
self.keyframes_avg_value.update({key : avg_value})
|
||||
|
||||
if not self.keyframes_avg_value:
|
||||
if 'is_dragging' in globals():
|
||||
del is_dragging
|
||||
scene.multikey['scale'] = 1
|
||||
anim_layers.redraw_areas(['VIEW_3D'])
|
||||
return('CANCELLED')
|
||||
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
def modal(self, context, event):
|
||||
|
||||
global is_dragging
|
||||
|
||||
try:
|
||||
scene = context.scene
|
||||
scale = scene.multikey.scale
|
||||
#Quit the modal operator when the slider is released
|
||||
if self.stop:
|
||||
del is_dragging
|
||||
scene.multikey['scale'] = 1
|
||||
anim_layers.redraw_areas(['VIEW_3D'])
|
||||
#modal is being cancelled because of undo issue with the modal running through the property
|
||||
return {'FINISHED'}
|
||||
if event.value == 'RELEASE': # Stop the modal on next frame. Don't block the event since we want to exit the field dragging
|
||||
self.stop = True
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
for key, key_value in self.keyframes_values.items():
|
||||
if not key.select_control_point:
|
||||
continue
|
||||
if key not in self.keyframes_avg_value:
|
||||
continue
|
||||
avg_value = self.keyframes_avg_value[key]
|
||||
handle_right_value = self.keyframes_handle_right[key]
|
||||
handle_left_value = self.keyframes_handle_left[key]
|
||||
|
||||
#add the value of the distance from the average * scale factor
|
||||
key.co[1] = avg_value + ((key_value - avg_value)*scale)
|
||||
key.handle_right[1] = avg_value + ((handle_right_value - avg_value)*scale)
|
||||
key.handle_left[1] = avg_value + ((handle_left_value - avg_value)*scale)
|
||||
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
except Exception as e:
|
||||
# Log the error
|
||||
print("Error:", e)
|
||||
self['scale'] = 1
|
||||
self.stop = True
|
||||
del is_dragging
|
||||
return {'CANCELLED'}
|
||||
|
||||
def scale_value(self, context):
|
||||
|
||||
if 'is_dragging' in globals():
|
||||
if is_dragging:
|
||||
return
|
||||
|
||||
obj = context.object
|
||||
|
||||
if obj is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
action = obj.animation_data.action
|
||||
|
||||
if action is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
if context.mode == 'POSE' and not context.selected_pose_bones:
|
||||
self['scale'] = 1
|
||||
return
|
||||
bpy.ops.anim.multikey_scale_value('INVOKE_DEFAULT')
|
||||
|
||||
def random_value(self, context):
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
action = obj.animation_data.action
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
for fcu in fcurves:
|
||||
# if obj.mode == 'POSE':
|
||||
if anim_layers.selected_bones_filter(obj, fcu):
|
||||
continue
|
||||
if not filter_properties(obj, fcu):
|
||||
continue
|
||||
value_list = []
|
||||
threshold = bpy.context.scene.multikey.randomness
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point == True:
|
||||
value_list.append(key.co[1])
|
||||
|
||||
if len(value_list) > 0:
|
||||
value = max(value_list)- min(value_list)
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value * random.uniform(-threshold, threshold))
|
||||
fcu.update()
|
||||
|
||||
self['randomness'] = 0.1
|
||||
|
||||
def evaluate_combine(data_path, added_array, eval_array, array_default, influence):
|
||||
|
||||
if 'scale' in data_path:
|
||||
eval_array = eval_array * (added_array / array_default) ** influence
|
||||
elif 'rotation_quaternion' in data_path:
|
||||
#multiply first the influence with the w separatly
|
||||
added_array[0] = added_array[0] + (1- added_array[0])*(1 - influence)
|
||||
added_array[1:] *= influence
|
||||
eval_array = np.array(Quaternion(eval_array) @ Quaternion(added_array))# ** influence
|
||||
#if it's a custom property
|
||||
elif 'rotation_euler' not in data_path and 'location' not in data_path:
|
||||
eval_array = eval_array + (added_array - array_default) * influence
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_array(fcurves, fcu_path, frame, array_default = [0, 0, 0]):
|
||||
'''Create an array from all the indexes'''
|
||||
|
||||
array_len = len(array_default)
|
||||
|
||||
# fcu_array = array_default if array_len == 4 else [0, 0, 0]
|
||||
fcu_array = []
|
||||
#get the missing arrays in case quaternion is not complete
|
||||
missing_arrays = []
|
||||
for i in range(array_len):
|
||||
fcu = fcurves.find(fcu_path, index = i)
|
||||
if fcu is None:
|
||||
missing_arrays.append(i)
|
||||
continue
|
||||
|
||||
fcu_array.append(fcu.evaluate(frame))
|
||||
|
||||
#In case it's a quaternion and missing attributes, then adding from default value
|
||||
if fcu_array and array_len == 4 and missing_arrays:
|
||||
for i in missing_arrays:
|
||||
fcu_array.insert(i, array_default[i])
|
||||
|
||||
if not len(fcu_array):
|
||||
return None
|
||||
return np.array(fcu_array)
|
||||
|
||||
def evaluate_layers(context, obj, anim_data, fcu, array_default):
|
||||
'''Calculate the evaluation of all the layers when using the nla'''
|
||||
|
||||
if not hasattr(anim_data, 'nla_tracks') or not anim_data.use_nla:
|
||||
return None
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return None
|
||||
frame = context.scene.frame_current
|
||||
blend_types = {'ADD' : '+', 'SUBTRACT' : '-', 'MULTIPLY' : '*'}
|
||||
fcu_path = fcu.data_path
|
||||
|
||||
eval_array = array_default
|
||||
|
||||
for track in nla_tracks:
|
||||
if track.mute:
|
||||
continue
|
||||
if not len(track.strips):
|
||||
continue
|
||||
for strip in track.strips:
|
||||
if not strip.frame_start < frame < strip.frame_end:
|
||||
continue
|
||||
action = strip.action
|
||||
if action is None:
|
||||
continue
|
||||
blend_type = strip.blend_type
|
||||
|
||||
#get the influence value either from the attribute or the fcurve. function coming from bake
|
||||
influence = strip.influence
|
||||
if len(strip.fcurves):
|
||||
if not strip.fcurves[0].mute and len(strip.fcurves[0].keyframe_points):
|
||||
influence = strip.fcurves[0].evaluate(frame)
|
||||
|
||||
#evaluate the frame according to the strip settings
|
||||
frame_eval = frame
|
||||
#change the frame if the strip is on hold
|
||||
if frame < strip.frame_start:
|
||||
if strip.extrapolation == 'HOLD':
|
||||
frame_eval = strip.frame_start
|
||||
elif frame >= strip.frame_end:
|
||||
if strip.extrapolation == 'HOLD' or strip.extrapolation == 'HOLD_FORWARD':
|
||||
frame_eval = strip.frame_end
|
||||
|
||||
last_frame = strip.frame_start + (strip.frame_end - strip.frame_start) / strip.repeat
|
||||
|
||||
if strip.repeat > 1 and (frame) >= last_frame:
|
||||
action_range = (strip.action_frame_end * strip.scale - strip.action_frame_start * strip.scale)
|
||||
frame_eval = (((frame_eval - strip.frame_start) % (action_range)) + strip.frame_start)
|
||||
|
||||
if strip.use_reverse:
|
||||
frame_eval = last_frame - (frame_eval - strip.frame_start)
|
||||
offset = (strip.frame_start * 1/strip.scale - strip.action_frame_start) * strip.scale
|
||||
frame_eval = strip.frame_start * 1/strip.scale + (frame_eval - strip.frame_start) * 1/strip.scale - offset * 1/strip.scale
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_blend_type(fcurves, eval_array, fcu_path, frame_eval, influence, array_default, blend_type, blend_types)
|
||||
|
||||
#Adding an extra layer from the action outside and on top of the nla
|
||||
tweak_mode = anim_data.use_tweak_mode
|
||||
if tweak_mode:
|
||||
anim_data.use_tweak_mode = False
|
||||
action = anim_data.action
|
||||
if action:
|
||||
influence = anim_data.action_influence
|
||||
blend_type = anim_data.action_blend_type
|
||||
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_blend_type(fcurves, eval_array, fcu_path, frame, influence, array_default, blend_type, blend_types)
|
||||
anim_data.use_tweak_mode = tweak_mode
|
||||
|
||||
return eval_array
|
||||
|
||||
|
||||
def evaluate_blend_type(fcurves, eval_array, fcu_path, frame, influence,
|
||||
array_default, blend_type, blend_types):
|
||||
'''Calculate the value based on the blend type'''
|
||||
|
||||
fcu_array = evaluate_array(fcurves, fcu_path, frame, array_default)
|
||||
if fcu_array is None:# or len(fcu_array) != len(eval_array):
|
||||
return eval_array
|
||||
###EVALUATION###
|
||||
if blend_type =='COMBINE':
|
||||
if 'location' in fcu_path or 'rotation_euler' in fcu_path:
|
||||
blend_type = 'ADD'
|
||||
if blend_type =='REPLACE':
|
||||
eval_array = eval_array * (1 - influence) + fcu_array * influence
|
||||
elif blend_type =='COMBINE':
|
||||
eval_array = evaluate_combine(fcu_path, fcu_array, eval_array, array_default, influence)
|
||||
else:
|
||||
eval_array = eval('eval_array' + blend_types[blend_type] + 'fcu_array' + '*' + str(influence))
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_value(self, context):
|
||||
for obj in context.selected_objects:
|
||||
|
||||
anim_data = obj.animation_data
|
||||
if anim_data is None:
|
||||
return
|
||||
if anim_data.action is None:
|
||||
return
|
||||
|
||||
action = obj.animation_data.action
|
||||
fcu_paths = []
|
||||
transformations = ["rotation_quaternion","rotation_euler", "location", "scale"]
|
||||
if obj.mode == 'POSE':
|
||||
bonelist = context.selected_pose_bones if obj.als.onlyselected else obj.pose.bones
|
||||
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
for fcu in fcurves:
|
||||
if fcu in fcu_paths:
|
||||
continue
|
||||
if obj.mode == 'POSE':
|
||||
if anim_layers.selected_bones_filter(obj, fcu):
|
||||
continue
|
||||
if not filter_properties(obj, fcu):
|
||||
continue
|
||||
|
||||
for bone in bonelist:
|
||||
#find the fcurve of the bone
|
||||
if fcu.data_path.rfind(bone.name) != 12 or fcu.data_path[12 + len(bone.name)] != '"':
|
||||
continue
|
||||
path_split = fcu.data_path.split('"].')
|
||||
|
||||
if len(path_split) <= 1:
|
||||
continue
|
||||
else:
|
||||
transform = fcu.data_path.split('"].')[1]
|
||||
if transform not in transformations:
|
||||
continue
|
||||
|
||||
current_value = getattr(obj.pose.bones[bone.name], transform)
|
||||
else:
|
||||
transform = fcu.data_path
|
||||
current_value = getattr(obj, transform)
|
||||
|
||||
array_default = np.array(bake_ops.attr_default(obj, (fcu.data_path, fcu.array_index)))
|
||||
eval_array = evaluate_layers(context, obj, anim_data, fcu, array_default)
|
||||
if eval_array is None:
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_array(fcurves, fcu.data_path, context.scene.frame_current, array_default)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
add_diff(obj, fcurves, fcu.data_path, np.array(current_value), eval_array)
|
||||
|
||||
class MULTIKEY_OT_Multikey(bpy.types.Operator):
|
||||
"""Edit all selected keyframes"""
|
||||
bl_label = "Edit Selected Keyframes"
|
||||
bl_idname = "fcurves.multikey"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
# bl_description = ('Select keyframes, move your bone or objecet and press the operator. Does not work with Autokey')
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object and context.active_object.animation_data and bpy.context.scene.tool_settings.use_keyframe_insert_auto == False
|
||||
|
||||
def execute(self, context):
|
||||
evaluate_value(self, context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class MultikeyProperties(bpy.types.PropertyGroup):
|
||||
|
||||
#selectedbones: bpy.props.BoolProperty(name="Affect only selected bones", description="Affect only selected bones", default=True, options={'HIDDEN'})
|
||||
#handletype: bpy.props.BoolProperty(name="Keep handle types", description="Keep handle types", default=False, options={'HIDDEN'})
|
||||
scale: bpy.props.FloatProperty(name="Scale Values Factor", description="Scale percentage from the average value", default=1.0, soft_max = 10, soft_min = -10, step=0.1, precision = 3, update = scale_value)
|
||||
randomness: bpy.props.FloatProperty(name="Randomness", description="Random Threshold of keyframes", default=0.1, min=0.0, max = 1.0, update = random_value)
|
||||
# is_dragging: bpy.props.BoolProperty(default = False)
|
||||
|
||||
#filters
|
||||
filter_location: bpy.props.BoolVectorProperty(name="Location", description="Filter Location properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
filter_rotation: bpy.props.BoolVectorProperty(name="Rotation", description="Filter Rotation properties", default=(True, True, True, True), size = 4, options={'HIDDEN'})
|
||||
filter_scale: bpy.props.BoolVectorProperty(name="Scale", description="Filter Scale properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
|
||||
class FilterProperties(bpy.types.Operator):
|
||||
"""Filter Location Rotation and Scale Properties"""
|
||||
bl_idname = "fcurves.filter"
|
||||
bl_label = "Filter Properties W X Y Z"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.window_manager
|
||||
return wm.invoke_props_dialog(self, width = 200)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
row = layout.row()
|
||||
row.label(text = 'Location')
|
||||
row.prop(context.scene.multikey, 'filter_location', text = '')
|
||||
row = layout.row()
|
||||
row.label(text = 'Rotation')
|
||||
row.prop(context.scene.multikey, 'filter_rotation', text = '')
|
||||
row = layout.row()
|
||||
row.label(text = 'Scale')
|
||||
row.prop(context.scene.multikey, 'filter_scale', text = '')
|
||||
|
||||
def execute(self, context):
|
||||
return {'CANCELLED'}
|
||||
|
||||
classes = (MultikeyProperties, FilterProperties, MULTIKEY_OT_Multikey, ScaleValuesOp)
|
||||
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
bpy.types.Scene.multikey = bpy.props.PointerProperty(type = MultikeyProperties, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
del bpy.types.Scene.multikey
|
||||
@@ -0,0 +1,649 @@
|
||||
import bpy
|
||||
|
||||
from . import anim_layers
|
||||
from . import bake_ops
|
||||
|
||||
def subscriptions_remove(handler = True):
|
||||
#clear all handlers and subsciptions
|
||||
bpy.msgbus.clear_by_owner(bpy.context.scene)
|
||||
|
||||
global influence_keys, selected_bones
|
||||
|
||||
if 'influence_keys' in globals():
|
||||
del influence_keys
|
||||
if 'selected_bones' in globals():
|
||||
del selected_bones
|
||||
|
||||
if not handler:
|
||||
return
|
||||
if check_handler in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.remove(check_handler)
|
||||
if animlayers_frame in bpy.app.handlers.frame_change_post:
|
||||
bpy.app.handlers.frame_change_post.remove(animlayers_frame)
|
||||
|
||||
def subscriptions_add(scene, handler = True):
|
||||
bpy.msgbus.clear_by_owner(scene)
|
||||
|
||||
subscribe_to_frame_end(scene)
|
||||
subscribe_to_track_name(scene)
|
||||
subscribe_to_action_name(scene)
|
||||
subscribe_to_strip_settings(scene)
|
||||
subscribe_to_influence(scene)
|
||||
|
||||
if not handler:
|
||||
return
|
||||
|
||||
if check_handler not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(check_handler)
|
||||
if animlayers_frame not in bpy.app.handlers.frame_change_post:
|
||||
bpy.app.handlers.frame_change_post.append(animlayers_frame)
|
||||
|
||||
def animlayers_frame(self, context):
|
||||
scene = bpy.context.scene
|
||||
current = scene.frame_current_final
|
||||
|
||||
#Make sure the animation is playing and not just running a motion path
|
||||
if not bpy.context.screen.is_animation_playing:
|
||||
return
|
||||
|
||||
#Checking if preview range was turned on or off, when using hotkey P it doesn't recognize
|
||||
#only during the frame handler
|
||||
if scene.get('framerange_preview') != scene.use_preview_range:
|
||||
scene['framerange_preview'] = scene.use_preview_range
|
||||
frameend_update_callback()
|
||||
return
|
||||
|
||||
frame_start, frame_end = bake_ops.frame_start_end(scene)
|
||||
reset_subscription = False
|
||||
if 'outofrange' not in globals():
|
||||
global outofrange
|
||||
outofrange = False if 0 <= current <= frame_end else True
|
||||
# print('out of range ', outofrange )
|
||||
|
||||
if 0 <= current <= frame_end:
|
||||
if outofrange:
|
||||
frameend_update_callback()
|
||||
outofrange = False
|
||||
return
|
||||
outofrange = True
|
||||
# if current <= frame_end:
|
||||
# return
|
||||
#iterate only through objects with anim layers turned on
|
||||
objects = [obj.object for obj in scene.AL_objects]
|
||||
for obj in objects:
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return
|
||||
for i, track in enumerate(nla_tracks):
|
||||
if len(track.strips) != 1:
|
||||
continue
|
||||
|
||||
#checks if the layer has a custom frame range
|
||||
layer = obj.Anim_Layers[i]
|
||||
if layer.frame_range:
|
||||
continue
|
||||
if not reset_subscription:
|
||||
subscriptions_remove(handler = False)
|
||||
reset_subscription = True
|
||||
strip = track.strips[0]
|
||||
if current < 0:
|
||||
# anim_layers.strip_action_recalc(layer, track.strips[0])
|
||||
strip.frame_start_ui = current
|
||||
anim_layers.update_action_frame_range(current, frame_end, layer, strip)
|
||||
# track.strips[0].action_frame_start = current * 1/layer.speed - layer.offset * 1/layer.speed
|
||||
strip.frame_end_ui = frame_end
|
||||
|
||||
elif current > frame_end:
|
||||
if strip.frame_start < 0:
|
||||
strip.frame_start_ui = 0
|
||||
anim_layers.update_action_frame_range(0, frame_end, layer, strip)
|
||||
# print('animlayers_frame ', current)
|
||||
strip.frame_end_ui = current + 10
|
||||
|
||||
if reset_subscription:
|
||||
subscriptions_add(scene, handler = False)
|
||||
|
||||
|
||||
def check_handler(self, context):
|
||||
'''A main function that performs a series of checks using a handler'''
|
||||
scene = bpy.context.scene
|
||||
#if there are no objects included in animation layers then return
|
||||
if not len(scene.AL_objects):
|
||||
return
|
||||
|
||||
obj = bpy.context.object
|
||||
|
||||
#if the object was removed from the scene, then remove it from anim layers object list
|
||||
if obj is None:
|
||||
i = 0
|
||||
while i < len(scene.AL_objects):
|
||||
if scene.AL_objects[i].object not in scene.objects.values():
|
||||
scene.AL_objects.remove(i)
|
||||
else:
|
||||
i += 1
|
||||
return
|
||||
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
if not anim_data.use_nla:
|
||||
obj.als.turn_on = False
|
||||
return
|
||||
if not len(obj.Anim_Layers):
|
||||
return
|
||||
if not hasattr(anim_data, 'nla_tracks') or not obj.als.turn_on: #obj.select_get() == False or
|
||||
return
|
||||
|
||||
anim_layers.add_obj_to_animlayers(obj, [item.object for item in scene.AL_objects])
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
layer = obj.Anim_Layers[obj.als.layer_index]
|
||||
active_action_update(obj, anim_data, nla_tracks)
|
||||
#check if a keyframe was removed
|
||||
if bpy.context.active_operator is not None:
|
||||
if bpy.context.active_operator.name in ['Transform', 'Delete Keyframes'] and obj.als.edit_all_keyframes:
|
||||
anim_layers.edit_all_keyframes()
|
||||
|
||||
if bpy.context.active_operator.name == 'Enter Tweak Mode':
|
||||
if not bpy.context.active_operator.properties['use_upper_stack_evaluation']:
|
||||
obj.als.upper_stack = False
|
||||
|
||||
if bpy.context.active_operator.name == 'Move Channels':
|
||||
anim_layers.visible_layers(obj, nla_tracks)
|
||||
|
||||
|
||||
# check if track and layers are synchronized
|
||||
if track_layer_synchronization(obj, nla_tracks):
|
||||
return
|
||||
|
||||
anim_layers.add_obj_to_animlayers(obj, [item.object for item in scene.AL_objects])
|
||||
|
||||
track = nla_tracks[obj.als.layer_index]
|
||||
always_sync_range(track, layer)
|
||||
# sync_strip_range(track, layer)
|
||||
|
||||
if anim_data.use_tweak_mode and layer.lock:
|
||||
layer['lock'] = False
|
||||
elif not anim_data.use_tweak_mode and not layer.lock:
|
||||
layer['lock'] = True
|
||||
|
||||
influence_sync(obj, nla_tracks)
|
||||
|
||||
# continue if locked
|
||||
if layer.lock:
|
||||
return
|
||||
|
||||
if obj.als.view_all_keyframes:
|
||||
anim_layers.hide_view_all_keyframes(obj, anim_data)
|
||||
check_selected_bones(obj)
|
||||
|
||||
influence_check(nla_tracks[obj.als.layer_index])
|
||||
|
||||
def track_layer_synchronization(obj, nla_tracks):
|
||||
'''check if track and layers are synchronized'''
|
||||
|
||||
if len(nla_tracks) == len(obj.Anim_Layers):
|
||||
return False
|
||||
|
||||
new_layers_names = set(track.name for track in nla_tracks).difference(set(layer.name for layer in obj.Anim_Layers))
|
||||
anim_layers.visible_layers(obj, nla_tracks)
|
||||
if obj.als.layer_index > len(obj.Anim_Layers)-1:
|
||||
obj.als.layer_index = len(obj.Anim_Layers)-1
|
||||
|
||||
#update new layer with strip settings
|
||||
frame_start, frame_end = bake_ops.frame_start_end(bpy.context.scene)
|
||||
|
||||
for layer_name in new_layers_names:
|
||||
if len(nla_tracks[layer_name].strips) != 1:
|
||||
continue
|
||||
strip = get_strip_in_meta(nla_tracks[layer_name].strips[0])
|
||||
layer = obj.Anim_Layers[layer_name]
|
||||
if (strip.frame_start, strip.frame_end) != (frame_start, frame_end):
|
||||
layer['frame_range'] = True
|
||||
update_strip_layer_settings(strip, layer)
|
||||
layer['action'] = strip.action
|
||||
return True
|
||||
|
||||
def active_action_update(obj, anim_data, nla_tracks):
|
||||
'''updating the active action into the selected layer'''
|
||||
if obj.Anim_Layers[obj.als.layer_index].lock:
|
||||
if anim_data.action != None:
|
||||
subscriptions_remove()
|
||||
anim_data.use_tweak_mode = False
|
||||
anim_data.action = None
|
||||
subscriptions_add(bpy.context.scene)
|
||||
return
|
||||
if anim_data.action == nla_tracks[obj.als.layer_index].strips[0].action:
|
||||
return
|
||||
if not len(nla_tracks[obj.als.layer_index].strips):
|
||||
return
|
||||
if not anim_data.action or anim_data.is_property_readonly('action'):
|
||||
return
|
||||
subscriptions_remove()
|
||||
action = anim_data.action
|
||||
anim_data.action = None
|
||||
obj.Anim_Layers[obj.als.layer_index].action = action
|
||||
subscriptions_add(bpy.context.scene)
|
||||
|
||||
def get_strip_in_meta(strip):
|
||||
'''check if it's meta strip then access the last strip inside meta hierarchy'''
|
||||
while len(strip.strips):
|
||||
strip = strip.strips[0]
|
||||
return strip
|
||||
|
||||
def sync_strip_range():
|
||||
|
||||
scene = bpy.context.scene
|
||||
frame_start, frame_end = bake_ops.frame_start_end(scene)
|
||||
|
||||
if scene.frame_current_final > frame_end:
|
||||
frame_end = scene.frame_current_final + 10
|
||||
|
||||
frame_start = scene.frame_current_final if scene.frame_current_final < 0 else 0.0
|
||||
|
||||
objects = [obj.object for obj in scene.AL_objects]
|
||||
for obj in objects:
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
continue
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
continue
|
||||
for i, track in enumerate(nla_tracks):
|
||||
if len(track.strips) != 1:
|
||||
continue
|
||||
if obj.Anim_Layers[i]['frame_range']:
|
||||
continue
|
||||
strip = track.strips[0]
|
||||
strip_frame_start = strip.frame_start
|
||||
strip_frame_end = strip.frame_end
|
||||
|
||||
if (strip_frame_start, round(strip_frame_end, 2)) != (frame_start, float(frame_end)):
|
||||
obj.Anim_Layers[i]['frame_range'] = True
|
||||
|
||||
def always_sync_range(track, layer):
|
||||
'''sync frame range when always sync turned on'''
|
||||
if not len(track.strips):
|
||||
return
|
||||
if not layer.frame_range:
|
||||
if track.strips[0].use_sync_length:
|
||||
track.strips[0].use_sync_length = False
|
||||
return
|
||||
if not track.strips[0].use_sync_length:
|
||||
if tuple(layer.action_range) != (0.0, 0.0): #reset action range when turned off
|
||||
layer.action_range = (0.0, 0.0)
|
||||
return
|
||||
strip = track.strips[0]
|
||||
if tuple(layer.action_range) == tuple((strip.action.frame_range[0], strip.action.frame_range[1])):
|
||||
return
|
||||
anim_layers.sync_frame_range(bpy.context)
|
||||
layer.action_range = strip.action.frame_range
|
||||
|
||||
def influence_sync(obj, nla_tracks):
|
||||
|
||||
#Tracks that dont have keyframes are locked
|
||||
for i, track in enumerate(nla_tracks):
|
||||
|
||||
if obj.Anim_Layers[i].lock:
|
||||
continue
|
||||
if not len(track.strips):
|
||||
continue
|
||||
if not len(track.strips[0].fcurves):
|
||||
continue
|
||||
if not len(track.strips[0].fcurves[0].keyframe_points):
|
||||
#apply the influence property to the temp property when keyframes are removed (but its still locked)
|
||||
if not track.strips[0].fcurves[0].lock:
|
||||
obj.Anim_Layers[i].influence = track.strips[0].influence
|
||||
track.strips[0].fcurves[0].lock = True
|
||||
|
||||
if obj.animation_data is None:
|
||||
return
|
||||
action = obj.animation_data.action
|
||||
if action is None:
|
||||
return
|
||||
#if a keyframe was found in the temporary property then add it to the
|
||||
data_path = 'Anim_Layers[' + str(obj.als.layer_index) + '].influence'
|
||||
fcurves = anim_layers.get_fcurves_channelbag(obj, action)
|
||||
fcu_influence = fcurves.find(data_path)
|
||||
if fcu_influence is None:
|
||||
return
|
||||
if not len(fcu_influence.keyframe_points):
|
||||
return
|
||||
#remove the temporary influence
|
||||
fcurves.remove(fcu_influence)
|
||||
#if the action was created just for the influence because of empty object data type then remove the action
|
||||
if action.name == obj.name + 'Action' and not len(obj.animation_data.nla_tracks) and not len(fcurves):
|
||||
bpy.data.actions.remove(action)
|
||||
if obj.Anim_Layers[obj.als.layer_index].influence_mute:
|
||||
return
|
||||
strip = nla_tracks[obj.als.layer_index].strips[0]
|
||||
strip.fcurves[0].lock = False
|
||||
strip.keyframe_insert('influence')
|
||||
strip.fcurves[0].update()
|
||||
|
||||
|
||||
def influence_check(selected_track):
|
||||
'''update influence when a keyframe was added without autokey'''
|
||||
#skip the next steps if a strip is missing or tracks were removed from the nla tracks
|
||||
if len(selected_track.strips) != 1:# or obj.als.layer_index > len(nla_tracks)-2:
|
||||
return
|
||||
if not len(selected_track.strips[0].fcurves):
|
||||
return
|
||||
|
||||
global influence_keys
|
||||
|
||||
if selected_track.strips[0].fcurves[0].mute or not len(selected_track.strips[0].fcurves[0].keyframe_points) or bpy.context.scene.tool_settings.use_keyframe_insert_auto:
|
||||
if 'influence_keys' in globals():
|
||||
del influence_keys
|
||||
return #when the fcurve doesnt have keyframes, or when autokey is turned on, then return
|
||||
|
||||
#update if the influence keyframes are changed. influence_keys are first added in influence_update_callback
|
||||
if 'influence_keys' not in globals():
|
||||
return
|
||||
if influence_keys != [tuple(key.co) for key in selected_track.strips[0].fcurves[0].keyframe_points]:
|
||||
selected_track.strips[0].fcurves[0].update()
|
||||
del influence_keys
|
||||
|
||||
|
||||
def check_selected_bones(obj):
|
||||
'''running in the handler and checking if the selected bones were changed during view multiply layer keyframes'''
|
||||
if not obj.als.only_selected_bones:
|
||||
return
|
||||
global selected_bones
|
||||
try:
|
||||
selected_bones
|
||||
except NameError:
|
||||
selected_bones = bpy.context.selected_pose_bones
|
||||
return
|
||||
else:
|
||||
if selected_bones != bpy.context.selected_pose_bones:
|
||||
selected_bones = bpy.context.selected_pose_bones
|
||||
obj.als.view_all_keyframes = True
|
||||
|
||||
########################### MSGBUS SUBSCRIPTIONS #############################
|
||||
|
||||
#Callback function for Scene frame end
|
||||
def frameend_update_callback():
|
||||
'''End the strips at the end of the scene or scene preview'''
|
||||
scene = bpy.context.scene
|
||||
if not scene.AL_objects:
|
||||
return
|
||||
frame_start, frame_end = bake_ops.frame_start_end(scene)
|
||||
if scene.frame_current_final > frame_end:
|
||||
frame_end = scene.frame_current_final + 10
|
||||
frame_start = scene.frame_current_final if scene.frame_current_final < 0 else 0
|
||||
|
||||
# subscriptions_remove(handler = False)
|
||||
for AL_item in scene.AL_objects:
|
||||
obj = AL_item.object
|
||||
if obj is None or obj not in scene.objects.values():
|
||||
continue
|
||||
#anim_data = anim_data_type(obj)
|
||||
anim_datas = anim_layers.anim_datas_append(obj)
|
||||
|
||||
for anim_data in anim_datas:
|
||||
if anim_data is None:
|
||||
continue
|
||||
if len(anim_data.nla_tracks) != len(obj.Anim_Layers):
|
||||
continue
|
||||
for layer, track in zip(obj.Anim_Layers, anim_data.nla_tracks):
|
||||
if layer.frame_range:
|
||||
continue
|
||||
if len(track.strips) != 1:
|
||||
continue
|
||||
strip = track.strips[0]
|
||||
|
||||
strip.frame_start = frame_start
|
||||
anim_layers.update_action_frame_range(frame_start, frame_end, layer, strip)
|
||||
strip.scale = layer.speed
|
||||
strip.frame_end = frame_end
|
||||
|
||||
# subscriptions_add(scene, handler = False)
|
||||
|
||||
#Subscribe to the scene frame_end
|
||||
def subscribe_to_frame_end(scene):
|
||||
'''subscribe_to_frame_end and frame preview end'''
|
||||
subscribe_end = scene.path_resolve("frame_end", False)
|
||||
subscribe_preview_end = scene.path_resolve("frame_preview_end", False)
|
||||
subscribe_use_preview = scene.path_resolve("use_preview_range", False)
|
||||
|
||||
for subscribe in [subscribe_end, subscribe_preview_end, subscribe_use_preview]:
|
||||
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe,
|
||||
owner=scene,
|
||||
args=(),
|
||||
notify=frameend_update_callback,)
|
||||
|
||||
# bpy.msgbus.publish_rna(key=subscribe)
|
||||
|
||||
# def action_framestart_update_callback(*args):
|
||||
# ''' update the strip start with the action start'''
|
||||
|
||||
|
||||
def track_update_callback():
|
||||
'''update layers with the tracks name'''
|
||||
# global initial_call
|
||||
# if initial_call:
|
||||
# return
|
||||
|
||||
if not bpy.context.selected_objects:
|
||||
return
|
||||
obj = bpy.context.object
|
||||
if obj is None:
|
||||
return
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
current_anim_data = anim_layers.anim_data_type(obj)
|
||||
anim_datas = anim_layers.anim_datas_append(obj)
|
||||
for anim_data in anim_datas:
|
||||
if anim_data is None:
|
||||
return
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):# or len(nla_tracks[:-1]) != len(obj.Anim_Layers):
|
||||
return
|
||||
override_tracks = anim_layers.check_override_tracks(obj, anim_data)
|
||||
for i, track in enumerate(nla_tracks):
|
||||
if anim_data != current_anim_data:
|
||||
continue
|
||||
#make sure there are no duplicated names
|
||||
if track.name != obj.Anim_Layers[i].name:
|
||||
#If its an override track, then make sure the reference object name is also synchronized
|
||||
if obj.Anim_Layers[i].name in override_tracks:
|
||||
override_tracks[obj.Anim_Layers[i].name].name = track.name
|
||||
obj.Anim_Layers[i].name = track.name
|
||||
if len(track.strips) == 1:
|
||||
track.strips[0].name = track.name
|
||||
|
||||
def subscribe_to_track_name(scene):
|
||||
'''Subscribe to the name of track'''
|
||||
|
||||
#subscribe_track = nla_track.path_resolve("name", False)
|
||||
subscribe_track = (bpy.types.NlaTrack, 'name')
|
||||
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe_track,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(),
|
||||
# Callback function for property update
|
||||
notify=track_update_callback,)
|
||||
|
||||
# bpy.msgbus.publish_rna(key=subscribe_track)
|
||||
|
||||
def action_name_callback():
|
||||
'''update layers with the tracks name'''
|
||||
# global initial_call
|
||||
# if initial_call:
|
||||
# return
|
||||
|
||||
obj = bpy.context.object
|
||||
if obj is None:
|
||||
return
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
#anim_datas = anim_layers.anim_datas_append(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return
|
||||
layer = obj.Anim_Layers[obj.als.layer_index]
|
||||
if not len(nla_tracks[obj.als.layer_index].strips):
|
||||
return
|
||||
action = nla_tracks[obj.als.layer_index].strips[0].action
|
||||
if action is None:
|
||||
return
|
||||
if not obj.als.auto_rename or layer.name == action.name:
|
||||
return
|
||||
layer.name = action.name
|
||||
|
||||
def subscribe_to_action_name(scene):
|
||||
'''Subscribe to the name of track'''
|
||||
|
||||
#subscribe_track = nla_track.path_resolve("name", False)
|
||||
subscribe_action = (bpy.types.Action, 'name')
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe_action,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(),
|
||||
# Callback function for property update
|
||||
notify=action_name_callback,)
|
||||
|
||||
# bpy.msgbus.publish_rna(key=subscribe_action)
|
||||
|
||||
def influence_update_callback(*args):
|
||||
'''update influence'''
|
||||
# global initial_call
|
||||
|
||||
if not bpy.context.selected_objects:
|
||||
return
|
||||
obj = bpy.context.object
|
||||
#checking if the object has nla tracks, when I used undo it was still calling the property on an object with no nla tracks
|
||||
if obj is None:
|
||||
return
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
if not len(anim_data.nla_tracks):
|
||||
return
|
||||
|
||||
track = anim_data.nla_tracks[obj.als.layer_index]
|
||||
if len(track.strips) != 1:
|
||||
return
|
||||
|
||||
if track.strips[0].fcurves[0].mute or track.strips[0].fcurves[0].lock:
|
||||
return
|
||||
|
||||
# print('influence_update_callback')
|
||||
#if the influence property and fcurve value are not the same then store the keyframes to check in the handler for a change
|
||||
if track.strips[0].influence == track.strips[0].fcurves[0].evaluate(bpy.context.scene.frame_current):
|
||||
return
|
||||
|
||||
global influence_keys
|
||||
influence_keys = [tuple(key.co) for key in track.strips[0].fcurves[0].keyframe_points]
|
||||
|
||||
if bpy.context.scene.tool_settings.use_keyframe_insert_auto and len(track.strips[0].fcurves[0].keyframe_points):
|
||||
track.strips[0].keyframe_insert('influence')
|
||||
track.strips[0].fcurves[0].update()
|
||||
return
|
||||
|
||||
|
||||
def subscribe_to_influence(scene):
|
||||
'''Subscribe to the influence of the track'''
|
||||
subscribe_influence = (bpy.types.NlaStrip, 'influence')
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe_influence,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(scene,),
|
||||
# Callback function for property update
|
||||
notify=influence_update_callback,)
|
||||
|
||||
|
||||
def subscribe_to_strip_settings(scene):
|
||||
'''Subscribe to the strip settings of the track'''
|
||||
|
||||
frame_start = (bpy.types.NlaStrip, 'frame_start')
|
||||
frame_end = (bpy.types.NlaStrip, 'frame_end')
|
||||
action_frame_start = (bpy.types.NlaStrip, 'action_frame_start')
|
||||
action_frame_end = (bpy.types.NlaStrip, 'action_frame_end')
|
||||
scale = (bpy.types.NlaStrip, 'scale')
|
||||
repeat = (bpy.types.NlaStrip, 'repeat')
|
||||
|
||||
attributes = [frame_start, frame_end, action_frame_start, action_frame_end, scale, repeat, frame_start, frame_end]
|
||||
|
||||
if bpy.app.version > (3, 2, 0):
|
||||
#this properties exist only after Blender 3.2
|
||||
frame_start_ui = (bpy.types.NlaStrip, 'frame_start_ui')
|
||||
frame_end_ui = (bpy.types.NlaStrip, 'frame_end_ui')
|
||||
attributes += [frame_start_ui, frame_end_ui]
|
||||
|
||||
for key in attributes:
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=key,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(),
|
||||
# Callback function for property update
|
||||
notify=strip_settings_callback,)
|
||||
|
||||
|
||||
def update_strip_layer_settings(strip, layer):
|
||||
layer['speed'] = strip.scale
|
||||
|
||||
# start_offset = strip.action.frame_range[0] - strip.frame_start
|
||||
# offset = (strip.action_frame_start - strip.frame_start - start_offset) * strip.scale + start_offset
|
||||
# offset = (strip.action_frame_start - strip.frame_start) * strip.scale
|
||||
if strip.repeat <= 1:
|
||||
offset = (strip.frame_start * 1/strip.scale - strip.action_frame_start) * strip.scale
|
||||
else:
|
||||
#During repeat the offset is based on the distance from the action first keyframe
|
||||
offset = strip.frame_start - strip.action.frame_range[0]
|
||||
|
||||
layer['offset'] = round(offset, 3)
|
||||
|
||||
#If custom frame range is turned off return to not lose frame range values
|
||||
if not layer.frame_range:
|
||||
return
|
||||
layer['frame_end'] = strip.frame_end
|
||||
layer['frame_start'] = strip.frame_start
|
||||
layer['repeat'] = strip.repeat
|
||||
|
||||
|
||||
def strip_settings_callback():
|
||||
'''subscribe_to_strip_settings callback'''
|
||||
|
||||
if not bpy.context.selected_objects:
|
||||
return
|
||||
obj = bpy.context.object
|
||||
if obj is None:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
if not len(anim_data.nla_tracks):
|
||||
return
|
||||
if not len(obj.Anim_Layers):
|
||||
return
|
||||
strip = anim_data.nla_tracks[obj.als.layer_index].strips[0]
|
||||
sync_strip_range()
|
||||
if not len(anim_data.nla_tracks[obj.als.layer_index].strips):
|
||||
return
|
||||
strip = anim_data.nla_tracks[obj.als.layer_index].strips[0]
|
||||
layer = obj.Anim_Layers[obj.als.layer_index]
|
||||
|
||||
update_strip_layer_settings(strip, layer)
|
||||
anim_layers.redraw_areas([ 'VIEW_3D'])
|
||||
BIN
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,410 @@
|
||||
# if "bpy" in locals():
|
||||
# import importlib
|
||||
# if "multikey" in locals():
|
||||
# importlib.reload()
|
||||
|
||||
import bpy
|
||||
import random
|
||||
import numpy as np
|
||||
from mathutils import Quaternion
|
||||
from . import bake_ops
|
||||
from . import anim_layers
|
||||
|
||||
def store_handles(key):
|
||||
#storing the distance between the handles bezier to the key value
|
||||
handle_r = key.handle_right[1] - key.co[1]
|
||||
handle_l = key.handle_left[1] - key.co[1]
|
||||
|
||||
return handle_r, handle_l
|
||||
|
||||
def apply_handles(key, handle_r, handle_l):
|
||||
key.handle_right[1] = key.co[1] + handle_r
|
||||
key.handle_left[1] = key.co[1] + handle_l
|
||||
|
||||
def filter_properties(obj, fcu):
|
||||
'Filter the W X Y Z attributes of the transform properties'
|
||||
|
||||
transformations = ["rotation_quaternion","rotation_euler", "location", "scale"]
|
||||
#check if the fcurve data path ends with any of the transformations
|
||||
if not any(fcu.data_path.endswith(transform) for transform in transformations):
|
||||
return True
|
||||
transform = fcu.data_path.split('"].')[1] if obj.mode == 'POSE' else fcu.data_path
|
||||
index = fcu.array_index
|
||||
if 'rotation' in transform:
|
||||
if transform == 'rotation_euler':
|
||||
index -= 1
|
||||
transform = 'rotation'
|
||||
transform = 'filter_' + transform
|
||||
#in case of channels like bbone_scalein that are no included then return
|
||||
if not hasattr(bpy.context.scene.multikey, transform):
|
||||
return True
|
||||
attr = getattr(bpy.context.scene.multikey, transform)
|
||||
return True if attr[index] else False
|
||||
|
||||
def add_value(key, value):
|
||||
if key.select_control_point:
|
||||
#store handle values in relative to the keyframe value
|
||||
handle_r, handle_l = store_handles(key)
|
||||
|
||||
key.co[1] += value
|
||||
apply_handles(key, handle_r, handle_l)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
def add_diff(obj, fcurves, path, current_value, eval_array):
|
||||
array_value = current_value - eval_array
|
||||
if not any(array_value):
|
||||
return
|
||||
for i, value in enumerate(array_value):
|
||||
fcu = fcurves.find(path, index = i)
|
||||
if fcu is None or not filter_properties(obj, fcu):
|
||||
continue
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value)
|
||||
fcu.update()
|
||||
|
||||
class ScaleValuesOp(bpy.types.Operator):
|
||||
"""Modal operator used while scale value is running before release"""
|
||||
bl_idname = "anim.multikey_scale_value"
|
||||
bl_label = "Scale Values"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
#reset the values for dragging
|
||||
self.stop = False
|
||||
scene = context.scene
|
||||
scene.multikey['is_dragging'] = True
|
||||
self.avg_value = dict()
|
||||
#dictionary of the keyframes and their original INITIAL values
|
||||
self.keyframes_values = dict()
|
||||
self.keyframes_handle_right = dict()
|
||||
self.keyframes_handle_left = dict()
|
||||
|
||||
#the average value for each fcurve
|
||||
self.keyframes_avg_value = dict()
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
action = obj.animation_data.action
|
||||
for fcu in action.fcurves:
|
||||
if obj.mode == 'POSE':
|
||||
if bake_ops.selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
if not filter_properties(obj, fcu):
|
||||
continue
|
||||
|
||||
#avg and value list per fcurve
|
||||
avg_value = []
|
||||
value_list = []
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
value_list.append(key.co[1])
|
||||
self.keyframes_values.update({key : key.co[1]})
|
||||
self.keyframes_handle_right.update({key : key.handle_right[1]})
|
||||
self.keyframes_handle_left.update({key : key.handle_left[1]})
|
||||
|
||||
if len(value_list)>1:
|
||||
#the average value with the scale property added to it
|
||||
avg_value = sum(value_list) / len(value_list)
|
||||
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
self.keyframes_avg_value.update({key : avg_value})
|
||||
|
||||
if not self.keyframes_avg_value:
|
||||
return('CANCELLED')
|
||||
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
def modal(self, context, event):
|
||||
|
||||
scene = context.scene
|
||||
scale = scene.multikey.scale
|
||||
|
||||
#Quit the modal operator when the slider is released
|
||||
if self.stop:
|
||||
scene.multikey['is_dragging'] = False
|
||||
scene.multikey['scale'] = 1
|
||||
anim_layers.redraw_areas(['VIEW_3D'])
|
||||
#modal is being cancelled because of undo issue with the modal running through the property
|
||||
return {'FINISHED'}
|
||||
|
||||
if event.value == 'RELEASE': # Stop the modal on next frame. Don't block the event since we want to exit the field dragging
|
||||
self.stop = True
|
||||
|
||||
for key, key_value in self.keyframes_values.items():
|
||||
if not key.select_control_point:
|
||||
continue
|
||||
if key not in self.keyframes_avg_value:
|
||||
continue
|
||||
avg_value = self.keyframes_avg_value[key]
|
||||
handle_right_value = self.keyframes_handle_right[key]
|
||||
handle_left_value = self.keyframes_handle_left[key]
|
||||
|
||||
#add the value of the distance from the average * scale factor
|
||||
key.co[1] = avg_value + ((key_value - avg_value)*scale)
|
||||
key.handle_right[1] = avg_value + ((handle_right_value - avg_value)*scale)
|
||||
key.handle_left[1] = avg_value + ((handle_left_value - avg_value)*scale)
|
||||
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
def scale_value(self, context):
|
||||
|
||||
scene = context.scene
|
||||
if scene.multikey.is_dragging:
|
||||
return
|
||||
obj = context.object
|
||||
|
||||
if obj is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
action = obj.animation_data.action
|
||||
|
||||
if action is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
if context.mode == 'POSE' and not context.selected_pose_bones:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
bpy.ops.anim.multikey_scale_value('INVOKE_DEFAULT')
|
||||
|
||||
def random_value(self, context):
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
action = obj.animation_data.action
|
||||
for fcu in action.fcurves:
|
||||
if obj.mode == 'POSE':
|
||||
if bake_ops.selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
if not filter_properties(obj, fcu):
|
||||
continue
|
||||
value_list = []
|
||||
threshold = bpy.context.scene.multikey.randomness
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point == True:
|
||||
value_list.append(key.co[1])
|
||||
|
||||
if len(value_list) > 0:
|
||||
value = max(value_list)- min(value_list)
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value * random.uniform(-threshold, threshold))
|
||||
fcu.update()
|
||||
|
||||
self['randomness'] = 0.1
|
||||
|
||||
def evaluate_array(action, fcu_path, frame, array_len):
|
||||
'''Create an array from all the indexes'''
|
||||
|
||||
fcu_array = []
|
||||
for i in range(array_len):
|
||||
fcu = action.fcurves.find(fcu_path, index = i)
|
||||
if fcu is None:
|
||||
continue
|
||||
fcu_array.append(fcu.evaluate(frame))
|
||||
if not len(fcu_array):
|
||||
return None
|
||||
return np.array(fcu_array)
|
||||
|
||||
def evaluate_layers(context, obj, anim_data, fcu, array_len):
|
||||
'''Calculate the evaluation of all the layers when using the nla'''
|
||||
|
||||
if not hasattr(anim_data, 'nla_tracks') or not anim_data.use_nla:
|
||||
return None
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return None
|
||||
frame = context.scene.frame_current
|
||||
#blend_types = {'ADD' : '+', 'SUBTRACT' : '-', 'MULTIPLY' : '*'}
|
||||
fcu_path = fcu.data_path
|
||||
|
||||
#array_default = np.array([bake_ops.attr_default(obj, (fcu_path, i)) for i in range(4) if anim_data.action.fcurves.find(fcu_path, index = i) is not None])
|
||||
array_default = np.array(bake_ops.attr_default(obj, (fcu_path, fcu.array_index)))
|
||||
eval_array = array_default
|
||||
for track in nla_tracks:
|
||||
if track.mute:
|
||||
continue
|
||||
if not len(track.strips):
|
||||
continue
|
||||
for strip in track.strips:
|
||||
if not strip.frame_start < frame < strip.frame_end:
|
||||
continue
|
||||
action = strip.action
|
||||
if action is None:
|
||||
continue
|
||||
blend_type = strip.blend_type
|
||||
|
||||
#get the influence value either from the attribute or the fcurve. function coming from bake
|
||||
influence = strip.influence
|
||||
if len(strip.fcurves):
|
||||
if not strip.fcurves[0].mute and len(strip.fcurves[0].keyframe_points):
|
||||
influence = strip.fcurves[0].evaluate(frame)
|
||||
|
||||
#evaluate the frame according to the strip settings
|
||||
frame_eval = frame
|
||||
#change the frame if the strip is on hold
|
||||
if frame < strip.frame_start:
|
||||
if strip.extrapolation == 'HOLD':
|
||||
frame_eval = strip.frame_start
|
||||
elif frame >= strip.frame_end:
|
||||
if strip.extrapolation == 'HOLD' or strip.extrapolation == 'HOLD_FORWARD':
|
||||
frame_eval = strip.frame_end
|
||||
|
||||
last_frame = strip.frame_start + (strip.frame_end - strip.frame_start) / strip.repeat
|
||||
|
||||
if strip.repeat > 1 and (frame) >= last_frame:
|
||||
action_range = (strip.action_frame_end * strip.scale - strip.action_frame_start * strip.scale)
|
||||
frame_eval = (((frame_eval - strip.frame_start) % (action_range)) + strip.frame_start)
|
||||
|
||||
if strip.use_reverse:
|
||||
frame_eval = last_frame - (frame_eval - strip.frame_start)
|
||||
offset = (strip.frame_start * 1/strip.scale - strip.action_frame_start) * strip.scale
|
||||
frame_eval = strip.frame_start * 1/strip.scale + (frame_eval - strip.frame_start) * 1/strip.scale - offset * 1/strip.scale
|
||||
|
||||
fcu_array = evaluate_array(action, fcu_path, frame_eval, array_len)
|
||||
if fcu_array is None:
|
||||
continue
|
||||
|
||||
###EVALUATION###
|
||||
eval_array = evaluation(blend_type, fcu_path, fcu_array, eval_array, array_default, influence)
|
||||
|
||||
#If there is an action on top of the nla tracks (not using anim layers) add it to the evaluation
|
||||
if anim_data.action is not None and not anim_data.use_tweak_mode:
|
||||
fcu_array = evaluate_array(anim_data.action, fcu_path, frame, array_len)
|
||||
if fcu_array is not None:
|
||||
eval_array = evaluation(anim_data.action_blend_type, fcu_path, fcu_array, eval_array, array_default, anim_data.action_influence)
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluation(blend_type, fcu_path, fcu_array, eval_array, array_default, influence):
|
||||
|
||||
blend_types = {'ADD' : '+', 'SUBTRACT' : '-', 'MULTIPLY' : '*'}
|
||||
# fcu_array = evaluate_array(action, fcu_path, frame_eval, array_len)
|
||||
# if fcu_array is None:
|
||||
# continue
|
||||
###EVALUATION###
|
||||
if blend_type =='COMBINE':
|
||||
if 'location' in fcu_path or 'rotation_euler' in fcu_path:
|
||||
blend_type = 'ADD'
|
||||
|
||||
if blend_type =='REPLACE':
|
||||
eval_array = eval_array * (1 - influence) + fcu_array * influence
|
||||
elif blend_type =='COMBINE':
|
||||
eval_array = bake_ops.evaluate_combine(fcu_path, fcu_array, eval_array, array_default, influence)
|
||||
else:
|
||||
eval_array = eval('eval_array' + blend_types[blend_type] + 'fcu_array' + '*' + str(influence))
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_value(self, context):
|
||||
for obj in context.selected_objects:
|
||||
|
||||
anim_data = obj.animation_data
|
||||
if anim_data is None:
|
||||
return
|
||||
if anim_data.action is None:
|
||||
return
|
||||
|
||||
action = obj.animation_data.action
|
||||
fcu_paths = []
|
||||
transformations = ["rotation_quaternion","rotation_euler", "location", "scale"]
|
||||
if obj.mode == 'POSE':
|
||||
bonelist = context.selected_pose_bones if obj.als.onlyselected else obj.pose.bones
|
||||
|
||||
for fcu in action.fcurves:
|
||||
if fcu in fcu_paths:
|
||||
continue
|
||||
if obj.mode == 'POSE':
|
||||
if bake_ops.selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
|
||||
for bone in bonelist:
|
||||
#find the fcurve of the bone
|
||||
if fcu.data_path.rfind(bone.name) != 12 or fcu.data_path[12 + len(bone.name)] != '"':
|
||||
continue
|
||||
# transform = fcu.data_path[15 + len(bone.name):]
|
||||
transform = fcu.data_path.split('"].')[1]
|
||||
if transform not in transformations:
|
||||
continue
|
||||
current_value = getattr(obj.pose.bones[bone.name], transform)
|
||||
else:
|
||||
transform = fcu.data_path
|
||||
current_value = getattr(obj, transform)
|
||||
|
||||
eval_array = evaluate_layers(context, obj, anim_data, fcu, len(current_value))
|
||||
if eval_array is None:
|
||||
eval_array = evaluate_array(action, fcu.data_path, context.scene.frame_current, len(current_value))
|
||||
#calculate the difference between current value and the fcurve value
|
||||
add_diff(obj, action.fcurves, fcu.data_path, np.array(current_value), eval_array)
|
||||
|
||||
class MULTIKEY_OT_Multikey(bpy.types.Operator):
|
||||
"""Edit all selected keyframes"""
|
||||
bl_label = "Edit Selected Keyframes"
|
||||
bl_idname = "fcurves.multikey"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
# bl_description = ('Select keyframes, move your bone or objecet and press the operator. Does not work with Autokey')
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object and context.active_object.animation_data and bpy.context.scene.tool_settings.use_keyframe_insert_auto == False
|
||||
|
||||
def execute(self, context):
|
||||
evaluate_value(self, context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class MultikeyProperties(bpy.types.PropertyGroup):
|
||||
|
||||
#selectedbones: bpy.props.BoolProperty(name="Affect only selected bones", description="Affect only selected bones", default=True, options={'HIDDEN'})
|
||||
#handletype: bpy.props.BoolProperty(name="Keep handle types", description="Keep handle types", default=False, options={'HIDDEN'})
|
||||
scale: bpy.props.FloatProperty(name="Scale Values Factor", description="Scale percentage from the average value", default=1.0, soft_max = 10, soft_min = -10, step=0.1, precision = 3, update = scale_value)
|
||||
randomness: bpy.props.FloatProperty(name="Randomness", description="Random Threshold of keyframes", default=0.1, min=0.0, max = 1.0, update = random_value)
|
||||
is_dragging: bpy.props.BoolProperty(default = False)
|
||||
|
||||
#filters
|
||||
filter_location: bpy.props.BoolVectorProperty(name="Location", description="Filter Location properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
filter_rotation: bpy.props.BoolVectorProperty(name="Rotation", description="Filter Rotation properties", default=(True, True, True, True), size = 4, options={'HIDDEN'})
|
||||
filter_scale: bpy.props.BoolVectorProperty(name="Scale", description="Filter Scale properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
|
||||
class FilterProperties(bpy.types.Operator):
|
||||
"""Filter Location Rotation and Scale Properties"""
|
||||
bl_idname = "fcurves.filter"
|
||||
bl_label = "Filter Properties W X Y Z"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
wm = context.window_manager
|
||||
return wm.invoke_props_dialog(self, width = 200)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
row = layout.row()
|
||||
row.label(text = 'Location')
|
||||
row.prop(context.scene.multikey, 'filter_location', text = '')
|
||||
row = layout.row()
|
||||
row.label(text = 'Rotation')
|
||||
row.prop(context.scene.multikey, 'filter_rotation', text = '')
|
||||
row = layout.row()
|
||||
row.label(text = 'Scale')
|
||||
row.prop(context.scene.multikey, 'filter_scale', text = '')
|
||||
|
||||
def execute(self, context):
|
||||
return {'CANCELLED'}
|
||||
|
||||
classes = (MultikeyProperties, FilterProperties, MULTIKEY_OT_Multikey, ScaleValuesOp)
|
||||
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
bpy.types.Scene.multikey = bpy.props.PointerProperty(type = MultikeyProperties, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
del bpy.types.Scene.multikey
|
||||
@@ -0,0 +1,634 @@
|
||||
import bpy
|
||||
|
||||
from . import anim_layers
|
||||
from . import bake_ops
|
||||
|
||||
def subscriptions_remove(handler = True):
|
||||
#clear all handlers and subsciptions
|
||||
bpy.msgbus.clear_by_owner(bpy.context.scene)
|
||||
if not handler:
|
||||
return
|
||||
if check_handler in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.remove(check_handler)
|
||||
if animlayers_frame in bpy.app.handlers.frame_change_post:
|
||||
bpy.app.handlers.frame_change_post.remove(animlayers_frame)
|
||||
|
||||
def subscriptions_add(scene, handler = True):
|
||||
bpy.msgbus.clear_by_owner(scene)
|
||||
global initial_call
|
||||
|
||||
initial_call = True
|
||||
subscribe_to_frame_end(scene)
|
||||
subscribe_to_track_name(scene)
|
||||
subscribe_to_action_name(scene)
|
||||
subscribe_to_strip_settings(scene)
|
||||
subscribe_to_influence(scene)
|
||||
|
||||
#If I call initial call from here it calls before running the previous functions
|
||||
#initial_call = False
|
||||
|
||||
if not handler:
|
||||
return
|
||||
|
||||
if check_handler not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(check_handler)
|
||||
if animlayers_frame not in bpy.app.handlers.frame_change_post:
|
||||
bpy.app.handlers.frame_change_post.append(animlayers_frame)
|
||||
|
||||
def animlayers_frame(self, context):
|
||||
scene = bpy.context.scene
|
||||
current = scene.frame_current_final
|
||||
|
||||
#Checking if preview range was turned on or off, when using hotkey P it doesn't recognize
|
||||
#only during the frame handler
|
||||
if scene.get('framerange_preview') != scene.use_preview_range:
|
||||
scene['framerange_preview'] = scene.use_preview_range
|
||||
frameend_update_callback()
|
||||
return
|
||||
|
||||
frame_start, frame_end = bake_ops.frame_start_end(scene)
|
||||
reset_subscription = False
|
||||
if 'outofrange' not in globals():
|
||||
global outofrange
|
||||
outofrange = False if frame_start <= current <= frame_end else True
|
||||
|
||||
if frame_start <= current <= frame_end:
|
||||
if outofrange:
|
||||
frameend_update_callback()
|
||||
outofrange = False
|
||||
return
|
||||
outofrange = True
|
||||
if current <= frame_end:
|
||||
return
|
||||
#iterate only through objects with anim layers turned on
|
||||
objects = [obj.object for obj in scene.AL_objects]
|
||||
for obj in objects:
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return
|
||||
for i, track in enumerate(nla_tracks):
|
||||
if len(track.strips) != 1:
|
||||
continue
|
||||
|
||||
#checks if the layer has a custom frame range
|
||||
if obj.Anim_Layers[i].frame_range:
|
||||
continue
|
||||
if not reset_subscription:
|
||||
subscriptions_remove(handler = False)
|
||||
reset_subscription = True
|
||||
|
||||
track.strips[0].frame_end_ui = current + 10
|
||||
|
||||
if reset_subscription:
|
||||
subscriptions_add(scene, handler = False)
|
||||
sync_strip_range()
|
||||
|
||||
def objects_viewlayer(scene):
|
||||
'''in case of an object excluded or included in the nla, update it because of an nla bug'''
|
||||
if len(bpy.context.view_layer.objects) == scene.als.viewlayer_objects:
|
||||
return
|
||||
i = 0
|
||||
while i < len(scene.AL_objects):
|
||||
obj = scene.AL_objects[i].object
|
||||
if obj is None:
|
||||
scene.AL_objects.remove(i)
|
||||
continue
|
||||
i += 1
|
||||
if obj.als.viewlayer and obj not in bpy.context.view_layer.objects.values():
|
||||
obj.als.viewlayer = False
|
||||
if not obj.als.viewlayer and obj in bpy.context.view_layer.objects.values():
|
||||
#anim_data = anim_layers.anim_data_type(obj)
|
||||
obj.als.upper_stack = False
|
||||
obj.als.viewlayer = True
|
||||
obj.als.layer_index = obj.als.layer_index
|
||||
#anim_layers.tweak_mode_upper_stack(bpy.context, anim_data)
|
||||
scene.als.viewlayer_objects = len(bpy.context.view_layer.objects)
|
||||
|
||||
def check_handler(self, context):
|
||||
'''A main function that performs a series of checks using a handler'''
|
||||
scene = bpy.context.scene
|
||||
#if there are no objects included in animation layers then return
|
||||
if not len(scene.AL_objects):
|
||||
return
|
||||
|
||||
objects_viewlayer(scene)
|
||||
|
||||
obj = bpy.context.object
|
||||
|
||||
#if the object was removed from the scene, then remove it from anim layers object list
|
||||
if obj is None:
|
||||
i = 0
|
||||
while i < len(scene.AL_objects):
|
||||
if scene.AL_objects[i].object not in scene.objects.values():
|
||||
scene.AL_objects.remove(i)
|
||||
else:
|
||||
i += 1
|
||||
return
|
||||
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
if not anim_data.use_nla:
|
||||
obj.als.turn_on = False
|
||||
return
|
||||
if not len(obj.Anim_Layers):
|
||||
return
|
||||
if not hasattr(anim_data, 'nla_tracks') or not obj.als.turn_on: #obj.select_get() == False or
|
||||
return
|
||||
anim_layers.add_obj_to_animlayers(obj, [item.object for item in scene.AL_objects])
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
layer = obj.Anim_Layers[obj.als.layer_index]
|
||||
active_action_update(obj, anim_data, nla_tracks)
|
||||
#check if a keyframe was removed
|
||||
if bpy.context.active_operator is not None:
|
||||
if bpy.context.active_operator.name in ['Transform', 'Delete Keyframes'] and obj.als.edit_all_keyframes:
|
||||
anim_layers.edit_all_keyframes()
|
||||
|
||||
if bpy.context.active_operator.name == 'Enter Tweak Mode':
|
||||
if not bpy.context.active_operator.properties['use_upper_stack_evaluation']:
|
||||
obj.als.upper_stack = False
|
||||
|
||||
if bpy.context.active_operator.name == 'Move Channels':
|
||||
anim_layers.visible_layers(obj, nla_tracks)
|
||||
|
||||
# check if track and layers are synchronized
|
||||
if len(nla_tracks) != len(obj.Anim_Layers):
|
||||
new_layers_names = set(track.name for track in nla_tracks).difference(set(layer.name for layer in obj.Anim_Layers))
|
||||
anim_layers.visible_layers(obj, nla_tracks)
|
||||
if obj.als.layer_index > len(obj.Anim_Layers)-1:
|
||||
obj.als.layer_index = len(obj.Anim_Layers)-1
|
||||
|
||||
#update new layer with strip settings
|
||||
frame_start, frame_end = bake_ops.frame_start_end(bpy.context.scene)
|
||||
|
||||
for layer_name in new_layers_names:
|
||||
if len(nla_tracks[layer_name].strips) != 1:
|
||||
continue
|
||||
strip = get_strip_in_meta(nla_tracks[layer_name].strips[0])
|
||||
layer = obj.Anim_Layers[layer_name]
|
||||
if (strip.frame_start, strip.frame_end) != (frame_start, frame_end):
|
||||
layer['frame_range'] = True
|
||||
update_strip_layer_settings(strip, layer)
|
||||
layer['action'] = strip.action
|
||||
return
|
||||
|
||||
anim_layers.add_obj_to_animlayers(obj, [item.object for item in scene.AL_objects])
|
||||
|
||||
track = nla_tracks[obj.als.layer_index]
|
||||
always_sync_range(track, layer)
|
||||
# sync_strip_range(track, layer)
|
||||
|
||||
if anim_data.use_tweak_mode and layer.lock:
|
||||
layer['lock'] = False
|
||||
elif not anim_data.use_tweak_mode and not layer.lock:
|
||||
layer['lock'] = True
|
||||
|
||||
influence_sync(obj, nla_tracks)
|
||||
|
||||
# continue if locked
|
||||
if layer.lock:
|
||||
return
|
||||
|
||||
if obj.als.view_all_keyframes:
|
||||
anim_layers.hide_view_all_keyframes(obj, anim_data)
|
||||
check_selected_bones(obj)
|
||||
|
||||
influence_check(nla_tracks[obj.als.layer_index])
|
||||
|
||||
def active_action_update(obj, anim_data, nla_tracks):
|
||||
'''updating the active action into the selected layer'''
|
||||
if obj.Anim_Layers[obj.als.layer_index].lock:
|
||||
if anim_data.action != None:
|
||||
subscriptions_remove()
|
||||
anim_data.use_tweak_mode = False
|
||||
anim_data.action = None
|
||||
subscriptions_add(bpy.context.scene)
|
||||
return
|
||||
if anim_data.action == nla_tracks[obj.als.layer_index].strips[0].action:
|
||||
return
|
||||
if not len(nla_tracks[obj.als.layer_index].strips):
|
||||
return
|
||||
if not anim_data.action or anim_data.is_property_readonly('action'):
|
||||
return
|
||||
subscriptions_remove()
|
||||
action = anim_data.action
|
||||
anim_data.action = None
|
||||
obj.Anim_Layers[obj.als.layer_index].action = action
|
||||
subscriptions_add(bpy.context.scene)
|
||||
|
||||
def get_strip_in_meta(strip):
|
||||
'''check if it's meta strip then access the last strip inside meta hierarchy'''
|
||||
while len(strip.strips):
|
||||
strip = strip.strips[0]
|
||||
return strip
|
||||
|
||||
def sync_strip_range():
|
||||
|
||||
scene = bpy.context.scene
|
||||
frame_start, frame_end = bake_ops.frame_start_end(scene)
|
||||
|
||||
if scene.frame_current_final > frame_end:
|
||||
frame_end = scene.frame_current_final + 10
|
||||
|
||||
objects = [obj.object for obj in scene.AL_objects]
|
||||
for obj in objects:
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
continue
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
continue
|
||||
for i, track in enumerate(nla_tracks):
|
||||
if len(track.strips) != 1:
|
||||
continue
|
||||
if obj.Anim_Layers[i]['frame_range']:
|
||||
continue
|
||||
strip = track.strips[0]
|
||||
strip_frame_start = strip.frame_start
|
||||
strip_frame_end = strip.frame_end
|
||||
|
||||
if (strip_frame_start, round(strip_frame_end)) != (0.0, float(frame_end)):
|
||||
obj.Anim_Layers[i]['frame_range'] = True
|
||||
|
||||
def always_sync_range(track, layer):
|
||||
'''sync frame range when always sync turned on'''
|
||||
if not len(track.strips):
|
||||
return
|
||||
if not layer.frame_range:
|
||||
if track.strips[0].use_sync_length:
|
||||
track.strips[0].use_sync_length = False
|
||||
return
|
||||
if not track.strips[0].use_sync_length:
|
||||
if tuple(layer.action_range) != (0.0, 0.0): #reset action range when turned off
|
||||
layer.action_range = (0.0, 0.0)
|
||||
return
|
||||
strip = track.strips[0]
|
||||
if tuple(layer.action_range) == tuple((strip.action.frame_range[0], strip.action.frame_range[1])):
|
||||
return
|
||||
anim_layers.sync_frame_range(bpy.context)
|
||||
layer.action_range = strip.action.frame_range
|
||||
|
||||
def influence_sync(obj, nla_tracks):
|
||||
|
||||
#Tracks that dont have keyframes are locked
|
||||
for i, track in enumerate(nla_tracks):
|
||||
|
||||
if obj.Anim_Layers[i].lock:
|
||||
continue
|
||||
if not len(track.strips):
|
||||
continue
|
||||
if not len(track.strips[0].fcurves):
|
||||
continue
|
||||
if not len(track.strips[0].fcurves[0].keyframe_points):
|
||||
#apply the influence property to the temp property when keyframes are removed (but its still locked)
|
||||
if not track.strips[0].fcurves[0].lock:
|
||||
obj.Anim_Layers[i].influence = track.strips[0].influence
|
||||
track.strips[0].fcurves[0].lock = True
|
||||
|
||||
if obj.animation_data is None:
|
||||
return
|
||||
action = obj.animation_data.action
|
||||
if action is None:
|
||||
return
|
||||
#if a keyframe was found in the temporary property then add it to the
|
||||
data_path = 'Anim_Layers[' + str(obj.als.layer_index) + '].influence'
|
||||
fcu_influence = action.fcurves.find(data_path)
|
||||
if fcu_influence is None:
|
||||
return
|
||||
if not len(fcu_influence.keyframe_points):
|
||||
return
|
||||
#remove the temporary influence
|
||||
action.fcurves.remove(fcu_influence)
|
||||
#if the action was created just for the influence because of empty object data type then remove the action
|
||||
if action.name == obj.name + 'Action' and not len(obj.animation_data.nla_tracks) and not len(action.fcurves):
|
||||
bpy.data.actions.remove(action)
|
||||
if obj.Anim_Layers[obj.als.layer_index].influence_mute:
|
||||
return
|
||||
strip = nla_tracks[obj.als.layer_index].strips[0]
|
||||
strip.fcurves[0].lock = False
|
||||
strip.keyframe_insert('influence')
|
||||
strip.fcurves[0].update()
|
||||
|
||||
|
||||
def influence_check(selected_track):
|
||||
'''update influence when a keyframe was added without autokey'''
|
||||
#skip the next steps if a strip is missing or tracks were removed from the nla tracks
|
||||
if len(selected_track.strips) != 1:# or obj.als.layer_index > len(nla_tracks)-2:
|
||||
return
|
||||
if not len(selected_track.strips[0].fcurves):
|
||||
return
|
||||
|
||||
global influence_keys
|
||||
|
||||
if selected_track.strips[0].fcurves[0].mute or not len(selected_track.strips[0].fcurves[0].keyframe_points) or bpy.context.scene.tool_settings.use_keyframe_insert_auto:
|
||||
if 'influence_keys' in globals():
|
||||
del influence_keys
|
||||
return #when the fcurve doesnt have keyframes, or when autokey is turned on, then return
|
||||
|
||||
#update if the influence keyframes are changed. influence_keys are first added in influence_update_callback
|
||||
if 'influence_keys' not in globals():
|
||||
return
|
||||
if influence_keys != [tuple(key.co) for key in selected_track.strips[0].fcurves[0].keyframe_points]:
|
||||
selected_track.strips[0].fcurves[0].update()
|
||||
del influence_keys
|
||||
|
||||
|
||||
def check_selected_bones(obj):
|
||||
'''running in the handler and checking if the selected bones were changed during view multiply layer keyframes'''
|
||||
if not obj.als.only_selected_bones:
|
||||
return
|
||||
global selected_bones
|
||||
try:
|
||||
selected_bones
|
||||
except NameError:
|
||||
selected_bones = bpy.context.selected_pose_bones
|
||||
return
|
||||
else:
|
||||
if selected_bones != bpy.context.selected_pose_bones:
|
||||
selected_bones = bpy.context.selected_pose_bones
|
||||
obj.als.view_all_keyframes = True
|
||||
|
||||
########################### MSGBUS SUBSCRIPTIONS #############################
|
||||
|
||||
#Callback function for Scene frame end
|
||||
def frameend_update_callback():
|
||||
'''End the strips at the end of the scene or scene preview'''
|
||||
|
||||
scene = bpy.context.scene
|
||||
if not scene.AL_objects:
|
||||
return
|
||||
frame_start, frame_end = bake_ops.frame_start_end(scene)
|
||||
if scene.frame_current_final > frame_end:
|
||||
frame_end = scene.frame_current_final + 10
|
||||
#return
|
||||
|
||||
for AL_item in scene.AL_objects:
|
||||
obj = AL_item.object
|
||||
if obj is None or obj not in scene.objects.values():
|
||||
continue
|
||||
#anim_data = anim_data_type(obj)
|
||||
anim_datas = anim_layers.anim_datas_append(obj)
|
||||
|
||||
for anim_data in anim_datas:
|
||||
if anim_data is None:
|
||||
continue
|
||||
if len(anim_data.nla_tracks) != len(obj.Anim_Layers):
|
||||
continue
|
||||
for layer, track in zip(obj.Anim_Layers, anim_data.nla_tracks):
|
||||
if layer.frame_range:
|
||||
continue
|
||||
if len(track.strips) == 1:
|
||||
|
||||
track.strips[0].action_frame_start = 0 - layer.offset * 1/layer.speed
|
||||
track.strips[0].action_frame_end = frame_end * 1/layer.speed - layer.offset * 1/layer.speed
|
||||
track.strips[0].frame_start = 0
|
||||
track.strips[0].frame_end = frame_end
|
||||
track.strips[0].scale = layer.speed
|
||||
|
||||
#Subscribe to the scene frame_end
|
||||
def subscribe_to_frame_end(scene):
|
||||
'''subscribe_to_frame_end and frame preview end'''
|
||||
subscribe_end = scene.path_resolve("frame_end", False)
|
||||
subscribe_preview_end = scene.path_resolve("frame_preview_end", False)
|
||||
subscribe_use_preview = scene.path_resolve("use_preview_range", False)
|
||||
|
||||
for subscribe in [subscribe_end, subscribe_preview_end, subscribe_use_preview]:
|
||||
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe,
|
||||
owner=scene,
|
||||
args=(),
|
||||
notify=frameend_update_callback,)
|
||||
|
||||
bpy.msgbus.publish_rna(key=subscribe)
|
||||
|
||||
# def action_framestart_update_callback(*args):
|
||||
# ''' update the strip start with the action start'''
|
||||
|
||||
|
||||
def track_update_callback():
|
||||
'''update layers with the tracks name'''
|
||||
global initial_call
|
||||
if initial_call:
|
||||
# initial_call = False
|
||||
return
|
||||
|
||||
if not bpy.context.selected_objects:
|
||||
return
|
||||
obj = bpy.context.object
|
||||
if obj is None:
|
||||
return
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
current_anim_data = anim_layers.anim_data_type(obj)
|
||||
anim_datas = anim_layers.anim_datas_append(obj)
|
||||
for anim_data in anim_datas:
|
||||
if anim_data is None:
|
||||
return
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):# or len(nla_tracks[:-1]) != len(obj.Anim_Layers):
|
||||
return
|
||||
override_tracks = anim_layers.check_override_tracks(obj, anim_data)
|
||||
for i, track in enumerate(nla_tracks):
|
||||
if anim_data != current_anim_data:
|
||||
continue
|
||||
#make sure there are no duplicated names
|
||||
if track.name != obj.Anim_Layers[i].name:
|
||||
#If its an override track, then make sure the reference object name is also synchronized
|
||||
if obj.Anim_Layers[i].name in override_tracks:
|
||||
override_tracks[obj.Anim_Layers[i].name].name = track.name
|
||||
obj.Anim_Layers[i].name = track.name
|
||||
if len(track.strips) == 1:
|
||||
track.strips[0].name = track.name
|
||||
|
||||
def subscribe_to_track_name(scene):
|
||||
'''Subscribe to the name of track'''
|
||||
|
||||
#subscribe_track = nla_track.path_resolve("name", False)
|
||||
subscribe_track = (bpy.types.NlaTrack, 'name')
|
||||
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe_track,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(),
|
||||
# Callback function for property update
|
||||
notify=track_update_callback,)
|
||||
|
||||
bpy.msgbus.publish_rna(key=subscribe_track)
|
||||
|
||||
def action_name_callback():
|
||||
'''update layers with the tracks name'''
|
||||
global initial_call
|
||||
if initial_call:
|
||||
# initial_call = False
|
||||
return
|
||||
|
||||
obj = bpy.context.object
|
||||
if obj is None:
|
||||
return
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
#anim_datas = anim_layers.anim_datas_append(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return
|
||||
layer = obj.Anim_Layers[obj.als.layer_index]
|
||||
if not len(nla_tracks[obj.als.layer_index].strips):
|
||||
return
|
||||
action = nla_tracks[obj.als.layer_index].strips[0].action
|
||||
if action is None:
|
||||
return
|
||||
if not obj.als.auto_rename or layer.name == action.name:
|
||||
return
|
||||
layer.name = action.name
|
||||
|
||||
def subscribe_to_action_name(scene):
|
||||
'''Subscribe to the name of track'''
|
||||
|
||||
#subscribe_track = nla_track.path_resolve("name", False)
|
||||
subscribe_action = (bpy.types.Action, 'name')
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe_action,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(),
|
||||
# Callback function for property update
|
||||
notify=action_name_callback,)
|
||||
|
||||
bpy.msgbus.publish_rna(key=subscribe_action)
|
||||
|
||||
def influence_update_callback(*args):
|
||||
'''update influence'''
|
||||
global initial_call
|
||||
if initial_call:
|
||||
initial_call = False
|
||||
return
|
||||
|
||||
if not bpy.context.selected_objects:
|
||||
return
|
||||
obj = bpy.context.object
|
||||
#checking if the object has nla tracks, when I used undo it was still calling the property on an object with no nla tracks
|
||||
if obj is None:
|
||||
return
|
||||
if not obj.als.turn_on:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
if not len(anim_data.nla_tracks):
|
||||
return
|
||||
|
||||
track = anim_data.nla_tracks[obj.als.layer_index]
|
||||
if len(track.strips) != 1:
|
||||
return
|
||||
|
||||
if track.strips[0].fcurves[0].mute or track.strips[0].fcurves[0].lock:
|
||||
return
|
||||
|
||||
if bpy.context.scene.tool_settings.use_keyframe_insert_auto and len(track.strips[0].fcurves[0].keyframe_points):
|
||||
track.strips[0].keyframe_insert('influence')
|
||||
track.strips[0].fcurves[0].update()
|
||||
return
|
||||
|
||||
#if the influence property and fcurve value are not the same then store the keyframes to check in the handler for a change
|
||||
if track.strips[0].influence != track.strips[0].fcurves[0].evaluate(bpy.context.scene.frame_current):
|
||||
global influence_keys
|
||||
influence_keys = [tuple(key.co) for key in track.strips[0].fcurves[0].keyframe_points]
|
||||
|
||||
def subscribe_to_influence(scene):
|
||||
'''Subscribe to the influence of the track'''
|
||||
subscribe_influence = (bpy.types.NlaStrip, 'influence')
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=subscribe_influence,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(scene,),
|
||||
# Callback function for property update
|
||||
notify=influence_update_callback,)
|
||||
|
||||
bpy.msgbus.publish_rna(key=subscribe_influence)
|
||||
|
||||
def subscribe_to_strip_settings(scene):
|
||||
'''Subscribe to the strip settings of the track'''
|
||||
|
||||
frame_start = (bpy.types.NlaStrip, 'frame_start')
|
||||
frame_end = (bpy.types.NlaStrip, 'frame_end')
|
||||
action_frame_start = (bpy.types.NlaStrip, 'action_frame_start')
|
||||
action_frame_end = (bpy.types.NlaStrip, 'action_frame_end')
|
||||
scale = (bpy.types.NlaStrip, 'scale')
|
||||
repeat = (bpy.types.NlaStrip, 'repeat')
|
||||
|
||||
attributes = [frame_start, frame_end, action_frame_start, action_frame_end, scale, repeat, frame_start, frame_end]
|
||||
|
||||
if bpy.app.version > (3, 2, 0):
|
||||
#this properties exist only after Blender 3.2
|
||||
frame_start_ui = (bpy.types.NlaStrip, 'frame_start_ui')
|
||||
frame_end_ui = (bpy.types.NlaStrip, 'frame_end_ui')
|
||||
attributes += [frame_start_ui, frame_end_ui]
|
||||
|
||||
for key in attributes:
|
||||
bpy.msgbus.subscribe_rna(
|
||||
key=key,
|
||||
# owner of msgbus subcribe (for clearing later)
|
||||
owner=scene,
|
||||
# Args passed to callback function (tuple)
|
||||
args=(),
|
||||
# Callback function for property update
|
||||
notify=strip_settings_callback,)
|
||||
|
||||
#bpy.msgbus.publish_rna(key=frame_start)
|
||||
|
||||
def update_strip_layer_settings(strip, layer):
|
||||
layer['speed'] = strip.scale
|
||||
|
||||
start_offset = strip.action.frame_range[0] - strip.frame_start
|
||||
offset = (strip.action_frame_start - strip.frame_start - start_offset) * strip.scale + start_offset
|
||||
layer['offset'] = round(-offset, 3)
|
||||
|
||||
#If custom frame range is turned off return to not lose frame range values
|
||||
if not layer.frame_range:
|
||||
return
|
||||
layer['frame_end'] = strip.frame_end
|
||||
layer['frame_start'] = strip.frame_start
|
||||
layer['repeat'] = strip.repeat
|
||||
|
||||
|
||||
def strip_settings_callback():
|
||||
'''subscribe_to_strip_settings callback'''
|
||||
global initial_call
|
||||
if initial_call:
|
||||
# initial_call = False
|
||||
return
|
||||
|
||||
if not bpy.context.selected_objects:
|
||||
return
|
||||
obj = bpy.context.object
|
||||
if obj is None:
|
||||
return
|
||||
anim_data = anim_layers.anim_data_type(obj)
|
||||
if anim_data is None:
|
||||
return
|
||||
if not len(anim_data.nla_tracks):
|
||||
return
|
||||
if not len(obj.Anim_Layers):
|
||||
return
|
||||
strip = anim_data.nla_tracks[obj.als.layer_index].strips[0]
|
||||
sync_strip_range()
|
||||
if not len(anim_data.nla_tracks[obj.als.layer_index].strips):
|
||||
return
|
||||
strip = anim_data.nla_tracks[obj.als.layer_index].strips[0]
|
||||
layer = obj.Anim_Layers[obj.als.layer_index]
|
||||
update_strip_layer_settings(strip, layer)
|
||||
anim_layers.redraw_areas([ 'VIEW_3D'])
|
||||
@@ -0,0 +1,189 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
|
||||
class GizmoSizeUp(bpy.types.Operator):
|
||||
"""Share keyframes between all the selected objects and bones"""
|
||||
bl_idname = "view3d.gizmo_size_up"
|
||||
bl_label = "Gizmo_Size_Up"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
context.preferences.view.gizmo_size += context.scene.animtoolbox.gizmo_size
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
class GizmoSizeDown(bpy.types.Operator):
|
||||
"""Share keyframes between all the selected objects and bones"""
|
||||
bl_idname = "view3d.gizmo_size_down"
|
||||
bl_label = "Gizmo_Size_Down"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
context.preferences.view.gizmo_size -= context.scene.animtoolbox.gizmo_size
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
def clear_isolate_pose_mode(scene):
|
||||
if not len(scene.animtoolbox.isolated):
|
||||
return
|
||||
for obj in scene.animtoolbox.isolated:
|
||||
if not obj.hidden:
|
||||
continue
|
||||
obj.hidden.hide_set(False)
|
||||
scene.animtoolbox.isolated.clear()
|
||||
scene.animtoolbox.active_obj = None
|
||||
|
||||
def isolate_pose_mode(scene):
|
||||
context = bpy.context
|
||||
#return when going out of isolate pose or when active object is not in pose mode
|
||||
if not scene.animtoolbox.isolate_pose_mode or context.active_object.mode != 'POSE':
|
||||
clear_isolate_pose_mode(scene)
|
||||
return
|
||||
|
||||
#handler continue only if the active object is None otherwise it collects all armature objects
|
||||
if scene.animtoolbox.active_obj is None:
|
||||
scene.animtoolbox.active_obj = context.active_object
|
||||
else:
|
||||
return
|
||||
|
||||
isolated = scene.animtoolbox.isolated
|
||||
for obj in context.view_layer.objects:
|
||||
if obj.type != 'ARMATURE':
|
||||
continue
|
||||
if obj.hide_get():
|
||||
continue
|
||||
rig = isolated.add()
|
||||
if obj.mode == 'POSE':
|
||||
rig.selected = obj
|
||||
else:
|
||||
rig.hidden = obj
|
||||
obj.hide_set(True)
|
||||
|
||||
class IsolatePoseMode(bpy.types.Operator):
|
||||
"""Isolates armatures during pose mode"""
|
||||
bl_idname = "anim.isolate_pose_mode"
|
||||
bl_label = "Isolate Pose Mode"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
# If the modal is already running, then don't run it the second time
|
||||
scene = context.scene
|
||||
if scene.animtoolbox.isolate_pose_mode:
|
||||
if isolate_pose_mode in bpy.app.handlers.depsgraph_update_pre:
|
||||
clear_isolate_pose_mode(scene)
|
||||
bpy.app.handlers.depsgraph_update_pre.remove(isolate_pose_mode)
|
||||
scene.animtoolbox.isolate_pose_mode = False
|
||||
return {'FINISHED'}
|
||||
|
||||
scene.animtoolbox.isolate_pose_mode = True
|
||||
isolate_pose_mode(scene)
|
||||
if isolate_pose_mode not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(isolate_pose_mode)
|
||||
return {'FINISHED'}
|
||||
|
||||
class SwitchBoneCollectionsVisibility(bpy.types.Operator):
|
||||
"""Turn all bone collections visible and then press again to switch back"""
|
||||
bl_idname = "anim.switch_collections_visibility"
|
||||
bl_label = "Bone Collections Visibility"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.app.version >= (4, 0, 0)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
if obj.type != 'ARMATURE':
|
||||
return {'CANCELLED'}
|
||||
if not obj.animation_data:
|
||||
self.report({'INFO'}, 'No animation is available')
|
||||
return {'CANCELLED'}
|
||||
|
||||
if not obj.animation_data.action:
|
||||
self.report({'INFO'}, 'No animation is available')
|
||||
return {'CANCELLED'}
|
||||
|
||||
collections = obj.data.collections
|
||||
|
||||
if not len(collections):
|
||||
self.report({'INFO'}, 'No collections are available')
|
||||
return {'CANCELLED'}
|
||||
#check if there are collections that are marked with
|
||||
tagged_col = ['atb' in col.keys() for col in collections]
|
||||
atb_ui = context.scene.animtoolbox
|
||||
|
||||
if any(tagged_col) and atb_ui.col_vis:
|
||||
#collections are already marked so return to previous collection visibilty
|
||||
for col in collections:
|
||||
if 'atb' in col.keys():
|
||||
col.is_visible = col['atb']
|
||||
del col['atb']
|
||||
atb_ui.col_vis = False
|
||||
else:
|
||||
#Mark visible collections and turn collections with animated bones on
|
||||
animated_bones = set()
|
||||
start = 'pose.bones["'
|
||||
end = '"]'
|
||||
#get all the animated bones from the fcurves
|
||||
for fcu in obj.animation_data.action.fcurves:
|
||||
start_index = fcu.data_path.find(start)
|
||||
end_index = fcu.data_path.find(end)
|
||||
#if it's not a posebone fcurve then skip
|
||||
if start_index == -1 or end_index == -1:
|
||||
continue
|
||||
animated_bones.add(fcu.data_path[start_index + len(start):end_index])
|
||||
|
||||
#check if the collecetion that is turned off has animated bones
|
||||
find_anim = []
|
||||
for col in collections:
|
||||
for bone in col.bones:
|
||||
if bone.name in animated_bones and not col.is_visible:
|
||||
# print(bone.name, 'in ', col.name)
|
||||
find_anim.append(col)
|
||||
break
|
||||
|
||||
if not find_anim:
|
||||
self.report({'INFO'}, 'No collections with animated bones and no visibility are found')
|
||||
return {'CANCELLED'}
|
||||
|
||||
#Turn on collections without visiblity
|
||||
for col in collections:
|
||||
if col in find_anim:
|
||||
#tag visibility
|
||||
col['atb'] = col.is_visible
|
||||
col.is_visible = True
|
||||
|
||||
atb_ui.col_vis = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
classes = (GizmoSizeUp, GizmoSizeDown, IsolatePoseMode, SwitchBoneCollectionsVisibility)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
@@ -0,0 +1,549 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
from mathutils import Matrix, Vector
|
||||
from math import radians
|
||||
import numpy
|
||||
|
||||
def draw_wgt(boneLength, bone):
|
||||
suffix = bone.id_data.name + '_' + bone.name
|
||||
if 'WGTB_object' + suffix in bpy.data.objects:
|
||||
obj = bpy.data.objects['WGTB_object'] + suffix
|
||||
if 'WGTB_shape' + suffix in obj.data.name:
|
||||
return obj
|
||||
mesh = bpy.data.meshes.new('WGTB_shape_' + suffix)
|
||||
obj = bpy.data.objects.new('WGTB_object_' + suffix, mesh)
|
||||
#coordinates of the sphere widget shape
|
||||
sphere = {"edges": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [0, 23], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [24, 47], [48, 49], [49, 50], [50, 51], [51, 52], [52, 53], [53, 54], [54, 55], [55, 56], [56, 57], [57, 58], [58, 59], [59, 60], [60, 61], [61, 62], [62, 63], [63, 64], [64, 65], [65, 66], [66, 67], [67, 68], [68, 69], [69, 70], [70, 71], [48, 71]],
|
||||
"vertices": [[0.0, 0.10000002384185791, 0.0], [-0.025881901383399963, 0.09659260511398315, 0.0], [-0.050000011920928955, 0.08660250902175903, 0.0], [-0.07071065902709961, 0.07071065902709961, 0.0], [-0.08660256862640381, 0.04999998211860657, 0.0], [-0.09659260511398315, 0.025881901383399963, 0.0], [-0.10000002384185791, 7.549793679118011e-09, 0.0], [-0.09659260511398315, -0.02588188648223877, 0.0], [-0.08660256862640381, -0.04999998211860657, 0.0], [-0.07071071863174438, -0.07071065902709961, 0.0], [-0.050000011920928955, -0.08660250902175903, 0.0], [-0.02588193118572235, -0.09659260511398315, 0.0], [-3.894143674187944e-08, -0.10000002384185791, 0.0], [0.025881856679916382, -0.09659260511398315, 0.0], [0.04999995231628418, -0.08660256862640381, 0.0], [0.07071065902709961, -0.07071071863174438, 0.0], [0.08660250902175903, -0.05000004172325134, 0.0], [0.09659254550933838, -0.025881946086883545, 0.0], [0.10000002384185791, -4.649123752642481e-08, 0.0], [0.09659260511398315, 0.025881856679916382, 0.0], [0.08660256862640381, 0.04999995231628418, 0.0], [0.07071071863174438, 0.07071065902709961, 0.0], [0.05000007152557373, 0.08660250902175903, 0.0], [0.025881975889205933, 0.09659254550933838, 0.0], [0.0, 7.450580596923828e-09, 0.10000002384185791], [-0.025881901383399963, 7.450580596923828e-09, 0.09659260511398315], [-0.050000011920928955, 7.450580596923828e-09, 0.08660250902175903], [-0.07071065902709961, 7.450580596923828e-09, 0.07071065902709961], [-0.08660256862640381, 3.725290298461914e-09, 0.04999998211860657], [-0.09659260511398315, 1.862645149230957e-09, 0.025881901383399963], [-0.10000002384185791, 8.881784197001252e-16, 7.549793679118011e-09], [-0.09659260511398315, -1.862645149230957e-09, -0.02588188648223877], [-0.08660256862640381, -3.725290298461914e-09, -0.04999998211860657], [-0.07071071863174438, -7.450580596923828e-09, -0.07071065902709961], [-0.050000011920928955, -7.450580596923828e-09, -0.08660250902175903], [-0.02588193118572235, -7.450580596923828e-09, -0.09659260511398315], [-3.894143674187944e-08, -7.450580596923828e-09, -0.10000002384185791], [0.025881856679916382, -7.450580596923828e-09, -0.09659260511398315], [0.04999995231628418, -7.450580596923828e-09, -0.08660256862640381], [0.07071065902709961, -7.450580596923828e-09, -0.07071071863174438], [0.08660250902175903, -3.725290298461914e-09, -0.05000004172325134], [0.09659254550933838, -1.862645149230957e-09, -0.025881946086883545], [0.10000002384185791, -3.552713678800501e-15, -4.649123752642481e-08], [0.09659260511398315, 1.862645149230957e-09, 0.025881856679916382], [0.08660256862640381, 3.725290298461914e-09, 0.04999995231628418], [0.07071071863174438, 7.450580596923828e-09, 0.07071065902709961], [0.05000007152557373, 7.450580596923828e-09, 0.08660250902175903], [0.025881975889205933, 7.450580596923828e-09, 0.09659254550933838], [-7.450580596923828e-09, 4.440892098500626e-16, 0.10000002384185791], [-9.313225746154785e-09, -0.025881901383399963, 0.09659260511398315], [-1.1175870895385742e-08, -0.050000011920928955, 0.08660250902175903], [-1.4901161193847656e-08, -0.07071065902709961, 0.07071065902709961], [-7.450580596923828e-09, -0.08660256862640381, 0.04999998211860657], [-7.450580596923828e-09, -0.09659260511398315, 0.025881901383399963], [-7.450580596923828e-09, -0.10000002384185791, 7.549793679118011e-09], [-7.450580596923828e-09, -0.09659260511398315, -0.02588188648223877], [0.0, -0.08660256862640381, -0.04999998211860657], [0.0, -0.07071071863174438, -0.07071065902709961], [3.725290298461914e-09, -0.050000011920928955, -0.08660250902175903], [5.587935447692871e-09, -0.02588193118572235, -0.09659260511398315], [7.450577044210149e-09, -3.894143674187944e-08, -0.10000002384185791], [9.313225746154785e-09, 0.025881856679916382, -0.09659260511398315], [1.1175870895385742e-08, 0.04999995231628418, -0.08660256862640381], [1.4901161193847656e-08, 0.07071065902709961, -0.07071071863174438], [7.450580596923828e-09, 0.08660250902175903, -0.05000004172325134], [7.450580596923828e-09, 0.09659254550933838, -0.025881946086883545], [7.450580596923828e-09, 0.10000002384185791, -4.649123752642481e-08], [7.450580596923828e-09, 0.09659260511398315, 0.025881856679916382], [0.0, 0.08660256862640381, 0.04999995231628418], [0.0, 0.07071071863174438, 0.07071065902709961], [-3.725290298461914e-09, 0.05000007152557373, 0.08660250902175903], [-5.587935447692871e-09, 0.025881975889205933, 0.09659254550933838]], "faces": []}
|
||||
mesh.from_pydata(numpy.array(sphere['vertices'])*[boneLength, boneLength, boneLength] , sphere['edges'], sphere['faces'])
|
||||
|
||||
return obj
|
||||
|
||||
def add_driver(obj, posebone, control, target, path, multiply = ''):
|
||||
|
||||
if isinstance(target, tuple):
|
||||
attr = posebone.driver_add(target[0], target[1])
|
||||
else:
|
||||
attr = posebone.driver_add(target)
|
||||
|
||||
var = attr.driver.variables.new()
|
||||
|
||||
var.targets[0].id = obj
|
||||
var.targets[0].data_path = 'pose.bones["' + control +'"].'+ path
|
||||
attr.driver.expression = var.name + multiply
|
||||
|
||||
def dup_values(source, target):
|
||||
if hasattr(source, 'parent'):
|
||||
target.parent = source.parent
|
||||
for prop in dir(source):
|
||||
if not hasattr(target, prop):
|
||||
continue
|
||||
value = getattr(source, prop)
|
||||
if type(value) not in {int, float, bool, str, Vector, Matrix, bpy.types.Object}:
|
||||
continue
|
||||
if '__' in prop[:2] and '__' in prop[-2:]:
|
||||
continue
|
||||
if target.is_property_readonly(prop):
|
||||
continue
|
||||
setattr(target, prop, value)
|
||||
|
||||
return target
|
||||
|
||||
def dup_constraints(source, target):
|
||||
if not source.constraints.items():
|
||||
return
|
||||
for source_con in source.constraints:
|
||||
target_con = target.constraints.new(source_con.type)
|
||||
dup_values(source_con, target_con)
|
||||
|
||||
def add_vis_bone_con(obj, bone_vis_name, bone_wgt_name):
|
||||
bone_vis = obj.pose.bones[bone_vis_name]
|
||||
con = bone_vis.constraints.new('STRETCH_TO')
|
||||
con.target = obj
|
||||
con.subtarget = bone_wgt_name
|
||||
|
||||
return bone_vis
|
||||
|
||||
class target:
|
||||
def __init__(self, bone):
|
||||
self.name = bone.name
|
||||
self.point = tuple(bone.tail)
|
||||
self.ctrl = 'TRGT_' + bone.name
|
||||
if bone.parent:
|
||||
self.parent = bone.parent.name
|
||||
#print('assign parent to target ', self.name, self.ctrl, self.parent)
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.point < other.point
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.point)
|
||||
|
||||
def __eq__(self, other):
|
||||
#if not isinstance(other, type(self)):
|
||||
# return NotImplemented
|
||||
return self.point == other.point
|
||||
|
||||
class parent:
|
||||
def __init__(self, bone):
|
||||
self.name = bone.name
|
||||
self.point = tuple(bone.head)
|
||||
self.ctrl = 'CTRL_' + bone.name
|
||||
if bone.parent:
|
||||
self.parent = bone.parent.name
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.point < other.point
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.point)
|
||||
|
||||
def __eq__(self, other):
|
||||
#if not isinstance(other, type(self)):
|
||||
# return NotImplemented
|
||||
return self.point == other.point
|
||||
|
||||
class constraint_dup:
|
||||
def __init__(self, bone, con):
|
||||
self.name = con.name
|
||||
self.target = con.target
|
||||
self.subtarget = con.subtarget
|
||||
self.bone = bone.name
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.bone)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.bone == other.bone
|
||||
|
||||
def bone_orientation(source, target, value):
|
||||
source.align_orientation(target)
|
||||
x, y, z = source.matrix.to_3x3().col
|
||||
R = (Matrix.Translation(source.head) @ Matrix.Rotation(radians(value), 4, x) @ Matrix.Translation(-source.head))
|
||||
source.transform(R, roll = False)
|
||||
source.align_roll(target.vector)
|
||||
|
||||
def find_ctrl(bone, controls):
|
||||
i = list(controls).index(bone)
|
||||
bone.ctrl = list(controls)[i].ctrl
|
||||
|
||||
return bone.ctrl
|
||||
|
||||
def add_controlers(self, obj, parents, targets):
|
||||
|
||||
#controls = set(parents).union(targets)
|
||||
controls = set(parents + targets)
|
||||
|
||||
#create hierarchy
|
||||
for bone in controls:
|
||||
editbone = obj.data.edit_bones[bone.name]
|
||||
if editbone.parent is None:
|
||||
continue
|
||||
parentnames = [bone.name for bone in parents]
|
||||
#if a target and its parent are part of the hierarchy then linked to its own bone parent
|
||||
if bone in targets and bone not in parents and editbone.parent.name in parentnames:
|
||||
parentbone = parent(editbone)
|
||||
else:
|
||||
parentbone = parent(editbone.parent)
|
||||
|
||||
if parentbone in controls and parentbone != bone:
|
||||
bone.parent = find_ctrl(parentbone, controls)
|
||||
else:
|
||||
bone.parent = editbone.parent.name
|
||||
|
||||
|
||||
edit_bones = obj.data.edit_bones
|
||||
for bone in controls:
|
||||
editbone = edit_bones[bone.name]
|
||||
ctrl = obj.data.edit_bones.new(bone.ctrl)
|
||||
ctrl.head = bone.point
|
||||
ctrl.tail = bone.point
|
||||
ctrl.tail[2] = bone.point[2] + (editbone.length / 3)
|
||||
ctrl.bbone_x = editbone.bbone_x
|
||||
ctrl.bbone_z = editbone.bbone_z
|
||||
ctrl.use_deform = False
|
||||
if self.bone_align:
|
||||
angle = 90 if self.align_90 else 0
|
||||
bone_orientation(ctrl, editbone, angle)
|
||||
if angle == 90:
|
||||
ctrl.align_roll(editbone.vector)
|
||||
else:
|
||||
ctrl.roll = editbone.roll
|
||||
|
||||
#apply hierarchy
|
||||
for bone in parents:
|
||||
editbone = edit_bones[bone.name]
|
||||
ctrl_name = find_ctrl(bone, controls)
|
||||
ctrl = edit_bones[ctrl_name]
|
||||
editbone.parent = ctrl
|
||||
|
||||
for bone in controls:
|
||||
ctrl = edit_bones[bone.ctrl]
|
||||
if hasattr(bone, 'parent'):
|
||||
ctrl.parent = edit_bones[bone.parent]
|
||||
|
||||
return controls
|
||||
|
||||
def pose_bbone_setup(bone, posebone, bbone_group = None):
|
||||
#add the custom shape to the widget bones
|
||||
custom_shape = draw_wgt(bone['length'], posebone)
|
||||
posebone.custom_shape = custom_shape
|
||||
posebone.use_custom_shape_bone_size = False
|
||||
if bbone_group:
|
||||
posebone.bone_group = bbone_group
|
||||
posebone.rotation_mode = 'XZY'
|
||||
posebone.lock_rotation[0] = True
|
||||
posebone.lock_rotation[2] = True
|
||||
|
||||
#####MAIN####
|
||||
class BboneWidgets(bpy.types.Operator):
|
||||
"""Add Bbone widget controls to the selected bones"""
|
||||
bl_idname = "armature.add_bbone_widgets"
|
||||
bl_label = "Add_Bbone_widgets"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.type == 'ARMATURE'
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
|
||||
obj.data.display_type = 'BBONE'
|
||||
|
||||
bones = []
|
||||
parentlayers = [False if i != 24 else True for i in range(32)]
|
||||
wgtlayers = [True if i == 0 else False for i in range(32)]
|
||||
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
obj.data.use_mirror_x = False
|
||||
for bone in obj.data.edit_bones:
|
||||
if not bone.select:
|
||||
continue
|
||||
if bone.bbone_segments == 1:
|
||||
bone.bbone_segments = 10
|
||||
bone.bbone_handle_type_start = 'TANGENT'
|
||||
bone.bbone_handle_type_end = 'TANGENT'
|
||||
bone_name = bone.name
|
||||
#add parent bone to the Bbone widgets
|
||||
parent = obj.data.edit_bones.new('WGTB_parent_'+ bone_name)
|
||||
parent_name = parent.name
|
||||
dup_values(bone, parent)
|
||||
parent.name = parent_name
|
||||
parent.select = False
|
||||
parent.select_head = False
|
||||
parent.select_tail = False
|
||||
|
||||
#change layer of the parent bone
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
parent.layers = parentlayers
|
||||
|
||||
#add bbone widget bones
|
||||
head_widget = obj.data.edit_bones.new('Bhead_'+ bone.name)
|
||||
head_widget.parent = parent
|
||||
#head_widget.head = bone.head
|
||||
head_widget.head = bone.head + (bone.tail - bone.head) * 0.25
|
||||
#head_widget.tail = (bone.tail - bone.head)/10
|
||||
head_widget.length = bone.length * 0.1
|
||||
head_widget.bbone_x = bone.bbone_x
|
||||
head_widget.bbone_z = bone.bbone_z
|
||||
head_widget.align_orientation(bone)
|
||||
head_widget.inherit_scale = 'NONE'
|
||||
head_name = head_widget.name
|
||||
|
||||
tail_widget = obj.data.edit_bones.new('Btail_'+ bone.name)
|
||||
tail_widget.parent = parent
|
||||
#tail_widget.head = bone.tail
|
||||
tail_widget.head = bone.head + (bone.tail - bone.head) * 0.75
|
||||
#tail_widget.tail = bone.tail - (bone.tail - bone.head)/10
|
||||
tail_widget.length = bone.length * 0.1
|
||||
tail_widget.bbone_x = bone.bbone_x
|
||||
tail_widget.bbone_z = bone.bbone_z
|
||||
tail_widget.align_orientation(bone)
|
||||
tail_widget.inherit_scale = 'NONE'
|
||||
tail_name = tail_widget.name
|
||||
|
||||
#add vis bones
|
||||
head_vis = obj.data.edit_bones.new('Bhead_vis_'+ bone.name)
|
||||
head_vis.parent = parent
|
||||
head_vis.head = bone.head
|
||||
head_vis.tail = head_widget.head
|
||||
head_vis.bbone_x = bone.bbone_x*0.1
|
||||
head_vis.bbone_z = bone.bbone_z*0.1
|
||||
|
||||
#head_vis_name = head_vis.name
|
||||
head_vis.hide_select = True
|
||||
head_vis.use_deform = False
|
||||
tail_vis = obj.data.edit_bones.new('Btail_vis_'+ bone.name)
|
||||
tail_vis.parent = parent
|
||||
tail_vis.head = bone.tail
|
||||
tail_vis.tail = tail_widget.head
|
||||
tail_vis.bbone_x = bone.bbone_x*0.1
|
||||
tail_vis.bbone_z = bone.bbone_z*0.1
|
||||
|
||||
#tail_vis_name = tail_vis.name
|
||||
tail_vis.hide_select = True
|
||||
|
||||
tail_vis.use_deform = False
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
tail_widget.layers = wgtlayers
|
||||
head_widget.layers = wgtlayers
|
||||
head_vis.layers = wgtlayers
|
||||
tail_vis.layers = wgtlayers
|
||||
|
||||
bones.append({'name': bone_name, 'parent': parent_name, 'head': head_name, 'tail': tail_name, 'head_vis': head_vis.name, 'tail_vis': tail_vis.name, 'length': bone.length})
|
||||
|
||||
#####POSE MODE#######
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
bone_groups = obj.pose.bone_groups
|
||||
if 'BBone Widgets' not in bone_groups:
|
||||
bbone_group = bone_groups.new(name = 'BBone Widgets')
|
||||
bbone_group.color_set = 'THEME09'
|
||||
else:
|
||||
bbone_group = bone_groups['BBone Widgets']
|
||||
else:
|
||||
bbone_group = None
|
||||
|
||||
for bone in bones:
|
||||
posebone = obj.pose.bones[bone['name']]
|
||||
# Prepare parent bone in pose mode
|
||||
poseparent = obj.pose.bones[bone['parent']]
|
||||
#disable use deform
|
||||
obj.data.bones[bone['parent']].use_deform = False
|
||||
obj.data.bones[bone['head']].use_deform = False
|
||||
obj.data.bones[bone['tail']].use_deform = False
|
||||
|
||||
pose_bbone_setup(bone, obj.pose.bones[bone['head']], bbone_group)
|
||||
pose_bbone_setup(bone, obj.pose.bones[bone['tail']], bbone_group)
|
||||
|
||||
dup_constraints(posebone, poseparent)
|
||||
|
||||
#add all the drivers
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_curveinx', 'location.x')
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_curveinz', 'location.z')
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_easein', 'location.y', '*5/'+ str(bone['length']))
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_rollin', 'rotation_euler.y')
|
||||
add_driver(obj, posebone, bone['head'], ('bbone_scalein', 0), 'scale.x')
|
||||
add_driver(obj, posebone, bone['head'], ('bbone_scalein', 1), 'scale.y')
|
||||
add_driver(obj, posebone, bone['head'], ('bbone_scalein', 2), 'scale.z')
|
||||
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_curveoutx', 'location.x')
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_curveoutz', 'location.z')
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_easeout', 'location.y', '*-5/'+ str(bone['length']))
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_rollout', 'rotation_euler.y')
|
||||
add_driver(obj, posebone, bone['tail'], ('bbone_scaleout', 0), 'scale.x')
|
||||
add_driver(obj, posebone, bone['tail'], ('bbone_scaleout', 1), 'scale.y')
|
||||
add_driver(obj, posebone, bone['tail'], ('bbone_scaleout', 2), 'scale.z')
|
||||
|
||||
#add constraints to visual bones
|
||||
head_vis = add_vis_bone_con(obj, bone['head_vis'], bone['head'])
|
||||
tail_vis = add_vis_bone_con(obj, bone['tail_vis'], bone['tail'])
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
head_vis.bone_group = bbone_group
|
||||
tail_vis.bone_group = bbone_group
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
class ChainControls(bpy.types.Operator):
|
||||
"""Add parent and target controls to the selected bones to create a chain control"""
|
||||
bl_idname = "armature.add_chain_ctrls"
|
||||
bl_label = "Add_Chain_Controls"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
parents: bpy.props.BoolProperty(name = 'Add Parents', description = "Align the controls 90 degrees to the original bones", default = True)
|
||||
targets: bpy.props.BoolProperty(name = 'Add Targets', description = "Align the controls 90 degrees to the original bones", default = True)
|
||||
keep_hierarchy: bpy.props.BoolProperty(name = 'Keep Hierarchy', description = "Keep the controls in the hierarchy of the original bones", default = True)
|
||||
bone_align: bpy.props.BoolProperty(name = 'Align to Bones', description = "Align the controls to the original bones", default = True)
|
||||
align_90: bpy.props.BoolProperty(name = '+90°', description = "Align the controls 90 degrees to the original bones", default = True)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.type == 'ARMATURE'
|
||||
def invoke(self, context, event):
|
||||
#obj = context.object
|
||||
wm = context.window_manager
|
||||
return wm.invoke_props_dialog(self, width = 200)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
row = layout.row()
|
||||
row.label(text = 'Add Control Bones')
|
||||
row = layout.row()
|
||||
row.prop(self, 'parents') #text = 'Size'
|
||||
row.prop(self, 'targets')
|
||||
|
||||
layout.separator()
|
||||
col = layout.column()
|
||||
col.prop(self, 'keep_hierarchy')
|
||||
row = layout.row()
|
||||
row.prop(self, 'bone_align')
|
||||
if self.bone_align:
|
||||
row.prop(self, 'align_90', toggle=True)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
targets = []
|
||||
parents = []
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
edit_bones = bpy.context.selected_editable_bones
|
||||
#create list of parent and target objects
|
||||
for bone in edit_bones:
|
||||
bone.use_connect = False
|
||||
if self.targets:
|
||||
targets.append(target(bone))
|
||||
if self.parents:
|
||||
parents.append(parent(bone))
|
||||
|
||||
controls = add_controlers(self, obj, parents, targets)
|
||||
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
|
||||
#Add the bone group for the ctrls if doesn't exist
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
bone_groups = obj.pose.bone_groups
|
||||
if 'Ctrl Bones' not in bone_groups:
|
||||
ctrl_group = bone_groups.new(name = 'Ctrl Bones')
|
||||
ctrl_group.color_set = 'THEME01'
|
||||
else:
|
||||
ctrl_group = bone_groups['Ctrl Bones']
|
||||
|
||||
for bone in controls:
|
||||
posebone = obj.pose.bones[bone.ctrl]
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
posebone.bone_group = ctrl_group
|
||||
else:
|
||||
posebone.color.palette = 'THEME01'
|
||||
|
||||
if self.targets:
|
||||
for bone in targets:
|
||||
#update from the controls set
|
||||
ctrl = find_ctrl(bone, controls)
|
||||
posebone = obj.pose.bones[bone.name]
|
||||
|
||||
con = posebone.constraints.new('STRETCH_TO')
|
||||
con.target = obj
|
||||
|
||||
con.subtarget = ctrl
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
class MergeRigs(bpy.types.Operator):
|
||||
"""Merge selected rigs to active and keep hierarchy and constraints for shared bones"""
|
||||
bl_idname = "armature.merge"
|
||||
bl_label = "Merge_Rigs"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.type == 'ARMATURE'
|
||||
|
||||
def execute(self, context):
|
||||
target_obj = context.object
|
||||
|
||||
if target_obj.type != 'ARMATURE':
|
||||
return {"CANCELLED"}
|
||||
|
||||
target_bones = set([bone.name for bone in target_obj.data.bones])
|
||||
constraints = []
|
||||
childrens = {}
|
||||
|
||||
#Store children and constraints
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
for obj in bpy.context.selected_objects:
|
||||
if obj.type != 'ARMATURE':
|
||||
continue
|
||||
if obj == target_obj:
|
||||
continue
|
||||
#create a set of all the similiar bones in all the rigs
|
||||
obj_bones = set([bone.name for bone in obj.data.bones])
|
||||
shared_bones = target_bones.intersection(obj_bones)
|
||||
|
||||
#find all the constraints and children
|
||||
for bone in obj.pose.bones:
|
||||
#store all the constraints
|
||||
for con in bone.constraints:
|
||||
if not hasattr(con, 'subtarget'):
|
||||
continue
|
||||
if con.target == obj and con.subtarget in shared_bones:
|
||||
constraints.append(constraint_dup(bone, con))
|
||||
if bone.name in shared_bones:
|
||||
for child in bone.children:
|
||||
if child.name in childrens:
|
||||
continue
|
||||
childrens.update({child.name : bone.name})
|
||||
|
||||
#remove shared bones
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
for obj in bpy.context.selected_objects:
|
||||
if obj.type != 'ARMATURE':
|
||||
continue
|
||||
if obj == target_obj:
|
||||
continue
|
||||
for bone in shared_bones:
|
||||
if bone not in obj.data.edit_bones:
|
||||
continue
|
||||
obj.data.edit_bones.remove(obj.data.edit_bones[bone])
|
||||
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
bpy.ops.object.join()
|
||||
|
||||
#restore constraints
|
||||
for con_dup in constraints:
|
||||
if con_dup.bone in target_bones:
|
||||
continue
|
||||
if con_dup.bone not in target_obj.pose.bones:
|
||||
continue
|
||||
#print('constraint on ',con_dup.bone, con_dup.name)
|
||||
posebone = target_obj.pose.bones[con_dup.bone]
|
||||
if con_dup.name not in posebone.constraints:
|
||||
continue
|
||||
con = posebone.constraints[con_dup.name]
|
||||
con.target = target_obj
|
||||
con.subtarget = con_dup.subtarget
|
||||
|
||||
#reparent all child bones
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
for child, parent in childrens.items():
|
||||
target_obj.data.edit_bones[child].parent = target_obj.data.edit_bones[parent]
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
classes = (MergeRigs,BboneWidgets, ChainControls)
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
# bpy.utils.register_class(BboneWidgets)
|
||||
# bpy.utils.register_class(ChainControls)
|
||||
# bpy.utils.register_class(RiggerToolBox_PT_Panel)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
# bpy.utils.unregister_class(BboneWidgets)
|
||||
# bpy.utils.unregister_class(ChainControls)
|
||||
# bpy.utils.unregister_class(RiggerToolBox_PT_Panel)
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,527 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
bl_info = {
|
||||
"name": "AnimToolBox",
|
||||
"author": "Tal Hershkovich",
|
||||
"version" : (0, 0, 7, 3),
|
||||
"blender" : (3, 2, 0),
|
||||
"location": "View3D - Properties - Animation Panel",
|
||||
"description": "A set of animation tools",
|
||||
"wiki_url": "",
|
||||
"category": "Animation"}
|
||||
|
||||
if "bpy" in locals():
|
||||
import importlib
|
||||
if "Rigger_Toolbox" in locals():
|
||||
importlib.reload(Rigger_Toolbox)
|
||||
if "TempCtrls" in locals():
|
||||
importlib.reload(TempCtrls)
|
||||
if "Tools" in locals():
|
||||
importlib.reload(Tools)
|
||||
if "Display" in locals():
|
||||
importlib.reload(Display)
|
||||
if "emp" in locals():
|
||||
importlib.reload(emp)
|
||||
if "multikey" in locals():
|
||||
importlib.reload(multikey)
|
||||
if "Rigger_Toolbox" in locals():
|
||||
importlib.reload(Rigger_Toolbox)
|
||||
if "ui" in locals():
|
||||
importlib.reload(ui)
|
||||
if "addon_updater_ops" in locals():
|
||||
importlib.reload(addon_updater_ops)
|
||||
|
||||
import bpy
|
||||
from . import addon_updater_ops
|
||||
from . import TempCtrls
|
||||
from . import Rigger_Toolbox
|
||||
from . import Tools
|
||||
from . import Display
|
||||
from . import emp
|
||||
from . import ui
|
||||
from . import multikey
|
||||
from . import Rigger_Toolbox
|
||||
from pathlib import Path
|
||||
from bpy.utils import register_class
|
||||
from bpy.utils import unregister_class
|
||||
from bpy.app.handlers import persistent
|
||||
import os
|
||||
|
||||
|
||||
class TempCtrlsItems(bpy.types.PropertyGroup):
|
||||
#located at context.scene.btc.ctrl_items
|
||||
controlled: bpy.props.PointerProperty(name = "controlled object", description = "rigs and objects that are being controlled", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
controller: bpy.props.PointerProperty(name = "controller object", description = "rigs and objects that are controling", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class TempCtrlsSceneSettings(bpy.types.PropertyGroup):
|
||||
#located at context.scene.btc
|
||||
root: bpy.props.BoolProperty(name = "Root Empty", description = "Add a root to the empties ", default = False, override = {'LIBRARY_OVERRIDABLE'}, update = TempCtrls.root_prop)
|
||||
root_bone: bpy.props.StringProperty(name = "Root bone", description = "Root empty as a root bone ", override = {'LIBRARY_OVERRIDABLE'}, update = TempCtrls.root_update)
|
||||
root_object: bpy.props.PointerProperty(name = "Root object", description = "Root empty as a root object ", update = TempCtrls.root_update, type = bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
ctrl_type: bpy.props.EnumProperty(name = 'Controllers', description="Select empties or a bone with a new rig to bake to", items = [('BONE', 'Bone','Bake to bones','BONE_DATA', 0), ('EMPTY', 'Empty', 'Bake to empties', 'EMPTY_ARROWS', 1)])
|
||||
ctrl_items: bpy.props.CollectionProperty(type = TempCtrlsItems, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
|
||||
bake_range_type: bpy.props.EnumProperty(name = 'Bake Range', description="Use either scene, actions length or custom frame range", default = 'KEYFRAMES', update= TempCtrls.update_range_type,
|
||||
items = [('SCENE', 'Scene Range', 'Bake to the scene range'), ('KEYFRAMES', 'Keyframes Range', 'Bake all the keyframes in the layers'), ('CUSTOM', 'Custom', 'Enter a custom frame range')], override = {'LIBRARY_OVERRIDABLE'})
|
||||
bake_range: bpy.props.IntVectorProperty(name='Frame Range', description='Bake to a custom frame range', size = 2, update= TempCtrls.update_bake_range)
|
||||
bake_layers: bpy.props.BoolProperty(name = "Bake Layers", description = "Use keyframes from all the layers to include in the bake", default = False)
|
||||
|
||||
target: bpy.props.EnumProperty(name = 'Affect', description="Cleanup created constraints and empties", default = 1,
|
||||
items = [('ALL', 'All Ctrl Rigs','Bake to all Ctrl Rigs', 0),
|
||||
('SELECTED', 'Selected Chains','Bake to only selected chain controlls', 1),
|
||||
('RELATIVE', 'Relative Ctrls Rig','Bake to the Relative Control rigs', 2)])
|
||||
# ('CONSTRAINTS', 'Constraints', 'Clean all the bone constraints', 3),
|
||||
# ('CONTROLLERS', 'Controllers', 'Remove all the baked empties', 4)])
|
||||
|
||||
selection: bpy.props.EnumProperty(name = 'Select', description="Select all controls, original bones or their relative", default = 'CONTROLLERS',
|
||||
items = [('RELATIVE_CTRLS', 'Relative Ctrls','Select the Relative controller to your current selection', 0),
|
||||
('RELATIVE_CONSTRAINED', 'Relative Constrained','Select the Relative original constrained bone to your current selection', 1),
|
||||
('CONTROLLERS', 'All Ctrls', 'Select all the controller bones or empties', 2), ('CONSTRAINED', 'All Constrained', 'Select all the original constrained bones', 3)])
|
||||
|
||||
#smartbake setting
|
||||
linksettings: bpy.props.BoolProperty(name = "Link Settings", description = "Link Settings", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bakesettings: bpy.props.BoolProperty(name = "bake settings", description = "bake settings", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
cleansettings: bpy.props.BoolProperty(name = "clean settings", description = "clean settings", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
smartbake: bpy.props.BoolProperty(name = "Smart Bake", description = "Keep Original Frame count", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
inbetween_keyframes: bpy.props.IntProperty(name = "Inbetween Keyframes", description = "Add inbetween keyframes", default = 0, override = {'LIBRARY_OVERRIDABLE'})
|
||||
from_origin: bpy.props.BoolProperty(name = "From Origin", description = "Use Keyframes from Original Bone", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
from_ctrl: bpy.props.BoolProperty(name = "From Controller", description = "Use Keyframes from Controller Bone", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
clean_ctrls: bpy.props.BoolProperty(name = "Remove Ctrls", description = "Remove Controls", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
clean_constraints: bpy.props.BoolProperty(name = "Remove Constraints", description = "Remove Constraints", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
rebake_to_org: bpy.props.BoolProperty(name = "ReBake connections to original bones", description = "ReBake ctrls from connected chains current anim to the original bones", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
link_to: bpy.props.EnumProperty(name = 'Link to Chain', description="Link to begining of an active chain or the tip of the chain", default = 1,
|
||||
items = [('BASE', 'Base','Link to the base of the active chain', 0), ('TIP', 'Tip', 'Link to the tip of the chain', 1)])
|
||||
# link_from: bpy.props.EnumProperty(name = 'Link to Chain', description="Link to begining of an active chain or the tip of the chain", default = 0,
|
||||
# items = [('BASE', 'Base','Link to the base of the active chain', 0), ('TIP', 'Tip', 'Link to the tip of the chain', 1)])
|
||||
|
||||
shape_size: bpy.props.FloatProperty(name='Size', description="Multiple factor for the shape size of the temp controls", update = TempCtrls.tempctrl_shapesize, min = 0.001, default = 1.5, override = {'LIBRARY_OVERRIDABLE'})#
|
||||
shape_type: bpy.props.EnumProperty(name = 'Shape Type', description="Display type for the controls", items = TempCtrls.ctrl_shape_items, update = TempCtrls.tempctrl_shape_type)
|
||||
color_set: bpy.props.EnumProperty(name="Bone Color Set", description="Choose a bone color set", items = TempCtrls.get_bone_color_sets, update = TempCtrls.update_bone_color, default = 9)
|
||||
|
||||
add_ik_ctrl: bpy.props.BoolProperty(name = 'Add an Extra IK Ctrl Bone', description = "Adds an extra bone ctrl as the ik ctrl", default = False, update = TempCtrls.add_ik_prop)
|
||||
pole_target: bpy.props.BoolProperty(name = 'Add Pole Target', description = "Adding Pole Target to the IK Chain", default = True, update = TempCtrls.pole_prop)
|
||||
pole_offset: bpy.props.FloatProperty(name="Offset", description="Offset the bone in the axis direction", default=1.0, update = TempCtrls.pole_offset)
|
||||
child: bpy.props.BoolProperty(name = 'Add extra child Ctrls', description = "Add an child control for an overlay control", default = False, update = TempCtrls.child_prop)
|
||||
orientation: bpy.props.BoolProperty(name = 'Use World Space Orientation', description = "Orient the bones to world space instead of to the original bones", default = True)
|
||||
|
||||
# enabled: bpy.props.BoolProperty(name = 'Switch On / Off', description = "Enabling and Disabling Temp Ctrls influence", default = True)
|
||||
|
||||
class TempCtrlsBoneSettings(bpy.types.PropertyGroup):
|
||||
#located at obj.pose.bones[##].btc
|
||||
root: bpy.props.BoolProperty(name = "Root Bone", description = "Bone is marked as the root bone", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
child: bpy.props.BoolProperty(name = "Child Bone", description = "Bone is marked as a child bone inside the setup", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
org_id: bpy.props.IntProperty(name = "Originate ID", description = "ID number of the bone the ctrl originates from", override = {'LIBRARY_OVERRIDABLE'})
|
||||
setup_id: bpy.props.IntProperty(name = "Setup ID", description = "ID number of the current chain setup", override = {'LIBRARY_OVERRIDABLE'})
|
||||
setup: bpy.props.EnumProperty(name = 'Setup Type', description="Describes what kind of setup the bone is part of", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [('NONE', 'No Setup','No Setup Applied', 0),
|
||||
('WORLDSPACE', 'World Space Ctrl','World Space Ctrl setup', 1),
|
||||
('TEMPFK', 'Temporary FK setup','Temporary FK chain setup', 2),
|
||||
('TEMPFK_FLIP', 'Temporary flipped FK setup','Temporary flipped FK chain setup', 3),
|
||||
('TEMPIK', 'Temporary IK setup','Temporary IK setup', 4),
|
||||
('POLE', 'Temporary IK Pole setup','Temporary IK Pole', 5),
|
||||
('PARENTCTRL', 'Parent Ctrl from cursor setup','Parent Ctrl from cursor setup', 6),
|
||||
('ROOT', 'Root', 'Root Ctrl for all the setups', 7),
|
||||
('EMPTY', 'Root', 'Root Ctrl for all the setups', 8),
|
||||
('TRACK_TO', 'Track To','World Space Track to Ctrl setup', 9),
|
||||
('TRACK_TO_EMPTY', 'Track To Empty','World Space Track to Empty Ctrl setup', 10)])
|
||||
|
||||
#using org mostly to decide if it needs a custom shape
|
||||
org: bpy.props.EnumProperty(name = 'Org Type', description="Describes what if the function of the bone", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [('CTRL', 'Controller Bone','Controller Bone', 0),
|
||||
('ORG', 'Original Bone','Original Bone', 1),
|
||||
('MCH', 'Mechanical Bone','Mechanical Bone', 2),
|
||||
('NONE', 'Nothing applied','Nothing applied', 3)])
|
||||
|
||||
shape: bpy.props.BoolProperty(name = "Apply shape", description = "Mark if the bone needs a shape", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class TempCtrlsObjectSetups(bpy.types.PropertyGroup):
|
||||
#located at obj.animtoolbox.ctrl_setups
|
||||
#name: using string of the id
|
||||
setup: bpy.props.EnumProperty(name = 'Setup Type', description="Describes what kind of setup the bone is part of",
|
||||
items = [('NONE', 'No Setup','No Setup Applied', 0),
|
||||
('WORLDSPACE', 'World Space Ctrl','World Space Ctrl setup', 1),
|
||||
('TEMPFK', 'Temporary FK setup','Temporary FK chain setup', 2),
|
||||
('TEMPFK_FLIP', 'Temporary flipped FK setup','Temporary flipped FK chain setup', 3),
|
||||
('TEMPIK', 'Temporary IK setup','Temporary IK setup', 4),
|
||||
('PARENTCTRL', 'Parent Ctrl from cursor setup','Parent Ctrl from cursor setup', 5),
|
||||
('ROOT', 'Root', 'Root Ctrl for all the setups', 6),
|
||||
('EMPTY', 'Root', 'Root Ctrl for all the setups', 8),
|
||||
('TRACK_TO', 'Track To','World Space Track to Ctrl setup', 9),
|
||||
('TRACK_TO_EMPTY', 'Track To Empty','World Space Track to Empty Ctrl setup', 10),
|
||||
])
|
||||
|
||||
class MultikeyProperties(bpy.types.PropertyGroup):
|
||||
|
||||
selectedbones: bpy.props.BoolProperty(name="Selected Bones", description="Affect only selected bones", default=True, options={'HIDDEN'})
|
||||
handletype: bpy.props.BoolProperty(name="Keep handle types", description="Keep handle types", default=False, options={'HIDDEN'})
|
||||
scale: bpy.props.FloatProperty(name="Scale Factor", description="Scale percentage of the average value", default=1.0, update = multikey.scale_value)
|
||||
randomness: bpy.props.FloatProperty(name="Randomness", description="Random Threshold of keyframes", default=0.1, min=0.0, max = 1.0, update = multikey.random_value)
|
||||
|
||||
class AnimToolBoxObjectSettings(bpy.types.PropertyGroup):
|
||||
|
||||
controlled: bpy.props.PointerProperty(name = 'Controlled Rig', description="Adding the rig object that is being controlled by the current object", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
controller: bpy.props.PointerProperty(name = 'Controller Rig', description="Adding the rig object that is used as the temp control object", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
ctrl_setups: bpy.props.CollectionProperty(type = TempCtrlsObjectSetups, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
ctrls_enabled: bpy.props.BoolProperty(name = 'Temp Ctrls Switch', description = "Enabling and Disabling Temp Ctrls influence", default = True)
|
||||
# influence: bpy.props.FloatProperty(name = "Influence Slider for the Temp Ctrls", description = "Switching the influence slider for the temp ctrls", default = 1, min = 0.0, max = 1.0)
|
||||
|
||||
#Used for Bake to Empties
|
||||
# org_id: bpy.props.IntProperty(name = "Originate ID", description = "ID number of the bone the ctrl originates from", override = {'LIBRARY_OVERRIDABLE'})
|
||||
setup_id: bpy.props.IntProperty(name = "Setup ID", description = "ID number of the current chain setup", override = {'LIBRARY_OVERRIDABLE'})
|
||||
root: bpy.props.BoolProperty(name = "Root Empty", description = "Empty is marked as the root ctrl", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
child: bpy.props.BoolProperty(name = "Child Empty", description = "Empty is marked as a child bone inside the setup", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
keyframes_offset: bpy.props.FloatProperty(name = "Keyframes Offset", description = "Interactive slider to offset keyframes back and forth ", default = 0)
|
||||
|
||||
class IsolatedRigs(bpy.types.PropertyGroup):
|
||||
|
||||
hidden: bpy.props.PointerProperty(name = "Hidden Rigs", description = "List of Rigs that are hidden during pose mode isolation", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
selected: bpy.props.PointerProperty(name = "Selected Rigs", description = "List of Rigs that are hidden during pose mode isolation", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class AnimToolBoxUILayout(bpy.types.PropertyGroup):
|
||||
'''Layout properties for the UI'''
|
||||
quick_menu: bpy.props.BoolProperty(name = "Use Quick Menu", description = "Opens header menu with only icon", default = False)
|
||||
copy_paste_matrix: bpy.props.BoolProperty(name = "Copy Matrix Menu", description = "Opens the menu for copy paste matrices", default = True)
|
||||
copy_paste_world: bpy.props.BoolProperty(name = "Copy Paste World Matrix", description = "Copy and Paste the World Matrix", default = False, update = Tools.copy_paste_world_update)
|
||||
copy_paste_relative: bpy.props.BoolProperty(name = "Copy Paste Relative Matrix", description = "Copy and Paste the Matrix relative to the active bone", default = False, update = Tools.copy_paste_relative_update)
|
||||
Inbetweens: bpy.props.BoolProperty(name = "Blendings/Inbetweens", description = "Opens the menu for Inbetweens", default = True)
|
||||
gizmo_size: bpy.props.BoolProperty(name = "Gizmo size", description = "Change the Gizmo size using alt +/- hotkeys", default = False)
|
||||
# temp_ctrls: bpy.props.BoolProperty(name = "Temp Ctrls", description = "Open Temp Ctrls", default = False)
|
||||
temp_ctrls_switch: bpy.props.BoolProperty(name = "Temp Ctrls Switch", description = "Temp Ctrls Switch", default = True)
|
||||
temp_ctrls_shapes: bpy.props.BoolProperty(name = "Temp Ctrls Shapes", description = "Temp Ctrls Shapes", default = True)
|
||||
|
||||
markers_retimer: bpy.props.BoolProperty(name = "Marker Retimer", description = "Flag when marker retimer turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
relative_cursor: bpy.props.BoolProperty(name = "Relative Cursor Mode", description = "Cursor moves relative to the selection", default = False)
|
||||
|
||||
is_dragging: bpy.props.BoolProperty(default = False)
|
||||
#using Blending sliders in the window manager to avoid undo issues with modal operators
|
||||
inbetween_worldmatrix: bpy.props.FloatProperty(name='Inbetween World Matrix', description="Adds an inbetween of the World Matrix to the Layer's neighbor keyframes", soft_min = -1, soft_max = 1, default=0.0, update = Tools.add_inbetween_worldmatrix, override = {'LIBRARY_OVERRIDABLE'})
|
||||
blend_mirror: bpy.props.FloatProperty(name='Blend Mirror', description="Blend into the mirrored pose", soft_min = 0, soft_max = 1, default=0, step = 1, update = Tools.blend_to_mirror, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
multikey: bpy.props.PointerProperty(type = MultikeyProperties, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class AnimToolBoxGlobalSettings(bpy.types.PropertyGroup):
|
||||
#context.scene.animtoolbox
|
||||
marker_frame_range: bpy.props.BoolProperty(name = "Marker Frame Range", description = "Flag when marker frame range turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bake_frame_range: bpy.props.BoolProperty(name = "Bake Frame Range", description = "Flag when marker bake range turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
# markers_retimer: bpy.props.BoolProperty(name = "Marker Retimer", description = "Flag when marker retimer turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
keyframes_offset: bpy.props.FloatProperty(name = "Keyframes Offset", description = "Interactive slider to offset keyframes back and forth ", soft_max = 2, soft_min = -2, default = 0, update = Tools.keyframes_offset_slider)
|
||||
rotation_mode: bpy.props.EnumProperty(name = 'Rotation Mode', description="Describes what kind of setup the bone is part of", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [('QUATERNION', 'Quaternion','Quaternion Rotation Order - No Gimbal Lock', 0),
|
||||
('XYZ', 'XYZ', 'XYZ Rotation Order', 1), ('XZY', 'XZY','XZY Rotation Order', 2),
|
||||
('YXZ', 'YXZ','YXZ Rotation Order', 3), ('YZX', 'YZX', 'YZX Rotation Order', 4),
|
||||
('ZXY', 'ZXY', 'ZXY Rotation Order', 5), ('ZYX', 'ZYX', 'ZYX Rotation Order', 6),
|
||||
('AXIS_ANGLE', 'AXIS_ANGLE', 'Axis Angle Rotation Order', 7)])
|
||||
|
||||
isolate_pose_mode: bpy.props.BoolProperty(name = "Isolate rig in pose mode", description = "Isolates the rig during pose mode, rigs in object mode are hidden", default = False)
|
||||
active_obj: bpy.props.PointerProperty(name = "Active Object", description = "Current Active Object", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
isolated: bpy.props.CollectionProperty(type = IsolatedRigs, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
|
||||
#Blendings
|
||||
inbetweener : bpy.props.FloatProperty(name='Inbetween Keyframe', description="Adds an inbetween Keyframe between the Layer's neighbor keyframes", soft_min = -1, soft_max = 1, default=0.0, options = set(), update = Tools.add_inbetween_key, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
motion_path: bpy.props.BoolProperty(name = "Motion Path", description = "Flag when Motion Path is on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_settings: bpy.props.BoolProperty(name = "Motion Path Settings", description = "Open the settings Menu", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_keyframe_scale: bpy.props.FloatProperty(name = "Scale Selecgted Keyframes Bounding Box", description = "Change the scale of the bounding box around the selected keyframes ", default = 0.1, step = 0.1, precision = 3)
|
||||
mp_color_before: bpy.props.FloatVectorProperty(name="Motion Path Before Color", subtype='COLOR', default=(1.0, 0.0, 0.0), min=0.0, max=1.0, description="Motion path color before the current frame")
|
||||
mp_color_after: bpy.props.FloatVectorProperty(name="Motion Path After Color", subtype='COLOR', default=(0.0, 1.0, 0.0), min=0.0, max=1.0, description="Motion path color before the current frame")
|
||||
mp_infront: bpy.props.BoolProperty(name = "Motion Path In Front", description = "Display motion path in front of all the objects", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_points: bpy.props.BoolProperty(name = "Motion Path Points", description = "Display motion path points", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_lines: bpy.props.BoolProperty(name = "Motion Path Lines", description = "Display motion path lines", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_handles: bpy.props.BoolProperty(name = "Motion Path Handles", description = "Display motion path handles on keyframe selection", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_display_frames: bpy.props.BoolProperty(name = "Frame Numbers", description = "Display frame numbers on all the keyframes", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_handle_types: bpy.props.EnumProperty(name = 'Set Keyframe Handle Type', description="Set handle type for selected keyframes", default = 'AUTO', update = emp.update_handle_type_prop,
|
||||
items = [('FREE', 'Free', 'Free', 'HANDLE_FREE', 0),
|
||||
('ALIGNED','Aligned', 'Aligned', 'HANDLE_ALIGNED', 1),
|
||||
('VECTOR', 'Vector', 'Vector', 'HANDLE_VECTOR', 2),
|
||||
('AUTO','Automatic', 'Automatic', 'HANDLE_AUTO', 3),
|
||||
('AUTO_CLAMPED','Auto Clamped', 'Auto Clamped', 'HANDLE_AUTOCLAMPED', 4)])
|
||||
|
||||
mp_interpolation: bpy.props.EnumProperty(name = 'Set Interpolation', description="Set Keyframe Interpolation", default = 'BEZIER', update = emp.update_interpolation_prop,
|
||||
items = [('BEZIER', 'Bezier', 'Bezier', 'IPO_BEZIER', 0),
|
||||
('LINEAR','Linear', 'Linear', 'IPO_LINEAR', 1),
|
||||
('CONSTANT', 'Constant', 'Constant', 'IPO_CONSTANT', 2)])
|
||||
|
||||
mp_frame_range: bpy.props.EnumProperty(name = 'Frame Range', description="Type of Frame Range", default = 'SCENE', #update = emp.mp_frame_range_update,
|
||||
items = [('KEYS_ALL', 'All_Keys','Use the Scene Frame Length for the Range', 0),
|
||||
('SCENE', 'Scene','Use the Scene Frame Length for the Range', 1),
|
||||
('MANUAL', 'Manual','Custom Frame range using numerical input or the markers frame ranger', 2),
|
||||
('AROUND', 'Around Frames','Show only around the current frame', 3)])
|
||||
mp_before: bpy.props.IntProperty(name = "Before", description = "Show the frames Before the current frame", min = 0, default = 10)
|
||||
mp_after: bpy.props.IntProperty(name = "After", description = "Show the frames After the current frame", min = 0, default = 10)
|
||||
selected_keyframes: bpy.props.StringProperty(name="Selected Keyframes", description="Serialized representation of selected keyframes")
|
||||
|
||||
gizmo_size: bpy.props.IntProperty(name = "Add to Gizmo Size", description = "Addition to Gizmo Size", max = 100, min = -100, default = 10)
|
||||
|
||||
#Copy/Pase Matrix
|
||||
range_type: bpy.props.EnumProperty(name = 'Paste to Frames', description="Paste to current frame or a range of frames.", update = Tools.bake_range_type,
|
||||
items = [('CURRENT', 'Current Frame','Paste Matrix to only current frame', 0),
|
||||
('SELECTED', 'Selected Keyframe','Paste Matrix to only selected keyframes', 1),
|
||||
('RANGE', 'Frame Range','Paste Matrix to a Frame Range', 2)])
|
||||
bake_frame_start: bpy.props.IntProperty(name = "Bake Frame Start", description = "Define the start frame to paste the matrix", min = 0, update = Tools.bake_frame_start_limit)
|
||||
bake_frame_end: bpy.props.IntProperty(name = "Bake Frame End", description = "Define the end frame to paste the matrix", min = 0, update = Tools.bake_frame_end_limit)
|
||||
|
||||
filter_location: bpy.props.BoolVectorProperty(name="Location", description="Filter Location properties", default=(False, False, False), size = 3, options={'HIDDEN'}, update = Tools.filter_name_update)
|
||||
filter_rotation: bpy.props.BoolVectorProperty(name="Rotation", description="Filter Rotation properties", default=(False, False, False, False), size = 4, options={'HIDDEN'}, update = Tools.filter_name_update)
|
||||
filter_scale: bpy.props.BoolVectorProperty(name="Scale", description="Filter Scale properties", default=(False, False, False), size = 3, options={'HIDDEN'}, update = Tools.filter_name_update)
|
||||
#The name displayed on the filter button
|
||||
filter_name: bpy.props.StringProperty(name="Filter Name", description="Change the name of the button while chaging the filter options", default= "", options={'HIDDEN'})
|
||||
filter_custom_props: bpy.props.BoolProperty(name = "Filter Custom Properties", description = "Filter custom properties", default = False)
|
||||
filter_keyframes: bpy.props.BoolProperty(name = "Filter Aelected Keyframes", description = "Filter selected keyframes for specific tools", default = False)
|
||||
|
||||
col_vis: bpy.props.BoolProperty(name = "Animated collections visibility", description = "Display if animated collections are turned on or off", default = False)
|
||||
|
||||
@addon_updater_ops.make_annotations
|
||||
class AnimToolBoxPreferences(bpy.types.AddonPreferences):
|
||||
# this must match the addon name, use '__package__'
|
||||
# when defining this in a submodule of a python package.
|
||||
bl_idname = __package__
|
||||
|
||||
category: bpy.props.StringProperty(
|
||||
name="Tab Category",
|
||||
description="Choose a name for the category of the panel",
|
||||
default="Animation",
|
||||
update=ui.update_panel
|
||||
)
|
||||
|
||||
quick_menu: bpy.props.BoolProperty(name = "Use Quick Menu", description = "Opens header menu with only icon", default = False)
|
||||
riggertoolbox: bpy.props.BoolProperty(name = "RiggerToolBox", description = "Include RiggerToolbox (experimental)", default = False, update = ui.add_riggertoolbox)
|
||||
multikey: bpy.props.BoolProperty(name = "Multikey", description = "Include Multikey for adju\sting multiply keyframes", default = False, update = ui.add_multikey)
|
||||
|
||||
#Temp Ctrls properties
|
||||
in_front: bpy.props.BoolProperty(name = "Always In Front", description = "Set Temp Ctrls to be always in front", default = True)
|
||||
clear_setup : bpy.props.BoolProperty(name = "Clear Selection Before Creating New Temp Ctrls", description = "Clear old setup when adding Temp ctrls to an existing chain", default = False)
|
||||
|
||||
#Editable motion path
|
||||
keyframes_range: bpy.props.IntProperty(name = "Keyframe Range", description = "The range of distance from the keyframes while hovering over them", min = 5, max = 100, default = 15)
|
||||
|
||||
# addon updater preferences from `__init__`, be sure to copy all of them
|
||||
auto_check_update: bpy.props.BoolProperty(
|
||||
name = "Auto-check for Update",
|
||||
description = "If enabled, auto-check for updates using an interval",
|
||||
default = True,
|
||||
)
|
||||
|
||||
updater_interval_months: bpy.props.IntProperty(
|
||||
name='Months',
|
||||
description = "Number of months between checking for updates",
|
||||
default=0,
|
||||
min=0
|
||||
)
|
||||
updater_interval_days: bpy.props.IntProperty(
|
||||
name='Days',
|
||||
description = "Number of days between checking for updates",
|
||||
default=7,
|
||||
min=0,
|
||||
|
||||
)
|
||||
updater_interval_hours: bpy.props.IntProperty(
|
||||
name='Hours',
|
||||
description = "Number of hours between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=23
|
||||
)
|
||||
updater_interval_minutes: bpy.props.IntProperty(
|
||||
name='Minutes',
|
||||
description = "Number of minutes between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=59
|
||||
)
|
||||
|
||||
#Draw the UI in the preferences
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
addon_updater_ops.update_settings_ui(self, context)
|
||||
|
||||
row = layout.row()
|
||||
col = row.column()
|
||||
|
||||
col.label(text="Tab Category:")
|
||||
col.prop(self, "category", text="")
|
||||
|
||||
layout.separator()
|
||||
col = layout.column()
|
||||
col.prop(self, "quick_menu", text="Use Quick Icons Menu")
|
||||
|
||||
layout.separator()
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
row.label(text = 'Temp Ctrls: ')
|
||||
row = box.row()
|
||||
row.prop(self, 'clear_setup')
|
||||
row.prop(self, 'in_front')
|
||||
|
||||
layout.separator()
|
||||
col = layout.column()
|
||||
col.label(text = 'Include Extras: ')
|
||||
row = layout.row()
|
||||
row.prop(self, "multikey", text="Multikey - Edit Multiply keyframes")
|
||||
row.prop(self, "riggertoolbox", text="RiggerToolBox (Experimental)")
|
||||
|
||||
@persistent
|
||||
def loadanimtoolbox_pre(self, context):
|
||||
scene = bpy.context.scene
|
||||
dns = bpy.app.driver_namespace
|
||||
if scene.animtoolbox.bake_frame_range:
|
||||
scene.animtoolbox.bake_frame_range = False
|
||||
|
||||
if scene.animtoolbox.motion_path:
|
||||
scene.animtoolbox.motion_path = False
|
||||
if 'mp_dh' in dns:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(dns['mp_dh'], 'WINDOW')
|
||||
bpy.app.driver_namespace.pop('mp_dh')
|
||||
|
||||
if 'markers_retimer_dh' in dns:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(dns['markers_retimer_dh'], 'WINDOW')
|
||||
bpy.app.driver_namespace.pop('markers_retimer_dh')
|
||||
|
||||
#remove the motion path app handler if it's still inside
|
||||
if emp.mp_value_update in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.remove(emp.mp_value_update)
|
||||
if emp.mp_frame_change in bpy.app.handlers.frame_change_post:
|
||||
bpy.app.handlers.frame_change_post.remove(emp.mp_frame_change)
|
||||
if emp.mp_undo_update in bpy.app.handlers.undo_pre:
|
||||
bpy.app.handlers.undo_pre.remove(emp.mp_undo_update)
|
||||
|
||||
@persistent
|
||||
def loadanimtoolbox_post(self, context):
|
||||
scene = bpy.context.scene
|
||||
dns = bpy.app.driver_namespace
|
||||
if scene.animtoolbox.isolate_pose_mode:
|
||||
if Display.isolate_pose_mode not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(Display.isolate_pose_mode)
|
||||
|
||||
if scene.animtoolbox.motion_path:
|
||||
scene.animtoolbox.motion_path = False
|
||||
if 'mp_dh' in dns:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(dns['mp_dh'], 'WINDOW')
|
||||
bpy.app.driver_namespace.pop('mp_dh')
|
||||
|
||||
Tools.selection_order(self, context)
|
||||
|
||||
classes = (TempCtrlsItems, TempCtrlsObjectSetups, TempCtrlsSceneSettings,TempCtrlsBoneSettings, MultikeyProperties, IsolatedRigs,
|
||||
AnimToolBoxObjectSettings, AnimToolBoxUILayout, AnimToolBoxGlobalSettings) + ui.classes
|
||||
|
||||
addon_keymaps = []
|
||||
|
||||
def register():
|
||||
# Note that preview collections returned by bpy.utils.previews
|
||||
# are regular py objects - you can use them to store custom data.
|
||||
|
||||
addon_updater_ops.register(bl_info)
|
||||
register_class(AnimToolBoxPreferences)
|
||||
addon_updater_ops.make_annotations(AnimToolBoxPreferences) # to avoid blender 2.8 warnings
|
||||
TempCtrls.register()
|
||||
Tools.register()
|
||||
Display.register()
|
||||
emp.register()
|
||||
|
||||
ui.register_custom_icon()
|
||||
|
||||
for cls in classes:
|
||||
# print(cls)
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.Scene.btc = bpy.props.PointerProperty(type = TempCtrlsSceneSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.PoseBone.btc = bpy.props.PointerProperty(type = TempCtrlsBoneSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Object.animtoolbox = bpy.props.PointerProperty(type = AnimToolBoxObjectSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Scene.animtoolbox = bpy.props.PointerProperty(type = AnimToolBoxGlobalSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.WindowManager.atb_ui = bpy.props.PointerProperty(type = AnimToolBoxUILayout, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
ui.update_panel(None, bpy.context)
|
||||
ui.add_multikey(None, bpy.context)
|
||||
ui.add_riggertoolbox(None, bpy.context)
|
||||
|
||||
if loadanimtoolbox_pre not in bpy.app.handlers.load_pre:
|
||||
bpy.app.handlers.load_pre.append(loadanimtoolbox_pre)
|
||||
if loadanimtoolbox_post not in bpy.app.handlers.load_post:
|
||||
bpy.app.handlers.load_post.append(loadanimtoolbox_post)
|
||||
|
||||
if Tools.selection_order not in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.append(Tools.selection_order)
|
||||
|
||||
#Make sure TAB hotkey in the NLA goes into full stack mode
|
||||
wm = bpy.context.window_manager
|
||||
kc = wm.keyconfigs.addon
|
||||
km = kc.keymaps.new(name= '3D View', space_type= 'VIEW_3D')
|
||||
if 'view3d.gizmo_size_up' not in km.keymap_items:
|
||||
kmi = km.keymap_items.new('view3d.gizmo_size_up', type= 'NUMPAD_PLUS', value= 'PRESS', alt = True, repeat = True)
|
||||
addon_keymaps.append((km, kmi))
|
||||
if 'view3d.gizmo_size_down' not in km.keymap_items:
|
||||
kmi = km.keymap_items.new('view3d.gizmo_size_down', type= 'NUMPAD_MINUS', value= 'PRESS', alt = True, repeat = True)
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
#Add Tools to the Toolbar
|
||||
bpy.utils.register_tool(ui.KeyframeOffsetTool, separator=True)
|
||||
|
||||
#Add tools to the menu
|
||||
bpy.types.VIEW3D_MT_editor_menus.append(ui.draw_menu)
|
||||
|
||||
def unregister():
|
||||
for pcoll in ui.preview_collections.values():
|
||||
bpy.utils.previews.remove(pcoll)
|
||||
ui.preview_collections.clear()
|
||||
|
||||
#addon_updater_ops.unregister()
|
||||
addon_updater_ops.unregister()
|
||||
unregister_class(AnimToolBoxPreferences)
|
||||
|
||||
TempCtrls.unregister()
|
||||
# Rigger_Toolbox.unregister()
|
||||
Tools.unregister()
|
||||
Display.unregister()
|
||||
emp.unregister()
|
||||
|
||||
ui.add_multikey(None, bpy.context)
|
||||
ui.add_riggertoolbox(None, bpy.context)
|
||||
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
|
||||
bpy.utils.unregister_tool(ui.KeyframeOffsetTool)
|
||||
|
||||
#Remove the header menu ui
|
||||
bpy.types.VIEW3D_MT_editor_menus.remove(ui.draw_menu)
|
||||
|
||||
del bpy.types.Scene.btc
|
||||
# del bpy.types.Bone.btc
|
||||
del bpy.types.Object.animtoolbox
|
||||
del bpy.types.Scene.animtoolbox
|
||||
if hasattr(bpy.types.Object, 'keyframes_offset'):
|
||||
del bpy.types.Object.keyframes_offset
|
||||
if hasattr(bpy.types.PoseBone, 'keyframes_offset'):
|
||||
del bpy.types.PoseBone.keyframes_offset
|
||||
|
||||
if loadanimtoolbox_pre in bpy.app.handlers.load_pre:
|
||||
bpy.app.handlers.load_pre.remove(loadanimtoolbox_pre)
|
||||
if loadanimtoolbox_post in bpy.app.handlers.load_post:
|
||||
bpy.app.handlers.load_post.remove(loadanimtoolbox_post)
|
||||
if Tools.selection_order in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.remove(Tools.selection_order)
|
||||
|
||||
for km, kmi in addon_keymaps:
|
||||
km.keymap_items.remove(kmi)
|
||||
addon_keymaps.clear()
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"last_check": "2025-06-19 15:30:39.178174",
|
||||
"backup_date": "June-19-2025",
|
||||
"update_ready": false,
|
||||
"ignore": false,
|
||||
"just_restored": false,
|
||||
"just_updated": false,
|
||||
"version_text": {}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
|
||||
class GizmoSizeUp(bpy.types.Operator):
|
||||
"""Share keyframes between all the selected objects and bones"""
|
||||
bl_idname = "view3d.gizmo_size_up"
|
||||
bl_label = "Gizmo_Size_Up"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
context.preferences.view.gizmo_size += context.scene.animtoolbox.gizmo_size
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
class GizmoSizeDown(bpy.types.Operator):
|
||||
"""Share keyframes between all the selected objects and bones"""
|
||||
bl_idname = "view3d.gizmo_size_down"
|
||||
bl_label = "Gizmo_Size_Down"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
context.preferences.view.gizmo_size -= context.scene.animtoolbox.gizmo_size
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
########################################################################################################################
|
||||
|
||||
def clear_isolate_pose_mode(scene):
|
||||
if not len(scene.animtoolbox.isolated):
|
||||
return
|
||||
for obj in scene.animtoolbox.isolated:
|
||||
if not obj.hidden:
|
||||
continue
|
||||
obj.hidden.hide_set(False)
|
||||
scene.animtoolbox.isolated.clear()
|
||||
scene.animtoolbox.active_obj = None
|
||||
|
||||
def isolate_pose_mode(scene):
|
||||
context = bpy.context
|
||||
#return when going out of isolate pose or when active object is not in pose mode
|
||||
if not scene.animtoolbox.isolate_pose_mode or context.active_object.mode != 'POSE':
|
||||
clear_isolate_pose_mode(scene)
|
||||
return
|
||||
|
||||
#handler continue only if the active object is None otherwise it collects all armature objects
|
||||
if scene.animtoolbox.active_obj is None:
|
||||
scene.animtoolbox.active_obj = context.active_object
|
||||
else:
|
||||
return
|
||||
|
||||
isolated = scene.animtoolbox.isolated
|
||||
for obj in context.view_layer.objects:
|
||||
if obj.type != 'ARMATURE':
|
||||
continue
|
||||
if obj.hide_get():
|
||||
continue
|
||||
rig = isolated.add()
|
||||
if obj.mode == 'POSE':
|
||||
rig.selected = obj
|
||||
else:
|
||||
rig.hidden = obj
|
||||
obj.hide_set(True)
|
||||
|
||||
class IsolatePoseMode(bpy.types.Operator):
|
||||
"""Isolates armatures during pose mode"""
|
||||
bl_idname = "anim.isolate_pose_mode"
|
||||
bl_label = "Isolate Pose Mode"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def execute(self, context):
|
||||
|
||||
# If the modal is already running, then don't run it the second time
|
||||
scene = context.scene
|
||||
if scene.animtoolbox.isolate_pose_mode:
|
||||
if isolate_pose_mode in bpy.app.handlers.depsgraph_update_pre:
|
||||
clear_isolate_pose_mode(scene)
|
||||
bpy.app.handlers.depsgraph_update_pre.remove(isolate_pose_mode)
|
||||
scene.animtoolbox.isolate_pose_mode = False
|
||||
return {'FINISHED'}
|
||||
|
||||
scene.animtoolbox.isolate_pose_mode = True
|
||||
isolate_pose_mode(scene)
|
||||
if isolate_pose_mode not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(isolate_pose_mode)
|
||||
return {'FINISHED'}
|
||||
|
||||
class SwitchBoneCollectionsVisibility(bpy.types.Operator):
|
||||
"""Turn all bone collections visible and then press again to switch back"""
|
||||
bl_idname = "anim.switch_collections_visibility"
|
||||
bl_label = "Bone Collections Visibility"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.app.version >= (4, 0, 0)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
if obj.type != 'ARMATURE':
|
||||
return {'CANCELLED'}
|
||||
if not obj.animation_data:
|
||||
self.report({'INFO'}, 'No animation is available')
|
||||
return {'CANCELLED'}
|
||||
|
||||
if not obj.animation_data.action:
|
||||
self.report({'INFO'}, 'No animation is available')
|
||||
return {'CANCELLED'}
|
||||
|
||||
collections = obj.data.collections
|
||||
|
||||
if not len(collections):
|
||||
self.report({'INFO'}, 'No collections are available')
|
||||
return {'CANCELLED'}
|
||||
#check if there are collections that are marked with
|
||||
tagged_col = ['atb' in col.keys() for col in collections]
|
||||
atb_ui = context.scene.animtoolbox
|
||||
|
||||
if any(tagged_col) and atb_ui.col_vis:
|
||||
#collections are already marked so return to previous collection visibilty
|
||||
for col in collections:
|
||||
if 'atb' in col.keys():
|
||||
col.is_visible = col['atb']
|
||||
del col['atb']
|
||||
atb_ui.col_vis = False
|
||||
else:
|
||||
#Mark visible collections and turn collections with animated bones on
|
||||
animated_bones = set()
|
||||
start = 'pose.bones["'
|
||||
end = '"]'
|
||||
#get all the animated bones from the fcurves
|
||||
for fcu in obj.animation_data.action.fcurves:
|
||||
start_index = fcu.data_path.find(start)
|
||||
end_index = fcu.data_path.find(end)
|
||||
#if it's not a posebone fcurve then skip
|
||||
if start_index == -1 or end_index == -1:
|
||||
continue
|
||||
animated_bones.add(fcu.data_path[start_index + len(start):end_index])
|
||||
|
||||
#check if the collecetion that is turned off has animated bones
|
||||
find_anim = []
|
||||
for col in collections:
|
||||
for bone in col.bones:
|
||||
if bone.name in animated_bones and not col.is_visible:
|
||||
# print(bone.name, 'in ', col.name)
|
||||
find_anim.append(col)
|
||||
break
|
||||
|
||||
if not find_anim:
|
||||
self.report({'INFO'}, 'No collections with animated bones and no visibility are found')
|
||||
return {'CANCELLED'}
|
||||
|
||||
#Turn on collections without visiblity
|
||||
for col in collections:
|
||||
if col in find_anim:
|
||||
#tag visibility
|
||||
col['atb'] = col.is_visible
|
||||
col.is_visible = True
|
||||
|
||||
atb_ui.col_vis = True
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
classes = (GizmoSizeUp, GizmoSizeDown, IsolatePoseMode, SwitchBoneCollectionsVisibility)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
@@ -0,0 +1,549 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
from mathutils import Matrix, Vector
|
||||
from math import radians
|
||||
import numpy
|
||||
|
||||
def draw_wgt(boneLength, bone):
|
||||
suffix = bone.id_data.name + '_' + bone.name
|
||||
if 'WGTB_object' + suffix in bpy.data.objects:
|
||||
obj = bpy.data.objects['WGTB_object'] + suffix
|
||||
if 'WGTB_shape' + suffix in obj.data.name:
|
||||
return obj
|
||||
mesh = bpy.data.meshes.new('WGTB_shape_' + suffix)
|
||||
obj = bpy.data.objects.new('WGTB_object_' + suffix, mesh)
|
||||
#coordinates of the sphere widget shape
|
||||
sphere = {"edges": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [0, 23], [24, 25], [25, 26], [26, 27], [27, 28], [28, 29], [29, 30], [30, 31], [31, 32], [32, 33], [33, 34], [34, 35], [35, 36], [36, 37], [37, 38], [38, 39], [39, 40], [40, 41], [41, 42], [42, 43], [43, 44], [44, 45], [45, 46], [46, 47], [24, 47], [48, 49], [49, 50], [50, 51], [51, 52], [52, 53], [53, 54], [54, 55], [55, 56], [56, 57], [57, 58], [58, 59], [59, 60], [60, 61], [61, 62], [62, 63], [63, 64], [64, 65], [65, 66], [66, 67], [67, 68], [68, 69], [69, 70], [70, 71], [48, 71]],
|
||||
"vertices": [[0.0, 0.10000002384185791, 0.0], [-0.025881901383399963, 0.09659260511398315, 0.0], [-0.050000011920928955, 0.08660250902175903, 0.0], [-0.07071065902709961, 0.07071065902709961, 0.0], [-0.08660256862640381, 0.04999998211860657, 0.0], [-0.09659260511398315, 0.025881901383399963, 0.0], [-0.10000002384185791, 7.549793679118011e-09, 0.0], [-0.09659260511398315, -0.02588188648223877, 0.0], [-0.08660256862640381, -0.04999998211860657, 0.0], [-0.07071071863174438, -0.07071065902709961, 0.0], [-0.050000011920928955, -0.08660250902175903, 0.0], [-0.02588193118572235, -0.09659260511398315, 0.0], [-3.894143674187944e-08, -0.10000002384185791, 0.0], [0.025881856679916382, -0.09659260511398315, 0.0], [0.04999995231628418, -0.08660256862640381, 0.0], [0.07071065902709961, -0.07071071863174438, 0.0], [0.08660250902175903, -0.05000004172325134, 0.0], [0.09659254550933838, -0.025881946086883545, 0.0], [0.10000002384185791, -4.649123752642481e-08, 0.0], [0.09659260511398315, 0.025881856679916382, 0.0], [0.08660256862640381, 0.04999995231628418, 0.0], [0.07071071863174438, 0.07071065902709961, 0.0], [0.05000007152557373, 0.08660250902175903, 0.0], [0.025881975889205933, 0.09659254550933838, 0.0], [0.0, 7.450580596923828e-09, 0.10000002384185791], [-0.025881901383399963, 7.450580596923828e-09, 0.09659260511398315], [-0.050000011920928955, 7.450580596923828e-09, 0.08660250902175903], [-0.07071065902709961, 7.450580596923828e-09, 0.07071065902709961], [-0.08660256862640381, 3.725290298461914e-09, 0.04999998211860657], [-0.09659260511398315, 1.862645149230957e-09, 0.025881901383399963], [-0.10000002384185791, 8.881784197001252e-16, 7.549793679118011e-09], [-0.09659260511398315, -1.862645149230957e-09, -0.02588188648223877], [-0.08660256862640381, -3.725290298461914e-09, -0.04999998211860657], [-0.07071071863174438, -7.450580596923828e-09, -0.07071065902709961], [-0.050000011920928955, -7.450580596923828e-09, -0.08660250902175903], [-0.02588193118572235, -7.450580596923828e-09, -0.09659260511398315], [-3.894143674187944e-08, -7.450580596923828e-09, -0.10000002384185791], [0.025881856679916382, -7.450580596923828e-09, -0.09659260511398315], [0.04999995231628418, -7.450580596923828e-09, -0.08660256862640381], [0.07071065902709961, -7.450580596923828e-09, -0.07071071863174438], [0.08660250902175903, -3.725290298461914e-09, -0.05000004172325134], [0.09659254550933838, -1.862645149230957e-09, -0.025881946086883545], [0.10000002384185791, -3.552713678800501e-15, -4.649123752642481e-08], [0.09659260511398315, 1.862645149230957e-09, 0.025881856679916382], [0.08660256862640381, 3.725290298461914e-09, 0.04999995231628418], [0.07071071863174438, 7.450580596923828e-09, 0.07071065902709961], [0.05000007152557373, 7.450580596923828e-09, 0.08660250902175903], [0.025881975889205933, 7.450580596923828e-09, 0.09659254550933838], [-7.450580596923828e-09, 4.440892098500626e-16, 0.10000002384185791], [-9.313225746154785e-09, -0.025881901383399963, 0.09659260511398315], [-1.1175870895385742e-08, -0.050000011920928955, 0.08660250902175903], [-1.4901161193847656e-08, -0.07071065902709961, 0.07071065902709961], [-7.450580596923828e-09, -0.08660256862640381, 0.04999998211860657], [-7.450580596923828e-09, -0.09659260511398315, 0.025881901383399963], [-7.450580596923828e-09, -0.10000002384185791, 7.549793679118011e-09], [-7.450580596923828e-09, -0.09659260511398315, -0.02588188648223877], [0.0, -0.08660256862640381, -0.04999998211860657], [0.0, -0.07071071863174438, -0.07071065902709961], [3.725290298461914e-09, -0.050000011920928955, -0.08660250902175903], [5.587935447692871e-09, -0.02588193118572235, -0.09659260511398315], [7.450577044210149e-09, -3.894143674187944e-08, -0.10000002384185791], [9.313225746154785e-09, 0.025881856679916382, -0.09659260511398315], [1.1175870895385742e-08, 0.04999995231628418, -0.08660256862640381], [1.4901161193847656e-08, 0.07071065902709961, -0.07071071863174438], [7.450580596923828e-09, 0.08660250902175903, -0.05000004172325134], [7.450580596923828e-09, 0.09659254550933838, -0.025881946086883545], [7.450580596923828e-09, 0.10000002384185791, -4.649123752642481e-08], [7.450580596923828e-09, 0.09659260511398315, 0.025881856679916382], [0.0, 0.08660256862640381, 0.04999995231628418], [0.0, 0.07071071863174438, 0.07071065902709961], [-3.725290298461914e-09, 0.05000007152557373, 0.08660250902175903], [-5.587935447692871e-09, 0.025881975889205933, 0.09659254550933838]], "faces": []}
|
||||
mesh.from_pydata(numpy.array(sphere['vertices'])*[boneLength, boneLength, boneLength] , sphere['edges'], sphere['faces'])
|
||||
|
||||
return obj
|
||||
|
||||
def add_driver(obj, posebone, control, target, path, multiply = ''):
|
||||
|
||||
if isinstance(target, tuple):
|
||||
attr = posebone.driver_add(target[0], target[1])
|
||||
else:
|
||||
attr = posebone.driver_add(target)
|
||||
|
||||
var = attr.driver.variables.new()
|
||||
|
||||
var.targets[0].id = obj
|
||||
var.targets[0].data_path = 'pose.bones["' + control +'"].'+ path
|
||||
attr.driver.expression = var.name + multiply
|
||||
|
||||
def dup_values(source, target):
|
||||
if hasattr(source, 'parent'):
|
||||
target.parent = source.parent
|
||||
for prop in dir(source):
|
||||
if not hasattr(target, prop):
|
||||
continue
|
||||
value = getattr(source, prop)
|
||||
if type(value) not in {int, float, bool, str, Vector, Matrix, bpy.types.Object}:
|
||||
continue
|
||||
if '__' in prop[:2] and '__' in prop[-2:]:
|
||||
continue
|
||||
if target.is_property_readonly(prop):
|
||||
continue
|
||||
setattr(target, prop, value)
|
||||
|
||||
return target
|
||||
|
||||
def dup_constraints(source, target):
|
||||
if not source.constraints.items():
|
||||
return
|
||||
for source_con in source.constraints:
|
||||
target_con = target.constraints.new(source_con.type)
|
||||
dup_values(source_con, target_con)
|
||||
|
||||
def add_vis_bone_con(obj, bone_vis_name, bone_wgt_name):
|
||||
bone_vis = obj.pose.bones[bone_vis_name]
|
||||
con = bone_vis.constraints.new('STRETCH_TO')
|
||||
con.target = obj
|
||||
con.subtarget = bone_wgt_name
|
||||
|
||||
return bone_vis
|
||||
|
||||
class target:
|
||||
def __init__(self, bone):
|
||||
self.name = bone.name
|
||||
self.point = tuple(bone.tail)
|
||||
self.ctrl = 'TRGT_' + bone.name
|
||||
if bone.parent:
|
||||
self.parent = bone.parent.name
|
||||
#print('assign parent to target ', self.name, self.ctrl, self.parent)
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.point < other.point
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.point)
|
||||
|
||||
def __eq__(self, other):
|
||||
#if not isinstance(other, type(self)):
|
||||
# return NotImplemented
|
||||
return self.point == other.point
|
||||
|
||||
class parent:
|
||||
def __init__(self, bone):
|
||||
self.name = bone.name
|
||||
self.point = tuple(bone.head)
|
||||
self.ctrl = 'CTRL_' + bone.name
|
||||
if bone.parent:
|
||||
self.parent = bone.parent.name
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.point < other.point
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.point)
|
||||
|
||||
def __eq__(self, other):
|
||||
#if not isinstance(other, type(self)):
|
||||
# return NotImplemented
|
||||
return self.point == other.point
|
||||
|
||||
class constraint_dup:
|
||||
def __init__(self, bone, con):
|
||||
self.name = con.name
|
||||
self.target = con.target
|
||||
self.subtarget = con.subtarget
|
||||
self.bone = bone.name
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.bone)
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.bone == other.bone
|
||||
|
||||
def bone_orientation(source, target, value):
|
||||
source.align_orientation(target)
|
||||
x, y, z = source.matrix.to_3x3().col
|
||||
R = (Matrix.Translation(source.head) @ Matrix.Rotation(radians(value), 4, x) @ Matrix.Translation(-source.head))
|
||||
source.transform(R, roll = False)
|
||||
source.align_roll(target.vector)
|
||||
|
||||
def find_ctrl(bone, controls):
|
||||
i = list(controls).index(bone)
|
||||
bone.ctrl = list(controls)[i].ctrl
|
||||
|
||||
return bone.ctrl
|
||||
|
||||
def add_controlers(self, obj, parents, targets):
|
||||
|
||||
#controls = set(parents).union(targets)
|
||||
controls = set(parents + targets)
|
||||
|
||||
#create hierarchy
|
||||
for bone in controls:
|
||||
editbone = obj.data.edit_bones[bone.name]
|
||||
if editbone.parent is None:
|
||||
continue
|
||||
parentnames = [bone.name for bone in parents]
|
||||
#if a target and its parent are part of the hierarchy then linked to its own bone parent
|
||||
if bone in targets and bone not in parents and editbone.parent.name in parentnames:
|
||||
parentbone = parent(editbone)
|
||||
else:
|
||||
parentbone = parent(editbone.parent)
|
||||
|
||||
if parentbone in controls and parentbone != bone:
|
||||
bone.parent = find_ctrl(parentbone, controls)
|
||||
else:
|
||||
bone.parent = editbone.parent.name
|
||||
|
||||
|
||||
edit_bones = obj.data.edit_bones
|
||||
for bone in controls:
|
||||
editbone = edit_bones[bone.name]
|
||||
ctrl = obj.data.edit_bones.new(bone.ctrl)
|
||||
ctrl.head = bone.point
|
||||
ctrl.tail = bone.point
|
||||
ctrl.tail[2] = bone.point[2] + (editbone.length / 3)
|
||||
ctrl.bbone_x = editbone.bbone_x
|
||||
ctrl.bbone_z = editbone.bbone_z
|
||||
ctrl.use_deform = False
|
||||
if self.bone_align:
|
||||
angle = 90 if self.align_90 else 0
|
||||
bone_orientation(ctrl, editbone, angle)
|
||||
if angle == 90:
|
||||
ctrl.align_roll(editbone.vector)
|
||||
else:
|
||||
ctrl.roll = editbone.roll
|
||||
|
||||
#apply hierarchy
|
||||
for bone in parents:
|
||||
editbone = edit_bones[bone.name]
|
||||
ctrl_name = find_ctrl(bone, controls)
|
||||
ctrl = edit_bones[ctrl_name]
|
||||
editbone.parent = ctrl
|
||||
|
||||
for bone in controls:
|
||||
ctrl = edit_bones[bone.ctrl]
|
||||
if hasattr(bone, 'parent'):
|
||||
ctrl.parent = edit_bones[bone.parent]
|
||||
|
||||
return controls
|
||||
|
||||
def pose_bbone_setup(bone, posebone, bbone_group = None):
|
||||
#add the custom shape to the widget bones
|
||||
custom_shape = draw_wgt(bone['length'], posebone)
|
||||
posebone.custom_shape = custom_shape
|
||||
posebone.use_custom_shape_bone_size = False
|
||||
if bbone_group:
|
||||
posebone.bone_group = bbone_group
|
||||
posebone.rotation_mode = 'XZY'
|
||||
posebone.lock_rotation[0] = True
|
||||
posebone.lock_rotation[2] = True
|
||||
|
||||
#####MAIN####
|
||||
class BboneWidgets(bpy.types.Operator):
|
||||
"""Add Bbone widget controls to the selected bones"""
|
||||
bl_idname = "armature.add_bbone_widgets"
|
||||
bl_label = "Add_Bbone_widgets"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.type == 'ARMATURE'
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
|
||||
obj.data.display_type = 'BBONE'
|
||||
|
||||
bones = []
|
||||
parentlayers = [False if i != 24 else True for i in range(32)]
|
||||
wgtlayers = [True if i == 0 else False for i in range(32)]
|
||||
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
obj.data.use_mirror_x = False
|
||||
for bone in obj.data.edit_bones:
|
||||
if not bone.select:
|
||||
continue
|
||||
if bone.bbone_segments == 1:
|
||||
bone.bbone_segments = 10
|
||||
bone.bbone_handle_type_start = 'TANGENT'
|
||||
bone.bbone_handle_type_end = 'TANGENT'
|
||||
bone_name = bone.name
|
||||
#add parent bone to the Bbone widgets
|
||||
parent = obj.data.edit_bones.new('WGTB_parent_'+ bone_name)
|
||||
parent_name = parent.name
|
||||
dup_values(bone, parent)
|
||||
parent.name = parent_name
|
||||
parent.select = False
|
||||
parent.select_head = False
|
||||
parent.select_tail = False
|
||||
|
||||
#change layer of the parent bone
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
parent.layers = parentlayers
|
||||
|
||||
#add bbone widget bones
|
||||
head_widget = obj.data.edit_bones.new('Bhead_'+ bone.name)
|
||||
head_widget.parent = parent
|
||||
#head_widget.head = bone.head
|
||||
head_widget.head = bone.head + (bone.tail - bone.head) * 0.25
|
||||
#head_widget.tail = (bone.tail - bone.head)/10
|
||||
head_widget.length = bone.length * 0.1
|
||||
head_widget.bbone_x = bone.bbone_x
|
||||
head_widget.bbone_z = bone.bbone_z
|
||||
head_widget.align_orientation(bone)
|
||||
head_widget.inherit_scale = 'NONE'
|
||||
head_name = head_widget.name
|
||||
|
||||
tail_widget = obj.data.edit_bones.new('Btail_'+ bone.name)
|
||||
tail_widget.parent = parent
|
||||
#tail_widget.head = bone.tail
|
||||
tail_widget.head = bone.head + (bone.tail - bone.head) * 0.75
|
||||
#tail_widget.tail = bone.tail - (bone.tail - bone.head)/10
|
||||
tail_widget.length = bone.length * 0.1
|
||||
tail_widget.bbone_x = bone.bbone_x
|
||||
tail_widget.bbone_z = bone.bbone_z
|
||||
tail_widget.align_orientation(bone)
|
||||
tail_widget.inherit_scale = 'NONE'
|
||||
tail_name = tail_widget.name
|
||||
|
||||
#add vis bones
|
||||
head_vis = obj.data.edit_bones.new('Bhead_vis_'+ bone.name)
|
||||
head_vis.parent = parent
|
||||
head_vis.head = bone.head
|
||||
head_vis.tail = head_widget.head
|
||||
head_vis.bbone_x = bone.bbone_x*0.1
|
||||
head_vis.bbone_z = bone.bbone_z*0.1
|
||||
|
||||
#head_vis_name = head_vis.name
|
||||
head_vis.hide_select = True
|
||||
head_vis.use_deform = False
|
||||
tail_vis = obj.data.edit_bones.new('Btail_vis_'+ bone.name)
|
||||
tail_vis.parent = parent
|
||||
tail_vis.head = bone.tail
|
||||
tail_vis.tail = tail_widget.head
|
||||
tail_vis.bbone_x = bone.bbone_x*0.1
|
||||
tail_vis.bbone_z = bone.bbone_z*0.1
|
||||
|
||||
#tail_vis_name = tail_vis.name
|
||||
tail_vis.hide_select = True
|
||||
|
||||
tail_vis.use_deform = False
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
tail_widget.layers = wgtlayers
|
||||
head_widget.layers = wgtlayers
|
||||
head_vis.layers = wgtlayers
|
||||
tail_vis.layers = wgtlayers
|
||||
|
||||
bones.append({'name': bone_name, 'parent': parent_name, 'head': head_name, 'tail': tail_name, 'head_vis': head_vis.name, 'tail_vis': tail_vis.name, 'length': bone.length})
|
||||
|
||||
#####POSE MODE#######
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
bone_groups = obj.pose.bone_groups
|
||||
if 'BBone Widgets' not in bone_groups:
|
||||
bbone_group = bone_groups.new(name = 'BBone Widgets')
|
||||
bbone_group.color_set = 'THEME09'
|
||||
else:
|
||||
bbone_group = bone_groups['BBone Widgets']
|
||||
else:
|
||||
bbone_group = None
|
||||
|
||||
for bone in bones:
|
||||
posebone = obj.pose.bones[bone['name']]
|
||||
# Prepare parent bone in pose mode
|
||||
poseparent = obj.pose.bones[bone['parent']]
|
||||
#disable use deform
|
||||
obj.data.bones[bone['parent']].use_deform = False
|
||||
obj.data.bones[bone['head']].use_deform = False
|
||||
obj.data.bones[bone['tail']].use_deform = False
|
||||
|
||||
pose_bbone_setup(bone, obj.pose.bones[bone['head']], bbone_group)
|
||||
pose_bbone_setup(bone, obj.pose.bones[bone['tail']], bbone_group)
|
||||
|
||||
dup_constraints(posebone, poseparent)
|
||||
|
||||
#add all the drivers
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_curveinx', 'location.x')
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_curveinz', 'location.z')
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_easein', 'location.y', '*5/'+ str(bone['length']))
|
||||
add_driver(obj, posebone, bone['head'], 'bbone_rollin', 'rotation_euler.y')
|
||||
add_driver(obj, posebone, bone['head'], ('bbone_scalein', 0), 'scale.x')
|
||||
add_driver(obj, posebone, bone['head'], ('bbone_scalein', 1), 'scale.y')
|
||||
add_driver(obj, posebone, bone['head'], ('bbone_scalein', 2), 'scale.z')
|
||||
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_curveoutx', 'location.x')
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_curveoutz', 'location.z')
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_easeout', 'location.y', '*-5/'+ str(bone['length']))
|
||||
add_driver(obj, posebone, bone['tail'], 'bbone_rollout', 'rotation_euler.y')
|
||||
add_driver(obj, posebone, bone['tail'], ('bbone_scaleout', 0), 'scale.x')
|
||||
add_driver(obj, posebone, bone['tail'], ('bbone_scaleout', 1), 'scale.y')
|
||||
add_driver(obj, posebone, bone['tail'], ('bbone_scaleout', 2), 'scale.z')
|
||||
|
||||
#add constraints to visual bones
|
||||
head_vis = add_vis_bone_con(obj, bone['head_vis'], bone['head'])
|
||||
tail_vis = add_vis_bone_con(obj, bone['tail_vis'], bone['tail'])
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
head_vis.bone_group = bbone_group
|
||||
tail_vis.bone_group = bbone_group
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
class ChainControls(bpy.types.Operator):
|
||||
"""Add parent and target controls to the selected bones to create a chain control"""
|
||||
bl_idname = "armature.add_chain_ctrls"
|
||||
bl_label = "Add_Chain_Controls"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
parents: bpy.props.BoolProperty(name = 'Add Parents', description = "Align the controls 90 degrees to the original bones", default = True)
|
||||
targets: bpy.props.BoolProperty(name = 'Add Targets', description = "Align the controls 90 degrees to the original bones", default = True)
|
||||
keep_hierarchy: bpy.props.BoolProperty(name = 'Keep Hierarchy', description = "Keep the controls in the hierarchy of the original bones", default = True)
|
||||
bone_align: bpy.props.BoolProperty(name = 'Align to Bones', description = "Align the controls to the original bones", default = True)
|
||||
align_90: bpy.props.BoolProperty(name = '+90°', description = "Align the controls 90 degrees to the original bones", default = True)
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.type == 'ARMATURE'
|
||||
def invoke(self, context, event):
|
||||
#obj = context.object
|
||||
wm = context.window_manager
|
||||
return wm.invoke_props_dialog(self, width = 200)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
row = layout.row()
|
||||
row.label(text = 'Add Control Bones')
|
||||
row = layout.row()
|
||||
row.prop(self, 'parents') #text = 'Size'
|
||||
row.prop(self, 'targets')
|
||||
|
||||
layout.separator()
|
||||
col = layout.column()
|
||||
col.prop(self, 'keep_hierarchy')
|
||||
row = layout.row()
|
||||
row.prop(self, 'bone_align')
|
||||
if self.bone_align:
|
||||
row.prop(self, 'align_90', toggle=True)
|
||||
|
||||
def execute(self, context):
|
||||
obj = context.object
|
||||
targets = []
|
||||
parents = []
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
edit_bones = bpy.context.selected_editable_bones
|
||||
#create list of parent and target objects
|
||||
for bone in edit_bones:
|
||||
bone.use_connect = False
|
||||
if self.targets:
|
||||
targets.append(target(bone))
|
||||
if self.parents:
|
||||
parents.append(parent(bone))
|
||||
|
||||
controls = add_controlers(self, obj, parents, targets)
|
||||
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
|
||||
#Add the bone group for the ctrls if doesn't exist
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
bone_groups = obj.pose.bone_groups
|
||||
if 'Ctrl Bones' not in bone_groups:
|
||||
ctrl_group = bone_groups.new(name = 'Ctrl Bones')
|
||||
ctrl_group.color_set = 'THEME01'
|
||||
else:
|
||||
ctrl_group = bone_groups['Ctrl Bones']
|
||||
|
||||
for bone in controls:
|
||||
posebone = obj.pose.bones[bone.ctrl]
|
||||
if bpy.app.version < (4, 0, 0):
|
||||
posebone.bone_group = ctrl_group
|
||||
else:
|
||||
posebone.color.palette = 'THEME01'
|
||||
|
||||
if self.targets:
|
||||
for bone in targets:
|
||||
#update from the controls set
|
||||
ctrl = find_ctrl(bone, controls)
|
||||
posebone = obj.pose.bones[bone.name]
|
||||
|
||||
con = posebone.constraints.new('STRETCH_TO')
|
||||
con.target = obj
|
||||
|
||||
con.subtarget = ctrl
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
class MergeRigs(bpy.types.Operator):
|
||||
"""Merge selected rigs to active and keep hierarchy and constraints for shared bones"""
|
||||
bl_idname = "armature.merge"
|
||||
bl_label = "Merge_Rigs"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return bpy.context.object.type == 'ARMATURE'
|
||||
|
||||
def execute(self, context):
|
||||
target_obj = context.object
|
||||
|
||||
if target_obj.type != 'ARMATURE':
|
||||
return {"CANCELLED"}
|
||||
|
||||
target_bones = set([bone.name for bone in target_obj.data.bones])
|
||||
constraints = []
|
||||
childrens = {}
|
||||
|
||||
#Store children and constraints
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
for obj in bpy.context.selected_objects:
|
||||
if obj.type != 'ARMATURE':
|
||||
continue
|
||||
if obj == target_obj:
|
||||
continue
|
||||
#create a set of all the similiar bones in all the rigs
|
||||
obj_bones = set([bone.name for bone in obj.data.bones])
|
||||
shared_bones = target_bones.intersection(obj_bones)
|
||||
|
||||
#find all the constraints and children
|
||||
for bone in obj.pose.bones:
|
||||
#store all the constraints
|
||||
for con in bone.constraints:
|
||||
if not hasattr(con, 'subtarget'):
|
||||
continue
|
||||
if con.target == obj and con.subtarget in shared_bones:
|
||||
constraints.append(constraint_dup(bone, con))
|
||||
if bone.name in shared_bones:
|
||||
for child in bone.children:
|
||||
if child.name in childrens:
|
||||
continue
|
||||
childrens.update({child.name : bone.name})
|
||||
|
||||
#remove shared bones
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
for obj in bpy.context.selected_objects:
|
||||
if obj.type != 'ARMATURE':
|
||||
continue
|
||||
if obj == target_obj:
|
||||
continue
|
||||
for bone in shared_bones:
|
||||
if bone not in obj.data.edit_bones:
|
||||
continue
|
||||
obj.data.edit_bones.remove(obj.data.edit_bones[bone])
|
||||
|
||||
bpy.ops.object.mode_set(mode = 'POSE')
|
||||
bpy.ops.object.join()
|
||||
|
||||
#restore constraints
|
||||
for con_dup in constraints:
|
||||
if con_dup.bone in target_bones:
|
||||
continue
|
||||
if con_dup.bone not in target_obj.pose.bones:
|
||||
continue
|
||||
#print('constraint on ',con_dup.bone, con_dup.name)
|
||||
posebone = target_obj.pose.bones[con_dup.bone]
|
||||
if con_dup.name not in posebone.constraints:
|
||||
continue
|
||||
con = posebone.constraints[con_dup.name]
|
||||
con.target = target_obj
|
||||
con.subtarget = con_dup.subtarget
|
||||
|
||||
#reparent all child bones
|
||||
bpy.ops.object.mode_set(mode = 'EDIT')
|
||||
for child, parent in childrens.items():
|
||||
target_obj.data.edit_bones[child].parent = target_obj.data.edit_bones[parent]
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
classes = (MergeRigs,BboneWidgets, ChainControls)
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
# bpy.utils.register_class(BboneWidgets)
|
||||
# bpy.utils.register_class(ChainControls)
|
||||
# bpy.utils.register_class(RiggerToolBox_PT_Panel)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
# bpy.utils.unregister_class(BboneWidgets)
|
||||
# bpy.utils.unregister_class(ChainControls)
|
||||
# bpy.utils.unregister_class(RiggerToolBox_PT_Panel)
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,527 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
bl_info = {
|
||||
"name": "AnimToolBox",
|
||||
"author": "Tal Hershkovich",
|
||||
"version" : (0, 0, 7, 1),
|
||||
"blender" : (3, 2, 0),
|
||||
"location": "View3D - Properties - Animation Panel",
|
||||
"description": "A set of animation tools",
|
||||
"wiki_url": "",
|
||||
"category": "Animation"}
|
||||
|
||||
if "bpy" in locals():
|
||||
import importlib
|
||||
if "Rigger_Toolbox" in locals():
|
||||
importlib.reload(Rigger_Toolbox)
|
||||
if "TempCtrls" in locals():
|
||||
importlib.reload(TempCtrls)
|
||||
if "Tools" in locals():
|
||||
importlib.reload(Tools)
|
||||
if "Display" in locals():
|
||||
importlib.reload(Display)
|
||||
if "emp" in locals():
|
||||
importlib.reload(emp)
|
||||
if "multikey" in locals():
|
||||
importlib.reload(multikey)
|
||||
if "Rigger_Toolbox" in locals():
|
||||
importlib.reload(Rigger_Toolbox)
|
||||
if "ui" in locals():
|
||||
importlib.reload(ui)
|
||||
if "addon_updater_ops" in locals():
|
||||
importlib.reload(addon_updater_ops)
|
||||
|
||||
import bpy
|
||||
from . import addon_updater_ops
|
||||
from . import TempCtrls
|
||||
from . import Rigger_Toolbox
|
||||
from . import Tools
|
||||
from . import Display
|
||||
from . import emp
|
||||
from . import ui
|
||||
from . import multikey
|
||||
from . import Rigger_Toolbox
|
||||
from pathlib import Path
|
||||
from bpy.utils import register_class
|
||||
from bpy.utils import unregister_class
|
||||
from bpy.app.handlers import persistent
|
||||
import os
|
||||
|
||||
|
||||
class TempCtrlsItems(bpy.types.PropertyGroup):
|
||||
#located at context.scene.btc.ctrl_items
|
||||
controlled: bpy.props.PointerProperty(name = "controlled object", description = "rigs and objects that are being controlled", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
controller: bpy.props.PointerProperty(name = "controller object", description = "rigs and objects that are controling", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class TempCtrlsSceneSettings(bpy.types.PropertyGroup):
|
||||
#located at context.scene.btc
|
||||
root: bpy.props.BoolProperty(name = "Root Empty", description = "Add a root to the empties ", default = False, override = {'LIBRARY_OVERRIDABLE'}, update = TempCtrls.root_prop)
|
||||
root_bone: bpy.props.StringProperty(name = "Root bone", description = "Root empty as a root bone ", override = {'LIBRARY_OVERRIDABLE'}, update = TempCtrls.root_update)
|
||||
root_object: bpy.props.PointerProperty(name = "Root object", description = "Root empty as a root object ", update = TempCtrls.root_update, type = bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
ctrl_type: bpy.props.EnumProperty(name = 'Controllers', description="Select empties or a bone with a new rig to bake to", items = [('BONE', 'Bone','Bake to bones','BONE_DATA', 0), ('EMPTY', 'Empty', 'Bake to empties', 'EMPTY_ARROWS', 1)])
|
||||
ctrl_items: bpy.props.CollectionProperty(type = TempCtrlsItems, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
|
||||
bake_range_type: bpy.props.EnumProperty(name = 'Bake Range', description="Use either scene, actions length or custom frame range", default = 'KEYFRAMES', update= TempCtrls.update_range_type,
|
||||
items = [('SCENE', 'Scene Range', 'Bake to the scene range'), ('KEYFRAMES', 'Keyframes Range', 'Bake all the keyframes in the layers'), ('CUSTOM', 'Custom', 'Enter a custom frame range')], override = {'LIBRARY_OVERRIDABLE'})
|
||||
bake_range: bpy.props.IntVectorProperty(name='Frame Range', description='Bake to a custom frame range', size = 2, update= TempCtrls.update_bake_range)
|
||||
bake_layers: bpy.props.BoolProperty(name = "Bake Layers", description = "Use keyframes from all the layers to include in the bake", default = False)
|
||||
|
||||
target: bpy.props.EnumProperty(name = 'Affect', description="Cleanup created constraints and empties", default = 1,
|
||||
items = [('ALL', 'All Ctrl Rigs','Bake to all Ctrl Rigs', 0),
|
||||
('SELECTED', 'Selected Chains','Bake to only selected chain controlls', 1),
|
||||
('RELATIVE', 'Relative Ctrls Rig','Bake to the Relative Control rigs', 2)])
|
||||
# ('CONSTRAINTS', 'Constraints', 'Clean all the bone constraints', 3),
|
||||
# ('CONTROLLERS', 'Controllers', 'Remove all the baked empties', 4)])
|
||||
|
||||
selection: bpy.props.EnumProperty(name = 'Select', description="Select all controls, original bones or their relative", default = 'CONTROLLERS',
|
||||
items = [('RELATIVE_CTRLS', 'Relative Ctrls','Select the Relative controller to your current selection', 0),
|
||||
('RELATIVE_CONSTRAINED', 'Relative Constrained','Select the Relative original constrained bone to your current selection', 1),
|
||||
('CONTROLLERS', 'All Ctrls', 'Select all the controller bones or empties', 2), ('CONSTRAINED', 'All Constrained', 'Select all the original constrained bones', 3)])
|
||||
|
||||
#smartbake setting
|
||||
linksettings: bpy.props.BoolProperty(name = "Link Settings", description = "Link Settings", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bakesettings: bpy.props.BoolProperty(name = "bake settings", description = "bake settings", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
cleansettings: bpy.props.BoolProperty(name = "clean settings", description = "clean settings", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
smartbake: bpy.props.BoolProperty(name = "Smart Bake", description = "Keep Original Frame count", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
inbetween_keyframes: bpy.props.IntProperty(name = "Inbetween Keyframes", description = "Add inbetween keyframes", default = 0, override = {'LIBRARY_OVERRIDABLE'})
|
||||
from_origin: bpy.props.BoolProperty(name = "From Origin", description = "Use Keyframes from Original Bone", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
from_ctrl: bpy.props.BoolProperty(name = "From Controller", description = "Use Keyframes from Controller Bone", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
clean_ctrls: bpy.props.BoolProperty(name = "Remove Ctrls", description = "Remove Controls", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
clean_constraints: bpy.props.BoolProperty(name = "Remove Constraints", description = "Remove Constraints", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
rebake_to_org: bpy.props.BoolProperty(name = "ReBake connections to original bones", description = "ReBake ctrls from connected chains current anim to the original bones", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
link_to: bpy.props.EnumProperty(name = 'Link to Chain', description="Link to begining of an active chain or the tip of the chain", default = 1,
|
||||
items = [('BASE', 'Base','Link to the base of the active chain', 0), ('TIP', 'Tip', 'Link to the tip of the chain', 1)])
|
||||
# link_from: bpy.props.EnumProperty(name = 'Link to Chain', description="Link to begining of an active chain or the tip of the chain", default = 0,
|
||||
# items = [('BASE', 'Base','Link to the base of the active chain', 0), ('TIP', 'Tip', 'Link to the tip of the chain', 1)])
|
||||
|
||||
shape_size: bpy.props.FloatProperty(name='Size', description="Multiple factor for the shape size of the temp controls", update = TempCtrls.tempctrl_shapesize, min = 0.001, default = 1.5, override = {'LIBRARY_OVERRIDABLE'})#
|
||||
shape_type: bpy.props.EnumProperty(name = 'Shape Type', description="Display type for the controls", items = TempCtrls.ctrl_shape_items, update = TempCtrls.tempctrl_shape_type)
|
||||
color_set: bpy.props.EnumProperty(name="Bone Color Set", description="Choose a bone color set", items = TempCtrls.get_bone_color_sets, update = TempCtrls.update_bone_color, default = 9)
|
||||
|
||||
add_ik_ctrl: bpy.props.BoolProperty(name = 'Add an Extra IK Ctrl Bone', description = "Adds an extra bone ctrl as the ik ctrl", default = False, update = TempCtrls.add_ik_prop)
|
||||
pole_target: bpy.props.BoolProperty(name = 'Add Pole Target', description = "Adding Pole Target to the IK Chain", default = True, update = TempCtrls.pole_prop)
|
||||
pole_offset: bpy.props.FloatProperty(name="Offset", description="Offset the bone in the axis direction", default=1.0, update = TempCtrls.pole_offset)
|
||||
child: bpy.props.BoolProperty(name = 'Add extra child Ctrls', description = "Add an child control for an overlay control", default = False, update = TempCtrls.child_prop)
|
||||
orientation: bpy.props.BoolProperty(name = 'Use World Space Orientation', description = "Orient the bones to world space instead of to the original bones", default = True)
|
||||
|
||||
# enabled: bpy.props.BoolProperty(name = 'Switch On / Off', description = "Enabling and Disabling Temp Ctrls influence", default = True)
|
||||
|
||||
class TempCtrlsBoneSettings(bpy.types.PropertyGroup):
|
||||
#located at obj.pose.bones[##].btc
|
||||
root: bpy.props.BoolProperty(name = "Root Bone", description = "Bone is marked as the root bone", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
child: bpy.props.BoolProperty(name = "Child Bone", description = "Bone is marked as a child bone inside the setup", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
org_id: bpy.props.IntProperty(name = "Originate ID", description = "ID number of the bone the ctrl originates from", override = {'LIBRARY_OVERRIDABLE'})
|
||||
setup_id: bpy.props.IntProperty(name = "Setup ID", description = "ID number of the current chain setup", override = {'LIBRARY_OVERRIDABLE'})
|
||||
setup: bpy.props.EnumProperty(name = 'Setup Type', description="Describes what kind of setup the bone is part of", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [('NONE', 'No Setup','No Setup Applied', 0),
|
||||
('WORLDSPACE', 'World Space Ctrl','World Space Ctrl setup', 1),
|
||||
('TEMPFK', 'Temporary FK setup','Temporary FK chain setup', 2),
|
||||
('TEMPFK_FLIP', 'Temporary flipped FK setup','Temporary flipped FK chain setup', 3),
|
||||
('TEMPIK', 'Temporary IK setup','Temporary IK setup', 4),
|
||||
('POLE', 'Temporary IK Pole setup','Temporary IK Pole', 5),
|
||||
('PARENTCTRL', 'Parent Ctrl from cursor setup','Parent Ctrl from cursor setup', 6),
|
||||
('ROOT', 'Root', 'Root Ctrl for all the setups', 7),
|
||||
('EMPTY', 'Root', 'Root Ctrl for all the setups', 8),
|
||||
('TRACK_TO', 'Track To','World Space Track to Ctrl setup', 9),
|
||||
('TRACK_TO_EMPTY', 'Track To Empty','World Space Track to Empty Ctrl setup', 10)])
|
||||
|
||||
#using org mostly to decide if it needs a custom shape
|
||||
org: bpy.props.EnumProperty(name = 'Org Type', description="Describes what if the function of the bone", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [('CTRL', 'Controller Bone','Controller Bone', 0),
|
||||
('ORG', 'Original Bone','Original Bone', 1),
|
||||
('MCH', 'Mechanical Bone','Mechanical Bone', 2),
|
||||
('NONE', 'Nothing applied','Nothing applied', 3)])
|
||||
|
||||
shape: bpy.props.BoolProperty(name = "Apply shape", description = "Mark if the bone needs a shape", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class TempCtrlsObjectSetups(bpy.types.PropertyGroup):
|
||||
#located at obj.animtoolbox.ctrl_setups
|
||||
#name: using string of the id
|
||||
setup: bpy.props.EnumProperty(name = 'Setup Type', description="Describes what kind of setup the bone is part of",
|
||||
items = [('NONE', 'No Setup','No Setup Applied', 0),
|
||||
('WORLDSPACE', 'World Space Ctrl','World Space Ctrl setup', 1),
|
||||
('TEMPFK', 'Temporary FK setup','Temporary FK chain setup', 2),
|
||||
('TEMPFK_FLIP', 'Temporary flipped FK setup','Temporary flipped FK chain setup', 3),
|
||||
('TEMPIK', 'Temporary IK setup','Temporary IK setup', 4),
|
||||
('PARENTCTRL', 'Parent Ctrl from cursor setup','Parent Ctrl from cursor setup', 5),
|
||||
('ROOT', 'Root', 'Root Ctrl for all the setups', 6),
|
||||
('EMPTY', 'Root', 'Root Ctrl for all the setups', 8),
|
||||
('TRACK_TO', 'Track To','World Space Track to Ctrl setup', 9),
|
||||
('TRACK_TO_EMPTY', 'Track To Empty','World Space Track to Empty Ctrl setup', 10),
|
||||
])
|
||||
|
||||
class MultikeyProperties(bpy.types.PropertyGroup):
|
||||
|
||||
selectedbones: bpy.props.BoolProperty(name="Selected Bones", description="Affect only selected bones", default=True, options={'HIDDEN'})
|
||||
handletype: bpy.props.BoolProperty(name="Keep handle types", description="Keep handle types", default=False, options={'HIDDEN'})
|
||||
scale: bpy.props.FloatProperty(name="Scale Factor", description="Scale percentage of the average value", default=1.0, update = multikey.scale_value)
|
||||
randomness: bpy.props.FloatProperty(name="Randomness", description="Random Threshold of keyframes", default=0.1, min=0.0, max = 1.0, update = multikey.random_value)
|
||||
|
||||
class AnimToolBoxObjectSettings(bpy.types.PropertyGroup):
|
||||
|
||||
controlled: bpy.props.PointerProperty(name = 'Controlled Rig', description="Adding the rig object that is being controlled by the current object", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
controller: bpy.props.PointerProperty(name = 'Controller Rig', description="Adding the rig object that is used as the temp control object", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
ctrl_setups: bpy.props.CollectionProperty(type = TempCtrlsObjectSetups, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
ctrls_enabled: bpy.props.BoolProperty(name = 'Temp Ctrls Switch', description = "Enabling and Disabling Temp Ctrls influence", default = True)
|
||||
# influence: bpy.props.FloatProperty(name = "Influence Slider for the Temp Ctrls", description = "Switching the influence slider for the temp ctrls", default = 1, min = 0.0, max = 1.0)
|
||||
|
||||
#Used for Bake to Empties
|
||||
# org_id: bpy.props.IntProperty(name = "Originate ID", description = "ID number of the bone the ctrl originates from", override = {'LIBRARY_OVERRIDABLE'})
|
||||
setup_id: bpy.props.IntProperty(name = "Setup ID", description = "ID number of the current chain setup", override = {'LIBRARY_OVERRIDABLE'})
|
||||
root: bpy.props.BoolProperty(name = "Root Empty", description = "Empty is marked as the root ctrl", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
child: bpy.props.BoolProperty(name = "Child Empty", description = "Empty is marked as a child bone inside the setup", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
keyframes_offset: bpy.props.FloatProperty(name = "Keyframes Offset", description = "Interactive slider to offset keyframes back and forth ", default = 0)
|
||||
|
||||
class IsolatedRigs(bpy.types.PropertyGroup):
|
||||
|
||||
hidden: bpy.props.PointerProperty(name = "Hidden Rigs", description = "List of Rigs that are hidden during pose mode isolation", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
selected: bpy.props.PointerProperty(name = "Selected Rigs", description = "List of Rigs that are hidden during pose mode isolation", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class AnimToolBoxUILayout(bpy.types.PropertyGroup):
|
||||
'''Layout properties for the UI'''
|
||||
quick_menu: bpy.props.BoolProperty(name = "Use Quick Menu", description = "Opens header menu with only icon", default = False)
|
||||
copy_paste_matrix: bpy.props.BoolProperty(name = "Copy Matrix Menu", description = "Opens the menu for copy paste matrices", default = True)
|
||||
copy_paste_world: bpy.props.BoolProperty(name = "Copy Paste World Matrix", description = "Copy and Paste the World Matrix", default = False, update = Tools.copy_paste_world_update)
|
||||
copy_paste_relative: bpy.props.BoolProperty(name = "Copy Paste Relative Matrix", description = "Copy and Paste the Matrix relative to the active bone", default = False, update = Tools.copy_paste_relative_update)
|
||||
Inbetweens: bpy.props.BoolProperty(name = "Blendings/Inbetweens", description = "Opens the menu for Inbetweens", default = True)
|
||||
gizmo_size: bpy.props.BoolProperty(name = "Gizmo size", description = "Change the Gizmo size using alt +/- hotkeys", default = False)
|
||||
# temp_ctrls: bpy.props.BoolProperty(name = "Temp Ctrls", description = "Open Temp Ctrls", default = False)
|
||||
temp_ctrls_switch: bpy.props.BoolProperty(name = "Temp Ctrls Switch", description = "Temp Ctrls Switch", default = True)
|
||||
temp_ctrls_shapes: bpy.props.BoolProperty(name = "Temp Ctrls Shapes", description = "Temp Ctrls Shapes", default = True)
|
||||
|
||||
markers_retimer: bpy.props.BoolProperty(name = "Marker Retimer", description = "Flag when marker retimer turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
relative_cursor: bpy.props.BoolProperty(name = "Relative Cursor Mode", description = "Cursor moves relative to the selection", default = False)
|
||||
|
||||
is_dragging: bpy.props.BoolProperty(default = False)
|
||||
#using Blending sliders in the window manager to avoid undo issues with modal operators
|
||||
inbetween_worldmatrix: bpy.props.FloatProperty(name='Inbetween World Matrix', description="Adds an inbetween of the World Matrix to the Layer's neighbor keyframes", soft_min = -1, soft_max = 1, default=0.0, update = Tools.add_inbetween_worldmatrix, override = {'LIBRARY_OVERRIDABLE'})
|
||||
blend_mirror: bpy.props.FloatProperty(name='Blend Mirror', description="Blend into the mirrored pose", soft_min = 0, soft_max = 1, default=0, step = 1, update = Tools.blend_to_mirror, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
multikey: bpy.props.PointerProperty(type = MultikeyProperties, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
class AnimToolBoxGlobalSettings(bpy.types.PropertyGroup):
|
||||
#context.scene.animtoolbox
|
||||
marker_frame_range: bpy.props.BoolProperty(name = "Marker Frame Range", description = "Flag when marker frame range turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bake_frame_range: bpy.props.BoolProperty(name = "Bake Frame Range", description = "Flag when marker bake range turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
# markers_retimer: bpy.props.BoolProperty(name = "Marker Retimer", description = "Flag when marker retimer turned on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
keyframes_offset: bpy.props.FloatProperty(name = "Keyframes Offset", description = "Interactive slider to offset keyframes back and forth ", soft_max = 2, soft_min = -2, default = 0, update = Tools.keyframes_offset_slider)
|
||||
rotation_mode: bpy.props.EnumProperty(name = 'Rotation Mode', description="Describes what kind of setup the bone is part of", override = {'LIBRARY_OVERRIDABLE'},
|
||||
items = [('QUATERNION', 'Quaternion','Quaternion Rotation Order - No Gimbal Lock', 0),
|
||||
('XYZ', 'XYZ', 'XYZ Rotation Order', 1), ('XZY', 'XZY','XZY Rotation Order', 2),
|
||||
('YXZ', 'YXZ','YXZ Rotation Order', 3), ('YZX', 'YZX', 'YZX Rotation Order', 4),
|
||||
('ZXY', 'ZXY', 'ZXY Rotation Order', 5), ('ZYX', 'ZYX', 'ZYX Rotation Order', 6),
|
||||
('AXIS_ANGLE', 'AXIS_ANGLE', 'Axis Angle Rotation Order', 7)])
|
||||
|
||||
isolate_pose_mode: bpy.props.BoolProperty(name = "Isolate rig in pose mode", description = "Isolates the rig during pose mode, rigs in object mode are hidden", default = False)
|
||||
active_obj: bpy.props.PointerProperty(name = "Active Object", description = "Current Active Object", type=bpy.types.Object, override = {'LIBRARY_OVERRIDABLE'})
|
||||
isolated: bpy.props.CollectionProperty(type = IsolatedRigs, override = {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
|
||||
|
||||
#Blendings
|
||||
inbetweener : bpy.props.FloatProperty(name='Inbetween Keyframe', description="Adds an inbetween Keyframe between the Layer's neighbor keyframes", soft_min = -1, soft_max = 1, default=0.0, options = set(), update = Tools.add_inbetween_key, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
motion_path: bpy.props.BoolProperty(name = "Motion Path", description = "Flag when Motion Path is on", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_settings: bpy.props.BoolProperty(name = "Motion Path Settings", description = "Open the settings Menu", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_keyframe_scale: bpy.props.FloatProperty(name = "Scale Selecgted Keyframes Bounding Box", description = "Change the scale of the bounding box around the selected keyframes ", default = 0.1, step = 0.1, precision = 3)
|
||||
mp_color_before: bpy.props.FloatVectorProperty(name="Motion Path Before Color", subtype='COLOR', default=(1.0, 0.0, 0.0), min=0.0, max=1.0, description="Motion path color before the current frame")
|
||||
mp_color_after: bpy.props.FloatVectorProperty(name="Motion Path After Color", subtype='COLOR', default=(0.0, 1.0, 0.0), min=0.0, max=1.0, description="Motion path color before the current frame")
|
||||
mp_infront: bpy.props.BoolProperty(name = "Motion Path In Front", description = "Display motion path in front of all the objects", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_points: bpy.props.BoolProperty(name = "Motion Path Points", description = "Display motion path points", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_lines: bpy.props.BoolProperty(name = "Motion Path Lines", description = "Display motion path lines", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_handles: bpy.props.BoolProperty(name = "Motion Path Handles", description = "Display motion path handles on keyframe selection", default = True, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_display_frames: bpy.props.BoolProperty(name = "Frame Numbers", description = "Display frame numbers on all the keyframes", default = False, override = {'LIBRARY_OVERRIDABLE'})
|
||||
mp_handle_types: bpy.props.EnumProperty(name = 'Set Keyframe Handle Type', description="Set handle type for selected keyframes", default = 'AUTO', update = emp.update_handle_type_prop,
|
||||
items = [('FREE', 'Free', 'Free', 'HANDLE_FREE', 0),
|
||||
('ALIGNED','Aligned', 'Aligned', 'HANDLE_ALIGNED', 1),
|
||||
('VECTOR', 'Vector', 'Vector', 'HANDLE_VECTOR', 2),
|
||||
('AUTO','Automatic', 'Automatic', 'HANDLE_AUTO', 3),
|
||||
('AUTO_CLAMPED','Auto Clamped', 'Auto Clamped', 'HANDLE_AUTOCLAMPED', 4)])
|
||||
|
||||
mp_interpolation: bpy.props.EnumProperty(name = 'Set Interpolation', description="Set Keyframe Interpolation", default = 'BEZIER', update = emp.update_interpolation_prop,
|
||||
items = [('BEZIER', 'Bezier', 'Bezier', 'IPO_BEZIER', 0),
|
||||
('LINEAR','Linear', 'Linear', 'IPO_LINEAR', 1),
|
||||
('CONSTANT', 'Constant', 'Constant', 'IPO_CONSTANT', 2)])
|
||||
|
||||
mp_frame_range: bpy.props.EnumProperty(name = 'Frame Range', description="Type of Frame Range", default = 'SCENE', #update = emp.mp_frame_range_update,
|
||||
items = [('KEYS_ALL', 'All_Keys','Use the Scene Frame Length for the Range', 0),
|
||||
('SCENE', 'Scene','Use the Scene Frame Length for the Range', 1),
|
||||
('MANUAL', 'Manual','Custom Frame range using numerical input or the markers frame ranger', 2),
|
||||
('AROUND', 'Around Frames','Show only around the current frame', 3)])
|
||||
mp_before: bpy.props.IntProperty(name = "Before", description = "Show the frames Before the current frame", min = 0, default = 10)
|
||||
mp_after: bpy.props.IntProperty(name = "After", description = "Show the frames After the current frame", min = 0, default = 10)
|
||||
selected_keyframes: bpy.props.StringProperty(name="Selected Keyframes", description="Serialized representation of selected keyframes")
|
||||
|
||||
gizmo_size: bpy.props.IntProperty(name = "Add to Gizmo Size", description = "Addition to Gizmo Size", max = 100, min = -100, default = 10)
|
||||
|
||||
#Copy/Pase Matrix
|
||||
range_type: bpy.props.EnumProperty(name = 'Paste to Frames', description="Paste to current frame or a range of frames.", update = Tools.bake_range_type,
|
||||
items = [('CURRENT', 'Current Frame','Paste Matrix to only current frame', 0),
|
||||
('SELECTED', 'Selected Keyframe','Paste Matrix to only selected keyframes', 1),
|
||||
('RANGE', 'Frame Range','Paste Matrix to a Frame Range', 2)])
|
||||
bake_frame_start: bpy.props.IntProperty(name = "Bake Frame Start", description = "Define the start frame to paste the matrix", min = 0, update = Tools.bake_frame_start_limit)
|
||||
bake_frame_end: bpy.props.IntProperty(name = "Bake Frame End", description = "Define the end frame to paste the matrix", min = 0, update = Tools.bake_frame_end_limit)
|
||||
|
||||
filter_location: bpy.props.BoolVectorProperty(name="Location", description="Filter Location properties", default=(False, False, False), size = 3, options={'HIDDEN'}, update = Tools.filter_name_update)
|
||||
filter_rotation: bpy.props.BoolVectorProperty(name="Rotation", description="Filter Rotation properties", default=(False, False, False, False), size = 4, options={'HIDDEN'}, update = Tools.filter_name_update)
|
||||
filter_scale: bpy.props.BoolVectorProperty(name="Scale", description="Filter Scale properties", default=(False, False, False), size = 3, options={'HIDDEN'}, update = Tools.filter_name_update)
|
||||
#The name displayed on the filter button
|
||||
filter_name: bpy.props.StringProperty(name="Filter Name", description="Change the name of the button while chaging the filter options", default= "", options={'HIDDEN'})
|
||||
filter_custom_props: bpy.props.BoolProperty(name = "Filter Custom Properties", description = "Filter custom properties", default = False)
|
||||
filter_keyframes: bpy.props.BoolProperty(name = "Filter Aelected Keyframes", description = "Filter selected keyframes for specific tools", default = False)
|
||||
|
||||
col_vis: bpy.props.BoolProperty(name = "Animated collections visibility", description = "Display if animated collections are turned on or off", default = False)
|
||||
|
||||
@addon_updater_ops.make_annotations
|
||||
class AnimToolBoxPreferences(bpy.types.AddonPreferences):
|
||||
# this must match the addon name, use '__package__'
|
||||
# when defining this in a submodule of a python package.
|
||||
bl_idname = __package__
|
||||
|
||||
category: bpy.props.StringProperty(
|
||||
name="Tab Category",
|
||||
description="Choose a name for the category of the panel",
|
||||
default="Animation",
|
||||
update=ui.update_panel
|
||||
)
|
||||
|
||||
quick_menu: bpy.props.BoolProperty(name = "Use Quick Menu", description = "Opens header menu with only icon", default = False)
|
||||
riggertoolbox: bpy.props.BoolProperty(name = "RiggerToolBox", description = "Include RiggerToolbox (experimental)", default = False, update = ui.add_riggertoolbox)
|
||||
multikey: bpy.props.BoolProperty(name = "Multikey", description = "Include Multikey for adju\sting multiply keyframes", default = False, update = ui.add_multikey)
|
||||
|
||||
#Temp Ctrls properties
|
||||
in_front: bpy.props.BoolProperty(name = "Always In Front", description = "Set Temp Ctrls to be always in front", default = True)
|
||||
clear_setup : bpy.props.BoolProperty(name = "Clear Selection Before Creating New Temp Ctrls", description = "Clear old setup when adding Temp ctrls to an existing chain", default = False)
|
||||
|
||||
#Editable motion path
|
||||
keyframes_range: bpy.props.IntProperty(name = "Keyframe Range", description = "The range of distance from the keyframes while hovering over them", min = 5, max = 100, default = 15)
|
||||
|
||||
# addon updater preferences from `__init__`, be sure to copy all of them
|
||||
auto_check_update: bpy.props.BoolProperty(
|
||||
name = "Auto-check for Update",
|
||||
description = "If enabled, auto-check for updates using an interval",
|
||||
default = True,
|
||||
)
|
||||
|
||||
updater_interval_months: bpy.props.IntProperty(
|
||||
name='Months',
|
||||
description = "Number of months between checking for updates",
|
||||
default=0,
|
||||
min=0
|
||||
)
|
||||
updater_interval_days: bpy.props.IntProperty(
|
||||
name='Days',
|
||||
description = "Number of days between checking for updates",
|
||||
default=7,
|
||||
min=0,
|
||||
|
||||
)
|
||||
updater_interval_hours: bpy.props.IntProperty(
|
||||
name='Hours',
|
||||
description = "Number of hours between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=23
|
||||
)
|
||||
updater_interval_minutes: bpy.props.IntProperty(
|
||||
name='Minutes',
|
||||
description = "Number of minutes between checking for updates",
|
||||
default=0,
|
||||
min=0,
|
||||
max=59
|
||||
)
|
||||
|
||||
#Draw the UI in the preferences
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
addon_updater_ops.update_settings_ui(self, context)
|
||||
|
||||
row = layout.row()
|
||||
col = row.column()
|
||||
|
||||
col.label(text="Tab Category:")
|
||||
col.prop(self, "category", text="")
|
||||
|
||||
layout.separator()
|
||||
col = layout.column()
|
||||
col.prop(self, "quick_menu", text="Use Quick Icons Menu")
|
||||
|
||||
layout.separator()
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
row.label(text = 'Temp Ctrls: ')
|
||||
row = box.row()
|
||||
row.prop(self, 'clear_setup')
|
||||
row.prop(self, 'in_front')
|
||||
|
||||
layout.separator()
|
||||
col = layout.column()
|
||||
col.label(text = 'Include Extras: ')
|
||||
row = layout.row()
|
||||
row.prop(self, "multikey", text="Multikey - Edit Multiply keyframes")
|
||||
row.prop(self, "riggertoolbox", text="RiggerToolBox (Experimental)")
|
||||
|
||||
@persistent
|
||||
def loadanimtoolbox_pre(self, context):
|
||||
scene = bpy.context.scene
|
||||
dns = bpy.app.driver_namespace
|
||||
if scene.animtoolbox.bake_frame_range:
|
||||
scene.animtoolbox.bake_frame_range = False
|
||||
|
||||
if scene.animtoolbox.motion_path:
|
||||
scene.animtoolbox.motion_path = False
|
||||
if 'mp_dh' in dns:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(dns['mp_dh'], 'WINDOW')
|
||||
bpy.app.driver_namespace.pop('mp_dh')
|
||||
|
||||
if 'markers_retimer_dh' in dns:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(dns['markers_retimer_dh'], 'WINDOW')
|
||||
bpy.app.driver_namespace.pop('markers_retimer_dh')
|
||||
|
||||
#remove the motion path app handler if it's still inside
|
||||
if emp.mp_value_update in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.remove(emp.mp_value_update)
|
||||
if emp.mp_frame_change in bpy.app.handlers.frame_change_post:
|
||||
bpy.app.handlers.frame_change_post.remove(emp.mp_frame_change)
|
||||
if emp.mp_undo_update in bpy.app.handlers.undo_pre:
|
||||
bpy.app.handlers.undo_pre.remove(emp.mp_undo_update)
|
||||
|
||||
@persistent
|
||||
def loadanimtoolbox_post(self, context):
|
||||
scene = bpy.context.scene
|
||||
dns = bpy.app.driver_namespace
|
||||
if scene.animtoolbox.isolate_pose_mode:
|
||||
if Display.isolate_pose_mode not in bpy.app.handlers.depsgraph_update_pre:
|
||||
bpy.app.handlers.depsgraph_update_pre.append(Display.isolate_pose_mode)
|
||||
|
||||
if scene.animtoolbox.motion_path:
|
||||
scene.animtoolbox.motion_path = False
|
||||
if 'mp_dh' in dns:
|
||||
bpy.types.SpaceView3D.draw_handler_remove(dns['mp_dh'], 'WINDOW')
|
||||
bpy.app.driver_namespace.pop('mp_dh')
|
||||
|
||||
Tools.selection_order(self, context)
|
||||
|
||||
classes = (TempCtrlsItems, TempCtrlsObjectSetups, TempCtrlsSceneSettings,TempCtrlsBoneSettings, MultikeyProperties, IsolatedRigs,
|
||||
AnimToolBoxObjectSettings, AnimToolBoxUILayout, AnimToolBoxGlobalSettings) + ui.classes
|
||||
|
||||
addon_keymaps = []
|
||||
|
||||
def register():
|
||||
# Note that preview collections returned by bpy.utils.previews
|
||||
# are regular py objects - you can use them to store custom data.
|
||||
|
||||
addon_updater_ops.register(bl_info)
|
||||
register_class(AnimToolBoxPreferences)
|
||||
addon_updater_ops.make_annotations(AnimToolBoxPreferences) # to avoid blender 2.8 warnings
|
||||
TempCtrls.register()
|
||||
Tools.register()
|
||||
Display.register()
|
||||
emp.register()
|
||||
|
||||
ui.register_custom_icon()
|
||||
|
||||
for cls in classes:
|
||||
# print(cls)
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.Scene.btc = bpy.props.PointerProperty(type = TempCtrlsSceneSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.PoseBone.btc = bpy.props.PointerProperty(type = TempCtrlsBoneSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Object.animtoolbox = bpy.props.PointerProperty(type = AnimToolBoxObjectSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.Scene.animtoolbox = bpy.props.PointerProperty(type = AnimToolBoxGlobalSettings, override = {'LIBRARY_OVERRIDABLE'})
|
||||
bpy.types.WindowManager.atb_ui = bpy.props.PointerProperty(type = AnimToolBoxUILayout, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
ui.update_panel(None, bpy.context)
|
||||
ui.add_multikey(None, bpy.context)
|
||||
ui.add_riggertoolbox(None, bpy.context)
|
||||
|
||||
if loadanimtoolbox_pre not in bpy.app.handlers.load_pre:
|
||||
bpy.app.handlers.load_pre.append(loadanimtoolbox_pre)
|
||||
if loadanimtoolbox_post not in bpy.app.handlers.load_post:
|
||||
bpy.app.handlers.load_post.append(loadanimtoolbox_post)
|
||||
|
||||
if Tools.selection_order not in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.append(Tools.selection_order)
|
||||
|
||||
#Make sure TAB hotkey in the NLA goes into full stack mode
|
||||
wm = bpy.context.window_manager
|
||||
kc = wm.keyconfigs.addon
|
||||
km = kc.keymaps.new(name= '3D View', space_type= 'VIEW_3D')
|
||||
if 'view3d.gizmo_size_up' not in km.keymap_items:
|
||||
kmi = km.keymap_items.new('view3d.gizmo_size_up', type= 'NUMPAD_PLUS', value= 'PRESS', alt = True, repeat = True)
|
||||
addon_keymaps.append((km, kmi))
|
||||
if 'view3d.gizmo_size_down' not in km.keymap_items:
|
||||
kmi = km.keymap_items.new('view3d.gizmo_size_down', type= 'NUMPAD_MINUS', value= 'PRESS', alt = True, repeat = True)
|
||||
addon_keymaps.append((km, kmi))
|
||||
|
||||
#Add Tools to the Toolbar
|
||||
bpy.utils.register_tool(ui.KeyframeOffsetTool, separator=True)
|
||||
|
||||
#Add tools to the menu
|
||||
bpy.types.VIEW3D_MT_editor_menus.append(ui.draw_menu)
|
||||
|
||||
def unregister():
|
||||
for pcoll in ui.preview_collections.values():
|
||||
bpy.utils.previews.remove(pcoll)
|
||||
ui.preview_collections.clear()
|
||||
|
||||
#addon_updater_ops.unregister()
|
||||
addon_updater_ops.unregister()
|
||||
unregister_class(AnimToolBoxPreferences)
|
||||
|
||||
TempCtrls.unregister()
|
||||
# Rigger_Toolbox.unregister()
|
||||
Tools.unregister()
|
||||
Display.unregister()
|
||||
emp.unregister()
|
||||
|
||||
ui.add_multikey(None, bpy.context)
|
||||
ui.add_riggertoolbox(None, bpy.context)
|
||||
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
|
||||
bpy.utils.unregister_tool(ui.KeyframeOffsetTool)
|
||||
|
||||
#Remove the header menu ui
|
||||
bpy.types.VIEW3D_MT_editor_menus.remove(ui.draw_menu)
|
||||
|
||||
del bpy.types.Scene.btc
|
||||
# del bpy.types.Bone.btc
|
||||
del bpy.types.Object.animtoolbox
|
||||
del bpy.types.Scene.animtoolbox
|
||||
if hasattr(bpy.types.Object, 'keyframes_offset'):
|
||||
del bpy.types.Object.keyframes_offset
|
||||
if hasattr(bpy.types.PoseBone, 'keyframes_offset'):
|
||||
del bpy.types.PoseBone.keyframes_offset
|
||||
|
||||
if loadanimtoolbox_pre in bpy.app.handlers.load_pre:
|
||||
bpy.app.handlers.load_pre.remove(loadanimtoolbox_pre)
|
||||
if loadanimtoolbox_post in bpy.app.handlers.load_post:
|
||||
bpy.app.handlers.load_post.remove(loadanimtoolbox_post)
|
||||
if Tools.selection_order in bpy.app.handlers.depsgraph_update_post:
|
||||
bpy.app.handlers.depsgraph_update_post.remove(Tools.selection_order)
|
||||
|
||||
for km, kmi in addon_keymaps:
|
||||
km.keymap_items.remove(kmi)
|
||||
addon_keymaps.clear()
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
+17
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"last_check": "2025-06-19 15:30:39.178174",
|
||||
"backup_date": "",
|
||||
"update_ready": true,
|
||||
"ignore": false,
|
||||
"just_restored": false,
|
||||
"just_updated": false,
|
||||
"version_text": {
|
||||
"link": "https://gitlab.com/api/v4/projects/45739913/repository/archive.zip?sha=198933935077e89aa87550163d3747388f2552e8",
|
||||
"version": [
|
||||
0,
|
||||
0,
|
||||
7,
|
||||
3
|
||||
]
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,527 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
import random
|
||||
import numpy as np
|
||||
from mathutils import Quaternion
|
||||
from . import Tools
|
||||
|
||||
def attr_default(obj, fcu_key):
|
||||
#check if the fcurve source belongs to a bone or obj
|
||||
if fcu_key[0][:10] == 'pose.bones':
|
||||
transform = fcu_key[0].split('.')[-1]
|
||||
attr = fcu_key[0].split('"')[-2]
|
||||
bone = fcu_key[0].split('"')[1]
|
||||
|
||||
if bone in obj.pose.bones:
|
||||
source = obj.pose.bones[bone]
|
||||
#if the bone not found still calculate the default based on the path
|
||||
elif '.rotation_quaternion' in fcu_key[0]:
|
||||
return [1.0, 0.0, 0.0, 0.0]
|
||||
elif '.scale' in fcu_key[0]:
|
||||
return [1.0, 1.0, 1.0]
|
||||
else:
|
||||
return [0]
|
||||
|
||||
#in case of shapekey animation
|
||||
elif fcu_key[0][:10] == 'key_blocks':
|
||||
attr = fcu_key[0].split('"')[1]
|
||||
if attr not in obj.data.shape_keys.key_blocks:
|
||||
return [0]
|
||||
shapekey = obj.data.shape_keys.key_blocks[attr]
|
||||
return 0 if shapekey.slider_min <= 0 else shapekey.slider_min
|
||||
#in case of transforms in object mode
|
||||
else:# fcu_key[0] in transform_types:
|
||||
source = obj
|
||||
transform = fcu_key[0]
|
||||
|
||||
#check when it's transform property of Blender
|
||||
if transform in source.bl_rna.properties.keys():
|
||||
if hasattr(source.bl_rna.properties[transform], 'default_array'):
|
||||
if len(source.bl_rna.properties[transform].default_array) > fcu_key[1]:
|
||||
attrvalue = source.bl_rna.properties[transform].default_array
|
||||
return attrvalue
|
||||
|
||||
#in case of property on object
|
||||
elif len(fcu_key[0].split('"')) > 1:
|
||||
if fcu_key[0].split('"')[1] in obj.keys():
|
||||
attr = fcu_key[0].split('"')[1]
|
||||
|
||||
if 'attr' not in locals():
|
||||
return [0]
|
||||
|
||||
#since blender 3 access to custom property settings changed
|
||||
if attr in source:
|
||||
if not isinstance(source[attr], float) and not isinstance(source[attr], int):
|
||||
return [0]
|
||||
id_attr = source.id_properties_ui(attr).as_dict()
|
||||
attrvalue = id_attr['default']
|
||||
return [attrvalue]
|
||||
|
||||
return [0]
|
||||
|
||||
def store_handles(key):
|
||||
#storing the distance between the handles bezier to the key value
|
||||
handle_r = key.handle_right[1] - key.co[1]
|
||||
handle_l = key.handle_left[1] - key.co[1]
|
||||
|
||||
return handle_r, handle_l
|
||||
|
||||
def apply_handles(key, handle_r, handle_l):
|
||||
key.handle_right[1] = key.co[1] + handle_r
|
||||
key.handle_left[1] = key.co[1] + handle_l
|
||||
|
||||
def selected_bones_filter(obj, fcu_data_path):
|
||||
if not bpy.context.window_manager.atb_ui.multikey.selectedbones:
|
||||
#if not obj.als.onlyselected:
|
||||
return False
|
||||
if obj.mode != 'POSE':
|
||||
return True
|
||||
transform_types = ['location', 'rotation_euler', 'rotation_quaternion', 'scale']
|
||||
#filter selected bones if option is turned on
|
||||
bones = [bone.path_from_id() for bone in bpy.context.selected_pose_bones]
|
||||
if fcu_data_path.split('].')[0]+']' not in bones and fcu_data_path not in transform_types:
|
||||
return True
|
||||
|
||||
# def filter_properties(obj, fcu):
|
||||
# 'Filter the W X Y Z attributes of the transform properties'
|
||||
# transform = fcu.data_path.split('"].')[1] if obj.mode == 'POSE' else fcu.data_path
|
||||
# index = fcu.array_index
|
||||
# if 'rotation' in transform:
|
||||
# if transform == 'rotation_euler':
|
||||
# index -= 1
|
||||
# transform = 'rotation'
|
||||
# transform = 'filter_' + transform
|
||||
# if not hasattr(bpy.context.scene.multikey, transform):
|
||||
# return False
|
||||
# attr = getattr(bpy.context.scene.multikey, transform)
|
||||
# #print(fcu.data_path, index, transform, attr[index])
|
||||
# return True if attr[index] else False
|
||||
|
||||
def add_value(key, value):
|
||||
if key.select_control_point:
|
||||
#store handle values in relative to the keyframe value
|
||||
handle_r, handle_l = store_handles(key)
|
||||
|
||||
key.co[1] += value
|
||||
apply_handles(key, handle_r, handle_l)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
def add_diff(fcurves, path, current_value, eval_array):
|
||||
array_value = current_value - eval_array
|
||||
if not any(array_value):
|
||||
return
|
||||
|
||||
for i, value in enumerate(array_value):
|
||||
fcu = fcurves.find(path, index = i)
|
||||
if fcu is None or Tools.filter_properties(bpy.context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value)
|
||||
fcu.update()
|
||||
|
||||
class ScaleValuesOp(bpy.types.Operator):
|
||||
"""Modal operator used while scale value is running before release"""
|
||||
bl_idname = "animtoolbox.multikey_scale_value"
|
||||
bl_label = "Scale Values"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
#reset the values for dragging
|
||||
self.stop = False
|
||||
ui = context.window_manager.atb_ui
|
||||
ui['is_dragging'] = True
|
||||
self.avg_value = dict()
|
||||
#dictionary of the keyframes and their original INITIAL values
|
||||
self.keyframes_values = dict()
|
||||
self.keyframes_handle_right = dict()
|
||||
self.keyframes_handle_left = dict()
|
||||
|
||||
#the average value for each fcurve
|
||||
self.keyframes_avg_value = dict()
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, obj.animation_data.action)
|
||||
for fcu in fcurves:
|
||||
if obj.mode == 'POSE':
|
||||
if selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
if Tools.filter_properties(context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
|
||||
#avg and value list per fcurve
|
||||
avg_value = []
|
||||
value_list = []
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
value_list.append(key.co[1])
|
||||
self.keyframes_values.update({key : key.co[1]})
|
||||
self.keyframes_handle_right.update({key : key.handle_right[1]})
|
||||
self.keyframes_handle_left.update({key : key.handle_left[1]})
|
||||
|
||||
if len(value_list)>1:
|
||||
#the average value with the scale property added to it
|
||||
avg_value = sum(value_list) / len(value_list)
|
||||
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
self.keyframes_avg_value.update({key : avg_value})
|
||||
|
||||
if not self.keyframes_avg_value:
|
||||
ui['is_dragging'] = False
|
||||
ui.multikey['scale'] = 1
|
||||
Tools.redraw_areas(['VIEW_3D'])
|
||||
return {'CANCELLED'}
|
||||
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
def modal(self, context, event):
|
||||
|
||||
ui = context.window_manager.atb_ui
|
||||
scale = ui.multikey.scale
|
||||
|
||||
#Quit the modal operator when the slider is released
|
||||
if self.stop:
|
||||
ui['is_dragging'] = False
|
||||
ui.multikey['scale'] = 1
|
||||
Tools.redraw_areas(['VIEW_3D'])
|
||||
#modal is being cancelled because of undo issue with the modal running through the property
|
||||
return {'FINISHED'}
|
||||
|
||||
if event.value == 'RELEASE': # Stop the modal on next frame. Don't block the event since we want to exit the field dragging
|
||||
self.stop = True
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
for key, key_value in self.keyframes_values.items():
|
||||
if not key.select_control_point:
|
||||
continue
|
||||
if key not in self.keyframes_avg_value:
|
||||
continue
|
||||
avg_value = self.keyframes_avg_value[key]
|
||||
handle_right_value = self.keyframes_handle_right[key]
|
||||
handle_left_value = self.keyframes_handle_left[key]
|
||||
|
||||
#add the value of the distance from the average * scale factor
|
||||
key.co[1] = avg_value + ((key_value - avg_value)*scale)
|
||||
key.handle_right[1] = avg_value + ((handle_right_value - avg_value)*scale)
|
||||
key.handle_left[1] = avg_value + ((handle_left_value - avg_value)*scale)
|
||||
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
def scale_value(self, context):
|
||||
|
||||
ui = context.window_manager.atb_ui
|
||||
if ui.is_dragging:
|
||||
return
|
||||
obj = context.object
|
||||
|
||||
if obj is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
action = obj.animation_data.action
|
||||
|
||||
if action is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
if context.mode == 'POSE' and not context.selected_pose_bones:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
bpy.ops.animtoolbox.multikey_scale_value('INVOKE_DEFAULT')
|
||||
|
||||
def random_value(self, context):
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, obj.animation_data.action)
|
||||
for fcu in fcurves:
|
||||
if obj.mode == 'POSE':
|
||||
if selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
if Tools.filter_properties(context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
value_list = []
|
||||
threshold = bpy.context.window_manager.atb_ui.multikey.randomness
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point == True:
|
||||
value_list.append(key.co[1])
|
||||
|
||||
if len(value_list) > 0:
|
||||
value = max(value_list)- min(value_list)
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value * random.uniform(-threshold, threshold))
|
||||
fcu.update()
|
||||
|
||||
def evaluate_combine(data_path, added_array, eval_array, array_default, influence):
|
||||
|
||||
if 'scale' in data_path:
|
||||
eval_array = eval_array * (added_array / array_default) ** influence
|
||||
elif 'rotation_quaternion' in data_path:
|
||||
#multiply first the influence with the w separatly
|
||||
added_array[0] = added_array[0] + (1- added_array[0])*(1 - influence)
|
||||
added_array[1:] *= influence
|
||||
eval_array = np.array(Quaternion(eval_array) @ Quaternion(added_array))# ** influence
|
||||
#if it's a custom property
|
||||
elif 'rotation_euler' not in data_path and 'location' not in data_path:
|
||||
eval_array = eval_array + (added_array - array_default) * influence
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_array(fcurves, fcu_path, frame, array_default = [0, 0, 0]):
|
||||
'''Create an array from all the indexes'''
|
||||
|
||||
array_len = len(array_default)
|
||||
fcu_array = []
|
||||
#get the missing arrays in case quaternion is not complete
|
||||
missing_arrays = []
|
||||
for i in range(array_len):
|
||||
fcu = fcurves.find(fcu_path, index = i)
|
||||
if fcu is None:
|
||||
missing_arrays.append(i)
|
||||
continue
|
||||
|
||||
fcu_array.append(fcu.evaluate(frame))
|
||||
|
||||
#In case it's a quaternion and missing attributes, then adding from default value
|
||||
if fcu_array and array_len == 4 and missing_arrays:
|
||||
for i in missing_arrays:
|
||||
fcu_array.insert(i, array_default[i])
|
||||
|
||||
if not len(fcu_array):
|
||||
return None
|
||||
return np.array(fcu_array)
|
||||
|
||||
def evaluate_layers(context, obj, anim_data, fcu, array_default):
|
||||
'''Calculate the evaluation of all the layers when using the nla'''
|
||||
|
||||
if not hasattr(anim_data, 'nla_tracks') or not anim_data.use_nla:
|
||||
return None
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return None
|
||||
frame = context.scene.frame_current
|
||||
blend_types = {'ADD' : '+', 'SUBTRACT' : '-', 'MULTIPLY' : '*'}
|
||||
fcu_path = fcu.data_path
|
||||
|
||||
eval_array = array_default
|
||||
|
||||
for track in nla_tracks:
|
||||
if track.mute:
|
||||
continue
|
||||
if not len(track.strips):
|
||||
continue
|
||||
for strip in track.strips:
|
||||
if not strip.frame_start < frame < strip.frame_end:
|
||||
continue
|
||||
action = strip.action
|
||||
if action is None:
|
||||
continue
|
||||
blend_type = strip.blend_type
|
||||
|
||||
#get the influence value either from the attribute or the fcurve. function coming from bake
|
||||
influence = strip.influence
|
||||
if len(strip.fcurves):
|
||||
if not strip.fcurves[0].mute and len(strip.fcurves[0].keyframe_points):
|
||||
influence = strip.fcurves[0].evaluate(frame)
|
||||
|
||||
#evaluate the frame according to the strip settings
|
||||
frame_eval = frame
|
||||
#change the frame if the strip is on hold
|
||||
if frame < strip.frame_start:
|
||||
if strip.extrapolation == 'HOLD':
|
||||
frame_eval = strip.frame_start
|
||||
elif frame >= strip.frame_end:
|
||||
if strip.extrapolation == 'HOLD' or strip.extrapolation == 'HOLD_FORWARD':
|
||||
frame_eval = strip.frame_end
|
||||
|
||||
last_frame = strip.frame_start + (strip.frame_end - strip.frame_start) / strip.repeat
|
||||
|
||||
if strip.repeat > 1 and (frame) >= last_frame:
|
||||
action_range = (strip.action_frame_end * strip.scale - strip.action_frame_start * strip.scale)
|
||||
frame_eval = (((frame_eval - strip.frame_start) % (action_range)) + strip.frame_start)
|
||||
|
||||
if strip.use_reverse:
|
||||
frame_eval = last_frame - (frame_eval - strip.frame_start)
|
||||
offset = (strip.frame_start * 1/strip.scale - strip.action_frame_start) * strip.scale
|
||||
frame_eval = strip.frame_start * 1/strip.scale + (frame_eval - strip.frame_start) * 1/strip.scale - offset * 1/strip.scale
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_blend_type(fcurves, eval_array, fcu_path, frame_eval, influence, array_default, blend_type, blend_types)
|
||||
|
||||
#Adding an extra layer from the action outside and on top of the nla
|
||||
tweak_mode = anim_data.use_tweak_mode
|
||||
if tweak_mode:
|
||||
anim_data.use_tweak_mode = False
|
||||
action = anim_data.action
|
||||
if action:
|
||||
influence = anim_data.action_influence
|
||||
blend_type = anim_data.action_blend_type
|
||||
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_blend_type(fcurves, eval_array, fcu_path, frame, influence, array_default, blend_type, blend_types)
|
||||
anim_data.use_tweak_mode = tweak_mode
|
||||
|
||||
return eval_array
|
||||
|
||||
|
||||
def evaluate_blend_type(fcurves, eval_array, fcu_path, frame, influence,
|
||||
array_default, blend_type, blend_types):
|
||||
'''Calculate the value based on the blend type'''
|
||||
|
||||
fcu_array = evaluate_array(fcurves, fcu_path, frame, array_default)
|
||||
if fcu_array is None:
|
||||
return eval_array
|
||||
###EVALUATION###
|
||||
if blend_type =='COMBINE':
|
||||
if 'location' in fcu_path or 'rotation_euler' in fcu_path:
|
||||
blend_type = 'ADD'
|
||||
if blend_type =='REPLACE':
|
||||
eval_array = eval_array * (1 - influence) + fcu_array * influence
|
||||
elif blend_type =='COMBINE':
|
||||
eval_array = evaluate_combine(fcu_path, fcu_array, eval_array, array_default, influence)
|
||||
else:
|
||||
eval_array = eval('eval_array' + blend_types[blend_type] + 'fcu_array' + '*' + str(influence))
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_value(self, context):
|
||||
ui = context.window_manager.atb_ui
|
||||
for obj in context.selected_objects:
|
||||
|
||||
anim_data = obj.animation_data
|
||||
if anim_data is None:
|
||||
return
|
||||
if anim_data.action is None:
|
||||
return
|
||||
|
||||
action = obj.animation_data.action
|
||||
fcu_paths = []
|
||||
transformations = ["rotation_quaternion","rotation_euler", "location", "scale"]
|
||||
if obj.mode == 'POSE':
|
||||
bonelist = context.selected_pose_bones if ui.multikey.selectedbones else obj.pose.bones
|
||||
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
for fcu in fcurves:
|
||||
if fcu in fcu_paths:
|
||||
continue
|
||||
if Tools.filter_properties(context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
if obj.mode == 'POSE':
|
||||
if selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
|
||||
for bone in bonelist:
|
||||
#find the fcurve of the bone
|
||||
if fcu.data_path.rfind(bone.name) != 12 or fcu.data_path[12 + len(bone.name)] != '"':
|
||||
continue
|
||||
path_split = fcu.data_path.split('"].')
|
||||
|
||||
if len(path_split) <= 1:
|
||||
continue
|
||||
else:
|
||||
transform = fcu.data_path.split('"].')[1]
|
||||
if transform not in transformations:
|
||||
continue
|
||||
current_value = getattr(obj.pose.bones[bone.name], transform)
|
||||
else:
|
||||
transform = fcu.data_path
|
||||
current_value = getattr(obj, transform)
|
||||
|
||||
array_default = np.array(attr_default(obj, (fcu.data_path, fcu.array_index)))
|
||||
# array_default = np.array([attr_default(obj, (fcu.data_path, i)) for i in range(4)
|
||||
# if fcurves.find(fcu.data_path, index = i) is not None])
|
||||
eval_array = evaluate_layers(context, obj, anim_data, fcu, array_default)
|
||||
if eval_array is None:
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_array(fcurves, fcu.data_path, context.scene.frame_current, array_default)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
add_diff(fcurves, fcu.data_path, np.array(current_value), eval_array)
|
||||
|
||||
class MULTIKEY_OT_Multikey(bpy.types.Operator):
|
||||
"""Edit all selected keyframes"""
|
||||
bl_label = "Edit Selected Keyframes"
|
||||
bl_idname = "animtoolbox.multikey"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object and context.active_object.animation_data and bpy.context.scene.tool_settings.use_keyframe_insert_auto == False
|
||||
|
||||
def execute(self, context):
|
||||
evaluate_value(self, context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class MultikeyProperties(bpy.types.PropertyGroup):
|
||||
|
||||
selectedbones: bpy.props.BoolProperty(name="Selected Bones", description="Affect only selected bones", default=True, options={'HIDDEN'})
|
||||
handletype: bpy.props.BoolProperty(name="Keep handle types", description="Keep handle types", default=False, options={'HIDDEN'})
|
||||
scale: bpy.props.FloatProperty(name="Scale Factor", description="Scale percentage of the average value", default=1.0, update = scale_value)
|
||||
randomness: bpy.props.FloatProperty(name="Randomness", description="Random Threshold of keyframes", default=0.1, min=0.0, max = 1.0, update = random_value)
|
||||
|
||||
#filters
|
||||
# filter_location: bpy.props.BoolVectorProperty(name="Location", description="Filter Location properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
# filter_rotation: bpy.props.BoolVectorProperty(name="Rotation", description="Filter Rotation properties", default=(True, True, True, True), size = 4, options={'HIDDEN'})
|
||||
# filter_scale: bpy.props.BoolVectorProperty(name="Scale", description="Filter Scale properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
|
||||
# class FilterProperties(bpy.types.Operator):
|
||||
# """Filter Location Rotation and Scale Properties"""
|
||||
# bl_idname = "fcurves.filter"
|
||||
# bl_label = "Filter Properties W X Y Z"
|
||||
# bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
# def invoke(self, context, event):
|
||||
# wm = context.window_manager
|
||||
# return wm.invoke_props_dialog(self, width = 200)
|
||||
|
||||
# def draw(self, context):
|
||||
# layout = self.layout
|
||||
# row = layout.row()
|
||||
# row.label(text = 'Location')
|
||||
# row.prop(context.scene.multikey, 'filter_location', text = '')
|
||||
# row = layout.row()
|
||||
# row.label(text = 'Rotation')
|
||||
# row.prop(context.scene.multikey, 'filter_rotation', text = '')
|
||||
# row = layout.row()
|
||||
# row.label(text = 'Scale')
|
||||
# row.prop(context.scene.multikey, 'filter_scale', text = '')
|
||||
|
||||
# def execute(self, context):
|
||||
# return {'CANCELLED'}
|
||||
|
||||
classes = (ScaleValuesOp, MULTIKEY_OT_Multikey)
|
||||
|
||||
#register, unregister = bpy.utils.register_classes_factory(classes)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
# bpy.types.Scene.animtoolbox.multikey = bpy.props.PointerProperty(type = MultikeyProperties, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
# del bpy.types.Scene.animtoolbox.multikey
|
||||
@@ -0,0 +1,700 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
from . import Rigger_Toolbox
|
||||
from . import multikey
|
||||
from . import Rigger_Toolbox
|
||||
from pathlib import Path
|
||||
from bpy.utils import register_class
|
||||
from bpy.utils import unregister_class
|
||||
import os
|
||||
|
||||
######################################################## MENUS ########################################################
|
||||
|
||||
class ANIMTOOLBOX_MT_Copy_Paste_Matrix(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Copy_Paste_Matrix'
|
||||
bl_label = "Copy Paste Matrix"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator('anim.copy_matrix', text = 'Copy World Matrix', icon ='DUPLICATE')
|
||||
layout.operator('anim.paste_matrix', text = 'Paste World Matrix', icon ='PASTEDOWN')
|
||||
layout.separator()
|
||||
layout.operator('anim.copy_relative_matrix', text = 'Copy Relative Matrix', icon ='DUPLICATE')
|
||||
layout.operator('anim.paste_relative_matrix', text = 'Paste Relative Matrix', icon ='PASTEDOWN')
|
||||
layout.separator()
|
||||
layout.prop_menu_enum(context.scene.animtoolbox, 'range_type', text = 'Frame Range Type')
|
||||
if context.scene.animtoolbox.range_type == 'RANGE':
|
||||
# split = layout.split(factor = 0.3)
|
||||
# layout.prop(context.scene.animtoolbox, 'bake_frame_start', text = 'Start')
|
||||
# layout.prop(context.scene.animtoolbox, 'bake_frame_end', text = 'End')
|
||||
layout.operator("anim.markers_bakerange", icon = 'MARKER', text ='Frame Range Markers Widget', depress = context.scene.animtoolbox.bake_frame_range)
|
||||
|
||||
class ANIMTOOLBOX_MT_Temp_Ctrls(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Temp_Ctrls'
|
||||
bl_label = "Temp Ctrls"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
custom_icons = preview_collections["main"]
|
||||
layout.operator('anim.bake_to_ctrl', text="World Space Ctrls", icon = 'WORLD')
|
||||
layout.operator('anim.bake_to_temp_fk', text="Temp FK Ctrls", icon = 'BONE_DATA')
|
||||
layout.operator('anim.bake_to_temp_ik', text="Temp IK Ctrls", icon = 'CON_KINEMATIC')
|
||||
layout.separator()
|
||||
layout.operator('anim.link_temp_chains', text="Link Temp Chains", icon = 'DECORATE_LINKED')
|
||||
layout.operator('anim.unlink_temp_chains', text="UnLink Temp Chains", icon = 'DECORATE_LINKED')
|
||||
layout.separator()
|
||||
layout.operator('anim.bake_temp_ctrls', text="Bake Temp Ctrls", icon_value = custom_icons["oven"].icon_id)
|
||||
layout.operator('anim.remove_bones_constraints', text="Cleanup", icon_value = custom_icons["trash"].icon_id)
|
||||
layout.prop_menu_enum(context.scene.btc, 'target', text = 'Bake To', icon = 'MOD_ARMATURE')
|
||||
layout.separator()
|
||||
|
||||
ctrl = context.object.animtoolbox.controller if context.object.animtoolbox.controller else context.object
|
||||
if ctrl:
|
||||
layout.prop(ctrl.animtoolbox, 'ctrls_enabled', text ='Temp Ctrls On/Off')
|
||||
|
||||
# layout.operator('anim.enable_tempctrls', text="On" , icon = 'HIDE_OFF')#icon = 'CONSTRAINT_BONE'
|
||||
# layout.operator('anim.disable_tempctrls', text="Off", icon = 'HIDE_ON')
|
||||
layout.separator()
|
||||
layout.prop_menu_enum(context.scene.btc, 'shape_type', icon = 'MESH_DATA')
|
||||
layout.prop(context.scene.btc, 'shape_size', slider = False, icon ='CON_SIZELIKE')
|
||||
layout.prop(context.scene.btc, 'color_set', text = '')
|
||||
# layout.prop(context.scene.btc, 'shape_type', icon = 'MESH_DATA', text ='')
|
||||
|
||||
class ANIMTOOLBOX_MT_Keyframe_Offset(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Keyframe_Offset'
|
||||
bl_label = "Interactive Keyframe Offset"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.prop(context.scene.animtoolbox, 'keyframes_offset', slider = False)
|
||||
layout.operator('anim.select_keyframes_offset', text="Select Offset Keyframes", icon ='RESTRICT_SELECT_OFF')
|
||||
layout.operator('anim.apply_keyframes_offset', text="Apply Offset", icon = 'ANIM')
|
||||
|
||||
class ANIMTOOLBOX_MT_Blendings(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Blendings'
|
||||
bl_label = "Blendings"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
layout.prop(ui, 'inbetween_worldmatrix', slider = True)
|
||||
layout.prop(context.scene.animtoolbox, 'inbetweener', slider = True)
|
||||
layout.prop(ui, 'blend_mirror', slider = True)
|
||||
|
||||
class ANIMTOOLBOX_MT_Multikey(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Multikey'
|
||||
bl_label = "Multikey"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
layout.operator("animtoolbox.multikey", icon = 'ACTION_TWEAK')
|
||||
layout.prop(ui.multikey, 'scale', slider = True)
|
||||
layout.prop(ui.multikey, 'randomness', slider = True)
|
||||
|
||||
class ANIMTOOLBOX_MT_Convert_Rotations(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Convert_Rotations'
|
||||
bl_label = "Convert Rotations"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator("anim.convert_rotation_mode", icon = 'DRIVER_ROTATIONAL_DIFFERENCE', text = 'Convert Rotation To')
|
||||
layout.operator("anim.find_rotation_mode", icon = 'VIEWZOOM', text = 'Recommend Euler Rotation')
|
||||
layout.prop_menu_enum(context.scene.animtoolbox, 'rotation_mode', text = 'Convert To')
|
||||
|
||||
class ANIMTOOLBOX_MT_operators(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_menu_operators'
|
||||
bl_label = "AnimToolBox"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
ui = context.window_manager.atb_ui
|
||||
custom_icons = preview_collections["main"]
|
||||
|
||||
if context.area.type == 'VIEW_3D':
|
||||
layout.menu('ANIMTOOLBOX_MT_Temp_Ctrls', text = 'Temp Ctrls', icon_value = custom_icons["puppet"].icon_id)
|
||||
layout.separator()
|
||||
layout.operator('anim.share_keyframes', text = 'Share Keyframes', icon_value = custom_icons["sharekeys"].icon_id)
|
||||
layout.operator('anim.relative_cursor', text = 'Relative Cursor Pivot', icon_value = custom_icons["relative_cursor"].icon_id, depress = ui.relative_cursor)
|
||||
layout.operator("anim.markers_retimer", icon_value = custom_icons["retime"].icon_id, text ='Markers Retimer', depress = ui.markers_retimer)
|
||||
layout.menu('ANIMTOOLBOX_MT_Convert_Rotations', text = 'Convert Rotations', icon = 'DRIVER_ROTATIONAL_DIFFERENCE')
|
||||
|
||||
layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Keyframe_Offset', text = 'Interactive Keyframe Offset', icon_value = custom_icons["keyframe_offset"].icon_id)
|
||||
layout.menu('ANIMTOOLBOX_MT_Blendings', text = 'Blendings and inbetweens', icon_value = custom_icons["sliders"].icon_id)
|
||||
layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Copy_Paste_Matrix', text = 'Copy Paste Matrix', icon_value = custom_icons["copy_matrix"].icon_id)
|
||||
|
||||
if bpy.context.preferences.addons[__package__].preferences.multikey:
|
||||
layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Multikey', text = 'Multikey', icon_value = custom_icons["multikey"].icon_id)
|
||||
|
||||
layout.separator(factor = 0.5)
|
||||
layout.operator('anim.switch_collections_visibility', icon = 'COLLECTION_COLOR_06', text = 'Animated Collections Visibilty')
|
||||
layout.operator('anim.isolate_pose_mode', icon_value = custom_icons["isolate"].icon_id, depress = scene.animtoolbox.isolate_pose_mode)
|
||||
layout.operator('object.motion_path_operator', text = 'Editable Motion Path', depress = scene.animtoolbox.motion_path, icon_value = custom_icons["mt"].icon_id)
|
||||
layout.separator()
|
||||
layout.prop(context.preferences.addons[__package__].preferences, 'quick_menu', text = 'Use Quick Icons Menu')
|
||||
# layout.prop(context.window_manager.atb_ui, 'quick_menu', text = 'Use Quick Icons Menu')
|
||||
# elif context.area.type == 'DOPESHEET_EDITOR':
|
||||
# layout.operator('wm.call_menu_pie', text="Pie AnimOffset").name = 'ANIMAIDE_MT_pie_anim_offset'
|
||||
# layout.menu('ANIMAIDE_MT_anim_offset')
|
||||
# layout.menu('ANIMAIDE_MT_anim_offset_mask')
|
||||
|
||||
# elif context.area.type == 'GRAPH_EDITOR':
|
||||
# layout.menu('ANIMAIDE_MT_curve_tools_pie')
|
||||
|
||||
######################################################## WorkSpaceTools ########################################################
|
||||
|
||||
class KeyframeOffsetTool(bpy.types.WorkSpaceTool):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_context_mode = 'POSE'
|
||||
bl_idname = 'animtoolbox.keyframe_offset'
|
||||
bl_label = 'Keyframe Offset Tool'
|
||||
bl_description = (
|
||||
'Offset the keyframes of the selected bone\n'
|
||||
'Shift + Click to select the bones with an offset\n'
|
||||
'Ctrl + Alt + Click to Apply the offset'
|
||||
)
|
||||
bl_icon = (Path(__file__).parent / "icons" / "ops.anim.keyframe_offset").as_posix()
|
||||
bl_keymap = (
|
||||
('anim.keyframe_offset', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG'}, None),
|
||||
# ('anim.select_keyframes_offset', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'shift': True}, None),
|
||||
('anim.apply_keyframes_offset', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'ctrl': True, 'alt': True}, None),
|
||||
|
||||
('view3d.select_box', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG', 'shift': True}, {'properties': [('mode', 'ADD')]}),
|
||||
('view3d.select_box', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG', 'ctrl': True}, {'properties': [('mode', 'SUB')]}),
|
||||
('view3d.select_box', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG', 'shift': True, 'ctrl': True}, {'properties': [('mode', 'AND')]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK'}, {'properties': [('deselect_all', True)]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'shift': True}, {'properties': [('toggle', True)]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'alt': True}, {'properties': [('enumerate', True)]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'shift': True, 'alt': True}, {'properties': [('toggle', True), ('enumerate', True)]})
|
||||
|
||||
)
|
||||
|
||||
######################################################## PANELS ########################################################
|
||||
class ANIMTOOLBOX_PT_Panel:
|
||||
bl_space_type = "VIEW_3D"
|
||||
bl_region_type = "UI"
|
||||
bl_category = "Animation"
|
||||
#bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.object is not None
|
||||
|
||||
class ANIMTOOLBOX_PT_MainPanel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
#bl_category = "Animation"
|
||||
bl_label = "AnimToolBox"
|
||||
bl_idname = "ANIMTOOLBOX_PT_MainPanel"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
self.layout.label(text='', icon_value = custom_icons["animtoolbox"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
if obj is None:
|
||||
return
|
||||
# layout = self.layout
|
||||
# row = layout.row(align = True)
|
||||
|
||||
# row.label(text = 'Support me on ')
|
||||
# row.operator("wm.url_open", text="Patreon", icon = 'FUND').url = "https://www.patreon.com/animtoolbox"
|
||||
|
||||
class TEMPCTRLS_PT_Panel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
#bl_category = "Animation"
|
||||
bl_label = "Temp Controls"
|
||||
bl_idname = "TEMPCTRLS_PT_Panel"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
self.layout.label(text="", icon_value = custom_icons["puppet"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
btc = context.scene.btc
|
||||
if obj is None:
|
||||
return
|
||||
custom_icons = preview_collections["main"]
|
||||
oven_icon = custom_icons["oven"]
|
||||
# row = layout.row()
|
||||
ui = context.window_manager.atb_ui
|
||||
layout = self.layout
|
||||
box = layout.box()
|
||||
col = box.column()
|
||||
col.operator('anim.bake_to_ctrl', text="WorldSpace Ctrls", icon ='WORLD') #
|
||||
col.operator('anim.bake_to_temp_fk', text="Temp FK Ctrls", icon = 'BONE_DATA')
|
||||
col.operator('anim.bake_to_temp_ik', text="Temp IK Ctrls", icon = 'CON_KINEMATIC')
|
||||
|
||||
# layout.separator(factor = 0.1)
|
||||
# box = layout.box()
|
||||
row = box.row()
|
||||
row.operator('anim.link_temp_chains', text="Link Temp Chains", icon = 'DECORATE_LINKED')
|
||||
row.prop(btc, 'linksettings', text = '', icon = 'SETTINGS')
|
||||
|
||||
if btc.linksettings:
|
||||
# insidebox = box.box()
|
||||
row = box.row()
|
||||
row.label(text = 'Link to Active Chain: ')
|
||||
row.prop(btc, 'link_to', text = '')
|
||||
row = box.row()
|
||||
row.operator('anim.unlink_temp_chains', text="UnLink Temp Chains", icon = 'UNLINKED')
|
||||
# row = insidebox.row()
|
||||
# row.label(text = 'Link from Chain: ')
|
||||
# row.prop(btc, 'link_from', text = '')
|
||||
# layout.separator(factor = 0.1)
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
row.operator('anim.bake_to_empties', text="WorldSpace Empties")
|
||||
row.operator('anim.empties_to_bones', text="", icon = 'EMPTY_AXIS')
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
# row.operator('anim.bake_constrained_bones', text="Quick Bake", icon = 'REC')
|
||||
row.operator('anim.bake_temp_ctrls', text="Bake Temp Ctrls", icon_value = oven_icon.icon_id)
|
||||
row.prop(btc, 'bakesettings', text = '', icon = 'SETTINGS')
|
||||
|
||||
if btc.bakesettings:
|
||||
insidebox = box.box()
|
||||
# split = insidebox.split(factor = 0.9)
|
||||
# split.prop(btc, 'smartbake', text = 'Smart Bake')
|
||||
# split.operator('fcurves.filter_ui', icon ='FILTER', text = '')
|
||||
# if btc.smartbake:
|
||||
# row.prop(btc, 'inbetween_keyframes')
|
||||
split = insidebox.split(factor = 0.3)
|
||||
split.label(text = 'Bake To:')
|
||||
# split.split(factor = 0.9)
|
||||
split_2 = split.split(factor = 0.9)
|
||||
split_2.prop(btc, 'target', text = '')
|
||||
split_2.operator('fcurves.filter_ui', icon ='FILTER', text = '')
|
||||
|
||||
split = insidebox.split(factor = 0.3)
|
||||
split.label(text = 'Bake Range:')
|
||||
split.prop(btc, 'bake_range_type', text = '')
|
||||
|
||||
if btc.bake_range_type == 'KEYFRAMES':
|
||||
row = insidebox.row()
|
||||
row.label(text = 'Keyframes: ')
|
||||
row.prop(btc, 'smartbake', text = 'Smart Bake')
|
||||
row.prop(btc, 'bake_layers', text = 'All Layers')
|
||||
row = insidebox.row()
|
||||
row.label(text = 'From:')
|
||||
row.prop(btc, 'from_origin', text = 'Origin')
|
||||
row.prop(btc, 'from_ctrl', text = 'Ctrls')
|
||||
|
||||
elif btc.bake_range_type == 'CUSTOM':
|
||||
row = insidebox.row()
|
||||
row.prop(btc, 'bake_range', text = '')
|
||||
|
||||
insidebox.separator(factor=0.1)
|
||||
row = insidebox.row()
|
||||
row.label(text = 'Clean: ')
|
||||
row.prop(btc, 'clean_constraints', text = 'Constraints')
|
||||
if btc.clean_constraints:
|
||||
row.prop(btc, 'clean_ctrls', text = 'Ctrls')
|
||||
|
||||
row = box.row()
|
||||
row.operator('anim.remove_bones_constraints', text="Cleanup", icon_value = custom_icons["trash"].icon_id)
|
||||
row.prop(btc, 'cleansettings', text = '', icon = 'SETTINGS')
|
||||
|
||||
if btc.cleansettings:
|
||||
insidebox = box.box()
|
||||
split = insidebox.split(factor = 0.4)
|
||||
split.label(text = 'Target: ')
|
||||
split.prop(btc, 'target', text = '')
|
||||
row = insidebox.row()
|
||||
row.label(text = 'Clean: ')
|
||||
row.prop(btc, 'clean_constraints', text = 'Constraints')
|
||||
if btc.clean_constraints:
|
||||
row.prop(btc, 'clean_ctrls', text = 'Ctrls')
|
||||
if btc.target == 'SELECTED':
|
||||
split = insidebox.split(factor = 0.68)
|
||||
split.label(text = 'ReBake Link Ctrls to Original: ')
|
||||
split.prop(btc, 'rebake_to_org', text = '')
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
# row = layout.row()
|
||||
|
||||
# row.prop(obj.animtoolbox, 'influence', text = 'Influence', slider = True)
|
||||
ctrl = obj.animtoolbox.controller if obj.animtoolbox.controller else obj
|
||||
if ctrl:
|
||||
enabled_icon = 'HIDE_OFF' if ctrl.animtoolbox.ctrls_enabled else 'HIDE_ON'
|
||||
row.prop(ctrl.animtoolbox, 'ctrls_enabled', text ='Temp Ctrls On/Off', icon = enabled_icon)
|
||||
# row = box.row()
|
||||
# row.prop(ui, 'temp_ctrls_switch', icon = 'RESTRICT_VIEW_OFF', text = '')
|
||||
# row.label(text = 'Temp Ctrls Switch: ')
|
||||
# row.prop(btc, 'target', text = '', icon = 'MOD_ARMATURE', icon_only = True)
|
||||
# if ui.temp_ctrls_switch:
|
||||
# # split = layout.split(factor = 0.225)
|
||||
# row = box.row()
|
||||
# row.operator('anim.enable_tempctrls', text="On" , icon = 'HIDE_OFF')#icon = 'CONSTRAINT_BONE'
|
||||
# row.operator('anim.disable_tempctrls', text="Off", icon = 'HIDE_ON')
|
||||
|
||||
box.separator(factor=0.1)
|
||||
row = box.row()
|
||||
row.prop(ui, 'temp_ctrls_shapes', icon = 'MESH_DATA', text = '')
|
||||
row.label(text = 'Temp Ctrls Shapes: ')
|
||||
row.prop(btc, 'target', text = '', icon = 'MOD_ARMATURE', icon_only = True)
|
||||
if ui.temp_ctrls_shapes:
|
||||
row = box.row()
|
||||
row.prop(btc, 'shape_size', slider = False)
|
||||
row.prop(btc, 'shape_type', text = '')
|
||||
row = layout.row()
|
||||
# split.label(text = 'Theme Color: ')
|
||||
row.prop(btc, 'color_set', text = '')
|
||||
|
||||
layout.separator()
|
||||
row = layout.row()
|
||||
row.operator('anim.btc_selections', text="Select", icon = 'CONSTRAINT_BONE')
|
||||
row.prop(btc, 'selection', text = '', icon = 'CON_ARMATURE')
|
||||
|
||||
class ANIMTOOLBOX_PT_Tools(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
bl_label = "Anim Tools"
|
||||
bl_idname = "ANIMTOOLBOX_PT_Tools"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
layout.label(text="", icon_value = custom_icons["toolbox"].icon_id)
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
scene = context.scene
|
||||
atb = scene.animtoolbox
|
||||
if obj is None:
|
||||
return
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
row = layout.row()
|
||||
filter_text = 'Filter Tools Properties' if atb.filter_name == '' else 'Filters: ' + atb.filter_name
|
||||
filter_depress = False if atb.filter_name == '' else True
|
||||
row.operator('fcurves.filter_ui', icon ='FILTER', text = filter_text, depress = filter_depress)
|
||||
layout.separator()
|
||||
#layout.operator('anim.keyframes_offset', text="Offset Keyframes", icon = 'NEXT_KEYFRAME')
|
||||
split = layout.split(factor = 0.9)
|
||||
split.prop(context.scene.animtoolbox, 'keyframes_offset', slider = True)
|
||||
split.operator('anim.apply_keyframes_offset', text="", icon_value = custom_icons["apply"].icon_id)
|
||||
split.operator('anim.select_keyframes_offset', text="", icon_value = custom_icons["select"].icon_id)
|
||||
row = layout.row()
|
||||
row.operator('anim.share_keyframes', text = 'Share Keyframes', icon_value = custom_icons["sharekeys"].icon_id)
|
||||
row = layout.row()
|
||||
row.operator("anim.relative_cursor", text ='Relative Cursor Pivot', icon_value = custom_icons["relative_cursor"].icon_id, depress = ui.relative_cursor)
|
||||
row = layout.row()
|
||||
row.operator("anim.markers_retimer", icon_value = custom_icons["retime"].icon_id, text ='Markers Retimer', depress = ui.markers_retimer)
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
box = layout.box()
|
||||
# icon = 'DOWNARROW_HLT' if ui.copy_paste_matrix is True else 'RIGHTARROW_THIN'
|
||||
# split = box.split(factor = 0.9)
|
||||
# split.prop(ui, 'copy_paste_matrix', icon_value = custom_icons["copy_matrix"].icon_id, text = 'Copy Paste Matrices')
|
||||
# split.operator('fcurves.filter', icon ='FILTER', text = '')
|
||||
row = box.row()
|
||||
row.prop(ui, 'copy_paste_matrix', icon_value = custom_icons["copy_matrix"].icon_id, text = 'Copy Paste Matrices')
|
||||
if ui.copy_paste_matrix:
|
||||
row = box.row()
|
||||
row.label(text = 'Copy World Matrix :', icon = 'WORLD')
|
||||
row.operator('anim.copy_matrix', text = '', icon ='DUPLICATE')
|
||||
row.operator('anim.paste_matrix', text = '', icon ='PASTEDOWN')
|
||||
row = box.row()
|
||||
row.label(text = 'Copy Relative Matrix :', icon = 'LINKED')
|
||||
row.operator('anim.copy_relative_matrix', text = '', icon ='DUPLICATE')
|
||||
row.operator('anim.paste_relative_matrix', text = '', icon ='PASTEDOWN')
|
||||
split = box.split(factor = 0.32)
|
||||
split.label(text = 'Paste To')
|
||||
split.prop(context.scene.animtoolbox, 'range_type', text = '')
|
||||
if context.scene.animtoolbox.range_type == 'RANGE':
|
||||
row = box.row()
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_start', text = 'Start')
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_end', text = 'End')
|
||||
row.operator("anim.markers_bakerange", icon = 'MARKER', text ='', depress = context.scene.animtoolbox.bake_frame_range)
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
box = layout.box()
|
||||
# icon = 'DOWNARROW_HLT' if ui.Inbetweens is True else 'RIGHTARROW_THIN'
|
||||
# split = box.split(factor = 0.9)
|
||||
# split.prop(ui, 'Inbetweens', icon_value = custom_icons["sliders"].icon_id, text = 'Blendings / Inbetweens')
|
||||
# split.operator('fcurves.filter', icon ='FILTER', text = '')
|
||||
row = box.row()
|
||||
row.prop(ui, 'Inbetweens', icon_value = custom_icons["sliders"].icon_id, text = 'Blendings / Inbetweens')
|
||||
|
||||
if ui.Inbetweens:
|
||||
col = box.column()
|
||||
col.prop(ui, 'inbetween_worldmatrix', slider = True)
|
||||
col.prop(scene.animtoolbox, 'inbetweener', slider = True)
|
||||
col.prop(ui, 'blend_mirror', slider = True)
|
||||
|
||||
layout.separator(factor = 1)
|
||||
# my_icon = custom_icons["rotations"]
|
||||
split = layout.split(factor = 0.6)
|
||||
split.operator("anim.convert_rotation_mode", icon = 'DRIVER_ROTATIONAL_DIFFERENCE', text = 'Convert Rotation To')
|
||||
# split.operator("anim.convert_rotation_mode", text = 'Convert Rotation To', icon_value = my_icon.icon_id)
|
||||
split = split.split(factor = 0.3)
|
||||
split.operator("anim.find_rotation_mode", icon = 'VIEWZOOM', text = '')
|
||||
split.prop(context.scene.animtoolbox, 'rotation_mode', text = '')
|
||||
|
||||
class MULTIKEY_PT_Panel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
"""Add random value to selected keyframes"""
|
||||
bl_label = "Multikey"
|
||||
bl_idname = "MULTIKEY_PT_Panel"
|
||||
# bl_space_type = 'VIEW_3D'
|
||||
# bl_region_type = 'UI'
|
||||
# bl_category= 'Animation'
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_Tools'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
layout.label(text="", icon_value = custom_icons["multikey"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
# layout.separator()
|
||||
split = layout.split(factor=0.1, align = True)
|
||||
split.prop(ui.multikey, 'selectedbones', icon_value = custom_icons["selected_bones"].icon_id, text = '')
|
||||
# split = split.split(factor=0.1, align = True)
|
||||
#split.operator('fcurves.filter', icon ='FILTER', text = '')
|
||||
split.operator("animtoolbox.multikey", icon = 'ACTION_TWEAK')
|
||||
layout.separator()
|
||||
row = layout.row(align = True)
|
||||
row.prop(ui.multikey, 'scale')
|
||||
row.prop(ui.multikey, 'randomness', slider = True)
|
||||
|
||||
class ANIMTOOLBOX_PT_Display(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
bl_label = "Display"
|
||||
bl_idname = "ANIMTOOLBOX_PT_Display"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
self.layout.label(text="", icon_value = custom_icons["display"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
scene = context.scene
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
custom_icons = preview_collections["main"]
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
icon = 'DOWNARROW_HLT' if ui.gizmo_size is True else 'RIGHTARROW_THIN'
|
||||
row.prop(ui, 'gizmo_size', icon = icon, text = 'Add to Gizmo Size:')
|
||||
if ui.gizmo_size:
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'gizmo_size', text = '')
|
||||
row.operator('view3d.gizmo_size_up', text="", icon ='ADD')
|
||||
row.operator('view3d.gizmo_size_down', text="", icon ='REMOVE')
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
row = layout.row()
|
||||
col_vis_icon = 'OUTLINER_COLLECTION' if scene.animtoolbox.col_vis else 'COLLECTION_COLOR_06'
|
||||
row.operator('anim.switch_collections_visibility', icon = col_vis_icon, text = 'Animated Collections Visibilty', depress = scene.animtoolbox.col_vis)
|
||||
layout.separator(factor = 0.5)
|
||||
row = layout.row()
|
||||
row.operator('anim.isolate_pose_mode', icon_value = custom_icons["isolate"].icon_id, depress = scene.animtoolbox.isolate_pose_mode)
|
||||
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
row.operator('object.motion_path_operator', text = 'Editable Motion Path', depress = scene.animtoolbox.motion_path, icon_value = custom_icons["mt"].icon_id)
|
||||
row.prop(scene.animtoolbox, 'mp_settings', text = '', icon = 'SETTINGS')
|
||||
if scene.animtoolbox.mp_settings:
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_color_before', text = '')
|
||||
row.prop(scene.animtoolbox, 'mp_color_after', text = '')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_keyframe_scale', text = 'Scale Keyframes Box', icon = 'CUBE')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_points', text = 'Points')
|
||||
row.prop(scene.animtoolbox, 'mp_lines', text = 'Lines')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_handles', text = 'Handles')
|
||||
row.prop(scene.animtoolbox, 'mp_infront', text = 'In Front')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_display_frames', text = 'Display Keyframe Numbers')
|
||||
row = box.row()
|
||||
row.prop(context.preferences.addons[__package__].preferences, 'keyframes_range', text = 'Keyframe Distance Range')
|
||||
if context.object is None:
|
||||
return
|
||||
|
||||
split = box.split(factor = 0.4)
|
||||
split.label(text ='Frame Range')
|
||||
# row.prop(scene.animtoolbox, 'mp_frame_range', text = '')
|
||||
|
||||
split.prop(context.scene.animtoolbox, 'mp_frame_range', text = '')
|
||||
if context.scene.animtoolbox.mp_frame_range == 'MANUAL':
|
||||
row = box.row()
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_start', text = 'Start')
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_end', text = 'End')
|
||||
row.operator("anim.markers_bakerange", icon = 'MARKER', text ='', depress = scene.animtoolbox.bake_frame_range)
|
||||
|
||||
elif context.scene.animtoolbox.mp_frame_range == 'AROUND':
|
||||
row = box.row()
|
||||
row.prop(context.scene.animtoolbox, 'mp_before', text = 'Before')
|
||||
row.prop(context.scene.animtoolbox, 'mp_after', text = 'After')
|
||||
# row.operator("anim.markers_bakerange", icon = 'MARKER', text ='', depress = scene.animtoolbox.bake_frame_range)
|
||||
|
||||
|
||||
class RIGGERTOOLBOX_PT_Panel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
bl_label = "Rigger Toolbox"
|
||||
bl_idname = "RIGGERTOOLBOX_PT_Panel"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
if obj is None:
|
||||
return
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
col.operator("armature.add_bbone_widgets", text = "Add Bbone Widgets", icon = 'IPO_BEZIER')
|
||||
col.separator()
|
||||
col.operator("armature.add_chain_ctrls", text = "Add Chain Controls", icon = 'OUTLINER_DATA_ARMATURE')
|
||||
col.separator()
|
||||
col.operator("armature.merge", text = "Merge Rigs", icon = 'MOD_ARMATURE')
|
||||
|
||||
# Add-ons Preferences Update Panel
|
||||
# Define Panel classes for updating
|
||||
panels = [ANIMTOOLBOX_PT_MainPanel, TEMPCTRLS_PT_Panel, ANIMTOOLBOX_PT_Tools, ANIMTOOLBOX_PT_Display]
|
||||
|
||||
def update_panel(self, context):
|
||||
message = "Animtoolbox: Updating Panel locations has failed"
|
||||
try:
|
||||
for panel in panels:
|
||||
if "bl_rna" in panel.__dict__:
|
||||
unregister_class(panel)
|
||||
|
||||
for panel in panels:
|
||||
panel.bl_category = context.preferences.addons[__package__].preferences.category
|
||||
register_class(panel)
|
||||
|
||||
except Exception as e:
|
||||
print("\n[{}]\n{}\n\nError:\n{}".format(__package__, message, e))
|
||||
pass
|
||||
|
||||
def add_multikey(self, context):
|
||||
if bpy.context.preferences.addons[__package__].preferences is None:
|
||||
return
|
||||
if bpy.context.preferences.addons[__package__].preferences.multikey:
|
||||
multikey.register()
|
||||
register_class(MULTIKEY_PT_Panel)
|
||||
register_class(ANIMTOOLBOX_MT_Multikey)
|
||||
panels.append(MULTIKEY_PT_Panel)
|
||||
#panels = panels + (MULTIKEY_PT_Panel)
|
||||
elif hasattr(bpy.types, 'MULTIKEY_PT_Panel'):
|
||||
multikey.unregister()
|
||||
panels.remove(MULTIKEY_PT_Panel)
|
||||
unregister_class(MULTIKEY_PT_Panel)
|
||||
unregister_class(ANIMTOOLBOX_MT_Multikey)
|
||||
|
||||
def add_riggertoolbox(self, context):
|
||||
if bpy.context.preferences.addons[__package__].preferences is None:
|
||||
return
|
||||
if bpy.context.preferences.addons[__package__].preferences.riggertoolbox:
|
||||
Rigger_Toolbox.register()
|
||||
register_class(RIGGERTOOLBOX_PT_Panel)
|
||||
panels.append(RIGGERTOOLBOX_PT_Panel)
|
||||
#panels = panels + (RIGGERTOOLBOX_PT_Panel)
|
||||
elif hasattr(bpy.types, 'RIGGERTOOLBOX_PT_Panel'):
|
||||
Rigger_Toolbox.unregister()
|
||||
panels.remove(RIGGERTOOLBOX_PT_Panel)
|
||||
unregister_class(RIGGERTOOLBOX_PT_Panel)
|
||||
|
||||
classes = (ANIMTOOLBOX_MT_Copy_Paste_Matrix, ANIMTOOLBOX_MT_Temp_Ctrls, ANIMTOOLBOX_MT_operators, ANIMTOOLBOX_MT_Keyframe_Offset,
|
||||
ANIMTOOLBOX_MT_Blendings, ANIMTOOLBOX_MT_Convert_Rotations) + tuple(panels)
|
||||
|
||||
preview_collections = {}
|
||||
#list of all the custom icons
|
||||
icons_list = {'relative_cursor' : 'relative_cursor.png', 'puppet' : 'puppet.png', 'animtoolbox' : 'animtoolbox.png',
|
||||
'sliders' : 'slider-navigation.png', 'world_space' : 'earth-rotation.png', 'isolate' : 'isolation.png',
|
||||
'mt' : 'curve.png', 'toolbox' : 'tools.png', 'oven' : 'oven.png', 'retime' : 'retime.png', 'copy_matrix' : 'copy_world.png',
|
||||
'sharekeys' : 'sharekeys.png', 'sliders' : 'sliders.png', 'keyframe_offset' : 'keyframes_offset.png', 'display' : 'display.png',
|
||||
'switch' : 'switch.png', 'trash' : 'trash.png', 'apply' : 'apply.png', 'select' : 'select.png', 'worldspace' : 'WorldSpace.png',
|
||||
'multikey' : 'multikey.png', 'selected_bones' : 'selected_bones.png'}
|
||||
|
||||
def register_custom_icon():
|
||||
# Note that preview collections returned by bpy.utils.previews
|
||||
# are regular py objects - you can use them to store custom data.
|
||||
import bpy.utils.previews
|
||||
custom_icons = bpy.utils.previews.new()
|
||||
# path to the folder where the icon is
|
||||
# the path is calculated relative to this py file inside the addon folder
|
||||
icons_dir = os.path.join(os.path.dirname(__file__), "icons")
|
||||
# load a preview thumbnail of a file and store in the previews collection
|
||||
for iconname, icon_file in icons_list.items():
|
||||
custom_icons.load(iconname, os.path.join(icons_dir, icon_file), 'IMAGE')
|
||||
preview_collections["main"] = custom_icons
|
||||
|
||||
def draw_menu(self, context):
|
||||
if context.mode == 'OBJECT' or context.mode == 'POSE':
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
ui = context.window_manager.atb_ui
|
||||
|
||||
custom_icons = preview_collections["main"]
|
||||
layout.menu('ANIMTOOLBOX_MT_menu_operators') #, icon_value = custom_icons["toolbox"].icon_id, text =''
|
||||
|
||||
if not context.preferences.addons[__package__].preferences.quick_menu:
|
||||
return
|
||||
#Only Icons Menu
|
||||
temp_ctrls = custom_icons["puppet"]
|
||||
layout.menu('ANIMTOOLBOX_MT_Temp_Ctrls' , icon_value = temp_ctrls.icon_id, text ='')
|
||||
# layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Copy_Paste_Matrix' , icon_value = custom_icons["copy_matrix"].icon_id, text ='')
|
||||
|
||||
layout.separator()
|
||||
layout.operator('anim.relative_cursor', text = '', depress = ui.relative_cursor, icon_value = custom_icons["relative_cursor"].icon_id)
|
||||
|
||||
layout.separator()
|
||||
layout.operator('anim.markers_retimer', text = '', depress = ui.markers_retimer, icon_value = custom_icons["retime"].icon_id)
|
||||
|
||||
layout.separator()
|
||||
layout.operator('anim.isolate_pose_mode', text = '', depress = scene.animtoolbox.isolate_pose_mode, icon_value = custom_icons["isolate"].icon_id)
|
||||
|
||||
layout.separator()
|
||||
layout.operator('object.motion_path_operator', text = '', depress = scene.animtoolbox.motion_path, icon_value = custom_icons["mt"].icon_id)
|
||||
BIN
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,527 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
import random
|
||||
import numpy as np
|
||||
from mathutils import Quaternion
|
||||
from . import Tools
|
||||
|
||||
def attr_default(obj, fcu_key):
|
||||
#check if the fcurve source belongs to a bone or obj
|
||||
if fcu_key[0][:10] == 'pose.bones':
|
||||
transform = fcu_key[0].split('.')[-1]
|
||||
attr = fcu_key[0].split('"')[-2]
|
||||
bone = fcu_key[0].split('"')[1]
|
||||
|
||||
if bone in obj.pose.bones:
|
||||
source = obj.pose.bones[bone]
|
||||
#if the bone not found still calculate the default based on the path
|
||||
elif '.rotation_quaternion' in fcu_key[0]:
|
||||
return [1.0, 0.0, 0.0, 0.0]
|
||||
elif '.scale' in fcu_key[0]:
|
||||
return [1.0, 1.0, 1.0]
|
||||
else:
|
||||
return [0]
|
||||
|
||||
#in case of shapekey animation
|
||||
elif fcu_key[0][:10] == 'key_blocks':
|
||||
attr = fcu_key[0].split('"')[1]
|
||||
if attr not in obj.data.shape_keys.key_blocks:
|
||||
return [0]
|
||||
shapekey = obj.data.shape_keys.key_blocks[attr]
|
||||
return 0 if shapekey.slider_min <= 0 else shapekey.slider_min
|
||||
#in case of transforms in object mode
|
||||
else:# fcu_key[0] in transform_types:
|
||||
source = obj
|
||||
transform = fcu_key[0]
|
||||
|
||||
#check when it's transform property of Blender
|
||||
if transform in source.bl_rna.properties.keys():
|
||||
if hasattr(source.bl_rna.properties[transform], 'default_array'):
|
||||
if len(source.bl_rna.properties[transform].default_array) > fcu_key[1]:
|
||||
attrvalue = source.bl_rna.properties[transform].default_array
|
||||
return attrvalue
|
||||
|
||||
#in case of property on object
|
||||
elif len(fcu_key[0].split('"')) > 1:
|
||||
if fcu_key[0].split('"')[1] in obj.keys():
|
||||
attr = fcu_key[0].split('"')[1]
|
||||
|
||||
if 'attr' not in locals():
|
||||
return [0]
|
||||
|
||||
#since blender 3 access to custom property settings changed
|
||||
if attr in source:
|
||||
if not isinstance(source[attr], float) and not isinstance(source[attr], int):
|
||||
return [0]
|
||||
id_attr = source.id_properties_ui(attr).as_dict()
|
||||
attrvalue = id_attr['default']
|
||||
return [attrvalue]
|
||||
|
||||
return [0]
|
||||
|
||||
def store_handles(key):
|
||||
#storing the distance between the handles bezier to the key value
|
||||
handle_r = key.handle_right[1] - key.co[1]
|
||||
handle_l = key.handle_left[1] - key.co[1]
|
||||
|
||||
return handle_r, handle_l
|
||||
|
||||
def apply_handles(key, handle_r, handle_l):
|
||||
key.handle_right[1] = key.co[1] + handle_r
|
||||
key.handle_left[1] = key.co[1] + handle_l
|
||||
|
||||
def selected_bones_filter(obj, fcu_data_path):
|
||||
if not bpy.context.window_manager.atb_ui.multikey.selectedbones:
|
||||
#if not obj.als.onlyselected:
|
||||
return False
|
||||
if obj.mode != 'POSE':
|
||||
return True
|
||||
transform_types = ['location', 'rotation_euler', 'rotation_quaternion', 'scale']
|
||||
#filter selected bones if option is turned on
|
||||
bones = [bone.path_from_id() for bone in bpy.context.selected_pose_bones]
|
||||
if fcu_data_path.split('].')[0]+']' not in bones and fcu_data_path not in transform_types:
|
||||
return True
|
||||
|
||||
# def filter_properties(obj, fcu):
|
||||
# 'Filter the W X Y Z attributes of the transform properties'
|
||||
# transform = fcu.data_path.split('"].')[1] if obj.mode == 'POSE' else fcu.data_path
|
||||
# index = fcu.array_index
|
||||
# if 'rotation' in transform:
|
||||
# if transform == 'rotation_euler':
|
||||
# index -= 1
|
||||
# transform = 'rotation'
|
||||
# transform = 'filter_' + transform
|
||||
# if not hasattr(bpy.context.scene.multikey, transform):
|
||||
# return False
|
||||
# attr = getattr(bpy.context.scene.multikey, transform)
|
||||
# #print(fcu.data_path, index, transform, attr[index])
|
||||
# return True if attr[index] else False
|
||||
|
||||
def add_value(key, value):
|
||||
if key.select_control_point:
|
||||
#store handle values in relative to the keyframe value
|
||||
handle_r, handle_l = store_handles(key)
|
||||
|
||||
key.co[1] += value
|
||||
apply_handles(key, handle_r, handle_l)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
def add_diff(fcurves, path, current_value, eval_array):
|
||||
array_value = current_value - eval_array
|
||||
if not any(array_value):
|
||||
return
|
||||
|
||||
for i, value in enumerate(array_value):
|
||||
fcu = fcurves.find(path, index = i)
|
||||
if fcu is None or Tools.filter_properties(bpy.context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value)
|
||||
fcu.update()
|
||||
|
||||
class ScaleValuesOp(bpy.types.Operator):
|
||||
"""Modal operator used while scale value is running before release"""
|
||||
bl_idname = "animtoolbox.multikey_scale_value"
|
||||
bl_label = "Scale Values"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
#reset the values for dragging
|
||||
self.stop = False
|
||||
ui = context.window_manager.atb_ui
|
||||
ui['is_dragging'] = True
|
||||
self.avg_value = dict()
|
||||
#dictionary of the keyframes and their original INITIAL values
|
||||
self.keyframes_values = dict()
|
||||
self.keyframes_handle_right = dict()
|
||||
self.keyframes_handle_left = dict()
|
||||
|
||||
#the average value for each fcurve
|
||||
self.keyframes_avg_value = dict()
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, obj.animation_data.action)
|
||||
for fcu in fcurves:
|
||||
if obj.mode == 'POSE':
|
||||
if selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
if Tools.filter_properties(context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
|
||||
#avg and value list per fcurve
|
||||
avg_value = []
|
||||
value_list = []
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
value_list.append(key.co[1])
|
||||
self.keyframes_values.update({key : key.co[1]})
|
||||
self.keyframes_handle_right.update({key : key.handle_right[1]})
|
||||
self.keyframes_handle_left.update({key : key.handle_left[1]})
|
||||
|
||||
if len(value_list)>1:
|
||||
#the average value with the scale property added to it
|
||||
avg_value = sum(value_list) / len(value_list)
|
||||
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point:
|
||||
self.keyframes_avg_value.update({key : avg_value})
|
||||
|
||||
if not self.keyframes_avg_value:
|
||||
ui['is_dragging'] = False
|
||||
ui.multikey['scale'] = 1
|
||||
Tools.redraw_areas(['VIEW_3D'])
|
||||
return {'CANCELLED'}
|
||||
|
||||
context.window_manager.modal_handler_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
def modal(self, context, event):
|
||||
|
||||
ui = context.window_manager.atb_ui
|
||||
scale = ui.multikey.scale
|
||||
|
||||
#Quit the modal operator when the slider is released
|
||||
if self.stop:
|
||||
ui['is_dragging'] = False
|
||||
ui.multikey['scale'] = 1
|
||||
Tools.redraw_areas(['VIEW_3D'])
|
||||
#modal is being cancelled because of undo issue with the modal running through the property
|
||||
return {'FINISHED'}
|
||||
|
||||
if event.value == 'RELEASE': # Stop the modal on next frame. Don't block the event since we want to exit the field dragging
|
||||
self.stop = True
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
for key, key_value in self.keyframes_values.items():
|
||||
if not key.select_control_point:
|
||||
continue
|
||||
if key not in self.keyframes_avg_value:
|
||||
continue
|
||||
avg_value = self.keyframes_avg_value[key]
|
||||
handle_right_value = self.keyframes_handle_right[key]
|
||||
handle_left_value = self.keyframes_handle_left[key]
|
||||
|
||||
#add the value of the distance from the average * scale factor
|
||||
key.co[1] = avg_value + ((key_value - avg_value)*scale)
|
||||
key.handle_right[1] = avg_value + ((handle_right_value - avg_value)*scale)
|
||||
key.handle_left[1] = avg_value + ((handle_left_value - avg_value)*scale)
|
||||
|
||||
return {'PASS_THROUGH'}
|
||||
|
||||
def scale_value(self, context):
|
||||
|
||||
ui = context.window_manager.atb_ui
|
||||
if ui.is_dragging:
|
||||
return
|
||||
obj = context.object
|
||||
|
||||
if obj is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
action = obj.animation_data.action
|
||||
|
||||
if action is None:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
if context.mode == 'POSE' and not context.selected_pose_bones:
|
||||
self['scale'] = 1
|
||||
return
|
||||
|
||||
bpy.ops.animtoolbox.multikey_scale_value('INVOKE_DEFAULT')
|
||||
|
||||
def random_value(self, context):
|
||||
|
||||
for obj in context.selected_objects:
|
||||
if obj.animation_data.action is None:
|
||||
continue
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, obj.animation_data.action)
|
||||
for fcu in fcurves:
|
||||
if obj.mode == 'POSE':
|
||||
if selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
if Tools.filter_properties(context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
value_list = []
|
||||
threshold = bpy.context.window_manager.atb_ui.multikey.randomness
|
||||
for key in fcu.keyframe_points:
|
||||
if key.select_control_point == True:
|
||||
value_list.append(key.co[1])
|
||||
|
||||
if len(value_list) > 0:
|
||||
value = max(value_list)- min(value_list)
|
||||
for key in fcu.keyframe_points:
|
||||
add_value(key, value * random.uniform(-threshold, threshold))
|
||||
fcu.update()
|
||||
|
||||
def evaluate_combine(data_path, added_array, eval_array, array_default, influence):
|
||||
|
||||
if 'scale' in data_path:
|
||||
eval_array = eval_array * (added_array / array_default) ** influence
|
||||
elif 'rotation_quaternion' in data_path:
|
||||
#multiply first the influence with the w separatly
|
||||
added_array[0] = added_array[0] + (1- added_array[0])*(1 - influence)
|
||||
added_array[1:] *= influence
|
||||
eval_array = np.array(Quaternion(eval_array) @ Quaternion(added_array))# ** influence
|
||||
#if it's a custom property
|
||||
elif 'rotation_euler' not in data_path and 'location' not in data_path:
|
||||
eval_array = eval_array + (added_array - array_default) * influence
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_array(fcurves, fcu_path, frame, array_default = [0, 0, 0]):
|
||||
'''Create an array from all the indexes'''
|
||||
|
||||
array_len = len(array_default)
|
||||
fcu_array = []
|
||||
#get the missing arrays in case quaternion is not complete
|
||||
missing_arrays = []
|
||||
for i in range(array_len):
|
||||
fcu = fcurves.find(fcu_path, index = i)
|
||||
if fcu is None:
|
||||
missing_arrays.append(i)
|
||||
continue
|
||||
|
||||
fcu_array.append(fcu.evaluate(frame))
|
||||
|
||||
#In case it's a quaternion and missing attributes, then adding from default value
|
||||
if fcu_array and array_len == 4 and missing_arrays:
|
||||
for i in missing_arrays:
|
||||
fcu_array.insert(i, array_default[i])
|
||||
|
||||
if not len(fcu_array):
|
||||
return None
|
||||
return np.array(fcu_array)
|
||||
|
||||
def evaluate_layers(context, obj, anim_data, fcu, array_default):
|
||||
'''Calculate the evaluation of all the layers when using the nla'''
|
||||
|
||||
if not hasattr(anim_data, 'nla_tracks') or not anim_data.use_nla:
|
||||
return None
|
||||
nla_tracks = anim_data.nla_tracks
|
||||
if not len(nla_tracks):
|
||||
return None
|
||||
frame = context.scene.frame_current
|
||||
blend_types = {'ADD' : '+', 'SUBTRACT' : '-', 'MULTIPLY' : '*'}
|
||||
fcu_path = fcu.data_path
|
||||
|
||||
eval_array = array_default
|
||||
|
||||
for track in nla_tracks:
|
||||
if track.mute:
|
||||
continue
|
||||
if not len(track.strips):
|
||||
continue
|
||||
for strip in track.strips:
|
||||
if not strip.frame_start < frame < strip.frame_end:
|
||||
continue
|
||||
action = strip.action
|
||||
if action is None:
|
||||
continue
|
||||
blend_type = strip.blend_type
|
||||
|
||||
#get the influence value either from the attribute or the fcurve. function coming from bake
|
||||
influence = strip.influence
|
||||
if len(strip.fcurves):
|
||||
if not strip.fcurves[0].mute and len(strip.fcurves[0].keyframe_points):
|
||||
influence = strip.fcurves[0].evaluate(frame)
|
||||
|
||||
#evaluate the frame according to the strip settings
|
||||
frame_eval = frame
|
||||
#change the frame if the strip is on hold
|
||||
if frame < strip.frame_start:
|
||||
if strip.extrapolation == 'HOLD':
|
||||
frame_eval = strip.frame_start
|
||||
elif frame >= strip.frame_end:
|
||||
if strip.extrapolation == 'HOLD' or strip.extrapolation == 'HOLD_FORWARD':
|
||||
frame_eval = strip.frame_end
|
||||
|
||||
last_frame = strip.frame_start + (strip.frame_end - strip.frame_start) / strip.repeat
|
||||
|
||||
if strip.repeat > 1 and (frame) >= last_frame:
|
||||
action_range = (strip.action_frame_end * strip.scale - strip.action_frame_start * strip.scale)
|
||||
frame_eval = (((frame_eval - strip.frame_start) % (action_range)) + strip.frame_start)
|
||||
|
||||
if strip.use_reverse:
|
||||
frame_eval = last_frame - (frame_eval - strip.frame_start)
|
||||
offset = (strip.frame_start * 1/strip.scale - strip.action_frame_start) * strip.scale
|
||||
frame_eval = strip.frame_start * 1/strip.scale + (frame_eval - strip.frame_start) * 1/strip.scale - offset * 1/strip.scale
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_blend_type(fcurves, eval_array, fcu_path, frame_eval, influence, array_default, blend_type, blend_types)
|
||||
|
||||
#Adding an extra layer from the action outside and on top of the nla
|
||||
tweak_mode = anim_data.use_tweak_mode
|
||||
if tweak_mode:
|
||||
anim_data.use_tweak_mode = False
|
||||
action = anim_data.action
|
||||
if action:
|
||||
influence = anim_data.action_influence
|
||||
blend_type = anim_data.action_blend_type
|
||||
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_blend_type(fcurves, eval_array, fcu_path, frame, influence, array_default, blend_type, blend_types)
|
||||
anim_data.use_tweak_mode = tweak_mode
|
||||
|
||||
return eval_array
|
||||
|
||||
|
||||
def evaluate_blend_type(fcurves, eval_array, fcu_path, frame, influence,
|
||||
array_default, blend_type, blend_types):
|
||||
'''Calculate the value based on the blend type'''
|
||||
|
||||
fcu_array = evaluate_array(fcurves, fcu_path, frame, array_default)
|
||||
if fcu_array is None:
|
||||
return eval_array
|
||||
###EVALUATION###
|
||||
if blend_type =='COMBINE':
|
||||
if 'location' in fcu_path or 'rotation_euler' in fcu_path:
|
||||
blend_type = 'ADD'
|
||||
if blend_type =='REPLACE':
|
||||
eval_array = eval_array * (1 - influence) + fcu_array * influence
|
||||
elif blend_type =='COMBINE':
|
||||
eval_array = evaluate_combine(fcu_path, fcu_array, eval_array, array_default, influence)
|
||||
else:
|
||||
eval_array = eval('eval_array' + blend_types[blend_type] + 'fcu_array' + '*' + str(influence))
|
||||
|
||||
return eval_array
|
||||
|
||||
def evaluate_value(self, context):
|
||||
ui = context.window_manager.atb_ui
|
||||
for obj in context.selected_objects:
|
||||
|
||||
anim_data = obj.animation_data
|
||||
if anim_data is None:
|
||||
return
|
||||
if anim_data.action is None:
|
||||
return
|
||||
|
||||
action = obj.animation_data.action
|
||||
fcu_paths = []
|
||||
transformations = ["rotation_quaternion","rotation_euler", "location", "scale"]
|
||||
if obj.mode == 'POSE':
|
||||
bonelist = context.selected_pose_bones if ui.multikey.selectedbones else obj.pose.bones
|
||||
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
for fcu in fcurves:
|
||||
if fcu in fcu_paths:
|
||||
continue
|
||||
if Tools.filter_properties(context.scene.animtoolbox, fcu):
|
||||
continue
|
||||
if obj.mode == 'POSE':
|
||||
if selected_bones_filter(obj, fcu.data_path):
|
||||
continue
|
||||
|
||||
for bone in bonelist:
|
||||
#find the fcurve of the bone
|
||||
if fcu.data_path.rfind(bone.name) != 12 or fcu.data_path[12 + len(bone.name)] != '"':
|
||||
continue
|
||||
path_split = fcu.data_path.split('"].')
|
||||
|
||||
if len(path_split) <= 1:
|
||||
continue
|
||||
else:
|
||||
transform = fcu.data_path.split('"].')[1]
|
||||
if transform not in transformations:
|
||||
continue
|
||||
current_value = getattr(obj.pose.bones[bone.name], transform)
|
||||
else:
|
||||
transform = fcu.data_path
|
||||
current_value = getattr(obj, transform)
|
||||
|
||||
array_default = np.array(attr_default(obj, (fcu.data_path, fcu.array_index)))
|
||||
# array_default = np.array([attr_default(obj, (fcu.data_path, i)) for i in range(4)
|
||||
# if fcurves.find(fcu.data_path, index = i) is not None])
|
||||
eval_array = evaluate_layers(context, obj, anim_data, fcu, array_default)
|
||||
if eval_array is None:
|
||||
fcurves = Tools.get_fcurves_channelbag(obj, action)
|
||||
eval_array = evaluate_array(fcurves, fcu.data_path, context.scene.frame_current, array_default)
|
||||
|
||||
#calculate the difference between current value and the fcurve value
|
||||
add_diff(fcurves, fcu.data_path, np.array(current_value), eval_array)
|
||||
|
||||
class MULTIKEY_OT_Multikey(bpy.types.Operator):
|
||||
"""Edit all selected keyframes"""
|
||||
bl_label = "Edit Selected Keyframes"
|
||||
bl_idname = "animtoolbox.multikey"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.active_object and context.active_object.animation_data and bpy.context.scene.tool_settings.use_keyframe_insert_auto == False
|
||||
|
||||
def execute(self, context):
|
||||
evaluate_value(self, context)
|
||||
return {'FINISHED'}
|
||||
|
||||
class MultikeyProperties(bpy.types.PropertyGroup):
|
||||
|
||||
selectedbones: bpy.props.BoolProperty(name="Selected Bones", description="Affect only selected bones", default=True, options={'HIDDEN'})
|
||||
handletype: bpy.props.BoolProperty(name="Keep handle types", description="Keep handle types", default=False, options={'HIDDEN'})
|
||||
scale: bpy.props.FloatProperty(name="Scale Factor", description="Scale percentage of the average value", default=1.0, update = scale_value)
|
||||
randomness: bpy.props.FloatProperty(name="Randomness", description="Random Threshold of keyframes", default=0.1, min=0.0, max = 1.0, update = random_value)
|
||||
|
||||
#filters
|
||||
# filter_location: bpy.props.BoolVectorProperty(name="Location", description="Filter Location properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
# filter_rotation: bpy.props.BoolVectorProperty(name="Rotation", description="Filter Rotation properties", default=(True, True, True, True), size = 4, options={'HIDDEN'})
|
||||
# filter_scale: bpy.props.BoolVectorProperty(name="Scale", description="Filter Scale properties", default=(True, True, True), size = 3, options={'HIDDEN'})
|
||||
|
||||
# class FilterProperties(bpy.types.Operator):
|
||||
# """Filter Location Rotation and Scale Properties"""
|
||||
# bl_idname = "fcurves.filter"
|
||||
# bl_label = "Filter Properties W X Y Z"
|
||||
# bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
# def invoke(self, context, event):
|
||||
# wm = context.window_manager
|
||||
# return wm.invoke_props_dialog(self, width = 200)
|
||||
|
||||
# def draw(self, context):
|
||||
# layout = self.layout
|
||||
# row = layout.row()
|
||||
# row.label(text = 'Location')
|
||||
# row.prop(context.scene.multikey, 'filter_location', text = '')
|
||||
# row = layout.row()
|
||||
# row.label(text = 'Rotation')
|
||||
# row.prop(context.scene.multikey, 'filter_rotation', text = '')
|
||||
# row = layout.row()
|
||||
# row.label(text = 'Scale')
|
||||
# row.prop(context.scene.multikey, 'filter_scale', text = '')
|
||||
|
||||
# def execute(self, context):
|
||||
# return {'CANCELLED'}
|
||||
|
||||
classes = (ScaleValuesOp, MULTIKEY_OT_Multikey)
|
||||
|
||||
#register, unregister = bpy.utils.register_classes_factory(classes)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
# bpy.types.Scene.animtoolbox.multikey = bpy.props.PointerProperty(type = MultikeyProperties, options={'LIBRARY_EDITABLE'}, override = {'LIBRARY_OVERRIDABLE'})
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in classes:
|
||||
unregister_class(cls)
|
||||
# del bpy.types.Scene.animtoolbox.multikey
|
||||
@@ -0,0 +1,700 @@
|
||||
# ***** 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 LICENCE BLOCK *****
|
||||
|
||||
import bpy
|
||||
from . import Rigger_Toolbox
|
||||
from . import multikey
|
||||
from . import Rigger_Toolbox
|
||||
from pathlib import Path
|
||||
from bpy.utils import register_class
|
||||
from bpy.utils import unregister_class
|
||||
import os
|
||||
|
||||
######################################################## MENUS ########################################################
|
||||
|
||||
class ANIMTOOLBOX_MT_Copy_Paste_Matrix(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Copy_Paste_Matrix'
|
||||
bl_label = "Copy Paste Matrix"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator('anim.copy_matrix', text = 'Copy World Matrix', icon ='DUPLICATE')
|
||||
layout.operator('anim.paste_matrix', text = 'Paste World Matrix', icon ='PASTEDOWN')
|
||||
layout.separator()
|
||||
layout.operator('anim.copy_relative_matrix', text = 'Copy Relative Matrix', icon ='DUPLICATE')
|
||||
layout.operator('anim.paste_relative_matrix', text = 'Paste Relative Matrix', icon ='PASTEDOWN')
|
||||
layout.separator()
|
||||
layout.prop_menu_enum(context.scene.animtoolbox, 'range_type', text = 'Frame Range Type')
|
||||
if context.scene.animtoolbox.range_type == 'RANGE':
|
||||
# split = layout.split(factor = 0.3)
|
||||
# layout.prop(context.scene.animtoolbox, 'bake_frame_start', text = 'Start')
|
||||
# layout.prop(context.scene.animtoolbox, 'bake_frame_end', text = 'End')
|
||||
layout.operator("anim.markers_bakerange", icon = 'MARKER', text ='Frame Range Markers Widget', depress = context.scene.animtoolbox.bake_frame_range)
|
||||
|
||||
class ANIMTOOLBOX_MT_Temp_Ctrls(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Temp_Ctrls'
|
||||
bl_label = "Temp Ctrls"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
custom_icons = preview_collections["main"]
|
||||
layout.operator('anim.bake_to_ctrl', text="World Space Ctrls", icon = 'WORLD')
|
||||
layout.operator('anim.bake_to_temp_fk', text="Temp FK Ctrls", icon = 'BONE_DATA')
|
||||
layout.operator('anim.bake_to_temp_ik', text="Temp IK Ctrls", icon = 'CON_KINEMATIC')
|
||||
layout.separator()
|
||||
layout.operator('anim.link_temp_chains', text="Link Temp Chains", icon = 'DECORATE_LINKED')
|
||||
layout.operator('anim.unlink_temp_chains', text="UnLink Temp Chains", icon = 'DECORATE_LINKED')
|
||||
layout.separator()
|
||||
layout.operator('anim.bake_temp_ctrls', text="Bake Temp Ctrls", icon_value = custom_icons["oven"].icon_id)
|
||||
layout.operator('anim.remove_bones_constraints', text="Cleanup", icon_value = custom_icons["trash"].icon_id)
|
||||
layout.prop_menu_enum(context.scene.btc, 'target', text = 'Bake To', icon = 'MOD_ARMATURE')
|
||||
layout.separator()
|
||||
|
||||
ctrl = context.object.animtoolbox.controller if context.object.animtoolbox.controller else context.object
|
||||
if ctrl:
|
||||
layout.prop(ctrl.animtoolbox, 'ctrls_enabled', text ='Temp Ctrls On/Off')
|
||||
|
||||
# layout.operator('anim.enable_tempctrls', text="On" , icon = 'HIDE_OFF')#icon = 'CONSTRAINT_BONE'
|
||||
# layout.operator('anim.disable_tempctrls', text="Off", icon = 'HIDE_ON')
|
||||
layout.separator()
|
||||
layout.prop_menu_enum(context.scene.btc, 'shape_type', icon = 'MESH_DATA')
|
||||
layout.prop(context.scene.btc, 'shape_size', slider = False, icon ='CON_SIZELIKE')
|
||||
layout.prop(context.scene.btc, 'color_set', text = '')
|
||||
# layout.prop(context.scene.btc, 'shape_type', icon = 'MESH_DATA', text ='')
|
||||
|
||||
class ANIMTOOLBOX_MT_Keyframe_Offset(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Keyframe_Offset'
|
||||
bl_label = "Interactive Keyframe Offset"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.prop(context.scene.animtoolbox, 'keyframes_offset', slider = False)
|
||||
layout.operator('anim.select_keyframes_offset', text="Select Offset Keyframes", icon ='RESTRICT_SELECT_OFF')
|
||||
layout.operator('anim.apply_keyframes_offset', text="Apply Offset", icon = 'ANIM')
|
||||
|
||||
class ANIMTOOLBOX_MT_Blendings(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Blendings'
|
||||
bl_label = "Blendings"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
layout.prop(ui, 'inbetween_worldmatrix', slider = True)
|
||||
layout.prop(context.scene.animtoolbox, 'inbetweener', slider = True)
|
||||
layout.prop(ui, 'blend_mirror', slider = True)
|
||||
|
||||
class ANIMTOOLBOX_MT_Multikey(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Multikey'
|
||||
bl_label = "Multikey"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
layout.operator("animtoolbox.multikey", icon = 'ACTION_TWEAK')
|
||||
layout.prop(ui.multikey, 'scale', slider = True)
|
||||
layout.prop(ui.multikey, 'randomness', slider = True)
|
||||
|
||||
class ANIMTOOLBOX_MT_Convert_Rotations(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_Convert_Rotations'
|
||||
bl_label = "Convert Rotations"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator("anim.convert_rotation_mode", icon = 'DRIVER_ROTATIONAL_DIFFERENCE', text = 'Convert Rotation To')
|
||||
layout.operator("anim.find_rotation_mode", icon = 'VIEWZOOM', text = 'Recommend Euler Rotation')
|
||||
layout.prop_menu_enum(context.scene.animtoolbox, 'rotation_mode', text = 'Convert To')
|
||||
|
||||
class ANIMTOOLBOX_MT_operators(bpy.types.Menu):
|
||||
bl_idname = 'ANIMTOOLBOX_MT_menu_operators'
|
||||
bl_label = "AnimToolBox"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return True
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
ui = context.window_manager.atb_ui
|
||||
custom_icons = preview_collections["main"]
|
||||
|
||||
if context.area.type == 'VIEW_3D':
|
||||
layout.menu('ANIMTOOLBOX_MT_Temp_Ctrls', text = 'Temp Ctrls', icon_value = custom_icons["puppet"].icon_id)
|
||||
layout.separator()
|
||||
layout.operator('anim.share_keyframes', text = 'Share Keyframes', icon_value = custom_icons["sharekeys"].icon_id)
|
||||
layout.operator('anim.relative_cursor', text = 'Relative Cursor Pivot', icon_value = custom_icons["relative_cursor"].icon_id, depress = ui.relative_cursor)
|
||||
layout.operator("anim.markers_retimer", icon_value = custom_icons["retime"].icon_id, text ='Markers Retimer', depress = ui.markers_retimer)
|
||||
layout.menu('ANIMTOOLBOX_MT_Convert_Rotations', text = 'Convert Rotations', icon = 'DRIVER_ROTATIONAL_DIFFERENCE')
|
||||
|
||||
layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Keyframe_Offset', text = 'Interactive Keyframe Offset', icon_value = custom_icons["keyframe_offset"].icon_id)
|
||||
layout.menu('ANIMTOOLBOX_MT_Blendings', text = 'Blendings and inbetweens', icon_value = custom_icons["sliders"].icon_id)
|
||||
layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Copy_Paste_Matrix', text = 'Copy Paste Matrix', icon_value = custom_icons["copy_matrix"].icon_id)
|
||||
|
||||
if bpy.context.preferences.addons[__package__].preferences.multikey:
|
||||
layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Multikey', text = 'Multikey', icon_value = custom_icons["multikey"].icon_id)
|
||||
|
||||
layout.separator(factor = 0.5)
|
||||
layout.operator('anim.switch_collections_visibility', icon = 'COLLECTION_COLOR_06', text = 'Animated Collections Visibilty')
|
||||
layout.operator('anim.isolate_pose_mode', icon_value = custom_icons["isolate"].icon_id, depress = scene.animtoolbox.isolate_pose_mode)
|
||||
layout.operator('object.motion_path_operator', text = 'Editable Motion Path', depress = scene.animtoolbox.motion_path, icon_value = custom_icons["mt"].icon_id)
|
||||
layout.separator()
|
||||
layout.prop(context.preferences.addons[__package__].preferences, 'quick_menu', text = 'Use Quick Icons Menu')
|
||||
# layout.prop(context.window_manager.atb_ui, 'quick_menu', text = 'Use Quick Icons Menu')
|
||||
# elif context.area.type == 'DOPESHEET_EDITOR':
|
||||
# layout.operator('wm.call_menu_pie', text="Pie AnimOffset").name = 'ANIMAIDE_MT_pie_anim_offset'
|
||||
# layout.menu('ANIMAIDE_MT_anim_offset')
|
||||
# layout.menu('ANIMAIDE_MT_anim_offset_mask')
|
||||
|
||||
# elif context.area.type == 'GRAPH_EDITOR':
|
||||
# layout.menu('ANIMAIDE_MT_curve_tools_pie')
|
||||
|
||||
######################################################## WorkSpaceTools ########################################################
|
||||
|
||||
class KeyframeOffsetTool(bpy.types.WorkSpaceTool):
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_context_mode = 'POSE'
|
||||
bl_idname = 'animtoolbox.keyframe_offset'
|
||||
bl_label = 'Keyframe Offset Tool'
|
||||
bl_description = (
|
||||
'Offset the keyframes of the selected bone\n'
|
||||
'Shift + Click to select the bones with an offset\n'
|
||||
'Ctrl + Alt + Click to Apply the offset'
|
||||
)
|
||||
bl_icon = (Path(__file__).parent / "icons" / "ops.anim.keyframe_offset").as_posix()
|
||||
bl_keymap = (
|
||||
('anim.keyframe_offset', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG'}, None),
|
||||
# ('anim.select_keyframes_offset', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'shift': True}, None),
|
||||
('anim.apply_keyframes_offset', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'ctrl': True, 'alt': True}, None),
|
||||
|
||||
('view3d.select_box', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG', 'shift': True}, {'properties': [('mode', 'ADD')]}),
|
||||
('view3d.select_box', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG', 'ctrl': True}, {'properties': [('mode', 'SUB')]}),
|
||||
('view3d.select_box', {'type': 'LEFTMOUSE', 'value': 'CLICK_DRAG', 'shift': True, 'ctrl': True}, {'properties': [('mode', 'AND')]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK'}, {'properties': [('deselect_all', True)]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'shift': True}, {'properties': [('toggle', True)]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'alt': True}, {'properties': [('enumerate', True)]}),
|
||||
('view3d.select', {'type': 'LEFTMOUSE', 'value': 'CLICK', 'shift': True, 'alt': True}, {'properties': [('toggle', True), ('enumerate', True)]})
|
||||
|
||||
)
|
||||
|
||||
######################################################## PANELS ########################################################
|
||||
class ANIMTOOLBOX_PT_Panel:
|
||||
bl_space_type = "VIEW_3D"
|
||||
bl_region_type = "UI"
|
||||
bl_category = "Animation"
|
||||
#bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.object is not None
|
||||
|
||||
class ANIMTOOLBOX_PT_MainPanel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
#bl_category = "Animation"
|
||||
bl_label = "AnimToolBox"
|
||||
bl_idname = "ANIMTOOLBOX_PT_MainPanel"
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
self.layout.label(text='', icon_value = custom_icons["animtoolbox"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
if obj is None:
|
||||
return
|
||||
# layout = self.layout
|
||||
# row = layout.row(align = True)
|
||||
|
||||
# row.label(text = 'Support me on ')
|
||||
# row.operator("wm.url_open", text="Patreon", icon = 'FUND').url = "https://www.patreon.com/animtoolbox"
|
||||
|
||||
class TEMPCTRLS_PT_Panel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
#bl_category = "Animation"
|
||||
bl_label = "Temp Controls"
|
||||
bl_idname = "TEMPCTRLS_PT_Panel"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
self.layout.label(text="", icon_value = custom_icons["puppet"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
btc = context.scene.btc
|
||||
if obj is None:
|
||||
return
|
||||
custom_icons = preview_collections["main"]
|
||||
oven_icon = custom_icons["oven"]
|
||||
# row = layout.row()
|
||||
ui = context.window_manager.atb_ui
|
||||
layout = self.layout
|
||||
box = layout.box()
|
||||
col = box.column()
|
||||
col.operator('anim.bake_to_ctrl', text="WorldSpace Ctrls", icon ='WORLD') #
|
||||
col.operator('anim.bake_to_temp_fk', text="Temp FK Ctrls", icon = 'BONE_DATA')
|
||||
col.operator('anim.bake_to_temp_ik', text="Temp IK Ctrls", icon = 'CON_KINEMATIC')
|
||||
|
||||
# layout.separator(factor = 0.1)
|
||||
# box = layout.box()
|
||||
row = box.row()
|
||||
row.operator('anim.link_temp_chains', text="Link Temp Chains", icon = 'DECORATE_LINKED')
|
||||
row.prop(btc, 'linksettings', text = '', icon = 'SETTINGS')
|
||||
|
||||
if btc.linksettings:
|
||||
# insidebox = box.box()
|
||||
row = box.row()
|
||||
row.label(text = 'Link to Active Chain: ')
|
||||
row.prop(btc, 'link_to', text = '')
|
||||
row = box.row()
|
||||
row.operator('anim.unlink_temp_chains', text="UnLink Temp Chains", icon = 'UNLINKED')
|
||||
# row = insidebox.row()
|
||||
# row.label(text = 'Link from Chain: ')
|
||||
# row.prop(btc, 'link_from', text = '')
|
||||
# layout.separator(factor = 0.1)
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
row.operator('anim.bake_to_empties', text="WorldSpace Empties")
|
||||
row.operator('anim.empties_to_bones', text="", icon = 'EMPTY_AXIS')
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
# row.operator('anim.bake_constrained_bones', text="Quick Bake", icon = 'REC')
|
||||
row.operator('anim.bake_temp_ctrls', text="Bake Temp Ctrls", icon_value = oven_icon.icon_id)
|
||||
row.prop(btc, 'bakesettings', text = '', icon = 'SETTINGS')
|
||||
|
||||
if btc.bakesettings:
|
||||
insidebox = box.box()
|
||||
# split = insidebox.split(factor = 0.9)
|
||||
# split.prop(btc, 'smartbake', text = 'Smart Bake')
|
||||
# split.operator('fcurves.filter_ui', icon ='FILTER', text = '')
|
||||
# if btc.smartbake:
|
||||
# row.prop(btc, 'inbetween_keyframes')
|
||||
split = insidebox.split(factor = 0.3)
|
||||
split.label(text = 'Bake To:')
|
||||
# split.split(factor = 0.9)
|
||||
split_2 = split.split(factor = 0.9)
|
||||
split_2.prop(btc, 'target', text = '')
|
||||
split_2.operator('fcurves.filter_ui', icon ='FILTER', text = '')
|
||||
|
||||
split = insidebox.split(factor = 0.3)
|
||||
split.label(text = 'Bake Range:')
|
||||
split.prop(btc, 'bake_range_type', text = '')
|
||||
|
||||
if btc.bake_range_type == 'KEYFRAMES':
|
||||
row = insidebox.row()
|
||||
row.label(text = 'Keyframes: ')
|
||||
row.prop(btc, 'smartbake', text = 'Smart Bake')
|
||||
row.prop(btc, 'bake_layers', text = 'All Layers')
|
||||
row = insidebox.row()
|
||||
row.label(text = 'From:')
|
||||
row.prop(btc, 'from_origin', text = 'Origin')
|
||||
row.prop(btc, 'from_ctrl', text = 'Ctrls')
|
||||
|
||||
elif btc.bake_range_type == 'CUSTOM':
|
||||
row = insidebox.row()
|
||||
row.prop(btc, 'bake_range', text = '')
|
||||
|
||||
insidebox.separator(factor=0.1)
|
||||
row = insidebox.row()
|
||||
row.label(text = 'Clean: ')
|
||||
row.prop(btc, 'clean_constraints', text = 'Constraints')
|
||||
if btc.clean_constraints:
|
||||
row.prop(btc, 'clean_ctrls', text = 'Ctrls')
|
||||
|
||||
row = box.row()
|
||||
row.operator('anim.remove_bones_constraints', text="Cleanup", icon_value = custom_icons["trash"].icon_id)
|
||||
row.prop(btc, 'cleansettings', text = '', icon = 'SETTINGS')
|
||||
|
||||
if btc.cleansettings:
|
||||
insidebox = box.box()
|
||||
split = insidebox.split(factor = 0.4)
|
||||
split.label(text = 'Target: ')
|
||||
split.prop(btc, 'target', text = '')
|
||||
row = insidebox.row()
|
||||
row.label(text = 'Clean: ')
|
||||
row.prop(btc, 'clean_constraints', text = 'Constraints')
|
||||
if btc.clean_constraints:
|
||||
row.prop(btc, 'clean_ctrls', text = 'Ctrls')
|
||||
if btc.target == 'SELECTED':
|
||||
split = insidebox.split(factor = 0.68)
|
||||
split.label(text = 'ReBake Link Ctrls to Original: ')
|
||||
split.prop(btc, 'rebake_to_org', text = '')
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
# row = layout.row()
|
||||
|
||||
# row.prop(obj.animtoolbox, 'influence', text = 'Influence', slider = True)
|
||||
ctrl = obj.animtoolbox.controller if obj.animtoolbox.controller else obj
|
||||
if ctrl:
|
||||
enabled_icon = 'HIDE_OFF' if ctrl.animtoolbox.ctrls_enabled else 'HIDE_ON'
|
||||
row.prop(ctrl.animtoolbox, 'ctrls_enabled', text ='Temp Ctrls On/Off', icon = enabled_icon)
|
||||
# row = box.row()
|
||||
# row.prop(ui, 'temp_ctrls_switch', icon = 'RESTRICT_VIEW_OFF', text = '')
|
||||
# row.label(text = 'Temp Ctrls Switch: ')
|
||||
# row.prop(btc, 'target', text = '', icon = 'MOD_ARMATURE', icon_only = True)
|
||||
# if ui.temp_ctrls_switch:
|
||||
# # split = layout.split(factor = 0.225)
|
||||
# row = box.row()
|
||||
# row.operator('anim.enable_tempctrls', text="On" , icon = 'HIDE_OFF')#icon = 'CONSTRAINT_BONE'
|
||||
# row.operator('anim.disable_tempctrls', text="Off", icon = 'HIDE_ON')
|
||||
|
||||
box.separator(factor=0.1)
|
||||
row = box.row()
|
||||
row.prop(ui, 'temp_ctrls_shapes', icon = 'MESH_DATA', text = '')
|
||||
row.label(text = 'Temp Ctrls Shapes: ')
|
||||
row.prop(btc, 'target', text = '', icon = 'MOD_ARMATURE', icon_only = True)
|
||||
if ui.temp_ctrls_shapes:
|
||||
row = box.row()
|
||||
row.prop(btc, 'shape_size', slider = False)
|
||||
row.prop(btc, 'shape_type', text = '')
|
||||
row = layout.row()
|
||||
# split.label(text = 'Theme Color: ')
|
||||
row.prop(btc, 'color_set', text = '')
|
||||
|
||||
layout.separator()
|
||||
row = layout.row()
|
||||
row.operator('anim.btc_selections', text="Select", icon = 'CONSTRAINT_BONE')
|
||||
row.prop(btc, 'selection', text = '', icon = 'CON_ARMATURE')
|
||||
|
||||
class ANIMTOOLBOX_PT_Tools(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
bl_label = "Anim Tools"
|
||||
bl_idname = "ANIMTOOLBOX_PT_Tools"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
layout.label(text="", icon_value = custom_icons["toolbox"].icon_id)
|
||||
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
scene = context.scene
|
||||
atb = scene.animtoolbox
|
||||
if obj is None:
|
||||
return
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
row = layout.row()
|
||||
filter_text = 'Filter Tools Properties' if atb.filter_name == '' else 'Filters: ' + atb.filter_name
|
||||
filter_depress = False if atb.filter_name == '' else True
|
||||
row.operator('fcurves.filter_ui', icon ='FILTER', text = filter_text, depress = filter_depress)
|
||||
layout.separator()
|
||||
#layout.operator('anim.keyframes_offset', text="Offset Keyframes", icon = 'NEXT_KEYFRAME')
|
||||
split = layout.split(factor = 0.9)
|
||||
split.prop(context.scene.animtoolbox, 'keyframes_offset', slider = True)
|
||||
split.operator('anim.apply_keyframes_offset', text="", icon_value = custom_icons["apply"].icon_id)
|
||||
split.operator('anim.select_keyframes_offset', text="", icon_value = custom_icons["select"].icon_id)
|
||||
row = layout.row()
|
||||
row.operator('anim.share_keyframes', text = 'Share Keyframes', icon_value = custom_icons["sharekeys"].icon_id)
|
||||
row = layout.row()
|
||||
row.operator("anim.relative_cursor", text ='Relative Cursor Pivot', icon_value = custom_icons["relative_cursor"].icon_id, depress = ui.relative_cursor)
|
||||
row = layout.row()
|
||||
row.operator("anim.markers_retimer", icon_value = custom_icons["retime"].icon_id, text ='Markers Retimer', depress = ui.markers_retimer)
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
box = layout.box()
|
||||
# icon = 'DOWNARROW_HLT' if ui.copy_paste_matrix is True else 'RIGHTARROW_THIN'
|
||||
# split = box.split(factor = 0.9)
|
||||
# split.prop(ui, 'copy_paste_matrix', icon_value = custom_icons["copy_matrix"].icon_id, text = 'Copy Paste Matrices')
|
||||
# split.operator('fcurves.filter', icon ='FILTER', text = '')
|
||||
row = box.row()
|
||||
row.prop(ui, 'copy_paste_matrix', icon_value = custom_icons["copy_matrix"].icon_id, text = 'Copy Paste Matrices')
|
||||
if ui.copy_paste_matrix:
|
||||
row = box.row()
|
||||
row.label(text = 'Copy World Matrix :', icon = 'WORLD')
|
||||
row.operator('anim.copy_matrix', text = '', icon ='DUPLICATE')
|
||||
row.operator('anim.paste_matrix', text = '', icon ='PASTEDOWN')
|
||||
row = box.row()
|
||||
row.label(text = 'Copy Relative Matrix :', icon = 'LINKED')
|
||||
row.operator('anim.copy_relative_matrix', text = '', icon ='DUPLICATE')
|
||||
row.operator('anim.paste_relative_matrix', text = '', icon ='PASTEDOWN')
|
||||
split = box.split(factor = 0.32)
|
||||
split.label(text = 'Paste To')
|
||||
split.prop(context.scene.animtoolbox, 'range_type', text = '')
|
||||
if context.scene.animtoolbox.range_type == 'RANGE':
|
||||
row = box.row()
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_start', text = 'Start')
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_end', text = 'End')
|
||||
row.operator("anim.markers_bakerange", icon = 'MARKER', text ='', depress = context.scene.animtoolbox.bake_frame_range)
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
box = layout.box()
|
||||
# icon = 'DOWNARROW_HLT' if ui.Inbetweens is True else 'RIGHTARROW_THIN'
|
||||
# split = box.split(factor = 0.9)
|
||||
# split.prop(ui, 'Inbetweens', icon_value = custom_icons["sliders"].icon_id, text = 'Blendings / Inbetweens')
|
||||
# split.operator('fcurves.filter', icon ='FILTER', text = '')
|
||||
row = box.row()
|
||||
row.prop(ui, 'Inbetweens', icon_value = custom_icons["sliders"].icon_id, text = 'Blendings / Inbetweens')
|
||||
|
||||
if ui.Inbetweens:
|
||||
col = box.column()
|
||||
col.prop(ui, 'inbetween_worldmatrix', slider = True)
|
||||
col.prop(scene.animtoolbox, 'inbetweener', slider = True)
|
||||
col.prop(ui, 'blend_mirror', slider = True)
|
||||
|
||||
layout.separator(factor = 1)
|
||||
# my_icon = custom_icons["rotations"]
|
||||
split = layout.split(factor = 0.6)
|
||||
split.operator("anim.convert_rotation_mode", icon = 'DRIVER_ROTATIONAL_DIFFERENCE', text = 'Convert Rotation To')
|
||||
# split.operator("anim.convert_rotation_mode", text = 'Convert Rotation To', icon_value = my_icon.icon_id)
|
||||
split = split.split(factor = 0.3)
|
||||
split.operator("anim.find_rotation_mode", icon = 'VIEWZOOM', text = '')
|
||||
split.prop(context.scene.animtoolbox, 'rotation_mode', text = '')
|
||||
|
||||
class MULTIKEY_PT_Panel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
"""Add random value to selected keyframes"""
|
||||
bl_label = "Multikey"
|
||||
bl_idname = "MULTIKEY_PT_Panel"
|
||||
# bl_space_type = 'VIEW_3D'
|
||||
# bl_region_type = 'UI'
|
||||
# bl_category= 'Animation'
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_Tools'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
layout.label(text="", icon_value = custom_icons["multikey"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
# layout.separator()
|
||||
split = layout.split(factor=0.1, align = True)
|
||||
split.prop(ui.multikey, 'selectedbones', icon_value = custom_icons["selected_bones"].icon_id, text = '')
|
||||
# split = split.split(factor=0.1, align = True)
|
||||
#split.operator('fcurves.filter', icon ='FILTER', text = '')
|
||||
split.operator("animtoolbox.multikey", icon = 'ACTION_TWEAK')
|
||||
layout.separator()
|
||||
row = layout.row(align = True)
|
||||
row.prop(ui.multikey, 'scale')
|
||||
row.prop(ui.multikey, 'randomness', slider = True)
|
||||
|
||||
class ANIMTOOLBOX_PT_Display(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
bl_label = "Display"
|
||||
bl_idname = "ANIMTOOLBOX_PT_Display"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw_header(self, context):
|
||||
custom_icons = preview_collections["main"]
|
||||
self.layout.label(text="", icon_value = custom_icons["display"].icon_id)
|
||||
|
||||
def draw(self, context):
|
||||
scene = context.scene
|
||||
layout = self.layout
|
||||
ui = context.window_manager.atb_ui
|
||||
custom_icons = preview_collections["main"]
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
icon = 'DOWNARROW_HLT' if ui.gizmo_size is True else 'RIGHTARROW_THIN'
|
||||
row.prop(ui, 'gizmo_size', icon = icon, text = 'Add to Gizmo Size:')
|
||||
if ui.gizmo_size:
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'gizmo_size', text = '')
|
||||
row.operator('view3d.gizmo_size_up', text="", icon ='ADD')
|
||||
row.operator('view3d.gizmo_size_down', text="", icon ='REMOVE')
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
row = layout.row()
|
||||
col_vis_icon = 'OUTLINER_COLLECTION' if scene.animtoolbox.col_vis else 'COLLECTION_COLOR_06'
|
||||
row.operator('anim.switch_collections_visibility', icon = col_vis_icon, text = 'Animated Collections Visibilty', depress = scene.animtoolbox.col_vis)
|
||||
layout.separator(factor = 0.5)
|
||||
row = layout.row()
|
||||
row.operator('anim.isolate_pose_mode', icon_value = custom_icons["isolate"].icon_id, depress = scene.animtoolbox.isolate_pose_mode)
|
||||
|
||||
layout.separator(factor = 0.5)
|
||||
|
||||
box = layout.box()
|
||||
row = box.row()
|
||||
row.operator('object.motion_path_operator', text = 'Editable Motion Path', depress = scene.animtoolbox.motion_path, icon_value = custom_icons["mt"].icon_id)
|
||||
row.prop(scene.animtoolbox, 'mp_settings', text = '', icon = 'SETTINGS')
|
||||
if scene.animtoolbox.mp_settings:
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_color_before', text = '')
|
||||
row.prop(scene.animtoolbox, 'mp_color_after', text = '')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_keyframe_scale', text = 'Scale Keyframes Box', icon = 'CUBE')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_points', text = 'Points')
|
||||
row.prop(scene.animtoolbox, 'mp_lines', text = 'Lines')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_handles', text = 'Handles')
|
||||
row.prop(scene.animtoolbox, 'mp_infront', text = 'In Front')
|
||||
row = box.row()
|
||||
row.prop(scene.animtoolbox, 'mp_display_frames', text = 'Display Keyframe Numbers')
|
||||
row = box.row()
|
||||
row.prop(context.preferences.addons[__package__].preferences, 'keyframes_range', text = 'Keyframe Distance Range')
|
||||
if context.object is None:
|
||||
return
|
||||
|
||||
split = box.split(factor = 0.4)
|
||||
split.label(text ='Frame Range')
|
||||
# row.prop(scene.animtoolbox, 'mp_frame_range', text = '')
|
||||
|
||||
split.prop(context.scene.animtoolbox, 'mp_frame_range', text = '')
|
||||
if context.scene.animtoolbox.mp_frame_range == 'MANUAL':
|
||||
row = box.row()
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_start', text = 'Start')
|
||||
row.prop(context.scene.animtoolbox, 'bake_frame_end', text = 'End')
|
||||
row.operator("anim.markers_bakerange", icon = 'MARKER', text ='', depress = scene.animtoolbox.bake_frame_range)
|
||||
|
||||
elif context.scene.animtoolbox.mp_frame_range == 'AROUND':
|
||||
row = box.row()
|
||||
row.prop(context.scene.animtoolbox, 'mp_before', text = 'Before')
|
||||
row.prop(context.scene.animtoolbox, 'mp_after', text = 'After')
|
||||
# row.operator("anim.markers_bakerange", icon = 'MARKER', text ='', depress = scene.animtoolbox.bake_frame_range)
|
||||
|
||||
|
||||
class RIGGERTOOLBOX_PT_Panel(ANIMTOOLBOX_PT_Panel, bpy.types.Panel):
|
||||
bl_label = "Rigger Toolbox"
|
||||
bl_idname = "RIGGERTOOLBOX_PT_Panel"
|
||||
bl_parent_id = 'ANIMTOOLBOX_PT_MainPanel'
|
||||
bl_options = {"DEFAULT_CLOSED"}
|
||||
|
||||
def draw(self, context):
|
||||
obj = context.object
|
||||
if obj is None:
|
||||
return
|
||||
layout = self.layout
|
||||
col = layout.column()
|
||||
|
||||
col.operator("armature.add_bbone_widgets", text = "Add Bbone Widgets", icon = 'IPO_BEZIER')
|
||||
col.separator()
|
||||
col.operator("armature.add_chain_ctrls", text = "Add Chain Controls", icon = 'OUTLINER_DATA_ARMATURE')
|
||||
col.separator()
|
||||
col.operator("armature.merge", text = "Merge Rigs", icon = 'MOD_ARMATURE')
|
||||
|
||||
# Add-ons Preferences Update Panel
|
||||
# Define Panel classes for updating
|
||||
panels = [ANIMTOOLBOX_PT_MainPanel, TEMPCTRLS_PT_Panel, ANIMTOOLBOX_PT_Tools, ANIMTOOLBOX_PT_Display]
|
||||
|
||||
def update_panel(self, context):
|
||||
message = "Animtoolbox: Updating Panel locations has failed"
|
||||
try:
|
||||
for panel in panels:
|
||||
if "bl_rna" in panel.__dict__:
|
||||
unregister_class(panel)
|
||||
|
||||
for panel in panels:
|
||||
panel.bl_category = context.preferences.addons[__package__].preferences.category
|
||||
register_class(panel)
|
||||
|
||||
except Exception as e:
|
||||
print("\n[{}]\n{}\n\nError:\n{}".format(__package__, message, e))
|
||||
pass
|
||||
|
||||
def add_multikey(self, context):
|
||||
if bpy.context.preferences.addons[__package__].preferences is None:
|
||||
return
|
||||
if bpy.context.preferences.addons[__package__].preferences.multikey:
|
||||
multikey.register()
|
||||
register_class(MULTIKEY_PT_Panel)
|
||||
register_class(ANIMTOOLBOX_MT_Multikey)
|
||||
panels.append(MULTIKEY_PT_Panel)
|
||||
#panels = panels + (MULTIKEY_PT_Panel)
|
||||
elif hasattr(bpy.types, 'MULTIKEY_PT_Panel'):
|
||||
multikey.unregister()
|
||||
panels.remove(MULTIKEY_PT_Panel)
|
||||
unregister_class(MULTIKEY_PT_Panel)
|
||||
unregister_class(ANIMTOOLBOX_MT_Multikey)
|
||||
|
||||
def add_riggertoolbox(self, context):
|
||||
if bpy.context.preferences.addons[__package__].preferences is None:
|
||||
return
|
||||
if bpy.context.preferences.addons[__package__].preferences.riggertoolbox:
|
||||
Rigger_Toolbox.register()
|
||||
register_class(RIGGERTOOLBOX_PT_Panel)
|
||||
panels.append(RIGGERTOOLBOX_PT_Panel)
|
||||
#panels = panels + (RIGGERTOOLBOX_PT_Panel)
|
||||
elif hasattr(bpy.types, 'RIGGERTOOLBOX_PT_Panel'):
|
||||
Rigger_Toolbox.unregister()
|
||||
panels.remove(RIGGERTOOLBOX_PT_Panel)
|
||||
unregister_class(RIGGERTOOLBOX_PT_Panel)
|
||||
|
||||
classes = (ANIMTOOLBOX_MT_Copy_Paste_Matrix, ANIMTOOLBOX_MT_Temp_Ctrls, ANIMTOOLBOX_MT_operators, ANIMTOOLBOX_MT_Keyframe_Offset,
|
||||
ANIMTOOLBOX_MT_Blendings, ANIMTOOLBOX_MT_Convert_Rotations) + tuple(panels)
|
||||
|
||||
preview_collections = {}
|
||||
#list of all the custom icons
|
||||
icons_list = {'relative_cursor' : 'relative_cursor.png', 'puppet' : 'puppet.png', 'animtoolbox' : 'animtoolbox.png',
|
||||
'sliders' : 'slider-navigation.png', 'world_space' : 'earth-rotation.png', 'isolate' : 'isolation.png',
|
||||
'mt' : 'curve.png', 'toolbox' : 'tools.png', 'oven' : 'oven.png', 'retime' : 'retime.png', 'copy_matrix' : 'copy_world.png',
|
||||
'sharekeys' : 'sharekeys.png', 'sliders' : 'sliders.png', 'keyframe_offset' : 'keyframes_offset.png', 'display' : 'display.png',
|
||||
'switch' : 'switch.png', 'trash' : 'trash.png', 'apply' : 'apply.png', 'select' : 'select.png', 'worldspace' : 'WorldSpace.png',
|
||||
'multikey' : 'multikey.png', 'selected_bones' : 'selected_bones.png'}
|
||||
|
||||
def register_custom_icon():
|
||||
# Note that preview collections returned by bpy.utils.previews
|
||||
# are regular py objects - you can use them to store custom data.
|
||||
import bpy.utils.previews
|
||||
custom_icons = bpy.utils.previews.new()
|
||||
# path to the folder where the icon is
|
||||
# the path is calculated relative to this py file inside the addon folder
|
||||
icons_dir = os.path.join(os.path.dirname(__file__), "icons")
|
||||
# load a preview thumbnail of a file and store in the previews collection
|
||||
for iconname, icon_file in icons_list.items():
|
||||
custom_icons.load(iconname, os.path.join(icons_dir, icon_file), 'IMAGE')
|
||||
preview_collections["main"] = custom_icons
|
||||
|
||||
def draw_menu(self, context):
|
||||
if context.mode == 'OBJECT' or context.mode == 'POSE':
|
||||
layout = self.layout
|
||||
scene = context.scene
|
||||
ui = context.window_manager.atb_ui
|
||||
|
||||
custom_icons = preview_collections["main"]
|
||||
layout.menu('ANIMTOOLBOX_MT_menu_operators') #, icon_value = custom_icons["toolbox"].icon_id, text =''
|
||||
|
||||
if not context.preferences.addons[__package__].preferences.quick_menu:
|
||||
return
|
||||
#Only Icons Menu
|
||||
temp_ctrls = custom_icons["puppet"]
|
||||
layout.menu('ANIMTOOLBOX_MT_Temp_Ctrls' , icon_value = temp_ctrls.icon_id, text ='')
|
||||
# layout.separator()
|
||||
layout.menu('ANIMTOOLBOX_MT_Copy_Paste_Matrix' , icon_value = custom_icons["copy_matrix"].icon_id, text ='')
|
||||
|
||||
layout.separator()
|
||||
layout.operator('anim.relative_cursor', text = '', depress = ui.relative_cursor, icon_value = custom_icons["relative_cursor"].icon_id)
|
||||
|
||||
layout.separator()
|
||||
layout.operator('anim.markers_retimer', text = '', depress = ui.markers_retimer, icon_value = custom_icons["retime"].icon_id)
|
||||
|
||||
layout.separator()
|
||||
layout.operator('anim.isolate_pose_mode', text = '', depress = scene.animtoolbox.isolate_pose_mode, icon_value = custom_icons["isolate"].icon_id)
|
||||
|
||||
layout.separator()
|
||||
layout.operator('object.motion_path_operator', text = '', depress = scene.animtoolbox.motion_path, icon_value = custom_icons["mt"].icon_id)
|
||||
@@ -0,0 +1,122 @@
|
||||
bl_info = {
|
||||
"name": "Datablock Tools",
|
||||
"author": "Mackenzie Crawford, Vitor Balbio",
|
||||
"version": (2, 2, 1),
|
||||
"blender": (2, 80, 0),
|
||||
"location": "View3D > Object > Datablock Tools",
|
||||
"description": "Some tools to handle datablocks",
|
||||
"warning": "",
|
||||
"tracker_url": "",
|
||||
"category": "3D View"}
|
||||
|
||||
import bpy
|
||||
import re
|
||||
|
||||
class CleanImagesOP(bpy.types.Operator):
|
||||
#replace the ".0x" images with the original and mark this to remove in next load
|
||||
bl_idname = "object.clean_images"
|
||||
bl_label = "Clean Images Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
ImageList = []
|
||||
#get full image name including extension
|
||||
for i in bpy.data.images:
|
||||
ImageList.append([i.name,i])
|
||||
|
||||
for obj in bpy.context.selected_objects:
|
||||
for uv in obj.data.uv_textures.items():
|
||||
for faceTex in uv[1].data:
|
||||
if (not (faceTex.image is None)):
|
||||
image = faceTex.image
|
||||
|
||||
if (bool(re.search(r'\.(\d){3}', image.name))): #if an image is set, and its name contains a . followed by 3 digits
|
||||
replaced = False
|
||||
for ima_name, ima in ImageList:
|
||||
if (image.name.startswith(ima_name) and (".0" not in ima_name)):
|
||||
faceTex.image.user_clear()
|
||||
faceTex.image = ima
|
||||
replaced = True
|
||||
if (replaced == False):
|
||||
#we didn't find a match, rename this one
|
||||
image.name = image.name.rsplit(".", 1)[0] #splits on the last . in the image name and returns the left part. Allows handling of names with multiple .s
|
||||
return {'FINISHED'}
|
||||
|
||||
class CleanMaterialsOP(bpy.types.Operator):
|
||||
#replace the ".0x" materials with the original and mark this to remove in next load
|
||||
bl_idname = "object.clean_materials"
|
||||
bl_label = "Clean Materials Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
matlist = bpy.data.materials
|
||||
for obj in bpy.context.selected_objects:
|
||||
for mat_slt in obj.material_slots:
|
||||
if (mat_slt.material != None and bool(re.search(r'\.(\d){3}', mat_slt.material.name))): #if a material is set, and its name contains a . followed by 3 digits
|
||||
replaced = False
|
||||
for mat in matlist:
|
||||
if ((mat.name == mat_slt.material.name.rsplit(".", 1)[0]) and (not bool(re.search(r'\.(\d){3}', mat.name)))):
|
||||
mat_slt.material = mat
|
||||
replaced = True
|
||||
if replaced == False:
|
||||
#we didn't find a match, rename this one
|
||||
mat_slt.material.name = mat_slt.material.name.rsplit(".", 1)[0] #splits on the last . in the material name and returns the left part. Allows handling of names with multiple .s
|
||||
return {'FINISHED'}
|
||||
|
||||
class RemoveAllMaterialsOP(bpy.types.Operator):
|
||||
#removes all materials from selected objects
|
||||
bl_idname = "object.remove_materials"
|
||||
bl_label = "Remove All Materials Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
for obj in bpy.context.selected_objects:
|
||||
#iterate through materials list and remove each sequentially
|
||||
obj.active_material_index = 0
|
||||
for i in range(len(obj.material_slots)):
|
||||
bpy.ops.object.material_slot_remove({'object': obj})
|
||||
return {'FINISHED'}
|
||||
|
||||
class DatablockToolsMenu(bpy.types.Menu):
|
||||
bl_label = "Datablock Tools"
|
||||
bl_idname = "VIEW_MT_datablock_tools"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("object.clean_materials")
|
||||
layout.operator("object.remove_materials")
|
||||
layout.operator("object.clean_images")
|
||||
layout.operator("object.set_instance")
|
||||
|
||||
def draw_item(self, context):
|
||||
layout = self.layout
|
||||
layout.menu(DatablockToolsMenu.bl_idname)
|
||||
|
||||
classes = (CleanMaterialsOP, RemoveAllMaterialsOP, CleanImagesOP, DatablockToolsMenu)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.VIEW3D_MT_object.append(draw_item)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in reverse(classes):
|
||||
unregister_class(cls)
|
||||
|
||||
bpy.types.VIEW3D_MT_object.remove(draw_item)
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
@@ -0,0 +1,57 @@
|
||||
# Datablock-Tools-2
|
||||
Updated version of Datablock Tools for Blender https://blenderartists.org/forum/showthread.php?320593-Datablock-Tools
|
||||
|
||||
Datablock Tools provides an easy way to remove duplicated material or UV image datablocks ("image.png.001", etc), typically created when copy-pasting objects. This reduces memory footprint and also makes editing materials a lot easier.
|
||||
|
||||
## Usage
|
||||
All datablock tools can be found under Object -> Datablock Tools.
|
||||
|
||||
* **Clean Images Datablocks:** Removes duplicated UV images from selected objects. If an original image is found ("image.png" instead of "image.png.001"), all duplicate instances will be replaced with the original. Otherwise, one instance is renamed to removed the .xxx suffix
|
||||
|
||||
* **Clean Materials Datablocks:** Removes duplicated materials from selected objects. If an original material is found ("material.png" instead of "material.png.001"), all duplicate instances will be replaced with the original. Otherwise, one instance is renamed to removed the .xxx suffix
|
||||
|
||||
* **Remove All Materials Datablocks:** Removes all materials from selected objects.
|
||||
|
||||
* **Set As Instance:** Converts all *selected* objects into instances of the *active* object. Any change to the geometry or materials of a single instance will affect all instances of the object.
|
||||
|
||||
## Changelog
|
||||
|
||||
### 2.2.1
|
||||
|
||||
* Remove "set as instance" tool. Blender includes an equivalent tool built-in anyway, no point duplicating code
|
||||
|
||||
### 2.2
|
||||
|
||||
* Update for Blender 2.80 API. Still compatible with 2.7x
|
||||
|
||||
### 2.1
|
||||
|
||||
* Fixed fatal bug with image datablock clean on objects with incomplete unwrapping
|
||||
|
||||
* If image datablock has no "original" version (without .xxx suffix), rename it to become that
|
||||
|
||||
* Image datablock cleaner now uses regex search, like the material cleaner
|
||||
|
||||
* Support image/material names with multiple periods, preserves image extensions
|
||||
|
||||
* Code styling and commenting improvements for future maintainability
|
||||
|
||||
* Text and layout tweaks
|
||||
|
||||
* Tool to remove all materials from an object
|
||||
|
||||
### 2.0
|
||||
|
||||
* First version by Mackenzie Crawford, taking over as de facto developer of apparently orphaned project
|
||||
|
||||
* Update for Blender 2.78 onwards
|
||||
|
||||
* Switch to regex-based datablock name comparisons
|
||||
|
||||
* In absence of a "virgin" material (not image yet) datablock, rename one of the existing duplicates instead of leaving all duplicates unchanged
|
||||
|
||||
* Restructure program and translate comments to English for better maintainability in the future
|
||||
|
||||
### 1.0, 1.1
|
||||
|
||||
* Original release by Vitor Balbio. See BlenderArtists thread [here](https://blenderartists.org/t/datablock-tool/595316) and deprecated Blender Wiki page [here](https://archive.blender.org/wiki/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Datablock_Tools/)
|
||||
@@ -0,0 +1,122 @@
|
||||
bl_info = {
|
||||
"name": "Datablock Tools",
|
||||
"author": "Mackenzie Crawford, Vitor Balbio",
|
||||
"version": (2, 2, 1),
|
||||
"blender": (2, 80, 0),
|
||||
"location": "View3D > Object > Datablock Tools",
|
||||
"description": "Some tools to handle datablocks",
|
||||
"warning": "",
|
||||
"tracker_url": "",
|
||||
"category": "3D View"}
|
||||
|
||||
import bpy
|
||||
import re
|
||||
|
||||
class CleanImagesOP(bpy.types.Operator):
|
||||
#replace the ".0x" images with the original and mark this to remove in next load
|
||||
bl_idname = "object.clean_images"
|
||||
bl_label = "Clean Images Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
ImageList = []
|
||||
#get full image name including extension
|
||||
for i in bpy.data.images:
|
||||
ImageList.append([i.name,i])
|
||||
|
||||
for obj in bpy.context.selected_objects:
|
||||
for uv in obj.data.uv_textures.items():
|
||||
for faceTex in uv[1].data:
|
||||
if (not (faceTex.image is None)):
|
||||
image = faceTex.image
|
||||
|
||||
if (bool(re.search(r'\.(\d){3}', image.name))): #if an image is set, and its name contains a . followed by 3 digits
|
||||
replaced = False
|
||||
for ima_name, ima in ImageList:
|
||||
if (image.name.startswith(ima_name) and (".0" not in ima_name)):
|
||||
faceTex.image.user_clear()
|
||||
faceTex.image = ima
|
||||
replaced = True
|
||||
if (replaced == False):
|
||||
#we didn't find a match, rename this one
|
||||
image.name = image.name.rsplit(".", 1)[0] #splits on the last . in the image name and returns the left part. Allows handling of names with multiple .s
|
||||
return {'FINISHED'}
|
||||
|
||||
class CleanMaterialsOP(bpy.types.Operator):
|
||||
#replace the ".0x" materials with the original and mark this to remove in next load
|
||||
bl_idname = "object.clean_materials"
|
||||
bl_label = "Clean Materials Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
matlist = bpy.data.materials
|
||||
for obj in bpy.context.selected_objects:
|
||||
for mat_slt in obj.material_slots:
|
||||
if (mat_slt.material != None and bool(re.search(r'\.(\d){3}', mat_slt.material.name))): #if a material is set, and its name contains a . followed by 3 digits
|
||||
replaced = False
|
||||
for mat in matlist:
|
||||
if ((mat.name == mat_slt.material.name.rsplit(".", 1)[0]) and (not bool(re.search(r'\.(\d){3}', mat.name)))):
|
||||
mat_slt.material = mat
|
||||
replaced = True
|
||||
if replaced == False:
|
||||
#we didn't find a match, rename this one
|
||||
mat_slt.material.name = mat_slt.material.name.rsplit(".", 1)[0] #splits on the last . in the material name and returns the left part. Allows handling of names with multiple .s
|
||||
return {'FINISHED'}
|
||||
|
||||
class RemoveAllMaterialsOP(bpy.types.Operator):
|
||||
#removes all materials from selected objects
|
||||
bl_idname = "object.remove_materials"
|
||||
bl_label = "Remove All Materials Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
for obj in bpy.context.selected_objects:
|
||||
#iterate through materials list and remove each sequentially
|
||||
obj.active_material_index = 0
|
||||
for i in range(len(obj.material_slots)):
|
||||
bpy.ops.object.material_slot_remove({'object': obj})
|
||||
return {'FINISHED'}
|
||||
|
||||
class DatablockToolsMenu(bpy.types.Menu):
|
||||
bl_label = "Datablock Tools"
|
||||
bl_idname = "VIEW_MT_datablock_tools"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("object.clean_materials")
|
||||
layout.operator("object.remove_materials")
|
||||
layout.operator("object.clean_images")
|
||||
layout.operator("object.set_instance")
|
||||
|
||||
def draw_item(self, context):
|
||||
layout = self.layout
|
||||
layout.menu(DatablockToolsMenu.bl_idname)
|
||||
|
||||
classes = (CleanMaterialsOP, RemoveAllMaterialsOP, CleanImagesOP, DatablockToolsMenu)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.VIEW3D_MT_object.append(draw_item)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in reverse(classes):
|
||||
unregister_class(cls)
|
||||
|
||||
bpy.types.VIEW3D_MT_object.remove(draw_item)
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
@@ -0,0 +1,57 @@
|
||||
# Datablock-Tools-2
|
||||
Updated version of Datablock Tools for Blender https://blenderartists.org/forum/showthread.php?320593-Datablock-Tools
|
||||
|
||||
Datablock Tools provides an easy way to remove duplicated material or UV image datablocks ("image.png.001", etc), typically created when copy-pasting objects. This reduces memory footprint and also makes editing materials a lot easier.
|
||||
|
||||
## Usage
|
||||
All datablock tools can be found under Object -> Datablock Tools.
|
||||
|
||||
* **Clean Images Datablocks:** Removes duplicated UV images from selected objects. If an original image is found ("image.png" instead of "image.png.001"), all duplicate instances will be replaced with the original. Otherwise, one instance is renamed to removed the .xxx suffix
|
||||
|
||||
* **Clean Materials Datablocks:** Removes duplicated materials from selected objects. If an original material is found ("material.png" instead of "material.png.001"), all duplicate instances will be replaced with the original. Otherwise, one instance is renamed to removed the .xxx suffix
|
||||
|
||||
* **Remove All Materials Datablocks:** Removes all materials from selected objects.
|
||||
|
||||
* **Set As Instance:** Converts all *selected* objects into instances of the *active* object. Any change to the geometry or materials of a single instance will affect all instances of the object.
|
||||
|
||||
## Changelog
|
||||
|
||||
### 2.2.1
|
||||
|
||||
* Remove "set as instance" tool. Blender includes an equivalent tool built-in anyway, no point duplicating code
|
||||
|
||||
### 2.2
|
||||
|
||||
* Update for Blender 2.80 API. Still compatible with 2.7x
|
||||
|
||||
### 2.1
|
||||
|
||||
* Fixed fatal bug with image datablock clean on objects with incomplete unwrapping
|
||||
|
||||
* If image datablock has no "original" version (without .xxx suffix), rename it to become that
|
||||
|
||||
* Image datablock cleaner now uses regex search, like the material cleaner
|
||||
|
||||
* Support image/material names with multiple periods, preserves image extensions
|
||||
|
||||
* Code styling and commenting improvements for future maintainability
|
||||
|
||||
* Text and layout tweaks
|
||||
|
||||
* Tool to remove all materials from an object
|
||||
|
||||
### 2.0
|
||||
|
||||
* First version by Mackenzie Crawford, taking over as de facto developer of apparently orphaned project
|
||||
|
||||
* Update for Blender 2.78 onwards
|
||||
|
||||
* Switch to regex-based datablock name comparisons
|
||||
|
||||
* In absence of a "virgin" material (not image yet) datablock, rename one of the existing duplicates instead of leaving all duplicates unchanged
|
||||
|
||||
* Restructure program and translate comments to English for better maintainability in the future
|
||||
|
||||
### 1.0, 1.1
|
||||
|
||||
* Original release by Vitor Balbio. See BlenderArtists thread [here](https://blenderartists.org/t/datablock-tool/595316) and deprecated Blender Wiki page [here](https://archive.blender.org/wiki/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Datablock_Tools/)
|
||||
@@ -0,0 +1,122 @@
|
||||
bl_info = {
|
||||
"name": "Datablock Tools",
|
||||
"author": "Mackenzie Crawford, Vitor Balbio",
|
||||
"version": (2, 2, 1),
|
||||
"blender": (2, 80, 0),
|
||||
"location": "View3D > Object > Datablock Tools",
|
||||
"description": "Some tools to handle datablocks",
|
||||
"warning": "",
|
||||
"tracker_url": "",
|
||||
"category": "3D View"}
|
||||
|
||||
import bpy
|
||||
import re
|
||||
|
||||
class CleanImagesOP(bpy.types.Operator):
|
||||
#replace the ".0x" images with the original and mark this to remove in next load
|
||||
bl_idname = "object.clean_images"
|
||||
bl_label = "Clean Images Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
ImageList = []
|
||||
#get full image name including extension
|
||||
for i in bpy.data.images:
|
||||
ImageList.append([i.name,i])
|
||||
|
||||
for obj in bpy.context.selected_objects:
|
||||
for uv in obj.data.uv_textures.items():
|
||||
for faceTex in uv[1].data:
|
||||
if (not (faceTex.image is None)):
|
||||
image = faceTex.image
|
||||
|
||||
if (bool(re.search(r'\.(\d){3}', image.name))): #if an image is set, and its name contains a . followed by 3 digits
|
||||
replaced = False
|
||||
for ima_name, ima in ImageList:
|
||||
if (image.name.startswith(ima_name) and (".0" not in ima_name)):
|
||||
faceTex.image.user_clear()
|
||||
faceTex.image = ima
|
||||
replaced = True
|
||||
if (replaced == False):
|
||||
#we didn't find a match, rename this one
|
||||
image.name = image.name.rsplit(".", 1)[0] #splits on the last . in the image name and returns the left part. Allows handling of names with multiple .s
|
||||
return {'FINISHED'}
|
||||
|
||||
class CleanMaterialsOP(bpy.types.Operator):
|
||||
#replace the ".0x" materials with the original and mark this to remove in next load
|
||||
bl_idname = "object.clean_materials"
|
||||
bl_label = "Clean Materials Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
matlist = bpy.data.materials
|
||||
for obj in bpy.context.selected_objects:
|
||||
for mat_slt in obj.material_slots:
|
||||
if (mat_slt.material != None and bool(re.search(r'\.(\d){3}', mat_slt.material.name))): #if a material is set, and its name contains a . followed by 3 digits
|
||||
replaced = False
|
||||
for mat in matlist:
|
||||
if ((mat.name == mat_slt.material.name.rsplit(".", 1)[0]) and (not bool(re.search(r'\.(\d){3}', mat.name)))):
|
||||
mat_slt.material = mat
|
||||
replaced = True
|
||||
if replaced == False:
|
||||
#we didn't find a match, rename this one
|
||||
mat_slt.material.name = mat_slt.material.name.rsplit(".", 1)[0] #splits on the last . in the material name and returns the left part. Allows handling of names with multiple .s
|
||||
return {'FINISHED'}
|
||||
|
||||
class RemoveAllMaterialsOP(bpy.types.Operator):
|
||||
#removes all materials from selected objects
|
||||
bl_idname = "object.remove_materials"
|
||||
bl_label = "Remove All Materials Datablocks"
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context):
|
||||
return context.selected_objects is not None
|
||||
|
||||
def execute(self, context):
|
||||
for obj in bpy.context.selected_objects:
|
||||
#iterate through materials list and remove each sequentially
|
||||
obj.active_material_index = 0
|
||||
for i in range(len(obj.material_slots)):
|
||||
bpy.ops.object.material_slot_remove({'object': obj})
|
||||
return {'FINISHED'}
|
||||
|
||||
class DatablockToolsMenu(bpy.types.Menu):
|
||||
bl_label = "Datablock Tools"
|
||||
bl_idname = "VIEW_MT_datablock_tools"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.operator("object.clean_materials")
|
||||
layout.operator("object.remove_materials")
|
||||
layout.operator("object.clean_images")
|
||||
layout.operator("object.set_instance")
|
||||
|
||||
def draw_item(self, context):
|
||||
layout = self.layout
|
||||
layout.menu(DatablockToolsMenu.bl_idname)
|
||||
|
||||
classes = (CleanMaterialsOP, RemoveAllMaterialsOP, CleanImagesOP, DatablockToolsMenu)
|
||||
|
||||
def register():
|
||||
from bpy.utils import register_class
|
||||
for cls in classes:
|
||||
register_class(cls)
|
||||
|
||||
bpy.types.VIEW3D_MT_object.append(draw_item)
|
||||
|
||||
def unregister():
|
||||
from bpy.utils import unregister_class
|
||||
for cls in reverse(classes):
|
||||
unregister_class(cls)
|
||||
|
||||
bpy.types.VIEW3D_MT_object.remove(draw_item)
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
@@ -0,0 +1,74 @@
|
||||
# ##### 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 #####
|
||||
|
||||
|
||||
bl_info = {
|
||||
"name": "Find Missing Textures - FMT",
|
||||
"author": "GilaDDD",
|
||||
"version": (3, 5),
|
||||
"blender": (2, 80, 0),
|
||||
"location": "Properties > Scene tab > Find Missing Textures",
|
||||
"description": "Powerful tool that simplifies managing missing textures. Quickly locate broken image paths and get detailed reports of the objects, materials, and nodes using them.",
|
||||
"doc_url": "https://blendermarket.com/products/report-missing-textures--fmt/docs",
|
||||
"category": "Material"}
|
||||
|
||||
from . import ops_fmt, panels_fmt
|
||||
import bpy
|
||||
from bpy.props import IntProperty, CollectionProperty, PointerProperty, BoolProperty
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.operator("texture.find_missing_textures", text ="Report Missing Textures (full report)")
|
||||
|
||||
# def warnning_before_render(self, *args):
|
||||
# bpy.ops.texture.find_missing_textures()
|
||||
|
||||
classes = (
|
||||
ops_fmt.TEXTURE_OT_find_missing_textures,
|
||||
ops_fmt.TEXTURE_OT_find_in_folder,
|
||||
ops_fmt.TEXTURE_OT_remove_image,
|
||||
ops_fmt.TEXTURE_OT_search_bars,
|
||||
panels_fmt.FMT_PT_Panel,
|
||||
panels_fmt.ListItem,
|
||||
panels_fmt.List_View,
|
||||
panels_fmt.SearchBars,
|
||||
)
|
||||
|
||||
def register():
|
||||
for cls in classes:
|
||||
bpy.utils.register_class(cls)
|
||||
bpy.types.Scene.fmt_list = CollectionProperty(type = panels_fmt.ListItem)
|
||||
bpy.types.Scene.fmt_search_bars = CollectionProperty(type = panels_fmt.SearchBars)
|
||||
bpy.types.Scene.fmt_list_pointer = PointerProperty(type=panels_fmt.ListItem)
|
||||
bpy.types.Scene.fmt_list_index = IntProperty(name = "", default = 0)
|
||||
bpy.types.Scene.fmt_extension_replace = BoolProperty(name = "replace_ext", default = 0)
|
||||
bpy.types.Scene.fmt_select_bad_obj = BoolProperty(name = "select bad objects", default = 1)
|
||||
bpy.types.TOPBAR_MT_file_external_data.append(draw)
|
||||
# bpy.app.handlers.render_init.append(warnning_before_render)
|
||||
|
||||
|
||||
def unregister():
|
||||
# bpy.app.handlers.render_init.remove(warnning_before_render)
|
||||
del bpy.types.Scene.fmt_list
|
||||
del bpy.types.Scene.fmt_search_bars
|
||||
del bpy.types.Scene.fmt_list_pointer
|
||||
del bpy.types.Scene.fmt_list_index
|
||||
del bpy.types.Scene.fmt_extension_replace
|
||||
bpy.types.TOPBAR_MT_file_external_data.remove(draw)
|
||||
for cls in classes:
|
||||
bpy.utils.unregister_class(cls)
|
||||
@@ -0,0 +1,156 @@
|
||||
import bpy
|
||||
from os import path, walk
|
||||
from pathlib import Path
|
||||
|
||||
class TEXTURE_OT_search_bars(bpy.types.Operator):
|
||||
"""Add or remove search bars"""
|
||||
bl_idname = "texture.bars"
|
||||
bl_label = "Add search bar"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
bl_region_type = 'UI'
|
||||
|
||||
add : bpy.props.StringProperty(default="")
|
||||
|
||||
def execute(self, context):
|
||||
if self.add[0] == "T":
|
||||
context.scene.fmt_search_bars.add()
|
||||
elif self.add[0] == "F":
|
||||
context.scene.fmt_search_bars.remove(int(self.add[1:]))
|
||||
return {'FINISHED'}
|
||||
|
||||
class TEXTURE_OT_remove_image(bpy.types.Operator):
|
||||
"""Delete the image from the file"""
|
||||
bl_idname = "texture.remove_image"
|
||||
bl_label = "Delete image"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
bl_region_type = 'UI'
|
||||
|
||||
def execute(self, context):
|
||||
if len(bpy.context.scene.fmt_list) > 0:
|
||||
image_name = bpy.context.scene.fmt_list[bpy.context.scene.fmt_list_index].img_name
|
||||
bpy.context.scene.fmt_list.remove(bpy.context.scene.fmt_list_index)
|
||||
bpy.data.images.remove(bpy.data.images[image_name])
|
||||
return {'FINISHED'}
|
||||
|
||||
class TEXTURE_OT_find_in_folder(bpy.types.Operator):
|
||||
"""Find your missing textures in this folder and subfolders"""
|
||||
bl_idname = "texture.folder_find"
|
||||
bl_label = "Find in folder"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
bl_region_type = 'UI'
|
||||
|
||||
def execute(self, context):
|
||||
scene = context.scene
|
||||
files_dir_list = []
|
||||
try:
|
||||
for search_path in scene.fmt_search_bars:
|
||||
if search_path.bars:
|
||||
for dirpath, dirnames, filenames in walk(bpy.path.abspath(search_path.bars)):
|
||||
files_dir_list.append([dirpath, filenames])
|
||||
except FileNotFoundError:
|
||||
print(f"Error - Bad file path {search_path.bars}")
|
||||
return {'FINISHED'}
|
||||
for missing_img in scene.fmt_list:
|
||||
img_file_name = bpy.path.basename(bpy.data.images[missing_img.img_name].filepath)
|
||||
for imgs in files_dir_list:
|
||||
if img_file_name in imgs[1]:
|
||||
bpy.data.images[missing_img.img_name].filepath = path.join(imgs[0], img_file_name)
|
||||
elif bpy.context.scene.fmt_extension_replace:
|
||||
self.search_different_extension(missing_img, img_file_name, imgs)
|
||||
|
||||
bpy.ops.texture.find_missing_textures()
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
def search_different_extension(self, missing_img, img_file_name, imgs):
|
||||
base_img_name = path.splitext(img_file_name)[0]
|
||||
for img_in_folders in imgs[1]:
|
||||
if base_img_name == path.splitext(img_in_folders)[0]:
|
||||
bpy.data.images[missing_img.img_name].filepath = path.join(imgs[0], img_in_folders)
|
||||
|
||||
class TEXTURE_OT_find_missing_textures(bpy.types.Operator):
|
||||
"""Search for misssing textures"""
|
||||
bl_idname = "texture.find_missing_textures"
|
||||
bl_label = "Search missing textures"
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
bl_region_type = 'UI'
|
||||
|
||||
def execute(self, context):
|
||||
bpy.context.scene.fmt_list.clear()
|
||||
self.search_for_missing_texture()
|
||||
self.report_full_list()
|
||||
if len(bpy.context.scene.fmt_list) > 0:
|
||||
self.report({'WARNING'}, "Some texture are missing!")
|
||||
return {'FINISHED'}
|
||||
|
||||
def search_for_missing_texture(self):
|
||||
if len(bpy.context.scene.fmt_search_bars) == 0:
|
||||
bpy.context.scene.fmt_search_bars.add()
|
||||
for img in bpy.data.images:
|
||||
if img.name == "Render Result" or img.name == "Viewer Node":
|
||||
continue
|
||||
if hasattr(img, 'has_data'):
|
||||
img.size[0] # Need to do this to refresh the data at the first time
|
||||
if img.has_data == False:
|
||||
self.add_texture_to_missing_list(img)
|
||||
elif not img.packed_file:
|
||||
if not Path(bpy.path.abspath(img.filepath)).is_file():
|
||||
self.add_texture_to_missing_list(img)
|
||||
|
||||
def report_full_list(self): # Get list of bad materials
|
||||
mat_list = []
|
||||
self.report({'INFO'}, f"------------------------------------------")
|
||||
self.report({'INFO'}, f"Missing material report:")
|
||||
self.report({'INFO'}, f"(Material name >> Node name (Node label) >> Image name)")
|
||||
self.report({'INFO'}, f"(Image path)")
|
||||
for mat in bpy.data.materials:
|
||||
if not mat.name == "Dots Stroke" and hasattr(mat.node_tree, 'nodes'):
|
||||
for node in mat.node_tree.nodes:
|
||||
if node.type == 'TEX_IMAGE':
|
||||
if hasattr(node.image, 'has_data'):
|
||||
if not node.image.has_data:
|
||||
if node.label == "":
|
||||
node_label = node.image.name
|
||||
else:
|
||||
node_label = node.label
|
||||
if not mat.name in mat_list:
|
||||
mat_list.append(mat.name)
|
||||
self.report({'WARNING'}, f"{mat.name} >> {node.name} ({node_label}) >> {node.image.name}")
|
||||
self.report({'WARNING'}, f"{node.image.filepath}")
|
||||
if not mat_list:
|
||||
self.report({'INFO'}, f"Good work! All the shaders are good!")
|
||||
else:
|
||||
self.search_object_with_bad_mat(mat_list)
|
||||
|
||||
def search_object_with_bad_mat(self, mat_list):
|
||||
self.deselect_all_objs()
|
||||
self.report({'INFO'}, f"------------------------------------------")
|
||||
self.report({'INFO'}, f"List of objects with missing textures:")
|
||||
if len(bpy.data.scenes) == 1:
|
||||
self.report({'INFO'}, f"Object name >> Material name")
|
||||
else:
|
||||
self.report({'INFO'}, f"Scene name >> Object name >> Material name")
|
||||
for scene in bpy.data.scenes:
|
||||
for obj in scene.objects:
|
||||
if obj.type == "MESH":
|
||||
if len(obj.material_slots.items()) > 0:
|
||||
for miss_mat in mat_list:
|
||||
if miss_mat in obj.material_slots:
|
||||
if len(bpy.data.scenes) == 1:
|
||||
if bpy.context.scene.fmt_select_bad_obj:
|
||||
obj.select_set(True)
|
||||
self.report({'WARNING'}, f"{obj.name} >> {miss_mat}")
|
||||
else:
|
||||
self.report({'WARNING'}, f"{scene.name} >> {obj.name} >> {miss_mat}")
|
||||
|
||||
def deselect_all_objs(self):
|
||||
if bpy.context.scene.fmt_select_bad_obj:
|
||||
for obj in bpy.context.selected_objects:
|
||||
obj.select_set(False)
|
||||
|
||||
|
||||
def add_texture_to_missing_list(self, img):
|
||||
img.reload()
|
||||
new_image_list = bpy.context.scene.fmt_list.add()
|
||||
new_image_list.img_name = img.name
|
||||
new_image_list.img_path = img.filepath
|
||||
@@ -0,0 +1,79 @@
|
||||
import bpy
|
||||
from bpy.props import StringProperty
|
||||
from bpy.types import PropertyGroup, UIList, Panel
|
||||
|
||||
class FMT_PT_Panel(Panel):
|
||||
"""Find missing texture panel"""
|
||||
bl_label = "Find missing textures"
|
||||
bl_idname = "FMT_PT_Panel"
|
||||
bl_space_type = "PROPERTIES"
|
||||
bl_region_type = "WINDOW"
|
||||
bl_context = "scene"
|
||||
|
||||
bl_category = "FMT"
|
||||
bl_icon = "OUTLINER_OB_HAIR"
|
||||
|
||||
def invoke(self, context, event):
|
||||
bpy.context.scene.fmt_search_bars.add()
|
||||
|
||||
def draw(self, context):
|
||||
scene = context.scene
|
||||
layout = self.layout
|
||||
row = layout.row()
|
||||
row.label(text=f"Bad images list: ({len(scene.fmt_list)} images)", icon ="LIBRARY_DATA_BROKEN")
|
||||
row = layout.row()
|
||||
row.template_list("List_View", "", scene, "fmt_list", scene, "fmt_list_index")
|
||||
row = layout.row()
|
||||
row.prop(bpy.context.scene, "fmt_select_bad_obj", text = "Select objects with bad textures")
|
||||
row = layout.row()
|
||||
|
||||
row.scale_x = .3
|
||||
row.operator("texture.remove_image", text = 'Delete selected image', icon ="TRASH")
|
||||
row.scale_x = .7
|
||||
row.operator("texture.find_missing_textures", icon ="FILE_REFRESH")
|
||||
row = layout.row()
|
||||
if len(bpy.context.scene.fmt_list) > 0 and len(scene.fmt_search_bars) > 0:
|
||||
|
||||
row.prop(bpy.context.scene, "fmt_extension_replace", text = "Search for images with different extension")
|
||||
row = layout.row()
|
||||
for bar_index in range (len(scene.fmt_search_bars)):
|
||||
row = layout.row()
|
||||
row.prop(scene.fmt_search_bars[bar_index], "bars", text ="Search path")
|
||||
row.operator("texture.bars", text = "", icon ="REMOVE").add = 'F'+ str(bar_index)
|
||||
row.operator("texture.bars", text = "", icon ="ADD").add = 'T'
|
||||
row = layout.row()
|
||||
row.operator("texture.folder_find", text = "Find textures in this folders", icon ="VIEWZOOM")
|
||||
|
||||
|
||||
class List_View(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data,
|
||||
active_propname, index):
|
||||
custom_icon = 'OBJECT_DATAMODE'
|
||||
if self.layout_type in {'DEFAULT', 'COMPACT'}:
|
||||
path_scale = 0.7
|
||||
layout.scale_x = 1 - path_scale
|
||||
layout.label(text=item.img_name)
|
||||
layout.scale_x = path_scale
|
||||
if not bpy.data.images[item.img_name].has_data:
|
||||
layout.prop(bpy.data.images[item.img_name], "filepath", text = "",icon="LIBRARY_DATA_BROKEN")
|
||||
else:
|
||||
layout.prop(bpy.data.images[item.img_name], "filepath", text = "",icon="IMAGE_DATA")
|
||||
|
||||
|
||||
elif self.layout_type in {'GRID'}:
|
||||
layout.alignment = 'CENTER'
|
||||
layout.label(text="", icon = custom_icon)
|
||||
|
||||
class ListItem(PropertyGroup):
|
||||
"""Group of properties representing an item in the list."""
|
||||
img_name: StringProperty(
|
||||
name="Name",
|
||||
description="Name of the image",
|
||||
default="Non")
|
||||
|
||||
class SearchBars(PropertyGroup):
|
||||
bars: StringProperty(
|
||||
name="Searching folder",
|
||||
subtype="DIR_PATH",
|
||||
description="Searching path for the images (folder and sub folders)",
|
||||
default="//")
|
||||
@@ -0,0 +1,26 @@
|
||||
**Last Updated:** 12/02/2025
|
||||
|
||||
This Personal Use License Agreement ("Agreement") is a legal agreement between you ("User") and Chris Braithwaite ("Licensor") for the use of the Visemes Lipsync Blender Plugin, and associated blender model ("Software"). By downloading, installing, or using the Software, you agree to the following terms:
|
||||
|
||||
1. **Personal Use Only**
|
||||
You may use this Software for personal, non-commercial purposes only.
|
||||
|
||||
2. **No Redistribution**
|
||||
You may not share, distribute, sublicense, or sell this Software in any form.
|
||||
|
||||
3. **No Modification**
|
||||
You may not modify, reverse-engineer, or create derivative works based on this Software.
|
||||
|
||||
4. **No Public or Commercial Use**
|
||||
This Software may not be used for commercial purposes, including but not limited to business, freelance work, or monetized projects.
|
||||
|
||||
5. **Ownership**
|
||||
The Licensor retains all rights, title, and interest in and to the Software. This Agreement grants no ownership rights to the User.
|
||||
|
||||
6. **Termination**
|
||||
Violation of any of these terms will result in immediate termination of this license.
|
||||
|
||||
7. **No Warranty**
|
||||
This Software is provided "as is," without warranty of any kind. The Licensor is not liable for any damages arising from its use.
|
||||
|
||||
By using this Software, you acknowledge that you have read, understood, and agreed to the terms of this Agreement.
|
||||
@@ -0,0 +1,210 @@
|
||||
bl_info = {
|
||||
"name": "Lip Sync",
|
||||
"description": "A tool for generating lip-sync animations using poses from the Asset Browser.",
|
||||
"author": "Blackout Creatively",
|
||||
"version": (1, 0, 3),
|
||||
"blender": (4, 3, 0),
|
||||
"location": "View3D > Tool > My Lipsync",
|
||||
"category": "Animation",
|
||||
}
|
||||
|
||||
import bpy
|
||||
|
||||
|
||||
class LipSyncProperties(bpy.types.PropertyGroup):
|
||||
"""Properties for Lip Sync Tool"""
|
||||
|
||||
prefix: bpy.props.StringProperty(name="Pose Prefix", default="") # Prefix for pose names
|
||||
|
||||
pose_0: bpy.props.StringProperty(name="Rest", default="Rest")
|
||||
pose_1: bpy.props.StringProperty(name="Aa", default="Aa")
|
||||
pose_2: bpy.props.StringProperty(name="D", default="D")
|
||||
pose_3: bpy.props.StringProperty(name="Ee", default="Ee")
|
||||
pose_4: bpy.props.StringProperty(name="F", default="F")
|
||||
pose_5: bpy.props.StringProperty(name="L", default="L")
|
||||
pose_6: bpy.props.StringProperty(name="M", default="M")
|
||||
pose_7: bpy.props.StringProperty(name="Oh", default="Oh")
|
||||
pose_8: bpy.props.StringProperty(name="R", default="R")
|
||||
pose_9: bpy.props.StringProperty(name="S", default="S")
|
||||
pose_10: bpy.props.StringProperty(name="Uh", default="Uh")
|
||||
pose_11: bpy.props.StringProperty(name="W-Oo", default="W-Oo")
|
||||
|
||||
holdPoseOffset: bpy.props.IntProperty(name="Hold Pose Frame Offset", default=2)
|
||||
|
||||
|
||||
class LipSyncPluginOperator(bpy.types.Operator):
|
||||
"""Lip Sync Animation Plugin"""
|
||||
bl_idname = "object.lip_sync_plugin"
|
||||
bl_label = "Lip Sync Animation"
|
||||
|
||||
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
|
||||
|
||||
def execute(self, context):
|
||||
props = context.scene.lip_sync_properties
|
||||
prefix = props.prefix.strip() # Get prefix, if any
|
||||
|
||||
value_to_string = {
|
||||
0: f"{prefix}{props.pose_0}",
|
||||
1: f"{prefix}{props.pose_1}",
|
||||
2: f"{prefix}{props.pose_2}",
|
||||
3: f"{prefix}{props.pose_3}",
|
||||
4: f"{prefix}{props.pose_4}",
|
||||
5: f"{prefix}{props.pose_5}",
|
||||
6: f"{prefix}{props.pose_6}",
|
||||
7: f"{prefix}{props.pose_7}",
|
||||
8: f"{prefix}{props.pose_8}",
|
||||
9: f"{prefix}{props.pose_9}",
|
||||
10: f"{prefix}{props.pose_10}",
|
||||
11: f"{prefix}{props.pose_11}",
|
||||
}
|
||||
|
||||
hold_offset = props.holdPoseOffset
|
||||
|
||||
try:
|
||||
with open(self.filepath, 'r') as file:
|
||||
lines = file.readlines()
|
||||
except Exception as e:
|
||||
self.report({'ERROR'}, f"Failed to read file: {e}")
|
||||
return {'CANCELLED'}
|
||||
|
||||
action_name = "Lip Sync"
|
||||
action = bpy.data.actions.get(action_name)
|
||||
if not action:
|
||||
action = bpy.data.actions.new(name=action_name)
|
||||
|
||||
obj = context.object
|
||||
if not obj or obj.type != 'ARMATURE':
|
||||
self.report({'ERROR'}, "No armature selected.")
|
||||
return {'CANCELLED'}
|
||||
|
||||
obj.animation_data_create()
|
||||
obj.animation_data.action = action
|
||||
|
||||
bpy.ops.object.mode_set(mode='POSE')
|
||||
|
||||
keyframe_data = []
|
||||
|
||||
for line in lines:
|
||||
try:
|
||||
parts = line.strip().split('\t')
|
||||
if len(parts) != 2:
|
||||
self.report({'WARNING'}, f"Skipping malformed line: '{line.strip()}'")
|
||||
continue
|
||||
|
||||
time = round(float(parts[0]))
|
||||
int_value = int(parts[1])
|
||||
|
||||
pose_name = value_to_string.get(int_value, None)
|
||||
if pose_name is None:
|
||||
self.report({'WARNING'}, f"Integer value {int_value} is not mapped. Skipping.")
|
||||
continue
|
||||
|
||||
keyframe_data.append((time, pose_name))
|
||||
except Exception as e:
|
||||
self.report({'WARNING'}, f"Error processing line '{line.strip()}': {e}")
|
||||
continue
|
||||
|
||||
keyframe_data.sort()
|
||||
|
||||
selected_bones = [bone.name for bone in obj.pose.bones if bone.bone.select]
|
||||
|
||||
for i, (time, pose_name) in enumerate(keyframe_data):
|
||||
# Apply the pose
|
||||
context.scene.frame_set(time)
|
||||
pose_asset = next(
|
||||
(action for action in bpy.data.actions if action.asset_data and action.name == pose_name),
|
||||
None
|
||||
)
|
||||
if not pose_asset:
|
||||
self.report({'WARNING'}, f"Pose '{pose_name}' not found in the asset library. Skipping.")
|
||||
continue
|
||||
|
||||
for fcurve in pose_asset.fcurves:
|
||||
data_path = fcurve.data_path
|
||||
bone_name = data_path.split('"')[1] if '"' in data_path else None
|
||||
if not bone_name or bone_name not in selected_bones:
|
||||
continue
|
||||
|
||||
pose_bone = obj.pose.bones.get(bone_name)
|
||||
if not pose_bone:
|
||||
continue
|
||||
|
||||
for keyframe in fcurve.keyframe_points:
|
||||
frame, value = keyframe.co
|
||||
if "location" in data_path:
|
||||
pose_bone.location[fcurve.array_index] = value
|
||||
elif "rotation_quaternion" in data_path:
|
||||
pose_bone.rotation_quaternion[fcurve.array_index] = value
|
||||
elif "scale" in data_path:
|
||||
pose_bone.scale[fcurve.array_index] = value
|
||||
|
||||
for bone_name in selected_bones:
|
||||
bone = obj.pose.bones.get(bone_name)
|
||||
if bone:
|
||||
bone.keyframe_insert(data_path="location", frame=time)
|
||||
bone.keyframe_insert(data_path="rotation_quaternion", frame=time)
|
||||
bone.keyframe_insert(data_path="scale", frame=time)
|
||||
|
||||
# Duplicate the pose if the gap between keyframes is too large and holdPoseOffset > 0
|
||||
if hold_offset > 0 and i < len(keyframe_data) - 1:
|
||||
next_time, _ = keyframe_data[i + 1]
|
||||
if next_time - time > hold_offset + 1:
|
||||
hold_time = next_time - hold_offset
|
||||
context.scene.frame_set(hold_time)
|
||||
|
||||
for bone_name in selected_bones:
|
||||
bone = obj.pose.bones.get(bone_name)
|
||||
if bone:
|
||||
bone.keyframe_insert(data_path="location", frame=hold_time)
|
||||
bone.keyframe_insert(data_path="rotation_quaternion", frame=hold_time)
|
||||
bone.keyframe_insert(data_path="scale", frame=hold_time)
|
||||
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
self.report({'INFO'}, "Lip Sync animation created successfully.")
|
||||
return {'FINISHED'}
|
||||
|
||||
def invoke(self, context, event):
|
||||
context.window_manager.fileselect_add(self)
|
||||
return {'RUNNING_MODAL'}
|
||||
|
||||
|
||||
class LipSyncPluginPanel(bpy.types.Panel):
|
||||
"""Creates a Panel in the Tool shelf"""
|
||||
bl_label = "Lip Sync Tool"
|
||||
bl_idname = "OBJECT_PT_lip_sync_tool"
|
||||
bl_space_type = 'VIEW_3D'
|
||||
bl_region_type = 'UI'
|
||||
bl_category = "Lipsync"
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
props = context.scene.lip_sync_properties
|
||||
|
||||
layout.label(text="Pose Prefix:")
|
||||
layout.prop(props, "prefix")
|
||||
|
||||
layout.label(text="Pose Mappings:")
|
||||
for i in range(12):
|
||||
layout.prop(props, f"pose_{i}")
|
||||
|
||||
layout.prop(props, "holdPoseOffset")
|
||||
layout.operator(LipSyncPluginOperator.bl_idname, text="Run Lip Sync Tool")
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(LipSyncProperties)
|
||||
bpy.types.Scene.lip_sync_properties = bpy.props.PointerProperty(type=LipSyncProperties)
|
||||
bpy.utils.register_class(LipSyncPluginOperator)
|
||||
bpy.utils.register_class(LipSyncPluginPanel)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_class(LipSyncPluginPanel)
|
||||
bpy.utils.unregister_class(LipSyncPluginOperator)
|
||||
del bpy.types.Scene.lip_sync_properties
|
||||
bpy.utils.unregister_class(LipSyncProperties)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
register()
|
||||
Binary file not shown.
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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 3 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, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user