properties_world.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. from bpy_extras.node_utils import find_node_input
  23. class WorldButtonsPanel:
  24. bl_space_type = 'PROPERTIES'
  25. bl_region_type = 'WINDOW'
  26. bl_context = "world"
  27. # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
  28. @classmethod
  29. def poll(cls, context):
  30. return (context.world and context.engine in cls.COMPAT_ENGINES)
  31. class WORLD_PT_context_world(WorldButtonsPanel, Panel):
  32. bl_label = ""
  33. bl_options = {'HIDE_HEADER'}
  34. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  35. @classmethod
  36. def poll(cls, context):
  37. return (context.engine in cls.COMPAT_ENGINES)
  38. def draw(self, context):
  39. layout = self.layout
  40. scene = context.scene
  41. world = context.world
  42. space = context.space_data
  43. if scene:
  44. layout.template_ID(scene, "world", new="world.new")
  45. elif world:
  46. layout.template_ID(space, "pin_id")
  47. class EEVEE_WORLD_PT_mist(WorldButtonsPanel, Panel):
  48. bl_label = "Mist Pass"
  49. bl_options = {'DEFAULT_CLOSED'}
  50. COMPAT_ENGINES = {'BLENDER_EEVEE'}
  51. @classmethod
  52. def poll(cls, context):
  53. engine = context.engine
  54. if context.world and (engine in cls.COMPAT_ENGINES):
  55. for view_layer in context.scene.view_layers:
  56. if view_layer.use_pass_mist:
  57. return True
  58. return False
  59. def draw(self, context):
  60. layout = self.layout
  61. layout.use_property_split = True
  62. world = context.world
  63. layout.prop(world.mist_settings, "start")
  64. layout.prop(world.mist_settings, "depth")
  65. layout.prop(world.mist_settings, "falloff")
  66. class WORLD_PT_custom_props(WorldButtonsPanel, PropertyPanel, Panel):
  67. COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
  68. _context_path = "world"
  69. _property_type = bpy.types.World
  70. class EEVEE_WORLD_PT_surface(WorldButtonsPanel, Panel):
  71. bl_label = "Surface"
  72. COMPAT_ENGINES = {'BLENDER_EEVEE'}
  73. @classmethod
  74. def poll(cls, context):
  75. engine = context.engine
  76. return context.world and (engine in cls.COMPAT_ENGINES)
  77. def draw(self, context):
  78. layout = self.layout
  79. world = context.world
  80. layout.prop(world, "use_nodes", icon='NODETREE')
  81. layout.separator()
  82. if world.use_nodes:
  83. ntree = world.node_tree
  84. node = ntree.get_output_node('EEVEE')
  85. if node:
  86. input = find_node_input(node, 'Surface')
  87. if input:
  88. layout.template_node_view(ntree, node, input)
  89. else:
  90. layout.label(text="Incompatible output node")
  91. else:
  92. layout.label(text="No output node")
  93. else:
  94. layout.prop(world, "color")
  95. class EEVEE_WORLD_PT_volume(WorldButtonsPanel, Panel):
  96. bl_label = "Volume"
  97. bl_options = {'DEFAULT_CLOSED'}
  98. COMPAT_ENGINES = {'BLENDER_EEVEE'}
  99. @classmethod
  100. def poll(cls, context):
  101. engine = context.engine
  102. world = context.world
  103. return world and world.use_nodes and (engine in cls.COMPAT_ENGINES)
  104. def draw(self, context):
  105. layout = self.layout
  106. world = context.world
  107. ntree = world.node_tree
  108. node = ntree.get_output_node('EEVEE')
  109. if node:
  110. input = find_node_input(node, 'Volume')
  111. if input:
  112. layout.template_node_view(ntree, node, input)
  113. else:
  114. layout.label(text="Incompatible output node")
  115. else:
  116. layout.label(text="No output node")
  117. class WORLD_PT_viewport_display(WorldButtonsPanel, Panel):
  118. bl_label = "Viewport Display"
  119. bl_options = {'DEFAULT_CLOSED'}
  120. bl_order = 10
  121. @classmethod
  122. def poll(cls, context):
  123. return context.world
  124. def draw(self, context):
  125. layout = self.layout
  126. layout.use_property_split = True
  127. world = context.world
  128. layout.prop(world, "color")
  129. classes = (
  130. WORLD_PT_context_world,
  131. EEVEE_WORLD_PT_surface,
  132. EEVEE_WORLD_PT_volume,
  133. EEVEE_WORLD_PT_mist,
  134. WORLD_PT_viewport_display,
  135. WORLD_PT_custom_props,
  136. )
  137. if __name__ == "__main__": # only for live edit.
  138. from bpy.utils import register_class
  139. for cls in classes:
  140. register_class(cls)