[Bf-blender-cvs] [7945bb2] temp-sybren-poselib: More UI stuff, still very rough and depends on pose lib preview property.
Sybren A. Stüvel
noreply at git.blender.org
Fri Sep 30 18:12:38 CEST 2016
Commit: 7945bb2062c2d5ad5b35d7da7184bf8042e4cb01
Author: Sybren A. Stüvel
Date: Fri Sep 30 18:12:29 2016 +0200
Branches: temp-sybren-poselib
https://developer.blender.org/rB7945bb2062c2d5ad5b35d7da7184bf8042e4cb01
More UI stuff, still very rough and depends on pose lib preview property.
===================================================================
M release/scripts/startup/bl_operators/__init__.py
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/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index a696410..01c954d 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -39,6 +39,7 @@ _modules = [
"object",
"object_randomize_transform",
"object_quick_effects",
+ "poselib",
"presets",
"rigidbody",
"screen_play_rendered_anim",
diff --git a/release/scripts/startup/bl_operators/poselib.py b/release/scripts/startup/bl_operators/poselib.py
index 7b550df..d74b2c0 100644
--- a/release/scripts/startup/bl_operators/poselib.py
+++ b/release/scripts/startup/bl_operators/poselib.py
@@ -38,8 +38,11 @@ from bpy.props import (
class POSELIB_OT_render_previews(Operator):
"Renders a preview image for each pose in the pose library"
+ import logging as __logging
+
bl_idname = "poselib.render_previews"
bl_label = "Render pose previews"
+ log = __logging.getLogger('bpy.ops.%s' % bl_idname)
render_method = EnumProperty(
items=[
@@ -51,6 +54,7 @@ class POSELIB_OT_render_previews(Operator):
plib_index = 0
+
@classmethod
def poll(cls, context):
"""Running only makes sense if there are any poses in the library."""
@@ -58,21 +62,54 @@ class POSELIB_OT_render_previews(Operator):
return bool(plib and plib.pose_markers)
def execute(self, context):
+ return {'PASS_THROUGH'}
+
+ def modal(self, context, event):
+ if event.type == 'ESC':
+ self._finish(context)
+ self.report({'INFO'}, 'Canceled rendering pose library previews')
+ return {'CANCELLED'}
+
+ if event.type != 'TIMER':
+ return {'PASS_THROUGH'}
+
plib = context.object.pose_library
- if self.plib_index >= len(plib.pose_markers):
+ pose_count = len(plib.pose_markers)
+ if self.plib_index >= pose_count:
+ self._finish(context)
+ self.report({'INFO'}, 'Done rendering pose library previews')
return {'FINISHED'}
- self.render_pose(self.plib_index)
+ self.render_pose(context, plib, self.plib_index)
self.plib_index += 1
return {'RUNNING_MODAL'}
- def render_pose(self, plib_index):
+ 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)
+
+ context.scene.frame_set(frame)
bpy.ops.poselib.apply_pose(pose_index=plib_index)
+ fname = '%03d.png' % (plib_index+1)
+ context.scene.render.filepath = os.path.join(plib.pose_previews_dir, fname)
+ bpy.ops.render.opengl(write_still=True)
+
def invoke(self, context, event):
wm = context.window_manager
wm.modal_handler_add(self)
+
+ self.wm = context.window_manager
+ self.timer = self.wm.event_timer_add(0.01, context.window)
self.plib_index = 0
+ self.orig_filepath = context.scene.render.filepath
+
return {'RUNNING_MODAL'}
+
+ def _finish(self, context):
+ self.wm.event_timer_remove(self.timer)
+ context.scene.render.filepath = self.orig_filepath
diff --git a/release/scripts/startup/bl_ui/__init__.py b/release/scripts/startup/bl_ui/__init__.py
index 2389be6..1dfca22 100644
--- a/release/scripts/startup/bl_ui/__init__.py
+++ b/release/scripts/startup/bl_ui/__init__.py
@@ -145,6 +145,9 @@ def register():
def unregister():
bpy.utils.unregister_module(__name__)
+ from . import properties_data_armature
+ properties_data_armature.unload_custom_icons()
+
# 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 d47a7e5..aaa80fb 100644
--- a/release/scripts/startup/bl_ui/properties_data_armature.py
+++ b/release/scripts/startup/bl_ui/properties_data_armature.py
@@ -161,6 +161,61 @@ 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
+ import os.path
+
+ icons = bpy.utils.previews.new()
+ icons.load('POSE_NOT_HERE', bpy.path.abspath('//agent_thumbs/001.png'), 'IMAGE')
+
+
+def unload_custom_icons():
+ global icons
+
+ if icons is None:
+ # Already unloaded
+ return
+
+ bpy.utils.previews.remove(icons)
+ icons = None
+
+
class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
bl_label = "Pose Library"
bl_options = {'DEFAULT_CLOSED'}
@@ -180,11 +235,16 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
if not poselib:
return
+ # layout.template_icon_view(
+ # poselib, 'pose_markers',
+ # show_labels=True,
+ # )
# list of poses in pose library
row = layout.row()
- row.template_list("UI_UL_list", "pose_markers", poselib, "pose_markers",
- poselib.pose_markers, "active_index", rows=5)
-
+ row.template_list("POSELIB_UL_poses", "pose_markers",
+ poselib, "pose_markers",
+ poselib.pose_markers, "active_index",
+ rows=5, type='GRID')
# column of operators for active pose
# - goes beside list
col = row.column(align=True)
@@ -211,7 +271,9 @@ class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
layout.prop(pose_marker_active, "camera",
text='Camera for %s' % pose_marker_active.name)
- # layout.operator("poselib.render_previews")
+
+ col.operator_context = 'INVOKE_DEFAULT'
+ layout.operator("poselib.render_previews")
# TODO: this panel will soon be deprecated too
class DATA_PT_ghost(ArmatureButtonsPanel, Panel):
More information about the Bf-blender-cvs
mailing list