Ejemplo n.º 1
0
def change_colour(object, material, colour):
    # use lambert as the default for the pompom s it looks a bit different from the cone
    cmds.sets(name=material + 'MaterialGroup', renderable=True, empty=True)
    cmds.shadingNode(material, name=material + 'Shader', asShader=True)

    if not colour:
        # randomly generate a colour   0 to 1 on each axis   r g b
        red = random.random()
        green = random.random()
        blue = random.random()
        cmds.setAttr(material + 'Shader.color',
                     red,
                     green,
                     blue,
                     type='double3')

    else:
        # we should add some error catching here
        red = colour[0]
        green = colour[1]
        blue = colour[2]
        cmds.setAttr(material + 'Shader.color',
                     red,
                     green,
                     blue,
                     type='double3')

    cmds.surfaceShaderList(material + 'Shader', add=material + 'MaterialGroup')
    cmds.sets(object, e=True, forceElement=material + 'MaterialGroup')
Ejemplo n.º 2
0
def create_mask_for_object_with_color(obj_name, color):
	mask_name = obj_name+"_MASK"
	group_name = obj_name+"_GROUP"

	cmd.shadingNode("surfaceShader", name=mask_name, asShader=True)
	cmd.setAttr(mask_name+".outColor", color[0], color[1], color[2], type="double3")

	cmd.sets(name=group_name, renderable=True, empty=True)
	cmd.surfaceShaderList(mask_name, add=group_name)
	cmd.sets(obj_name, e=True, forceElement=group_name)
Ejemplo n.º 3
0
def create_texture(n):
    """
    creates the textures for any spherical object
    """
    myShader = cmds.shadingNode('lambert', asShader=True,
                                name=n + '_lambert')  # creating lambert
    cmds.sets(name=n + "_lambertG",
              renderable=True,
              empty=True,
              noSurfaceShader=True)  # creating lambertGroup
    cmds.connectAttr(n + '_lambert.outColor',
                     n + "_lambertG.surfaceShader",
                     force=True)  # connecting lamberGroup to lambert

    cmds.surfaceShaderList(n + '_lambert', add=n + "_lambertG")

    cmds.sets(n, e=True, forceElement=n + "_lambertG")

    myFile = cmds.shadingNode("file", name=n + '_file',
                              asTexture=True)  # creating file
    my2dTexture = cmds.shadingNode("place2dTexture",
                                   name=n + '_2dTexture',
                                   asUtility=True)  # creating texture

    for i in connections:
        cmds.connectAttr(my2dTexture + '.' + i, myFile + '.' + i, force=True)
    cmds.connectAttr(my2dTexture + '.outUV', myFile + '.uv')
    cmds.connectAttr(my2dTexture + '.outUvFilterSize',
                     myFile + '.uvFilterSize')

    cmds.connectAttr(myFile + '.outColor', myShader + '.color', force=True)

    if n == 'sun':
        cmds.setAttr(myFile + '.fileTextureName',
                     "sourceimages/8k_sun.jpg",
                     type="string")
    elif n == 'background':
        cmds.setAttr(myFile + '.fileTextureName',
                     "sourceimages/8k_background.jpg",
                     type="string")
    else:
        # 2k images for planets
        cmds.setAttr(myFile + '.fileTextureName',
                     texture_name.format(n),
                     type="string")

    cmds.setAttr(my2dTexture + ".rotateFrame", 90)

    # this is for the dark sides of the planets to be atleast dimly lit
    cmds.setAttr(myShader + ".ambientColor",
                 0.0194805,
                 0.0194805,
                 0.0194805,
                 type='double3')
Ejemplo n.º 4
0
def create_shadowPlane():
	if cmds.objExists("shadow_plane"):
		print "Shadow plane already exists in the scene."
	else:
		shadowPlane = cmds.polyPlane(n="shadow_plane", sx=10, sy=10)
		cmds.scale( 300, 300, 300, shadowPlane)
		cmds.select(shadowPlane)
		cmds.sets(name='matte_SG', renderable=True, empty=True)
		cmds.shadingNode('aiShadowMatte', name="shadowMatte_MAT", asShader=True)
		cmds.surfaceShaderList('shadowMatte_MAT', add="matte_SG")
		cmds.sets(shadowPlane, e=True, forceElement="matte_SG")
		print "Shadow plane created."
def setMaterial(objName, objNameL, materialType, materialTypeL, treecolour, leavescolour, progress):
   '''Assigns a material to the object 'objectName'

      objName      : the group of cylinders making up the trunk and branches of the tree
      objNameL     : the group of leave objects
      materialType : is string that specifies the type of the sufrace shader of the tree(leaves and cyclinders), 
                     this can be any of Maya's valid surface shaders such as:
                     lambert, blin, phong, etc.
      treecolour   : is a list of (R,G,B) values within the range [0,1]
                     which specify the colour of the cyclinders
      leavescolour : is a list of (R,G,B) values within the range [0,1]
                     which specify the colour of the leaves
      progress     : the path name to the progress bar control to allow for editing
      On Exit      : 'objName' and 'objNameL' have been assigned a new material according to the 
                     input values of the procedure, and two tuples (both of two strings) 
                     which contain the new shading group name, and the new shader
                     name are returned to the caller
	'''
   cmds.progressBar(progress, edit=True, pr=8000*0.6)
   
   # create a new set
   setName = cmds.sets(name='_MaterialGroup_', renderable=True, empty=True)
   
   # create a new shading node
   shaderName = cmds.shadingNode(materialType, asShader=True)
   
   # change its colour
   cmds.setAttr(shaderName+'.color', treecolour[0], treecolour[1], treecolour[2], type='double3')
   
   # add to the list of surface shaders
   cmds.surfaceShaderList(shaderName, add=setName)
   
   # assign the material to the object
   cmds.sets(objName, edit=True, forceElement=setName)
   cmds.progressBar(progress, edit=True, pr=8000*0.8)
   
   if not objNameL == "noleaves":
        # create a new set
       setNameL = cmds.sets(name='_MaterialGroup_1', renderable=True, empty=True)
       
       # create a new shading node
       shaderNameL = cmds.shadingNode(materialTypeL, asShader=True)
       
       # change its colour
       cmds.setAttr(shaderNameL+'.color', leavescolour[0], leavescolour[1], leavescolour[2], type='double3')
       
       # add to the list of surface shaders
       cmds.surfaceShaderList(shaderNameL, add=setNameL)
       
       cmds.sets(objNameL, edit=True, forceElement=setNameL)
       
   cmds.progressBar(progress, pr = 8000,  edit=True)
Ejemplo n.º 6
0
def create_mask_for_object_with_color(obj_name, color):
    mask_name = obj_name + "_MASK"
    group_name = obj_name + "_GROUP"

    cmd.shadingNode("surfaceShader", name=mask_name, asShader=True)
    cmd.setAttr(mask_name + ".outColor",
                color[0],
                color[1],
                color[2],
                type="double3")

    cmd.sets(name=group_name, renderable=True, empty=True)
    cmd.surfaceShaderList(mask_name, add=group_name)
    cmd.sets(obj_name, e=True, forceElement=group_name)
Ejemplo n.º 7
0
    def create_mask_for_object_with_color(self, obj_name, color):
        """ Creates a segmentation mask for the specified object in the given color """
        mask_name = obj_name + "_MASK"
        group_name = obj_name + "_GROUP"

        cmd.shadingNode("surfaceShader", name=mask_name, asShader=True)
        cmd.setAttr(mask_name + ".outColor",
                    color[0],
                    color[1],
                    color[2],
                    type="double3")

        cmd.sets(name=group_name, renderable=True, empty=True)
        cmd.surfaceShaderList(mask_name, add=group_name)
        cmd.sets(obj_name, e=True, forceElement=group_name)
Ejemplo n.º 8
0
def makeShader(colour, materialName = "material", type = "blinn"):
    '''
    Creates a shader of the specified type and colour.
    
    colour: A triple with values between 0 and 1, that define the rgb value for a colour.
    materialName: The name the material will be given.
    type: A string that specifies the type of the shader.
    On exit: A shader and shading group has been created and the specified 
             colour has been set for the shader. A tuple with the name of the material 
             and the name of the shading group is returned.
    '''
    shadingGroup = cmds.sets(name = materialName + "Group", renderable=True, empty=True)
    shader = cmds.shadingNode(type, asShader=True)
    cmds.setAttr(shader + ".color", colour[0], colour[1], colour[2])
    cmds.surfaceShaderList(shader, add=shadingGroup)
    shader = cmds.rename(shader, materialName)
    return (shader, shadingGroup)
Ejemplo n.º 9
0
def setMaterial(objName, materialType, colour, leafmodelGroup, colourleaf,
                materialTypeLeaf):
    '''Assigns a material to the object 'objectName'

   objectName      : is the name of a 3D object in the scene which is the branch
   materialType    : is string that specifies the type of the sufrace shader, 
                     this can be any of Maya's valid surface shaders such as:
                     lambert, blin, phong, etc. 
   colour          : is a 3-tuple of (R,G,B) and (H,S,V) values within the range [0,1]
                     which specify the colour of the material
                     colour=(0.024, 0.369, 0.024)):
   leafmodelGroup  : is the name of a 3D object in the scene which is the leaf
   colourleaf      : is a 3-tuple of (R,G,B) and (H,S,V) values within the range [0,1]
                     which specify the colour of the material
   materialTypeLeaf: is string that specifies the type of the sufrace shader, 
                     this can be any of Maya's valid surface shaders such as:
                     lambert, blin, phong, etc. 
   On Exit         : 'objName' has been assigned a new material according to the 
                     input values of the procedure, and a tuple (of two strings) 
                     which contains the new shading group name, and the new shader
                     name is returned to the caller
	'''

    # branch material and colour
    setName = cmds.sets(name='_MaterialGroup_', renderable=True, empty=True)
    shaderName = cmds.shadingNode(materialType, asShader=True)
    cmds.setAttr(shaderName + '.color',
                 colour[0],
                 colour[1],
                 colour[2],
                 type='double3')
    cmds.surfaceShaderList(shaderName, add=setName)
    cmds.sets(objName, edit=True, forceElement=setName)

    # leaf material and colour
    setLeafName = cmds.sets(name='_MaterialLeafGroup_',
                            renderable=True,
                            empty=True)
    shaderLeafName = cmds.shadingNode(materialTypeLeaf, asShader=True)
    cmds.setAttr(shaderLeafName + '.color',
                 colourleaf[0],
                 colourleaf[1],
                 colourleaf[2],
                 type='double3')
    cmds.surfaceShaderList(shaderLeafName, add=setLeafName)
    cmds.sets(leafmodelGroup, edit=True, forceElement=setLeafName)
Ejemplo n.º 10
0
def colorObject(objName, materialName="lambert", materialColor=(0, 0, 0)):
    """source from Xiaosong Yang's source.
	takes an object and creates and assigns a material to that object with the specified colour.
	
	objName       : name of object to assign shader to
	materialName  : type of material to create
	materialColor : color of the material
	
	return        : name of the shader created
	"""
    setName = cmds.sets(name="_MaterialGroup_", renderable=True, empty=True)
    # create a new shading node
    shaderName = cmds.shadingNode(materialName, asShader=True)
    # add to the list of surface shaders
    cmds.surfaceShaderList(shaderName, add=setName)
    # assign the material to the object
    cmds.sets(objName, edit=True, forceElement=setName)
    return shaderName
Ejemplo n.º 11
0
def colorObject(objName, materialName="lambert", materialColor=(0,0,0)):
	'''source from Xiaosong Yang's source.
	takes an object and creates and assigns a material to that object with the specified colour.
	
	objName       : name of object to assign shader to
	materialName  : type of material to create
	materialColor : color of the material
	
	return        : name of the shader created
	'''
	setName = cmds.sets(name='_MaterialGroup_', renderable=True, empty=True)
	# create a new shading node
	shaderName = cmds.shadingNode(materialName, asShader=True)
	# add to the list of surface shaders
	cmds.surfaceShaderList(shaderName, add=setName)
	# assign the material to the object
	cmds.sets(objName, edit=True, forceElement=setName)
	return shaderName
Ejemplo n.º 12
0
 def apply_texture(self, *args):
     object = cmds.ls(sl=True)
     selectedMenuItem = cmds.optionMenu('optionMenu', q=True, value=True)
     cmds.sets(name='imageMaterialGroup', renderable=True, empty=True)
     shaderNode = cmds.shadingNode('phong',
                                   name='shaderNode',
                                   asShader=True)
     fileNode = cmds.shadingNode('file', name='fileTexture', asTexture=True)
     cmds.setAttr('fileTexture' + '.fileTextureName',
                  self.myDir[0] + '/' + selectedMenuItem,
                  type="string")
     shadingGroup = cmds.sets(name='textureMaterialGroup',
                              renderable=True,
                              empty=True)
     cmds.connectAttr('shaderNode' + '.outColor',
                      'textureMaterialGroup' + '.surfaceShader')
     cmds.connectAttr('fileTexture' + '.outColor', 'shaderNode' + '.color')
     cmds.surfaceShaderList('shaderNode', add='imageMaterialGroup')
     cmds.sets(object, e=True, forceElement='imageMaterialGroup')
Ejemplo n.º 13
0
def create_saturn_rings():
    """
    for creating saturns rings..... more like a ring actually
    """
    cmds.torus(name='saturn_rings',
               axis=[0, 1.0, 0],
               radius=0.361,
               heightRatio=0.1)
    cmds.setAttr('saturn_ringsShape.castsShadows', 0)
    cmds.setAttr('saturn_ringsShape.receiveShadows', 0)
    cmds.setAttr('saturn_rings.scaleY', 0.125)

    myShader = cmds.shadingNode('lambert', asShader=True,
                                name='ring_lambert')  # creating lambert
    cmds.sets(name="ring_lambertG",
              renderable=True,
              empty=True,
              noSurfaceShader=True)  # creating lambertGroup
    cmds.connectAttr('ring_lambert.outColor',
                     "ring_lambertG.surfaceShader",
                     force=True)  # connecting lamberGroup to lambert

    cmds.surfaceShaderList('ring_lambert', add="ring_lambertG")

    cmds.sets('saturn_rings', e=True, forceElement="ring_lambertG")

    wood = cmds.shadingNode("wood", name='ring_wood',
                            asTexture=True)  # creating file
    my3dTexture = cmds.shadingNode("place3dTexture",
                                   name='ring_3dTexture',
                                   asUtility=True)  # creating texture

    cmds.connectAttr('ring_3dTexture.worldInverseMatrix',
                     'ring_wood.placementMatrix')

    cmds.connectAttr('ring_wood.outColor', myShader + '.color', force=True)
    cmds.parent('saturn_rings', 'saturn')
Ejemplo n.º 14
0
def color(object, material, color, export=False, fbx=False): 
  mc.sets(name=material+'MaterialGroup', renderable=True, empty=True)
  mc.shadingNode(material, name=material+'Shader', asShader=True)
  mc.setAttr(material+'Shader.color', color[0], color[1], color[2], type='double3')
  mc.surfaceShaderList(material+'Shader', add=material+'MaterialGroup')
  mc.sets(object, e=True, forceElement=material+'MaterialGroup')
Ejemplo n.º 15
0
Archivo: red.py Proyecto: chirs/studio5
import maya.cmds as cmds

# Create a NURBS plane.
cmds.nurbsPlane( d=3, p=(0, 0, 0), lr=1, axis=(0, 0, 0), n='plane1' )

# Make it red.
cmds.sets( name='redMaterialGroup', renderable=True, empty=True )
cmds.shadingNode( 'phong', name='redShader', asShader=True )
cmds.setAttr( 'redShader.color', 1, 0, 0, type='double3' )
cmds.surfaceShaderList( 'redShader', add='redMaterialGroup' )
cmds.sets( 'plane1', e=True, forceElement='redMaterialGroup' )

Ejemplo n.º 16
0
def PolyToruses(\
x = random.uniform(-10,10),\
x_r = 1,\
y = random.uniform(0,20),\
y_r = 1,\
z = random.uniform(-10,10),\
z_r = 1,\
xRot = random.uniform( 0, 360 ),\
xRot_r = 10,\
yRot = random.uniform( 0, 360 ),\
yRot_r = 10,\
zRot = random.uniform( 0, 360 ),\
zRot_r = 10,\
r = random.uniform(0,2),\
r_r = .1,\
g = random.uniform(0,2),\
g_r = .1,\
b = random.randint(0,2),\
b_r = .1,\
scaleF = random.uniform( 0.3, 1.5 ),\
scaleF_r = .1,\
):
    
    def change(start,min,max,rate):
    	if random.randint(0,5) == 0:
    		rate = (-1 * rate)
    	start += rate
    	if start < min or start > max:
    		rate = (-1 * rate)
    		start += rate
    	return start,rate
    
  
    for i in range( 0, 50 ):
       
       #create cube
    	cmds.polyTorus( sx=1, sy=1, r=1, sr=1, n='torus{}'.format(i))
    	
    	#vary location
    	x = change(x,-10,10,x_r)[0]
    	x_r = change(x,-10,10,x_r)[1]
    	y = change(y,0,20,y_r)[0]
    	y_r = change(y,0,20,y_r)[1]
    	z = change(z,-10,10,z_r)[0]
    	z_r = change(z,-10,10,z_r)[1]
    	
    	#vary rotation
    	xRot = change(xRot,1,360,xRot_r)[0]
    	xRot_r = change(xRot,1,360,xRot_r)[1]
    	yRot = change(yRot,1,360,yRot_r)[0]
    	yRot_r = change(yRot,1,360,yRot_r)[1]
    	zRot = change(zRot,1,360,zRot_r)[0]
    	zRot_r = change(zRot,1,360,zRot_r)[1]
    	
    	#vary color
    	r = change(r,0,2,r_r)[0]
    	r_r = change(r,0,2,r_r)[1]
    	g = change(g,0,2,g_r)[0]
    	g_r = change(g,0,2,g_r)[1]
    	b = change(b,0,2,b_r)[0]
    	b_r = change(b,0,2,b_r)[1]
    	
    	#vary scale
    	scaleF = change(scaleF,0.3,1.5,scaleF_r)[0]
    	scaleF_r = change(scaleF,0.3,1.5,scaleF_r)[1]
    	
    	#apply variabels
    	cmds.rotate( xRot, yRot, zRot, 'torus{}'.format(i))
    	
    	cmds.scale(scaleF, scaleF, scaleF, 'torus{}'.format(i))
    	
    	cmds.move( x, y, z, 'torus{}'.format(i))
    	
    	cmds.sets( name='TorusMaterial{}'.format(i), renderable=True, empty=True )
    	cmds.shadingNode( 'phong', name='TorusShader{}'.format(i), asShader=True )
    	cmds.setAttr( 'TorusShader{}'.format(i)+'.color', r, g, b, type='double3' )
    	cmds.surfaceShaderList( 'TorusShader{}'.format(i), add='TorusMaterial{}'.format(i))
    	cmds.sets( 'torus{}'.format(i), forceElement='TorusMaterial{}'.format(i))
Ejemplo n.º 17
0
def assignShaderColour( _objName, _shaderType = 'lambert', _colour = [ 0.5, 0.5, 0.5 ] ):  
    shadingGroup = cmds.sets( empty = True, renderable = True)    #creates empty set, stored in variable shadingGrop
    shaderName = cmds.shadingNode (_shaderType, asShader = True)                          #creates lambert shading node, stored in variable shader name
    cmds.setAttr( shaderName + '.color', _colour[0], _colour[1], _colour[2], type = 'double3' )    #changes shader node's color attribute
    cmds.surfaceShaderList( shaderName , add = shadingGroup)           #adds the shader node to the shadingGroup 
    cmds.sets( _objName , edit = True, forceElement = shadingGroup)     #adds object to shading group
Ejemplo n.º 18
0
 def add(self):
     cmds.sets(name="MAT_GROUP", renderable=True, empty=True)
     cmds.surfaceShaderList(SHADER_NAME, add="MAT_GROUP")
     cmds.sets(self.object, e=True, forceElement="MAT_GROUP")