Advertisement
Guest User

Untitled

a guest
Oct 20th, 2020
2,961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.60 KB | None | 0 0
  1. # ##### BEGIN LICENSE BLOCK #####
  2. #
  3. #  Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)
  4. #
  5. #  This work is licensed under the Creative Commons
  6. #  Attribution-NonCommercial-NoDerivatives 4.0 International License.
  7. #
  8. #  To view a copy of this license,
  9. #  visit http://creativecommons.org/licenses/by-nc-nd/4.0/.
  10. #
  11. # ##### END LICENSE BLOCK #####
  12.  
  13. bl_info = {
  14.     "name": "INSTAMIST",
  15.     "author": "Darkfall",
  16.     "version": (1, 0),
  17.     "blender": (2, 90, 1),
  18.     "location": "View3D > N > INSTA-MIST",
  19.     "description": "Adds Mist to your scene along with arranging the compositor",
  20.     "warning": "",
  21.     "doc_url": "",
  22.     "category": "Add Mist",
  23. }
  24.  
  25.  
  26. import bpy
  27. from bpy.types import Panel, Operator
  28.  
  29.  
  30. def mist_comp_action(context):
  31.     tree = context.scene.node_tree
  32.    
  33.    
  34.     comp_node = tree.nodes.get('Composite')
  35.     comp_node.location = (700, 0)
  36.    
  37.     viewer_node = tree.nodes.new('CompositorNodeViewer')
  38.     viewer_node.location = (700, 200)
  39.    
  40.     render_layer_node = tree.nodes.get('Render Layers')
  41.     render_layer_node.location = (-200, 0)
  42.    
  43.     mix_node = tree.nodes.new('CompositorNodeMixRGB')
  44.     mix_node.location = (500, 0)
  45.     mix_node.blend_type = 'ADD'
  46.     mix_node.use_clamp = True
  47.    
  48.     mix2_node = tree.nodes.new('CompositorNodeMixRGB')
  49.     mix2_node.location = (300, 0)
  50.     mix2_node.blend_type = 'MULTIPLY'
  51.     mix2_node.use_clamp = True
  52.    
  53.     cr_node = tree.nodes.new('CompositorNodeValToRGB')
  54.     cr_node.location = (0, 0)
  55.     cr_node.color_ramp.elements[0].color = (0.2, 0.2, 0.2, 1)
  56.     cr_node.color_ramp.elements.new(position= 0.27)
  57.    
  58.     link = tree.links.new
  59.    
  60.     link(mix_node.outputs[0], viewer_node.inputs[0])
  61.     link(mix_node.outputs[0], comp_node.inputs[0])
  62.     link(mix2_node.outputs[0], mix_node.inputs[1])
  63.     link(cr_node.outputs[0], mix2_node.inputs[1])
  64.     link(render_layer_node.outputs[0], mix_node.inputs[2])
  65.     link(render_layer_node.outputs[3], cr_node.inputs[0])
  66.     return {'FINISHED'}
  67.  
  68.  
  69.  
  70. class INSTAMIST_PT_main_panel(Panel):
  71.     bl_label = "INSTA-MIST"
  72.     bl_idname = "INSTAMIST_PT_main_panel"
  73.     bl_space_type = 'VIEW_3D'
  74.     bl_region_type = 'UI'
  75.     bl_category = "INSTA-MIST"
  76.  
  77.     def draw(self, context):
  78.         layout = self.layout
  79.         scene = context.scene
  80.        
  81.  
  82.         layout.operator("instamist.add_mist_operator")
  83.  
  84.  
  85. class INSTAMIST_PT_sub_panel(Panel):
  86.     bl_label = "INSTA-MIST Options"
  87.     bl_idname = "INSTAMIST_PT_sub_panel"
  88.     bl_space_type = 'VIEW_3D'
  89.     bl_region_type = 'UI'
  90.     bl_category = "INSTA-MIST"
  91.     bl_parent_id = 'INSTAMIST_PT_main_panel'
  92.    
  93.     @classmethod
  94.     def poll(cls, context):
  95.         return (context.scene.view_layers["View Layer"].use_pass_mist == True
  96. )
  97.  
  98.     def draw(self, context):
  99.         layout = self.layout
  100.         scene = context.scene
  101.         world = scene.world.mist_settings
  102.        
  103.         layout.prop(world, "start")
  104.         layout.prop(world, "depth")
  105.         layout.prop(world, "falloff")
  106.  
  107.  
  108. class INSTAMIST_OT_add_mist(Operator):
  109.     bl_label = "Enable/Disable Mist"
  110.     bl_idname = "instamist.add_mist_operator"
  111.    
  112.    
  113.    
  114.     def execute(self, context):
  115.         scene = context.scene
  116.         camera = bpy.data.cameras['Camera']
  117.         vl = scene.view_layers["View Layer"]
  118.         tree = scene.node_tree
  119.        
  120.         if vl.use_pass_mist == False:
  121.             vl.use_pass_mist = True
  122.             camera.show_mist = True
  123.             if scene.use_nodes == False:
  124.                 scene.use_nodes = True
  125.             mist_comp_action(context)    
  126.            
  127.         elif vl.use_pass_mist == True:
  128.             vl.use_pass_mist = False
  129.             camera.show_mist = False
  130.            
  131.             mix1 = tree.nodes.remove(tree.nodes.get('Mix'))
  132.             mix2 = tree.nodes.remove(tree.nodes.get('Mix.001'))
  133.             cr = tree.nodes.remove(tree.nodes.get('ColorRamp'))
  134.            
  135.             comp_node = tree.nodes.get('Composite')
  136.             viewer_node = tree.nodes.get('Viewer')
  137.             render_layer_node = tree.nodes.get('Render Layers')
  138.            
  139.             tree.links.new(render_layer_node.outputs[0], comp_node.inputs[0])
  140.             tree.links.new(render_layer_node.outputs[0], viewer_node.inputs[0])
  141.         return {'FINISHED'}
  142.    
  143.  
  144. classes = [INSTAMIST_PT_main_panel, INSTAMIST_OT_add_mist, INSTAMIST_PT_sub_panel]
  145.  
  146.  
  147.  
  148. def register():
  149.     for cls in classes:
  150.         bpy.utils.register_class(cls)
  151.        
  152.  
  153. def unregister():
  154.     for cls in classes:
  155.         bpy.utils.unregister_class(cls)
  156.  
  157.  
  158.  
  159. if __name__ == "__main__":
  160.     register()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement