diff options
author | Philipp Oeser <info@graphics-engineer.com> | 2015-10-15 13:05:18 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-10-15 13:07:23 +0300 |
commit | 2bb20f6129b05bbaddbe126c2dabb868107a0c23 (patch) | |
tree | 9b8b9c775c70871a474b926a9831add00685e3cd | |
parent | f78b58128b4c22e92d2e6ec1f2cc21a68fbabc56 (diff) |
Cleanup: Import Images As Planes: Automatically generate the transparent material nodes system
when enabling "Use Alpha", for Cycles.
- Removed two options from Cycles Materal settings during import
("Diffuse & Transparent", "Emission & Transparent").
- Nodetree creation stays the same, but transparent BSDF (along the other needed nodes)
is now added when Import Option "Use Alpha" is checked.
Reviewers: testscreenings, mont29
Reviewed By: mont29
Projects: #addons
Differential Revision: https://developer.blender.org/D1437
-rw-r--r-- | io_import_images_as_planes.py | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/io_import_images_as_planes.py b/io_import_images_as_planes.py index 27e8424b..c47af01d 100644 --- a/io_import_images_as_planes.py +++ b/io_import_images_as_planes.py @@ -19,7 +19,7 @@ bl_info = { "name": "Import Images as Planes", "author": "Florian Meyer (tstscr), mont29, matali", - "version": (2, 0, 3), + "version": (2, 0, 4), "blender": (2, 76, 1), "location": "File > Import > Images as Planes or Add > Mesh > Images as Planes", "description": "Imports images and creates planes with the appropriate aspect ratio. " @@ -76,9 +76,7 @@ VID_EXT_FILTER = {e for ext_k, ext_v in EXT_FILTER.items() if ext_k in {"avi", " CYCLES_SHADERS = ( ('BSDF_DIFFUSE', "Diffuse", "Diffuse Shader"), - ('EMISSION', "Emission", "Emission Shader"), - ('BSDF_DIFFUSE_BSDF_TRANSPARENT', "Diffuse & Transparent", "Diffuse and Transparent Mix"), - ('EMISSION_BSDF_TRANSPARENT', "Emission & Transparent", "Emission and Transparent Mix") + ('EMISSION', "Emission", "Emission Shader") ) # ----------------------------------------------------------------------------- @@ -503,37 +501,31 @@ class IMPORT_OT_image_to_plane(Operator, AddObjectHelper): if self.shader == 'BSDF_DIFFUSE': bsdf_diffuse = node_tree.nodes.new('ShaderNodeBsdfDiffuse') - node_tree.links.new(out_node.inputs[0], bsdf_diffuse.outputs[0]) node_tree.links.new(bsdf_diffuse.inputs[0], tex_image.outputs[0]) + if self.use_transparency: + bsdf_transparent = node_tree.nodes.new('ShaderNodeBsdfTransparent') + mix_shader = node_tree.nodes.new('ShaderNodeMixShader') + node_tree.links.new(out_node.inputs[0], mix_shader.outputs[0]) + node_tree.links.new(mix_shader.inputs[0], tex_image.outputs[1]) + node_tree.links.new(mix_shader.inputs[2], bsdf_diffuse.outputs[0]) + node_tree.links.new(mix_shader.inputs[1], bsdf_transparent.outputs[0]) + else: + node_tree.links.new(out_node.inputs[0], bsdf_diffuse.outputs[0]) elif self.shader == 'EMISSION': emission = node_tree.nodes.new('ShaderNodeEmission') lightpath = node_tree.nodes.new('ShaderNodeLightPath') - node_tree.links.new(out_node.inputs[0], emission.outputs[0]) - node_tree.links.new(emission.inputs[0], tex_image.outputs[0]) - node_tree.links.new(emission.inputs[1], lightpath.outputs[0]) - - elif self.shader == 'BSDF_DIFFUSE_BSDF_TRANSPARENT': - bsdf_diffuse = node_tree.nodes.new('ShaderNodeBsdfDiffuse') - bsdf_transparent = node_tree.nodes.new('ShaderNodeBsdfTransparent') - mix_shader = node_tree.nodes.new('ShaderNodeMixShader') - node_tree.links.new(out_node.inputs[0], mix_shader.outputs[0]) - node_tree.links.new(mix_shader.inputs[0], tex_image.outputs[1]) - node_tree.links.new(mix_shader.inputs[2], bsdf_diffuse.outputs[0]) - node_tree.links.new(mix_shader.inputs[1], bsdf_transparent.outputs[0]) - node_tree.links.new(bsdf_diffuse.inputs[0], tex_image.outputs[0]) - - elif self.shader == 'EMISSION_BSDF_TRANSPARENT': - emission = node_tree.nodes.new('ShaderNodeEmission') - lightpath = node_tree.nodes.new('ShaderNodeLightPath') - bsdf_transparent = node_tree.nodes.new('ShaderNodeBsdfTransparent') - mix_shader = node_tree.nodes.new('ShaderNodeMixShader') - node_tree.links.new(out_node.inputs[0], mix_shader.outputs[0]) - node_tree.links.new(mix_shader.inputs[0], tex_image.outputs[1]) - node_tree.links.new(mix_shader.inputs[2], emission.outputs[0]) - node_tree.links.new(mix_shader.inputs[1], bsdf_transparent.outputs[0]) node_tree.links.new(emission.inputs[0], tex_image.outputs[0]) node_tree.links.new(emission.inputs[1], lightpath.outputs[0]) + if self.use_transparency: + bsdf_transparent = node_tree.nodes.new('ShaderNodeBsdfTransparent') + mix_shader = node_tree.nodes.new('ShaderNodeMixShader') + node_tree.links.new(out_node.inputs[0], mix_shader.outputs[0]) + node_tree.links.new(mix_shader.inputs[0], tex_image.outputs[1]) + node_tree.links.new(mix_shader.inputs[2], emission.outputs[0]) + node_tree.links.new(mix_shader.inputs[1], bsdf_transparent.outputs[0]) + else: + node_tree.links.new(out_node.inputs[0], emission.outputs[0]) auto_align_nodes(node_tree) return material |