Cycles Automatic Material Textures Node

(silvio.falcinel) #1

This script automatically assigns the image-texture from “standard blender material” to “cycles shader nodes”, through a simple click you can switch to rehabilitate all the standard materials for blender.

now the script works for the image-texture in channel color and normal
and I beginning to enable interpretation for translate all parameters
from standard material to cycles shader node

but I try to help, I can not find the acces in Roughness value in cycles shader node
Thank you for your attention and anyone who can help…

installation:
user preferences > addons > system > “Cycles Auto Material Textures Node”

usage:
Properties > Material > “Automatic Massive Material Nodes”

system_cycles_material_text_node.py

# cycles_material_text_node.py Copyright (C) 2012, Silvio Falcinelli
#
# Show Information About the Blend.
# ***** 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": "Cycles Auto Material Texures Node Editor",
    "author": "Silvio Falcinelli",
    "version": (0,1),
    "blender": (2, 6, 2),
    "api": 44136,
    "location": "Properties > Material > Automatic Node Editor ",
    "description": "automatic cycles texture map",
    "warning": "beta",
    "wiki_url": 'http://www.rendering3d.net/' \
        'scripts/materialedior',
    "tracker_url": "https://projects.blender.org/tracker/index.php?" \
        "func=detail&aid=????",
    "category": "System"}


import bpy

def AutoNodeOff():
    mats = bpy.data.materials
    for cmat in mats:
        cmat.use_nodes=False

def AutoNode():
    mats = bpy.data.materials
    for cmat in mats:
        #print(cmat.name)
        cmat.use_nodes=True
        TreeNodes=cmat.node_tree
        links = TreeNodes.links
    
        shader=''
        for n in TreeNodes.nodes:
    
            if n.type == 'TEX_IMAGE' or n.type == 'RGBTOBW':
                TreeNodes.nodes.remove(n)

            if n.type == 'OUTPUT_MATERIAL':
                shout = n       
                        
            if n.type == 'BACKGROUND':
                shader=n              
            if n.type == 'BSDF_DIFFUSE':
                shader=n  
            if n.type == 'BSDF_GLOSSY':
                shader=n              
            if n.type == 'BSDF_GLASS':
                shader=n  
            if n.type == 'BSDF_TRANSLUCENT':
                shader=n     
            if n.type == 'BSDF_TRANSPARENT':
                shader=n   
            if n.type == 'BSDF_VELVET':
                shader=n     
            if n.type == 'EMISSION':
                shader=n 
            if n.type == 'HOLDOUT':
                shader=n   

        if cmat.raytrace_mirror.use and cmat.raytrace_mirror.reflect_factor>0.001:
            print("MIRROR")
            if shader:
                if not shader.type == 'BSDF_GLOSSY':
                    print("MAKE MIRROR SHADER NODE")
                    TreeNodes.nodes.remove(shader)
                    shader = TreeNodes.nodes.new('BSDF_GLOSSY')    # RGB node
                    shader.location = 0,450
                    #print(shader.glossy)
                    links.new(shader.outputs[0],shout.inputs[0]) 
                        
        if not shader:
            shader = TreeNodes.nodes.new('BSDF_DIFFUSE')    # RGB node
            shader.location = 0,450
             
            shout = TreeNodes.nodes.new('OUTPUT_MATERIAL')
            shout.location = 200,400          
            links.new(shader.outputs[0],shout.inputs[0])                
                   
                   
                   
        if shader:                         
            textures = cmat.texture_slots
            for tex in textures:
                                
                if tex:
                    if tex.texture.type=='IMAGE':
                         
                        img = tex.texture.image
                        #print(img.name)  
                        shtext = TreeNodes.nodes.new('TEX_IMAGE')
          
                        shtext.location = -200,400 
        
                        shtext.image=img
        
                        if tex.use_map_color_diffuse:
                            links.new(shtext.outputs[0],shader.inputs[0]) 
    
                        if tex.use_map_normal:
                            t = TreeNodes.nodes.new('RGBTOBW')
                            t.location = -0,300 
                            links.new(t.outputs[0],shout.inputs[2]) 
                            links.new(shtext.outputs[0],t.inputs[0]) 
 


class Refresh(bpy.types.Operator):
    bl_idname = "ml.refresh"
    bl_label = "Refresh"
    bl_description = "Refresh"
    bl_register = True
    bl_undo = True
    @classmethod
    def poll(cls, context):
        return True
    def execute(self, context):
        AutoNode()
        return {'FINISHED'}


class Refresh(bpy.types.Operator):
    bl_idname = "ml.restore"
    bl_label = "Restore"
    bl_description = "Restore"
    bl_register = True
    bl_undo = True
    @classmethod
    def poll(cls, context):
        return True
    def execute(self, context):
        AutoNodeOff()
        return {'FINISHED'}



class OBJECT_PT_scenemassive(bpy.types.Panel):
    bl_label = "Automatic Massive Material Nodes"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "material"
    

    def draw(self, context):
        sc = context.scene
        ob_cols = []
        db_cols = []
        layout = self.layout
        l_row = layout.row()
        ob_cols.append(l_row.column())
        layout.separator()
        row = ob_cols[0].row() 
        row.operator("ml.refresh", text='BLENDER > CYCLES', icon='FORCE_TEXTURE')
        layout.separator()
        row = ob_cols[0].row() 
        row.operator("ml.restore", text='BLENDER Mode  (Node Off)', icon='MATERIAL')        
        layout.separator()
        row = ob_cols[0].row() 
        layout.separator()
        row = ob_cols[0].row() 
        layout.separator()
        row = ob_cols[0].row() 
        row.label(text="Ver 0.1 beta  Silvio Falcinelli")
        layout.separator()
        row = ob_cols[0].row() 
        row.label(text="wwww.rendering3d.net")


 
def register():
    bpy.utils.register_module(__name__)
    pass

def unregister():
    bpy.utils.unregister_module(__name__)

    pass

if __name__ == "__main__":
    register()


1 Like

(MmAaXx) #2

cool!

thankyou :slight_smile:

0 Likes

(3Duaun) #3

very useful, thank you

0 Likes

(hotzst) #4

Cool. I only which it had been available, when I changed all my materials.

0 Likes

(jecrobinson) #5

Great! Thanks for this.

0 Likes

(Meta-Androcto) #6

great job, thanks for this awesome timesaver :slight_smile:

0 Likes

(Kramon) #7

So if i get it. When i have work in cycles some many materials and then i think i want to do render white in BI i just click one button and all materials are changed?

0 Likes

(RickyBlender) #8

interesting

can you give API pages where you found this

i did some nodes for composite before for BL so might be interesting to learn more about cycles

thanks

0 Likes

(cmomoney) #9
if n.type == 'BSDF_DIFFUSE':
    shader = n
    roughness = shader.inputs['Roughness']
    roughness.default_value = 0.5 #roughness value
0 Likes

(silvio.falcinel) #10

Thanks to all and special thanks to cmomoney !!! exactly what I expected, I can now go on to refine the script, two or three days and put new script

0 Likes

(RickyBlender) #11

ok but what can this do ?

i mean does convert mat + text from BL to cycles

and can it convert a simple BL mat + procedural text to cycles equivalent ?

can you be more specific is waht it can do ?

thanks

0 Likes

(silvio.falcinel) #12

my intent to convert-interpret all possible parameters from blender to cycles, I think it’s very handy to have possibility to use both-more engines in the same job !

0 Likes

(silvio.falcinel) #13

http://www.blender.org/documentation/blender_python_api_2_62_release/contents.html

but I can not find anything, I proceed very attempts…

.

0 Likes

(silvio.falcinel) #14

now supports many parameters of material and textures in combination of many nodes!

http://www.rendering3d.net/sharing/system_cycles_material_text_node.py

for next upgrade I try to add preview material cycles

0 Likes

(RickyBlender) #15

can you explain a little how it works

i mean in BL you can have an object with several material and each mat can have several textures
so up tow hat point do you transfert mat and text ?

thanks

0 Likes

(silvio.falcinel) #16

for a new job making in cycles is certainly the best result by make directly the materials cycles shader node, but if you want to use old scenes native in blender automatic convertion setting is useful

0 Likes

(RickyBlender) #17

ok but can it convert all mat and text to cycles
or only one mat and one text to a mat in cycles ?

thanks

0 Likes

(silvio.falcinel) #18

one click and convert all materials scene at once !
but is beta script i writen in only 2 day…

0 Likes

(RickyBlender) #19

and eaht about textures procedural or UV map for each mat?

thanks

0 Likes

(silvio.falcinel) #20

for UV now support only UV mesh image standard mapping, I saw that there are various possibilities of translate more UV map, and 'only a matter of time to complete the script

for procedural textures is problematic for very different BL Cycles
now I added only DISTORTED_NOISE but not same is similar…
the solution is use automatic strategy for rendering images in files from procedural texture

I follow my list of priorities to completion
1 add the texure mapping mask
2 lock material (for materials that do not want to automatically overwrite)
3 the preview for cycles material
4 more mapping type
5 strategy for procedural textures

I know that ic is a lot to develop it takes perseverance and patient to write all

0 Likes