Cleanup: pep8, cycles

This commit is contained in:
Campbell Barton
2018-07-12 11:03:13 +02:00
parent b328a59373
commit 0108ce1fe5
5 changed files with 883 additions and 866 deletions

View File

@@ -47,7 +47,7 @@ import bpy
from . import ( from . import (
engine, engine,
version_update, version_update,
) )
class CyclesRender(bpy.types.RenderEngine): class CyclesRender(bpy.types.RenderEngine):

View File

@@ -83,14 +83,16 @@ def _parse_command_line():
import _cycles import _cycles
_cycles.set_resumable_chunk( _cycles.set_resumable_chunk(
int(args.cycles_resumable_num_chunks), int(args.cycles_resumable_num_chunks),
int(args.cycles_resumable_current_chunk)) int(args.cycles_resumable_current_chunk),
)
elif args.cycles_resumable_start_chunk is not None and \ elif args.cycles_resumable_start_chunk is not None and \
args.cycles_resumable_end_chunk: args.cycles_resumable_end_chunk:
import _cycles import _cycles
_cycles.set_resumable_chunk_range( _cycles.set_resumable_chunk_range(
int(args.cycles_resumable_num_chunks), int(args.cycles_resumable_num_chunks),
int(args.cycles_resumable_start_chunk), int(args.cycles_resumable_start_chunk),
int(args.cycles_resumable_end_chunk)) int(args.cycles_resumable_end_chunk),
)
def init(): def init():
@@ -206,6 +208,7 @@ def system_info():
import _cycles import _cycles
return _cycles.system_info() return _cycles.system_info()
def register_passes(engine, scene, srl): def register_passes(engine, scene, srl):
engine.register_pass(scene, srl, "Combined", 4, "RGBA", 'COLOR') engine.register_pass(scene, srl, "Combined", 4, "RGBA", 'COLOR')

View File

@@ -31,7 +31,7 @@ import _cycles
enum_devices = ( enum_devices = (
('CPU', "CPU", "Use CPU for rendering"), ('CPU', "CPU", "Use CPU for rendering"),
('GPU', "GPU Compute", "Use GPU compute device for rendering, configured in the system tab in the user preferences"), ('GPU', "GPU Compute", "Use GPU compute device for rendering, configured in the system tab in the user preferences"),
) )
if _cycles.with_network: if _cycles.with_network:
enum_devices += (('NETWORK', "Networked Device", "Use networked device for rendering"),) enum_devices += (('NETWORK', "Networked Device", "Use networked device for rendering"),)
@@ -39,34 +39,34 @@ if _cycles.with_network:
enum_feature_set = ( enum_feature_set = (
('SUPPORTED', "Supported", "Only use finished and supported features"), ('SUPPORTED', "Supported", "Only use finished and supported features"),
('EXPERIMENTAL', "Experimental", "Use experimental and incomplete features that might be broken or change in the future", 'ERROR', 1), ('EXPERIMENTAL', "Experimental", "Use experimental and incomplete features that might be broken or change in the future", 'ERROR', 1),
) )
enum_displacement_methods = ( enum_displacement_methods = (
('BUMP', "Bump Only", "Bump mapping to simulate the appearance of displacement"), ('BUMP', "Bump Only", "Bump mapping to simulate the appearance of displacement"),
('DISPLACEMENT', "Displacement Only", "Use true displacement of surface only, requires fine subdivision"), ('DISPLACEMENT', "Displacement Only", "Use true displacement of surface only, requires fine subdivision"),
('BOTH', "Displacement and Bump", "Combination of true displacement and bump mapping for finer detail"), ('BOTH', "Displacement and Bump", "Combination of true displacement and bump mapping for finer detail"),
) )
enum_bvh_layouts = ( enum_bvh_layouts = (
('BVH2', "BVH2", "", 1), ('BVH2', "BVH2", "", 1),
('BVH4', "BVH4", "", 2), ('BVH4', "BVH4", "", 2),
) )
enum_bvh_types = ( enum_bvh_types = (
('DYNAMIC_BVH', "Dynamic BVH", "Objects can be individually updated, at the cost of slower render time"), ('DYNAMIC_BVH', "Dynamic BVH", "Objects can be individually updated, at the cost of slower render time"),
('STATIC_BVH', "Static BVH", "Any object modification requires a complete BVH rebuild, but renders faster"), ('STATIC_BVH', "Static BVH", "Any object modification requires a complete BVH rebuild, but renders faster"),
) )
enum_filter_types = ( enum_filter_types = (
('BOX', "Box", "Box filter"), ('BOX', "Box", "Box filter"),
('GAUSSIAN', "Gaussian", "Gaussian filter"), ('GAUSSIAN', "Gaussian", "Gaussian filter"),
('BLACKMAN_HARRIS', "Blackman-Harris", "Blackman-Harris filter"), ('BLACKMAN_HARRIS', "Blackman-Harris", "Blackman-Harris filter"),
) )
enum_aperture_types = ( enum_aperture_types = (
('RADIUS', "Radius", "Directly change the size of the aperture"), ('RADIUS', "Radius", "Directly change the size of the aperture"),
('FSTOP', "F-stop", "Change the size of the aperture by f-stop"), ('FSTOP', "F-stop", "Change the size of the aperture by f-stop"),
) )
enum_panorama_types = ( enum_panorama_types = (
('EQUIRECTANGULAR', "Equirectangular", "Render the scene with a spherical camera, also known as Lat Long panorama"), ('EQUIRECTANGULAR', "Equirectangular", "Render the scene with a spherical camera, also known as Lat Long panorama"),
@@ -74,23 +74,23 @@ enum_panorama_types = (
('FISHEYE_EQUISOLID', "Fisheye Equisolid", ('FISHEYE_EQUISOLID', "Fisheye Equisolid",
"Similar to most fisheye modern lens, takes sensor dimensions into consideration"), "Similar to most fisheye modern lens, takes sensor dimensions into consideration"),
('MIRRORBALL', "Mirror Ball", "Uses the mirror ball mapping"), ('MIRRORBALL', "Mirror Ball", "Uses the mirror ball mapping"),
) )
enum_curve_primitives = ( enum_curve_primitives = (
('TRIANGLES', "Triangles", "Create triangle geometry around strands"), ('TRIANGLES', "Triangles", "Create triangle geometry around strands"),
('LINE_SEGMENTS', "Line Segments", "Use line segment primitives"), ('LINE_SEGMENTS', "Line Segments", "Use line segment primitives"),
('CURVE_SEGMENTS', "Curve Segments", "Use segmented cardinal curve primitives"), ('CURVE_SEGMENTS', "Curve Segments", "Use segmented cardinal curve primitives"),
) )
enum_triangle_curves = ( enum_triangle_curves = (
('CAMERA_TRIANGLES', "Planes", "Create individual triangles forming planes that face camera"), ('CAMERA_TRIANGLES', "Planes", "Create individual triangles forming planes that face camera"),
('TESSELLATED_TRIANGLES', "Tessellated", "Create mesh surrounding each strand"), ('TESSELLATED_TRIANGLES', "Tessellated", "Create mesh surrounding each strand"),
) )
enum_curve_shape = ( enum_curve_shape = (
('RIBBONS', "Ribbons", "Ignore thickness of each strand"), ('RIBBONS', "Ribbons", "Ignore thickness of each strand"),
('THICK', "Thick", "Use thickness of strand when rendering"), ('THICK', "Thick", "Use thickness of strand when rendering"),
) )
enum_tile_order = ( enum_tile_order = (
('CENTER', "Center", "Render from center to the edges"), ('CENTER', "Center", "Render from center to the edges"),
@@ -99,46 +99,46 @@ enum_tile_order = (
('TOP_TO_BOTTOM', "Top to Bottom", "Render from top to bottom"), ('TOP_TO_BOTTOM', "Top to Bottom", "Render from top to bottom"),
('BOTTOM_TO_TOP', "Bottom to Top", "Render from bottom to top"), ('BOTTOM_TO_TOP', "Bottom to Top", "Render from bottom to top"),
('HILBERT_SPIRAL', "Hilbert Spiral", "Render in a Hilbert Spiral"), ('HILBERT_SPIRAL', "Hilbert Spiral", "Render in a Hilbert Spiral"),
) )
enum_use_layer_samples = ( enum_use_layer_samples = (
('USE', "Use", "Per render layer number of samples override scene samples"), ('USE', "Use", "Per render layer number of samples override scene samples"),
('BOUNDED', "Bounded", "Bound per render layer number of samples by global samples"), ('BOUNDED', "Bounded", "Bound per render layer number of samples by global samples"),
('IGNORE', "Ignore", "Ignore per render layer number of samples"), ('IGNORE', "Ignore", "Ignore per render layer number of samples"),
) )
enum_sampling_pattern = ( enum_sampling_pattern = (
('SOBOL', "Sobol", "Use Sobol random sampling pattern"), ('SOBOL', "Sobol", "Use Sobol random sampling pattern"),
('CORRELATED_MUTI_JITTER', "Correlated Multi-Jitter", "Use Correlated Multi-Jitter random sampling pattern"), ('CORRELATED_MUTI_JITTER', "Correlated Multi-Jitter", "Use Correlated Multi-Jitter random sampling pattern"),
) )
enum_integrator = ( enum_integrator = (
('BRANCHED_PATH', "Branched Path Tracing", "Path tracing integrator that branches on the first bounce, giving more control over the number of light and material samples"), ('BRANCHED_PATH', "Branched Path Tracing", "Path tracing integrator that branches on the first bounce, giving more control over the number of light and material samples"),
('PATH', "Path Tracing", "Pure path tracing integrator"), ('PATH', "Path Tracing", "Pure path tracing integrator"),
) )
enum_volume_sampling = ( enum_volume_sampling = (
('DISTANCE', "Distance", "Use distance sampling, best for dense volumes with lights far away"), ('DISTANCE', "Distance", "Use distance sampling, best for dense volumes with lights far away"),
('EQUIANGULAR', "Equiangular", "Use equiangular sampling, best for volumes with low density with light inside or near the volume"), ('EQUIANGULAR', "Equiangular", "Use equiangular sampling, best for volumes with low density with light inside or near the volume"),
('MULTIPLE_IMPORTANCE', "Multiple Importance", "Combine distance and equi-angular sampling for volumes where neither method is ideal"), ('MULTIPLE_IMPORTANCE', "Multiple Importance", "Combine distance and equi-angular sampling for volumes where neither method is ideal"),
) )
enum_volume_interpolation = ( enum_volume_interpolation = (
('LINEAR', "Linear", "Good smoothness and speed"), ('LINEAR', "Linear", "Good smoothness and speed"),
('CUBIC', "Cubic", "Smoothed high quality interpolation, but slower") ('CUBIC', "Cubic", "Smoothed high quality interpolation, but slower")
) )
enum_world_mis = ( enum_world_mis = (
('NONE', "None", "Don't sample the background, faster but might cause noise for non-solid backgrounds"), ('NONE', "None", "Don't sample the background, faster but might cause noise for non-solid backgrounds"),
('AUTOMATIC', "Auto", "Automatically try to determine the best setting"), ('AUTOMATIC', "Auto", "Automatically try to determine the best setting"),
('MANUAL', "Manual", "Manually set the resolution of the sampling map, higher values are slower and require more memory but reduce noise") ('MANUAL', "Manual", "Manually set the resolution of the sampling map, higher values are slower and require more memory but reduce noise")
) )
enum_device_type = ( enum_device_type = (
('CPU', "CPU", "CPU", 0), ('CPU', "CPU", "CPU", 0),
('CUDA', "CUDA", "CUDA", 1), ('CUDA', "CUDA", "CUDA", 1),
('OPENCL', "OpenCL", "OpenCL", 2) ('OPENCL', "OpenCL", "OpenCL", 2)
) )
enum_texture_limit = ( enum_texture_limit = (
('OFF', "No Limit", "No texture size limit", 0), ('OFF', "No Limit", "No texture size limit", 0),
@@ -149,7 +149,8 @@ enum_texture_limit = (
('2048', "2048", "Limit texture size to 2048 pixels", 5), ('2048', "2048", "Limit texture size to 2048 pixels", 5),
('4096', "4096", "Limit texture size to 4096 pixels", 6), ('4096', "4096", "Limit texture size to 4096 pixels", 6),
('8192', "8192", "Limit texture size to 8192 pixels", 7), ('8192', "8192", "Limit texture size to 8192 pixels", 7),
) )
class CyclesRenderSettings(bpy.types.PropertyGroup): class CyclesRenderSettings(bpy.types.PropertyGroup):
@classmethod @classmethod
@@ -1139,7 +1140,6 @@ class CyclesObjectSettings(bpy.types.PropertyGroup):
default=False, default=False,
) )
@classmethod @classmethod
def unregister(cls): def unregister(cls):
del bpy.types.Object.cycles del bpy.types.Object.cycles
@@ -1204,12 +1204,14 @@ class CyclesCurveRenderSettings(bpy.types.PropertyGroup):
def unregister(cls): def unregister(cls):
del bpy.types.Scene.cycles_curves del bpy.types.Scene.cycles_curves
def update_render_passes(self, context): def update_render_passes(self, context):
scene = context.scene scene = context.scene
rd = scene.render rd = scene.render
rl = rd.layers.active rl = rd.layers.active
rl.update_render_passes() rl.update_render_passes()
class CyclesRenderLayerSettings(bpy.types.PropertyGroup): class CyclesRenderLayerSettings(bpy.types.PropertyGroup):
@classmethod @classmethod
def register(cls): def register(cls):
@@ -1421,7 +1423,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
return device_entry return device_entry
return None return None
def update_device_entries(self, device_list): def update_device_entries(self, device_list):
for device in device_list: for device in device_list:
if not device[1] in {'CUDA', 'OPENCL', 'CPU'}: if not device[1] in {'CUDA', 'OPENCL', 'CPU'}:
@@ -1439,7 +1440,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
# Update name in case it changed # Update name in case it changed
entry.name = device[0] entry.name = device[0]
def get_devices(self): def get_devices(self):
import _cycles import _cycles
# Layout of the device tuples: (Name, Type, Persistent ID) # Layout of the device tuples: (Name, Type, Persistent ID)
@@ -1465,7 +1465,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
opencl_devices.extend(cpu_devices) opencl_devices.extend(cpu_devices)
return cuda_devices, opencl_devices return cuda_devices, opencl_devices
def get_num_gpu_devices(self): def get_num_gpu_devices(self):
import _cycles import _cycles
device_list = _cycles.available_devices() device_list = _cycles.available_devices()
@@ -1478,11 +1477,9 @@ class CyclesPreferences(bpy.types.AddonPreferences):
num += 1 num += 1
return num return num
def has_active_device(self): def has_active_device(self):
return self.get_num_gpu_devices() > 0 return self.get_num_gpu_devices() > 0
def draw_impl(self, layout, context): def draw_impl(self, layout, context):
layout.label(text="Cycles Compute Device:") layout.label(text="Cycles Compute Device:")
layout.row().prop(self, "compute_device_type", expand=True) layout.row().prop(self, "compute_device_type", expand=True)
@@ -1500,7 +1497,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
for device in opencl_devices: for device in opencl_devices:
box.prop(device, "use", text=device.name) box.prop(device, "use", text=device.name)
def draw(self, context): def draw(self, context):
self.draw_impl(self.layout, context) self.draw_impl(self.layout, context)

View File

@@ -22,7 +22,7 @@ from bpy.types import (
Panel, Panel,
Menu, Menu,
Operator, Operator,
) )
class CYCLES_MT_sampling_presets(Menu): class CYCLES_MT_sampling_presets(Menu):
@@ -86,6 +86,7 @@ def use_sample_all_lights(context):
return cscene.sample_all_lights_direct or cscene.sample_all_lights_indirect return cscene.sample_all_lights_direct or cscene.sample_all_lights_indirect
def show_device_active(context): def show_device_active(context):
cscene = context.scene.cycles cscene = context.scene.cycles
if cscene.device != 'GPU': if cscene.device != 'GPU':
@@ -1741,6 +1742,7 @@ class CYCLES_SCENE_PT_simplify(CyclesButtonsPanel, Panel):
col = split.column() col = split.column()
col.prop(cscene, "ao_bounces_render") col.prop(cscene, "ao_bounces_render")
def draw_device(self, context): def draw_device(self, context):
scene = context.scene scene = context.scene
layout = self.layout layout = self.layout

View File

@@ -75,19 +75,25 @@ def foreach_cycles_node(callback):
traversed = set() traversed = set()
for material in bpy.data.materials: for material in bpy.data.materials:
if check_is_new_shading_material(material): if check_is_new_shading_material(material):
foreach_notree_node(material.node_tree, foreach_notree_node(
material.node_tree,
callback, callback,
traversed) traversed,
)
for world in bpy.data.worlds: for world in bpy.data.worlds:
if check_is_new_shading_world(world): if check_is_new_shading_world(world):
foreach_notree_node(world.node_tree, foreach_notree_node(
world.node_tree,
callback, callback,
traversed) traversed,
)
for lamp in bpy.data.lamps: for lamp in bpy.data.lamps:
if check_is_new_shading_world(lamp): if check_is_new_shading_world(lamp):
foreach_notree_node(lamp.node_tree, foreach_notree_node(
lamp.node_tree,
callback, callback,
traversed) traversed,
)
def displacement_node_insert(material, nodetree, traversed): def displacement_node_insert(material, nodetree, traversed):
@@ -102,9 +108,11 @@ def displacement_node_insert(material, nodetree, traversed):
# Gather links to replace # Gather links to replace
displacement_links = [] displacement_links = []
for link in nodetree.links: for link in nodetree.links:
if link.to_node.bl_idname == 'ShaderNodeOutputMaterial' and \ if (
link.from_node.bl_idname != 'ShaderNodeDisplacement' and \ link.to_node.bl_idname == 'ShaderNodeOutputMaterial' and
link.to_socket.identifier == 'Displacement': link.from_node.bl_idname != 'ShaderNodeDisplacement' and
link.to_socket.identifier == 'Displacement'
):
displacement_links.append(link) displacement_links.append(link)
# Replace links with displacement node # Replace links with displacement node
@@ -117,20 +125,22 @@ def displacement_node_insert(material, nodetree, traversed):
nodetree.links.remove(link) nodetree.links.remove(link)
node = nodetree.nodes.new(type='ShaderNodeDisplacement') node = nodetree.nodes.new(type='ShaderNodeDisplacement')
node.location[0] = 0.5 * (from_node.location[0] + to_node.location[0]); node.location[0] = 0.5 * (from_node.location[0] + to_node.location[0])
node.location[1] = 0.5 * (from_node.location[1] + to_node.location[1]); node.location[1] = 0.5 * (from_node.location[1] + to_node.location[1])
node.inputs['Scale'].default_value = 0.1 node.inputs['Scale'].default_value = 0.1
node.inputs['Midlevel'].default_value = 0.0 node.inputs['Midlevel'].default_value = 0.0
nodetree.links.new(from_socket, node.inputs['Height']) nodetree.links.new(from_socket, node.inputs['Height'])
nodetree.links.new(node.outputs['Displacement'], to_socket) nodetree.links.new(node.outputs['Displacement'], to_socket)
def displacement_nodes_insert(): def displacement_nodes_insert():
traversed = set() traversed = set()
for material in bpy.data.materials: for material in bpy.data.materials:
if check_is_new_shading_material(material): if check_is_new_shading_material(material):
displacement_node_insert(material, material.node_tree, traversed) displacement_node_insert(material, material.node_tree, traversed)
def displacement_principled_nodes(node): def displacement_principled_nodes(node):
if node.bl_idname == 'ShaderNodeDisplacement': if node.bl_idname == 'ShaderNodeDisplacement':
if node.space != 'WORLD': if node.space != 'WORLD':
@@ -139,6 +149,7 @@ def displacement_principled_nodes(node):
if node.subsurface_method != 'RANDOM_WALK': if node.subsurface_method != 'RANDOM_WALK':
node.subsurface_method = 'BURLEY' node.subsurface_method = 'BURLEY'
def square_roughness_node_insert(material, nodetree, traversed): def square_roughness_node_insert(material, nodetree, traversed):
if nodetree in traversed: if nodetree in traversed:
return return
@@ -176,13 +187,14 @@ def square_roughness_node_insert(material, nodetree, traversed):
node = nodetree.nodes.new(type='ShaderNodeMath') node = nodetree.nodes.new(type='ShaderNodeMath')
node.operation = 'POWER' node.operation = 'POWER'
node.location[0] = 0.5 * (from_node.location[0] + to_node.location[0]); node.location[0] = 0.5 * (from_node.location[0] + to_node.location[0])
node.location[1] = 0.5 * (from_node.location[1] + to_node.location[1]); node.location[1] = 0.5 * (from_node.location[1] + to_node.location[1])
nodetree.links.new(from_socket, node.inputs[0]) nodetree.links.new(from_socket, node.inputs[0])
node.inputs[1].default_value = 0.5 node.inputs[1].default_value = 0.5
nodetree.links.new(node.outputs['Value'], to_socket) nodetree.links.new(node.outputs['Value'], to_socket)
def square_roughness_nodes_insert(): def square_roughness_nodes_insert():
traversed = set() traversed = set()
for material in bpy.data.materials: for material in bpy.data.materials:
@@ -298,6 +310,7 @@ def ambient_occlusion_node_relink(material, nodetree, traversed):
nodetree.links.remove(link) nodetree.links.remove(link)
nodetree.links.new(from_node.outputs['Color'], to_socket) nodetree.links.new(from_node.outputs['Color'], to_socket)
def ambient_occlusion_nodes_relink(): def ambient_occlusion_nodes_relink():
traversed = set() traversed = set()
for material in bpy.data.materials: for material in bpy.data.materials:
@@ -335,9 +348,11 @@ def do_versions(self):
for scene in bpy.data.scenes: for scene in bpy.data.scenes:
cscene = scene.cycles cscene = scene.cycles
sample_clamp = cscene.get("sample_clamp", False) sample_clamp = cscene.get("sample_clamp", False)
if (sample_clamp and if (
sample_clamp and
not cscene.is_property_set("sample_clamp_direct") and not cscene.is_property_set("sample_clamp_direct") and
not cscene.is_property_set("sample_clamp_indirect")): not cscene.is_property_set("sample_clamp_indirect")
):
cscene.sample_clamp_direct = sample_clamp cscene.sample_clamp_direct = sample_clamp
cscene.sample_clamp_indirect = sample_clamp cscene.sample_clamp_indirect = sample_clamp
@@ -353,10 +368,11 @@ def do_versions(self):
if bpy.data.version <= (2, 72, 0): if bpy.data.version <= (2, 72, 0):
for scene in bpy.data.scenes: for scene in bpy.data.scenes:
cscene = scene.cycles cscene = scene.cycles
if (cscene.get("no_caustics", False) and if (
cscene.get("no_caustics", False) and
not cscene.is_property_set("caustics_reflective") and not cscene.is_property_set("caustics_reflective") and
not cscene.is_property_set("caustics_refractive")): not cscene.is_property_set("caustics_refractive")
):
cscene.caustics_reflective = False cscene.caustics_reflective = False
cscene.caustics_refractive = False cscene.caustics_refractive = False