misc small changes and bmesh support for testing script
[blender.git] / intern / cycles / blender / addon / ui.py
index da99e4e23d633843679fab2d41df666ae3570eb3..70f38fa7e8ccc97235143c4c674a655c4f092c48 100644 (file)
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 
+# <pep8 compliant>
+
 import bpy
 
 from bpy.types import Panel, Menu
 
-from cycles import enums
-from cycles import engine
+from . import enums, engine
+
 
 class CYCLES_MT_integrator_presets(Menu):
     bl_label = "Integrator Presets"
@@ -30,16 +32,18 @@ class CYCLES_MT_integrator_presets(Menu):
     COMPAT_ENGINES = {'CYCLES'}
     draw = Menu.draw_preset
 
+
 class CyclesButtonsPanel():
     bl_space_type = "PROPERTIES"
     bl_region_type = "WINDOW"
     bl_context = "render"
-    
+
     @classmethod
     def poll(cls, context):
         rd = context.scene.render
         return rd.engine == 'CYCLES'
 
+
 class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel):
     bl_label = "Integrator"
     bl_options = {'DEFAULT_CLOSED'}
@@ -49,7 +53,7 @@ class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel):
 
         scene = context.scene
         cscene = scene.cycles
-        
+
         row = layout.row(align=True)
         row.menu("CYCLES_MT_integrator_presets", text=bpy.types.CYCLES_MT_integrator_presets.bl_label)
         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMIN")
@@ -59,15 +63,16 @@ class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel):
 
         col = split.column()
         sub = col.column(align=True)
-        sub.label(text="Passes:")
-        sub.prop(cscene, "passes", text="Render")
-        sub.prop(cscene, "preview_passes", text="Preview")
+        sub.label(text="Samples:")
+        sub.prop(cscene, "samples", text="Render")
+        sub.prop(cscene, "preview_samples", text="Preview")
+        sub.prop(cscene, "seed")
 
         sub = col.column(align=True)
-        sub.label("Tranparency:")
+        sub.label("Transparency:")
         sub.prop(cscene, "transparent_max_bounces", text="Max")
         sub.prop(cscene, "transparent_min_bounces", text="Min")
-        sub.prop(cscene, "no_caustics")
+        sub.prop(cscene, "use_transparent_shadows", text="Shadows")
 
         col = split.column()
 
@@ -81,11 +86,13 @@ class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel):
         sub.prop(cscene, "diffuse_bounces", text="Diffuse")
         sub.prop(cscene, "glossy_bounces", text="Glossy")
         sub.prop(cscene, "transmission_bounces", text="Transmission")
+        sub.prop(cscene, "no_caustics")
 
         #row = col.row()
         #row.prop(cscene, "blur_caustics")
         #row.active = not cscene.no_caustics
-        
+
+
 class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
     bl_label = "Film"
 
@@ -97,7 +104,7 @@ class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
 
         split = layout.split()
 
-        col = split.column();
+        col = split.column()
         col.prop(cscene, "film_exposure")
         col.prop(cscene, "film_transparent")
 
@@ -107,6 +114,7 @@ class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
         if cscene.filter_type != 'BOX':
             sub.prop(cscene, "filter_width", text="Width")
 
+
 class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
     bl_label = "Performance"
     bl_options = {'DEFAULT_CLOSED'}
@@ -139,6 +147,45 @@ class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
         sub.label(text="Acceleration structure:")
         sub.prop(cscene, "debug_bvh_type", text="")
         sub.prop(cscene, "debug_use_spatial_splits")
+        sub.prop(cscene, "use_cache")
+
+
+class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
+    bl_label = "Layers"
+    bl_options = {'DEFAULT_CLOSED'}
+    COMPAT_ENGINES = {'BLENDER_RENDER'}
+
+    def draw(self, context):
+        layout = self.layout
+
+        scene = context.scene
+        rd = scene.render
+
+        row = layout.row()
+        row.template_list(rd, "layers", rd.layers, "active_index", rows=2)
+
+        col = row.column(align=True)
+        col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
+        col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
+
+        row = layout.row()
+        rl = rd.layers.active
+        row.prop(rl, "name")
+        row.prop(rd, "use_single_layer", text="", icon_only=True)
+
+        split = layout.split()
+
+        col = split.column()
+        col.prop(scene, "layers", text="Scene")
+
+        col = split.column()
+        col.prop(rl, "layers", text="Layer")
+
+        layout.separator()
+
+        rl = rd.layers[0]
+        layout.prop(rl, "material_override", text="Material")
+
 
 class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
     bl_label = "Post Processing"
@@ -158,21 +205,40 @@ class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
         col = split.column()
         col.prop(rd, "dither_intensity", text="Dither", slider=True)
 
-class Cycles_PT_camera(CyclesButtonsPanel, Panel):
-    bl_label = "Cycles"
+
+class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
+    bl_label = "Depth of Field"
     bl_context = "data"
 
     @classmethod
     def poll(cls, context):
-        return context.camera
+        return context.camera and CyclesButtonsPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
 
-        camera = context.camera
-        ccamera = camera.cycles
+        cam = context.camera
+        ccam = cam.cycles
+
+        split = layout.split()
+
+        col = split.column()
+        col.label("Focus:")
+        col.prop(cam, "dof_object", text="")
+
+        sub = col.row()
+        sub.active = cam.dof_object is None
+        sub.prop(cam, "dof_distance", text="Distance")
+
+        col = split.column()
+
+        col.label("Aperture:")
+        col.prop(ccam, "aperture_size", text="Size")
+
+        sub = col.column(align=True)
+        sub.prop(ccam, "aperture_blades", text="Blades")
+        sub.prop(ccam, "aperture_rotation", text="Rotation")
 
-        layout.prop(ccamera, "lens_radius")
 
 class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
     bl_label = "Surface"
@@ -222,13 +288,19 @@ class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
             split.template_ID(space, "pin_id")
             split.separator()
 
+
 class Cycles_PT_mesh_displacement(CyclesButtonsPanel, Panel):
     bl_label = "Displacement"
     bl_context = "data"
 
     @classmethod
     def poll(cls, context):
-        return context.mesh or context.curve or context.meta_ball
+        if CyclesButtonsPanel.poll(context):
+            if context.mesh or context.curve or context.meta_ball:
+                if context.scene.cycles.feature_set == 'EXPERIMENTAL':
+                    return True
+
+        return False
 
     def draw(self, context):
         layout = self.layout
@@ -245,8 +317,9 @@ class Cycles_PT_mesh_displacement(CyclesButtonsPanel, Panel):
             cdata = mball.cycles
 
         layout.prop(cdata, "displacement_method", text="Method")
-        layout.prop(cdata, "use_subdivision");
-        layout.prop(cdata, "dicing_rate");
+        layout.prop(cdata, "use_subdivision")
+        layout.prop(cdata, "dicing_rate")
+
 
 class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
     bl_label = "Ray Visibility"
@@ -256,7 +329,7 @@ class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
     @classmethod
     def poll(cls, context):
         ob = context.object
-        return ob and ob.type in ('MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META') # todo: 'LAMP'
+        return CyclesButtonsPanel.poll(context) and ob and ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META'}  # todo: 'LAMP'
 
     def draw(self, context):
         layout = self.layout
@@ -275,39 +348,45 @@ class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
         col.prop(visibility, "transmission")
         col.prop(visibility, "shadow")
 
+
 def find_node(material, nodetype):
     if material and material.node_tree:
         ntree = material.node_tree
 
         for node in ntree.nodes:
-            if type(node) is not bpy.types.NodeGroup and node.type == nodetype:
+            if getattr(node, "type", None) == nodetype:
                 return node
-    
+
     return None
 
+
 def find_node_input(node, name):
     for input in node.inputs:
         if input.name == name:
             return input
-    
+
     return None
 
-def panel_node_draw(layout, id, output_type, input_name):
-    if not id.node_tree:
-        layout.prop(id, "use_nodes")
-        return
 
-    ntree = id.node_tree
+def panel_node_draw(layout, id_data, output_type, input_name):
+    if not id_data.node_tree:
+        layout.prop(id_data, "use_nodes", icon='NODETREE')
+        return False
+
+    ntree = id_data.node_tree
 
-    node = find_node(id, output_type)
+    node = find_node(id_data, output_type)
     if not node:
         layout.label(text="No output node.")
     else:
         input = find_node_input(node, input_name)
-        layout.template_node_view(ntree, node, input);
+        layout.template_node_view(ntree, node, input)
+
+    return True
+
 
 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
-    bl_label = "Surface"
+    bl_label = "Lamp"
     bl_context = "data"
 
     @classmethod
@@ -317,8 +396,50 @@ class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
 
-        mat = context.lamp
-        panel_node_draw(layout, mat, 'OUTPUT_LAMP', 'Surface')
+        lamp = context.lamp
+        clamp = lamp.cycles
+
+        layout.prop(lamp, "type", expand=True)
+
+        split = layout.split()
+        col = split.column(align=True)
+
+        if lamp.type in {'POINT', 'SUN', 'SPOT'}:
+            col.prop(lamp, "shadow_soft_size", text="Size")
+        elif lamp.type == 'AREA':
+            col.prop(lamp, "shape", text="")
+            sub = col.column(align=True)
+
+            if lamp.shape == 'SQUARE':
+                sub.prop(lamp, "size")
+            elif lamp.shape == 'RECTANGLE':
+                sub.prop(lamp, "size", text="Size X")
+                sub.prop(lamp, "size_y", text="Size Y")
+
+        col = split.column()
+        col.prop(clamp, "cast_shadow")
+
+        if lamp.type == 'SPOT':
+            layout.label(text="Not supported, interpreted as point lamp.")
+        elif lamp.type == 'HEMI':
+            layout.label(text="Not supported, interpreted as sun lamp.")
+
+
+class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
+    bl_label = "Nodes"
+    bl_context = "data"
+
+    @classmethod
+    def poll(cls, context):
+        return context.lamp and CyclesButtonsPanel.poll(context)
+
+    def draw(self, context):
+        layout = self.layout
+
+        lamp = context.lamp
+        if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
+            layout.prop(lamp, "color")
+
 
 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
     bl_label = "Surface"
@@ -331,23 +452,29 @@ class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
 
-        mat = context.world
-        panel_node_draw(layout, mat, 'OUTPUT_WORLD', 'Surface')
+        world = context.world
+        if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
+            layout.prop(world, "horizon_color", text="Color")
+
 
 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
     bl_label = "Volume"
     bl_context = "world"
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(cls, context):
-        return context.world and CyclesButtonsPanel.poll(context)
+        # world = context.world
+        # world and world.node_tree and CyclesButtonsPanel.poll(context)
+        return False
 
     def draw(self, context):
         layout = self.layout
         layout.active = False
 
-        mat = context.world
-        panel_node_draw(layout, mat, 'OUTPUT_WORLD', 'Volume')
+        world = context.world
+        panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
+
 
 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
     bl_label = "Surface"
@@ -361,30 +488,41 @@ class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
         layout = self.layout
 
         mat = context.material
-        panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface')
+        if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
+            layout.prop(mat, "diffuse_color")
+
 
 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
     bl_label = "Volume"
     bl_context = "material"
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(cls, context):
-        return context.material and CyclesButtonsPanel.poll(context)
+        # mat = context.material
+        # mat and mat.node_tree and CyclesButtonsPanel.poll(context)
+        return False
 
     def draw(self, context):
         layout = self.layout
         layout.active = False
 
         mat = context.material
+        cmat = mat.cycles
+
         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
 
+        layout.prop(cmat, "homogeneous_volume")
+
+
 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
     bl_label = "Displacement"
     bl_context = "material"
 
     @classmethod
     def poll(cls, context):
-        return context.material and CyclesButtonsPanel.poll(context)
+        mat = context.material
+        return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
@@ -392,6 +530,7 @@ class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
         mat = context.material
         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
 
+
 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
     bl_label = "Settings"
     bl_context = "material"
@@ -399,17 +538,22 @@ class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
 
     @classmethod
     def poll(cls, context):
-        # return context.material and CyclesButtonsPanel.poll(context)
-        return False
+        return context.material and CyclesButtonsPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
 
         mat = context.material
-    
-        row = layout.row()
-        row.label(text="Light Group:")
-        row.prop(mat, "light_group", text="")
+        cmat = mat.cycles
+
+        split = layout.split()
+
+        col = split.column()
+        col.prop(mat, "diffuse_color", text="Viewport Color")
+
+        col = split.column()
+        col.prop(cmat, "sample_as_light")
+
 
 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
     bl_label = ""
@@ -423,9 +567,9 @@ class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
         tex = context.texture
         space = context.space_data
         pin_id = space.pin_id
-        use_pin_id = space.use_pin_id;
+        use_pin_id = space.use_pin_id
         user = context.texture_user
-        node = context.texture_node
+        node = context.texture_node
 
         if not use_pin_id or not isinstance(pin_id, bpy.types.Texture):
             pin_id = None
@@ -443,7 +587,7 @@ class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
                 col.template_ID(space, "pin_id")
             elif user:
                 col.template_ID(user, "texture", new="texture.new")
-            
+
             if tex:
                 row = split.row()
                 row.prop(tex, "use_nodes", icon="NODETREE", text="")
@@ -454,6 +598,7 @@ class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
                     split.label(text="Type:")
                     split.prop(tex, "type", text="")
 
+
 class CyclesTexture_PT_nodes(CyclesButtonsPanel, Panel):
     bl_label = "Nodes"
     bl_context = "texture"
@@ -469,6 +614,7 @@ class CyclesTexture_PT_nodes(CyclesButtonsPanel, Panel):
         tex = context.texture
         panel_node_draw(layout, tex, 'OUTPUT_TEXTURE', 'Color')
 
+
 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
     bl_label = "Node"
     bl_context = "texture"
@@ -485,6 +631,7 @@ class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
         ntree = node.id_data
         layout.template_node_view(ntree, node, None)
 
+
 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
     bl_label = "Mapping"
     bl_context = "texture"
@@ -497,41 +644,82 @@ class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
 
     def draw(self, context):
         layout = self.layout
-        layout.label("Texture coordinate mapping goes here.");
-        layout.label("Translate, rotate, scale, projection, XYZ.")
 
-class CyclesTexture_PT_color(CyclesButtonsPanel, Panel):
+        # tex = context.texture
+        node = context.texture_node
+
+        mapping = node.texture_mapping
+
+        row = layout.row()
+
+        row.column().prop(mapping, "location")
+        row.column().prop(mapping, "rotation")
+        row.column().prop(mapping, "scale")
+
+        layout.label(text="Projection:")
+
+        row = layout.row()
+        row.prop(mapping, "mapping_x", text="")
+        row.prop(mapping, "mapping_y", text="")
+        row.prop(mapping, "mapping_z", text="")
+
+
+class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
     bl_label = "Color"
     bl_context = "texture"
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(cls, context):
-        tex = context.texture
-        node = context.texture_node
-        return (node or (tex and tex.use_nodes)) and CyclesButtonsPanel.poll(context)
+        # tex = context.texture
+        # node = context.texture_node
+        return False
+        #return (node or (tex and tex.use_nodes)) and CyclesButtonsPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
-        layout.label("Color modification options go here.");
-        layout.label("Ramp, brightness, contrast, saturation.")
-    
+
+        # tex = context.texture
+        node = context.texture_node
+
+        mapping = node.color_mapping
+
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Blend:")
+        col.prop(mapping, "blend_type", text="")
+        col.prop(mapping, "blend_factor", text="Factor")
+        col.prop(mapping, "blend_color", text="")
+
+        col = split.column()
+        col.label(text="Adjust:")
+        col.prop(mapping, "brightness")
+        col.prop(mapping, "contrast")
+        col.prop(mapping, "saturation")
+
+        layout.separator()
+
+        layout.prop(mapping, "use_color_ramp", text="Ramp")
+        if mapping.use_color_ramp:
+            layout.template_color_ramp(mapping, "color_ramp", expand=True)
+
+
 def draw_device(self, context):
     scene = context.scene
     layout = self.layout
 
-    if scene.render.engine == "CYCLES":
+    if scene.render.engine == 'CYCLES':
         cscene = scene.cycles
 
-        available_devices = engine.available_devices()
-        available_cuda = 'cuda' in available_devices
-        available_opencl = 'opencl' in available_devices
+        layout.prop(cscene, "feature_set")
 
-        if available_cuda or available_opencl:
+        device_type = context.user_preferences.system.compute_device_type
+        if device_type == 'CUDA':
+            layout.prop(cscene, "device")
+        elif device_type == 'OPENCL' and cscene.feature_set == 'EXPERIMENTAL':
             layout.prop(cscene, "device")
-            if cscene.device == 'GPU' and available_cuda and available_opencl:
-                layout.prop(cscene, "gpu_type")
-        if cscene.device == 'CPU' and engine.with_osl():
-            layout.prop(cscene, "shading_system")
+
 
 def draw_pause(self, context):
     layout = self.layout
@@ -540,17 +728,24 @@ def draw_pause(self, context):
     if scene.render.engine == "CYCLES":
         view = context.space_data
 
-        if view.viewport_shade == "RENDERED":
+        if view.viewport_shade == 'RENDERED':
             cscene = scene.cycles
             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
 
+
 def get_panels():
-    return [
+    return (
         bpy.types.RENDER_PT_render,
         bpy.types.RENDER_PT_output,
         bpy.types.RENDER_PT_encoding,
         bpy.types.RENDER_PT_dimensions,
         bpy.types.RENDER_PT_stamp,
+        bpy.types.SCENE_PT_scene,
+        bpy.types.SCENE_PT_audio,
+        bpy.types.SCENE_PT_unit,
+        bpy.types.SCENE_PT_keying_sets,
+        bpy.types.SCENE_PT_keying_set_paths,
+        bpy.types.SCENE_PT_physics,
         bpy.types.WORLD_PT_context_world,
         bpy.types.DATA_PT_context_mesh,
         bpy.types.DATA_PT_context_camera,
@@ -564,6 +759,7 @@ def get_panels():
         bpy.types.DATA_PT_vertex_colors,
         bpy.types.DATA_PT_camera,
         bpy.types.DATA_PT_camera_display,
+        bpy.types.DATA_PT_lens,
         bpy.types.DATA_PT_custom_props_mesh,
         bpy.types.DATA_PT_custom_props_camera,
         bpy.types.DATA_PT_custom_props_lamp,
@@ -581,7 +777,24 @@ def get_panels():
         bpy.types.TEXTURE_PT_distortednoise,
         bpy.types.TEXTURE_PT_voxeldata,
         bpy.types.TEXTURE_PT_pointdensity,
-        bpy.types.TEXTURE_PT_pointdensity_turbulence]
+        bpy.types.TEXTURE_PT_pointdensity_turbulence,
+        bpy.types.PARTICLE_PT_context_particles,
+        bpy.types.PARTICLE_PT_emission,
+        bpy.types.PARTICLE_PT_hair_dynamics,
+        bpy.types.PARTICLE_PT_cache,
+        bpy.types.PARTICLE_PT_velocity,
+        bpy.types.PARTICLE_PT_rotation,
+        bpy.types.PARTICLE_PT_physics,
+        bpy.types.PARTICLE_PT_boidbrain,
+        bpy.types.PARTICLE_PT_render,
+        bpy.types.PARTICLE_PT_draw,
+        bpy.types.PARTICLE_PT_children,
+        bpy.types.PARTICLE_PT_field_weights,
+        bpy.types.PARTICLE_PT_force_fields,
+        bpy.types.PARTICLE_PT_vertexgroups,
+        bpy.types.PARTICLE_PT_custom_props,
+        )
+
 
 def register():
     bpy.types.RENDER_PT_render.append(draw_device)
@@ -589,11 +802,11 @@ def register():
 
     for panel in get_panels():
         panel.COMPAT_ENGINES.add('CYCLES')
-    
+
+
 def unregister():
     bpy.types.RENDER_PT_render.remove(draw_device)
     bpy.types.VIEW3D_HT_header.remove(draw_pause)
 
     for panel in get_panels():
         panel.COMPAT_ENGINES.remove('CYCLES')
-