[Bf-blender-cvs] [10c91c2] temp-sybren-poselib: More poselib stuff

Sybren A. Stüvel noreply at git.blender.org
Tue Nov 1 14:54:37 CET 2016


Commit: 10c91c29c52b10b194e6123aeccb9f5173d6f0fd
Author: Sybren A. Stüvel
Date:   Tue Oct 11 10:24:25 2016 +0200
Branches: temp-sybren-poselib
https://developer.blender.org/rB10c91c29c52b10b194e6123aeccb9f5173d6f0fd

More poselib stuff

===================================================================

M	release/scripts/startup/bl_operators/poselib.py
M	release/scripts/startup/bl_ui/__init__.py
M	release/scripts/startup/bl_ui/properties_data_armature.py

===================================================================

diff --git a/release/scripts/startup/bl_operators/poselib.py b/release/scripts/startup/bl_operators/poselib.py
index d74b2c0..44c77ed 100644
--- a/release/scripts/startup/bl_operators/poselib.py
+++ b/release/scripts/startup/bl_operators/poselib.py
@@ -89,13 +89,13 @@ class POSELIB_OT_render_previews(Operator):
     def render_pose(self, context, plib, plib_index):
         import os.path
 
-        frame = plib.pose_markers[plib_index].frame
-        self.log.info('Rendering pose %i at frame %i', plib_index, frame)
+        marker = plib.pose_markers[plib_index]
+        self.log.info('Rendering pose %s at frame %i', marker.name, marker.frame)
 
-        context.scene.frame_set(frame)
+        context.scene.frame_set(marker.frame)
         bpy.ops.poselib.apply_pose(pose_index=plib_index)
 
-        fname = '%03d.png' % (plib_index+1)
+        fname = '%s.png' % marker.name
         context.scene.render.filepath = os.path.join(plib.pose_previews_dir, fname)
         bpy.ops.render.opengl(write_still=True)
 
diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index 1dfca22..4d5c4aa 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -139,6 +139,20 @@ def register():
             default={'OFFICIAL', 'COMMUNITY'},
             options={'ENUM_FLAG'},
             )
+
+    # properties_data_armature.py
+    from . import properties_data_armature
+    bpy.types.Action.pose_previews = EnumProperty(
+        items=properties_data_armature.pose_preview_items,
+        update=properties_data_armature.update_pose)
+    bpy.types.Action.pose_previews_dir = StringProperty(
+        name='Thumbnail Path',
+        subtype='DIR_PATH',
+        default='',
+        # update=filepath_update
+    )
+
+
     # done...
 
 
@@ -148,6 +162,10 @@ def unregister():
     from . import properties_data_armature
     properties_data_armature.unload_custom_icons()
 
+    del bpy.types.Object.pose_previews
+    if properties_data_armature.previews:
+        bpy.utils.previews.remove(properties_data_armature.previews)
+
 
 # Define a default UIList, when a list does not need any custom drawing...
 # Keep in sync with its #defined name in UI_interface.h
diff --git a/release/scripts/startup/bl_ui/properties_data_armature.py b/release/scripts/startup/bl_ui/properties_data_armature.py
index aaa80fb..b98eaf8 100644
--- a/release/scripts/startup/bl_ui/properties_data_armature.py
+++ b/release/scripts/startup/bl_ui/properties_data_armature.py
@@ -161,59 +161,54 @@ class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
         sub.operator("pose.group_deselect", text="Deselect")
 
 
-class POSELIB_UL_poses(bpy.types.UIList):
-    # The draw_item function is called for each item of the collection that is visible in the list.
-    #   data is the RNA object containing the collection,
-    #   item is the currently drawn item of the collection,
-    #   icon is the "computed" icon for the item (as an integer, because some objects like materials or textures
-    #   have custom icons ID, which are not available as enum items).
-    #   active_data is the RNA object containing the active property for the collection (i.e. integer pointing to the
-    #   active item of the collection).
-    #   active_propname is the name of the active property (use 'getattr(active_data, active_propname)').
-    #   index is index of the current item in the collection.
-    #   flt_flag is the result of the filtering process for this item.
-    #   Note: as index and flt_flag are optional arguments, you do not have to use/declare them here if you don't
-    #         need them.
-    def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
-        if self.layout_type != 'GRID':
-            super().draw_item(context, layout, data, item, icon, active_data, active_propname)
-
-        if icon == 17:
-            if icons is None: load_custom_icons()
-            icon = icons['POSE_NOT_HERE'].icon_id
-
-        col = layout.column(align=True)
-        col.alignment = 'CENTER'
-        col.label(text='', icon_value=icon)
-        col.label(text=item.name)
-
-
-icons = None
-
-def load_custom_icons():
-    global icons
-
-    if icons is not None:
-        # Already loaded
-        return
-
-    import bpy.utils.previews
-    import blender_cloud
+previews = None
+
+
+def pose_preview_items(poselib, context):
+    global previews
     import os.path
 
-    icons = bpy.utils.previews.new()
-    icons.load('POSE_NOT_HERE', bpy.path.abspath('//agent_thumbs/001.png'), 'IMAGE')
+    if context is None or not poselib.pose_previews_dir:
+        return []
+
+    directory = bpy.path.abspath(poselib.pose_previews_dir)
+    if not os.path.isdir(directory):
+        return []
+
+    if previews is not None and directory == previews.get('pose_previews_dir', None):
+        return previews.pose_previews
+
+    if previews is None:
+        previews = bpy.utils.previews.new()
+    else:
+        previews.clear()
+
+    no_thumbnail = os.path.join(os.path.dirname(__file__),
+                                'thumbnails',
+                                'no_thumbnail.png')
+    no_thumb_thumb = previews.load('NO THUMBNAIL', no_thumbnail, 'IMAGE')
 
+    enum_items = []
+    for pose_idx, pose_marker in enumerate(poselib.pose_markers):
+        filepath = os.path.join(directory, '%s.png' % pose_marker.name)
+        if os.path.exists(filepath):
+            thumb = previews.load(pose_marker.name, filepath, 'IMAGE')
+        else:
+            print('Warning: "%s" does not exist' % filepath)
+            thumb = no_thumb_thumb
 
-def unload_custom_icons():
-    global icons
+        enum_items.append((pose_marker.name, pose_marker.name, pose_marker.name,
+                           thumb.icon_id, pose_idx))
 
-    if icons is None:
-        # Already unloaded
-        return
+    previews.pose_previews = enum_items
+    previews['pose_previews_dir'] = directory
+    return previews.pose_previews
 
-    bpy.utils.previews.remove(icons)
-    icons = None
+
+def update_pose(poselib_action, context):
+    pose_name = poselib_action.pose_previews
+    poselib_action.pose_markers.active = poselib_action.pose_markers[pose_name]
+    bpy.ops.poselib.apply_pose(pose_index=poselib_action.pose_markers.active_index)
 
 
 class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
@@ -241,10 +236,9 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
         # )
         # list of poses in pose library
         row = layout.row()
-        row.template_list("POSELIB_UL_poses", "pose_markers",
-                          poselib, "pose_markers",
+        row.template_list("UI_UL_list", "pose_markers", poselib, "pose_markers",
                           poselib.pose_markers, "active_index",
-                          rows=5, type='GRID')
+                          rows=5)
         # column of operators for active pose
         # - goes beside list
         col = row.column(align=True)
@@ -272,9 +266,13 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
             layout.prop(pose_marker_active, "camera",
                         text='Camera for %s' % pose_marker_active.name)
 
+        layout.template_icon_view(poselib, 'pose_previews', show_labels=True)
+        layout.prop(poselib, "pose_previews_dir")
+
         col.operator_context = 'INVOKE_DEFAULT'
         layout.operator("poselib.render_previews")
 
+
 # TODO: this panel will soon be deprecated too
 class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
     bl_label = "Ghost"
@@ -397,5 +395,7 @@ class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
     _context_path = "object.data"
     _property_type = bpy.types.Armature
 
+
+
 if __name__ == "__main__":  # only for live edit.
     bpy.utils.register_module(__name__)




More information about the Bf-blender-cvs mailing list