[Bf-extensions-cvs] [5a901c6] master: restored cycled to blender convertor to contrib. supports basic materials & image textures only.
Brendon Murphy
noreply at git.blender.org
Fri Jul 25 22:17:23 CEST 2014
Commit: 5a901c69846c6f94ab96cff49e4f061351d4009d
Author: Brendon Murphy
Date: Sat Jul 26 06:15:51 2014 +1000
Branches: master
https://developer.blender.org/rBAC5a901c69846c6f94ab96cff49e4f061351d4009d
restored cycled to blender convertor to contrib.
supports basic materials & image textures only.
===================================================================
A cycles_materials.py
===================================================================
diff --git a/cycles_materials.py b/cycles_materials.py
new file mode 100644
index 0000000..d9c6fae
--- /dev/null
+++ b/cycles_materials.py
@@ -0,0 +1,519 @@
+# convert_materials_to_cycles.py
+#
+# Copyright (C) 5-mar-2012, Silvio Falcinelli. Fixes by others.
+#
+# special thanks to user blenderartists.org cmomoney
+#
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+
+bl_info = {
+ "name": "Convert Materials to Cycles",
+ "author": "Silvio Falcinelli",
+ "version": (0, 11),
+ "blender": (2, 68, 0),
+ "location": "Properties > Material > Convert to Cycles",
+ "description": "Convert non-nodes materials to Cycles",
+ "warning": "beta",
+ "wiki_url": 'http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/System/Convert_Materials_to_Cycles',
+ "category": "Materials"}
+
+
+import bpy
+import math
+from math import log
+from math import pow
+from math import exp
+import os.path
+
+def AutoNodeOff():
+ mats = bpy.data.materials
+ for cmat in mats:
+ cmat.use_nodes = False
+ bpy.context.scene.render.engine = 'BLENDER_RENDER'
+
+def BakingText(tex, mode):
+ print('________________________________________')
+ print('INFO start bake texture ' + tex.name)
+ bpy.ops.object.mode_set(mode='OBJECT')
+ sc = bpy.context.scene
+ tmat = ''
+ img = ''
+ Robj = bpy.context.active_object
+ for n in bpy.data.materials:
+ if n.name == 'TMP_BAKING':
+ tmat = n
+ if not tmat:
+ tmat = bpy.data.materials.new('TMP_BAKING')
+ tmat.name = "TMP_BAKING"
+
+ bpy.ops.mesh.primitive_plane_add()
+ tm = bpy.context.active_object
+ tm.name = "TMP_BAKING"
+ tm.data.name = "TMP_BAKING"
+ bpy.ops.object.select_pattern(extend=False, pattern="TMP_BAKING", case_sensitive=False)
+ sc.objects.active = tm
+ bpy.context.scene.render.engine = 'BLENDER_RENDER'
+ tm.data.materials.append(tmat)
+ if len(tmat.texture_slots.items()) == 0:
+ tmat.texture_slots.add()
+ tmat.texture_slots[0].texture_coords = 'UV'
+ tmat.texture_slots[0].use_map_alpha = True
+ tmat.texture_slots[0].texture = tex.texture
+ tmat.texture_slots[0].use_map_alpha = True
+ tmat.texture_slots[0].use_map_color_diffuse = False
+ tmat.use_transparency = True
+ tmat.alpha = 0
+ tmat.use_nodes = False
+ tmat.diffuse_color = 1, 1, 1
+ bpy.ops.object.mode_set(mode='EDIT')
+ bpy.ops.uv.unwrap()
+
+ for n in bpy.data.images:
+ if n.name == 'TMP_BAKING':
+ n.user_clear()
+ bpy.data.images.remove(n)
+
+ if mode == "ALPHA" and tex.texture.type == 'IMAGE':
+ sizeX = tex.texture.image.size[0]
+ sizeY = tex.texture.image.size[1]
+ else:
+ sizeX = 600
+ sizeY = 600
+ bpy.ops.image.new(name="TMP_BAKING", width=sizeX, height=sizeY, color=(0.0, 0.0, 0.0, 1.0), alpha=True, float=False)
+ bpy.data.screens['UV Editing'].areas[1].spaces[0].image = bpy.data.images["TMP_BAKING"]
+ sc.render.engine = 'BLENDER_RENDER'
+ img = bpy.data.images["TMP_BAKING"]
+ img = bpy.data.images.get("TMP_BAKING")
+ img.file_format = "JPEG"
+ if mode == "ALPHA" and tex.texture.type == 'IMAGE':
+ img.filepath_raw = tex.texture.image.filepath + "_BAKING.jpg"
+
+ else:
+ img.filepath_raw = tex.texture.name + "_PTEXT.jpg"
+
+ sc.render.bake_type = 'ALPHA'
+ sc.render.use_bake_selected_to_active = True
+ sc.render.use_bake_clear = True
+ bpy.ops.object.bake_image()
+ img.save()
+ bpy.ops.object.mode_set(mode='OBJECT')
+ bpy.ops.object.delete()
+ bpy.ops.object.select_pattern(extend=False, pattern=Robj.name, case_sensitive=False)
+ sc.objects.active = Robj
+ img.user_clear()
+ bpy.data.images.remove(img)
+ bpy.data.materials.remove(tmat)
+
+ # print('INFO : end Bake ' + img.filepath_raw )
+ print('________________________________________')
+
+def AutoNode(active=False):
+
+ sc = bpy.context.scene
+
+ if active:
+
+ mats = bpy.context.active_object.data.materials
+
+ else:
+
+ mats = bpy.data.materials
+
+
+ for cmat in mats:
+ cmat.use_nodes = True
+ TreeNodes = cmat.node_tree
+ links = TreeNodes.links
+
+ # Don't alter nodes of locked materials
+ locked = False
+ for n in TreeNodes.nodes:
+ if n.type == 'ShaderNodeOutputMaterial':
+ if n.label == 'Locked':
+ locked = True
+ break
+
+ if not locked:
+ # Convert this material from non-nodes to Cycles nodes
+
+ shader = ''
+ shmix = ''
+ shtsl = ''
+ Add_Emission = ''
+ Add_Translucent = ''
+ Mix_Alpha = ''
+ sT = False
+
+ for n in TreeNodes.nodes:
+ TreeNodes.nodes.remove(n)
+
+ # Starting point is diffuse BSDF and output material
+ shader = TreeNodes.nodes.new('ShaderNodeBsdfDiffuse')
+ shader.location = 0, 470
+ shout = TreeNodes.nodes.new('ShaderNodeOutputMaterial')
+ shout.location = 200, 400
+ links.new(shader.outputs[0], shout.inputs[0])
+
+ sM = True
+ for tex in cmat.texture_slots:
+ if tex:
+ if tex.use:
+ if tex.use_map_alpha:
+ sM = False
+ if sc.EXTRACT_ALPHA:
+ if tex.texture.type == 'IMAGE' and tex.texture.use_alpha:
+ if not os.path.exists(bpy.path.abspath(tex.texture.image.filepath + "_BAKING.jpg")) or sc.EXTRACT_OW:
+ BakingText(tex, 'ALPHA')
+ else:
+ if not tex.texture.type == 'IMAGE':
+ if not os.path.exists(bpy.path.abspath(tex.texture.name + "_PTEXT.jpg")) or sc.EXTRACT_OW:
+ BakingText(tex, 'PTEXT')
+
+ cmat_is_transp = cmat.use_transparency and cmat.alpha < 1
+
+ if cmat_is_transp and cmat.raytrace_transparency.ior == 1 and not cmat.raytrace_mirror.use and sM:
+ if not shader.type == 'ShaderNodeBsdfTransparent':
+ print("INFO: Make TRANSPARENT shader node " + cmat.name)
+ TreeNodes.nodes.remove(shader)
+ shader = TreeNodes.nodes.new('ShaderNodeBsdfTransparent')
+ shader.location = 0, 470
+ links.new(shader.outputs[0], shout.inputs[0])
+
+ if not cmat.raytrace_mirror.use and not cmat_is_transp:
+ if not shader.type == 'ShaderNodeBsdfDiffuse':
+ print("INFO: Make DIFFUSE shader node" + cmat.name)
+ TreeNodes.nodes.remove(shader)
+ shader = TreeNodes.nodes.new('ShaderNodeBsdfDiffuse')
+ shader.location = 0, 470
+ links.new(shader.outputs[0], shout.inputs[0])
+
+ if cmat.raytrace_mirror.use and cmat.raytrace_mirror.reflect_factor > 0.001 and cmat_is_transp:
+ if not shader.type == 'ShaderNodeBsdfGlass':
+ print("INFO: Make GLASS shader node" + cmat.name)
+ TreeNodes.nodes.remove(shader)
+ shader = TreeNodes.nodes.new('ShaderNodeBsdfGlass')
+ shader.location = 0, 470
+ links.new(shader.outputs[0], shout.inputs[0])
+
+ if cmat.raytrace_mirror.use and not cmat_is_transp and cmat.raytrace_mirror.reflect_factor > 0.001 :
+ if not shader.type == 'ShaderNodeBsdfGlossy':
+ print("INFO: Make MIRROR shader node" + cmat.name)
+ TreeNodes.nodes.remove(shader)
+ shader = TreeNodes.nodes.new('ShaderNodeBsdfGlossy')
+ shader.location = 0, 520
+ links.new(shader.outputs[0], shout.inputs[0])
+
+ if cmat.emit > 0.001 :
+ if not shader.type == 'ShaderNodeEmission' and not cmat.raytrace_mirror.reflect_factor > 0.001 and not cmat_is_transp:
+ print("INFO: Mix EMISSION shader node" + cmat.name)
+ TreeNodes.nodes.remove(shader)
+ shader = TreeNodes.nodes.new('ShaderNodeEmission')
+ shader.location = 0, 450
+ links.new(shader.outputs[0], shout.inputs[0])
+ else:
+ if not Add_Emission:
+ print("INFO: Add EMISSION shader node" + cmat.name)
+ shout.location = 550, 330
+ Add_Emission = TreeNodes.nodes.new('ShaderNodeAddShader')
+ Add_Emission.location = 370, 490
+
+ shem = TreeNodes.nodes.new('ShaderNodeEmission')
+ shem.location = 180, 380
+
+ links.new(Add_Emission.outputs[0], shout.inputs[0])
+ links.new(shem.outputs[0], Add_Emission.inputs[1])
+ links.new(shader.outputs[0], Add_Emission.inputs[0])
+
+ shem.inputs['Color'].default_value = cmat.diffuse_color.r, cmat.diffuse_color.g, cmat.diffuse_color.b, 1
+ shem.inputs['Strength'].default_value = cmat.emit
+
+ if
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list