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
_cycles.set_resumable_chunk(
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 \
args.cycles_resumable_end_chunk:
import _cycles
_cycles.set_resumable_chunk_range(
int(args.cycles_resumable_num_chunks),
int(args.cycles_resumable_start_chunk),
int(args.cycles_resumable_end_chunk))
int(args.cycles_resumable_end_chunk),
)
def init():
@@ -206,6 +208,7 @@ def system_info():
import _cycles
return _cycles.system_info()
def register_passes(engine, scene, srl):
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),
)
class CyclesRenderSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
@@ -1139,7 +1140,6 @@ class CyclesObjectSettings(bpy.types.PropertyGroup):
default=False,
)
@classmethod
def unregister(cls):
del bpy.types.Object.cycles
@@ -1204,12 +1204,14 @@ class CyclesCurveRenderSettings(bpy.types.PropertyGroup):
def unregister(cls):
del bpy.types.Scene.cycles_curves
def update_render_passes(self, context):
scene = context.scene
rd = scene.render
rl = rd.layers.active
rl.update_render_passes()
class CyclesRenderLayerSettings(bpy.types.PropertyGroup):
@classmethod
def register(cls):
@@ -1421,7 +1423,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
return device_entry
return None
def update_device_entries(self, device_list):
for device in device_list:
if not device[1] in {'CUDA', 'OPENCL', 'CPU'}:
@@ -1439,7 +1440,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
# Update name in case it changed
entry.name = device[0]
def get_devices(self):
import _cycles
# Layout of the device tuples: (Name, Type, Persistent ID)
@@ -1465,7 +1465,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
opencl_devices.extend(cpu_devices)
return cuda_devices, opencl_devices
def get_num_gpu_devices(self):
import _cycles
device_list = _cycles.available_devices()
@@ -1478,11 +1477,9 @@ class CyclesPreferences(bpy.types.AddonPreferences):
num += 1
return num
def has_active_device(self):
return self.get_num_gpu_devices() > 0
def draw_impl(self, layout, context):
layout.label(text="Cycles Compute Device:")
layout.row().prop(self, "compute_device_type", expand=True)
@@ -1500,7 +1497,6 @@ class CyclesPreferences(bpy.types.AddonPreferences):
for device in opencl_devices:
box.prop(device, "use", text=device.name)
def draw(self, 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
def show_device_active(context):
cscene = context.scene.cycles
if cscene.device != 'GPU':
@@ -1741,6 +1742,7 @@ class CYCLES_SCENE_PT_simplify(CyclesButtonsPanel, Panel):
col = split.column()
col.prop(cscene, "ao_bounces_render")
def draw_device(self, context):
scene = context.scene
layout = self.layout

View File

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