Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/addon/version_update.py
| Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | def ambient_occlusion_node_relink(nodetree): | ||||
| # Replace links | # Replace links | ||||
| for link in ao_links: | for link in ao_links: | ||||
| from_node = link.from_node | from_node = link.from_node | ||||
| to_socket = link.to_socket | to_socket = link.to_socket | ||||
| 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 light_emission_node_to_energy(light): | |||||
| energy = 1.0 | |||||
| color = (1.0, 1.0, 1.0) | |||||
| # If nodetree has animation or drivers, don't try to convert. | |||||
| if not light.node_tree or light.node_tree.animation_data: | |||||
| return energy, color | |||||
| # Find emission node | |||||
| output_node = light.node_tree.get_output_node('CYCLES') | |||||
| if not output_node: | |||||
| return energy, color | |||||
| emission_node = None | |||||
| for link in light.node_tree.links: | |||||
| if link.to_node == output_node and \ | |||||
| link.from_node.bl_idname == 'ShaderNodeEmission': | |||||
| emission_node = link.from_node | |||||
| break | |||||
| if not emission_node: | |||||
| return energy, color | |||||
| # Don't convert if anything is linked | |||||
| strength_socket = emission_node.inputs['Strength'] | |||||
| color_socket = emission_node.inputs['Color'] | |||||
| if strength_socket.is_linked or color_socket.is_linked: | |||||
| return energy, color | |||||
| energy = strength_socket.default_value | |||||
| color = tuple(color_socket.default_value) | |||||
| strength_socket.default_value = 1.0 | |||||
| color_socket.default_value = (1.0, 1.0, 1.0, 1.0) | |||||
| light.use_nodes = False | |||||
| return energy, color | |||||
| def light_emission_unify(light, engine): | |||||
| # Adjust Eevee light strength to match Cycles. | |||||
| if light.type != 'SUN': | |||||
| light.energy *= 100.0 | |||||
| # Attempt to extract constant energy and color from nodes. | |||||
| use_nodes = light.use_nodes | |||||
| energy, color = light_emission_node_to_energy(light) | |||||
| if engine == 'CYCLES': | |||||
| if use_nodes: | |||||
| # Energy extracted from nodes | |||||
| light.energy = energy | |||||
| light.color = (color[0], color[1], color[2]) | |||||
| else: | |||||
| # Default cycles multipliers if there are no nodes. | |||||
| if light.type == 'SUN': | |||||
| light.energy = 1.0 | |||||
| else: | |||||
| light.energy = 100.0 | |||||
| else: | |||||
| # Disable nodes if scene was configured for Eevee. | |||||
| light.use_nodes = False | |||||
| @persistent | @persistent | ||||
| def do_versions(self): | def do_versions(self): | ||||
| if bpy.context.preferences.version <= (2, 78, 1): | if bpy.context.preferences.version <= (2, 78, 1): | ||||
| prop = bpy.context.preferences.addons[__package__].preferences | prop = bpy.context.preferences.addons[__package__].preferences | ||||
| system = bpy.context.preferences.system | system = bpy.context.preferences.system | ||||
| if not prop.is_property_set("compute_device_type"): | if not prop.is_property_set("compute_device_type"): | ||||
| # Device might not currently be available so this can fail | # Device might not currently be available so this can fail | ||||
| try: | try: | ||||
| if system.legacy_compute_device_type == 1: | if system.legacy_compute_device_type == 1: | ||||
| prop.compute_device_type = 'OPENCL' | prop.compute_device_type = 'OPENCL' | ||||
| elif system.legacy_compute_device_type == 2: | elif system.legacy_compute_device_type == 2: | ||||
| prop.compute_device_type = 'CUDA' | prop.compute_device_type = 'CUDA' | ||||
| else: | else: | ||||
| prop.compute_device_type = 'NONE' | prop.compute_device_type = 'NONE' | ||||
| except: | except: | ||||
| pass | pass | ||||
| # Init device list for UI | # Init device list for UI | ||||
| prop.get_devices(prop.compute_device_type) | prop.get_devices(prop.compute_device_type) | ||||
| # We don't modify startup file because it assumes to | |||||
| # have all the default values only. | |||||
| if not bpy.data.is_saved: | |||||
| return | |||||
| # Map of versions used by libraries. | # Map of versions used by libraries. | ||||
| library_versions = {} | library_versions = {} | ||||
| library_versions[bpy.data.version] = [None] | library_versions[bpy.data.version] = [None] | ||||
| for library in bpy.data.libraries: | for library in bpy.data.libraries: | ||||
| library_versions.setdefault(library.version, []).append(library) | library_versions.setdefault(library.version, []).append(library) | ||||
| # Do versioning per library, since they might have different versions. | # Do versioning per library, since they might have different versions. | ||||
| max_need_versioning = (2, 80, 41) | max_need_versioning = (2, 80, 51) | ||||
| for version, libraries in library_versions.items(): | for version, libraries in library_versions.items(): | ||||
| if version > max_need_versioning: | if version > max_need_versioning: | ||||
| continue | continue | ||||
| # Scenes | # Scenes | ||||
| for scene in bpy.data.scenes: | for scene in bpy.data.scenes: | ||||
| if scene.library not in libraries: | if scene.library not in libraries: | ||||
| continue | continue | ||||
| ▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | for version, libraries in library_versions.items(): | ||||
| cscene.aa_samples = 4 | cscene.aa_samples = 4 | ||||
| if not cscene.is_property_set("preview_aa_samples"): | if not cscene.is_property_set("preview_aa_samples"): | ||||
| cscene.preview_aa_samples = 4 | cscene.preview_aa_samples = 4 | ||||
| if not cscene.is_property_set("blur_glossy"): | if not cscene.is_property_set("blur_glossy"): | ||||
| cscene.blur_glossy = 0.0 | cscene.blur_glossy = 0.0 | ||||
| if not cscene.is_property_set("sample_clamp_indirect"): | if not cscene.is_property_set("sample_clamp_indirect"): | ||||
| cscene.sample_clamp_indirect = 0.0 | cscene.sample_clamp_indirect = 0.0 | ||||
| # Lamps | # Lights | ||||
| for light in bpy.data.lights: | for light in bpy.data.lights: | ||||
| if light.library not in libraries: | if light.library not in libraries: | ||||
| continue | continue | ||||
| if version <= (2, 76, 5): | if version <= (2, 76, 5): | ||||
| clight = light.cycles | clight = light.cycles | ||||
| # MIS | # MIS | ||||
| if not clight.is_property_set("use_multiple_importance_sampling"): | if not clight.is_property_set("use_multiple_importance_sampling"): | ||||
| clight.use_multiple_importance_sampling = False | clight.use_multiple_importance_sampling = False | ||||
| if version <= (2, 80, 51): | |||||
| light_emission_unify(light, bpy.context.engine) | |||||
| # Worlds | # Worlds | ||||
| for world in bpy.data.worlds: | for world in bpy.data.worlds: | ||||
| if world.library not in libraries: | if world.library not in libraries: | ||||
| continue | continue | ||||
| if version <= (2, 76, 9): | if version <= (2, 76, 9): | ||||
| cworld = world.cycles | cworld = world.cycles | ||||
| ▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines | |||||