ぬの部屋(仮)
nu-no-he-ya
  •     123
    45678910
    11121314151617
    18192021222324
    25262728293031
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30      
       1234
    567891011
    12131415161718
    19202122232425
    262728293031 
           
     123456
    78910111213
    14151617181920
    21222324252627
    282930    
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31      
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
    1234567
    891011121314
    15161718192021
    22232425262728
    2930     
           
        123
    45678910
    11121314151617
    18192021222324
    25262728293031
           
      12345
    6789101112
    13141516171819
    20212223242526
    27282930   
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031     
         12
    3456789
    10111213141516
    17181920212223
    242526272829 
           
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031     
        123
    45678910
    11121314151617
    18192021222324
    252627282930 
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30      
       1234
    567891011
    12131415161718
    19202122232425
    262728293031 
           
    1234567
    891011121314
    15161718192021
    22232425262728
    293031    
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
           
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
    1234567
    891011121314
    15161718192021
    22232425262728
    2930     
           
        123
    45678910
    11121314151617
    18192021222324
    25262728293031
           
        123
    45678910
    11121314151617
    18192021222324
    25262728   
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31      
       1234
    567891011
    12131415161718
    19202122232425
    2627282930  
           
    1234567
    15161718192021
    293031    
           
         12
    3456789
    10111213141516
           
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031     
        123
    45678910
    11121314151617
    18192021222324
    252627282930 
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    30      
       1234
    567891011
    12131415161718
    19202122232425
    262728293031 
           
    1234567
    891011121314
    15161718192021
    22232425262728
    293031    
           
        123
    45678910
    11121314151617
    18192021222324
    25262728293031
           
      12345
    6789101112
    13141516171819
    20212223242526
    27282930   
           
        123
    45678910
    11121314151617
    18192021222324
    252627282930 
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
       1234
    567891011
    12131415161718
    19202122232425
    2627282930  
           
    1234567
    891011121314
    15161718192021
    22232425262728
    293031    
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
           
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
      12345
    6789101112
    13141516171819
    20212223242526
    2728     
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031     
     123456
    78910111213
    14151617181920
    21222324252627
    282930    
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31      
    1234567
    891011121314
    15161718192021
    22232425262728
    293031    
           
        123
    45678910
    11121314151617
    18192021222324
    252627282930 
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
     123456
    78910111213
    14151617181920
    21222324252627
    28293031   
           
       1234
    567891011
    12131415161718
    19202122232425
    262728293031 
           
     123456
    78910111213
    14151617181920
    21222324252627
    282930    
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31      
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
    1234567
    891011121314
    15161718192021
    22232425262728
    2930     
           
        123
    45678910
    11121314151617
    18192021222324
    25262728293031
           
      12345
    6789101112
    13141516171819
    20212223242526
    27282930   
           
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031     
          1
    2345678
    9101112131415
    16171819202122
    232425262728 
           
       1234
    567891011
    12131415161718
    19202122232425
    262728293031 
           
    1234567
    891011121314
    15161718192021
    22232425262728
    293031    
           
         12
    3456789
    10111213141516
    17181920212223
    24252627282930
           
      12345
    6789101112
    13141516171819
    20212223242526
    2728293031  
           
    1234567
    891011121314
    15161718192021
    22232425262728
    2930     
           
        123
    45678910
    11121314151617
    18192021222324
    25262728293031
           
  • Blender Cycles PythonでTextureノードが何に接続されているかを検出する

    DAZ Importer 1.4でBlenderへExportした結果のマテリアルがある。

    これのテクスチャノードが、Bump用なのか、あるいはDiffuse用なのか…を知りたい。

    スクリプト

    import bpy
    
    
    
    # @brief 与えられたCyclesのノードツリーの中のImage Textureノードを全て取得して返す
    # @param [in] nodetree Cyclesのノードツリー
    # @return Image Textureノードの一覧
    def get_all_textures(nodetree):
        nodes = nodetree.nodes
    
        texturenodelist = []
            
        for node in nodes:
            if node.type == 'TEX_IMAGE':
                texturenodelist.append(node)
                
        return texturenodelist
    # @brief ノードのto_nodeを辿り、特定のノードが見つかるまで再帰的に検索する
    # @param [in] node Cyclesのノード
    # @return 見つかったノード
    # @retval None 見つからなかった場合
    def get_input_to(node):
        
        if node.type == 'BUMP':
            return node
        if node.type == 'NORMAL_MAP':
            return node
        elif node.type == 'BSDF_DIFFUSE':
            return node
        elif node.type == 'BSDF_GLOSSY':
            return node
        elif node.type == 'BSDF_PRINCIPLED':
            return node
    
        for output in node.outputs:
            for link in output.links:
                return get_input_to(link.to_node)# 目的のノード出ないなら再帰呼び出し
        return None
    # @brief テクスチャノードから、そのノードが繋がっているノードを探す
    # @param [in] texnode CyclesのImage Textureノード
    # @return 見つかったBump,Normalまたは各種BSDFノード
    # @retval None 見つからなかった
    def get_tex_input_to(texnode):
        for link in texnode.outputs["Color"].links:# テクスチャノードの"Color"に接続されたノードを探す
            prevnode = link.to_node
            tonode = get_input_to(prevnode)
            
            if tonode is not None:
                return tonode
    
        return None
    # @brief マテリアルスロット内の全てのマテリアルについて、テクスチャノードの接続先を検索する
    # @param [in] slots マテリアルスロット
    # @return なし
    def about_all_material(slots):
        
        for slot in slots:
            
            texturenodelist=[]
            
            material = slot.material
        
            nodetree = material.node_tree
            
            print("------" , material.name , "-------")
            texturenodelist = get_all_textures(nodetree)
            
            for texnode in texturenodelist:
                
                inputto = get_tex_input_to(texnode)
                
                print( texnode.name , inputto )
    print("---------------")
    print("---------------")
    print("---------------")
    
    # 呼び出し
    about_all_material(bpy.context.active_object.material_slots)
    

    出力結果

    ------ Torso-1 -------
    Acicia_NM_1002 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1002 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1002 Base <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_1002_SSS <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_Torso_Ref_1002 <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    ------ Face-1 -------
    Acicia_NM_1001 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1001 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1001 Shadow 07 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    Acicia_1001_SSS Default None
    Acicia_1001_Spec None
    ------ Lips-1 -------
    Acicia_NM_1001 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1001 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia 1001 Lip 02 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    Acicia_1001_SSS Lip 02 None
    Acicia_1001_Spec None
    Acicia_Spc_1001 <bpy_struct, ShaderNodeBsdfGlossy("Glossy BSDF")>
    ------ Teeth-1 -------
    Acicia_MouthNM_1005 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_MouthB_1005 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1005 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    ------ Ears-1 -------
    Acicia_NM_1001 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1001 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1001 Shadow 07 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    Acicia_1001_SSS Default None
    Acicia_1001_Spec None
    ------ Legs-1 -------
    Acicia_NM_1003 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1003 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1003 Base <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_1003_SSS <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_Rh_1003 <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    ------ EyeSocket-1 -------
    Acicia_B_1001 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1001 Shadow 07 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    Acicia_1001_SSS Default None
    Acicia_1001_Spec None
    Acicia_NM_1001 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    ------ Mouth-1 -------
    Acicia_MouthNM_1005 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_MouthB_1005 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1005 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    ------ Arms-1 -------
    Acicia_NM_1004 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1004 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1004 Base <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_1004_SSS <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_Rh_1004 <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    ------ Pupils-1 -------
    ------ EyeMoisture-2 -------
    ------ Fingernails-1 -------
    Acicia_NM_1004 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1004 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1004 Base <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_1004_SSS <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_Rh_1004 <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    ------ Cornea-1 -------
    ------ Irises-1 -------
    Acicia_EyesNM_1006 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_EyesB_1006 <bpy_struct, ShaderNodeBump("Bump")>
    Acacia Eyes Color Red 02 <bpy_struct, ShaderNodeBsdfDiffuse("Diffuse BSDF")>
    ------ Sclera-1 -------
    Acicia_1006 <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    ------ Toenails-1 -------
    Acicia_NM_1003 <bpy_struct, ShaderNodeNormalMap("Normal Map")>
    Acicia_B_1003 <bpy_struct, ShaderNodeBump("Bump")>
    Acicia_1003 Base <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_1003_SSS <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    Acicia_Rh_1003 <bpy_struct, ShaderNodeBsdfPrincipled("Principled BSDF")>
    

    特定できなかった物はNoneが入っている