Пример #1
0
def createTrackwayVisualization(trackway):

    references = []

    for foot in trackway:
        references.extend(createMarchingSphere(foot))

    references.append(createHipsIndicator(trackway))
    references.append(createShoulderIndicator(trackway))

    group = cmds.group(*references, world=True, name=name)
    cmds.select(group)

    applyShaders(trackway)
    createRenderEnvironment()

    minTime = min(0, int(cmds.playbackOptions(query=True, minTime=True)))
    maxTime = trackway.duration

    cmds.playbackOptions(
        minTime=minTime, animationStartTime=minTime,
        maxTime= maxTime, animationEndTime=maxTime)

    cmds.currentTime(0, update=True)
    cmds.select(group)
Пример #2
0
def zbw_stepAll():
    sel = cmds.ls(sl=True)
    keyList = []
    keySet = set()
    allKeys = []
    #get timeslider range start
    startF = cmds.playbackOptions(query=True, min=True)
    #get end frame
    endF = cmds.playbackOptions(query=True, max=True)
    #get all the keyed frames
    for this in sel:
        keyList = cmds.keyframe(this, query=True, time=(startF,endF))
        for key in keyList:
            key = int(key)
            keySet.add(key)
    #print keyList
    keySet = set(keyList)
    for frame in keySet:
        allKeys.append(frame)

    allKeys.sort()
    allKeys.reverse()
    #print allKeys

    for object in sel:
        for thisKey in allKeys:
            cmds.currentTime(thisKey)
            cmds.setKeyframe(object, t=thisKey, ott="step")
Пример #3
0
 def store(self):
     '''
     store animation
     '''
     # make sure o
     if self.poseOnly:
         self.mtrx.append(cmds.xform(self.obj, q=True, m=True, ws=True))
     else:
         if self.keys:
             current = cmds.currentTime(q=True)
             # ui off
             cn.uiEnable(controls='modelPanel')
             # autokey state
             autoK = cmds.autoKeyframe(q=True, state=True)
             cmds.autoKeyframe(state=False)
             for key in self.keys:
                 cmds.currentTime(key)
                 self.pos.append(cmds.xform(self.obj, q=True, rp=True, ws=True))
                 self.rot.append(cmds.xform(self.obj, q=True, ro=True, ws=True))
                 self.mtrx.append(cmds.xform(self.obj, q=True, m=True, ws=True))
             # restore everything
             cmds.currentTime(current)
             cmds.autoKeyframe(state=autoK)
             cn.uiEnable(controls='modelPanel')
         else:
             message('No keys, forcing timeline range.', maya=True)
             self.keys = range(int(self.rng.start), int(self.rng.end))
             self.rng.keyStart = self.rng.start
             self.rng.keyEnd = self.rng.end
             self.store()
Пример #4
0
def buildGhostAnimation(*args):
    
    obj = 'ghost_body1'

    # get animation start and end points from ui controls
    animation_start = cmds.intField('animation_start', query=True, value=True)
    animation_end   = cmds.intField('animation_end', query=True, value=True)

    for current_time in range(animation_start, animation_end + 1):
        
        cmds.currentTime(current_time, edit=True)
        locatorPos = cmds.xform('character_locator', q=1, t=True)
        
        x = round(locatorPos[0], 2)
        z = round(locatorPos[2], 2)

        if x % 1 == 0.25 or z % 1 == 0.25:
            cmds.xform(obj, rotation = [0, 11.25, 0])
        elif x % 1 == 0.5 or z % 1 == 0.5:
            cmds.xform(obj, rotation = [0, 22.5, 0])
        elif x % 1 == 0.75 or z % 1 == 0.75:
            cmds.xform(obj, rotation = [0, 33.75, 0])
        elif x % 1 == 0 or z % 1 == 0:
            cmds.xform(obj, rotation = [0, 0, 0])
        else:
            assert False, "Unhandled character position"

        cmds.setKeyframe([obj])
Пример #5
0
def exportDeformAnimation(folder):
    '''Use MDD file to export defrom animation.'''
    minframe = int( mc.playbackOptions(q = True, min = True) )
    maxframe = int( mc.playbackOptions(q = True, max = True) )
    totalframes = maxframe - minframe + 1
    t = mc.currentUnit(q = True, t = True)
    fps = _mfps[t]
    
    parts = []
    selectionList = mo.MSelectionList()
    mo.MGlobal.getActiveSelectionList(selectionList)
    itList = mo.MItSelectionList(selectionList, mo.MFn.kTransform)
    while not itList.isDone():
        path = mo.MDagPath()
        itList.getDagPath(path)
        partialName = str(path.partialPathName())
        name = partialName.split(":")[-1]
        part = MDD(name, mo.MFnMesh(path), totalframes, fps)
        parts.append(part)
        itList.next()
    # add animation
    for frame in range(minframe, maxframe + 1):
        mc.currentTime(frame, edit = True)
        for p in parts:
            p.addFrame()
            
    # write files
    for p in parts:
        p.writeToFile(folder)
        print "write %s done." % p.name
    print "All is done."
    return True
Пример #6
0
def exportSgKeyData( targetTransformNodes, startFrame, endFrame, step, folderPath=None, exportByMatrix=False, *args ):
    
    import sgBFunction_scene
    import copy
    
    if step < 0.05:
        cmds.error( "Step Must be larger then %.f." % step )
    
    sgBFunction_base.autoLoadPlugin( "sgBDataCmd" )
    if not folderPath: folderPath = sgBFunction_fileAndPath.getDefaultSgKeyDataPath()
    sgBFunction_fileAndPath.makeFolder( folderPath )
    sgBFunction_fileAndPath.removeChildFiles( folderPath )
    
    targetTransformNodeParents = []
    for transformNode in targetTransformNodes:
        targetTransformNodeParents += sgBFunction_dag.getParents( transformNode )
        targetTransformNodeParents.append( transformNode )
    targetTransformNodeParents = list( set( targetTransformNodeParents ) )
    
    sgBFunction_scene.exportTransformData( targetTransformNodeParents, folderPath )
    
    cmds.sgBDataCmd_key( targetTransformNodes, se=1, folderPath= folderPath, ebm=exportByMatrix )
    
    cuTime = copy.copy( startFrame )
    
    while cuTime <= endFrame+1:
        cmds.currentTime( cuTime )
        cmds.sgBDataCmd_key( write=1 )
        cuTime += step

    cmds.sgBDataCmd_key( ee=1 )
Пример #7
0
 def __uicb_setReferenceBwavNode(self, *args):
     '''
     : PRO_PACK : set the internal reference offset used to offset the audionode. 
     
     .. note::
         If you pass this a bwav then it caches that bwav for use as the offset. 
         If you pass it a node, and that node has the timecode attrs, then it caches the offset itself.
     '''
     selectedAudio=cmds.ls(sl=True, type='audio')
     self.__bwav_reference = None
     self.__cached_tc_offset = None
     if selectedAudio:
         if not len(selectedAudio)==1:
             log.warning("Please only select 1 piece of Audio to use for reference")
             return
         reference=AudioNode(selectedAudio[0])
         if reference.isBwav():
             self.__bwav_reference=selectedAudio[0]
             cmds.text('bwavRefTC', edit=True,
                       label='frame %s == %s' % (reference.startFrame,reference.bwav_timecodeFormatted()))
         else:
             raise IOError("selected Audio node is NOT a Bwav so can't be used as reference")
     else:
         selectedNode = cmds.ls(sl=True,l=True)
         if len(selectedNode)==1:
             relativeTC = self.pro_audio.Timecode(selectedNode[0]).getTimecode_from_node()
             actualframe = cmds.currentTime(q=True)
             self.__cached_tc_offset = actualframe - self.pro_audio.timecode_to_frame(relativeTC)
             cmds.text('bwavRefTC', edit=True,
                       label='frame %s == %s' % (cmds.currentTime(q=True), relativeTC))
         else:
             log.warning("No reference audio track selected for reference")
         return
def dsEmitAlongLocator(start,end,ss):
    y = start
    x = end
    cmds.currentTime(y)
    
    locX = cmds.getAttr('locator1.translateX')
    locY = cmds.getAttr('locator1.translateY')
    locZ = cmds.getAttr('locator1.translateZ')
    beforePos = [locX,locY,locZ]
    
    while y <= x:
        cmds.currentTime(y)
        locX = cmds.getAttr('locator1.translateX')
        locY = cmds.getAttr('locator1.translateY')
        locZ = cmds.getAttr('locator1.translateZ')
        pos = [locX,locY,locZ]
        
        dist = [pos[0]-beforePos[0],pos[1]-beforePos[1],pos[2]-beforePos[2]]
        val = [dist[0]/ss,dist[1]/ss,dist[2]/ss]

        for i in range(ss):
            beforePos = [beforePos[0]+val[0],beforePos[1]+val[1],beforePos[2]+val[2]]
            cmds.emit( object='trail_pt', pos=(beforePos))
            
        beforePos = pos
        y = y + 1
Пример #9
0
	def applyToObj( self, obj=None, applyAsWorld=False, clearFirst=False ):
		'''applies the current clip to an object - if the animation is being applied as world space, first check to make
		sure the world space animation for the clip exists.  then separate the transform channels out of the channels list
		and apply them as world space data.  then we need to apply the rest of the channels as per normal'''
		if obj is None:
			obj = self.obj

		if applyAsWorld and self.hasWorld:
			for matrix in self.world:
				cmd.currentTime(matrix.time)
				tfn = OpenMaya.MFnTransform( api.getMDagPath(obj) )
				tfn.set( OpenMaya.MTransformationMatrix( key[0] ) )

			'''nonTransformChannels = []
			for channel in self.channels:
				if channel.attr not in g_validWorldAttrs: nonTransformChannels.append(channel)

			frames = self.as_frames(transformChannels)
			for channel in self.world:
				tgtAttrpath = obj +'.'+ channel.attr
				channel.applyToObj(obj,applyAsWorld)

			#run a euler filter over the resulting rotation animation - converting to world space
			#rotations often causes all sorts of nasty euler flips
			maya.mel.eval('filterCurve %s.rx %s.ry %s.rz;'%(obj,obj,obj))

			for channel in transformChannels:
				channel.applyToObj(obj)'''
		else:
			for channel in self.channels.values():
				channel.applyToObj(obj,clearFirst=clearFirst)
def nuke_track_node():
	"""
	creates a nuke track node for the selected transform.
	selection order: trasnform, camera
	"""
	
	selection	= cmds.ls( selection = True )
	point		= selection[0]
	camera		= selection[1]
	cameraShape	= cmds.listRelatives( shapes = True )[0]
	aperture_h	= cmds.camera( camera, hfa=1, q=1)
	aperture_v	= cmds.camera( camera, vfa=1, q=1)
	trackNode	= 'Tracker3 { track1 {{curve x1 '
	tx			= ''
	ty			= ''
	endframe	= 48
	
	for frame in range( 1, endframe + 1 ):
		cmds.currentTime( frame )
		fov_h	= cmds.camera( camera, hfv=1, q=1)
		fov_v	= cmds.camera( camera, vfv=1, q=1)
		track	= get_normalized_screen_position( point, camera, fov_h, fov_v, aperture_h, aperture_v )
		tx		+= str( track[0] * 1280 ) + ' '
		ty		+= str( track[1] * 720 ) + ' '

	trackNode += tx + '} {curve x1 ' + ty + '}}}'
	print '#' * 50
	print '>>> tracker node, copy paste to nuke:'
	print trackNode
Пример #11
0
def pathAnimPose(root='', i=0, length=0, ns='', point=''):
    # point number
    # i = i + 1
    # number of point controls
    pathControls = 47
    # number of points left
    numOfCt = pathControls - i
    # print numOfCt, '___controls'
    # print length, '___length'
    # print length / numOfCt, '___frame'
    # advance every nframe
    nframe = 1
    # if frame length is larger than points left, skip frames
    if length > numOfCt:
        nframe = int(round(float(length) / float(numOfCt), 0))
    # print nframe, '__________'
    pnt = ''
    while i <= 47:
        current = cmds.currentTime(q=True)
        cmds.currentTime(current + nframe)
        t = cmds.xform(root, q=True, ws=True, t=True)
        n = pad(i)
        pnt = ns + ':' + point + n
        # print pnt
        # print cmds.currentTime(current + nframe)
        cmds.xform(pnt, ws=True, t=t)
        i = i + 1
    def exportAbc(self, root, frameRange=(1,24), suffix="", **kargs):

        self.__abc_files.append(expandFileName('testAnimParticleReadWrite_%s.abc' % suffix))

        # seed on first frame
        cmds.currentTime(1)
        maya.mel.eval("seed(1)")
        
        # First, eval time from one to frameRange start to avoid a possible jump
        for i in range(1,frameRange[0]):
            cmds.currentTime(i)


        # Format argument for extra atrbutes
        argStr = " "
        for item in kargs:
            if isinstance(kargs[item], (tuple,list)):
                for element in kargs[item]:
                    argStr += " -%s %s" % ( item, element )
            else:
               argStr += " -%s %s" % ( item, kargs[item] )

        # Export
        stdoutWrite("writefile: %s" % self.__abc_files[-1])
        cmds.AbcExport(j='-fr %d %d -root %s %s -file ' % (frameRange[0], frameRange[1], root, argStr) + self.__abc_files[-1] )
Пример #13
0
def changeToLastFrame(currentFrame):
    removeBoxesFromView(currentFrame)
    cmds.currentTime( currentFrame - 1, edit = True, update= True)
    showNewBoxesInView(frame = int(cmds.currentTime( query=True )))
    cmds.textField(g_currentFrameField,e=True,ip=1,tx=currentFrame-1)
    global g_currentFrame
    g_currentFrame = currentFrame-1
Пример #14
0
 def _plotter_avrg(self):
     '''plots a locator to a vertice or face per keyframe in a timeline'''
     selObj=cmds.ls(sl=1, fl=1)      
     if len(selObj)>0:
         pass
     else:
         print "Select 1 object" 
         return     
     getTopRange=cmds.playbackOptions(q=1, max=1)+1#get framerange of scene to set keys in iteration 
     getLowRange=cmds.playbackOptions(q=1, min=1)-1#get framerange of scene to set keys in iteration 
     edgeBucket=[]
     getRange=arange(getLowRange,getTopRange, 1 )
     getloc=cmds.spaceLocator(n=selObj[0]+"cnstr_lctr")
     cmds.normalConstraint(selObj[0], getloc[0])
     placeloc=cmds.spaceLocator(n=selObj[0]+"lctr")
     for each in getRange:
         cmds.currentTime(each)            
         transform=cmds.xform(selObj, q=1, ws=1, t=1)
         posBucketx=self.array_median_find(transform[0::3])
         posBuckety=self.array_median_find(transform[1::3])
         posBucketz=self.array_median_find(transform[2::3])
         cmds.xform(getloc[0], ws=1, t=(posBucketx, posBuckety, posBucketz))  
         cmds.SetKeyTranslate(getloc[0])
         cmds.xform(placeloc[0], ws=1, t=(posBucketx, posBuckety, posBucketz))
         cmds.SetKeyTranslate(placeloc[0])               
         rotate=cmds.xform(getloc[0], q=True, ws=1, ro=True)
         cmds.xform(placeloc[0], ws=1, ro=rotate)  
         cmds.SetKeyRotate(placeloc[0])
         cmds.currentTime(each)            
Пример #15
0
	def exportObjects(self):
		for object in self.objects:
			cmds.select(object, r= True)
	
			if self.exportType == 1:
				fileType = 'Fbx'
				cmds.loadPlugin('fbxmaya', qt= True)
				melCmd.eval('FBXExportShowUI -v false;')
			else:
			  fileType = 'OBJexport'
			  cmds.loadPlugin('objExport', qt= True)
			
			if bool(self.exportGeometrySequence) == bool(True):
				startF = self.startFrame
				endF = self.endFrame 
			else:
				startF = endF = cmds.currentTime( query=True )
			
			nameExtension = ''
			exportName = object.replace(':', '_')
			
			for timevalue in range(startF, (endF+1), 1):
				if bool(self.exportGeometrySequence) == bool(True):
					nameExtension = '.%04d' % timevalue 
				cmds.currentTime(timevalue)
				if self.exportType == 1:
					melCmd.eval('FBXExport -f "' + self.exportPath + exportName + nameExtension + '.fbx" -s')
				else:
					cmds.file(self.exportPath+exportName+nameExtension, op='', typ=fileType, pr=True, es=True )  

			print 'Exported: ' + object;
Пример #16
0
    def exportAndRender(self,
                        renderDir,
                        renderSettings,
                        mitsubaPath,
                        oiiotoolPath,
                        mtsDir, 
                        keepTempFiles,  
                        animation, 
                        frame=None, 
                        verbose=False):

        if frame != None:
            # Calling this can lead to Maya 2016 locking up if you don't have MAYA_RELEASE_PYTHON_GIL set
            # See Readme
            cmds.currentTime(float(frame))
        else:
            frame = 1

        sceneName = self.getScenePrefix()

        scenePrefix = cmds.getAttr("defaultRenderGlobals.imageFilePrefix")
        if scenePrefix is None:
            scenePrefix = sceneName

        outFileName = os.path.join(renderDir, "%s.xml" % scenePrefix)

        # Export scene and geometry
        geometryFiles = MitsubaRendererIO.writeScene(outFileName, renderDir, renderSettings)

        # Render scene, delete scene and geometry
        imageName = self.renderScene(outFileName, renderDir, mitsubaPath, oiiotoolPath,
            mtsDir, keepTempFiles, geometryFiles, animation, frame, verbose,
            renderSettings)

        return imageName
Пример #17
0
 def export(self, selection):
     """start the export procedure"""
     # save settings
     self.saveSettings()
     if self.items:
         # get display values and turn them off
         UTILS.getDisplayItems()
         UTILS.setDisplayOff()
         # get the output path from the textfield
         outputFile = self.textfieldValidator(cmds.textField(self.textField, text=True, q=True))
         createScene = False
         if outputFile:
             # generate the nuke script
             EXPORTER = exporter.Exporter(self.items, outputFile, self.framerange, False)
             EXPORTER.startExport()
         else:
             cmds.confirmDialog(t='Error', m='The output file is not correct.\nex: /<path>/nukefile.nk')
         # set display back on
         UTILS.setDisplayOn()
         # set playback at the original frame
         cmds.currentTime(self.framerange['current'])
         # select original selection
         if self.originalSel:
             cmds.select(self.originalSel, r=True)
         
     else:
         cmds.confirmDialog(t='Error', m='There is nothing to export!')
    def testAnimMeshReload(self):

        MayaCmds.polyCube( name = 'mesh')
        MayaCmds.setKeyframe('meshShape.vtx[0:7]', time=[1, 24])
        MayaCmds.setKeyframe('meshShape.vtx[0:7]')
        MayaCmds.currentTime(12, update=True)
        MayaCmds.select('meshShape.vtx[0:7]')
        MayaCmds.scale(5, 5, 5, r=True)
        MayaCmds.setKeyframe('meshShape.vtx[0:7]', time=[12])
        self.__files.append(util.expandFileName('testAnimMeshReadWrite.abc'))
        MayaCmds.AbcExport(j='-fr 1 24 -root mesh -f ' + self.__files[-1])

        # reading test
        MayaCmds.AbcImport(self.__files[-1], mode='open')

        # save as a maya file
        self.__files.append(util.expandFileName('test.mb'))
        MayaCmds.file(rename=self.__files[-1])
        MayaCmds.file(save=True)

        # reload as a maya file
        MayaCmds.file(self.__files[-1], open=True)
        MayaCmds.AbcImport(self.__files[-2], mode='import')

        retVal = True
        mesh1 = '|mesh|meshShape'
        mesh2 = '|mesh1|meshShape'
        for t in range(1, 25):
            MayaCmds.currentTime(t, update=True)
            if not util.compareMesh( mesh1, mesh2 ):
                self.fail('%s and %s were not equal at frame %d' % (mesh1,
                    mesh2, t))
Пример #19
0
 def change_visibility(self, btn, frame):
     """Changes the visibility of the sculpts."""
     table = self.uif.get_object_table(btn)
     obj = self.uif.get_object_tab(table)
     btn_row, btn_column = self.uif.get_row_column(btn)
     show = False
     for row in range(table.rowCount()):
         button = table.cellWidget(row, btn_column)
         if row == btn_row:
             if not button.isChecked():
                 button.setText('Original')
                 button.setStyleSheet('QToolButton{color:#ddd;}')
                 self.show_hide_sculpt(table, row, False)
                 show = True
             else:
                 button.setText('Sculpt')
                 button.setStyleSheet('QToolButton{color:#000;}')
                 self.show_hide_sculpt(table, row, True)
         else:
             button.setChecked(False)
             button.setText('Original')
             button.setStyleSheet('QToolButton{color:#ddd;}')
             self.show_hide_sculpt(table, row, False)
     # end for row in range(table.rowCount())
     self.show_original(obj[1], show)
     if not show:
         cmds.currentTime(frame)
         sculpt = table.item(btn_row, self.column_name).text()
         trans = self.get_transform_dag_path(obj[1], sculpt)
         if len(cmds.ls(sl=True, l=True)) > 0:
             if cmds.ls(sl=True, l=True)[0] != trans:
                 cmds.select(trans, r=True)
Пример #20
0
 def setUp(self):
     cmds.file(new=1, f=1)
     self.cube = cmds.polyCube()[0]
     for i in xrange(1,21,2):
         cmds.currentTime(i)
         pm.setAttr(self.cube + '.tx', i)
         pm.setKeyframe(self.cube + '.tx')
Пример #21
0
    def __exit__(self, *exc_info):

        cmds.autoKeyframe(state=self.autoKeyState)
        cmds.currentTime(self.time)

        if self.selection:
            cmds.select(self.selection)
 def LoadJointMotionPaths( self, roots ):
     """ prep the data structure that holds the motion paths """
     animPaths = {}
     for root in roots:
         animPaths[root] = {}
         self.trace[root] = Trajectory("%sTrace"%root)
         # find all nearby joints
         joints = [j for j in mc.listRelatives( root, allDescendents=True ) if j in self.traceableObjs]  # TODO: just get the nearby joints by projecting them all onto the viewing plane and finding the distance
         # get the motion path of each nearby joint
         if len(joints) > 0:
             for j in joints:
                 animPaths[root][j] = Trajectory( "%s_path"%j )
                 if debug > 0:
                     mc.group(name="%sGrp"%j,empty=True)
     
     startFrame = mc.playbackOptions(q=True,minTime=True)
     endFrame = mc.playbackOptions(q=True,maxTime=True)+1
     for t in [float(x)/self.substeps+startFrame for x in range(0, int(endFrame-startFrame)*self.substeps)]:
         mc.currentTime(t)
         for root in roots:
             joints = [j for j in mc.listRelatives( root, allDescendents=True ) if j in self.traceableObjs]
             for j in joints:
                 point = Vector( mc.xform(j, q=True, ws=True, t=True) ) 
                 animPaths[root][j].AddPoint( point, t )
                 if debug > 0:
                     loc = mc.spaceLocator(p=point)
                     mc.parent(loc,"%sGrp"%j)
             self.trace[root].SetSearchList( animPaths[root] )
Пример #23
0
def refresh():
    cmds.undoInfo(stateWithoutFlush=False)
    # cmds.refresh(force=True)
    # print "refresh"
    cmds.refresh(suspend=False)
    cmds.currentTime(cmds.currentTime(query=True), edit=True)
    cmds.undoInfo(stateWithoutFlush=True)
Пример #24
0
    def setUp(self):
        MayaCmds.file(new=True, force=True)
        self.__files = []

        # write out an animated Alembic file
        createAnimatedSolarSystem()
        self.__files.append(util.expandFileName("testAnimatedSolarSystem.abc"))
        MayaCmds.AbcExport(j="-fr 1 24 -root group1 -root group2 -file " + self.__files[-1])

        # write out a static Alembic file that's different than the static scene
        # created by createStaticSolarSystem()
        MayaCmds.currentTime(12, update=True)
        self.__files.append(util.expandFileName("testStaticSolarSystem.abc"))
        MayaCmds.AbcExport(j="-fr 12 12 -root group1 -root group2 -file " + self.__files[-1])

        # write out an animated mesh with animated parent transform node
        MayaCmds.polyPlane(sx=2, sy=2, w=1, h=1, ch=0, n="polyMesh")
        MayaCmds.createNode("transform", n="group")
        MayaCmds.parent("polyMesh", "group")

        # key the transform node
        MayaCmds.setKeyframe("group", attribute="translate", t=[1, 4])
        MayaCmds.move(0.36, 0.72, 0.36)
        MayaCmds.setKeyframe("group", attribute="translate", t=2)

        # key the mesh node
        MayaCmds.select("polyMesh.vtx[0:8]")
        MayaCmds.setKeyframe(t=[1, 4])
        MayaCmds.scale(0.1, 0.1, 0.1, r=True)
        MayaCmds.setKeyframe(t=2)
        self.__files.append(util.expandFileName("testAnimatedMesh.abc"))
        MayaCmds.AbcExport(j="-fr 1 4 -root group -file " + self.__files[-1])

        MayaCmds.file(new=True, force=True)
Пример #25
0
def bake_camera(node):
        print 'baking camera '+str(node)+'...', 
        camera_info = get_camera_info(node)

        newCamera = cmds.camera()
        
        for frame in camera_info['frames']:
            cmds.currentTime(frame)
            # set matrix
            cmds.xform(newCamera[0], m=camera_info['matrix.'+str(frame)])
            cmds.setAttr(newCamera[1]+'.focalLength', camera_info['focal.'+str(frame)])
            cmds.setAttr(newCamera[1]+'.horizontalFilmAperture', camera_info['hap.'+str(frame)])
            cmds.setAttr(newCamera[1]+'.verticalFilmAperture', camera_info['vap.'+str(frame)])
            cmds.setAttr(newCamera[1]+'.horizontalFilmOffset', camera_info['hfo.'+str(frame)])
            cmds.setAttr(newCamera[1]+'.verticalFilmOffset', camera_info['vfo.'+str(frame)])
            # set keyframes
            cmds.setKeyframe(newCamera[0]+'.tx')
            cmds.setKeyframe(newCamera[0]+'.ty')
            cmds.setKeyframe(newCamera[0]+'.tz')
            cmds.setKeyframe(newCamera[0]+'.rx')
            cmds.setKeyframe(newCamera[0]+'.ry')
            cmds.setKeyframe(newCamera[0]+'.rz')
            cmds.setKeyframe(newCamera[1]+'.focalLength')
            cmds.setKeyframe(newCamera[1]+'.horizontalFilmAperture')
            cmds.setKeyframe(newCamera[1]+'.verticalFilmAperture')
            cmds.setKeyframe(newCamera[1]+'.horizontalFilmOffset')
            cmds.setKeyframe(newCamera[1]+'.verticalFilmOffset')
        print 'created '+str(newCamera)+',',
Пример #26
0
def frameSection(nudge=24):

    curvesShown = cmds.animCurveEditor("graphEditor1GraphEd", query=True, curvesShown=True)
    if not curvesShown:
        return

    firstSelKey = cmds.keyframe(selected=True, query=True, timeChange=True)
    # lastKey     = max(cmds.keyframe(selected=False, query=True, timeChange=True))
    lastKey = cmds.playbackOptions(query=True, maxTime=True)

    if firstSelKey:  # if key is selected
        firstSelKey = min(firstSelKey)
    else:
        # firstSelKey = min(cmds.keyframe(selected=False, query=True, timeChange=True))
        firstSelKey = cmds.playbackOptions(query=True, minTime=True)

        try:
            if G.AM_lastFrameSection + nudge < lastKey and G.AM_lastCurvesShown == curvesShown:
                firstSelKey = G.AM_lastFrameSection + nudge
        except:
            pass

    G.AM_lastFrameSection = firstSelKey
    G.AM_lastCurvesShown = curvesShown

    framePlaybackRange.framePlaybackRangeFn(rangeStart=(firstSelKey - 1), rangeEnd=(firstSelKey + nudge + 2))
    cmds.currentTime(firstSelKey, edit=True)
Пример #27
0
def walkParticlesProjection(camera, particles, step=1, start=None, end=None, pBar=None):
    if start is None:
        start = cmds.playbackOptions(q=True, minTime=True)
    if end is None:
        end   = cmds.playbackOptions(q=True, maxTime=True)
    start = int(start)
    end   = int(end)
        
    #pStep = 0 if pBar is None else int(100 / (end - start + 1))
    pStep = 1

    coords = None
    
    for frame in xrange(start, end + 1):
        #log("... FRAME %d ..." % frame)
        cmds.currentTime(frame)
        
        points = getParticlesProjection(camera, particles, step)
        pid    = 0

        if coords is None:
            coords = [None] * len(points)
        
        for point in points:
            if coords[pid] is None:
                coords[pid] = [None] * (end - start + 1)
                
            coords[pid][frame - start] = point
            pid += 1
            
        if pBar:
            cmds.progressBar(pBar, e=1, s=pStep)
    
    return coords
Пример #28
0
 def setObjectToShatterCmd(self, *args):
     '''
     
     '''
     if not (cmds.draggerContext(self._IScontextTool._mContext, exists = True)):
         
         iMinTime = cmds.playbackOptions(query = True, minTime = True)
         cmds.currentTime(iMinTime, edit = True)       
         
         polySelection = cmds.filterExpand(selectionMask = 12)
         if polySelection:            
             
             if len(polySelection) > 0:                   
                 
                 mBreakNode = cmds.listConnections(polySelection[0], sh = True, type = 'fxBreakGeometry')
                 if not mBreakNode:
                     
                     cmds.button(self._ISaddBtn, edit = True, label = 'Please wait... checking mesh toplogy')
                     self._IScontextTool.checkForNonManifoldMeshes(polySelection[0])
                     cmds.delete(polySelection[0], ch = True)                    
                 
                 self.resetIShatterGUI()
                 self._IScontextTool._mVoroObject = polySelection[0]                
                 cmds.button(self._ISaddBtn, edit = True, label = polySelection[0])
                 cmds.button(self._ISdelBtn, edit = True, enable = True)
                 cmds.button(self._ISprocessBtn, edit = True, enable = True)
                 cmds.checkBox(self._ISborderEdgesCbx, edit = True, enable = True)
                 cmds.checkBox(self._IShideObjectsCbx, edit = True, enable = True)                                                                                                  
                 
         else:
             cmds.confirmDialog(title = 'Oups... IShatter Error', message = 'You must select one mesh object first !', button = 'OK', defaultButton = 'Yes', cancelButton = 'No', dismissString = 'No')            
Пример #29
0
def set_vertex_position(getVtxPosOfFrame = 101):
    '''
    This method sets the vertex positions 
    of the mesh by the vertex positions at the 
    specified frameNumber 
    '''

    #Cloudy:SF_C_hatSculpt138918980693
    #Cloudy:C_hat_PLY

    #--- get the selected object
    sel = cmds.ls(selection = True)
    #--- get the current frame
    current_frame = cmds.currentTime(query = True)
    #--- jump to the specified frame
    cmds.currentTime(getVtxPosOfFrame)

    #--- get the vertex positions of the selected mesh
    for i in sel:
        #--- get the original mesh, verts and vert positions
        original_mesh = i.split('SF')[0] + i.split('SF_')[-1].split('Sculpt')[0] + '_PLY' 
        original_vert = cmds.ls(original_mesh + '.vtx[*]', flatten = True)
        original_pos = []
        for v in original_vert:
            pos = cmds.xform(v, query = True, translation = True, worldSpace = True)
            original_pos.append(pos)

        #--- go to the initial frame
        cmds.currentTime(current_frame)
        #--- set the vertex positions of the sculpt mesh
        sculpt_vert = cmds.ls(i + '.vtx[*]', flatten = True)
        for v, pos in zip(sculpt_vert, original_pos):
            cmds.xform(v, translation = pos, worldSpace = True)
Пример #30
0
def createKeyFrames(numFrames, boundary):
	'''create the keyframes for the animation'''
	for frame in range(numFrames):
		cmds.currentTime( frame, edit=True )
		for b in boids:

			# How to stop a running maya script:
			# When a script is running in maya, Everything
			# freezes and maya does not repond to input.
			# To get around this maya has to be stopped from
			# the outside. This if-statement looks for a empty file
			# named "stop.maya" anywhere you want in your filesystem.
			# If it is found, maya exits the script. To stop a script,
			# just add this file to your defined path and it exits. When
			# you want to start the script again, just rename it to something
			# else, eg: run.maya.
			if os.path.isfile('C:\\dev\\stop.maya'):
				sys.exit()

			neighborhood = getNeighborhood(b)
			alignment(b, neighborhood)
			separation(b, neighborhood)
			cohesion(b, neighborhood)
			boundary.avoidWalls(b)
			followPath(b)
			obstacleAvoidance(b)
			wander(b)
			b.move(dt)
			b.setKeyFrame(frame)
Пример #31
0
def SetCurrentRotKey(node, inTangent=TAN_LINEAR, outTangent=TAN_LINEAR):
    """ Set rotation keyframe with current value and current time """
    rotation = cmds.getAttr('%s.rotate' % node)[0]
    time = cmds.currentTime(query=True)
    SetRotKeyframe(node, rotation, time, inTangent, outTangent)
 def time_line_operations(self):
     checker = self.sender().objectName()
     if 'play' in checker:
         cmds.play(forward=True)
     if 'rewind' in checker:
         cmds.currentTime(int(cmds.playbackOptions(minTime=True)))
Пример #33
0
    cmds.setAttr('left_L.rx', -angle)
    cmds.setKeyframe(at='rotateX')

    cmds.select('leg_R')
    cmds.setAttr('leg_R.rx', angle)
    cmds.setKeyframe(at='rotateX')


def change_height(height):

    cmds.select('Lego_Group')
    cmds.setAttr('Lego_Group.ty', height)
    cmds.setKeyframe(at='translateY')


ctime = cmds.currentTime(query=True)

cmds.select('Lego_Group')
cmds.setAttr('Lego_Group.tz', 0)
cmds.setKeyframe(at='translateZ')

for index in range(1, 5):

    rotate_limbs(0)
    change_height(0)

    ctime += 5
    cmds.currentTime(ctime)
    rotate_limbs(90)
    change_height(3)
Пример #34
0
def SetCurrentPosKey(node, inTangent=TAN_LINEAR, outTangent=TAN_LINEAR):
    """ Set position keyframe with current value and current time """
    position = cmds.getAttr('%s.translate' % node)[0]
    time = cmds.currentTime(query=True)
    SetPosKeyframe(node, position, time, inTangent, outTangent)
Пример #35
0
def calcFinalRotation(sourceJ, targetJ, key):
    #Isolate rotation from keyframe
    cmds.currentTime(0)
    sBindPose = sourceJ.getRotation().asMatrix()
    invrsBindPose = sBindPose.inverse()
    cmds.currentTime(key)

    #Isolated Rotation
    kI = invrsBindPose * sourceJ.getRotation().asMatrix()

    #Convert rotation to standard coordinate space

    sBO = sourceJ.getOrientation().asMatrix()
    sBO2 = sBO.inverse()

    #Get Parents
    sBPOmtx = dt.Matrix()

    sParent = sourceJ.getParent()
    if (sParent != None):
        cmds.currentTime(0)
        sBPO = getParentsBPO(sourceJ, sBPOmtx)
        cmds.currentTime(key)
        sBPO2 = sBPO.inverse()
    else:
        sBPO = dt.Matrix()
        sBPO2 = sBPO.inverse()

    #World Space Rotation
    kII = sBO2 * sBPO2 * kI * sBPO * sBO

    #Convert rotation to target joint coordinate space

    tBO = targetJ.getOrientation().asMatrix()
    tBO2 = tBO.inverse()

    #Get Parents
    tBPOmtx = dt.Matrix()

    #TEST
    tParent = targetJ.getParent()
    if (tParent != None):
        cmds.currentTime(0)
        tBPO = getParentsBPO(targetJ, tBPOmtx)
        cmds.currentTime(key)
        tBPO2 = tBPO.inverse()
    else:
        tBPO = dt.Matrix()
        tBPO2 = tBPO.inverse()

    #Translated Rotation
    kIII = tBO * tBPO * kII * tBPO2 * tBO2

    #Calculate Final Rotation
    cmds.currentTime(0)
    tBindPose = targetJ.getRotation().asMatrix()
    finalRot = tBindPose * kIII
    cmds.currentTime(key)

    #Convert Matrix to Euler Rotation

    eulerRot = dt.EulerRotation(finalRot)
    degRot = dt.degrees(eulerRot)

    return degRot
Пример #36
0
def getWorldValueAtFrameAccurate(attr, frame):
    mc.currentTime(frame)
    return mc.getAttr(attr)
Пример #37
0
def tangentScale(value, outValue=None):

    if outValue == None:
        outValue = value

    curves = None

    #order of operations:
    #selected keys, visible in graph editor on current frame
    selected = False
    time = mc.currentTime(query=True)
    curves = mc.keyframe(query=True, name=True, selected=True)
    if curves:
        #try selected keys first
        selected = True
    else:
        #then visible in graph editor
        graphVis = mc.selectionConnection('graphEditor1FromOutliner',
                                          query=True,
                                          obj=True)
        if graphVis:
            curves = mc.keyframe(graphVis, query=True, name=True)
        else:
            #otherwise try keyed channels.
            sel = mc.ls(sl=True)
            if not sel:
                return
            curves = mc.listConnections(sel, s=True, d=False, type='animCurve')
            if not curves:
                return

    for curve in curves:

        keyTimes = list()

        #set tangents weighted if they aren't already
        if mc.keyTangent(curve, query=True, weightedTangents=True):
            mc.keyTangent(curve, edit=True, weightedTangents=True)

        if selected:
            keyTimes = mc.keyframe(curve,
                                   query=True,
                                   timeChange=True,
                                   selected=True)
        else:
            keyTimes = [time]

        for t in keyTimes:

            weight = mc.keyTangent(curve,
                                   time=(t, ),
                                   query=True,
                                   inWeight=True,
                                   outWeight=True)
            if not weight:
                continue

            inOut = list()

            for w, v in zip(weight, [value, outValue]):
                if v < 1 and w < 0.1:
                    inOut.append(0)
                elif v > 1 and w == 0:
                    inOut.append(0.1)
                else:
                    inOut.append(w * v)

            mc.keyTangent(curve,
                          time=(t, ),
                          edit=True,
                          absolute=True,
                          inWeight=inOut[0],
                          outWeight=inOut[1])
Пример #38
0
    def apply_animation_and_break_all_connections_test(self):
        cmds.file(get_app_file(KIKO_APP_NAME, 'locators_hierarchy.ma'),
                  force=True,
                  open=True,
                  options='v=0;')

        self._manager.export_to_file(self._kiko_file,
                                     objects=['parent'],
                                     hierarchy=True)

        min = int(cmds.playbackOptions(q=True, minTime=True))
        max = int(cmds.playbackOptions(q=True, maxTime=True))

        MayaPreferences.reset()
        MayaPreferences.break_all_connections_in_apply_mode = True

        children = cmds.listRelatives('parent',
                                      ad=True,
                                      f=True,
                                      typ='transform')

        cache = {}
        for c in children:
            if 'constraint' in cmds.nodeType(c, i=True):
                continue

            values = {}
            for attr in TRANSFORM_ATTR:
                val = []
                for i in range(min, max):
                    cmds.currentTime(i)
                    val.append(cmds.getAttr(c + attr))
                values[attr] = val
            cache[c] = values

        self._manager.import_from_file(
            self._kiko_file,
            objects=['parent'],
            import_obj_method=IMPORT_METHODS.OBJECT.HIERARCHY,
            ignore_item_chunks=True)

        #constraints should have been deleted
        assert_false(
            bool([
                c for c in cmds.listConnections(
                    '|parent|childD', s=True, d=False)
                if 'constraint' in cmds.nodeType(c, i=True)
            ]))

        #checking values are the same
        for c in children:
            if 'constraint' in cmds.nodeType(c, i=True):
                continue
            for attr in TRANSFORM_ATTR:
                index = 0
                for i in range(min, max):
                    cmds.currentTime(i)
                    assert_true(
                        floats_equal(cmds.getAttr(c + attr),
                                     cache[c][attr][index]))
                    index += 1

        MayaPreferences.reset()
Пример #39
0
    def animation_rig_by_name_test(self):
        #test with names, remove namespace
        prefix = 'walk_cycle'
        cmds.file(get_app_file(KIKO_APP_NAME, 'walk_cycle.ma'),
                  i=True,
                  typ="mayaAscii",
                  iv=True,
                  ra=True,
                  mnc=False,
                  options="v=0;",
                  rpr=prefix)

        controls = cmds.sets(prefix + "_controls", q=True)
        self._manager.export_to_file(self._kiko_file, objects=controls)

        cmds.file(get_app_file(KIKO_APP_NAME, 'walk_cycle.ma'),
                  i=True,
                  namespace=prefix,
                  typ="mayaAscii",
                  iv=True,
                  mnc=False,
                  ra=True,
                  options="v=0;",
                  rnn=True)

        #deleting the animation from the imported rig
        new_controls = cmds.sets(prefix + ":controls", q=True)
        for c in new_controls:
            attrs = list(
                set(cmds.listAttr(c, keyable=True) or [])
                | set(cmds.listAttr(c, channelBox=True) or []))
            for a in attrs:
                all_keys = cmds.keyframe(c, query=True, indexValue=True, at=a)
                if all_keys:
                    all_keys.sort()
                    all_keys.reverse()
                    for k in all_keys:
                        cmds.cutKey(c, attribute=a, index=(k, k), clear=True)

        #import
        cmds.select(new_controls, r=True)
        self._manager.import_from_file(self._kiko_file,
                                       prefix_to_add=prefix + ":",
                                       str_replacements={prefix + '_': ''},
                                       ignore_item_chunks=True)

        #compare
        min = cmds.playbackOptions(q=True, minTime=True)
        max = cmds.playbackOptions(q=True, maxTime=True)

        for i in range(int(min), int(max)):
            cmds.currentTime(i)
            for c in controls:
                attrs = list(
                    set(cmds.listAttr(c, keyable=True) or [])
                    | set(cmds.listAttr(c, channelBox=True) or []))
                other_c = prefix + ":" + c.replace(prefix + "_", "")
                for a in attrs:
                    val = cmds.getAttr(c + '.' + a)
                    if isinstance(val, float):
                        assert_true(
                            floats_equal(val, cmds.getAttr(other_c + '.' + a)))
                    else:
                        assert_equal(val, cmds.getAttr(other_c + '.' + a))
Пример #40
0
    def exportAbc(self, dryRun=None):
        # get selection
        sel = mc.ls(sl=1)

        if len(sel) < 1:
            mc.warning('Nothing selected')
            return

        # asset name
        assetName = mc.textFieldGrp(windowName + '_assetName', q=1, text=1)

        # start and end range
        start = mc.intFieldGrp(windowName + '_range_startEnd', q=1, value1=1)
        end = mc.intFieldGrp(windowName + '_range_startEnd', q=1, value2=1)

        # check if using current frame
        range = mc.radioButtonGrp(windowName + '_range_radio', q=1, select=1)

        if range == 1:
            currentFrame = mc.currentTime(q=1)
            start = currentFrame
            end = currentFrame

        # publish directory
        exportDir = getExportDir()

        # type
        type = mc.optionMenuGrp(windowName + '_type', q=1, value=1).lower()

        exportPath = os.path.join(exportDir, assetName, type)

        # increment version if set to autoversion
        if mc.radioButtonGrp(windowName + '_version_radio', q=1,
                             select=1) == 1:
            versionNum = getLatestVersion(exportPath) + 1
            version = ('v' + str(versionNum).zfill(3))
        else:
            version = mc.textFieldGrp(windowName + '_selVersion', q=1, text=1)

        exportPath = os.path.join(exportPath, version)

        if dryRun:
            print 'Asset alembic export path is ' + exportPath
            exportAssetJsonFile(exportPath, assetName, version, dryRun)
            return

        root = ''

        for obj in sel:
            root += ' -root ' + obj

        if not os.path.exists(exportPath):
            os.makedirs(exportPath)

        # export asset json file
        self.exportAssetJsonFile(exportPath, assetName, version, dryRun)

        # add asset name with format
        exportPath = os.path.join(exportPath, assetName + '.abc')

        command = "-frameRange " + str(start) + " " + str(
            end) + " -uvWrite -worldSpace" + root + " -file " + exportPath

        mc.AbcExport(jobArg=command)

        if os.path.exists(exportPath):
            mc.confirmDialog(title='Export Successfull',
                             message='Asset Exported Successfully',
                             button='Ok')

        # for some reason the alembic command is exporting a folder named 'alembic'
        # this will remove it as long as its empty
        os.rmdir(os.path.join(exportDir, 'alembic'))

        # create set
        tbaSet = 'TBA_asset_' + assetName
        if mc.objExists(tbaSet):
            mc.delete(tbaSet)

        mc.sets(sel, name=tbaSet)

        # add assetVersion attribute
        mc.addAttr(tbaSet, shortName='assetVersion', dataType='string')
        # update attrs on meta node (and lock them)
        mc.setAttr(tbaSet + '.assetVersion', version, type='string')

        self.updateVersionsList()

        print 'Exported alembic to: ' + exportPath
Пример #41
0
 def set_key(self, time=None, value=None):
     time = time or cmds.currentTime(q=True)
     value = value or self.get()
     cmds.setKeyframe(self.path, time=time, value=value)
Пример #42
0
def createTloc(parent=""):
    """
    Creates "TLOC" and "Center3D camera".
    You can do point triangulation and quality check at the same time.

    You might not see TLOC if the image plane is to close to the camera. Give the image plane's "Depth" a higher value to fix this problem.

    Active View Camera's centerOfInterest determines TLOC's initial depth.

    Active View Camera's locatorScale determines TLOC's initial scale.
    """

    currentTime = int(mc.currentTime(q=True))
    indexList = [6, 9, 13, 14, 16, 17, 18]
    random_index = random.choice(indexList)

    # Create TLOC & TLOC GRP
    tlocTrans = mc.spaceLocator(name="tloc_{}f_#".format(currentTime))[0]
    tlocShape = mc.listRelatives(tlocTrans, shapes=True)[0]
    tlocGrp = mc.group(tlocTrans, name="{}_grp".format(tlocTrans))

    # Get Active 3D View Camera
    active3dViewCamShape, active3dViewCamTrans = getActive3dViewCam()

    # Active View Camera's centerOfInterest determines TLOC's initial depth.
    initDepth = mc.getAttr(active3dViewCamShape + ".centerOfInterest")

    # Active View Camera's locatorScale determines TLOC's initial scale.
    tlocScale = mc.getAttr(active3dViewCamShape + ".locatorScale")

    # Add Depth Attribute to TLOC
    mc.addAttr(tlocTrans,
               shortName="depth",
               longName="Depth",
               attributeType="float",
               defaultValue=initDepth)
    mc.setAttr(tlocTrans + ".depth", keyable=True)

    # Connect Depth Attribute to ScaleXYZ
    mc.connectAttr(tlocTrans + ".depth", tlocTrans + ".sx")
    mc.connectAttr(tlocTrans + ".depth", tlocTrans + ".sy")
    mc.connectAttr(tlocTrans + ".depth", tlocTrans + ".sz")

    # Set TLOC Color
    mc.setAttr(tlocShape + ".overrideEnabled", 1)
    mc.setAttr(tlocShape + ".overrideColor", random_index)

    # Get world space scale of Active 3D View Camera
    active3dViewCamWorldSpaceScale = mc.xform(active3dViewCamTrans,
                                              q=True,
                                              worldSpace=True,
                                              scale=True)[0]  # Just return sx

    # Store Near Clip Plane value
    nearClipPlaneStored = mc.getAttr(active3dViewCamShape + ".nearClipPlane")

    # Temporarily set Near Clip Plane
    mc.setAttr(active3dViewCamShape + ".nearClipPlane", initDepth)
    mc.refresh(
        force=True
    )  # Need to refresh the viewport to apply the new near clip plane value.

    # Get Cursor Position
    cursorPos = QtGui.QCursor.pos()
    widget = QtWidgets.QApplication.widgetAt(cursorPos)
    widgetHeight = widget.height()
    relpos = widget.mapFromGlobal(cursorPos)

    position = om.MPoint()  # 3D point with double-precision coordinates
    direction = om.MVector()  # 3D vector with double-precision coordinates

    omui.M3dView().active3dView().viewToWorld(
        relpos.x(),
        widgetHeight - relpos.y(
        ),  # The relpos.y() alone returns a mirrored position. Must subtract it with widgetHeight.
        position,  # world point
        direction)

    # Orient TLOC GRP to Camera
    oc = mc.orientConstraint(active3dViewCamTrans,
                             tlocGrp,
                             maintainOffset=False)
    mc.delete(oc)

    # Move TLOC GRP to Cursor Position
    mc.xform(tlocGrp,
             worldSpace=True,
             translation=[position.x, position.y, position.z])

    # Move TLOC GRP pivot to Camera Position
    active3dViewCamPos = mc.xform(active3dViewCamTrans,
                                  q=True,
                                  worldSpace=True,
                                  translation=True)
    mc.xform(tlocGrp,
             worldSpace=True,
             pivots=[
                 active3dViewCamPos[0], active3dViewCamPos[1],
                 active3dViewCamPos[2]
             ])

    # Move TLOC GRP under parent
    if parent != "":
        mc.parent(tlocGrp, parent)

    setClipboardText(parent)
    """
    Eventually TLOC GRP has to go inside camera or object point group.
    Locking translation and rotation attributes can make things complicated.

    # Lock TLOC GRP translation & rotation attributes
    axisList = ["x", "y", "z"]
    attrList = ["t", "r"]
    for axis in axisList:
        for attr in attrList:
            mc.setAttr("{0}.{1}{2}".format(tlocGrp, attr, axis), lock=True)
    """

    # Connect TLOC and TLOC GRP scale
    mc.connectAttr(tlocTrans + ".s", tlocGrp + ".s")

    tlocInitScale = 50  # DO NOT TOUCH THIS. Manipulate scale with "tlocScale(locatorScale)" param.

    # Expression for TLOC scale continuity.
    mc.expression(s="""
                    {0}.lsx = 1 / {1}.sx * {2} * {3} / {4} * {5};
                    {0}.lsy = 1 / {1}.sy * {2} * {3} / {4} * {5};
                    {0}.lsz = 0;
                    """.format(tlocShape, tlocGrp,
                               active3dViewCamWorldSpaceScale, initDepth,
                               tlocInitScale, tlocScale),
                  object=tlocGrp)

    # Just for marking the Reference Frame
    mc.setKeyframe(tlocTrans + ".rx", value=0, time=[currentTime])

    # Jump to point triangulation mode
    pointTriangulationMode(tlocTrans)

    # Set Near Clip Plane back to stored value
    mc.setAttr(active3dViewCamShape + ".nearClipPlane", nearClipPlaneStored)
Пример #43
0
    def pathAnim(self, **arg):
        start = 0
        end = 0
        arg['fractionMode'] = 1
        arg['follow'] = 1
        arg['followAxis'] = 'x'
        arg['upAxis'] = 'y'
        arg['worldUpType'] = 'vector'
        arg['worldUpVector'] = (0, 1, 0)
        arg['inverseUp'] = False
        arg['inverseFront'] = False
        arg['bank'] = False

        countvalue = cmds.intSliderGrp(self.slidername, q=1, v=True)

        starts = 1
        ends = countvalue
        cu = 0
        cmds.currentTime(ends)
        sel = cmds.ls(sl=1)

        uo = len(sel)

        if uo is 2:
            shapes = cmds.listRelatives(sel[1], s=1)
            if cmds.nodeType(shapes[0]) != 'nurbsCurve':
                cmds.error(
                    'must selcet one object and select another nurbsCurve')
        else:
            cmds.error(
                'must select two object:first select object and select a nurbsCurve'
            )

        if cmds.objExists(sel[1] + '_' + self.group):
            cmds.delete(sel[1] + '_' + self.group)
        self.pathcurves = sel[1]
        self.objcounts = []

        for i in range(countvalue):
            self.objcounts.append(cmds.duplicate(sel[0]))
            cmds.select(self.objcounts[cu], add=1)
            cu = cu + 1
        cmds.group(n=sel[1] + '_' + self.group)
        for s in self.objcounts:
            cmds.pathAnimation(self.pathcurves,
                               s,
                               startTimeU=start,
                               endTimeU=end,
                               **arg)

            starts = starts + 1
            ends = ends + 1

            start = starts
            end = ends

        listmotion = cmds.ls('motionPath*')
        for i in listmotion:
            if 'Value' in i:
                cmds.delete(i)
        cmds.currentTime(1, e=True)

        cmds.select(sel[0])
        cmds.select(sel[1], add=1)
Пример #44
0
    def process(self, instance):
        self.log.info("Extracting capture..")

        start = cmds.currentTime(query=True)
        end = cmds.currentTime(query=True)
        self.log.info("start: {}, end: {}".format(start, end))

        camera = instance.data['review_camera']

        capture_preset = ""
        capture_preset = instance.context.data['presets']['maya']['capture']
        try:
            preset = lib.load_capture_preset(data=capture_preset)
        except:
            preset = {}
        self.log.info('using viewport preset: {}'.format(capture_preset))

        # preset["off_screen"] =  False

        preset['camera'] = camera
        preset['format'] = "image"
        # preset['compression'] = "qt"
        preset['quality'] = 50
        preset['compression'] = "jpg"
        preset['start_frame'] = start
        preset['end_frame'] = end
        preset['camera_options'] = {
            "displayGateMask": False,
            "displayResolution": False,
            "displayFilmGate": False,
            "displayFieldChart": False,
            "displaySafeAction": False,
            "displaySafeTitle": False,
            "displayFilmPivot": False,
            "displayFilmOrigin": False,
            "overscan": 1.0,
            "depthOfField": cmds.getAttr("{0}.depthOfField".format(camera)),
        }

        stagingDir = self.staging_dir(instance)
        filename = "{0}".format(instance.name)
        path = os.path.join(stagingDir, filename)

        self.log.info("Outputting images to %s" % path)

        preset['filename'] = path
        preset['overwrite'] = True

        pm.refresh(f=True)

        refreshFrameInt = int(pm.playbackOptions(q=True, minTime=True))
        pm.currentTime(refreshFrameInt - 1, edit=True)
        pm.currentTime(refreshFrameInt, edit=True)

        with maintained_time():
            filename = preset.get("filename", "%TEMP%")

            # Force viewer to False in call to capture because we have our own
            # viewer opening call to allow a signal to trigger between
            # playblast and viewer
            preset['viewer'] = False

            # Remove panel key since it's internal value to capture_gui
            preset.pop("panel", None)

            path = capture.capture(**preset)
            playblast = self._fix_playblast_output_path(path)

        _, thumbnail = os.path.split(playblast)

        self.log.info("file list  {}".format(thumbnail))

        if "representations" not in instance.data:
            instance.data["representations"] = []

        representation = {
            'name': 'thumbnail',
            'ext': 'jpg',
            'files': thumbnail,
            "stagingDir": stagingDir,
            "thumbnail": True
        }
        instance.data["representations"].append(representation)
Пример #45
0
def OptimizeSkeleton(pbCollapseToes=False,
                     pLoadExternalBaseMesh=False,
                     pLoadExternalMorphs=False,
                     pLoadExternalUVs=False,
                     pCreateIKConstraints=False,
                     inBeepAfterComplete=True):
    print 'Starting skeleton and mesh optimization'
    start = time.clock()
    cmds.currentTime(0, edit=True)  #set skeleton to 'reference' position
    cmds.select(all=True)
    mel.eval('gotoBindPose')
    cmds.select(clear=True)

    dazUtils.RemoveObjectsByWildcard(['Fingernails_*'], 'transform')
    mayaUtils.ParentAllGeometryToWorld()
    mayaUtils.FixMaxInfluencesForAllSkinClusters(4)
    dazUtils.DestroyUnusedJoints(pbCollapseToes)
    mayaUtils.ResetBindPoseForAllSkinClusters()
    mayaUtils.SetSkinMethodForAllSkinClusters(0)  # set skinning type to linear

    dazUtils.RenameSkeletonJoints()
    oldJoints = mayaUtils.GetHierarchy('root')

    # collect data for skin export
    skinData = mayaUtils.GetSkinExportData(
    )  # transform, shape, skincluster, jointsList

    mayaUtils.ExportSkinning(skinData)  # export skinning
    dazUtils.DuplicateSkeletonJoints('root', 'DAZ_')
    dazUtils.FixNewJointsOrientation()
    dazUtils.RecreateHierarchy('root', 'DAZ_')
    dazUtils.JointOrientToRotation('DAZ_root')
    dazUtils.AlighnTwistJoints()

    cmds.delete(oldJoints)
    dazUtils.RenameNewSkeleton()

    if pLoadExternalBaseMesh:  # Do it when mesh unskinned
        dazUtils.TryLoadExternalBaseMeshBodyMorph()

    #load external secondary uv here
    if pLoadExternalUVs:
        dazUtils.TryLoadExternalUVs()

    dazUtils.AddNippleJointsAndAimBreast()

    mayaUtils.ImportSkinning(skinData,
                             pDeleteFilesAfterImport=True)  # import skinning

    cmds.select(clear=True)

    dazUtils.AddEndJoints()
    mayaUtils.FixMaxInfluencesForAllSkinClusters(4)
    dazUtils.MakeBendCorrectiveJoints()
    dazUtils.CreateIkJoints(pCreateIKConstraints)

    dazUtils.SetJointsVisualProperties()

    if pLoadExternalMorphs:
        dazUtils.TryLoadExternalMorphTargets()

    dazUtils.OptimizeBodyMaterials(
    )  # Check this, try to extract blendshape before baking history, then readd it. Done 26102019

    mayaUtils.FixMaxInfluencesForAllSkinClusters(4)

    dazUtils.RenameAndCombineMeshes()

    #no need anymore, mask for tesselation now writen in secondary uv and loaded externally
    #dazUtils.SetVertexColorForBorderVertices() #for genitalia mesh also
    dazUtils.CollapseUVTiles()  #use this instead

    dazUtils.PostprocessGenitaliaObject('HazardFemaleGenitalia*')

    mayaUtils.CleanUnusedMaterials()

    #dazUtils.SafeBakePartialHistoryKeepBlendShapes(shape)

    dazUtils.ReplaceEyesWithExternalMeshes()

    print 'FINISHED skeleton and mesh optimization: time taken %.02f seconds' % (
        time.clock() - start)
    if inBeepAfterComplete:
        mayaUtils.NotifyWithSound()
Пример #46
0
def writeOut(*args):
    """ writes out the json data as a dict per frame within a dict"""
    convert = cmds.checkBoxGrp(widgets["convertCBG"], q=True, v1=True)
    desktopPath = get_path()
    fr = 24
    # get current framerate
    if convert:
        convert_to_new_fps("20fps")
        fr = 20
    try:
        rangeMin = int(cmds.playbackOptions(q=True, min=True))
        rangeMax = int(cmds.playbackOptions(q=True, max=True))

        allData = {}
        allData["shotInfo"] = []

        for i in range(rangeMin, rangeMax + 1):
            frameInfo = {}
            cmds.currentTime(i)

            frameInfo["frameRate"] = fr
            frameInfo["frameNum"] = i
            frameInfo["theta"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.theta")
            frameInfo["rtWheelPosX"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtPosX")
            frameInfo["rtWheelPosY"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtPosY")
            frameInfo["rtWheelPosZ"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtPosZ")
            frameInfo["lfWheelPosX"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfPosX")
            frameInfo["lfWheelPosY"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfPosY")
            frameInfo["lfWheelPosZ"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfPosZ")
            frameInfo["lfRPM"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfRPM")
            frameInfo["lfVelocCPF"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfVelocCPF")
            frameInfo["lfVelocMPS"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfVelocMPS")
            frameInfo["lfAccelMPSS"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.lfAccelMPSS")
            frameInfo["rtRPM"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtRPM")
            frameInfo["rtVelocCPF"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtVelocCPF")
            frameInfo["rtVelocMPS"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtVelocMPS")
            frameInfo["rtAccelMPSS"] = cmds.getAttr(
                "iRobotLawnMower_mstrBodyCtrl.rtAccelMPSS")

            # sortedFrameInfo = collections.OrderedDict(sorted(frameInfo.items()))
            allData["shotInfo"].append(frameInfo)

        with open(desktopPath, "w") as outfile:
            json.dump(allData, outfile, indent=2)
    except Exception as inst:
        cmds.warning("had an issue sending out the data:")
        print inst

    if convert:
        cmds.currentUnit(time="film")
Пример #47
0
    def Constraints(self, *args):
        # creat a loc
        # creat constrain rootM to loc, all
        # bake anim for loc
        # rootm --> parent -w
        # rootm delete keyfarme
        # creat constrain loc to root ,tx,tz, rz
        # parent(rootm, root)
        # creat constrain loc to root ,all

        # startNum = cmds.playbackOptions(q = True , ast = True)
        # endNum = cmds.playbackOptions(q = True , aet = True)

        # returnMess = cmds.confirmDialog( title='Confirm', message='烘焙时间轴为' + str(startNum) + '-' + str(endNum), button=['Yes','No'], defaultButton='Yes', cancelButton='No', dismissString='No' )
        # if returnMess == "No":
        #     return
        startNum = cmds.intFieldGrp("StartFrame", q=True, value1=True)
        endNum = cmds.intFieldGrp("EndFrame", q=True, value1=True)
        cmds.currentUnit(time='ntsc', linear='centimeter')
        cmds.currentTime(startNum)

        locPos = cmds.spaceLocator()
        cmds.parentConstraint('Root_M', locPos, mo=True)

        cmds.bakeResults(locPos,
                         simulation=True,
                         t=(startNum, endNum),
                         hierarchy="below",
                         sb=1,
                         dic=True,
                         pok=True,
                         ral=False,
                         rwl=False,
                         cp=True)

        cmds.parent('Root_M', world=True)
        keyframelist = cmds.ls(type='animCurveTL') + cmds.ls(
            type='animCurveTA') + cmds.ls(type='animCurveTU')
        for i in keyframelist:
            if not ('Root_M' not in i):
                cmds.delete(i)

        t = cmds.checkBoxGrp("translateAxes", q=True, value2=True)
        if t:
            trans = []
        else:
            trans = ["y"]

        r = cmds.checkBoxGrp("rotateAxes", q=True, value2=True)
        if r:
            rot = ["x", "z"]
        else:
            rot = ["x", "y", "z"]

        parentConA = cmds.parentConstraint(locPos,
                                           'Root',
                                           st=trans,
                                           sr=rot,
                                           mo=True)
        cmds.bakeResults('Root',
                         simulation=True,
                         t=(startNum, endNum),
                         hierarchy="below",
                         sb=1,
                         dic=True,
                         pok=True,
                         ral=False,
                         rwl=False,
                         cp=True)
        cmds.delete(parentConA)

        cmds.parent('Root_M', 'Root')
        parentConB = cmds.parentConstraint(locPos, 'Root_M', mo=True)
        cmds.bakeResults('Root_M',
                         simulation=True,
                         t=(startNum, endNum),
                         hierarchy="below",
                         sb=1,
                         dic=True,
                         pok=True,
                         ral=False,
                         rwl=False,
                         cp=True)
        cmds.delete(parentConB)
        cmds.delete(locPos)
Пример #48
0
def CreateOptimizedSkeletonOnlyAndRetargetAnim(bFilterCurves=True,
                                               inBeepAfterComplete=True):
    print 'Starting skeleton optimization'
    start = time.clock()
    cmds.currentTime(0, edit=True)  #set skeleton to 'reference' position

    dazUtils.RemoveObjectsByWildcard(['Fingernails_*'], 'transform')
    dazUtils.RemoveObjectsByWildcard(['HazardFemaleGenitalia_*Shape'],
                                     'transform')

    mayaUtils.ParentAllGeometryToWorld()

    primaryMesh = mayaUtils.FindMeshByWildcard('Genesis8*',
                                               preferShapeWithMaxVertices=True,
                                               checkForMatWithName='Torso')

    if primaryMesh:
        cmds.select(primaryMesh)
    else:
        cmds.select(all=True)

    mel.eval('gotoBindPose')
    cmds.select(clear=True)

    #delete all meshes
    shapesToDelete = mayaUtils.GetMultipleShapesTransforms(
        cmds.ls(geometry=True, objectsOnly=True))
    if shapesToDelete:
        for s in shapesToDelete:
            cmds.delete(s)
            print 'Deleting {0}'.format(s)

    dazUtils.RenameSkeletonJoints()
    oldJoints = mayaUtils.GetHierarchy('root')

    dazUtils.DuplicateSkeletonJoints('root', 'DAZ_')

    dazUtils.FixNewJointsOrientation()
    dazUtils.RecreateHierarchy('root', 'DAZ_')
    dazUtils.JointOrientToRotation('DAZ_root')

    #delete twist joints for animation retargetting/ they are procedurally animated in engine
    unusedJoints = cmds.ls('DAZ_*twist*')
    for j in unusedJoints:
        cmds.delete(j)
        print '\tDeleting {0}'.format(j)

    print 'Renaming OLD skeleton'
    oldJoints = mayaUtils.GetHierarchy('root')
    for j in oldJoints:
        mayaUtils.RenameJoint(j, 'OLD_' + j)

    dazUtils.RenameNewSkeleton()  #remove DAZ_ prefix

    dazUtils.AddNippleJointsAndAimBreast()

    cmds.select(clear=True)
    #create constraint from old skeleton to new
    print 'Creating constraints'
    newJoints = mayaUtils.GetHierarchy('root')

    for j in newJoints:
        oldJoint = 'OLD_' + j
        print '\tCreating parentConstraint from {0} to {1}'.format(oldJoint, j)
        #not all joints can exist on old skeleton (e.g. nipples)
        if cmds.objExists(oldJoint) and cmds.nodeType(oldJoint) == 'joint':
            cmds.parentConstraint(oldJoint, j, maintainOffset=True)

    dazUtils.CreateIkJoints()  #create AFTER constraining new skeleton to old

    # No need to bake IK joints, they are auto baked during exporting to fbx

    print '\n'
    print "\t\t******** BAKING ANIMATION ********"
    print '\n'
    attributesToBake = ['tx', 'ty', 'tz', 'rx', 'ry', 'rz']
    timeRange = (cmds.playbackOptions(animationStartTime=True, query=True),
                 cmds.playbackOptions(animationEndTime=True, query=True))
    print 'timeRange = {0}'.format(timeRange)
    cmds.bakeResults(newJoints,
                     attribute=attributesToBake,
                     time=timeRange,
                     minimizeRotation=True,
                     preserveOutsideKeys=True,
                     simulation=True,
                     disableImplicitControl=True)

    print '\n'
    print "\t\t******** Filtering curves ********"
    print '\n'

    if bFilterCurves:
        animNodes = cmds.listConnections(newJoints, type="animCurve")
        if animNodes:
            print 'Performing filtering for {0} anim curves'.format(
                len(animNodes))
            oldKeysCount = cmds.keyframe(animNodes, q=True, keyframeCount=True)
            cmds.filterCurve(animNodes,
                             filter='simplify',
                             timeTolerance=0.01,
                             tolerance=0.01)
            newKeysCount = cmds.keyframe(animNodes, q=True, keyframeCount=True)
            percent = float(newKeysCount) / float(oldKeysCount) * 100.0
            print '{0} keys filtered to {1} keys ({2:.1f}%)'.format(
                oldKeysCount, newKeysCount, percent)
    else:
        print 'Filtering NOT requested'

    #clean scene after finishing
    print 'Deleting old skeleton'
    cmds.select(clear=True)
    cmds.select(mayaUtils.GetHierarchy('OLD_root'))
    cmds.delete()

    print 'FINISHED animation retargeting: time taken %.02f seconds' % (
        time.clock() - start)
    if inBeepAfterComplete:
        mayaUtils.NotifyWithSound()
Пример #49
0
def snapshot(outputPath,
             width=400,
             height=None,
             hud=False,
             grid=False,
             camera=None):
    if height is None:
        height = width

    outputExt = os.path.splitext(outputPath)[1].lower().lstrip('.')

    formatNum = KNOWN_FORMATS.get(outputExt)
    if formatNum is None:
        raise ValueError(
            "input image had unrecognized extension: {}".format(outputExt))

    # if given relative path, make it relative to current dir (the test
    # temp base), rather than the workspace dir
    outputPath = os.path.abspath(outputPath)

    # save the old output image format
    oldFormat = cmds.getAttr("defaultRenderGlobals.imageFormat")
    # save the hud setting
    oldHud = cmds.headsUpDisplay(q=1, layoutVisibility=1)
    # save the grid setting
    oldGrid = cmds.grid(q=1, toggle=1)
    # save the old view transform
    oldColorTransform = cmds.colorManagementPrefs(q=1,
                                                  outputTarget="playblast",
                                                  outputTransformName=1)

    # Some environments use legacy synColor transforms with 2022 and above.
    # Find whether the color config should be Raw or Raw legacy
    # However depending on the MAYA_COLOR_MANAGEMENT_SYNCOLOR env var or the loaded
    # configs, this may be under a different names. So procedurally find it.
    colorTransforms = cmds.colorManagementPrefs(q=1, outputTransformNames=True)
    if "Raw" in colorTransforms:
        newColorTransform = "Raw"
    elif "Raw (legacy)" in colorTransforms:
        newColorTransform = "Raw (legacy)"
    else:
        # RAW should be reliably raw-like in most configs, so find the first ending in RAW
        newColorTransform = [
            c for c in colorTransforms if c.startswith("Raw ")
        ]
        if newColorTransform:
            newColorTransform = newColorTransform[0]
        else:
            raise RuntimeError(
                "Could not find Raw color space in available color transforms")

    # Some environments have locked color policies that prevent changing color policies
    # so we must disable and restore this accordingly.
    lockedColorTransforms = os.environ.get(
        "MAYA_COLOR_MANAGEMENT_POLICY_LOCK") == '1'
    if lockedColorTransforms:
        os.environ['MAYA_COLOR_MANAGEMENT_POLICY_LOCK'] = '0'

    # Find the current model panel for playblasting
    # to make sure the desired camera is set, if any
    panel = mayaUtils.activeModelPanel()
    oldCamera = cmds.modelPanel(panel, q=True, cam=True)
    if camera:
        cmds.modelEditor(panel, edit=True, camera=camera)

    # do these in a separate try/finally from color management, because
    # color management seems a bit more finicky
    cmds.setAttr("defaultRenderGlobals.imageFormat", formatNum)
    cmds.headsUpDisplay(layoutVisibility=hud)
    cmds.grid(toggle=grid)
    try:
        cmds.colorManagementPrefs(e=1,
                                  outputTarget="playblast",
                                  outputTransformName=newColorTransform)
        try:
            cmds.playblast(cf=outputPath,
                           viewer=False,
                           format="image",
                           frame=cmds.currentTime(q=1),
                           offScreen=1,
                           widthHeight=(width, height),
                           percent=100)
        finally:
            cmds.colorManagementPrefs(e=1,
                                      outputTarget="playblast",
                                      outputTransformName=oldColorTransform)
    finally:
        cmds.setAttr("defaultRenderGlobals.imageFormat", oldFormat)
        cmds.headsUpDisplay(layoutVisibility=oldHud)
        cmds.grid(toggle=oldGrid)
        if lockedColorTransforms:
            os.environ['MAYA_COLOR_MANAGEMENT_POLICY_LOCK'] = '1'

        if camera:
            cmds.lookThru(panel, oldCamera)
Пример #50
0
 def _jump_to_frame(self):
     '''
     Jump to frame in Maya Timeline
     '''
     if (self.frame):
         mc.currentTime(self.frame)
Пример #51
0
def doubleParent():
    '''
    Make a double locator parent chain

    Usage example:
        want to attach an apple to a hand
        rather than parent the apple directly, constrain the apple to a locator which is the child of another
        then constrain the parent to the hand

    Addition:
        Add a control with the previous location baked

    '''


    #get the guy
    justOne = cmds.ls( sl=True )[0]

    start, end = utl.frameRange()
    print start
    #make a temp locator at the spot we copied
    if cmds.objExists('watch_this_space'):
        cmds.delete('watch_this_space')


    controlCircleName = 'sandwichControl_'+justOne
    offsetCircleName = 'sandwichOffset_'+justOne
    bakedCircleName = 'bakedControl_'+justOne
    sandwichChildName = 'sandwichChild_'+justOne


    controlCircle = cmds.circle( nr=(0,0,1), c=(0,0,0), name=controlCircleName, r=2)
    cmds.setAttr( controlCircleName+'.overrideEnabled', 1)
    cmds.setAttr( controlCircleName+'.overrideColor', 6)
    offsetCircle = cmds.circle( nr=(0,0,1), c=(0,0,0), name=offsetCircleName, r=1.5)
    cmds.setAttr( offsetCircleName+'.overrideEnabled', 1)
    cmds.setAttr( offsetCircleName+'.overrideColor', 9)


    #bakedCircle = cmds.circle( nr=(0,0,1), c=(0,0,0), name=bakedCircleName, r=2)
    #cmds.setAttr( bakedCircleName+'.overrideEnabled', 1)
    #cmds.setAttr( bakedCircleName+'.overrideColor', 10)

    sandwichChild = cmds.spaceLocator( name='sandwichChild_'+justOne )
    cmds.parent( offsetCircleName, controlCircleName)
    cmds.parent( sandwichChildName, offsetCircleName)

    #temp Locator move TO target object
    tempParentConstraint = cmds.parentConstraint(justOne, controlCircle)
    cmds.delete(tempParentConstraint)

    #tempParentConstraint = cmds.parentConstraint(justOne, bakedCircle)
    theParentConstraint = cmds.parentConstraint( sandwichChild, justOne)
    listOfWeights = cmds.parentConstraint( theParentConstraint, query=True, wal=True)
    otherWeights = cmds.parentConstraint( theParentConstraint, query=True, tl=True)
    #print listOfWeights
    #print theParentConstraint
    #print otherWeights
    cT = cmds.currentTime( query=True )
    cmds.currentTime( cT-1, update=False)
    cmds.setKeyframe( theParentConstraint[0]+'.'+listOfWeights[0], v=0 )
    cmds.currentTime( cT, update=False)
    cmds.setKeyframe( theParentConstraint[0]+'.'+listOfWeights[0], v=1 )
    #cmds.setKeyframe( v=1, at='translateX' )
    cmds.select('sandwichControl_'+justOne)
Пример #52
0
def createCurves(ptList, start=None, end=None, inc=1):
    '''
	Create motion path curves for the specified list of points.
	@param ptList: List of objects to create motion paths from
	@type ptList: list
	@param start: Start frame for motion path curve. If None, use first frame from timeline.
	@type start: int or None
	@param end: Start frame for motion path curve. If None, use last frame from timeline.
	@type end: int or None
	@param inc: Frame increment for motion path curve. Values will be clamped to a minimum of 1.
	@type inc: int or None
	'''
    # ==========
    # - Checks -
    # ==========

    if not ptList:
        raise Exception(
            'No valid point list provided! Unable to creat motion path...')

    # Check Start/End
    if start == None: start = mc.playbackOptions(q=True, min=True)
    if end == None: end = mc.playbackOptions(q=True, max=True)
    if end < start:
        raise Exception('Invalid time range! Start is greater than end.')

    # Check Increment
    if inc < 1: inc = 1
    if inc > (end - start):
        raise Exception('Frame increment is greater than the time range!')

    # ======================
    # - Build Motion Paths -
    # ======================

    hasEndPt = False

    # Initialize Motion Paths
    crvList = []
    mc.currentTime(start)
    for pt in ptList:

        # Create Motion Path Curves
        pos = glTools.utils.base.getPosition(pt)
        crv = mc.curve(p=[pos], d=1)
        crv = mc.rename(crv, pt + '_curve')
        crvList.append(crv)

        # Encode Source Object Name
        mc.addAttr(crv, ln='sourceObject', dt='string')
        mc.setAttr(crv + '.sourceObject', pt, type='string')

        # Encode Motion Start/End
        mc.addAttr(crv, ln='motionStart')
        mc.setAttr(crv + '.motionStart', start)
        mc.addAttr(crv, ln='motionEnd')
        mc.setAttr(crv + '.motionEnd', end)

    # Track Paths
    for i in range(start + inc, end + 1, inc):
        mc.currentTime(i)
        if i == end: hasEndPt = True
        for n in range(len(ptList)):
            pos = glTools.utils.base.getPosition(ptList[n])
            mc.curve(crvList[n], a=True, p=pos)

    # Ensure End Point
    if not hasEndPt:
        mc.currentTime(end)
        for n in range(len(ptList)):
            pos = glTools.utils.base.getPosition(ptList[n])
            mc.curve(crvList[n], a=True, p=pos)

    # Rebuild Motion Paths
    for crv in crvList:
        mc.rebuildCurve(crv,
                        ch=False,
                        rpo=True,
                        rt=0,
                        end=1,
                        kr=2,
                        kcp=True,
                        kep=True)

    # =================
    # - Return Result -
    # =================

    return crvList
Пример #53
0
def OCT_BakeCamera():
    allSelCamera = mc.ls(selection=True)
    find = False
    if not allSelCamera:
        mc.confirmDialog(title='Confirm', message=u'请选择摄像机')
        return
    for obj in allSelCamera:
        buf = mc.listRelatives(obj, fullPath=True, children=True)
        if buf:
            if mc.nodeType(buf[0]) == "camera" or mc.nodeType(
                    buf[0]) == "stereoRigCamera":
                find = True
            else:
                find = False
                break
        else:
            find = False
            break

    if not find:
        mc.confirmDialog(title='Confirm', message=u'请选择摄像机')
        return

    timeLine = mc.playbackOptions(q=True, min=True)
    timeLine1 = mc.playbackOptions(q=True, max=True)

    for baked in allSelCamera:
        mc.select(d=True)
        mc.select(baked, r=True)
        #复制相机
        CopyCamera = mc.duplicate(rr=True)
        #改名
        selCamreaName = baked + baked
        mc.rename(baked, selCamreaName)
        mc.rename(CopyCamera[0], baked)
        mc.parent(baked, w=True)

        attrs = mc.listAttr(baked, keyable=True, locked=True)
        if attrs:
            for attr in attrs:
                mc.setAttr("%s.%s" % (baked, attr), l=False)

        buf = mc.listRelatives(baked, fullPath=True, children=True)
        attrShapes = mc.listAttr(buf[0], keyable=True, locked=True)
        if attrShapes:
            for at in attrShapes:
                mc.setAttr("%s.%s" % (baked, at), l=False)

        mc.parentConstraint(selCamreaName, baked, w=1)
        mc.bakeResults(baked,
                       simulation=True,
                       t=(timeLine, timeLine1),
                       sampleBy=True,
                       disableImplicitControl=True,
                       preserveOutsideKeys=True,
                       sparseAnimCurveBake=False,
                       removeBakedAttributeFromLayer=False,
                       bakeOnOverrideLayer=False,
                       minimizeRotation=True,
                       controlPoints=False,
                       shape=True)

        oldShapes = mc.listRelatives(selCamreaName,
                                     fullPath=True,
                                     children=True)

        attrs = [
            "horizontalFilmOffset", "verticalFilmOffset", "filmFitOffset",
            "focalLength"
        ]

        focal = mc.listConnections("%s.focalLength" % buf[0],
                                   s=True,
                                   plugs=True)
        if focal:
            mc.disconnectAttr(focal[0], "%s.focalLength" % buf[0])

        for i in range(int(timeLine), int(timeLine1) + 1):
            mc.currentTime(i)
            for attr in attrs:
                num = mc.getAttr("%s.%s" % (oldShapes[0], attr))
                mc.setKeyframe(buf[0], v=num, at=attr, t=i)

        # nameShapes = mc.listRelatives(baked,c= True)
        # for i in range(int(timeLine), int(timeLine1)+1):
        #     mc.setKeyframe(nameShapes,at = "filmFitOffset",t = i)
        #     mc.setKeyframe(nameShapes,at = "horizontalFilmOffset",t = i)
        #     mc.setKeyframe(nameShapes,at = "verticalFilmOffset",t = i)
        # setKeyframe -v $translate[0] -at scaleX -t $keyframe[0] $child;


#OCT_BakeCamera()
Пример #54
0
 def __enter__(self):
     self.autoKeyState = cmds.autoKeyframe(query=True, state=True)
     self.time = int(cmds.currentTime(q=True))
     self.selection = cmds.ls(sl=True)
Пример #55
0
 def getEnd(self):
     self.maxValue = cmds.currentTime(q=True)
     self.endBtn.setText("End : " + str(int(self.maxValue)))
Пример #56
0
    def doIt(self, args):
        '''Creates the node and connects everything based on the parameters given'''
        # get the arguments passed in
        argData = OpenMaya.MArgParser(self.syntax(), args)

        # get objects to use in the constraint and make sure there is only two
        objects = []
        argData.getObjects(objects)
        if not objects:
            # use the selection
            objects = cmds.ls(sl=True)

        for obj in objects:
            self.sList.add(obj)

        # if there is less than two objects given, return an error
        if self.sList.length() < 2:
            raise RuntimeError(
                'Two transforms are required to create constraint.')

        # get the target object path and make sure it's a transform type
        targetDAG = OpenMaya.MDagPath()
        try:
            self.sList.getDagPath(0, targetDAG)
        except RuntimeError:
            raise RuntimeError(
                'Target object must be a DAG object type. Unable to get path to object.'
            )

        targetTransFn = OpenMaya.MFnTransform()
        try:
            targetTransFn.setObject(targetDAG)
        except RuntimeError:
            raise RuntimeError(
                'Target object type invalid. You must choose a transform.')

        # get the constraint object path and make sure it's a transform type
        constraintDAG = OpenMaya.MDagPath()
        try:
            self.sList.getDagPath(1, constraintDAG)
        except RuntimeError:
            raise RuntimeError(
                'Constraint object must be a DAG object type. Unable to get path to object.'
            )

        constrainedTransFn = OpenMaya.MFnTransform()
        try:
            constrainedTransFn.setObject(constraintDAG)
        except RuntimeError:
            raise RuntimeError(
                'Constraint object type invalid. You must choose a transform.')

        numSkips = argData.numberOfFlagUses('-sk')
        if numSkips > 3:
            raise RuntimeError('You can not have more than 3 skip flags.')

        if argData.isFlagSet('-n'):
            self.nodeName = argData.flagArgumentString('-n', 0)

        for i in range(numSkips):
            argList = OpenMaya.MArgList()
            argData.getFlagArgumentList('-sk', i, argList)

            axis = argList.asString(0)

            if axis == 'x':
                self.skipX = True
            elif axis == 'y':
                self.skipY = True
            elif axis == 'z':
                self.skipZ = True

        # distance flag
        if argData.isFlagSet('-d'):
            self.distanceValue = argData.flagArgumentDouble('-d', 0)
        else:
            # calculate the distance
            targetPos = targetTransFn.getTranslation(OpenMaya.MSpace.kWorld)
            constrainedPos = constrainedTransFn.getTranslation(
                OpenMaya.MSpace.kWorld)
            localPos = targetPos - constrainedPos
            self.distanceValue = localPos.length()

        # start frame flag
        if argData.isFlagSet('-sf'):
            self.startFrame = argData.flagArgumentDouble('-sf', 0)
        else:
            self.startFrame = cmds.currentTime(q=True)

        # start position
        if argData.isFlagSet('-sp'):
            spX = argData.flagArgumentDouble('-sp', 0)
            spY = argData.flagArgumentDouble('-sp', 1)
            spZ = argData.flagArgumentDouble('-sp', 2)

            self.startVector = OpenMaya.MVector(spX, spY, spZ)
        else:
            self.startVector = constrainedTransFn.getTranslation(
                OpenMaya.MSpace.kTransform)

        self.redoIt()
Пример #57
0
def maintained_time():
    ct = cmds.currentTime(query=True)
    try:
        yield
    finally:
        cmds.currentTime(ct, edit=True)
Пример #58
0
    def _render(self, state, data):

        # Execute integration before_playblast
        for name, integration in self.integrations.items():
            if integration.enabled:
                integration.before_playblast(integration.form, data)

        # Prepare resolution
        if data.pop('half_res', False):
            data['resolution'] = (
                round_to_even(data['resolution'][0] * 0.5),
                round_to_even(data['resolution'][1] * 0.5),
            )

        if data['capture_mode'] == 'snapshot':
            # Render snapshot
            data['start_frame'] = cmds.currentTime(q=True)
            data['end_frame'] = data['start_frame']
            out_file = playblast(
                camera=data['camera'],
                state=state,
                format='image',
                compression='png',
                completeFilename=data['filename'],
                frame=[data['start_frame']],
                width=data['resolution'][0],
                height=data['resolution'][1],
            )
        else:
            # Call extension handler
            extension = hooks.extension.get(data['ext_option'])
            framerange = get_framerange()
            data['start_frame'] = framerange[0]
            data['end_frame'] = framerange[1]
            data['fps'] = get_fps()
            data['sound'] = get_sound_track()
            out_file = extension.handler(
                data=dict(
                    state=state,
                    camera=data['camera'],
                    filename=data['filename'],
                    width=data['resolution'][0],
                    height=data['resolution'][1],
                    sound=data['sound'],
                    fps=data['fps'],
                    start_frame=data['start_frame'],
                    end_frame=data['end_frame'],
                ),
                options=extension.options or {},
            )

        # Execute postrender callbacks
        if 'postrender' in data:
            for name, enabled in data['postrender'].items():
                if enabled:
                    postrender = hooks.postrender.get(name)
                    postrender.handler(data['filename'])

        # Update filename from playblast command
        data['filename'] = out_file

        # Execute integration after_playblast
        for name, integration in self.integrations.items():
            if integration.enabled:
                integration.after_playblast(integration.form, data)

        return data
Пример #59
0
def traceArc(space='camera'):
    '''
    The main function for creating the arc.
    '''

    if space not in ('world', 'camera'):
        OpenMaya.MGlobal.displayWarning('Improper space argument.')
        return

    global ML_TRACE_ARC_PREVIOUS_SELECTION
    global ML_TRACE_ARC_PREVIOUS_SPACE

    globalScale = 1
    if mc.optionVar(exists='ml_arcTracer_brushGlobalScale'):
        globalScale = mc.optionVar(query='ml_arcTracer_brushGlobalScale')

    #save for reset:
    origTime = mc.currentTime(query=True)

    #frame range
    frameRange = utl.frameRange()
    start = frameRange[0]
    end = frameRange[1]

    #get neccesary nodes
    objs = mc.ls(sl=True, type='transform')
    if not objs:
        OpenMaya.MGlobal.displayWarning('Select objects to trace')
        return

    ML_TRACE_ARC_PREVIOUS_SELECTION = objs
    ML_TRACE_ARC_PREVIOUS_SPACE = space

    cam = None
    nearClipPlane = None
    shortCam = ''
    if space == 'camera':
        cam = utl.getCurrentCamera()

        #the arc will be placed just past the clip plane distance, but no closer than 1 unit.
        nearClipPlane = max(mc.getAttr(cam + '.nearClipPlane'), 1)

        shortCam = mc.ls(cam, shortNames=True)[0]

    topGroup = 'ml_arcGroup'
    worldGrp = 'ml_arcWorldGrp'
    localGrp = 'ml_localGrp_' + shortCam

    #create nodes
    if not mc.objExists(topGroup):
        topGroup = mc.group(empty=True, name=topGroup)

    parentGrp = topGroup
    if space == 'world' and not mc.objExists(worldGrp):
        worldGrp = mc.group(empty=True, name=worldGrp)
        mc.setAttr(worldGrp + '.overrideEnabled', 1)
        mc.setAttr(worldGrp + '.overrideDisplayType', 2)
        mc.parent(worldGrp, topGroup)
        parentGrp = mc.ls(worldGrp)[0]

    if space == 'camera':
        camConnections = mc.listConnections(cam + '.message',
                                            plugs=True,
                                            source=False,
                                            destination=True)
        if camConnections:
            for cc in camConnections:
                if '.ml_parentCam' in cc:
                    localGrp = mc.ls(cc, o=True)[0]

        if not mc.objExists(localGrp):
            localGrp = mc.group(empty=True, name=localGrp)
            mc.parentConstraint(cam, localGrp)
            mc.setAttr(localGrp + '.overrideEnabled', 1)
            mc.setAttr(localGrp + '.overrideDisplayType', 2)
            mc.parent(localGrp, topGroup)

            mc.addAttr(localGrp, at='message', longName='ml_parentCam')
            mc.connectAttr(cam + '.message', localGrp + '.ml_parentCam')

        parentGrp = mc.ls(localGrp)[0]

    #group per object:
    group = []

    for i, obj in enumerate(objs):
        sn = mc.ls(obj, shortNames=True)[0]
        name = sn.replace(':', '_')

        groupName = 'ml_{}_arcGrp'.format(name)
        if mc.objExists(groupName):
            mc.delete(groupName)

        group.append(mc.group(empty=True, name=groupName))

        group[i] = mc.parent(group[i], parentGrp)[0]
        mc.setAttr(group[i] + '.translate', 0, 0, 0)
        mc.setAttr(group[i] + '.rotate', 0, 0, 0)

    with utl.UndoChunk():

        #determine the method to run. Test fast against accurate.
        #If fast is the same, continue with fast method.
        #Otherwise revert to accurate method.

        mc.currentTime(start)
        fastPoints = arcDataFast([objs[0]], parentGrp, start + 1, start + 1,
                                 space, nearClipPlane, cam)
        accuratePoints = arcDataAccurate([objs[0]], parentGrp, start + 1,
                                         start + 1, space, nearClipPlane, cam)

        points = None
        #if they're equivalent, continue with fast:
        if [int(x * 1000000) for x in fastPoints[0][0]
            ] == [int(x * 1000000) for x in accuratePoints[0][0]]:
            points = arcDataFast([objs[0]], parentGrp, start, end, space,
                                 nearClipPlane, cam)
        else:
            points = arcDataAccurate([objs[0]], parentGrp, start, end, space,
                                     nearClipPlane, cam)

        #create the curves and do paint effects
        mc.ResetTemplateBrush()
        brush = mc.getDefaultBrush()
        mc.setAttr(brush + '.screenspaceWidth', 1)
        mc.setAttr(brush + '.distanceScaling', 0)
        mc.setAttr(brush + '.brushWidth', 0.005)

        for i, obj in enumerate(objs):

            #setup brush for path
            globalScale
            mc.setAttr(brush + '.globalScale', globalScale)
            mc.setAttr(brush + '.screenspaceWidth', 1)
            mc.setAttr(brush + '.distanceScaling', 0)
            mc.setAttr(brush + '.brushWidth', 0.003)

            #color
            for c in ('R', 'G', 'B'):
                color = random.uniform(0.3, 0.7)
                mc.setAttr(brush + '.color1' + c, color)

            baseCurve = mc.curve(d=3, p=points[i])
            #fitBspline makes a curve that goes THROUGH the points, a more accurate path
            curve = mc.fitBspline(baseCurve,
                                  constructionHistory=False,
                                  tolerance=0.001,
                                  name='ml_arcTracer_curve_#')
            mc.delete(baseCurve)

            #paint fx
            mc.AttachBrushToCurves(curve)
            stroke = mc.ls(sl=True)[0]
            mc.rename(
                mc.listConnections(stroke + '.brush', destination=False)[0],
                'ml_arcTracer_brush_#')

            stroke = mc.parent(stroke, group[i])[0]

            mc.setAttr(stroke + '.overrideEnabled', 1)
            mc.setAttr(stroke + '.overrideDisplayType', 2)

            mc.setAttr(stroke + '.displayPercent', 92)
            mc.setAttr(stroke + '.sampleDensity', 0.5)
            mc.setAttr(stroke + '.inheritsTransform', 0)
            mc.setAttr(stroke + '.translate', 0, 0, 0)
            mc.setAttr(stroke + '.rotate', 0, 0, 0)

            curve = mc.parent(curve, group[i])[0]
            mc.setAttr(curve + '.translate', 0, 0, 0)
            mc.setAttr(curve + '.rotate', 0, 0, 0)

            mc.hide(curve)

            #setup brush for tics
            if space == 'camera':
                mc.setAttr(brush + '.brushWidth', 0.008)
            if space == 'world':
                mc.setAttr(brush + '.brushWidth', 0.005)
            mc.setAttr(brush + '.color1G', 0)
            mc.setAttr(brush + '.color1B', 0)

            for t in range(len(points[i])):
                frameCurve = None
                if space == 'camera':
                    vec = utl.Vector(points[i][t][0], points[i][t][1],
                                     points[i][t][2])
                    vec *= 0.98
                    frameCurve = mc.curve(d=1, p=[points[i][t], vec[:]])

                elif space == 'world':
                    frameCurve = mc.circle(constructionHistory=False,
                                           radius=0.0001,
                                           sections=4)[0]
                    mc.setAttr(frameCurve + '.translate', points[i][t][0],
                               points[i][t][1], points[i][t][2])
                    constraint = mc.tangentConstraint(curve,
                                                      frameCurve,
                                                      aimVector=(0, 0, 1),
                                                      worldUpType='scene')
                    #mc.delete(constraint)

                #check for keyframe
                colorAttribute = 'color1G'
                if mc.keyframe(obj,
                               time=((t + start - 0.5), (t + start + 0.5)),
                               query=True):
                    mc.setAttr(brush + '.color1R', 1)
                else:
                    mc.setAttr(brush + '.color1R', 0)

                mc.AttachBrushToCurves(curve)

                stroke = mc.ls(sl=True)[0]
                thisBrush = mc.listConnections(stroke + '.brush',
                                               destination=False)[0]
                thisBrush = mc.rename(thisBrush, 'ml_arcTracer_brush_#')

                #setup keyframes for frame highlighting
                mc.setKeyframe(thisBrush,
                               attribute='color1G',
                               value=0,
                               time=(start + t - 1, start + t + 1))
                mc.setKeyframe(thisBrush,
                               attribute='color1G',
                               value=1,
                               time=(start + t, ))

                stroke = mc.parent(stroke, group[i])[0]

                mc.hide(frameCurve)

                mc.setAttr(stroke + '.displayPercent', 92)
                mc.setAttr(stroke + '.sampleDensity', 0.5)

                frameCurve = mc.parent(frameCurve, group[i])[0]

                if space == 'camera':
                    mc.setAttr(stroke + '.inheritsTransform', 0)
                    mc.setAttr(
                        stroke + '.pressureScale[1].pressureScale_Position', 1)
                    mc.setAttr(
                        stroke + '.pressureScale[1].pressureScale_FloatValue',
                        0)
                    mc.setAttr(stroke + '.translate', 0, 0, 0)
                    mc.setAttr(stroke + '.rotate', 0, 0, 0)
                    mc.setAttr(frameCurve + '.translate', 0, 0, 0)
                    mc.setAttr(frameCurve + '.rotate', 0, 0, 0)

        mc.currentTime(origTime, edit=True)
        panel = mc.getPanel(withFocus=True)
        try:
            mc.modelEditor(panel, edit=True, strokes=True)
        except:
            pass

    mc.select(objs, replace=True)
    mc.refresh()
Пример #60
0
 def getSt(self):
     self.minValue = cmds.currentTime(q=True)
     self.stBtn.setText("Start : " + str(int(self.minValue)))