Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import c4d
- #-- Gr4ph0s
- # visit graphos.fr
- def getEntry(mat):
- diffuse = mat[c4d.OCT_MATERIAL_DIFFUSE_LINK]
- roughness = mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK]
- bump = mat[c4d.OCT_MATERIAL_BUMP_LINK]
- normal = mat[c4d.OCT_MATERIAL_NORMAL_LINK]
- displace = mat[c4d.OCT_MATERIAL_DISPLACEMENT_LINK]
- opacity = mat[c4d.OCT_MATERIAL_OPACITY_LINK]
- transmission = mat[c4d.OCT_MATERIAL_TRANSMISSION_LINK]
- emission = mat[c4d.OCT_MATERIAL_EMISSION]
- medium = mat[c4d.OCT_MATERIAL_MEDIUM]
- buffer = []
- try :
- if diffuse.CheckType(5833):
- buffer.append([1,diffuse[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if roughness.CheckType(5833):
- buffer.append([2,roughness[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if bump.CheckType(5833):
- buffer.append([3,bump[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if normal.CheckType(5833):
- buffer.append([4,normal[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if displace.CheckType(5833):
- buffer.append([5,displace[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if opacity.CheckType(5833):
- buffer.append([6,opacity[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if transmission.CheckType(5833):
- buffer.append([7,transmission[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if emission.CheckType(5833):
- buffer.append([8,emission[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- try :
- if medium.CheckType(5833):
- buffer.append([9,medium[c4d.BITMAPSHADER_FILENAME]])
- except:
- pass
- return buffer
- def get_shader(mat):
- shader = mat.GetFirstShader()
- while shader:
- if shader.CheckType(5833):
- test = c4d.BaseShader(1029508)
- test[c4d.IMAGETEXTURE_FILE] = "testbbbbbb"
- mat.InsertShader(test)
- mat.Message(c4d.MSG_UPDATE)
- mat.Update(True, True)
- print shader[c4d.BITMAPSHADER_FILENAME]
- shader = shader.GetNext()
- def remplaceEntry(mat,data):
- for i in xrange(0,len(data)):
- id = data[i][0]
- imageTexture = c4d.BaseShader(1029508)
- if id == 1:
- path = mat[c4d.OCT_MATERIAL_DIFFUSE_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_DIFFUSE_LINK] = imageTexture
- if id == 2:
- path = mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_ROUGHNESS_LINK] = imageTexture
- if id == 3:
- path = mat[c4d.OCT_MATERIAL_BUMP_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_BUMP_LINK] = imageTexture
- if id == 4:
- path = mat[c4d.OCT_MATERIAL_NORMAL_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_NORMAL_LINK] = imageTexture
- if id == 5:
- path = mat[c4d.OCT_MATERIAL_DISPLACEMENT_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_DISPLACEMENT_LINK] = imageTexture
- if id == 6:
- path = mat[c4d.OCT_MATERIAL_OPACITY_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_OPACITY_LINK] = imageTexture
- if id == 7:
- path = mat[c4d.OCT_MATERIAL_TRANSMISSION_LINK][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_TRANSMISSION_LINK] = imageTexture
- if id == 8:
- path = mat[c4d.OCT_MATERIAL_EMISSION][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_EMISSION] = imageTexture
- if id == 9:
- path = mat[c4d.OCT_MATERIAL_MEDIUM][c4d.BITMAPSHADER_FILENAME]
- imageTexture[c4d.IMAGETEXTURE_FILE] = path
- mat[c4d.OCT_MATERIAL_MEDIUM] = imageTexture
- mat.InsertShader(imageTexture )
- mat.Message(c4d.MSG_UPDATE)
- mat.Update(True, True)
- def main():
- allMat = doc.GetActiveMaterials()
- for mat in allMat:
- data = getEntry(mat)
- remplaceEntry(mat,data)
- mat = mat.GetNext()
- c4d.EventAdd()
- if __name__=='__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement