def set_up_sub_joint(base_axis, new_axis, Post, Post1, Ant, Ant1, Zyg_ant, Zyg_post, inter, cent_D, cent_V, cent_L, cent_R, Pcent_D, Pcent_V, Pcent_L, Pcent_R): #Set up intersection cmds.polyCBoolOp(Ant1, Post1, op=3, n=inter) #Set up parenting relationships cmds.parent(Ant1, Ant) cmds.parent(Zyg_ant, Ant) #centrum objects cmds.parent(cent_D, Ant) cmds.parent(cent_V, Ant) cmds.parent(cent_L, Ant) cmds.parent(cent_R, Ant) #axis cmds.parent(base_axis, Ant) cmds.parent(Post1, Post) cmds.parent(Zyg_post, Post) #centrum objects cmds.parent(Pcent_D, Post) cmds.parent(Pcent_V, Post) cmds.parent(Pcent_L, Post) cmds.parent(Pcent_R, Post) #Create joint center locator cmds.spaceLocator(n=new_axis) cmds.matchTransform(new_axis, base_axis) cmds.parent(new_axis, base_axis) cmds.parent(Post, new_axis)
def BU_IntersectionPreserveMeshes(): selection = cmds.ls(sl=True) # If you don't have exactly two meshes selected it ends the function if len(selection) > 2 or len(selection) < 2: print "You have to select two elements" return firstObj = selection[0] secondObj = selection[1] # I duplicate the objects to use it again firstObjCopy = cmds.duplicate(firstObj) secondObjCopy = cmds.duplicate(secondObj) # This will be used later as well secondObjCopy2 = cmds.duplicate(secondObj) # First I do the difference between the first and the second object cmds.polyCBoolOp(firstObj, secondObj, op=2) # Then I do the intersection intersObj = cmds.polyCBoolOp(firstObjCopy, secondObjCopy, op=3) # This will get preserve all the meshes used for the intersection intersObjCopy = cmds.duplicate(intersObj) cmds.polyCBoolOp(secondObjCopy2, intersObjCopy, op=2)
def detectCollision(obj1, obj2, *args): collided = None duplicateInputRoom = cmds.duplicate(obj1, n=obj1 + 'd', renameChildren=True) duplicateOutputRoom = cmds.duplicate(obj2, n=obj2 + 'd', renameChildren=True) cmds.scriptEditorInfo(historyFilename=workspacePath + "log.txt", writeHistory=True) #start noting the history cmds.polyCBoolOp(duplicateInputRoom[0], duplicateOutputRoom[0], op=3, n='auxIntersection') #try for warning cmds.scriptEditorInfo(writeHistory=False) #stop recording information with open(workspacePath + "log.txt", 'r') as f: lines = f.readlines() collided = len( lines ) == 0 #if the file is empty of any error - then there is an intersection/collision os.remove(workspacePath + "log.txt") #remove it cmds.delete(duplicateInputRoom) cmds.delete(duplicateOutputRoom) cmds.delete('auxIntersection') return collided
def makeRoundHoleBlock(blockDepth): cubeDimX = 0.74 cubeDimY = 0.78 cubeDimZ = (blockDepth * 0.8) - (blockDepth*0.8/blockDepth) # Make Block block = cmds.polyCube(width=cubeDimX, height=cubeDimY, depth=cubeDimZ, ch=False) cmds.move((cubeDimY/2.0), moveY=True) # Make left endcap endCap = cmds.polyCylinder(r=cubeDimY * 0.5, h=cubeDimX, ax=(1,0,0), ch=False ) cmds.move( (cubeDimZ * 0.5), moveZ=True, a=True) cmds.move( (cubeDimY * 0.5), moveY=True, a=True) block = cmds.polyCBoolOp( block[0], endCap[0], op=1, ch=False ) # Make right endcap endCap = cmds.polyCylinder(r=cubeDimY * 0.5, h=cubeDimX, ax=(1,0,0), ch=False ) cmds.move( (cubeDimZ * -0.5), moveZ=True, a=True) cmds.move( (cubeDimY * 0.5), moveY=True, a=True) block = cmds.polyCBoolOp( block[0], endCap[0], op=1, ch=False ) cmds.xform(centerPivots = True ) for z in range(blockDepth): block = makeBeamHole( block, z , cubeDimX, cubeDimY, cubeDimZ ) block = makeBeamPipe( block, z , cubeDimX, cubeDimY, cubeDimZ ) return block
def makeBeamPipe( block, x, cubeDimX, cubeDimY, cubeDimZ ): innerPipe = cmds.polyPipe( r=cubeDimY * 0.5, h=cubeDimX*2, t=0.05, ax=(1,0,0) ) innerAdd = cmds.polyPipe( r=cubeDimY * 0.45, h=cubeDimX*1.64, t=0.1, ax=(1,0,0) ) inner = cmds.polyCBoolOp( innerPipe[0], innerAdd[0], op=1, ch=False ) cmds.move( (x*0.8) - (cubeDimZ/2.0), moveZ= True, a=True) cmds.move( (cubeDimY * 0.5), moveY= True, a=True) block = cmds.polyCBoolOp( block[0], inner[0], op=1, ch=False ) return block
def createGear(): teeth = 16 teethLength = 0.2 # name nsTmp = "Gear" + str(rnd.randint(1000, 9999)) cmds.select(clear=True) cmds.namespace(add=nsTmp) cmds.namespace(set=nsTmp) # query colour from UI rgb = cmds.colorSliderGrp('gearColour', q=True, rgbValue=True) # base gear = cmds.polyCylinder(r=0.7, h=0.4, sx=32) # extrude teeth for i in range(31): if (i % 2 == 0): cmds.select(gear[0] + ".f[" + str(i) + "]") cmds.polyExtrudeFacet(ltz=0.1) cmds.polyExtrudeFacet(ltz=0.1) cmds.polyMoveFacet(lsx=0.5) # decor tmp = cmds.polyCylinder(r=0.6, h=0.2) cmds.move(0.2, moveY=True, a=True) gear = cmds.polyCBoolOp(gear, tmp, op=2, ch=False) tmp = cmds.polyCylinder(r=0.6, h=0.2) cmds.move(-0.2, moveY=True, a=True) gear = cmds.polyCBoolOp(gear, tmp, op=2, ch=False) # center cylind = cmds.polyCylinder(r=0.3, h=0.6) #create x shape x = cmds.polyCube(w=0.5, h=0.6, d=0.2) tmp = cmds.polyCube(w=0.2, h=0.6, d=0.5) #combine them x = cmds.polyCBoolOp(x, tmp, op=1) x2 = cmds.duplicate(x) # remove from center cylind = cmds.polyCBoolOp(cylind, x, op=2) # remove from base gear = cmds.polyCBoolOp(gear, x2, op=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.3, moveY=True, a=True) cmds.delete(ch=True) cmds.hyperShade(assign=(nsTmp + ":blckMat")) cmds.namespace(removeNamespace=":" + nsTmp, mergeNamespaceWithParent=True)
def createRoundedBlock( blockSizeX, blockSizeY, blockSizeZ, blockLength ): edgeCylinderL = cmds.polyCylinder ( h = blockSizeZ, r = blockSizeY/2 ) cmds.rotate( 90, rotateX = True ) cmds.move( ( -blockSizeX/2 ), moveX = True, a=True) edgeCylinderR = cmds.polyCylinder ( h = blockSizeZ, r = blockSizeY/2 ) cmds.rotate( 90, rotateX = True ) cmds.move( ( blockSizeX/2 ), moveX = True, a=True) block = cmds.polyCube ( h = blockSizeY, w = blockSizeX, d = blockSizeZ, sx = ( blockLength - 1 ) * 2, sy = 2 ) block = cmds.polyCBoolOp( block, edgeCylinderL, op = 1 ) block = cmds.polyCBoolOp( block, edgeCylinderR, op = 1 ) return block
def RightBlock(): firstBlockDepth = cmds.intSliderGrp('firstAngleDepth', query=True, value=True) secondBlockDepth = cmds.intSliderGrp('secondAngleDepth', query=True, value=True) rgb = cmds.colorSliderGrp('angled90BlockColour', query=True, rgbValue=True) cmds.select(clear=True) cubeDimY = 1 * 0.96 cubeDimZ = firstBlockDepth * 0.8 firstBlock = makeRoundHoleBlock(firstBlockDepth) secondBlock = makeRoundHoleBlock(secondBlockDepth) cmds.move((cubeDimZ / 2.0), moveZ=True) cmds.move((cubeDimZ / 2.0), moveY=True) cmds.rotate('90deg', 0, 0, secondBlock[0]) finalShape = cmds.polyCBoolOp(firstBlock[0], secondBlock[0], op=1) # Adding on the colour myShader = cmds.shadingNode('lambert', asShader=True, name="blockMaterial") cmds.setAttr(myShader + ".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.select(finalShape, r=True) cmds.hyperShade(assign=myShader) cmds.namespace(set=":")
def connector(): rgb = cmds.colorSliderGrp('miscColour', query=True, rgbValue=True) cX = 1.6 cY = 0.6 cZ = 0.6 cMiddle = cmds.polyCylinder( h = 1.6/2, r = 0.5/2, sz = 1 ) cmds.rotate( 90, rotateZ = True ) cmds.move( (1.6/2)/2, moveX = True ) cInsideRidge = cmds.polyCylinder( h = 0.1, r = cY/2, sz = 1 ) cmds.rotate( 90, rotateZ = True ) cmds.move( 0.1/2, moveX = True ) cOutsideRidge = cmds.polyTorus( sr = 0.05, r = (cY/2.6)) cmds.rotate( 90, rotateZ = True ) cmds.move( (cX/2) - (0.08/2), moveX = True ) connector = cmds.polyCBoolOp( cMiddle, cInsideRidge, op = 1 ) connector = cmds.polyCBoolOp( connector, cOutsideRidge, op = 1 ) cCut = createRoundedBlock( cY * 0.6, cY * 0.2, 5, 2 ) cmds.move( cY + 0.1, moveX = True ) connector = cmds.polyCBoolOp( connector, cCut, op = 2 ) cMCut = cmds.polyCylinder( h = 1.6, r = 0.45/2, sz = 1 ) cmds.rotate( 90, rotateZ = True ) cmds.move( (1.6/2)/2, moveX = True ) connector = cmds.polyCBoolOp( connector, cMCut, op = 2 ) connectorL = cmds.duplicate( connector ) cmds.scale( -1, scaleX = True ) cmds.move( -(1.6/2), moveX = True ) connector = cmds.polyUnite( connector, connectorL) myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( connector ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def HoleConnector(): components = [] # Fetching slider data rgb = cmds.colorSliderGrp('HoleColour', query=True, rgbValue=True) cmds.select(clear=True) cubeDimX = 0.74 cubeDimY = 0.78 # Inner tube innerCyl = cmds.polyPipe( r=cubeDimY * 0.40, h=cubeDimX*3.85, t=0.1, ax=(1,0,0), ch=False ) # End Ring endCyl1 = cmds.polyPipe( r=cubeDimY * 0.45, h=cubeDimX*0.1, t=0.05, ax=(1,0,0), ch=False ) cmds.move(cubeDimX*1 - (cubeDimX*0.05),0,0) midShape = cmds.polyCBoolOp( innerCyl[0], endCyl1[0] , op=1, ch=False) # Subtraction cube endCube1 = cmds.polyCube(width=0.5, height=0.09, depth=1, ch=False) cmds.move(cubeDimX*1 - (cubeDimX*0.15),0,0) midShape = cmds.polyCBoolOp( midShape[0], endCube1[0], op=2, ch=False ) # End Ring 2 endCyl2 = cmds.polyPipe( r=cubeDimY * 0.45, h=cubeDimX*0.1, t=0.05, ax=(1,0,0), ch=False ) cmds.move((cubeDimX*0.05) - cubeDimX*1,0,0) midShape = cmds.polyCBoolOp( midShape[0], endCyl2[0] , op=1, ch=False) # Subtraction cube 2 endCube2 = cmds.polyCube(width=0.5, height=0.09, depth=1, ch=False) cmds.move((cubeDimX*0.15) - cubeDimX*1,0,0) midShape = cmds.polyCBoolOp( midShape[0], endCube2[0], op=2, ch=False ) outerCyl1 = cmds.polyPipe( r=cubeDimY * 0.45, h=cubeDimX*0.2, t=0.05, ax=(1,0,0),ch=False ) finalShape = cmds.polyCBoolOp( midShape[0], outerCyl1[0], op=1, ch=False ) # Adding on the color shadedShape = addShader(finalShape, rgb)
def booleanLoop(legacy=False): #1. Make an array of all selections target = mc.ls(sl=1) if (legacy): #2. Boolean union each item in the array to the next for i in range(0,len(target)-1,2): mc.polyBoolOp(target[i],target[i+1]) #3. Delete construction history mc.delete(ch=True) #4. Recenter the pivot mc.xform(cp=True) else: mc.polyCBoolOp() mc.delete(ch=True)
def booleanLoop(legacy=False): #1. Make an array of all selections target = mc.ls(sl=1) if (legacy): #2. Boolean union each item in the array to the next for i in range(0, len(target) - 1, 2): mc.polyBoolOp(target[i], target[i + 1]) #3. Delete construction history mc.delete(ch=True) #4. Recenter the pivot mc.xform(cp=True) else: mc.polyCBoolOp() mc.delete(ch=True)
def connector(): connectorLength = cmds.intSliderGrp('connectorLength', q=True, v=True) connectorSizeX = (1 * 0.8) - 0.1 connectorSizeY = (1 * 0.8) - 0.1 connectorSizeZ = (connectorLength * 0.4) rgb = cmds.colorSliderGrp('blockColour', q=True, rgbValue=True) connector = cmds.polyCylinder(r=(connectorSizeX/2.0),h=connectorSizeZ, sh=6) cmds.rotate(90,rotateX=True) cmds.move((connectorSizeY/2.0), moveY=True, a=True) connectorName = cmds.ls(connector)[0] cmds.select(connectorName+".e[40:99]") cmds.scale(0.8, 0.8, 0.8, relative=True) cmds.select(connectorName+".e[40:59]") cmds.move(-0.13, moveZ=True,r=True) cmds.select(connectorName+".e[80:99]") cmds.move(0.13, moveZ=True,r=True) axelShape = cmds.polyCube(h = 0.19, w=(connectorSizeZ+0.2), d=0.19) cmds.move((connectorSizeY/2.0), moveY=True, a=True) axelName = cmds.ls(axelShape)[0] cmds.select(axelName+".f[0]") cmds.select(axelName+".f[1]", add=True) cmds.select(axelName+".f[2]", add=True) cmds.select(axelName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(axelShape) cmds.polyBevel(sg=2, oaf=True, fn=True) cmds.rotate(90, rotateY=True) if(connectorLength == 2): cmds.select(connectorName+".e[242]") cmds.select(connectorName+".e[246]", add=True) cmds.move(-0.05, moveY=True, relative=True) cmds.select(connectorName+".e[252]") cmds.select(connectorName+".e[256]", add=True) cmds.move(0.05, moveY=True, relative=True) cmds.select(connector) cmds.select(axelShape, add=True) connector = cmds.polyCBoolOp(op=2, ch=False, n="Connector" + str(rnd.randint(1000,9999))) applyMaterial(connector, rgb) cmds.delete(ch=True)
def createBlockHoles( blockSizeX, blockSizeY, block, blockLength, blockOffset ): hcList = [] rcyList = [] rcuList = [] for j in range( blockLength ): #create cylinders to cut holes holeCylinder = cmds.polyCylinder( r = 0.24, h = 2, sz=1 ) cmds.rotate( 90, rotateX = True ) cmds.move((blockSizeY/2), moveY = True, a = True) cmds.move(((j * 0.8) - (blockSizeX/2.0) + blockOffset ), moveX = True, a = True) hcList.append( holeCylinder ) #create cylinders to cut sunken area around holes ##create a cylinder ridgeCylinder = cmds.polyCylinder( r=0.31, h=2, sz=1 ) cmds.rotate( 90, rotateX = True ) cmds.move((blockSizeY/2), moveY = True, a = True) cmds.move(((j * 0.8) - (blockSizeX/2.0) + blockOffset ), moveX = True, a = True) rcyList.append( ridgeCylinder ) ##create a cube ridgeCube = cmds.polyCube ( h = 0.64, w = blockSizeY, d = blockSizeY ) cmds.rotate( 90, rotateX = True ) cmds.move((blockSizeY/2), moveY=True ) cmds.move(((j * 0.8) - (blockSizeX/2.0) + blockOffset ), moveX=True ) rcuList.append( ridgeCube ) if len( hcList ) > 1 : holeCylinders = cmds.polyUnite( *hcList ) ridgeCylinders = cmds.polyUnite( *rcyList ) ridgeCubes = cmds.polyUnite( *rcuList ) else: holeCylinders = hcList[0] ridgeCylinders = rcyList[0] ridgeCubes = rcuList[0] block = cmds.polyCBoolOp( block, holeCylinders, op=2 ) ridgeCutter = cmds.polyCBoolOp( ridgeCylinders, ridgeCubes, op=2 ) block = cmds.polyCBoolOp( block, ridgeCutter, op=2 ) return block
def addToCollisionUnion(self, obj): unionAmounts = len(self.collisionUnions) if self.blockIndex >= 15 * unionAmounts: #amount of blocks in a single union cmds.rename(obj, "collisionUnion" + str(len(self.collisionUnions))) self.collisionUnions.append("collisionUnion" + str(len(self.collisionUnions))) else: self.collisionUnions[unionAmounts - 1] = cmds.polyCBoolOp( self.collisionUnions[unionAmounts - 1], obj, op=1, ch=False)[0]
def BU_DiffIntersection(): selection = cmds.ls(sl=True) # If you don't have exactly two meshes selected it ends the function if len(selection) > 2 or len(selection) < 2: print "You have to select two elements" return firstObj = selection[0] secondObj = selection[1] # I duplicate the objects to use it again firstObjCopy = cmds.duplicate(firstObj) secondObjCopy = cmds.duplicate(secondObj) # First I do the difference between the first and the second object cmds.polyCBoolOp(firstObj, secondObj, op=2) # Then I do the intersection cmds.polyCBoolOp(firstObjCopy, secondObjCopy, op=3)
def HoleBlock(): # Initialize the building blocks and the subtraction blocks components = [] subtracts = [] blockDepth = cmds.intSliderGrp('HoleblockDepth', query=True, value=True) rgb = cmds.colorSliderGrp('HoleblockColour', query=True, rgbValue=True) cmds.select(clear=True) blockWidth = 1 cubeDimX = blockWidth * 0.8 blockHeight = 1 cubeDimY = blockHeight * 0.96 cubeDimZ = blockDepth * 0.8 cube = cmds.polyCube(h=cubeDimY, w=cubeDimX, d=cubeDimZ, sz=blockDepth) cmds.move((cubeDimY / 2.0), moveY=True) # Pipes on top of block for i in range(blockDepth): components.append(cmds.polyPipe(r=0.24, h=0.36, thickness=0.09)[0]) cmds.move((cubeDimY + 0.10), moveY=True, a=True) cmds.move(((i * 0.8) - (cubeDimZ / 2.0) + 0.4), moveZ=True, a=True) # Holes within block for k in range(blockDepth - 1): holes = cmds.polyCylinder(h=1, r=0.24, ax=(1, 0, 0)) subtracts.append(holes[0]) cmds.move(0, cubeDimY - 0.38, ((k * 0.8) - (cubeDimZ / 2.0) + 0.8), holes[0], a=True) # Unite the cube and the top addShape = cmds.polyUnite(cube, components, ch=False) currentHole = subtracts[0] for hole in range(len(subtracts) - 1): uniteHole = cmds.polyUnite(currentHole, subtracts[hole + 1], ch=False) currentHole = uniteHole finalShape = cmds.polyCBoolOp(addShape, uniteHole, op=2, ch=False)[0] # Adding on the colour myShader = cmds.shadingNode('lambert', asShader=True, name="blockMaterial") cmds.setAttr(myShader + ".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.select(finalShape, r=True) cmds.hyperShade(assign=myShader) cmds.namespace(set=":")
def HoleBlock(): # Initialize the building blocks and the subtraction blocks components = [] subtracts = [] # Fetching slider data blockDepth = cmds.intSliderGrp('HoleblockDepth', query=True, value=True) rgb = cmds.colorSliderGrp('HoleblockColour', query=True, rgbValue=True) cmds.select(clear=True) blockWidth = 1 cubeDimX = blockWidth * 0.8 blockHeight = 1 cubeDimY = blockHeight * 0.96 cubeDimZ = blockDepth * 0.8 cube = cmds.polyCube(h=cubeDimY, w=cubeDimX, d=cubeDimZ, sz=blockDepth, ch=False) cmds.move((cubeDimY/2.0), moveY=True) # Pipes on top of block for i in range(blockDepth): components.append(cmds.polyPipe(r=0.24, h=0.36, thickness=0.09, ch=False)[0]) cmds.move((cubeDimY + 0.10), moveY=True, a=True) cmds.move(((i * 0.8) - (cubeDimZ/2.0) + 0.4), moveZ=True, a=True) # Holes within block for k in range(blockDepth - 1): holes = cmds.polyCylinder( h=1, r=0.24, ax=(1,0,0), ch=False) subtracts.append(holes[0]); cmds.move( 0, cubeDimY - 0.38, ((k*0.8) - (cubeDimZ/2.0) + 0.8), holes[0], a=True) # Unite the cube and the top addShape = cmds.polyUnite(cube, components, ch=False) currentHole = subtracts[0] # Unite all of the holes for a boolean subtraction for hole in range(len(subtracts)- 1): uniteHole = cmds.polyUnite(currentHole, subtracts[hole+1], ch=False) currentHole = uniteHole finalShape = cmds.polyCBoolOp(addShape, currentHole, op=2, ch=False)[0] # Adding on the colour shadedShape = addShader(finalShape, rgb)
def createBeamIndents(block, blockDepth, blockSizeX, blockSizeY, blockSizeZ): beam = block indentArray = [] for i in range(blockDepth): #h = 0.6 (same as outer holes), #w = 0.15 (estimate for space between), #d = 0.35 (estimate based on image) indent = cmds.polyCube(h=0.6, w=0.15, d=0.35, sy=3) cmds.move((blockSizeX/2.0), moveX = True, a = True) cmds.move((blockSizeY/2.0), moveY = True, a = True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+0.65), moveZ = True) indentName = cmds.ls(indent)[0] cmds.select(indentName+'.vtx[2:5]') cmds.move(0, 0, -0.1, r=True) cmds.select(indentName+'.vtx[10:13]') cmds.move(0, 0, 0.1, r=True) indentArray.append(indent) indent = cmds.polyCube(h=0.6, w=0.15, d=0.4, sy=3) cmds.move((-1*(blockSizeX/2.0)), moveX = True, a = True) cmds.move((blockSizeY/2.0), moveY = True, a = True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+0.65), moveZ = True) indentName = cmds.ls(indent)[0] cmds.select(indentName+'.vtx[2:5]') cmds.move(0, 0, -0.1, r=True) cmds.select(indentName+'.vtx[10:13]') cmds.move(0, 0, 0.1, r=True) indentArray.append(indent) cmds.select(clear=True) #combine hourglass shaped indents into one polygon for indent in indentArray: cmds.select(indent, add=True) indents = cmds.polyUnite(ch=False) cmds.select(clear=True) cmds.select(beam) cmds.select(indents, add=True) finalBlock = cmds.polyCBoolOp(op=2, ch=False) return finalBlock
def axle(): axleLength = cmds.intSliderGrp( 'axleLength', query = True, value = True) rgb = cmds.colorSliderGrp('miscColour', query=True, rgbValue=True) axleX = axleLength * 0.8 axleY = 0.4 axleZ = 0.4 hAxle = cmds.polyCube( w = axleX, h = axleY/2, d = axleZ ) vAxle = cmds.polyCube( w = axleX, h = axleY, d = axleZ/2 ) axle = cmds.polyCBoolOp( hAxle, vAxle, op = 1 )[0] myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( axle ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
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)
def createRoundedBeams(block, blockSizeX, blockSizeY, blockSizeZ): endCyl1 = cmds.polyCylinder(r=(blockSizeY/2.0), h=blockSizeX) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move((blockSizeY/2.0), moveY=True) cmds.move((blockSizeZ/2.0), moveZ=True, a=True) endCyl2= cmds.polyCylinder(r=(blockSizeY/2.0), h=blockSizeX) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move((blockSizeY/2.0), moveY=True) cmds.move((-blockSizeZ/2.0), moveZ=True, a=True) cmds.select(block) cmds.select(endCyl1, add=True) cmds.select(endCyl2, add=True) #combine cylindrical ends with rectangle using union boolean #joins them but removes intersecting parts roundedBlock = cmds.polyCBoolOp(op=1,ch=False) return roundedBlock
def makeBeamHole( block, z, cubeDimX, cubeDimY, cubeDimZ ): hole = cmds.polyCylinder( r=cubeDimY * 0.45, h=cubeDimX, ax=(1,0,0), ch=False ) cmds.move( (z * 0.8) - (cubeDimZ/2.0), moveZ= True, a=True) cmds.move( (cubeDimY * 0.5), moveY= True, a=True) block = cmds.polyCBoolOp( block[0], hole[0], op=2, ch=False ) return block
def uniformVoroPoints(self): ''' Performs voronoi uniform fragmentation ''' # duplicate original shape mVoroInputMeshFn = OpenMaya.MFnMesh(self._mVoroInputMeshDAG) mPoints = OpenMaya.MPointArray() mVerticesCount = OpenMaya.MIntArray() mVerticesList = OpenMaya.MIntArray() mVoroInputMeshFn.getPoints(mPoints, OpenMaya.MSpace.kWorld) mVoroInputMeshFn.getVertices(mVerticesCount, mVerticesList) mNumPoly = mVoroInputMeshFn.numPolygons() mCopyMeshFn = OpenMaya.MFnMesh() mCopyTrs = mCopyMeshFn.create(mPoints.length(), mNumPoly, mPoints, mVerticesCount, mVerticesList) mDagPath = OpenMaya.MDagPath() OpenMaya.MDagPath.getAPathTo(mCopyTrs, mDagPath) mMeshName = mDagPath.fullPathName() # create boolean op between sphere and duplicated shape mRadius = cmds.getAttr(self._mVoroImpactShape + '.radius') mRadius = max(.15, mRadius) mImpact = cmds.polySphere(r = mRadius, sx = 8, sy = 8) cmds.xform(mImpact[0], translation = [self._mOriginPt.x, self._mOriginPt.y, self._mOriginPt.z]) cmds.select(clear = True) mVolume = None if int(cmds.about(version = True).split()[0]) > 2014: try: mVolume = cmds.polyCBoolOp(mMeshName, mImpact[0], op = 3, ch = False, classification = 1, n = 'IS_Volume') except: pass else: try: mVolume = cmds.polyBoolOp(mMeshName, mImpact[0], op = 3, ch = False, n = 'IS_Volume') except: pass cmds.flushUndo() # Check if mVolume is valid if mVolume: if cmds.polyEvaluate(mVolume, face = True) == 0: cmds.delete(mVolume) mVolume = cmds.polySphere(r = mRadius, sx = 8, sy = 8) else: mVolume = cmds.polySphere(r = mRadius, sx = 8, sy = 8) # Fill volume of the boolean object with points mSelection = OpenMaya.MSelectionList() mSelection.add(mVolume[0]) mSelection.getDagPath(0, mDagPath) mDagPath.extendToShape() mVerts = OpenMaya.MPointArray() triangleCounts, triangleVertices = OpenMaya.MIntArray(), OpenMaya.MIntArray() mVolMeshFn = OpenMaya.MFnMesh(mDagPath) mVolMeshFn.getPoints(mVerts, OpenMaya.MSpace.kWorld) mVolMeshFn.getTriangles(triangleCounts, triangleVertices) numTriangles = triangleVertices.length() / 3 mHitPoint = OpenMaya.MFloatPoint() mFloatRaySource = OpenMaya.MFloatPoint() mFloatRayNormal = OpenMaya.MFloatVector() # Randomly select a face, find a point on face surface (with bary coords) and launch a ray from the reversed normal mAccelerationStructure = mVolMeshFn.autoUniformGridParams() for n in xrange(self._mVoroCount): triId = rand.randint(0, numTriangles-1) v0 = triangleVertices[3 * triId + 0] v1 = triangleVertices[3 * triId + 1] v2 = triangleVertices[3 * triId + 2] mVectorAB = mVerts[v1] - mVerts[v0] mVectorAC = mVerts[v2] - mVerts[v0] mNormal = (mVectorAB ^ mVectorAC) * -1.0 mNormal.normalize() u = rand.uniform(0.0,1.0) v = rand.uniform(0.0, (1.0 - u)) mSample = (mVerts[v0] + mVectorAB * u + mVectorAC * v) + (mNormal * 0.001) mFloatRaySource.x, mFloatRaySource.y, mFloatRaySource.z = mSample.x, mSample.y, mSample.z mFloatRayNormal.x, mFloatRayNormal.y, mFloatRayNormal.z = mNormal.x, mNormal.y, mNormal.z hit = mVolMeshFn.closestIntersection( mFloatRaySource, mFloatRayNormal, None, None, None, OpenMaya.MSpace.kWorld, 99999, None, mAccelerationStructure, mHitPoint, None, None, None, None, None ) if hit: mDistance = mFloatRaySource.distanceTo(mHitPoint) self._mVoroPoints.append(mSample + (mNormal * rand.uniform(0.0, mDistance))) mVolMeshFn.freeCachedIntersectionAccelerator() cmds.delete(mVolume) # hide IShatter sphere helper cmds.setAttr(self._mVoroImpactTrs + '.visibility', False) cmds.setAttr(self._mVoroImpactShape + '.radius', 0.0001) cmds.xform(self._mVoroImpactTrs, translation = [0.0, 0.0, 0.0]) self._mView.refresh(False, True) # update fractureFX mel.eval("fxEraseParticles " + self._mVoroParticleObject) mVoroParticleSysFn = OpenMayaFX.MFnParticleSystem(self._mVoroParticleSysDAG) mVoroParticleSysFn.emit(self._mVoroPoints) mVoroParticleSysFn.saveInitialState()
def angularBeam(): horizontalLength = cmds.intSliderGrp('horizontalLength', query=True, value=True) angledLength = cmds.intSliderGrp('angledLength', query=True, value=True) angleSelected = cmds.radioButtonGrp('angleDegree', query=True, select=True) angleDegree = angleArray[angleSelected] leftCross = cmds.checkBox('leftCrossCheck', query = True, value = True) rightCross = cmds.checkBox('rightCrossCheck', query = True, value = True) rgb = cmds.colorSliderGrp('beamColour', query=True, rgbValue=True) holeOffset = 0.0; cubeSizeH = (horizontalLength - 1) * 0.8 cubeSizeA = (angledLength - 1) * 0.8 cubeSizeZ = 0.8 cubeSizeY = 0.8 horizontalCube = createRoundedBlock( cubeSizeH, cubeSizeY, cubeSizeZ, horizontalLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) if( leftCross == True ): holeOffset = 0.8 horizontalCube = createBlockHoles( cubeSizeH, cubeSizeY, horizontalCube, horizontalLength - 1, holeOffset ) hCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] cmds.move( -(cubeSizeH/2), cubeSizeY/2, 0 ) horizontalCube = cmds.polyCBoolOp( horizontalCube, cross, op = 2 )[0] else: horizontalCube = createBlockHoles( cubeSizeH, cubeSizeY, horizontalCube, horizontalLength, holeOffset ) angledCube = createRoundedBlock( cubeSizeA, cubeSizeY, cubeSizeZ, angledLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) if( rightCross == True ): holeOffset = 0.0 angledCube = createBlockHoles( cubeSizeA, cubeSizeY,angledCube, angledLength - 1, holeOffset ) hCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] cmds.move( cubeSizeA/2, cubeSizeY/2, 0 ) angledCube = cmds.polyCBoolOp( angledCube, cross, op = 2 )[0] else: holeOffset = 0.0 angledCube = createBlockHoles( cubeSizeA, cubeSizeY, angledCube, angledLength, holeOffset )[0] cmds.move( ( - (cubeSizeA/2.0)), (cubeSizeY/2), 0, angledCube+".scalePivot", angledCube+".rotatePivot", absolute=True) cmds.rotate( angleDegree, rotateZ = True ) cmds.move( ((cubeSizeH/2) + (cubeSizeA/2)), moveX = True ) angledBeam = cmds.polyUnite( horizontalCube, angledCube ) myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( angledBeam ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def doubleAngularBeam(): horizontalLength = cmds.intSliderGrp('dHorizontalLength', query=True, value=True) verticalLength = cmds.intSliderGrp('dVerticalLength', query=True, value=True) angledLength = 3.8 leftCross = cmds.checkBox('leftCrossCheck', query = True, value = True) rightCross = cmds.checkBox('rightCrossCheck', query = True, value = True) rgb = cmds.colorSliderGrp('beamColour', query=True, rgbValue=True) holeOffset = 0.0; cubeSizeH = (horizontalLength - 1) * 0.8 cubeSizeA = 3.04 cubeSizeV = (verticalLength - 1) * 0.8 cubeSizeZ = 0.8 cubeSizeY = 0.8 beamAngle = 45 angledDistance = ( math.sin( math.radians(45))) * cubeSizeA #create horizontal section of angled beam horizontalCube = createRoundedBlock( cubeSizeH, cubeSizeY, cubeSizeZ, horizontalLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) if( leftCross == True ): holeOffset = 0.8 horizontalCube = createBlockHoles( cubeSizeH, cubeSizeY, horizontalCube, horizontalLength - 1, holeOffset ) hCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] cmds.move( -(cubeSizeH/2), cubeSizeY/2, 0 ) horizontalCube = cmds.polyCBoolOp( horizontalCube, cross, op = 2 )[0] else: horizontalCube = createBlockHoles( cubeSizeH, cubeSizeY, horizontalCube, horizontalLength, holeOffset ) #create angled section of angled beam angledCube = createRoundedBlock( cubeSizeA, cubeSizeY, cubeSizeZ, angledLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) #create left hole in angled beam section holeCylinderL = cmds.polyCylinder( r = 0.24, h = 2, sz=1 ) cmds.rotate( 90, rotateX = True ) cmds.move((cubeSizeY/2), moveY = True, a = True) cmds.move(( - (cubeSizeA/2.0)), moveX = True, a = True) ridgeCylinderL = cmds.polyCylinder( r=0.31, h=2, sz=1 ) cmds.rotate( 90, rotateX = True ) cmds.move((cubeSizeY/2), moveY = True, a = True) cmds.move(( - ( cubeSizeA / 2.0 )), moveX = True, a = True) ridgeCubeL = cmds.polyCube ( h = 0.64, w = cubeSizeY, d = cubeSizeY ) cmds.rotate( 90, rotateX = True ) cmds.move(( cubeSizeY / 2 ), moveY=True ) cmds.move(( - (cubeSizeA/2.0)), moveX=True ) angledCube = cmds.polyCBoolOp( angledCube, holeCylinderL, op=2 ) ridgeCutterL = cmds.polyCBoolOp( ridgeCylinderL, ridgeCubeL, op=2 ) angledCube = cmds.polyCBoolOp( angledCube, ridgeCutterL, op=2 ) #create right hole in angled beam section holeCylinderR = cmds.polyCylinder( r = 0.24, h = 2, sz=1 ) cmds.rotate( 90, rotateX = True ) cmds.move((cubeSizeY/2), moveY = True, a = True) cmds.move(((angledLength * 0.8) - (cubeSizeA/2.0)), moveX = True, a = True) ridgeCylinderR = cmds.polyCylinder( r=0.31, h=2, sz=1 ) cmds.rotate( 90, rotateX = True ) cmds.move((cubeSizeY/2), moveY = True, a = True) cmds.move(((angledLength * 0.8) - (cubeSizeA/2.0)), moveX = True, a = True) ridgeCubeR = cmds.polyCube ( h = 0.64, w = cubeSizeY, d = cubeSizeY ) cmds.rotate( 90, rotateX = True ) cmds.move((cubeSizeY/2), moveY=True ) cmds.move(((angledLength * 0.8) - (cubeSizeA/2.0)), moveX=True ) angledCube = cmds.polyCBoolOp( angledCube, holeCylinderR, op=2 ) ridgeCutterR = cmds.polyCBoolOp( ridgeCylinderR, ridgeCubeR, op=2 ) angledCube = cmds.polyCBoolOp( angledCube, ridgeCutterR, op=2 ) #create rounded rectangle cutout in angled beam section holeBlock = createRoundedBlock( ( cubeSizeA - ( 0.8 * 2 )), 0.48, 2, angledLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) ridgeBlock = createRoundedBlock( ( cubeSizeA - ( 0.8 * 2 )), 0.62, 2, angledLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) ridgeCube = cmds.polyCube ( h = cubeSizeY, w = cubeSizeA, d = 0.64 ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) angledCube = cmds.polyCBoolOp( angledCube, holeBlock, op=2 ) ridgeCutter = cmds.polyCBoolOp( ridgeBlock, ridgeCube, op=2 ) angledCube = cmds.polyCBoolOp( angledCube, ridgeCutter, op=2 ) #move and rotate angled beam in to position cmds.move( ( - (cubeSizeA/2.0)), (cubeSizeY/2), 0, angledCube[0]+".scalePivot",angledCube[0]+".rotatePivot", absolute=True) cmds.rotate( beamAngle, rotateZ = True ) cmds.move( ((cubeSizeH/2) + (cubeSizeA/2)), moveX = True ) doubleBeam = cmds.polyUnite( horizontalCube, angledCube ) #create vertical section of angled beam verticalCube = createRoundedBlock( cubeSizeV, cubeSizeY, cubeSizeZ, verticalLength ) cmds.move(( cubeSizeY / 2.0 ), moveY = True ) if( rightCross == True ): holeOffset = 0.0 verticalCube = createBlockHoles( cubeSizeV, cubeSizeY, verticalCube, verticalLength - 1, holeOffset ) hCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] cmds.move( cubeSizeV/2, cubeSizeY/2, 0 ) verticalCube = cmds.polyCBoolOp( verticalCube, cross, op = 2 )[0] else: holeOffset = 0.0 verticalCube = createBlockHoles( cubeSizeV, cubeSizeY, verticalCube, verticalLength, holeOffset ) cmds.move( ( - (cubeSizeA/2.0)), (cubeSizeY/2), 0, angledCube[0]+".scalePivot",angledCube[0]+".rotatePivot", absolute=True) cmds.rotate( 90, rotateZ = True ) cmds.move( (( cubeSizeH / 2 ) + angledDistance ), moveX = True ) cmds.move( (( cubeSizeV / 2 ) + angledDistance ), moveY = True ) doubleBeam = cmds.polyUnite( doubleBeam, verticalCube ) #add material myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( doubleBeam ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def makeBeamPipe(block, x, cubeDimX, cubeDimY, cubeDimZ): hole = cmds.polyCylinder(r=cubeDimY * 0.45, h=cubeDimX, ax=(1, 0, 0)) cmds.move((x * 0.6) - (cubeDimZ / 2.0), moveZ=True, a=True) cmds.move((cubeDimY * 0.5), moveY=True, a=True) block = cmds.polyCBoolOp(block[0], hole[0], op=2) return block
def rim(): #get values from UI rimStyle = cmds.radioButtonGrp( 'rimStyle', query = True, select = True) rgb = cmds.colorSliderGrp('wheelColour', query=True, rgbValue=True) #set up variables radius = 1.6 widthHalf = 2.1 / 2 if( rimStyle == 1 ): mediumCircle = cmds.polyCylinder( h = widthHalf * 0.4, r = radius * 0.67 ) cmds.rotate( 90, rotateZ = True ) crossV = cmds.polyCube( w = widthHalf, h = 0.4, d = 0.2 ) crossH = cmds.polyCube( w = widthHalf, h = 0.2, d = 0.4 ) cross = cmds.polyCBoolOp( crossV, crossH, op = 1 ) cmds.move( widthHalf / 2, moveX = True ) mediumCircle = cmds.polyCBoolOp( mediumCircle, cross, op = 2 ) innerCircle = cmds.polyPipe( h = widthHalf * 0.3, r = radius * 0.33, t = 0.14 ) cmds.rotate( 90, rotateZ = True ) cmds.move( ((widthHalf * 0.4) / 2) + ((widthHalf * 0.3) / 2), moveX = True ) outerCircle = cmds.polyPipe( h = widthHalf, r = radius, t = 0.2 ) cmds.rotate( 90, rotateZ = True ) cmds.move( (((widthHalf * 0.4) / 2) + ((widthHalf * 0.5) / 2)) + 0.1, moveX = True ) outerCircleCut = cmds.polyPipe( h = widthHalf * 0.33, r = radius, t = 0.1 ) cmds.rotate( 90, rotateZ = True ) cmds.move( (((widthHalf * 0.4) / 2) + ((widthHalf * 0.5) / 2)) + 0.1, moveX = True ) outerCircle = cmds.polyCBoolOp( outerCircle, outerCircleCut, op = 2 ) slope = cmds.polyCone() cmds.rotate( 90, rotateZ = True ) cmds.move( 0.810, moveX = True ) cmds.scale( 5.455, 1, 5.455 ) slopeCutL = cmds.polyCylinder( h = widthHalf, r = radius ) cmds.rotate( 90, rotateZ = True ) cmds.move( -( widthHalf / 2), moveX = True ) slopeCutR = cmds.polyCylinder( h = 4, r = radius * 10 ) cmds.rotate( 90, rotateZ = True ) cmds.move( 2.326, moveX = True ) slope = cmds.polyCBoolOp( slope, slopeCutL, op = 2 )[0] slope = cmds.polyCBoolOp( slope, slopeCutR, op = 2 )[0] cmds.delete( slope+".f[21]") rimL = cmds.polyUnite( mediumCircle, innerCircle, outerCircle, slope ) cmds.move( (widthHalf*0.4)/2, moveX = True ) rimR = cmds.duplicate( rimL ) cmds.scale( -1, scaleX = True ) cmds.move( -((widthHalf*0.4)/2), moveX = True ) rim = cmds.polyUnite( rimR, rimL ) elif( rimStyle == 2 ): radius = 1.5 circleList = [] mainCircle = cmds.polyCylinder( h = 0.4, r = radius - 0.2 ) innerCircle = cmds.polyCylinder( h = 0.5, r = radius * 0.2 ) hCross = cmds.polyCube( w = radius * 0.24, h = 3, d = radius * 0.1 ) vCross = cmds.polyCube( w = radius * 0.1, h = 3, d = radius * 0.24 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] rim = cmds.polyCBoolOp( mainCircle, innerCircle, op = 1 ) rim = cmds.polyCBoolOp( rim, cross, op = 2 ) lRidge = cmds.polyTorus( sr = 0.1, r = (radius * 0.9)) cmds.move( 0.4/2, moveY = True ) rRidge = cmds.polyTorus( sr = 0.1, r = (radius * 0.9)) cmds.move( -(0.4/2), moveY = True ) rim = cmds.polyCBoolOp( rim, lRidge, op = 1 )[0] rim = cmds.polyCBoolOp( rim, rRidge, op = 1 )[0] cutCircle = cmds.polyCylinder( h = 3, r = radius * 0.17 )[0] cmds.move( 0, 0, 0.8) cmds.move( 0, 0, 0, cutCircle+".scalePivot", cutCircle+".rotatePivot", absolute=True) circleList.append( cutCircle ) for i in range( 0, 5): cutCircle = cmds.duplicate( cutCircle ) cmds.rotate( 0, 60, 0, cutCircle, r = True ) circleList.append( cutCircle ) cutCircles = cmds.polyUnite( *circleList) rim = cmds.polyCBoolOp( rim, cutCircles, op = 2 ) cmds.rotate( 90, rotateX = True ) myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( rim ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def polyCBoolOp(*args, **kwargs): res = cmds.polyCBoolOp(*args, **kwargs) if not kwargs.get('query', kwargs.get('q', False)): res = _factories.maybeConvert(res, _general.PyNode) return res
def straightBeam(): #get values from UI beamLength = cmds.intSliderGrp('beamLength', query=True, value=True) leftCross = cmds.checkBox('leftCrossCheck', query = True, value = True) rightCross = cmds.checkBox('rightCrossCheck', query = True, value = True) rgb = cmds.colorSliderGrp('beamColour', query=True, rgbValue=True) #set up variables holeOffset = 0.0; beamSizeX = ( beamLength - 1 ) * 0.8 beamSizeZ = 0.8 beamSizeY = 0.8 #hAxle = cmds.polyCube( w = axleX, h = axleY/2, d = axleZ ) #vAxle = cmds.polyCube( w = axleX, h = axleY, d = axleZ/2 ) #axle = cmds.polyCBoolOp( hAxle, vAxle, op = 1 )[0] beam = createRoundedBlock( beamSizeX, beamSizeY, beamSizeZ, beamLength ) cmds.move(( beamSizeY / 2.0 ), moveY = True ) if( leftCross == True and rightCross == False): holeOffset = 0.8 beam = createBlockHoles( beamSizeX, beamSizeY, beam, beamLength - 1, holeOffset ) hCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] cmds.move( -(beamSizeX/2), beamSizeY/2, 0 ) beam = cmds.polyCBoolOp( beam, cross, op = 2 )[0] elif( leftCross == False and rightCross == True): beam = createBlockHoles( beamSizeX, beamSizeY, beam, beamLength - 1, holeOffset ) hCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) cross = cmds.polyCBoolOp( hCross, vCross, op = 1 )[0] cmds.move( (beamSizeX/2), beamSizeY/2, 0 ) beam = cmds.polyCBoolOp( beam, cross, op = 2 )[0] elif( leftCross == True and rightCross == True): holeOffset = 0.8 beam = createBlockHoles( beamSizeX, beamSizeY, beam, beamLength - 2, holeOffset ) hLCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vLCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) lCross = cmds.polyCBoolOp( hLCross, vLCross, op = 1 )[0] cmds.move( -(beamSizeX/2), beamSizeY/2, 0 ) beam = cmds.polyCBoolOp( beam, lCross, op = 2 )[0] hRCross = cmds.polyCube( w = 0.62, h = 0.31, d = 3 ) vRCross = cmds.polyCube( w = 0.31, h = 0.62, d = 3 ) rCross = cmds.polyCBoolOp( hRCross, vRCross, op = 1 )[0] cmds.move( beamSizeX/2, beamSizeY/2, 0 ) beam = cmds.polyCBoolOp( beam, rCross, op = 2 )[0] else: beam = createBlockHoles( beamSizeX, beamSizeY, beam, beamLength, holeOffset ) myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( beam ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def createWheel(): # query UI choice createTire = cmds.radioButtonGrp('wheelTire', q=True, sl=True) createHub = cmds.radioButtonGrp('wheelHub', q=True, sl=True) # create a tire if (createTire == 1): # name nsTmp = "Tire" + str(rnd.randint(1000, 9999)) cmds.select(clear=True) cmds.namespace(add=nsTmp) cmds.namespace(set=nsTmp) # query colour from UI rgb = cmds.colorSliderGrp('tireColour', q=True, rgbValue=True) # create cylinder for the base tire = cmds.polyCylinder(r=3.5, h=3.5, sx=36) # add a smaller sphere to round up the tire tmp = cmds.polySphere(r=3.35, sy=15, sx=36) cmds.scale(1.1, scaleY=True) # remove non intersecting parts tire = cmds.polyCBoolOp(tire, tmp, op=3, ch=False) # Add texture: # create cylinder as the base for texture at 1 side texture1 = cmds.polyCylinder(r=2.8, h=1.75, sx=36) # move it up cmds.move(1.75 / 2, moveY=True, a=True) # in range of subdivisions for i in range(35): #for all even numbers if (i % 2 == 0): cmds.select(texture1[0] + ".f[" + str(i) + "]") # local translate on Z and scale x cmds.polyExtrudeFacet(ltz=1, lsx=1.35) # duplicate texture 1 for the 2nd side texture2 = cmds.duplicate(texture1) cmds.select(texture2) cmds.move(-1.75 / 2, moveY=True, a=True) cmds.rotate(10, rotateY=True, a=True) # combine textures 1 and 2 texture = cmds.polyCBoolOp(texture1, texture2, op=1, ch=False) # add a smaller sphere to round up the texture tmp = cmds.polySphere(r=3.7, sy=13, sx=36) # remove non intersecting parts texture = cmds.polyCBoolOp(texture, tmp, op=3, ch=False) cmds.polyMergeVertex(d=0.05, ch=False) # create another cylinder for the hole tmp = cmds.polyCylinder(r=2, h=3.5) # remove it tire = cmds.polyCBoolOp(tire, tmp, op=2, ch=False) tmp = cmds.polyCylinder(r=2, h=3.5) texture = cmds.polyCBoolOp(texture, tmp, op=2, ch=False) # 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.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move(3.466, moveY=True, a=True) cmds.delete(ch=True) cmds.hyperShade(assign=(nsTmp + ":blckMat")) cmds.namespace(removeNamespace=":" + nsTmp, mergeNamespaceWithParent=True) # create a hub if (createHub == 1): # name nsTmp = "Hub" + str(rnd.randint(1000, 9999)) cmds.select(clear=True) cmds.namespace(add=nsTmp) cmds.namespace(set=nsTmp) # query colour from UI rgb = cmds.colorSliderGrp('hubColour', q=True, rgbValue=True) # base hub = cmds.polyCylinder(r=2.1, h=2.8) # outline tmp = cmds.polyCylinder(r=1.6, h=2.8) hub = cmds.polyCBoolOp(hub, tmp, op=2, ch=False) # inner part of the hub hubIn = cmds.polyCylinder(r=1.6, h=1.8) # center hubCenter = cmds.polyCylinder(r=0.3, h=2.4) hubIn = cmds.polyCBoolOp(hubIn, hubCenter, op=2, ch=False) # decor parts d1 = cmds.polyCylinder(r=0.4, h=2.8) cmds.move(-0.85, moveX=True, a=True) cmds.move(-0.03, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d1, op=1, ch=False) # subtract smaller cylinder inside d1c = cmds.polyCylinder(r=0.3, h=2.9) cmds.move(-0.85, moveX=True, a=True) cmds.move(-0.03, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d1c, op=2, ch=False) d3 = cmds.polyCylinder(r=0.4, h=2.8) cmds.move(-0.422, moveX=True, a=True) cmds.move(0.648, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d3, op=1, ch=False) # subtract smaller cylinder inside d3c = cmds.polyCylinder(r=0.3, h=2.9) cmds.move(-0.422, moveX=True, a=True) cmds.move(0.648, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d3c, op=2, ch=False) d4 = cmds.polyCylinder(r=0.4, h=2.8) cmds.move(0.416, moveX=True, a=True) cmds.move(0.627, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d4, op=1, ch=False) # subtract smaller cylinder inside d4c = cmds.polyCylinder(r=0.3, h=2.9) cmds.move(0.416, moveX=True, a=True) cmds.move(0.627, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d4c, op=2, ch=False) d5 = cmds.polyCylinder(r=0.4, h=2.8) cmds.move(0.835, moveX=True, a=True) cmds.move(-0.049, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d5, op=1, ch=False) # subtract smaller cylinder inside d5c = cmds.polyCylinder(r=0.3, h=2.9) cmds.move(0.835, moveX=True, a=True) cmds.move(-0.049, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d5c, op=2, ch=False) d6 = cmds.polyCylinder(r=0.4, h=2.8) cmds.move(0.431, moveX=True, a=True) cmds.move(-0.692, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d6, op=1, ch=False) # subtract smaller cylinder inside d6c = cmds.polyCylinder(r=0.3, h=2.9) cmds.move(0.431, moveX=True, a=True) cmds.move(-0.692, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d6c, op=2, ch=False) d7 = cmds.polyCylinder(r=0.4, h=2.8) cmds.move(-0.384, moveX=True, a=True) cmds.move(-0.734, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d7, op=1, ch=False) # subtract smaller cylinder inside d7c = cmds.polyCylinder(r=0.3, h=2.9) cmds.move(-0.384, moveX=True, a=True) cmds.move(-0.734, moveZ=True, a=True) hubIn = cmds.polyCBoolOp(hubIn, d7c, op=2, ch=False) # 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.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move(3.466, moveY=True, a=True) cmds.delete(ch=True) cmds.hyperShade(assign=(nsTmp + ":blckMat")) cmds.namespace(removeNamespace=":" + nsTmp, mergeNamespaceWithParent=True)
def tyre(): #get values from UI rgb = cmds.colorSliderGrp('wheelColour', query=True, rgbValue=True) #set up variables radius = 2.85 widthHalf = 2.7 ridgeShapeList = [] innerCircle = cmds.polyPipe( h = widthHalf * 0.7, r = 2.65, t = 1.05 ) outerCircle = cmds.polyPipe( h = widthHalf, r = 2.65, t = 0.85 ) ridge1 = cmds.polyPipe( h = (widthHalf * 0.33)/2, r = 2.85, t = 0.80 ) cmds.move( -0.567, moveY = True) ridge2 = cmds.polyPipe( h = widthHalf * 0.33, r = 2.85, t = 0.80 ) cmds.move( -0.120, moveY = True) tire = cmds.polyCBoolOp( innerCircle, outerCircle, op = 1 )[0] tire = cmds.polyCBoolOp( tire, ridge1, op = 1 )[0] tire = cmds.polyCBoolOp( tire, ridge2, op = 1 )[0] ridgeShape = cmds.polyCube( w = 0.63, h = 0.2, d = 0.2) cmds.move( -0.05, moveY = True) ridgeShapeL = cmds.polyCube( w = 0.2, h = 0.33, d = 0.2, sy = 2)[0] cmds.select( ridgeShapeL+'.vtx[4]', ridgeShapeL+'.vtx[5]') cmds.move( -0.09, moveZ = True ) ridgeShapeR = cmds.duplicate( ridgeShapeL ) cmds.move( -((0.63/2) - 0.1), 0.33/2, 0, ridgeShapeL ) cmds.move( (0.63/2) - 0.1, 0.33/2, 0, ridgeShapeR ) ridgeShape = cmds.polyCBoolOp( ridgeShape, ridgeShapeL, op = 1 )[0] ridgeShape = cmds.polyCBoolOp( ridgeShape, ridgeShapeR, op = 1 )[0] cmds.move( 0, 0.343, radius - 0.14) cmds.move( 0, 0, 0, ridgeShape+".scalePivot", ridgeShape+".rotatePivot", absolute=True) ridgeShapeList.append( ridgeShape ) for i in range( 0, 19): ridgeShape = cmds.duplicate( ridgeShape )[0] cmds.rotate( 0, 18, 0, ridgeShape, r = True ) ridgeShapeList.append( ridgeShape ) ridges = cmds.polyUnite( *ridgeShapeList ) cmds.rotate( 9, rotateY = True ) tireL = cmds.polyUnite( tire, ridges )[0] cmds.rotate( 90, tireL, rotateZ = True ) cmds.move( ((widthHalf / 2)/2), tireL, moveX = True ) tireR = cmds.duplicate( tireL )[0] cmds.scale( -1, scaleY = True ) cmds.move( -((widthHalf / 2)/2), tireL, moveX = True ) tire = cmds.polyUnite( tireR, tireL ) myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) cmds.select( tire ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def axel(): axelHeight = 1 axelWidth = 1 axelLength = cmds.intSliderGrp('axelLength', q=True, v=True) rgb = cmds.colorSliderGrp('blockColour', q=True, rgbValue=True) axelRadius = 0.48 #0.18 base middle, then extrusions 0.15 each side, slightly smaller than axelSizeX = axelWidth * 0.8 axelSizeY = axelHeight * 0.32 axelSizeZ = axelLength * 0.8 if(axelLength == 2): axel = cmds.polyCube(h = 0.18, w=axelSizeZ, d=0.18) cmds.move((axelRadius/2.0), moveY=True, a=True) axelName = cmds.ls(axel)[0] cmds.select(axelName+".f[0]") cmds.select(axelName+".f[1]", add=True) cmds.select(axelName+".f[2]", add=True) cmds.select(axelName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(axel) cmds.polyBevel(sg=2, oaf=True, fn=True) cmds.rotate(90, rotateY=True) #booleans for grooves groove1 = cmds.polyPipe(r=0.25, h=0.25,thickness=0.06) groove2 = cmds.polyPipe(r=0.25, h=0.25,thickness=0.06) cmds.select(groove1) cmds.select(groove2,add=True) cmds.rotate(90,rotateX=True) cmds.move((axelRadius/2.0), moveY=True) cmds.select(groove1) cmds.move(((axelSizeZ/2.0)-0.3), moveZ=True, r=True) cmds.select(groove2) cmds.move(((-axelSizeZ/2.0)+0.3), moveZ=True, r=True) cmds.select(axel) cmds.select(groove1, add=True) cmds.select(groove2, add=True) axel = cmds.polyCBoolOp(op=2, ch=True, n="Axel" + str(rnd.randint(1000,9999))) if(axelLength > 2): axel = cmds.polyCube(h = 0.19, w=axelSizeZ, d=0.19, n="Axel" + str(rnd.randint(1000,9999))) cmds.move((axelSizeY/2.0), moveY=True, a=True) axelName = cmds.ls(axel)[0] cmds.select(axelName+".f[0]") cmds.select(axelName+".f[1]", add=True) cmds.select(axelName+".f[2]", add=True) cmds.select(axelName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(axel) cmds.polyBevel(sg=2, oaf=True, fn=True) cmds.rotate(90, rotateY=True) applyMaterial(axel, rgb) cmds.delete(ch=True)
def hub(wheelRadius): hubRadius = wheelRadius - 1 hubWidth = 3 * 0.8 hubThickness = 0 rgb = cmds.colorSliderGrp('hubColor', q=True, rgbValue=True) outerHub = cmds.polyCylinder(r=hubRadius, h=hubWidth) cmds.move((wheelRadius), moveY=True, a=True) cmds.rotate(90, rotateX=True) innerHubL = cmds.polyCylinder(r=hubRadius-0.3, h=0.6) cmds.move((wheelRadius), moveY=True, a=True) cmds.rotate(90, rotateX=True) cmds.move(1.2,moveZ=True, r=True) innerHubR = cmds.polyCylinder(r=hubRadius-0.3, h=0.6) cmds.move((wheelRadius), moveY=True, a=True) cmds.rotate(90, rotateX=True) cmds.move(-1.2,moveZ=True, r=True) cmds.select(outerHub) cmds.select(innerHubL, add=True) cmds.select(innerHubR, add=True) hub = cmds.polyCBoolOp(op=2, ch=False) cmds.select(clear=True) pairs = [] holeArray = [] hubHoleArray =[] #outer, larger radius, slight indent for i in range(-1,2,2): hole = cmds.polyCylinder(r=0.3, h=0.2, sz=1) cmds.rotate(90, rotateX=True) cmds.move((i*0.8), moveX=True, a=True) cmds.move(-0.9,moveZ=True) pairs.append(hole) hole = cmds.polyCylinder(r=0.3, h=0.2, sz=1) cmds.rotate(90, rotateX=True) cmds.move((i*0.8), moveX=True, a=True) cmds.move(0.9,moveZ=True) pairs.append(hole) for pair in pairs: cmds.select(pair, add=True) pair1 = cmds.polyUnite(ch=False) cmds.select(pair1) pair2 = cmds.duplicate() cmds.rotate(60,rotateZ=True) cmds.select(pair1) pair3 = cmds.duplicate() cmds.rotate(120,rotateZ=True) cmds.select(pair1) cmds.select(pair2,add=True) cmds.select(pair3,add=True) hubIndents = cmds.polyUnite(ch=False) cmds.move(wheelRadius, moveY=True) cmds.select(hub) cmds.select(hubIndents, add=True) indentedHub = cmds.polyCBoolOp(op=2) holePairs = [] for i in range(-1,2,2): hole = cmds.polyCylinder(r=0.25, h=3, sz=1) cmds.rotate(90, rotateX=True) cmds.move(0,moveZ=True) cmds.move((i*0.8), moveX=True, a=True) holePairs.append(hole) cmds.select(clear=True) for pair in holePairs: cmds.select(pair, add=True) holePair1 = cmds.polyUnite(ch=False) cmds.select(holePair1) holePair2 = cmds.duplicate() cmds.rotate(60,rotateZ=True) cmds.select(holePair1) holePair3 = cmds.duplicate() cmds.rotate(120,rotateZ=True) cmds.select(holePair1) cmds.select(holePair2,add=True) cmds.select(holePair3,add=True) hubIndents = cmds.polyUnite(ch=False) cmds.move(wheelRadius, moveY=True) cmds.select(indentedHub) cmds.select(hubIndents, add=True) holedHub = cmds.polyCBoolOp(op=2) cyl = cmds.polyCylinder(r=0.3, h=2.2) cmds.move(0,moveZ=True) cmds.move((wheelRadius), moveY=True, a=True) cmds.rotate(90,rotateX=True) cmds.select(cyl) cmds.select(holedHub, add=True) hub = cmds.polyCBoolOp(op=1) axelHole = cmds.polyCube(h = 0.19, w=2.5, d=0.19) cmds.move(wheelRadius, moveY=True, a=True) holeName = cmds.ls(axelHole)[0] cmds.select(holeName+".f[0]") cmds.select(holeName+".f[1]", add=True) cmds.select(holeName+".f[2]", add=True) cmds.select(holeName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(axelHole) cmds.polyBevel(sg=2, oaf=True, fn=True) cmds.rotate(90, rotateY=True) cmds.select(hub) cmds.select(axelHole,add=True) finalHub = cmds.polyCBoolOp(op=2, n="Hub" + str(rnd.randint(1000,9999))) applyMaterial(finalHub, rgb) cmds.delete(ch=True)
def roundedBlockWithHolesAngle(): # set up block dimensions height = 3 width = 1 #bump bendAngle = cmds.radioButtonGrp('roundedBlockWithHolesBendAngle', q=True, sl=True) if (bendAngle == 1): length = cmds.intSliderGrp('roundedBlockWithHolesAngleLength', q=True, v=True) bendLength = cmds.intSliderGrp('roundedBlockWithHolesAngleBendLength', q=True, v=True) if (bendAngle == 2): length = 4 bendLength = 3 rgb = cmds.colorSliderGrp('roundedBlockWithHolesAngleColour', q=True, rgbValue=True) # name nsTmp = "RoundedBlockWithHolesAngle" + str(rnd.randint(1000, 9999)) cmds.select(clear=True) cmds.namespace(add=nsTmp) cmds.namespace(set=nsTmp) # define cubes size cubeSizeX = width * 0.8 cubeSizeZ = length * 0.8 cubeSizeY = height * 0.32 bendSizeZ = bendLength * 0.8 # create a cube cube = cmds.polyCube(h=cubeSizeY, w=cubeSizeX, d=cubeSizeZ) # move it up cmds.move((cubeSizeY / 2.0), moveY=True) # create holes for i in range(width): for j in range(length): # create cylinder in the place of a hole hole = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((i * 0.8) - (cubeSizeX / 2.0) + 0.4), moveX=True, a=True) cmds.move(((j * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) # remove it from the base block cube = cmds.polyCBoolOp(cube, hole, op=2, caching=False, ch=False) # add cylinders to round corners # right side rCylind = cmds.polyCylinder(r=cubeSizeY * 0.5, h=cubeSizeX) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeX / 2.0 + 0.079), moveY=True, a=True) cmds.move((-cubeSizeZ * 0.5), moveZ=True, a=True) # merge right cylinder with cube cube = cmds.polyCBoolOp(cube, rCylind, op=1, caching=False, ch=False) # add a hole rHole = cmds.polyCylinder(r=0.25, h=height / 2.0) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeX / 2.0) + 0.4), moveX=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) cube = cmds.polyCBoolOp(cube, rHole, op=2, caching=False, ch=False) # left side lCylind = cmds.polyCylinder(r=cubeSizeY * 0.5, h=cubeSizeX) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeX / 2.0 + 0.079), moveY=True, a=True) cmds.move((cubeSizeZ * 0.5), moveZ=True, a=True) # merge left cylinder with cube cube = cmds.polyCBoolOp(cube, lCylind, op=1, caching=False, ch=False) # create a hole lHole = cmds.polyCylinder(r=0.25, h=height / 2.0) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((width * 0.8) - cubeSizeX), moveX=True, a=True) cmds.move(((length * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) cube = cmds.polyCBoolOp(cube, lHole, op=2, caching=False, ch=False) # create a second cube for bend if (bendAngle == 1): # at 90 degrees cubeBend = cmds.polyCube(h=cubeSizeY, w=cubeSizeX, d=bendSizeZ) cmds.rotate(90, rotateX=True, a=True) # move it up cmds.move((bendSizeZ / 2.0), moveY=True) # add cylinder to its end endCylind = cmds.polyCylinder(r=cubeSizeY * 0.5, h=cubeSizeX) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((bendSizeZ), moveY=True, a=True) # merge cube with cylinder cubeBend = cmds.polyCBoolOp(cubeBend, endCylind, op=1, caching=False, ch=False) # move bended cube to cube's end cmds.move((-cubeSizeZ / 2), moveZ=True, a=True) # move it up a bit cmds.move(0.5, moveY=True) # add holes to bended part # create holes for i in range(width): for j in range(bendLength): # create cylinder in the place of a hole bHole = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeX / 2.0) + 0.4), moveX=True, a=True) cmds.move(((j * 0.8) + (cubeSizeY / 2.0)), moveY=True, a=True) # remove it from the base block cubeBend = cmds.polyCBoolOp(cubeBend, bHole, op=2, caching=False, ch=False) # create the last hole endHole = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) cmds.move((((bendLength) * 0.8) + (cubeSizeY / 2.0)), moveY=True, a=True) # remove it from end cylinder cubeBend = cmds.polyCBoolOp(cubeBend, endHole, op=2, caching=False, ch=False) if (bendAngle == 2): # bend at 60 degrees # create a cube for bend cubeBend = cmds.polyCube(h=cubeSizeY, w=cubeSizeX, d=bendSizeZ) # move & rotate cmds.move((cubeSizeY), moveY=True) cmds.rotate(60, rotateX=True, a=True) cmds.move((0 - (cubeSizeZ / 2.0) + 1.04), moveZ=True, a=True) # add cylinder to its end endCylind = cmds.polyCylinder(r=cubeSizeY * 0.5 + 0.01, h=cubeSizeX) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((bendSizeZ - 0.4), moveY=True, a=True) cmds.move((-bendSizeZ / 2 + 0.04), moveZ=True, a=True) # merge cube with cylinder cubeBend = cmds.polyCBoolOp(cubeBend, endCylind, op=1, caching=False, ch=False) # move bended cube to cube's end cmds.move((-cubeSizeZ / 2), moveZ=True, a=True) # move it up a bit cmds.move(0.5, moveY=True) # add holes to bended part # create holes # HOLE ONE (from bottom) hole1 = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move(cubeSizeY / 2, moveY=True, a=True) cmds.move(-cubeSizeZ / 2.0, moveZ=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeX * 0.5) + 0.4), moveX=True, a=True) # remove it from the base block cubeBend = cmds.polyCBoolOp(cubeBend, hole1, op=2, caching=False, ch=False) # HOLE TWO hole2 = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move(1.129, moveY=True, a=True) cmds.move(-1.994, moveZ=True, a=True) # remove it from the base block cubeBend = cmds.polyCBoolOp(cubeBend, hole2, op=2, caching=False, ch=False) # HOLE THREE hole3 = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move(1.834, moveY=True, a=True) cmds.move(-2.363, moveZ=True, a=True) # remove it from the base block cubeBend = cmds.polyCBoolOp(cubeBend, hole3, op=2, caching=False, ch=False) # HOLE FOUR endHole = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move(-2.741, moveZ=True, a=True) cmds.move(2.49, moveY=True, a=True) # remove it from end cylinder cubeBend = cmds.polyCBoolOp(cubeBend, endHole, op=2, caching=False, ch=False) # 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.delete(ch=True) cmds.hyperShade(assign=(nsTmp + ":blckMat")) cmds.namespace(removeNamespace=":" + nsTmp, mergeNamespaceWithParent=True)
def createHoles(block, blockDepth, blockSizeX, blockSizeY, blockSizeZ, axelHoles, holeOffset, holeOffsetZ): beam = block #Holes are offset on reg blocks (in between bumps) if(holeOffset == True): holeArray = [] for i in range(blockDepth-1): #outer, larger radius, slight indent hole = cmds.polyCylinder(r=0.3, h=0.1, sz=1) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move(((blockSizeY/2.0) + 0.1), moveY=True, a=True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+ holeOffsetZ), moveZ=True, a=True) cmds.move((blockSizeX/2.0), moveX = True, a = True) holeArray.append(hole) #same as above, other side of block hole = cmds.polyCylinder(r=0.3, h=0.1, sz=1) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move(((blockSizeY/2.0) +0.1), moveY=True, a=True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+ holeOffsetZ), moveZ=True, a=True) cmds.move((-1*(blockSizeX/2.0)), moveX = True, a = True) holeArray.append(hole) #smaller radius, full way through block hole = cmds.polyCylinder(r=0.25, h=blockSizeX, sz=1) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move(((blockSizeY/2.0) + 0.1), moveY=True, a=True) cmds.move(((i * 0.8) - (blockSizeZ/2.0) + holeOffsetZ), moveZ=True, a=True) holeArray.append(hole) cmds.select(beam) for hole in holeArray: cmds.select(hole, add=True) finalBlock = cmds.polyCBoolOp(op=2) #Holes on rounded beams are not offset, are flush with rounded ends else: #if no axel holes if(axelHoles == 0): start = 0 end = 1 if(axelHoles ==1): start = 1 end = 1 if(axelHoles ==2): start = 1 end = 0 holeArray = [] for i in range(start, blockDepth+end): #outer, larger radius, slight indent hole = cmds.polyCylinder(r=0.3, h=0.1, sz=1) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move((blockSizeY/2.0), moveY=True, a=True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+ holeOffsetZ), moveZ=True, a=True) cmds.move((blockSizeX/2.0), moveX = True, a = True) holeArray.append(hole) #same as above, other side of block hole = cmds.polyCylinder(r=0.3, h=0.1, sz=1) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move((blockSizeY/2.0), moveY=True, a=True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+ holeOffsetZ), moveZ=True, a=True) cmds.move((-1*(blockSizeX/2.0)), moveX = True, a = True) holeArray.append(hole) #smaller radius, full way through block hole = cmds.polyCylinder(r=0.25, h=blockSizeX, sz=1) cmds.rotate(90, rotateX=True) cmds.rotate(90, rotateY=True) cmds.move((blockSizeY/2.0), moveY=True, a=True) cmds.move(((i * 0.8) - (blockSizeZ/2.0)+ holeOffsetZ), moveZ=True, a=True) holeArray.append(hole) if(axelHoles == 1): cmds.select(clear=True) #each part of axel shape - 0.19 #each oart comes out 0.15 #total axle diameter = 0.48, axle hole diam = 0.49 hole = cmds.polyCube(h = 0.19, w=2, d=0.19) cmds.move((blockSizeY/2.0), moveY=True, a=True) cmds.move((((-blockSizeZ)/2.0)+ holeOffsetZ), moveZ=True, a=True) holeName = cmds.ls(hole)[0] cmds.select(holeName+".f[0]") cmds.select(holeName+".f[1]", add=True) cmds.select(holeName+".f[2]", add=True) cmds.select(holeName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(hole) cmds.polyBevel(sg=2, oaf=True, fn=True) holeArray.append(hole) if(axelHoles == 2): cmds.select(clear=True) hole = cmds.polyCube(h = 0.19, w=2, d=0.19) cmds.move((blockSizeY/2.0), moveY=True, a=True) cmds.move((((-blockSizeZ)/2.0)+ holeOffsetZ), moveZ=True, a=True) holeName = cmds.ls(hole)[0] cmds.select(holeName+".f[0]") cmds.select(holeName+".f[1]", add=True) cmds.select(holeName+".f[2]", add=True) cmds.select(holeName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(hole) cmds.polyBevel(sg=2, oaf=True, fn=True) holeArray.append(hole) cmds.select(clear=True) hole = cmds.polyCube(h = 0.19, w=2, d=0.19) cmds.move((blockSizeY/2.0), moveY=True, a=True) cmds.move((((blockSizeZ)/2.0)- holeOffsetZ), moveZ=True, a=True) holeName = cmds.ls(hole)[0] cmds.select(holeName+".f[0]") cmds.select(holeName+".f[1]", add=True) cmds.select(holeName+".f[2]", add=True) cmds.select(holeName+".f[3]", add=True) cmds.polyExtrudeFacet(lt=(0,0,0.15), kft=False) cmds.select(hole) cmds.polyBevel(sg=2, oaf=True, fn=True) holeArray.append(hole) cmds.select(beam) for hole in holeArray: cmds.select(hole, add=True) #punch holes through rounded block finalBlock = cmds.polyCBoolOp(op=2, ch=False, n="Block" + str(rnd.randint(1000,9999))) return finalBlock
def brick(): #get values from UI brickLength = cmds.intSliderGrp( 'brickLength', query = True, value = True) brickWidth = cmds.intSliderGrp( 'brickWidth', query = True, value = True) brickHeight = cmds.intSliderGrp('brickHeight', query = True, value = True) flatBrick = cmds.checkBox('flatBrickCheck', query = True, value = True) brickStuds = cmds.radioButtonGrp( 'brickStudOptions', query = True, select = True) brickHoles = cmds.radioButtonGrp( 'brickHoleOptions', query = True, select = True) rgb = cmds.colorSliderGrp('brickColour', query=True, rgbValue=True) transparent = cmds.checkBox('makeTransparent', query = True, value = True) #set up variables brickList = [] studList = [] if brickHoles == 1: holeOffset = 0.8 holeNum = brickWidth - 1 else: holeOffset = 0.4 holeNum = brickWidth brickSizeX = brickWidth * 0.8 brickSizeZ = brickLength * 0.8 if( flatBrick == True ): brickSizeY = 0.32 elif( flatBrick == False ): brickSizeY = 0.96 #create brick for h in range ( brickHeight ): brick = cmds.polyCube( h = brickSizeY, w = brickSizeX, d = brickSizeZ ) cmds.move( ( brickSizeY / 2 ), brick, moveY = True ) if( brickHoles == 1 or brickHoles == 2 ): brick = createBlockHoles( brickSizeX, brickSizeY, brick, holeNum, holeOffset ) cmds.makeIdentity(apply=True, t=1, r=1, s=1, n=0) cmds.move( ( brickSizeY * h ), brick, moveY = True, a = True ) brickList.append( brick ) if( len( brickList ) > 1 ): brick = cmds.polyUnite( *brickList ) else: brick = brickList[0] if( brickStuds == 1 or brickStuds == 2 ): for l in range ( brickLength ): for w in range( brickWidth ): stud = cmds.polyCylinder( h = 0.18, r = 0.24 ) if( brickStuds == 1 ): studCut = cmds.polyCylinder( h = 0.18, r = 0.15 ) stud = cmds.polyCBoolOp( stud, studCut, op = 2 ) cmds.move(((w * 0.8) - (brickSizeX/2.0) + 0.4 ), moveX = True, a = True) cmds.move((brickSizeY * brickHeight) + (0.18/2), moveY = True, a = True) cmds.move(((l * 0.8) - (brickSizeZ/2.0) + 0.4), moveZ = True, a = True) studList.append( stud ) studs = cmds.polyUnite( *studList ) brick = cmds.polyUnite( studs, brick ) myShader = cmds.shadingNode( 'phong', asShader=True ) cmds.setAttr( myShader+".color", rgb[0], rgb[1], rgb[2], type='double3') cmds.setAttr( myShader+".reflectivity", 0 ) if( transparent == True ): cmds.setAttr( myShader+".transparency", 0.5, 0.5, 0.5, type = 'double3' ) cmds.select( brick ) cmds.hyperShade( assign = myShader ) cmds.delete( ch = True )
def defaultBooleanPush(*args): cmds.polyCBoolOp(op=1, n='result') print 'boolean action'
def roundedBlockWithHoles(): # set up block dimensions height = 3 width = 1 #bump length = cmds.intSliderGrp('roundedBlockWithHolesLength', q=True, v=True) rgb = cmds.colorSliderGrp('roundedBlockWithHolesColour', q=True, rgbValue=True) # name nsTmp = "RoundedBlockWithHoles" + str(rnd.randint(1000, 9999)) cmds.select(clear=True) cmds.namespace(add=nsTmp) cmds.namespace(set=nsTmp) # define cube's size cubeSizeX = width * 0.8 cubeSizeZ = length * 0.8 cubeSizeY = height * 0.32 # create a cube cube = cmds.polyCube(h=cubeSizeY, w=cubeSizeX, d=cubeSizeZ) # move it up cmds.move((cubeSizeY / 2.0), moveY=True) # create holes for i in range(width): for j in range(length): # create cylinder in the place of a hole hole = cmds.polyCylinder(r=0.25, h=height / 2.0) # rotate and position it cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((i * 0.8) - (cubeSizeX / 2.0) + 0.4), moveX=True, a=True) cmds.move(((j * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) # remove it from the base block cube = cmds.polyCBoolOp(cube, hole, op=2, caching=False, ch=False) # add cylinders to round corners # right side rCylind = cmds.polyCylinder(r=cubeSizeY * 0.5, h=cubeSizeX) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeX / 2.0 + 0.079), moveY=True, a=True) cmds.move((-cubeSizeZ * 0.5), moveZ=True, a=True) # create a hole in it rHole = cmds.polyCylinder(r=0.25, h=height / 2.0) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeX / 2.0) + 0.4), moveX=True, a=True) cmds.move(((0 * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) rCylind = cmds.polyCBoolOp(rCylind, rHole, op=2, caching=False, ch=False) # left side lCylind = cmds.polyCylinder(r=cubeSizeY * 0.5, h=cubeSizeX) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeX / 2.0 + 0.079), moveY=True, a=True) cmds.move((cubeSizeZ * 0.5), moveZ=True, a=True) # create a hole in it lHole = cmds.polyCylinder(r=0.25, h=height / 2.0) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((width * 0.8) - cubeSizeX), moveX=True, a=True) cmds.move(((length * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) lCylind = cmds.polyCBoolOp(lCylind, lHole, op=2, caching=False, ch=False) # subtract a cylinder from left side of the cube lCubeHole = cmds.polyCylinder(r=0.25, h=height / 2.0) cmds.rotate(90, rotateX=True, a=True) cmds.rotate(90, rotateY=True, a=True) cmds.move((cubeSizeY / 2.0), moveY=True, a=True) cmds.move(((width * 0.8) - cubeSizeX), moveX=True, a=True) cmds.move(((length * 0.8) - (cubeSizeZ / 2.0)), moveZ=True, a=True) cube = cmds.polyCBoolOp(cube, lCubeHole, op=2, caching=False, ch=False) # 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.delete(ch=True) cmds.hyperShade(assign=(nsTmp + ":blckMat")) cmds.namespace(removeNamespace=":" + nsTmp, mergeNamespaceWithParent=True)