properties_data_speaker.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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
  21. from rna_prop_ui import PropertyPanel
  22. class DataButtonsPanel:
  23. bl_space_type = 'PROPERTIES'
  24. bl_region_type = 'WINDOW'
  25. bl_context = "data"
  26. @classmethod
  27. def poll(cls, context):
  28. engine = context.engine
  29. return context.speaker and (engine in cls.COMPAT_ENGINES)
  30. class DATA_PT_context_speaker(DataButtonsPanel, Panel):
  31. bl_label = ""
  32. bl_options = {'HIDE_HEADER'}
  33. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  34. def draw(self, context):
  35. layout = self.layout
  36. ob = context.object
  37. speaker = context.speaker
  38. space = context.space_data
  39. split = layout.split(factor=0.65)
  40. if ob:
  41. split.template_ID(ob, "data")
  42. elif speaker:
  43. split.template_ID(space, "pin_id")
  44. class DATA_PT_speaker(DataButtonsPanel, Panel):
  45. bl_label = "Sound"
  46. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  47. def draw(self, context):
  48. layout = self.layout
  49. speaker = context.speaker
  50. layout.template_ID(speaker, "sound", open="sound.open_mono")
  51. layout.use_property_split = True
  52. layout.prop(speaker, "muted")
  53. col = layout.column()
  54. col.active = not speaker.muted
  55. col.prop(speaker, "volume", slider=True)
  56. col.prop(speaker, "pitch")
  57. class DATA_PT_distance(DataButtonsPanel, Panel):
  58. bl_label = "Distance"
  59. bl_options = {'DEFAULT_CLOSED'}
  60. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  61. def draw(self, context):
  62. layout = self.layout
  63. layout.use_property_split = True
  64. speaker = context.speaker
  65. layout.active = not speaker.muted
  66. col = layout.column()
  67. sub = col.column(align=True)
  68. sub.prop(speaker, "volume_min", slider=True, text="Volume Min")
  69. sub.prop(speaker, "volume_max", slider=True, text="Max")
  70. col.prop(speaker, "attenuation")
  71. col.separator()
  72. col.prop(speaker, "distance_max", text="Max Distance")
  73. col.prop(speaker, "distance_reference", text="Distance Reference")
  74. class DATA_PT_cone(DataButtonsPanel, Panel):
  75. bl_label = "Cone"
  76. bl_options = {'DEFAULT_CLOSED'}
  77. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  78. def draw(self, context):
  79. layout = self.layout
  80. layout.use_property_split = True
  81. speaker = context.speaker
  82. layout.active = not speaker.muted
  83. col = layout.column()
  84. sub = col.column(align=True)
  85. sub.prop(speaker, "cone_angle_outer", text="Angle Outer")
  86. sub.prop(speaker, "cone_angle_inner", text="Inner")
  87. col.separator()
  88. col.prop(speaker, "cone_volume_outer", slider=True)
  89. class DATA_PT_custom_props_speaker(DataButtonsPanel, PropertyPanel, Panel):
  90. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  91. _context_path = "object.data"
  92. _property_type = bpy.types.Speaker
  93. classes = (
  94. DATA_PT_context_speaker,
  95. DATA_PT_speaker,
  96. DATA_PT_distance,
  97. DATA_PT_cone,
  98. DATA_PT_custom_props_speaker,
  99. )
  100. if __name__ == "__main__": # only for live edit.
  101. from bpy.utils import register_class
  102. for cls in classes:
  103. register_class(cls)