Advertisement
gr4ph0s

ConvertOctaneBitmap

May 30th, 2016
3,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PyCon 5.98 KB | None | 0 0
  1. import c4d
  2. #-- Gr4ph0s
  3. # visit graphos.fr
  4.  
  5. def getEntry(mat):
  6.     buffer = []
  7.     try :
  8.         diffuse = mat[c4d.OCT_MATERIAL_DIFFUSE_LINK]
  9.         if diffuse.CheckType(5833):
  10.             buffer.append([1,diffuse[c4d.BITMAPSHADER_FILENAME]])
  11.     except:
  12.         pass
  13.     try :
  14.         roughness = mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK]
  15.         if roughness.CheckType(5833):
  16.             buffer.append([2,roughness[c4d.BITMAPSHADER_FILENAME]])
  17.     except:
  18.         pass
  19.     try :
  20.         bump = mat[c4d.OCT_MATERIAL_BUMP_LINK]
  21.         if bump.CheckType(5833):
  22.             buffer.append([3,bump[c4d.BITMAPSHADER_FILENAME]])
  23.     except:
  24.         pass
  25.     try :
  26.         normal = mat[c4d.OCT_MATERIAL_NORMAL_LINK]
  27.         if normal.CheckType(5833):
  28.             buffer.append([4,normal[c4d.BITMAPSHADER_FILENAME]])
  29.     except:
  30.         pass
  31.     try :
  32.         displace = mat[c4d.OCT_MATERIAL_DISPLACEMENT_LINK]
  33.         if displace.CheckType(5833):
  34.             buffer.append([5,displace[c4d.BITMAPSHADER_FILENAME]])
  35.     except:
  36.         pass
  37.     try :
  38.         opacity = mat[c4d.OCT_MATERIAL_OPACITY_LINK]
  39.         if opacity.CheckType(5833):
  40.             buffer.append([6,opacity[c4d.BITMAPSHADER_FILENAME]])
  41.     except:
  42.         pass
  43.     try :
  44.         transmission = mat[c4d.OCT_MATERIAL_TRANSMISSION_LINK]
  45.         if transmission.CheckType(5833):
  46.             buffer.append([7,transmission[c4d.BITMAPSHADER_FILENAME]])
  47.     except:
  48.         pass
  49.     try :
  50.         emission = mat[c4d.OCT_MATERIAL_EMISSION]
  51.         if emission.CheckType(5833):
  52.             buffer.append([8,emission[c4d.BITMAPSHADER_FILENAME]])
  53.     except:
  54.         pass
  55.     try :
  56.         medium = mat[c4d.OCT_MATERIAL_MEDIUM]
  57.         if medium.CheckType(5833):
  58.             buffer.append([9,medium[c4d.BITMAPSHADER_FILENAME]])
  59.     except:
  60.         pass
  61.     try :
  62.         specular = mat[c4d.OCT_MATERIAL_SPECULAR_LINK]
  63.         if medium.CheckType(5833):
  64.             buffer.append([10,specular[c4d.BITMAPSHADER_FILENAME]])
  65.     except:
  66.         pass
  67.     try :
  68.         filmwidth = mat[c4d.OCT_MATERIAL_FILMWIDTH_LINK]
  69.         if filmwidth.CheckType(5833):
  70.             buffer.append([11,filmwidth[c4d.BITMAPSHADER_FILENAME]])
  71.     except:
  72.         pass
  73.     try :
  74.         reflection = mat[c4d.OCT_MATERIAL_REFLECTION_LINK]
  75.         if reflection.CheckType(5833):
  76.             buffer.append([12,reflection[c4d.BITMAPSHADER_FILENAME]])
  77.     except:
  78.         pass
  79.        
  80.     return buffer
  81.  
  82. def get_shader(mat):
  83.     shader = mat.GetFirstShader()
  84.     while shader:
  85.         if shader.CheckType(5833):
  86.             test = c4d.BaseShader(1029508)
  87.             test[c4d.IMAGETEXTURE_FILE] = "testbbbbbb"
  88.             mat.InsertShader(test)
  89.             mat.Message(c4d.MSG_UPDATE)
  90.             mat.Update(True, True)
  91.             print shader[c4d.BITMAPSHADER_FILENAME]
  92.         shader = shader.GetNext()
  93.        
  94.    
  95. def remplaceEntry(mat,data):
  96.     for i in xrange(0,len(data)):
  97.         id = data[i][0]
  98.         imageTexture = c4d.BaseShader(1029508)
  99.         if id == 1:
  100.             path = mat[c4d.OCT_MATERIAL_DIFFUSE_LINK][c4d.BITMAPSHADER_FILENAME]
  101.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  102.             mat[c4d.OCT_MATERIAL_DIFFUSE_LINK] = imageTexture
  103.         if id == 2:
  104.             path = mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK][c4d.BITMAPSHADER_FILENAME]
  105.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  106.             mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK] = imageTexture
  107.         if id == 3:
  108.             path = mat[c4d.OCT_MATERIAL_BUMP_LINK][c4d.BITMAPSHADER_FILENAME]
  109.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  110.             mat[c4d.OCT_MATERIAL_BUMP_LINK] = imageTexture
  111.         if id == 4:
  112.             path = mat[c4d.OCT_MATERIAL_NORMAL_LINK][c4d.BITMAPSHADER_FILENAME]
  113.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  114.             mat[c4d.OCT_MATERIAL_NORMAL_LINK] = imageTexture
  115.         if id == 5:
  116.             path = mat[c4d.OCT_MATERIAL_DISPLACEMENT_LINK][c4d.BITMAPSHADER_FILENAME]
  117.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  118.             mat[c4d.OCT_MATERIAL_DISPLACEMENT_LINK] = imageTexture
  119.         if id == 6:
  120.             path = mat[c4d.OCT_MATERIAL_OPACITY_LINK][c4d.BITMAPSHADER_FILENAME]
  121.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  122.             mat[c4d.OCT_MATERIAL_OPACITY_LINK] = imageTexture
  123.         if id == 7:
  124.             path = mat[c4d.OCT_MATERIAL_TRANSMISSION_LINK][c4d.BITMAPSHADER_FILENAME]
  125.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  126.             mat[c4d.OCT_MATERIAL_TRANSMISSION_LINK] = imageTexture
  127.         if id == 8:
  128.             path = mat[c4d.OCT_MATERIAL_EMISSION][c4d.BITMAPSHADER_FILENAME]
  129.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  130.             mat[c4d.OCT_MATERIAL_EMISSION] = imageTexture
  131.         if id == 9:
  132.             path = mat[c4d.OCT_MATERIAL_MEDIUM][c4d.BITMAPSHADER_FILENAME]
  133.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  134.             mat[c4d.OCT_MATERIAL_MEDIUM] = imageTexture  
  135.         if id == 10:
  136.             path = mat[c4d.OCT_MATERIAL_SPECULAR_LINK][c4d.BITMAPSHADER_FILENAME]
  137.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  138.             mat[c4d.OCT_MATERIAL_SPECULAR_LINK] = imageTexture  
  139.         if id == 11:
  140.             path = mat[c4d.OCT_MATERIAL_FILMWIDTH_LINK][c4d.BITMAPSHADER_FILENAME]
  141.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  142.             mat[c4d.OCT_MATERIAL_FILMWIDTH_LINK] = imageTexture  
  143.         if id == 12:
  144.             path = mat[c4d.OCT_MATERIAL_REFLECTION_LINK][c4d.BITMAPSHADER_FILENAME]
  145.             imageTexture[c4d.IMAGETEXTURE_FILE] = path
  146.             mat[c4d.OCT_MATERIAL_REFLECTION_LINK] = imageTexture      
  147.  
  148.    
  149.         mat.InsertShader(imageTexture )
  150.         mat.Message(c4d.MSG_UPDATE)
  151.         mat.Update(True, True)
  152.  
  153. def main():
  154.     allMat = doc.GetActiveMaterials()
  155.     for mat in allMat:
  156.         data = getEntry(mat)
  157.         remplaceEntry(mat,data)
  158.         mat = mat.GetNext()
  159.        
  160.     c4d.EventAdd()    
  161.  
  162. if __name__=='__main__':
  163.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement