Advertisement
gr4ph0s

ConvertOctaneBitmap

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