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

@@ -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

@@ -151,6 +151,7 @@ enum_texture_limit = (
('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
def register(cls): def register(cls):
@@ -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

@@ -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