properties_data_armature.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. # ##### BEGIN GPL LICENSE BLOCK #####
  2. #
  3. # This program is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU General Public License
  5. # as published by the Free Software Foundation; either version 2
  6. # of the License, or (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software Foundation,
  15. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. #
  17. # ##### END GPL LICENSE BLOCK #####
  18. # <pep8 compliant>
  19. import bpy
  20. from bpy.types import Panel, Menu
  21. from rna_prop_ui import PropertyPanel
  22. from bl_ui.properties_animviz import (
  23. MotionPathButtonsPanel,
  24. MotionPathButtonsPanel_display,
  25. )
  26. class ArmatureButtonsPanel:
  27. bl_space_type = 'PROPERTIES'
  28. bl_region_type = 'WINDOW'
  29. bl_context = "data"
  30. @classmethod
  31. def poll(cls, context):
  32. return context.armature
  33. class DATA_PT_context_arm(ArmatureButtonsPanel, Panel):
  34. bl_label = ""
  35. bl_options = {'HIDE_HEADER'}
  36. def draw(self, context):
  37. layout = self.layout
  38. ob = context.object
  39. arm = context.armature
  40. space = context.space_data
  41. if ob:
  42. layout.template_ID(ob, "data")
  43. elif arm:
  44. layout.template_ID(space, "pin_id")
  45. class DATA_PT_skeleton(ArmatureButtonsPanel, Panel):
  46. bl_label = "Skeleton"
  47. def draw(self, context):
  48. layout = self.layout
  49. arm = context.armature
  50. layout.row().prop(arm, "pose_position", expand=True)
  51. col = layout.column()
  52. col.label(text="Layers:")
  53. col.prop(arm, "layers", text="")
  54. col.label(text="Protected Layers:")
  55. col.prop(arm, "layers_protected", text="")
  56. class DATA_PT_display(ArmatureButtonsPanel, Panel):
  57. bl_label = "Viewport Display"
  58. bl_options = {'DEFAULT_CLOSED'}
  59. def draw(self, context):
  60. layout = self.layout
  61. layout.use_property_split = True
  62. ob = context.object
  63. arm = context.armature
  64. layout.prop(arm, "display_type", text="Display As")
  65. flow = layout.grid_flow(row_major=False, columns=0, even_columns=False, even_rows=False, align=True)
  66. col = flow.column()
  67. col.prop(arm, "show_names", text="Names")
  68. col = flow.column()
  69. col.prop(arm, "show_axes", text="Axes")
  70. col = flow.column()
  71. col.prop(arm, "show_bone_custom_shapes", text="Shapes")
  72. col = flow.column()
  73. col.prop(arm, "show_group_colors", text="Group Colors")
  74. if ob:
  75. col = flow.column()
  76. col.prop(ob, "show_in_front", text="In Front")
  77. class DATA_MT_bone_group_context_menu(Menu):
  78. bl_label = "Bone Group Specials"
  79. def draw(self, _context):
  80. layout = self.layout
  81. layout.operator("pose.group_sort", icon='SORTALPHA')
  82. class DATA_PT_bone_groups(ArmatureButtonsPanel, Panel):
  83. bl_label = "Bone Groups"
  84. bl_options = {'DEFAULT_CLOSED'}
  85. @classmethod
  86. def poll(cls, context):
  87. return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
  88. def draw(self, context):
  89. layout = self.layout
  90. ob = context.object
  91. pose = ob.pose
  92. group = pose.bone_groups.active
  93. row = layout.row()
  94. rows = 1
  95. if group:
  96. rows = 4
  97. row.template_list(
  98. "UI_UL_list",
  99. "bone_groups",
  100. pose,
  101. "bone_groups",
  102. pose.bone_groups,
  103. "active_index",
  104. rows=rows,
  105. )
  106. col = row.column(align=True)
  107. col.active = (ob.proxy is None)
  108. col.operator("pose.group_add", icon='ADD', text="")
  109. col.operator("pose.group_remove", icon='REMOVE', text="")
  110. col.menu("DATA_MT_bone_group_context_menu", icon='DOWNARROW_HLT', text="")
  111. if group:
  112. col.separator()
  113. col.operator("pose.group_move", icon='TRIA_UP', text="").direction = 'UP'
  114. col.operator("pose.group_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
  115. split = layout.split()
  116. split.active = (ob.proxy is None)
  117. col = split.column()
  118. col.prop(group, "color_set")
  119. if group.color_set:
  120. col = split.column()
  121. sub = col.row(align=True)
  122. sub.enabled = group.is_custom_color_set # only custom colors are editable
  123. sub.prop(group.colors, "normal", text="")
  124. sub.prop(group.colors, "select", text="")
  125. sub.prop(group.colors, "active", text="")
  126. row = layout.row()
  127. row.active = (ob.proxy is None)
  128. sub = row.row(align=True)
  129. sub.operator("pose.group_assign", text="Assign")
  130. # row.operator("pose.bone_group_remove_from", text="Remove")
  131. sub.operator("pose.group_unassign", text="Remove")
  132. sub = row.row(align=True)
  133. sub.operator("pose.group_select", text="Select")
  134. sub.operator("pose.group_deselect", text="Deselect")
  135. class DATA_PT_pose_library(ArmatureButtonsPanel, Panel):
  136. bl_label = "Pose Library"
  137. bl_options = {'DEFAULT_CLOSED'}
  138. @classmethod
  139. def poll(cls, context):
  140. return (context.object and context.object.type == 'ARMATURE' and context.object.pose)
  141. def draw(self, context):
  142. layout = self.layout
  143. ob = context.object
  144. poselib = ob.pose_library
  145. layout.template_ID(ob, "pose_library", new="poselib.new", unlink="poselib.unlink")
  146. if poselib:
  147. # warning about poselib being in an invalid state
  148. if poselib.fcurves and not poselib.pose_markers:
  149. layout.label(icon='ERROR', text="Error: Potentially corrupt library, run 'Sanitize' operator to fix")
  150. # list of poses in pose library
  151. row = layout.row()
  152. row.template_list("UI_UL_list", "pose_markers", poselib, "pose_markers",
  153. poselib.pose_markers, "active_index", rows=5)
  154. # column of operators for active pose
  155. # - goes beside list
  156. col = row.column(align=True)
  157. # invoke should still be used for 'add', as it is needed to allow
  158. # add/replace options to be used properly
  159. col.operator("poselib.pose_add", icon='ADD', text="")
  160. col.operator_context = 'EXEC_DEFAULT' # exec not invoke, so that menu doesn't need showing
  161. pose_marker_active = poselib.pose_markers.active
  162. if pose_marker_active is not None:
  163. col.operator("poselib.pose_remove", icon='REMOVE', text="")
  164. col.operator(
  165. "poselib.apply_pose",
  166. icon='ZOOM_SELECTED',
  167. text="",
  168. ).pose_index = poselib.pose_markers.active_index
  169. col.operator("poselib.action_sanitize", icon='HELP', text="") # XXX: put in menu?
  170. if pose_marker_active is not None:
  171. col.operator("poselib.pose_move", icon='TRIA_UP', text="").direction = 'UP'
  172. col.operator("poselib.pose_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
  173. class DATA_PT_iksolver_itasc(ArmatureButtonsPanel, Panel):
  174. bl_label = "Inverse Kinematics"
  175. bl_options = {'DEFAULT_CLOSED'}
  176. @classmethod
  177. def poll(cls, context):
  178. ob = context.object
  179. return (ob and ob.pose)
  180. def draw(self, context):
  181. layout = self.layout
  182. layout.use_property_split = True
  183. ob = context.object
  184. itasc = ob.pose.ik_param
  185. layout.prop(ob.pose, "ik_solver")
  186. if itasc:
  187. layout.prop(itasc, "mode")
  188. simulation = (itasc.mode == 'SIMULATION')
  189. if simulation:
  190. layout.prop(itasc, "reiteration_method", expand=False)
  191. col = layout.column()
  192. col.active = not simulation or itasc.reiteration_method != 'NEVER'
  193. col.prop(itasc, "precision")
  194. col.prop(itasc, "iterations")
  195. if simulation:
  196. col.prop(itasc, "use_auto_step")
  197. sub = layout.column(align=True)
  198. if itasc.use_auto_step:
  199. sub.prop(itasc, "step_min", text="Steps Min")
  200. sub.prop(itasc, "step_max", text="Max")
  201. else:
  202. sub.prop(itasc, "step_count", text="Steps")
  203. col.prop(itasc, "solver")
  204. if simulation:
  205. col.prop(itasc, "feedback")
  206. col.prop(itasc, "velocity_max")
  207. if itasc.solver == 'DLS':
  208. col.separator()
  209. col.prop(itasc, "damping_max", text="Damping Max", slider=True)
  210. col.prop(itasc, "damping_epsilon", text="Damping Epsilon", slider=True)
  211. class DATA_PT_motion_paths(MotionPathButtonsPanel, Panel):
  212. #bl_label = "Bones Motion Paths"
  213. bl_options = {'DEFAULT_CLOSED'}
  214. bl_context = "data"
  215. @classmethod
  216. def poll(cls, context):
  217. # XXX: include pose-mode check?
  218. return (context.object) and (context.armature)
  219. def draw(self, context):
  220. # layout = self.layout
  221. ob = context.object
  222. avs = ob.pose.animation_visualization
  223. pchan = context.active_pose_bone
  224. mpath = pchan.motion_path if pchan else None
  225. self.draw_settings(context, avs, mpath, bones=True)
  226. class DATA_PT_motion_paths_display(MotionPathButtonsPanel_display, Panel):
  227. #bl_label = "Bones Motion Paths"
  228. bl_context = "data"
  229. bl_parent_id = "DATA_PT_motion_paths"
  230. bl_options = {'DEFAULT_CLOSED'}
  231. @classmethod
  232. def poll(cls, context):
  233. # XXX: include pose-mode check?
  234. return (context.object) and (context.armature)
  235. def draw(self, context):
  236. # layout = self.layout
  237. ob = context.object
  238. avs = ob.pose.animation_visualization
  239. pchan = context.active_pose_bone
  240. mpath = pchan.motion_path if pchan else None
  241. self.draw_settings(context, avs, mpath, bones=True)
  242. class DATA_PT_custom_props_arm(ArmatureButtonsPanel, PropertyPanel, Panel):
  243. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  244. _context_path = "object.data"
  245. _property_type = bpy.types.Armature
  246. classes = (
  247. DATA_PT_context_arm,
  248. DATA_PT_skeleton,
  249. DATA_MT_bone_group_context_menu,
  250. DATA_PT_bone_groups,
  251. DATA_PT_pose_library,
  252. DATA_PT_motion_paths,
  253. DATA_PT_motion_paths_display,
  254. DATA_PT_display,
  255. DATA_PT_iksolver_itasc,
  256. DATA_PT_custom_props_arm,
  257. )
  258. if __name__ == "__main__": # only for live edit.
  259. from bpy.utils import register_class
  260. for cls in classes:
  261. register_class(cls)