Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.58 KB | None | 0 0
  1. #STEP 1 CREATE THE MATERIAL AND APPLY IT TO THE OBJECT
  2.  
  3. import bpy
  4.  
  5. def makeMaterial(name, diffuse):
  6. mat = bpy.data.materials.new(name)
  7. mat.diffuse_color = diffuse
  8. mat.use_nodes = True
  9. return mat
  10.  
  11. def setMaterial (ob, mat):
  12. me = ob.data # me ????????
  13. me.materials.append(mat)
  14.  
  15. # Run make and set material commands
  16. def run(origin):
  17. dominoMat = makeMaterial('dominoMaterial', (0.4, 0.6, 0.8))
  18. setMaterial(bpy.context.object, dominoMat)
  19.  
  20. if __name__ == "__main__": # == or === ???????
  21. run((0,0,0))
  22.  
  23.  
  24. #STEP 2 REFINE MATERIAL
  25.  
  26. import bpy
  27.  
  28. # MAKE SURE RENDERER IS SET TO CYCLES
  29. bpy.context.scene.render.engine = 'CYCLES'
  30.  
  31. # CHOOSE IMAGE TEXTURE
  32.  
  33. image = bpy.data.images.load('/Users/sebba/Desktop/DominoesTextureStrip_Dif.png')
  34.  
  35. # Create the domino material
  36.  
  37. def makeMaterial(name, diffuse):
  38. #NEW MATERIAL
  39. mat = bpy.data.materials.new(name)
  40. mat.diffuse_color = diffuse
  41. mat.use_nodes = True
  42. #DELETE ALL CURRENT NODES
  43. mat.node_tree.nodes.clear()
  44. #ADD DESIRED NODES, SET VALUES, LOCATIONS AND CONNECTIONS BETWEEN NODES
  45. texture = mat.node_tree.nodes.new(type = 'ShaderNodeTexImage')
  46. texture.image = image
  47. mapping = mat.node_tree.nodes.new(type = 'ShaderNodeMapping')
  48. coordinate = mat.node_tree.nodes.new(type = 'ShaderNodeTexCoord')
  49. diffuse = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfDiffuse')
  50. glossy = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfGlossy')
  51. glossy.inputs[1].default_value = 0.15
  52. mix = mat.node_tree.nodes.new(type = 'ShaderNodeMixShader')
  53. mix.inputs[0].default_value = 0.12
  54. bump = mat.node_tree.nodes.new(type = 'ShaderNodeBump')
  55. bump.inputs[0].default_value = 0.2
  56. bump.inputs[1].default_value = 0.1
  57. output = mat.node_tree.nodes.new(type = 'ShaderNodeOutputMaterial')
  58. texture.location = -500,500
  59. mapping.location = -900,400
  60. coordinate.location = -1100,400
  61. diffuse.location = 0,400
  62. glossy.location = 0,200
  63. mix.location = 300,200
  64. bump.location = -300,200
  65. output.location = 500,300
  66. mat.node_tree.links.new(diffuse.outputs[0], mix.inputs[1])
  67. mat.node_tree.links.new(glossy.outputs[0], mix.inputs[2])
  68. mat.node_tree.links.new(mix.outputs[0], output.inputs[0])
  69. mat.node_tree.links.new(coordinate.outputs[2], mapping.inputs[0])
  70. mat.node_tree.links.new(texture.outputs[0], diffuse.inputs[0])
  71. mat.node_tree.links.new(texture.outputs[0], bump.inputs[2])
  72. mat.node_tree.links.new(mapping.outputs[0], texture.inputs[0])
  73. mat.node_tree.links.new(bump.outputs[0], glossy.inputs[2])
  74. mat.node_tree.links.new(bump.outputs[0], diffuse.inputs[2])
  75. return mat
  76.  
  77. # PUT MATERIAL ON OBJECT
  78. def setMaterial(ob, mat)
  79. me = ob.data
  80. me.materials.append(mat)
  81.  
  82. # RUN MAKE AND SET MATERIAL COMMAND
  83. def run(origin):
  84. dominoMat = makeMaterial('dominoMaterial', (0.4, 0.6, 0.8)
  85. setMaterial(bpy.context.object, dominoMat)
  86.  
  87. # ENSURES EACH DOMINO HAS IT'S OWN RANDOMLY GENERATED FACE
  88. if __name__ == "__main__":
  89. run((0,0,0))
  90.  
  91.  
  92.  
  93. #STEP 2 REFINE MATERIAL
  94.  
  95. # import bpy
  96.  
  97. import random
  98.  
  99. # MAKE SURE RENDERER IS SET TO CYCLES
  100. bpy.context.scene.render.engine = 'CYCLES'
  101.  
  102. # CHOOSE IMAGE TEXTURE
  103. image = bpy.data.images.load('/Users/sebba/Desktop/DominoesTextureStrip_Dif.png')
  104.  
  105. # Create the domino material
  106.  
  107. def makeMaterial(name, diffuse):
  108. #NEW MATERIAL
  109. mat = bpy.data.materials.new(name)
  110. mat.diffuse_color = diffuse
  111. mat.use_nodes = True
  112. #DELETE ALL CURRENT NODES
  113. mat.node_tree.nodes.clear()
  114. #ADD DESIRED NODES, SET VALUES, LOCATIONS AND CONNECTIONS BETWEEN NODES
  115. texture = mat.node_tree.nodes.new(type = 'ShaderNodeTexImage')
  116. texture.image = image
  117. mapping = mat.node_tree.nodes.new(type = 'ShaderNodeMapping')
  118. mapping.translation = random.randint(0,27) * 0.42855,0.0
  119. mapping.rotation = 0.0,random,randint(0,1) *3.14159
  120. coordinate = mat.node_tree.nodes.new(type = 'ShaderNodeTexCoord')
  121. diffuse = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfDiffuse')
  122. glossy = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfGlossy')
  123. glossy.inputs[1].default_value = 0.15
  124. mix = mat.node_tree.nodes.new(type = 'ShaderNodeMixShader')
  125. mix.inputs[0].default_value = 0.12
  126. bump = mat.node_tree.nodes.new(type = 'ShaderNodeBump')
  127. bump.inputs[0].default_value = 0.2
  128. bump.inputs[1].default_value = 0.1
  129. output = mat.node_tree.nodes.new(type = 'ShaderNodeOutputMaterial')
  130. texture.location = -500,500
  131. mapping.location = -900,400
  132. coordinate.location = -1100,400
  133. diffuse.location = 0,400
  134. glossy.location = 0,200
  135. mix.location = 300,200
  136. bump.location = -300,200
  137. output.location = 500,300
  138. mat.node_tree.links.new(diffuse.outputs[0], mix.inputs[1])
  139. mat.node_tree.links.new(glossy.outputs[0], mix.inputs[2])
  140. mat.node_tree.links.new(mix.outputs[0], output.inputs[0])
  141. mat.node_tree.links.new(coordinate.outputs[2], mapping.inputs[0])
  142. mat.node_tree.links.new(texture.outputs[0], diffuse.inputs[0])
  143. mat.node_tree.links.new(texture.outputs[0], bump.inputs[2])
  144. mat.node_tree.links.new(mapping.outputs[0], texture.inputs[0])
  145. mat.node_tree.links.new(bump.outputs[0], glossy.inputs[2])
  146. mat.node_tree.links.new(bump.outputs[0], diffuse.inputs[2])
  147. return mat
  148.  
  149. # PUT MATERIAL ON OBJECT
  150. def setMaterial(ob, mat)
  151. me = ob.data
  152. me.materials.append(mat)
  153.  
  154. # RUN MAKE AND SET MATERIAL COMMAND
  155. def run(origin):
  156. dominoMat = makeMaterial('dominoMaterial', (0.4, 0.6, 0.8)
  157. setMaterial(bpy.context.object, dominoMat)
  158.  
  159. x = -1
  160. # ENSURES EACH DOMINO HAS IT'S OWN RANDOMLY GENERATED FACE
  161. if __name__ == "__main__":
  162. for obj in Group_List:
  163. x = x + 1
  164. bpy.context.scene.objects.active = bpy.data.objects.[Group_List[x].name]
  165. run((0,0,0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement