Exemplo n.º 1
0
def extrudeLedge(face):
    """ extrude the first ledge on rooftop """
    localScaleRDM = random.uniform(0.88, 0.98)
    localScale = (localScaleRDM, localScaleRDM, 1)
    cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=0, localScale=localScale)

    return face
def createHoneyPiece(n):
    planeName = 'plane'+str(n)
    print planeName
    cmds.polyPlane(w=20, h=20, sx=12, sy=12, n=planeName)
    edgeNum = 26
    modVal = 1;
    edgeArray = []
    for i in range(52):
        edgeArray.append(planeName+'.e['+str(edgeNum)+']');
        edgeNum += 2
        if(edgeNum == 51):
            edgeNum = 101
        if(edgeNum==50):
            edgeNum = 49
        if(edgeNum == 126):
            edgeNum = 176
        if(edgeNum==125):
            edgeNum = 124
        if(edgeNum==201):
            edgeNum = 251
        if(edgeNum==200):
            edgeNum = 199
        if(edgeNum==275):
            edgeNum = 274
    cmds.polyBevel(edgeArray, offset=1,offsetAsFraction=1,autoFit=1,segments=1,worldSpace=1,uvAssignment=0,fillNgons=1,mergeVertices=1,mergeVertexTolerance=0.0001,smoothingAngle=30,miteringAngle=180,angleTolerance=180,ch=1)
    cmds.select( clear=True)
    print len(edgeArray)
    del edgeArray[:]
    print len(edgeArray)
    for i in range(532, 620):
        cmds.select(planeName+'.e['+str(i)+']', toggle=True);
    size = 36;
    edgeNum = 31
    counter = 0
    for i in range(size):
        cmds.select(planeName+'.e['+str(edgeNum)+']', toggle=True);
        edgeNum += 2
        counter += 1
        if(counter == 12):
            counter = 0
            edgeNum += 7;
    cmds.delete();
    for i in range(12):
         cmds.select(planeName+'.f['+str(i)+']', toggle=True);
    for i in range(96, 108):
         cmds.select(planeName+'.f['+str(i)+']', toggle=True);
    for i in range(1,8):
        cmds.select(planeName+'.f['+str(i*12)+']', toggle=True);
    for i in range(1,8):
        cmds.select(planeName+'.f['+str(i*12+11)+']', toggle=True);
    cmds.delete();
    
    cmds.scale(1, 1, 0.5, planeName);
    #cmds.select(planeName+'.f[0:113]')
    cmds.polyExtrudeFacet(planeName+'.f[0:113]', constructionHistory=1, keepFacesTogether=0, pvx=4.7, pvy=-1.058, pvz=2.38, divisions=1, twist=0, taper=1, off=0, thickness=0, smoothingAngle=30)
    cmds.setAttr("polyExtrudeFace"+str(n*2+1)+".localScale", 0.833333, 0.833333, 0.829938, type="double3")
    cmds.delete();
    cmds.select(planeName+'.f[0:723]')
    cmds.polyExtrudeFacet(constructionHistory=1, keepFacesTogether=1, pvx=-4.7, pvy=-1.058, pvz=2.38, divisions=1, twist=0, taper=1, off=0, thickness=0, smoothingAngle=30)
    cmds.setAttr("polyExtrudeFace"+str(n*2+2)+".localTranslate", 0, 0, 1, type="double3")
Exemplo n.º 3
0
def changeGear(transform, constructor, extrudeNode, teeth = 5, length = 0.2):
    '''
    this function will change target gearlike geo's teeth number and teeth length
    :param transform: transform node
    :param constructor: mesh constructor
    :param extrudeNode: extrudenode
    :param teeth: new number of teeth
    :param length: new number of teeth length
    :return: 0
    '''
    spin = teeth*2
    ##use edit flag to change target meshNode(constructor)
    cmds.polyPipe(constructor, edit = True, subdivisionsAxis=spin)
    faceNum = range(spin * 2, spin * 3, 2)

    cmds.select(clear=True)

    newFaceList = []
    for face in faceNum:
        #build a new extrudeFaceList to upgrade the Node
        newFaceList.append("f[%s]" % (face))
    ##ust need to edit the current extrude attr
    print newFaceList;
    ##use setAttr to specify the new list of extrude faces
    cmds.setAttr("%s.inputComponents" % (extrudeNode), len(newFaceList), *newFaceList, type ='componentList')
    ##it seems can use cmds.xxxnode(edit = True) to change it's flag value
    cmds.polyExtrudeFacet(extrudeNode, edit=True, ltz=length)
    return 0
Exemplo n.º 4
0
def hsbc() :
    
    hsbcBuilding = mc.polyCube(h=9,n="HSBC")
    mc.move(0,9/2.0,0,hsbcBuilding)
    mc.polyExtrudeFacet( hsbcBuilding[0] +".f[1]", kft=False, ltz=2, ls=(.5, .5, 0) )
    
    mc.select(clear =True)
Exemplo n.º 5
0
def extrudeSimple(face):
    """ extrude a simple rooftop """
    localScaleRDM = random.uniform(0.88, 0.98)
    localScale = (localScaleRDM, localScaleRDM, 1)
    thickness = random.randint(30,65)
    cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=thickness, localScale=localScale)

    return face
Exemplo n.º 6
0
def extrudeHole(face):
    """ extrude a rounded and  """
    iterations = 5
    localScale = 0.9
    thickness = 25
    for iteration in range(iterations):
        cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=thickness, localScale=[localScale, localScale, localScale])
        thickness -= 10
    
    return face
Exemplo n.º 7
0
def extrudeConcave(face):
    """ extrude a concave rooftop """
    iterations = 3
    localScale = 0.85
    thickness = 25
    for iteration in range(iterations):
        cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=thickness, localScale=[localScale, localScale, localScale])
        localScale += 0.04
        thickness += 5

    return face
Exemplo n.º 8
0
def extrudeRounded(face):
    """ extrude a rounded rooftop """
    iterations = 4
    localScale = 0.92
    thickness = random.randint(25,35)
    for iteration in range(iterations):
        cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=thickness, localScale=[localScale, localScale, localScale])
        localScale -= 0.04
        thickness -= 5

    return face
Exemplo n.º 9
0
def extrudePinched(face):
    """ extrude a pinched rooftop if the face has exactly 4 edges """
    iterations = 1
    localScaleX = 1
    localScaleY = 0
    localScaleZ = 1
    thickness = 25
    for iteration in range(iterations):
        cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=thickness, localScale=[localScaleX, localScaleY, localScaleZ])

    return face
Exemplo n.º 10
0
	def extrudeTool(self):
		X = self.getSelection() # adds selection to a variable so we can deselect it later while still using it for the Dragger command.
		if self.getType(0) == 'face':
			cmds.polyExtrudeFacet( X, constructionHistory = 1, keepFacesTogether = 1)
			self.setAttributes( attrs = [('Thickness', '.thickness'), ('Offset', '.offset'), ('Division', '.divisions'), ('Z Translate', '.localTranslateZ'), ('Faces Together', '.keepFacesTogether')] )
		elif self.getType(0) == 'edge':
			cmds.polyExtrudeEdge( X, constructionHistory = 1, keepFacesTogether = 1)
			self.setAttributes( attrs = [('Thickness', '.thickness'), ('Offset', '.offset'), ('Division', '.divisions'), ('Z Translate', '.localTranslateZ')] )
		else:
			pass
		#cmds.select( deselect = 1 ) # removes selection from the face initially extruded, to allow for rotation and translation of new extruded face
		self.Dragger( X , 'Extrude')
Exemplo n.º 11
0
def add_spikes(obj):
    """This function adds spikes to a polygon object."""

    try:
        polyCount = cmds.polyEvaluate(obj, face=True)
    except:
        raise
    for i in range(0,polyCount):
        face="%s.f[%s]" % (obj,i)
        cmds.polyExtrudeFacet(face, ltz=1, ch=0)
        cmds.polyExtrudeFacet(face, ltz=1, ch=0, ls=[0.1,0.1,0.1])
    cmds.polySoftEdge(obj, a=180, ch=0)
    cmds.select(obj)
Exemplo n.º 12
0
def extrudeDouble(face):
    """ extrude a double iteration rooftop """
    iterations = 2
    s = 0.0
    t = 0
    for iteration in range(iterations):
        localScaleRDM = random.uniform(0.88-s, 0.98-s)
        localScale = (localScaleRDM, localScaleRDM, 1)
        thickness = random.randint(30,65)-t
        cmds.polyExtrudeFacet(face, ch=HISTORY, keepFacesTogether=False, thickness=thickness, localScale=localScale)
        s += 0.2
        t += 10

    return face
Exemplo n.º 13
0
	def crear(self):
			
		#Tipo 1
		if(self.edififio_seleccionado == 0):
			cmds.polyCube(w = self.anchura, d = self.Largo, h = self.Anchura_random, n =  str(self.EdificioName))
			
		#Tipo 2
		elif(self.edififio_seleccionado == 1):
		
			cmds.polyCube(w = self.anchura, d = self.Largo, h = self.Anchura_random, n =  str(self.EdificioName))
			
			#Modificamos las caras aleatoriamente
			for i in range(0, random.randrange(0,3)):
				cmds.polyExtrudeFacet(str(self.EdificioName) + ".f[1]", kft = False, ls = (0.8, 0.8, 0))
				cmds.polyExtrudeFacet(str(self.EdificioName) + ".f[1]", kft = False, ltz = 30)	
			
		#Tipo 3	
		else:
			cmds.polyCube(w = self.anchura, d = self.Largo, h = self.Anchura_random, sx = self.xDiv, sy = self.yDiv, sz = self.zDiv, n = str(self.EdificioName))			
			
			sides = []
			
			#Seleccionamos el edificio
			for i in range(0, 8):
				if(i != 1 and i != 3):
					sides.append(str(self.EdificioName) + ".f[" + str(self.xDiv * self.yDiv * i) + ":" + str((self.xDiv * self.yDiv * (i+1)) - 1) + "]")
			
			#Modificamos las caras para generar ventanas
			cmds.polyExtrudeFacet(sides[0], sides[1], sides[2], sides[3], sides[4], sides[5], kft = False, ls = (0.8, 0.8, 0))
			windows = cmds.ls(sl = True)
			cmds.polyExtrudeFacet(windows[1], windows[2], windows[3], kft = False, ltz = -0.2)
			cmds.select( self.EdificioName)
Exemplo n.º 14
0
	def create(self):
			
		#building type number 1
		if(self.buildingType == 0):
			cmds.polyCube(w = self.width, d = self.depth, h = self.height, n =  str(self.buildingName))
			
		#building type number 2	
		elif(self.buildingType == 1):
		
			cmds.polyCube(w = self.width, d = self.depth, h = self.height, n =  str(self.buildingName))
			
			#random number of upward extrusions
			for i in range(0, random.randrange(0,3)):
				cmds.polyExtrudeFacet(str(self.buildingName) + ".f[1]", kft = False, ls = (0.8, 0.8, 0))
				cmds.polyExtrudeFacet(str(self.buildingName) + ".f[1]", kft = False, ltz = 30)	
			
		#building type number 3	
		else:
			cmds.polyCube(w = self.width, d = self.depth, h = self.height, sx = self.xDiv, sy = self.yDiv, sz = self.zDiv, n = str(self.buildingName))			
			
			sides = []
			
			#select everything except the top and bottom of the building
			for i in range(0, 8):
				if(i != 1 and i != 3):
					sides.append(str(self.buildingName) + ".f[" + str(self.xDiv * self.yDiv * i) + ":" + str((self.xDiv * self.yDiv * (i+1)) - 1) + "]")
			
			#extrude the faces to create windows
			cmds.polyExtrudeFacet(sides[0], sides[1], sides[2], sides[3], sides[4], sides[5], kft = False, ls = (0.8, 0.8, 0))
			windows = cmds.ls(sl = True)
			cmds.polyExtrudeFacet(windows[1], windows[2], windows[3], kft = False, ltz = -0.2)
			cmds.select( self.buildingName)
Exemplo n.º 15
0
def makeGear(teeth = 10, length = 0.5):
    '''
    this function will create a gear according to specified number of teeth and length
    :param teeth: number of teeth that gear has
    :param length: number of teeth length
    :return: 1.transform node 2. meshconstructor 3. extrudeNode
    '''
    removeGear()
    spin = teeth * 2
    #total side face number = teeth number * 2
    transform, constructor = cmds.polyPipe(subdivisionsAxis=spin, name='Gear')

    ##calculate sideFaceID from spin*2 to spin*3 at intervals of one
    faceNum = range(spin * 2, spin * 3, 2)


    ##clean everySelection
    cmds.select(clear=True)
    for face in faceNum:
        print face
        ##select target faces based of sideFaceID
        cmds.select("%s.f[%s]" % (transform, face), add=True) or []
    ##set  localTranslateZ flag to make the length of gear
    extrudeAttr = cmds.polyExtrudeFacet(ltz = length)[0]

    print extrudeAttr
    print transform, constructor
    return  transform,constructor,extrudeAttr
Exemplo n.º 16
0
def changeTeeth(constructor, extrude, teeth=10, length=1):
    # we get the number of spans
    spans = teeth * 2
    #We edit the polyPipe node to change its teeth
    cmds.polyPipe(constructor, edit=True, sa=spans)
    # input components attr allow us to change the extrude node
    sideFaces = range(spans * 2, spans * 3, 2)
    faceNames = []
    for face in sideFaces:
        faceName = 'f[%s]' % (face)
        faceNames.append(faceName)
    # We define what we want to change where and how many tgrough the setAttr functions
    cmds.setAttr('%s.inputComponents' % (extrude),
                 len(faceNames),
                 *(faceNames),
                 type='componentList')  # expands faceName list
    #We edit the polyExtrude node to change its legth
    cmds.polyExtrudeFacet(extrude, edit=True, ltz=length)
Exemplo n.º 17
0
def changeTeeth(constructor, extrude, teeth=10, length=0.3):
    spans = teeth * 2

    cmds.polyPipe(constructor, edit=True, subdivisionsAxis=spans)

    sideFaces = range(spans * 2, spans * 3, 2)
    faceNames = []

    for face in sideFaces:
        faceName = 'f[%s]' % (face)
        faceNames.append(faceName)

    cmds.setAttr('%s.inputComponents' % (extrude),
                 len(faceNames),
                 *faceNames,
                 type="componentList")

    cmds.polyExtrudeFacet(extrude, edit=True, ltz=length)
Exemplo n.º 18
0
    def makeTeeth(self, teeth=10, length=0.3):
        mc.select(clear=True)
        faces = self.getTeethFaces(teeth)

        for face in faces:
            mc.select('%s.%s' % (self.transform, face), add=True)

        self.extrude = mc.polyExtrudeFacet(localTranslateZ=length)[0]
        mc.select(clear=True)
Exemplo n.º 19
0
def flatTop(_top):
    edge = random.choice([True, False])
    edgeHeight = random.uniform(0.1, 0.5)
    edgeWidth = random.uniform(0.7, 0.95)
    boxSizeX = random.uniform(0.2, 0.8)
    boxSizeY = random.uniform(0.2, 0.8)
    boxSizeZ = random.uniform(0.2, 0.8)

    if edge == True:
        cmds.polyExtrudeFacet(_top, translateY=edgeHeight)
        cmds.polyExtrudeFacet(_top,
                              localScale=(edgeWidth, edgeWidth, edgeWidth))
        cmds.polyExtrudeFacet(_top, translateY=(-1 * edgeHeight))

    else:
        cmds.polyExtrudeFacet(_top, localScale=(boxSizeX, boxSizeY, boxSizeZ))
        cmds.move(boxSizeX / 4, 0, boxSizeZ / 4, _top, r=True)
        cmds.polyExtrudeFacet(_top, translateY=2 * edgeHeight)
Exemplo n.º 20
0
def create_joint(name, side, position):
    groove = True
    j_radius = 0.05
    rotation = [90, 90, 0]
    ctrl_rotation = [90, 0, 0]

    if name in ['elbow', 'knee', 'ankle', 'wrist']:
        j_radius = 0.038
        if name in ['wrist', 'ankle']:
            j_radius = 0.032
            if name == 'wrist':
                rotation = [90, 0, 0]
    elif name == 'shoulder':
        rotation = [90, 0, 0]
        ctrl_rotation = [45, 90, 0]
        if side == r:
            ctrl_rotation = [-45, 90, 0]
    elif name == 'neck':
        groove = False
    elif name == 'waist':
        j_radius = 0.08
        groove = False

    ctrl_crv = cmds.circle(name='{0}_joint_{1}_crv'.format(name, side),
                           radius=1.75 * j_radius)

    cmds.move(position[0], position[1], position[2], ctrl_crv)
    cmds.rotate(ctrl_rotation[0], ctrl_rotation[1], ctrl_rotation[2], ctrl_crv)

    paintCurve(ctrl_crv[0], side)

    joint_geo = cmds.polySphere(name='{0}_joint_{1}_geo'.format(name, side),
                                radius=j_radius,
                                sy=21)

    cmds.move(position[0], position[1], position[2], joint_geo)
    cmds.rotate(rotation[0], rotation[1], rotation[2], joint_geo)

    if groove:
        cmds.polyExtrudeFacet('{0}_joint_{1}_geo.f[180:199]'.format(
            name, side),
                              kft=True,
                              ltz=-0.004)
def make_stair(w_val, h_val):

    stairbody = cmds.polyCube(n='stair_body*', w=w_val, h=0.4, d=2.5)
    cmds.move(0, 0.2, 0)
    cmds.move(0, h_val + 0.2, 0)

    stairfoot = cmds.polyCube(n='stair_foot*', w=0.1, h=h_val, d=0.5)

    cmds.polyExtrudeFacet('stair_foot_.f[1]', kft=True, ltz=0.4)
    cmds.polyExtrudeFacet('stair_foot_.f[8]', kft=True, ltz=2)

    cmds.select(stairfoot)
    cmds.move(w_val / 2 + 0.05, h_val / 2, 1, r=True)
    stairfoot_dup = cmds.duplicate(stairfoot[0])
    cmds.move(-w_val - 0.1, 0, 0, r=True)

    cmds.group(stairbody, stairfoot, stairfoot_dup, name='stairs')
    cmds.move(0, 0, -1.25)
    cmds.makeIdentity(apply=True)
Exemplo n.º 22
0
    def makeTeeth(self, teeth=10, length=0.3):
        # The logic here is exactly the same as in the makeTeeth function we created
        cmds.select(clear=True)
        faces = self.getTeethFaces(teeth)
        for face in faces:
            cmds.select('%s.%s' % (self.transform, face), add=True)

        # Instead of returning a value, lets just store the extrude node onto the class as a class variable
        self.extrude = cmds.polyExtrudeFacet(localTranslateZ=length)[0]
        cmds.select(clear=True)
Exemplo n.º 23
0
def branchMesh(branchName, branchBark, branchNode, branchParent):
    
    #setup new cylinder for each branch
    jointPosWorld = cmds.joint(branchParent, a=True, query=True, p=True)
    cmds.polySphere(r=0.5)
    cmds.move(jointPosWorld[0],jointPosWorld[1], jointPosWorld[2])
    
    cmds.polyCylinder(n=branchBark, sx=20, sy=0, sz=0, h=8, r = 2)
    cmds.move(8/2, y=True)
    cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0)
    cmds.select( d=True )
    for k in range(20): 
        cmds.select(branchBark+'.f[' + (str(k)) + ']', add=True)
    cmds.select(branchBark+'.f[21]', add=True)
    cmds.delete(s=True)
    
    cmds.move(0,0,0, branchBark+".scalePivot",branchBark+".rotatePivot", absolute=True)
    
    cmds.select(d=True)
    cmds.select(branchBark)
    cmds.move(jointPosWorld[0],jointPosWorld[1], jointPosWorld[2])    
    
    #aims cylinder face at next node position, then rotates so extrusion with ltz can be performed
    cmds.aimConstraint( branchNode, branchBark )
    cmds.aimConstraint( branchNode, branchBark, rm=True)
    cmds.select(branchBark)
    cmds.rotate('90deg', rotateZ=True, os=True, r=True)
    cmds.scale(0.25,0.25,0.25)
    
    rotationVal=cmds.joint(branchName, query=True,ax=True, ay=True, az=True)
    
    jointPosWorld = cmds.joint(branchName, a=True, query=True, p=True)
    jointPosRelative = cmds.joint(branchName, r=True, query=True, p=True)
    
    cmds.move(jointPosWorld[0], jointPosWorld[1], jointPosWorld[2], branchBark+'.scalePivot',branchBark+'.rotatePivot', absolute=True)
    cmds.select(branchBark+'.f[0]')
    
    localZ = math.sqrt((math.pow(jointPosRelative[0], 2)) + (math.pow(jointPosRelative[1], 2)) + (math.pow(jointPosRelative[2], 2)))
    
    cmds.polyExtrudeFacet(lrx = rotationVal[0], ltx = 0, lty = 0, ltz = localZ)
   
    cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0)
    cmds.select(branchBark+'.f[0]', d=True)
Exemplo n.º 24
0
def blueprintIKArrow():
    """ Arrow geo creation """
    arrow = cmds.polyCube(name='blueprint_ikArrow',
                          width=5,
                          height=1,
                          subdivisionsX=2,
                          subdivisionsY=2,
                          axis=(0, 1, 0))
    cmds.select(arrow)
    cmds.select('blueprint_ikArrow.vtx[1]', 'blueprint_ikArrow.vtx[4]',
                'blueprint_ikArrow.vtx[7]', 'blueprint_ikArrow.vtx[10]',
                'blueprint_ikArrow.vtx[13]', 'blueprint_ikArrow.vtx[16]')
    cmds.move(2.15,
              0,
              0,
              relative=True,
              objectSpace=True,
              worldSpaceDistance=True)
    cmds.select('blueprint_ikArrow.f[5]', 'blueprint_ikArrow.f[11]')
    cmds.polyExtrudeFacet(pivotX=2.325000048)
    cmds.setAttr('polyExtrudeFace1.localTranslate', 0, 0, 0.65, type='double3')
    cmds.select('blueprint_ikArrow.vtx[5]', 'blueprint_ikArrow.vtx[14]')
    cmds.move(1.15,
              0,
              0,
              relative=True,
              objectSpace=True,
              worldSpaceDistance=True)
    cmds.select('blueprint_ikArrow.vtx[2]', 'blueprint_ikArrow.vtx[8]',
                'blueprint_ikArrow.vtx[11]', 'blueprint_ikArrow.vtx[17]')
    cmds.move(0.648,
              0,
              0,
              relative=True,
              objectSpace=True,
              worldSpaceDistance=True)
    """ Create and assign shader """
    shader = cmds.shadingNode('lambert', name='bp_red', asShader=True)
    cmds.select(arrow)
    cmds.hyperShade(assign=shader)
    cmds.setAttr(shader + '.color', 1, 0, 0, type='double3')
    """ Delete history """
    cmds.delete(constructionHistory=True)
    def changeGear(self, teeth = 5, length = 0.2):
        spin = teeth * 2
        ##use edit flag to change target meshNode(constructor)
        cmds.polyPipe(self.constructor, edit=True, subdivisionsAxis=spin)
        faceNum = range(spin * 2, spin * 3, 2)

        cmds.select(clear=True)

        newFaceList = []
        for face in faceNum:
            # build a new extrudeFaceList to upgrade the Node
            newFaceList.append("f[%s]" % (face))
        ##ust need to edit the current extrude attr
        print newFaceList;
        ##use setAttr to specify the new list of extrude faces
        cmds.setAttr("%s.inputComponents" % (self.extrudeNode), len(newFaceList), *newFaceList, type='componentList')
        ##it seems can use cmds.xxxnode(edit = True) to change it's flag value
        cmds.polyExtrudeFacet(self.extrudeNode, edit=True, ltz=length)
        return 0
Exemplo n.º 26
0
def changeTeeth(constructor, extrude, teeth=10, length=0.3):
    spans = teeth * 2

    #edit=True is important. taking the existing node and change that.
    cmds.polyPipe(constructor, edit=True, subdivisionsAxis=spans)

    sideFaces = range(spans * 2, spans * 3, 2)
    faceNames = []

    for face in sideFaces:
        facename = "f[%s]" % (face)
        faceNames.append(facename)

    #note: *faceNames -> the `*` means expanding the list into individual arguements
    cmds.setAttr('%s.inputComponents' % (extrude),
                 len(faceNames),
                 *faceNames,
                 type="componentList")
    cmds.polyExtrudeFacet(extrude, edit=True, ltz=length)
Exemplo n.º 27
0
def extrude_building(building=None, height=None):
    """
    Given an object will extrude it upwards
    """

    building_face = '{}.f[0]'.format(building)

    if not height:
        building_scale = math.ceil(
            cmds.polyEvaluate(building_face, worldArea=True) / 1000000)
        if building_scale > 12:
            building_scale = 12

        num_stories = math.floor(random.uniform(1, 3)) * building_scale

        height = 450 * num_stories

    cmds.polyExtrudeFacet(building_face, kft=True, ltz=height, sma=0)
    cmds.polyNormalPerVertex(building, ufn=True)
Exemplo n.º 28
0
def changeTeeth(constructor, extrudeFaces, teeth=10, length=0.3):
    spans = teeth * 2
    # use polypipe with the poly pipe that you already have. use edit flag so it knows to edit the existing one instead of creating a new one
    cmds.polyPipe(constructor, edit=True, subdivisionsAxis=spans)
    sideFaces = range(spans * 2, spans * 3, 2)
    faceNames = []

    for face in sideFaces:
        faceName = 'f[%s]' % (face)
        faceNames.append(faceName)

    # print faceNames
    # get the length of the faceNames list, give it to setAttr(), get list of all the faces to use: expand the face names list so each one will be a parameter
    cmds.setAttr('%s.inputComponents' % (extrudeFaces),
                 len(faceNames),
                 *faceNames,
                 type="componentList")
    cmds.polyExtrudeFacet(extrudeFaces, edit=True,
                          ltz=length)  # localTranslateZ shorthand
Exemplo n.º 29
0
    def addTrunkMesh(self):

        for curve in self.allBranchCurves:

            #Names trunk
            startIdx = len(self.name) + len("_curve_")
            trunkName = self.name + "_trunk_" + curve["name"][startIdx:]

            #Creates cylinder and moves it to the origin pt
            cmds.polyCylinder(name=trunkName,
                              subdivisionsX=20,
                              subdivisionsY=1,
                              r=curve["baseRad"])
            cmds.move(-1,
                      trunkName + ".scalePivot",
                      trunkName + ".rotatePivot",
                      moveY=True,
                      relative=True)

            #move polygon to start and align with normal
            cmds.select(clear=True)
            cmds.select(trunkName, tgl=True)
            cmds.select(curve["name"], add=True)
            cmds.pathAnimation(follow=True,
                               followAxis='y',
                               upAxis='z',
                               startTimeU=True)

            #Selects the face to scale and extrude
            cmds.select(clear=True)
            cmds.select(trunkName + ".f[26]")

            #get Scale of decreased radius
            scale = [curve["tipRad"] / curve["baseRad"] for i in range(3)]

            #extrudes along curve
            cmds.polyExtrudeFacet(inputCurve=curve["name"],
                                  d=1,
                                  localScale=scale)

            cmds.parent(trunkName, self.trunkGroup)
            self.allTrunks.append(trunkName)
 def buildRoof(self):
     cmds.select(clear = True)
     if(self.roofType == 1):
         cmds.polyPlane(w=self.dim[0],h=self.dim[2], sx=1, sy=1, n = 'roof' + str(self.idx))
         cmds.move(self.pos[0], self.dim[1] + 0.0*self.roofHeight, self.pos[2], r=1)
         cmds.select('roof'+str(self.idx)+'.f[1]')
         cmds.polyExtrudeFacet(s=[0.9,1.0,0.9], t=[0.0, self.roofHeight, 0.0])
     else:
         cmds.polyCube(w=self.dim[0], h=self.roofHeight, d=self.dim[2], n = 'roof' + str(self.idx))
         cmds.move(self.pos[0], self.dim[1] + 0.5*self.roofHeight, self.pos[2], r=1)
         if(self.dim[2] < self.dim[0] ):
             cmds.select('roof' + str(self.idx) + '.vtx[2:3]')
             cmds.move(0, 0, -0.5 * self.dim[2], r=1)
             cmds.select('roof' + str(self.idx) + '.vtx[4:5]')
             cmds.move(0, 0, 0.5 * self.dim[2], r=1)
         else:
             cmds.select(['roof' + str(self.idx) + '.vtx[2]', 'roof' + str(self.idx) + '.vtx[4]'])
             cmds.move(0.5 * self.dim[0], 0, 0, r=1)
             cmds.select(['roof' + str(self.idx) + '.vtx[3]', 'roof' + str(self.idx) + '.vtx[5]'])
             cmds.move(-0.5 * self.dim[0], 0, 0, r=1)
	def set_key_extrusion(self, start, end, numExt):
		# create individual constants for this extrusion
		distance = random.uniform(self.minDist, self.maxDist)
		scale = [random.uniform(self.minScale, self.maxScale), \
		 	     random.uniform(self.minScale, self.maxScale), \
				 random.uniform(self.minScale, self.maxScale) \
		]
		# get a random face
		randomFace = self.get_random_face()
		# create extrude node
		cmds.polyExtrudeFacet(randomFace.name, kft=False)
		# get extrusion node
		extrusion = "polyExtrudeFace" + str(numExt)
		# set initial keyframe
		cmds.setKeyframe( extrusion, attribute=['localTranslateZ', 'localScaleX', 'localScaleY', 'localScaleZ'], t=start )
		# set final keyframes
		cmds.setKeyframe( extrusion, attribute='localTranslateZ', v=distance, t=end )
		cmds.setKeyframe( extrusion, attribute='localScaleX', v=scale[0], t=end )
		cmds.setKeyframe( extrusion, attribute='localScaleY', v=scale[1], t=end )
		cmds.setKeyframe( extrusion, attribute='localScaleZ', v=scale[2], t=end )
Exemplo n.º 32
0
    def changeTeeth(self, teeth=10, length=1):
        spans = teeth * 2

        cmds.polyPipe(self.constructor, edit=True, subdivisionsAxis=spans)

        sideFaces = range(spans * 2, spans * 3, 2)
        faceNames = []

        for face in sideFaces:
            faceName = 'f[%s]' % (face)
            faceNames.append(faceName)
        #expend list instead of give list,
        cmds.setAttr('%s.inputComponents' % (self.extrude),
                     len(faceNames),
                     *faceNames,
                     type="componentList")

        cmds.polyExtrudeFacet(self.extrude, edit=True, localTranslateZ=length)

        cmds.select(clear=True)
Exemplo n.º 33
0
def honeycomb(xbound, zbound, flat, buildCity):
	dx = 0
	indentOn = False #start 0.867 ahead
	cellnum = 0
	while (dx < xbound):
		dz = 0
		if(indentOn):
			dz = 0.867
		while (dz < zbound):
			cellname = "cell" + "%04d"%cellnum
			randomheight = 0
			raiseMe = False
			if not flat:
				randomheight = .1 - (0.2 * random.random())
			if buildCity:
				if xbound/2 - xbound/10 < dx and dx < xbound/2 + xbound/10 and zbound/2 - zbound/10 < dz and dz < zbound/2 + zbound/10:
					raiseMe = True
					randombuildingheight = 20 - (10 * random.random())
				
			cmds.polyCylinder(name = cellname, ax=[0,1,0], radius=1, height=1, sx=6, sy=1, sz=0)
			if raiseMe:
				cmds.move(0, randombuildingheight, 0, cellname+'.f[7]', r=True)
			else:
				cmds.move(0, randomheight, 0, cellname+'.f[7]', r=True)
			cmds.polyExtrudeFacet(cellname+'.f[7]', kft=False, s=(0.896415,0.896415,0.896415), divisions = 3)
			cmds.polyExtrudeFacet(cellname+'.f[7]', kft=False, ty=-0.15636, divisions=3)
			cmds.select(cellname)
			cmds.polyBevel(offset = 0.7, offsetAsFraction = 1, autoFit = 1, segments = 1, worldSpace = 1, uvAssignment = 0, fillNgons = 1, mergeVertices = 1, mergeVertexTolerance = 0.0001,  miteringAngle = 180, angleTolerance = 180, ch = 1)

			cmds.move(dx, 0, dz)
			
			print "cylinder " + cellname + " location = dx: " + str(dx) + ", dz: " + str(dz)
			
			dz+=1.729
			cellnum += 1
		dx += 1.5
		indentOn = not indentOn
		
	cmds.select([node for node in cmds.ls() if 'cell' in node and 'Shape' not in node])
	cmds.group(name='honeycomb')
	cmds.move(-xbound/2, 0, -zbound/2, 'honeycomb')
Exemplo n.º 34
0
def generateGrass(numberOfGrassObjects):
    grassObjects = []
    for i in range(numberOfGrassObjects):
        # Start by creating a new object for the grass to be built with
        grassObjects.append(cmds.polyCube(w=1, h=0.01, d=1))
        # Move the object into a position accordingly
        if (i != 0): moveObject(i)

        # Make the grass do grass things...
        grassSegments = random.randint(3, 7)
        currentName = grassObjects[len(grassObjects) - 1][0]
        cmds.select('{}.f[{}]'.format(currentName, 1))
        # Randomly extrude and position the grass
        for i in range(grassSegments):
            translateList = [
                random.uniform(-0.5, 0.5),
                random.uniform(-0.5, 0.5),
                random.uniform(0.5, 1.5)
            ]
            cmds.polyExtrudeFacet(localTranslate=translateList,
                                  localScale=(0.7, 0.7, 0.7))
Exemplo n.º 35
0
    def modGear(self, teeth=10, length=0.3):

        spans = teeth * 2

        cmds.polyPipe(self.constructor, edit=1, subdivisionsAxis=spans)

        sideFacesNumber = range(spans*2, spans*3, 2)

        faceNames = []

        for face in sideFacesNumber:
            faceName = 'f[%s]' % (face)

            faceNames.append(faceName)

        cmds.setAttr('%s.inputComponents' % (self.extrude),
                     len(faceNames),
                     *faceNames,
                     type="componentList")

        cmds.polyExtrudeFacet(self.extrude, edit=1, ltz=length)
Exemplo n.º 36
0
    def modify(self, teeth=15, length=0.1):
        """
        This function will modify existing gear's profile
        :param teeth: number of teeth to create
        :param length: how long is the extrusion of the teeth
        """
        spans = teeth * 2
        cmds.polyPipe(self.constructor, edit=True, subdivisionsAxis=spans)

        side_faces = range(spans * 2, spans * 3, 2)
        face_names = []

        for face in side_faces:
            name = "f[%s]" % face
            face_names.append(name)

        cmds.setAttr('%s.inputComponents' % self.extrude,
                     len(face_names),
                     *face_names,
                     type="componentList")
        cmds.polyExtrudeFacet(self.extrude, edit=True, ltz=length)
Exemplo n.º 37
0
def makeBuilding(face, levels, height, sidewalkHeight):
    hl = height/levels
    type = random.choice(['indent', 'rim','well'])
    makeSidewalk(face, sidewalkHeight)
    for i in range(1, levels):
        dHeight = height/(2*i)
        #extrude in
        extrude1 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
        cmds.setAttr(extrude1+".localScaleX", 0.5+(0.5*random.random())); 
        cmds.setAttr(extrude1+".localScaleY", 0.5+(0.5*random.random()));
        #extrude again and translate up
        extrude2 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
        cmds.setAttr(extrude2+".localTranslateZ",  dHeight)
        if type == 'indent':
            makeIndent(face, hl/10.0)
        if type == 'rim':
            makeRim(face, hl/10.0)
        if type == 'well':
            makeWell(face, hl/30.0)
        if(i == levels-1 and random.random() > 0.6):
            makeAntenna(face, dHeight/2.0)
Exemplo n.º 38
0
def createRack():
    rgb = cmds.colorSliderGrp('rackColour', q=True, rgbValue=True)

    # name
    nsTmp = "Rack" + str(rnd.randint(1000, 9999))

    cmds.select(clear=True)
    cmds.namespace(add=nsTmp)
    cmds.namespace(set=nsTmp)

    # base
    rack = cmds.polyCube(h=0.6, w=1.5, d=6, sz=24)

    # extrude teeth
    for i in range(24):
        if (i % 2 == 1):
            cmds.select(rack[0] + ".f[" + str(i) + "]")
            cmds.polyExtrudeFacet(ltz=0.3)
            cmds.polyExtrudeFacet(ltz=0.3)
            cmds.polyMoveFacet(lsx=0.1)

    tmp = cmds.polyCube(h=0.6, w=1.5, d=2)
    cmds.move(-3.753, moveZ=True)
    rack = cmds.polyCBoolOp(rack, tmp, op=2)
    tmp = cmds.polyCube(h=0.6, w=1.5, d=2)

    # add material
    myShader = cmds.shadingNode('lambert', asShader=True, name="blckMat")
    cmds.setAttr(nsTmp + ":blckMat.color",
                 rgb[0],
                 rgb[1],
                 rgb[2],
                 type='double3')

    cmds.polyUnite((nsTmp + ":*"), n=nsTmp, ch=False)
    cmds.move(0.4, moveY=True, a=True)
    cmds.delete(ch=True)

    cmds.hyperShade(assign=(nsTmp + ":blckMat"))
    cmds.namespace(removeNamespace=":" + nsTmp, mergeNamespaceWithParent=True)
Exemplo n.º 39
0
def createGear(teeth=10, length=0.3):
    """
    This function will create a gear with the given parameters
    Args:
        teeth: The number of teeth to create
        length: The length of the teeth

    Returns:
        A tuple of the transform, constructor and extrude node
    """
    # Above this is the docstring enclosed in """ """ that documents the function
    # This helps for people who want to use the function without needing to read the code

    # Teeth are every alternate face, so we double the number of teeth to get the number of spans required
    spans = teeth * 2

    # the polyPipe command will create a polygon pipe
    # the subdivisionsAxis will say how many divisions we'll have along it's length
    # It returns a list of [transform, constructor]
    # Instead of getting a list and then extracting it's members, we can directly expand it to variables like here
    # The transform is the name of the node created and the constructor is the node that creates the pipe and controls its parameters
    transform, constructor = cmds.polyPipe(subdivisionsAxis=spans)

    # We need to select all the faces that will become the teeth.
    # We use the range function to start at span times 2 because that's where the side faces start from
    # Then we continue until span times 3 because that's where it ends
    # The third optional parameter is how big the steps we will take are.
    # So we'll be taking 2 steps instead of 1. e.g. 0, 2, 4, 6, 8
    # This will return a list of numbers
    sideFaces = range(spans * 2, spans * 3, 2)

    # Now we need to clear the selection because we'll be adding each face to it
    cmds.select(clear=True)

    # We'll loop through all the faces in the list of sideFaces
    for face in sideFaces:
        # We'll add to the selection
        # The '%s.f[%s]' notation looks odd but it expands to something like pPipe1.f[20]
        # Which tells it to select the 20th face of the pPipe1 object
        # The %s notation means it is a placeholder for the value of the variables after the %
        cmds.select('%s.f[%s]' % (transform, face), add=True)

    # Now we extrude the selected faces by the given length
    # This gives us back the value of the extrude node inside a list
    extrude = cmds.polyExtrudeFacet(localTranslateZ=length)[0]

    # Finally we return a tuple of (transform, constructor, extrude)
    # A tuple is similar to a list but cannot be modified.
    # Notice that we don't need to provide the parenthesis that define a tuple, just adding  the comma here will do it for us

    # Here the transform is our gear node, the constructor is the node that creates the original pipe and the extrude is the node that extrudes the faces
    return transform, constructor, extrude
    def CreateLeaves(self, height, minSize, maxSize):
        leafBase = cmds.polyPrimitive(r=1, l=1, pt=0)[0]
        cmds.move(height, y=True)
        cmds.polyChipOff(dup=False, kft=False)
        cmds.polyChipOff(dup=False, kft=True, ltz=0.08, ran=1.0)
        cmds.polyExtrudeFacet(ltz=0.6)
        cmds.polySmooth()
        cmds.polySeparate()

        cmds.xform(cp=True)

        for leaf in cmds.ls(sl=True):
            leafScale = round(random.uniform(minSize, maxSize), 3)
            cmds.select(leaf)
            cmds.polySoftEdge(a=0, name=leaf)
            cmds.scale(leafScale, leafScale, leafScale)
            leafPosition = cmds.xform(leaf, q=True, rp=True, ws=True)
            leafPosition[1] = height + 0.5 * (height - leafPosition[1])
            cmds.xform(leaf, t=leafPosition, ws=True)
            self.SetRandomLeafColor(leaf)

        return leafBase
Exemplo n.º 41
0
    def makeBuilding(self, face, levels, height, sidewalkHeight):
        """
        Creates a building frm a supplied polygon face.

        @param face string
            The face from which to create the building.
        @param levels float
            The number of levels to extrude.
        @param height float
            The total height of the building.
        @param sidewalkHeight float
            The height of the sidewalk.
        """
        hl = height/levels
        presetType = random.choice(['indent', 'rim','well'])
        self.makeSidewalk(face, sidewalkHeight)
        for i in range(1, levels):
            dHeight = height/(2*i)

            # Extrude in.
            extrude1 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
            cmds.setAttr(extrude1+".localScaleX", 0.5+(0.5*random.random())); 
            cmds.setAttr(extrude1+".localScaleY", 0.5+(0.5*random.random()));

            # Extrude again and translate up.
            extrude2 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
            cmds.setAttr(extrude2+".localTranslateZ",  dHeight)

            # Add a preset.
            if presetType == 'indent':
                self.makeIndent(face, hl/10.0)
            if presetType == 'rim':
                self.makeRim(face, hl/10.0)
            if presetType == 'well':
                self.makeWell(face, hl/30.0)

            # If we're at the top level, add an antenna.
            if(i == levels-1 and random.random() > ANTENNA_CHANCE):
                self.makeAntenna(face, dHeight/2.0)
Exemplo n.º 42
0
def extrudeList(face, extrudes, heights, scales):
    """
    Given a face and a list of extrusions, performs the extrudes in order,
    applying the given heights and scales. NOTE: The height for down is a
    positive number.

    @param face string
        The start face to extrude.
    @param extrudes list
        A list containing extrude keywords to apply to face.
    @param heights list
        A list of height values corresponding to 'up' or 'down' extrusion 
        keywords.
    @param scales list
        A list of scale values corresponding to 'out' and 'in' keywords.
    """
    if len(extrudes) != len(heights) + len(scales):
        return
    heightIndex = 0
    scaleIndex = 0
    for e in extrudes:
        if e in ["up", "down", "antenna"]:
            h = heights[heightIndex]
            if e == "down":
                h = -1.0*h
            extrude1 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
            cmds.setAttr(extrude1+".localTranslateZ", h)
            if e == "antenna":
                cmds.setAttr(extrude1+".localScaleX", 0.5)
                cmds.setAttr(extrude1+".localScaleY", 0.5)
            heightIndex += 1
        elif e in ["in", "out"]:
            s = scales[scaleIndex]
            extrude1 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
            cmds.setAttr(extrude1+".localScaleX", s)
            cmds.setAttr(extrude1+".localScaleY", s)
            scaleIndex += 1
        else:
            print "e was not a valid extrude type"
Exemplo n.º 43
0
def modificar_tuerca(constructor, extruded_faces, teeth=10, length=0.3):
    spans = teeth * 2
    
    cmds.polyPipe(constructor, edit=True, subdivisionsAxis=spans)
    
    side_faces = range(spans*2, spans*3, 2)
    face_names = []
    
    for face in side_faces:
        face_name = 'f[%s]' % (face)
        face_names.append(face_name)
        
    print extruded_faces
    # Cambia el numero de dientes
    cmds.setAttr('%s.inputComponents' % extruded_faces[0], 
                 len(face_names),
                 *face_names,
                 type="componentList")
                 
    # Cambiar la longitud de los dientes
    cmds.polyExtrudeFacet(extruded_faces, edit=True, ltz=length)
     
	def change_teeth(self, teeth=10, length=0.3):
		"""
		Allows you to change the number of teeth and length of an existing gear mesh
		Args:
			teeth: How many teeth the gear will have
			length: How long each teeth will be
		"""
		subdivisions_axis = teeth * 2
		cmds.polyPipe(self.poly_pipe_constructor, edit=True, subdivisionsAxis=subdivisions_axis)
		side_faces = range(subdivisions_axis * 2, subdivisions_axis * 3, 2)
		face_names = []

		for face in side_faces:
			face_name = "f[%s]" % face
			face_names.append(face_name)
		# print("face_names: " + str(face_names))  # the faces that should be extruded in the modified gear

		# setAttr has different parameters depending on the type of data we're trying to set https://help.autodesk.com/cloudhelp/2018/CHS/Maya-Tech-Docs/CommandsPython/setAttr.html
		# In this case we want to set a list of face components on the extrude node's inputComponents attribute
		# The asterisk unpacks the list and passes the elements as individual arguments
		cmds.setAttr("%s.inputComponents" % self.extrude, len(face_names), *face_names, type="componentList")
		cmds.polyExtrudeFacet(self.extrude, edit=True, localTranslateZ=length)
    def changeGear(self, teeth=5, length=0.2):
        spin = teeth * 2
        ##use edit flag to change target meshNode(constructor)
        cmds.polyPipe(self.constructor, edit=True, subdivisionsAxis=spin)
        faceNum = range(spin * 2, spin * 3, 2)

        cmds.select(clear=True)

        newFaceList = []
        for face in faceNum:
            # build a new extrudeFaceList to upgrade the Node
            newFaceList.append("f[%s]" % (face))
        ##ust need to edit the current extrude attr
        print newFaceList
        ##use setAttr to specify the new list of extrude faces
        cmds.setAttr("%s.inputComponents" % (self.extrudeNode),
                     len(newFaceList),
                     *newFaceList,
                     type='componentList')
        ##it seems can use cmds.xxxnode(edit = True) to change it's flag value
        cmds.polyExtrudeFacet(self.extrudeNode, edit=True, ltz=length)
        return 0
Exemplo n.º 46
0
    def changeTeeth(self, teeth=10, length=0.3):
        spans = teeth * 2

        # This sets the number of subdivision axes i.e. # of gears
        cmds.polyPipe(self.constructor, edit=True, subdivisionsAxis=spans)

        # This stores the names/#s of the faces to select
        sideFaces = range(spans * 2, spans * 3, 2)
        faceNames = []

        for face in sideFaces:
            faceName = 'f[%s]' % (face)
            faceNames.append(faceName)

        # This extrudes only the faces we want extruded, otherwise Maya doesn't know which ones
        cmds.setAttr('%s.inputComponents' % (self.extrude),
                     len(faceNames),
                     *faceNames,
                     type="componentList")

        # This actively changes the extrusion, i.e. changes the extrusion value on the z axis
        cmds.polyExtrudeFacet(self.extrude, edit=True, ltz=length)
Exemplo n.º 47
0
    def createGear(self, teeth=10, length=0.3):
        spans = teeth * 2

        self.transform, self.constructor = cmds.polyPipe(
            subdivisionsAxis=spans)
        sideFaces = range(spans * 2, spans * 3, 2)

        cmds.select(clear=True)

        for face in sideFaces:
            cmds.select('%s.f[%s]' % (self.transform, face), add=True)

        self.extrude = cmds.polyExtrudeFacet(localTranslateZ=length)[0]
Exemplo n.º 48
0
def makeProxyGeo():
    """This function creates a default proxy geo if the user does not provides one """

    # Create a cube
    geo = cmds.polyCube(name="TreadProxyGeo", width=5, height=.5, depth=1, sx=5)[0]
    faces = [0,2,4,11,13]
    cmds.select(clear=True)
    
    # Select specific faces to make desired shape
    for f in faces:
        cmds.select("%s.f[%s]"%(geo,f), add=True)

    # Extrude those faces 
    cmds.polyExtrudeFacet(thickness=.5, offset=.1)

    # Select the geo itself
    cmds.select(geo, r=True)

    # Delete its history
    cmds.DeleteHistory()

    # Return reference to the geo
    return geo
Exemplo n.º 49
0
  def generate(cls, *args):
    components = []
    width = cmds.intSliderGrp(cls.get_prefix() + Labels["radius_label"], query=True, value=True)
    height = cmds.intSliderGrp(cls.get_prefix() + Labels["height_label"], query=True, value=True)
    subdivs = cmds.intSliderGrp(cls.get_prefix() + Labels["subdivs_label"], query=True, value=True)
    rgb = cmds.colorSliderGrp(cls.get_prefix() + Labels["color_label"], query=True, rgbValue=True)
    wheel_radius = width * Constants["wheel_radius_unit"]
    wheel_height = height * Constants["wheel_height_unit"]
    
    wheel_component = cmds.polyCylinder(name=get_unique_name(cls.get_prefix(), "cylender"), sx=subdivs, h=wheel_height, r=wheel_radius)
    wheel_extrusion_faces = []
    cmds.select(r=True)

    for i in range(0, subdivs):
      if i % 2 == 1:
        facet_title = wheel_component[0] + ".f[" + str(i) + "]"
        wheel_extrusion_faces.append(facet_title)

    cmds.polyExtrudeFacet(wheel_extrusion_faces, ltz=Constants["wheel_ridge_depth"])
    shader = cmds.shadingNode('blinn', asShader=True, name=get_unique_name(cls.get_prefix(),"mat"))
    cmds.setAttr(shader + ".color", rgb[0],rgb[1],rgb[2], type='double3')
    cmds.select(wheel_component[0], r=True)
    cmds.hyperShade(assign=shader)
Exemplo n.º 50
0
 def build(self, file):
     print "start to build"
     osm = pooper.data()
     osm.castData(file)
     osm.freezePoints(100000)
     ct = 0
     pro = self.progressBar(len(osm.buildings), 100)
     for key, val in osm.buildings.items():
         if ct in pro:
             self.valueUpdated.emit(pro[ct])
         ct += 1
         if val.type and val.type.startswith("build"):
             tPoint = self.ps2tuple(osm.points, val.pID)
             if len(tPoint) <= 2: continue
             bid = "b" + str(key)
             cmds.polyCreateFacet(p=tPoint, n=bid)
             if cmds.polyInfo(fn=True)[0].split(' ')[-2][0] == "-":
                 cmds.polyNormal(nm=0)
             if val.height:
                 cmds.select(bid)
                 cmds.xform(cp=True)
                 cmds.polyExtrudeFacet(kft=False, ltz=val.height)
         elif len(val.pID) >= 3 and val.pID[0] == val.pID[-1]:
             tPoint = self.ps2tuple(osm.points, val.pID)
             if len(tPoint) <= 2: continue
             bid = "b" + str(key)
             cmds.polyCreateFacet(p=tPoint, n=bid)
             if cmds.polyInfo(fn=True)[0].split(' ')[-2][0] == "-":
                 cmds.polyNormal(nm=0)
             if val.height:
                 cmds.select(bid)
                 cmds.xform(cp=True)
                 cmds.polyExtrudeFacet(kft=False, ltz=val.height)
         elif "boundary" in val.tags:
             tPoint = self.ps2tuple(osm.points, val.pID)
             if len(tPoint) <= 2: continue
             cmds.curve(p=tPoint, d=1)
Exemplo n.º 51
0
def extrudeList(face, extrudes, heights, scales):
    if(len(extrudes) != len(heights) + len(scales)):
        return
    i = 0 #for heights
    j = 0 #for scales
    for e in extrudes:
        if(e == "up" or e == "down" or e == "antenna"):
            h = heights[i]
            if(e == "down"):
                h = -1.0*h
            extrude1 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
            cmds.setAttr(extrude1+".localTranslateZ", h)
            if(e == "antenna"):
                cmds.setAttr(extrude1+".localScaleX", 0.5)
                cmds.setAttr(extrude1+".localScaleY", 0.5)
            i += 1
        elif(e == "in" or e == "out"):
            s = scales[j]
            extrude1 = cmds.polyExtrudeFacet(face, ch=1, kft=0)[0]
            cmds.setAttr(extrude1+".localScaleX", s)
            cmds.setAttr(extrude1+".localScaleY", s)
            j += 1
        else:
            print "e was not a valid extrude type"
def generateGrass(numberOfGrassObjects):
    # Create list to hold the objects within the grass to be created
    grassObjects = []
    # Make a grass object for each part
    for i in range(numberOfGrassObjects):
        # Start by creating a new object for the grass to be built with
        grassObjects.append(cmds.polyCube(w=1, h=0.01, d=1))
        # Move the object into a position accordingly
        if (i != 0): moveGrassObject(i)

        # Make the grass do grass things...
        grassSegments = random.randint(3, 7)
        currentName = grassObjects[len(grassObjects) - 1][0]
        cmds.select('{}.f[{}]'.format(currentName, 1))
        # Randomly extrude and position the grass
        for i in range(grassSegments):
            translateList = [
                random.uniform(-0.5, 0.5),
                random.uniform(-0.5, 0.5),
                random.uniform(0.5, 1.5)
            ]
            cmds.polyExtrudeFacet(localTranslate=translateList,
                                  localScale=(0.7, 0.7, 0.7))

    # Now that we have all of the grass that we need generated we can now group it all and return it
    for grass in grassObjects:
        cmds.select(grass[0], tgl=True)

    grassGrp = cmds.polyUnite(ch=False)
    cmds.select(grassGrp[0])

    # My smooth brain made the grass way too big, so let's scale it down afterwards and pretend nothing happened, it will be fine
    scaleValue = random.uniform(0.02, 0.1)
    cmds.scale(scaleValue, scaleValue, scaleValue)

    return grassGrp
Exemplo n.º 53
0
    def CreateGear(self, teeth = 10, length = 0.3):
        '''
        Create a gear with the given parameters
        Args:
            teeth: number of teeth
            length: Length of the teeth
        '''
        self.transform, self.node = cmds.polyPipe(subdivisionsAxis = teeth * 2)
        cmds.select(clear =True)

        faces = self.GetTeethFaces(teeth)
        for face in faces:
            cmds.select("%s.%s" % (self.transform, face), add = True)

        self.extrude = cmds.polyExtrudeFacet(localTranslateZ = length)[0]
        cmds.select(clear = True)
Exemplo n.º 54
0
def solidifyObject(object, height=1, divisions=2, history=True):
	"""
	Solidifies given object.

	:param object: Object.
	:type object: str
	:param height: Extrusion height.
	:type height: float
	:param division: Extrusion divisions.
	:type division: float
	:param history: Keep construction history.
	:type history: bool
	"""

	if hasBorderEdges(object):
		transform = getTransform(object)
		vertices = cmds.ls(cmds.polyListComponentConversion(object, toVertex=True), fl=True)

		barycenters = cmds.xform(vertices, q=True, t=True, ws=True)
		barycenter = getAverageVector([(barycenters[i], barycenters[i + 1], barycenters[i + 2]) for i in range(0, len(barycenters), 3)])

		normals = cmds.polyNormalPerVertex(cmds.polyListComponentConversion(object, toVertexFace=True), q=True, xyz=True)
		normals = [(normals[i], normals[i + 1], normals[i + 2]) for i in range(0, len(normals), 3)]
		averageNormal = vectorMatrixMultiplication(normalize(getAverageVector(normals)), cmds.xform(transform, query=True, matrix=True, worldSpace=True))

		facesCount = cmds.polyEvaluate(object, face=True)
		faces = object + ".f[0:" + str(facesCount - 1) + "]"
		extrude = cmds.polyExtrudeFacet(faces, constructionHistory=1, keepFacesTogether=1, divisions=divisions)
		cmds.setAttr(extrude[0] + ".localTranslateZ", height)
		borderEdges = cmds.polyListComponentConversion(faces, te=True, bo=True)
		cmds.polyMapCut(borderEdges)
		uvs = cmds.polyListComponentConversion(object + ".f[0:" + str(facesCount - 1) + "]", toUV=1)
		cmds.polyEditUV(uvs, u=0, v=-5)

		extendedFaces = cmds.ls(faces, fl=True)
		for i in range(divisions):
			adjacentEdges = cmds.polyListComponentConversion(extendedFaces, ff=True, te=True)
			extendedFaces.extend(cmds.ls(cmds.polyListComponentConversion(adjacentEdges, fe=True, tf=True), fl=True))

		borderFaces = list(set(extendedFaces).difference(set(cmds.ls(faces, fl=True))))
		cmds.select(borderFaces)
		cmds.polyAutoProjection(borderFaces, t=barycenter, ry=getAngle((0, 0, 1), averageNormal), rz=getAngle((1, 0, 0), averageNormal))
		uvs = cmds.polyListComponentConversion(borderFaces, toUV=1)
		cmds.polyEditUV(uvs, u=0, v=-5)

		not history and cmds.delete(object, ch=True)
Exemplo n.º 55
0
def createSpeaker():
    """create a speaker shape to be used as a sound visualiser.
	
	return : name of the cylinder created
	"""
    # create cylinder
    speaker = cmds.polyCylinder(h=0.025, r=0.5)
    # extrude to create 'speaker' shape
    cmds.polyExtrudeFacet(speaker[0] + ".f[21]", scale=(0.8, 0.8, 0.8))
    cmds.polyExtrudeFacet(speaker[0] + ".f[21]", scale=(0.5, 0.5, 0.5), translate=(0, -0.2, 0))
    cmds.polyExtrudeFacet(speaker[0] + ".f[21]", translate=(0, 0.1, 0))
    return speaker
Exemplo n.º 56
0
def normalCheck(meshList=[]):
	'''
	Setup normal check properties for a specified list of meshes.
	@param meshList: List of meshes to setup normal check for
	@type meshList: list
	'''
	# Check Mesh List
	meshList = cleanup.getMeshList(meshList)
	if not meshList: return []
	
	# Check Normal Shader
	normalSG = 'normalCheckSG'
	normalShader = 'normalCheckShader'
	if not mc.objExists(normalShader):
		# Create Shader
		normalShader = mc.shadingNode('lambert',asShader=True,n=normalShader)
		normalSG = mc.sets(renderable=True,noSurfaceShader=True,empty=True,name=normalSG)
		mc.connectAttr(normalShader+'.outColor',normalSG+'.surfaceShader',f=True)
		mc.setAttr(normalShader+'.color',0,0,0)
		mc.setAttr(normalShader+'.incandescence',1,0,0)
	
	# Setup Normal Check
	for mesh in meshList:
		
		# Clear selection
		mc.select(cl=True)
		
		# Turn on double sided
		mc.setAttr(mesh+'.doubleSided',1)
		
		# Extrude face
		numFace = mc.polyEvaluate(mesh,f=True)
		polyExtrude = mc.polyExtrudeFacet(mesh+'.f[0:'+str(numFace)+']',ch=1,kft=True,pvt=(0,0,0),divisions=2,twist=0,taper=1,off=0,smoothingAngle=30)
		mm.eval('PolySelectTraverse 1')
		extrudeFaceList = mc.filterExpand(ex=True,sm=34)
		mc.setAttr(polyExtrude[0]+'.localTranslateZ',-0.001)
		
		# Apply shader
		mc.sets(extrudeFaceList,fe=normalSG)
	
	# Set selection
	mc.select(meshList)
	
	# Retrun result
	return meshList
    def makeGear(self, teeth=10,length=0.5):
        self.removeGear(self.name)
        spin = teeth * 2
        # total side face number = teeth number * 2
        transform, constructor = cmds.polyPipe(subdivisionsAxis=spin, name=self.name)

        ##calculate sideFaceID from spin*2 to spin*3 at intervals of one
        faceNum = range(spin * 2, spin * 3, 2)

        ##clean everySelection
        cmds.select(clear=True)
        for face in faceNum:
            print face
            ##select target faces based of sideFaceID
            cmds.select("%s.f[%s]" % (transform, face), add=True) or []
        ##set  localTranslateZ flag to make the length of gear
        extrudeAttr = cmds.polyExtrudeFacet(ltz=length)[0]

        print transform, constructor, extrudeAttr
        self.transform = transform
        self.constructor = constructor
        self.extrudeNode = extrudeAttr
        return  0
Exemplo n.º 58
0
 def createBladeOfGrass(self):
     """ This method creates a blade of grass. """
     
     # random the high of blade
     self.grassHeight = 0.2 * random.randrange ( 6, 10 );
     
     # create the plane of blade
     mc.polyPlane( axis=(0, 0, 0), subdivisionsX=2, subdivisionsY=6, height=4 );
     mc.move( 0, 2, 0 )
     self.currentBlade = mc.ls( sl=True );
     
     # create the form of blade
     mc.displaySmoothness( divisionsU=3, divisionsV=3, pointsWire=16, pointsShaded=4, polygonObject=3 );
     mc.select( self.currentBlade[0] + ".vtx[18:20]", r=True ) ;
     mc.softSelect( softSelectEnabled=True, ssd=20, sud=0.5 );
     mc.scale( 0.1, 1, 1, p=(0, 9.86, 0), r=True );
     mc.softSelect( ssd=8.08, sud=0.5 );
     
     # bend the grass
     bendGrassRandom = 15 * (3.0 - random.random())
     mc.rotate( bendGrassRandom, 0, 0, os=True, r=True, p=(0, 9.18, 0) );
     mc.select( self.currentBlade )
     extrudeFace = mc.polyExtrudeFacet( self.currentBlade[0] + ".f[0:11]", constructionHistory=1, keepFacesTogether=1, pvx=0, pvy=4.84, pvz=0.14, divisions=1, twist=0, taper=1, off=0, thickness=0, smoothingAngle=30 );
     mc.setAttr( extrudeFace[0] + ".localTranslate", 0, 0, 0.05, type='double3' );
     mc.softSelect( softSelectEnabled=False )
     
     # scale the blade
     mc.select( self.currentBlade )
     mc.scale( 1, self.grassHeight, 1, r=True )
     
     # delete history
     maya.mel.eval( "DeleteHistory" )
     
     # change the position
     self.changePositionBlade()
     
     return self.currentBlade
Exemplo n.º 59
0
import maya.cmds as mc
import random

currentObjSel = mc.ls(sl=True, tr=True)
objFaceCnt = mc.polyEvaluate(currentObjSel, f=True)
print objFaceCnt

randnum = random.sample(xrange(0, objFaceCnt), (objFaceCnt))

for value in randnum:
	#print(value)
	
	currentFaceCnt = mc.polyEvaluate(currentObjSel, f=True) #used in the next for loop
	#print currentFaceCnt
	
	extRand = random.uniform(1,3)
	mc.select(currentObjSel[0] + '.f[' + str(value) + ']', r=True)
	mc.polyExtrudeFacet(ltz = extRand, d=2)
	
	for obj in range(1):
		
		newFaceCnt = mc.polyEvaluate(currentObjSel, f=True)
		getFace = newFaceCnt - currentFaceCnt
		print getFace
Exemplo n.º 60
0
 getCurvLen = mc.arclen(curveObj)
 makeCvrLenInt = math.ceil(getCurvLen*.5)#reduces the amount of spans the curve has, this is useful on very long extrusions 
 
 
 makeCircle = mc.circle(n="newCircle",d=1, s=12)
 aCircle = mc.planarSrf(makeCircle[0], n="extruTube", ch=1, d=1, ko=0, rn=0, po=1, nds=3)
 getTesInfo = mc.listConnections(aCircle[1], t="nurbsTessellate")
 mc.setAttr(getTesInfo[0] + ".polygonCount", 1)
 mc.setAttr(getTesInfo[0] + ".polygonType", 1)
 mc.setAttr(getTesInfo[0] + ".format", 0)
 
 
 getCurveCVPos = mc.xform(curveObj + ".cv[0]", ws=True, q=True, translation=True)
 mc.xform(makeCircle[0], ws=True, t=(getCurveCVPos[0], getCurveCVPos[1], getCurveCVPos[2]),ro=(90, 0, 0))#use "ro" to orient the circle to the curve if your extrusion is black
 
 tubes = mc.polyExtrudeFacet(aCircle[0] + ".f[0]", inc=curveObj, d=makeCvrLenInt)
 subCurveCreate = mc.createNode("subCurve", n="subCurve_" + curveObj)
 curveShape = mc.listRelatives(curveObj, s=True)
 
 mc.setAttr(subCurveCreate + ".relative", 1)
 mc.connectAttr(curveShape[0] + ".worldSpace", subCurveCreate + ".inputCurve", f=True)
 mc.connectAttr(subCurveCreate + ".outputCurve", tubes[0] + ".inputProfile", f=True)     
 
 
 mc.setAttr(subCurveCreate + ".maxValue", 0)
 mc.setKeyframe(subCurveCreate, attribute='maxValue', t=[sortedKeyFrameList[0]])
 mc.setAttr(subCurveCreate + ".maxValue", 1)
 mc.setKeyframe(subCurveCreate, attribute='maxValue', t=[sortedKeyFrameList[-1]])
 
 #set the visibility
 mc.setAttr(aCircle[0] + ".visibility", 1)