예제 #1
0
def finalizeTread(*args):    
    """This function creates a wire deformer that drives the shape of the mesh with a curve"""

    # Here we make wire deformer
    def makeWire(geo, CCurve, dropOffD=10):
        theWire = cmds.wire(geo, w=CCurve, n ="inputWire")
        wireNode = theWire[0]
        data.treadBaseWire = "{}BaseWire".format(CCurve)
        data.treadBaseWire = checkDuplicatedName(data.treadBaseWire)
        
        # Change dropoff distance
        cmds.setAttr("%s.dropoffDistance[0]"%wireNode, dropOffD)
    
    makeWire(data.treadMesh, data.treadCircle, 35)
    
    cmds.select(data.treadCircle, r=True)

    # Use point on curve deformation
    locatorPoints = addPointOnCurve()

    # Use result locators to add controllers to them
    controlGroups = controlOnLocator("curvePointCtrl", *locatorPoints)

    # Group the circle and base wire for organization
    wireCurvesGroup = cmds.group(data.treadCircle, data.treadBaseWire, name="TreadWireDeform")
    
    # Create main controller
    data.mainController = makeMainController()
    data.mainController = checkDuplicatedName(data.mainController)

    data.mainControllerGroup = cmds.group(data.mainController, name="TreadMainControllerGroup")

    cmds.select(data.mainControllerGroup, data.treadMesh)
    # Align the circle to the mesh
    cmds.align(x="mid", z="mid", alignToLead=True)

    # Parent curve controllers to main controller
    cmds.parent(controlGroups[0], data.mainController)
    cmds.parent(controlGroups[1], data.mainController)

    # Constraint curves and mesh to main controller to rotate properly due to wire deformer
    cmds.select(data.mainController,data.treadMesh)
    cmds.orientConstraint(maintainOffset=True)
    cmds.select(data.mainController, wireCurvesGroup)
    cmds.orientConstraint(maintainOffset=True)

    # Make the tread rotate with main controller
    rotationExpression()

    # Delete locators
    cmds.delete(data.firstLocator, data.secondLocator)

    # Save this rigging data to the rigging node
    data.writeToNode()
예제 #2
0
def tv():

    #group MODULE
    mir = random.randint(0, 19)
    crazyR = random.randint(0, 1000)
    tvBase = 'TvBase' + str(mir) + str(crazyR)
    tv = 'Tv' + str(mir) + str(crazyR)
    cmds.group(n=tvBase, em=True)
    cmds.group(n=tv, em=True)
    base_heigh = 0.5
    base_width = 4
    stick_height = 2
    tv_width = cmds.intSliderGrp(slider4, q=True, value=True)

    #base:
    base = cmds.polyCube(h=base_heigh, w=base_width, depth=2)
    cmds.polyBevel3(base, offset=0.1)
    stick = cmds.polyCube(h=stick_height, w=base_width / 2, depth=0.5)
    # cmds.move(0,base_heigh/2,base_width/4)
    cmds.select(base, stick)
    cmds.align(x='mid', y='dist', atl=True)
    cmds.parent(base, stick, tvBase)
    #tv screen:
    screen = cmds.polyCube(h=tv_width / 2, w=tv_width, depth=0.2)
    cmds.polyBevel3(screen, offset=0.02)
    cmds.select(base, screen)
    cmds.align(y='stack', atl=True)
    cmds.select(stick, screen)
    cmds.align(y='stack', atl=True)
    # cmds.move(0,-base_heigh/20.0,-base_width/10.0)
    cmds.parent(tvBase, screen, tv)
예제 #3
0
def makeTread(*args):
    """This function creates the circle that represent the tread"""

    # Get the position from both locators
    loc1Pos = cmds.getAttr("{}.translateZ".format(data.firstLocator))
    loc2Pos = cmds.getAttr("{}.translateZ".format(data.secondLocator))
    locDistance = abs(loc1Pos-loc2Pos)
    data.curveRadius = locDistance/2.0
    locCenter = (loc1Pos+loc2Pos)/2.0
    
    # Create the curve
    curveQuality = cmds.intSliderGrp("curveQuality", q=True, v=True)
    data.treadCircle = cmds.circle(name="TreadCurve", radius=data.curveRadius, nr=(1,0,0), sections=curveQuality)[0]
    data.treadCircle = checkDuplicatedName(data.treadCircle)
    
    # ****************************************** Here we align the circle to the locators ********************************************
    
    # Create a group containing the locators
    locatorGroup = cmds.group(data.firstLocator, data.secondLocator, n="LocGroup")

    # Select the circle
    cmds.select(data.treadCircle)

    # Select the group
    cmds.select(locatorGroup, add=True)

    # Align the circle to the group
    cmds.align(x="mid", y="mid", z="mid", alignToLead=True)

    # Unparent the locators
    cmds.parent(data.firstLocator, data.secondLocator, world=True)
    # Delete the locator group
    cmds.delete(locatorGroup)
    
    # Finish selecting the curve
    cmds.select(data.treadCircle)
    cmds.FreezeTransformations()
    cmds.DeleteHistory()
예제 #4
0
def wheelSelection(*args):
    """This functiion groups the wheels and adds a locator to control their rotation"""

    # Get the list of selected objects
    wheelSet = cmds.ls(selection=True)
    
    # Group the selected objects
    data.wheelGroup = cmds.group(name="WheelsGroup")
    # Create locator controller
    locatorName = checkDuplicatedName("WheelsController")
    data.mainController = cmds.spaceLocator(name=locatorName)[0]

    cmds.scale(4.0,4.0,4.0)

    data.mainControllerGroup = cmds.group(name="WheelsControllerGroup")
    
    # Align locator to group
    cmds.select(data.wheelGroup, add=True)
    cmds.align(xAxis="mid", yAxis="max", zAxis="mid", alignToLead=True)
    cmds.select(data.mainController)

    # *************************** Connection editor way *********************************
    # It is not ideal because there is no way to control the rotation speed
    '''
    for wheel in wheelSet:
        cmds.connectAttr("WheelsCtrl.tz", "{}.ry".format(wheel))
        '''
    
    # Get the speed from the slider
    rotationSpeed = cmds.floatSliderGrp(makeWindow.RotSpeed, q=True, v=True)

    # Add expression to control wheels
    for wheel in wheelSet:
        myExpression = cmds.expression(name="WheelSetRotation", string="{}.rotateX = {}.translateZ*{}".format(wheel, data.mainController, rotationSpeed))
        cmds.parentConstraint(data.mainController, wheel, maintainOffset=True, skipRotate="x")

    data.writeToNode()
	def locators(self, *args):
		''' Locator(s) function. Independent from the __init__ module. '''

		selection= cmds.ls( sl=True, fl=True )

		parentSelection = cmds.checkBox( self.locCheckBoxes[0], value= True, query= True )
		addAdditionalGroups = cmds.checkBox( self.locCheckBoxes[1], value= True, query= True )
		selNaming = cmds.checkBox( self.locCheckBoxes[2], value= True, query= True )
		alpha = string.uppercase
		object= []
		locators= []

		AboveAlphabet = False
		vtxSel = False

		if not selection:
			om.MGlobal.displayWarning('Please select a normalform object or a vertex component.')
			sys.exit()


		if selNaming == False:
			locName = cmds.textField( self.locTexts, query= True, tx=1 )

			if not locName:
				om.MGlobal.displayWarning('Cannot have an empty text field!.')
				sys.exit()


			

		print '---------------------------------------------'

		try:

			if selection[0].split('.')[1].split('[')[0] == 'vtx':
				print 'Selection is a vertex.'

				object = selection[0].split('.')[0]
	
				if selNaming == True:
					locName= 'geo_%s_grp'%selection[0].split('.')[0]

	
				vtxSel = True

		except:

			pass

		if cmds.nodeType(selection[0]) == 'normalform':
			print 'Selection is a normalform.'

		if addAdditionalGroups == True:
			print 'Adding additional groups:  %s'%addAdditionalGroups

		if selNaming == True:
			print 'Use naming from selection:  %s'%selNaming

		if selNaming == False:
			print 'Use naming from textField:  %s'%selNaming

		if parentSelection == True:
			print 'Parenting selections:  %s'%parentSelection


		# Create locators in the center of geos.
		if vtxSel == False:

			if (len( selection ) < 26) == True:
				AboveAlphabet = False
				print "%s is greater than 25: %s"%( len(selection), AboveAlphabet)
	
			if (len( selection ) > 26) == True:
				AboveAlphabet = True
				print "%s is greater than 26: %s"%( len(selection), AboveAlphabet)



			for index, eachSel in enumerate(selection):
				

				if cmds.getAttr( '%s.tx'%eachSel, k=0, l=1 ):

					cmds.setAttr( '%s.tx'%eachSel, k=1, l=0 )
					cmds.setAttr( '%s.ty'%eachSel, k=1, l=0 )
					cmds.setAttr( '%s.tz'%eachSel, k=1, l=0 )

				if cmds.getAttr( '%s.tx'%eachSel, k=1, l=0 ):

					# Alphabet has 26 letters. If selection is > 26, do numbers.
					if selNaming == True:

						locName = eachSel

						if "_grp" in eachSel:
							locName.replace( "_grp", "" )


						if "_GRP" in eachSel:
							locName.replace( "_GRP", "" )


						if "_GP" in eachSel:
							locName.replace( "_GP", "" )

						if "_gp" in eachSel:
							locName.replace( "_gp", "" )


						if AboveAlphabet == False:
							point= cmds.spaceLocator( name= '%s%s_grp'%( locName, alpha[index] ) )

						if AboveAlphabet == True:
							point= cmds.spaceLocator( name= '%s%s_grp'%( locName, index ) )



					if selNaming == False:



						if AboveAlphabet == False:
							point= cmds.spaceLocator( name= '%s%s_grp'%( locName, alpha[index] ) )

						if AboveAlphabet == True:
							point= cmds.spaceLocator( name= '%s%s_grp'%( locName, index ) )
					

					cmds.align( point, eachSel, xAxis='mid', yAxis='mid', zAxis='mid', atl=True )

					print 'Created a locator for: %s'%eachSel


				if addAdditionalGroups == True:

					rename = point[0].replace( "_grp", "" )
					dupl= cmds.duplicate( point, name = rename + '_plug' )

					cmds.select(clear=True)
					originGrp= cmds.group( name= '%s_zro'%rename, em=True, world=True )
					cmds.parent( originGrp, dupl )

					cmds.delete( cmds.listRelatives( dupl, shapes=True )[0] )

					cmds.parent( dupl, point )


				if parentSelection == True:

					if addAdditionalGroups == False:
						cmds.parent( eachSel, point )

					if addAdditionalGroups == True:
						cmds.parent( eachSel, originGrp )


				locators.append( point )

			cmds.select(clear=True)
			for eachLoc in locators:
				cmds.select( eachLoc, tgl=True )

			# End of len(selection) function of locator method.
			print '---------------------------------------------'
			
		
		# Create locators with aim constrained towards a vertex.
		if vtxSel == True:

			if len(selection) == 1:

				vertexA= selection[0].split('.')[1].split('[')[1].split(']')[0].split(':')[0]
				print selection[0].split('.')[0] + '.vtx[%s]'%vertexA

				Target0= cmds.xform( selection[0].split('.')[0] + '.vtx[%s]'%vertexA, translation=True, worldSpace=True, query=True )

				point= cmds.spaceLocator( name= locName )

				cmds.xform( point, translation= Target0 )

				if addAdditionalGroups == True:

					rename = point[0].replace( "_grp", "" )
					dupl= cmds.duplicate( point, name = rename + '_plug' )

					cmds.select(clear=True)
					originGrp= cmds.group( name= '%s_zro'%rename, em=True, world=True )
					cmds.parent( originGrp, dupl )

					cmds.delete( cmds.listRelatives( dupl, shapes=True )[0] )

					cmds.parent( dupl, point )


				if parentSelection == True:

					if addAdditionalGroups == False:
						cmds.parent( object, point )

					if addAdditionalGroups == True:
						cmds.parent( object, originGrp )

					cmds.select( point )


				print( ' Created a locator on a vertex:  %s'%selection[0].split('.')[1] )


			if len(selection) == 2:

				start= cmds.spaceLocator( name='start_placer_loc' )
				end= cmds.spaceLocator( name='end_placer_loc' )

				point= cmds.spaceLocator( name= locName )

				locList= cmds.ls( start, end )

				target0= cmds.xform( selection[0], translation=True, worldSpace=True, query=True )
				target1= cmds.xform( selection[1], translation=True, worldSpace=True, query=True )

				cmds.xform( start, ws=1, t= target0 )
				cmds.xform( end, ws=1, t= target1 )

				cmds.pointConstraint( start, end, point, maintainOffset=False )
				cmds.aimConstraint( start, point, maintainOffset=False )


				cmds.delete(start, end)


				if addAdditionalGroups == True:

					rename = point[0].replace( "_grp", "" )
					dupl= cmds.duplicate( point, name = rename + '_plug' )

					cmds.select(clear=True)
					originGrp= cmds.group( name= '%s_zro'%rename, em=True, world=True )
					cmds.parent( originGrp, dupl )

					cmds.delete( cmds.listRelatives( dupl, shapes=True )[0] )

					cmds.parent( dupl, point )


				if parentSelection == True:

					if addAdditionalGroups == False:
						cmds.parent( object, point )

					if addAdditionalGroups == True:
						cmds.parent( object, originGrp )

					cmds.select( point )



			if len(selection) > 2:

				# Credit: Marc English for the boundingbox.
				point= cmds.spaceLocator( name= locName )


				bbox =  cmds.exactWorldBoundingBox(selection)	

				x = (bbox[0] + bbox[3]) / 2	
				y = (bbox[1] + bbox[4]) / 2	
				z = (bbox[2] + bbox[5]) / 2


				cmds.setAttr( point ,x,y,z)


				if addAdditionalGroups == True:

					rename = point[0].replace( "_grp", "" )
					dupl= cmds.duplicate( point, name = rename + '_plug' )

					cmds.select(clear=True)
					originGrp= cmds.group( name= '%s_zro'%rename, em=True, world=True )
					cmds.parent( originGrp, dupl )

					cmds.delete( cmds.listRelatives( dupl, shapes=True )[0] )

					cmds.parent( dupl, point )


				if parentSelection == True:

					if addAdditionalGroups == False:
						cmds.parent( object, point )

					if addAdditionalGroups == True:
						cmds.parent( object, originGrp )

					cmds.select( point )


			print( ' Created a locator between two vertices:  %s'%point )

			print '---------------------------------------------'
예제 #6
0
    def create(self):

        print("asset path: ", self.assetspath)

        blankdocument = self.assetspath + '/MayaProject.ma'

        print("Document path: ", blankdocument)

        # Open your file
        self.render_file = cmds.file(blankdocument, o=True)

        cmds.file(new=True, f=True)
        cmds.file(rn=blankdocument)

        # Open Shot List
        views = []
        newviews = []

        # Placeholder Object
        cmds.polyCube(n='placeholder')
        cmds.group('placeholder', n='ProductGroup')
        cmds.move(0, 1, 0)
        cmds.select('placeholder')
        cmds.CenterPivot('placeholder')

        # Import OBJ from Agisoft
        ModelPath = self.assetspath + '/output/model.obj'
        cmds.file(ModelPath, i=True)
        cmds.select('Mesh')
        cmds.CenterPivot('Mesh')
        cmds.select('Mesh', 'placeholder')
        cmds.align(x='mid', y='mid', z='mid', alignToLead=True)
        cmds.group('Mesh', p='ProductGroup')

        # Delete Placeholder
        cmds.delete('placeholder')

        # Key Model Positions
        with open(self.assetspath + '/shotListConfig.txt') as inf:

            # Identify all elements in view column
            for line in inf:
                parts = line.split()
                if len(parts) > 1:
                    s = parts[3]
                    views.append(s)

            # replace tqt elements with angle
            for idx, item in enumerate(views):
                if item == 'tqt':
                    views[idx] = '0_45_0'
                    print(views)

            # Remove the header line
            views.pop(0)

            # Replace _ with , for each element
            angles = ([view.replace('_', ',') for view in views])

            # Remove Duplicates
            for i in angles:
                if i not in newviews:
                    newviews.append(i)

            # Define Frames
            frame = 0
            view = []

            # Assign X, Y & Z values from the first 3 elements
            for view in newviews:
                viewsplit = view.split(",")
                x = viewsplit[0]
                y = viewsplit[1]
                z = viewsplit[2]

                # Move frame forward one
                frame += 1
                # Print New Frame
                print(frame)

                # Set Key Frame with new X,Y & Z values on new time frame
                cmds.rotate(x, y, z, 'ProductGroup')
                cmds.setKeyframe('ProductGroup', time=frame)

                # Print X,Y & Z Values
                print("x= " + x)
                print("y= " + y)
                print("z= " + z)

        # Create Lights
        cmds.directionalLight(n='key', intensity=.2, rs=True)
        cmds.rotate(-45, -45, 0)
        cmds.scale(10, 10, 10)
        cmds.setAttr("keyShape.lightAngle", 5)
        cmds.setAttr("keyShape.shadowRays", 15)

        # Create Camera
        cam = cmds.camera(n='maincamera', ff='vertical')
        cmds.move(0, 1, 12)
        width = 512
        height = 512
        cmds.setAttr('defaultResolution.deviceAspectRatio',
                     ((width) / (height)))
        cmds.setAttr('maincameraShape2.backgroundColor', 1, 1, 1)
        cmds.setAttr('maincameraShape2.focalLength', 85)

        # Group Scene
        cmds.group('maincamera1', 'key', n='Scene')

        # Group ALL
        cmds.group('Scene', 'ProductGroup', n='ALL')

        # Save File
        cmds.file(rename=self.render_file)
        cmds.file(save=True, type='mayaAscii')
예제 #7
0
# get position from locators
pelvisPos = cmds.xform('COG', query=True, worldSpace=True, translation=True)
hipPos = cmds.xform('hip', query=True, worldSpace=True, translation=True)
kneePos = cmds.xform('knee', query=True, worldSpace=True, translation=True)
anklePos = cmds.xform('ankle', query=True, worldSpace=True, translation=True)
ballPos = cmds.xform('ball', query=True, worldSpace=True, translation=True)
toePos = cmds.xform('toe', query=True, worldSpace=True, translation=True)

pvKneeLoc = cmds.spaceLocator(n='KneeLocTemp')
pvCtrlLoc = cmds.spaceLocator(n='pvKneeCtrlLoc')
cmds.parent(pvCtrlLoc, pvKneeLoc)

cmds.delete(cmds.pointConstraint('hip', 'ankle', pvKneeLoc))
cmds.select(pvKneeLoc, 'knee')
cmds.align(x='mid', alignToLead=True)
cmds.align(y='mid', alignToLead=True)
cmds.move(0, 0, 20, pvCtrlLoc, localSpace=True)
cmds.select(clear=True)

# make bind joints
pelvisJnt = cmds.joint(name='pelvis',
                       absolute=True,
                       radius=2,
                       position=pelvisPos)

hipJnt = cmds.joint(name=si + un + 'hip',
                    absolute=True,
                    radius=2,
                    position=hipPos)
kneeJnt = cmds.joint(name=si + un + 'knee',
예제 #8
0
	def create(self):
		
		print ("asset path: ", self.assetspath)

		blankdocument = self.assetspath+'/MayaProject.ma'
		
		print ("Document path: ", blankdocument)

		# Open your file
		self.render_file = cmds.file(blankdocument, o=True)

		cmds.file(new=True,f=True)
		cmds.file(rn=blankdocument)
		
		# Open Shot List
		views = []
		newviews = []		

		# Placeholder Object
		cmds.polyCube(n='placeholder')
		cmds.group('placeholder',n='ProductGroup')
		cmds.move(0,1,0)
		cmds.select('placeholder')
		cmds.CenterPivot('placeholder')

		# Import OBJ from Agisoft
		ModelPath = self.assetspath+'/output/model.obj'
		cmds.file(ModelPath, i=True)
		cmds.select('Mesh')
		cmds.CenterPivot('Mesh')
		cmds.select('Mesh','placeholder')
		cmds.align(x='mid',y='mid',z='mid',alignToLead=True)
		cmds.group('Mesh',p='ProductGroup')

		# Delete Placeholder
		cmds.delete('placeholder')
		
		# Key Model Positions
		with open(self.assetspath+'/shotListConfig.txt') as inf:
			  		
			# Identify all elements in view column		
			for line in inf:
				parts = line.split() 
				if len(parts) > 1:   
					s = parts[3]
					views.append(s)
					
			# replace tqt elements with angle 
			for idx, item in enumerate(views):
				if item == 'tqt':
					views[idx] = '0_45_0'
					print (views)  			
					
			# Remove the header line		
			views.pop(0)
			
			# Replace _ with , for each element
			angles = ([view.replace('_', ',') for view in views])
			
			# Remove Duplicates
			for i in angles:
				if i not in newviews:
					newviews.append(i)
							
			# Define Frames
			frame = 0
			view = []
			
			# Assign X, Y & Z values from the first 3 elements 
			for view in newviews:
				viewsplit = view.split(",")
				x = viewsplit[0]
				y = viewsplit[1]
				z = viewsplit[2]
				
				# Move frame forward one
				frame += 1
				# Print New Frame
				print (frame)
				
				# Set Key Frame with new X,Y & Z values on new time frame
				cmds.rotate( x, y, z, 'ProductGroup' )
				cmds.setKeyframe('ProductGroup',time=frame)
				
				# Print X,Y & Z Values
				print ("x= " + x)
				print ("y= " + y)
				print ("z= " + z)		

		# Create Lights
		cmds.directionalLight(n='key',intensity=.2,rs=True)
		cmds.rotate(-45,-45,0)
		cmds.scale(10,10,10)
		cmds.setAttr("keyShape.lightAngle",5)
		cmds.setAttr("keyShape.shadowRays",15)

		# Create Camera 
		cam = cmds.camera(n='maincamera',ff='vertical')
		cmds.move(0,1,12)
		width = 512
		height = 512
		cmds.setAttr( 'defaultResolution.deviceAspectRatio', ( ( width ) / ( height ) ) )
		cmds.setAttr('maincameraShape2.backgroundColor',1,1,1)
		cmds.setAttr('maincameraShape2.focalLength', 85)

		# Group Scene
		cmds.group('maincamera1','key', n='Scene')

		# Group ALL
		cmds.group('Scene','ProductGroup',n='ALL')

		# Save File
		cmds.file(rename=self.render_file)
		cmds.file( save=True, type='mayaAscii' )