def polyWire( mesh, gridSize = 0.9, depth = 0.5, extrudeMode = 0 ): # Select the faces pm.select( mesh[ 0 ].f ) # Extrude and scale the faces extrude = pm.polyExtrudeFacet( constructionHistory = True, keepFacesTogether = False, divisions = 1, twist = 0, taper = 1, off = 0 ) pm.PyNode( extrude[ 0 ] ).localScale.set( [ gridSize, gridSize, gridSize ] ) # Delete inner faces pm.delete() pm.select( mesh[ 0 ].f ) # Extrude the faces extrude = pm.polyExtrudeFacet( constructionHistory = True, keepFacesTogether = True, divisions = 1, twist = 0, taper = 1, off = 0 ) if extrudeMode == 0: pm.PyNode( extrude[ 0 ] ).scale.set( [ depth, depth, depth ] ) elif extrudeMode == 1: pm.PyNode( extrude[ 0 ] ).localTranslate.set( [ 0, 0, depth ] ) pm.select( clear = True )
def create_link(self): """ creates a Torus and extrudes half of it To be used as alternative to a provided geometry """ base_chain = pm.polyTorus(radius=self.radius, sr=self.section_radius, tw=0, sx=20, sy=20, ax=(0, 1, 0), ch = 1)[0] if self.extrude is not 0: faces = [] for j in base_chain.vtx: if j.getPosition()[0] > 0: faces.append(j.connectedFaces()) pm.polyExtrudeFacet(faces, translateX=self.extrude) return base_chain
def make_proxy_wheel(obj, wheel_name, cutout=False): tolerance = .5 sel = pm.selected() bb = obj.getBoundingBox() radius = max(bb.depth(), bb.width(), bb.height())/2 height = min(bb.depth(), bb.width(), bb.height()) axis = [0,1,0] if bb.height() - bb.width() > tolerance: # allow for a tolerance of difference axis = [1,0,0] if bb.width() - bb.depth() > tolerance: axis = [0,0,1] #print axis, bb.depth(), bb.width(), bb.height() cylinder = pm.polyCylinder(n=wheel_name, axis=axis, height=height, radius=radius, sc=True) pm.xform(cylinder, t=bb.center()) cylinder_shape = cylinder[0].getShape() bevel_edges = cylinder_shape.e[0:39] pm.polyBevel(bevel_edges, com=0, fraction=0.4, offsetAsFraction=1, autoFit=1, segments=4, worldSpace=1, uvAssignment=0, smoothingAngle=30, fillNgons=1, mergeVertices=1, mergeVertexTolerance=0.0001, miteringAngle=180, angleTolerance=180, ch=1) pm.polyExtrudeFacet(cylinder_shape.f[180:219], ltz=-0.16, lsx=0.2, lsy=0.2) light_faces_indexes = [224, 225, 228, 229, 232, 233, 244, 245, 248, 249, 252, 253] dark_faces = [face for face in cylinder_shape.f[:] if face.index() not in light_faces_indexes] dark_lambert = pm.shadingNode("blinn", n="dark_shader", asShader=True) dark_lambert.color.set([.16, .16, .16]) dark_lambert.eccentricity.set(0.5) dark_lambert.specularColor.set([.16, .16, .16]) dark_set = pm.sets( renderable=True, noSurfaceShader=True, empty=True, name="dark_shaderSG" ) dark_lambert.outColor.connect(dark_set.surfaceShader) pm.sets(dark_set, forceElement=dark_faces) light_faces = [cylinder_shape.f[index] for index in light_faces_indexes] light_lambert = pm.shadingNode("lambert", n="light_shader", asShader=True) light_lambert.color.set([.7, .7, .7]) light_set = pm.sets( renderable=True, noSurfaceShader=True, empty=True, name="light_shaderSG" ) light_lambert.outColor.connect(light_set.surfaceShader) pm.sets(light_set, forceElement=light_faces) if cutout: if "r_" == wheel_name[:2]: pm.delete(cylinder_shape.f[200:219]) if "l_" == wheel_name[:2]: pm.delete(cylinder_shape.f[180:199]) pm.select(sel,r=True) return cylinder[0]
def change_teeth(self, constructor, extrude, teeth=10, length=0.3): spans = teeth * 2 pm.polyPipe(constructor, edit=True, subdivisionsAxis=spans) side_faces = range(spans * 2, spans * 3, 2) # print side_faces face_names = [] for face in side_faces: face_name = 'f[%s]' % face face_names.append(face_name) print(face_names) pm.setAttr('%s.inputComponents' % extrude, len(face_names), *face_names, type='componentList') pm.polyExtrudeFacet(extrude, edit=True, ltz=length)
def create_tower_top(y_position, radius): """Create the top of the tower which consists of a cylinder, then some parapets on top to look like a medieval tower Args: y_position (float): The position in y for this tower section radius (float): The radius of this tower section """ tower_top_parts = [] # create cylinder name = pm.polyCylinder(name='towerTopBase#', height=3.0, radius=radius, subdivisionsY=3, subdivisionsCaps=10)[0] # move so bottom in correct location compared to previous section pm.move(name, y_position, y=True) tower_top_parts.append(name) # create parapets # create cylinder name = pm.polyCylinder(name='towerTopParapets#', height=5.0, radius=radius + 0.5, subdivisionsY=2, subdivisionsCaps=10)[0] # move so bottom in correct location compared to previous section pm.move(name, y_position + 5.0 / 2 + 3.0 / 2, y=True) # Extrude the central faces of the tower inwards to make hollowed section pm.polyExtrudeFacet(name + '.f[240:399]', name + '.f[420:440]', divisions=2, localTranslateZ=-4.5) # Select the even faces on the edge of the tower for extruding pm.polyExtrudeFacet( [name + '.f[' + str(x) + ']' for x in range(220, 240) if x % 2 == 0], localTranslateZ=2) tower_top_parts.append(name) return pm.group(*tower_top_parts, name='towerTop#')
def polyWire(mesh, gridSize=0.9, depth=0.5, extrudeMode=0): # Select the faces pm.select(mesh[0].f) # Extrude and scale the faces extrude = pm.polyExtrudeFacet(constructionHistory=True, keepFacesTogether=False, divisions=1, twist=0, taper=1, off=0) pm.PyNode(extrude[0]).localScale.set([gridSize, gridSize, gridSize]) # Delete inner faces pm.delete() pm.select(mesh[0].f) # Extrude the faces extrude = pm.polyExtrudeFacet(constructionHistory=True, keepFacesTogether=True, divisions=1, twist=0, taper=1, off=0) if extrudeMode == 0: pm.PyNode(extrude[0]).scale.set([depth, depth, depth]) elif extrudeMode == 1: pm.PyNode(extrude[0]).localTranslate.set([0, 0, depth]) pm.select(clear=True)
def create_gear(teeth=10, length=0.3): """This creates a gear with the given parameter Keyword Arguments: teeth {int} -- Number of teeth to create (default: {10}) length {float} -- Length of each gear teeth (default: {0.3}) Returns: [type] -- A tuple of the transform, constructor and extrude node """ # Teeth are every alternate face so spans x 2 spans = teeth * 2 transform, constructor = pm.polyPipe(subdivisionsAxis=spans) side_faces = range(spans * 2, spans * 3, 2) pm.select(clear=True) for face in side_faces: pm.select('%s.f[%s]' % (transform, face), add=True) extrude = pm.polyExtrudeFacet(localTranslateZ=length)[0] return transform, constructor, extrude
def create(self, startLocation=[0, 0, 0]): try: py.delete(tempConnectorName) except: pass py.polyCube(n=tempConnectorName, height=100, width=100, depth=10, subdivisionsWidth=3, subdivisionsHeight=3) py.setAttr(tempConnectorName + '.rz', lock=True, keyable=False, channelBox=False) py.scale(tempConnectorName + '.f[4]', (0.25, 0.25, 0.25)) py.polyExtrudeFacet(tempConnectorName + '.f[4]', localTranslateZ=10) py.polyExtrudeFacet(tempConnectorName + '.f[4]', localScale=(1.25, 1.25, 1.25)) py.polyExtrudeFacet(tempConnectorName + '.f[4]', localTranslateZ=20) py.scale(tempConnectorName + '.f[4]', (0, 0, 1)) py.polyExtrudeFacet(tempConnectorName + '.f[32]', localScale=(0.3, 0.27, 1)) py.polyExtrudeFacet(tempConnectorName + '.f[32]', localTranslateZ=3) py.polyExtrudeFacet(tempConnectorName + '.f[32]', localScale=(1.25, 1.25, 1.25)) py.polyExtrudeFacet(tempConnectorName + '.f[32]', localTranslateZ=5) py.scale(tempConnectorName + '.f[32]', (0, 1, 0)) py.move(tempConnectorName + '.f[32]', (0, 0, 6.15), r=True) py.xform(tempConnectorName, pivots=(0, -50, -5)) py.move(tempConnectorName, startLocation) py.select(tempConnectorName)
# Copyright (c) 2015 Cesar A. Rodriguez #from pymel.core import * import pymel.core as pm #pm.createNode('transform', name='ecoliTransform') #pm.createNode('mesh', name='ecoliMesh', parent='ecoliTransform') #pm.createNode('Ecoli', name='ecoliNode') # #pm.connectAttr('time1.outTime', 'ecoliNode.time') #pm.connectAttr('ecoliNode.outputMesh', 'ecoliMesh.inMesh') # #sets -add initialShadingGroup ecoliMesh; #pm.sets('ecoliMesh', add='initialShadingGroup') pm.polyExtrudeFacet('ecoliTransform.f[2]', ch=True, pvz=3, ltz=3.0, twist=0, taper=1, tk=0) pm.polyChipOff('ecoliTransform.f[2]', 'ecoliTransform.f[6:9]', dup=False, tz=1) pm.polySeparate('ecoliMesh') pm.select(clear=True)
def makeShell(self): if not self.hasShell(): self.ExtrudeNode = pm.polyExtrudeFacet(self.mesh, ltz=1)