Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #STEP 1 CREATE THE MATERIAL AND APPLY IT TO THE OBJECT
- import bpy
- def makeMaterial(name, diffuse):
- mat = bpy.data.materials.new(name)
- mat.diffuse_color = diffuse
- mat.use_nodes = True
- return mat
- def setMaterial (ob, mat):
- me = ob.data # me ????????
- me.materials.append(mat)
- # Run make and set material commands
- def run(origin):
- dominoMat = makeMaterial('dominoMaterial', (0.4, 0.6, 0.8))
- setMaterial(bpy.context.object, dominoMat)
- if __name__ == "__main__": # == or === ???????
- run((0,0,0))
- #STEP 2 REFINE MATERIAL
- import bpy
- # MAKE SURE RENDERER IS SET TO CYCLES
- bpy.context.scene.render.engine = 'CYCLES'
- # CHOOSE IMAGE TEXTURE
- image = bpy.data.images.load('/Users/sebba/Desktop/DominoesTextureStrip_Dif.png')
- # Create the domino material
- def makeMaterial(name, diffuse):
- #NEW MATERIAL
- mat = bpy.data.materials.new(name)
- mat.diffuse_color = diffuse
- mat.use_nodes = True
- #DELETE ALL CURRENT NODES
- mat.node_tree.nodes.clear()
- #ADD DESIRED NODES, SET VALUES, LOCATIONS AND CONNECTIONS BETWEEN NODES
- texture = mat.node_tree.nodes.new(type = 'ShaderNodeTexImage')
- texture.image = image
- mapping = mat.node_tree.nodes.new(type = 'ShaderNodeMapping')
- coordinate = mat.node_tree.nodes.new(type = 'ShaderNodeTexCoord')
- diffuse = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfDiffuse')
- glossy = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfGlossy')
- glossy.inputs[1].default_value = 0.15
- mix = mat.node_tree.nodes.new(type = 'ShaderNodeMixShader')
- mix.inputs[0].default_value = 0.12
- bump = mat.node_tree.nodes.new(type = 'ShaderNodeBump')
- bump.inputs[0].default_value = 0.2
- bump.inputs[1].default_value = 0.1
- output = mat.node_tree.nodes.new(type = 'ShaderNodeOutputMaterial')
- texture.location = -500,500
- mapping.location = -900,400
- coordinate.location = -1100,400
- diffuse.location = 0,400
- glossy.location = 0,200
- mix.location = 300,200
- bump.location = -300,200
- output.location = 500,300
- mat.node_tree.links.new(diffuse.outputs[0], mix.inputs[1])
- mat.node_tree.links.new(glossy.outputs[0], mix.inputs[2])
- mat.node_tree.links.new(mix.outputs[0], output.inputs[0])
- mat.node_tree.links.new(coordinate.outputs[2], mapping.inputs[0])
- mat.node_tree.links.new(texture.outputs[0], diffuse.inputs[0])
- mat.node_tree.links.new(texture.outputs[0], bump.inputs[2])
- mat.node_tree.links.new(mapping.outputs[0], texture.inputs[0])
- mat.node_tree.links.new(bump.outputs[0], glossy.inputs[2])
- mat.node_tree.links.new(bump.outputs[0], diffuse.inputs[2])
- return mat
- # PUT MATERIAL ON OBJECT
- def setMaterial(ob, mat)
- me = ob.data
- me.materials.append(mat)
- # RUN MAKE AND SET MATERIAL COMMAND
- def run(origin):
- dominoMat = makeMaterial('dominoMaterial', (0.4, 0.6, 0.8)
- setMaterial(bpy.context.object, dominoMat)
- # ENSURES EACH DOMINO HAS IT'S OWN RANDOMLY GENERATED FACE
- if __name__ == "__main__":
- run((0,0,0))
- #STEP 2 REFINE MATERIAL
- # import bpy
- import random
- # MAKE SURE RENDERER IS SET TO CYCLES
- bpy.context.scene.render.engine = 'CYCLES'
- # CHOOSE IMAGE TEXTURE
- image = bpy.data.images.load('/Users/sebba/Desktop/DominoesTextureStrip_Dif.png')
- # Create the domino material
- def makeMaterial(name, diffuse):
- #NEW MATERIAL
- mat = bpy.data.materials.new(name)
- mat.diffuse_color = diffuse
- mat.use_nodes = True
- #DELETE ALL CURRENT NODES
- mat.node_tree.nodes.clear()
- #ADD DESIRED NODES, SET VALUES, LOCATIONS AND CONNECTIONS BETWEEN NODES
- texture = mat.node_tree.nodes.new(type = 'ShaderNodeTexImage')
- texture.image = image
- mapping = mat.node_tree.nodes.new(type = 'ShaderNodeMapping')
- mapping.translation = random.randint(0,27) * 0.42855,0.0
- mapping.rotation = 0.0,random,randint(0,1) *3.14159
- coordinate = mat.node_tree.nodes.new(type = 'ShaderNodeTexCoord')
- diffuse = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfDiffuse')
- glossy = mat.node_tree.nodes.new(type = 'ShaderNodeBsdfGlossy')
- glossy.inputs[1].default_value = 0.15
- mix = mat.node_tree.nodes.new(type = 'ShaderNodeMixShader')
- mix.inputs[0].default_value = 0.12
- bump = mat.node_tree.nodes.new(type = 'ShaderNodeBump')
- bump.inputs[0].default_value = 0.2
- bump.inputs[1].default_value = 0.1
- output = mat.node_tree.nodes.new(type = 'ShaderNodeOutputMaterial')
- texture.location = -500,500
- mapping.location = -900,400
- coordinate.location = -1100,400
- diffuse.location = 0,400
- glossy.location = 0,200
- mix.location = 300,200
- bump.location = -300,200
- output.location = 500,300
- mat.node_tree.links.new(diffuse.outputs[0], mix.inputs[1])
- mat.node_tree.links.new(glossy.outputs[0], mix.inputs[2])
- mat.node_tree.links.new(mix.outputs[0], output.inputs[0])
- mat.node_tree.links.new(coordinate.outputs[2], mapping.inputs[0])
- mat.node_tree.links.new(texture.outputs[0], diffuse.inputs[0])
- mat.node_tree.links.new(texture.outputs[0], bump.inputs[2])
- mat.node_tree.links.new(mapping.outputs[0], texture.inputs[0])
- mat.node_tree.links.new(bump.outputs[0], glossy.inputs[2])
- mat.node_tree.links.new(bump.outputs[0], diffuse.inputs[2])
- return mat
- # PUT MATERIAL ON OBJECT
- def setMaterial(ob, mat)
- me = ob.data
- me.materials.append(mat)
- # RUN MAKE AND SET MATERIAL COMMAND
- def run(origin):
- dominoMat = makeMaterial('dominoMaterial', (0.4, 0.6, 0.8)
- setMaterial(bpy.context.object, dominoMat)
- x = -1
- # ENSURES EACH DOMINO HAS IT'S OWN RANDOMLY GENERATED FACE
- if __name__ == "__main__":
- for obj in Group_List:
- x = x + 1
- bpy.context.scene.objects.active = bpy.data.objects.[Group_List[x].name]
- run((0,0,0))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement