-
-
Save spawly/3ceee6897519e74c3d3cddd3f96ef073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
""" | |
############################################################################### | |
PROPERTY GROUPS: START-UP CONFIGURATION OF DATA IN PANELS UI. | |
############################################################################### | |
""" | |
GroupObjectsData = None | |
class GroupObjects: | |
def __init__(self, blender_objects: bpy.types.bpy_prop_collection = None): | |
self.blender_objs = [] | |
self.data = {} | |
if len(blender_objects) > 0: | |
for obj in blender_objects: | |
if "Group_obj" in obj.name: | |
self.blender_objs.append(obj) | |
def add_keypose(self, frame: int): | |
bpy.context.scene.frame_current = frame | |
frame_name = "frame_" + str(frame) | |
self.data[frame_name] = {} | |
for obj in self.blender_objs: | |
x, y, z = obj.location | |
self.data[frame_name][obj.name] = (x, y, z) | |
obj.keyframe_insert(data_path="location", frame=frame) | |
class GroupPosesPropertyGroup_PGT(bpy.types.PropertyGroup): | |
frame = bpy.props.IntProperty(name="hui") | |
class GroupKeyposes_UL(bpy.types.UIList): | |
def draw_item(self, context, layout, data, item, icon, active_data, active_propname): | |
if self.layout_type in {'DEFAULT', 'COMPACT'}: | |
if item: | |
row = layout.row() | |
row.prop(item, "frame", text="frame_" + str(item.frame)) | |
row.enabled = False | |
else: | |
layout.label(text="", translate=False, icon_value=icon) | |
elif self.layout_type in {'GRID'}: | |
layout.alignment = 'CENTER' | |
layout.label(text="", icon_value=icon) | |
""" | |
############################################################################### | |
UI AND PANELS FRONTEND. | |
############################################################################### | |
""" | |
class PanelExmpl_PT(bpy.types.Panel): | |
bl_idname = "GroupPosesPanel" | |
bl_label = "Group poses" | |
bl_space_type = 'VIEW_3D' | |
bl_region_type = 'UI' | |
bl_category = 'View' | |
bl_options = {'DEFAULT_CLOSED'} | |
def draw(self, context): | |
layout = self.layout | |
scene = context.scene | |
layout.label(text="Group frames") | |
layout.operator('group.add_keypose', text='Add Keypose') | |
row1 = layout.row() | |
row1.prop(scene, 'current_group_frame') | |
row2 = layout.row() | |
row2.template_list("GroupKeyposes_UL", "myul_id", scene, "group_created_poses", scene, | |
"current_group_frame") | |
""" | |
############################################################################### | |
BACKEND OF BLENDER PANELS UI. | |
############################################################################### | |
""" | |
class AddKeypose_OT(bpy.types.Operator): | |
bl_idname = "group.add_keypose" | |
bl_label = "Add Keypose Operator" | |
bl_options = {"INTERNAL"} | |
def execute(self, context): | |
global GroupObjectsData | |
if GroupObjectsData is None: | |
GroupObjectsData = GroupObjects(bpy.data.objects) | |
scene = context.scene | |
current_frame = scene.frame_current | |
GroupObjectsData.add_keypose(current_frame) | |
scene.current_group_frame = current_frame | |
keypose = scene.group_created_poses.add() | |
keypose.frame = current_frame | |
print("INFO: frame {}; \n{}".format(current_frame, GroupObjectsData.data)) | |
return {"FINISHED"} | |
""" | |
############################################################################### | |
ADDON INFO. REGISTER/UNREGISTER FUNCTIONS. | |
############################################################################### | |
""" | |
bl_info = { | |
"name": "EXMPL ADDON", | |
"version": (0, 1, 0), | |
"blender": (2, 80, 0), | |
"location": "View3D > Sidebar > View Tab > Group Poses", | |
"warning": "", | |
"wiki_url": "", | |
"support": "TESTING" | |
} | |
def register(): | |
bpy.types.Scene.current_group_frame = bpy.props.IntProperty(name="current_group_frame") | |
bpy.utils.register_class(GroupPosesPropertyGroup_PGT) | |
bpy.types.Scene.group_created_poses = bpy.props.CollectionProperty(type=GroupPosesPropertyGroup_PGT) | |
bpy.utils.register_class(GroupKeyposes_UL) | |
bpy.utils.register_class(AddKeypose_OT) | |
bpy.utils.register_class(PanelExmpl_PT) | |
def unregister(): | |
del bpy.types.Scene.group_created_poses | |
bpy.utils.unregister_class(GroupPosesPropertyGroup_PGT) | |
bpy.utils.unregister_class(PanelExmpl_PT) | |
bpy.utils.unregister_class(AddKeypose_OT) | |
bpy.utils.unregister_class(GroupKeyposes_UL) | |
if __name__ == '__main__': | |
register() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment