def bake(end): # Baking fold animation keyframes cmds.currentTime(0) cmds.select("shirt") cmds.bakeSimulation(simulation=True, controlPoints=True, shape=True, time=(0, end))
def exportSceneFromRoot(root, isAnimation, fbxPreset, startFrame, endFrame, outputFile): print '************************************' print 'fbxExporterUtil:::exportSceneFromRoot' exportGroup = [] importFromReference() for child in [ x for x in root.getChildren() if x.nodeType() == 'transform' ]: if 'MAINCtrl' in child.name(): controlRoot = child controlGroup = controlRoot.getChildren(ad=True) if isAnimation: print('This scene contain animation') print('animation end at :' + str(endFrame)) else: print('This is a static mesh scene') elif 'SHJntGrp' in child.name(): rrSklJ = child if len(child.getChildren(ad=True, type='joint')) > 0: skinJoints = child.getChildren(ad=True, type='joint') exportGroup.extend(skinJoints) pm.mel.FBXLoadExportPresetFile(f=fbxPreset) if isAnimation: skinJointsName = [joint.name() for joint in skinJoints] # FBX setting pm.mel.FBXExportInAscii(v=True) pm.mel.FBXExportBakeComplexStart(value=startFrame) pm.mel.FBXExportBakeComplexEnd(value=endFrame) cmd.bakeSimulation(skinJointsName, t=(startFrame, endFrame)) else: skinGroup = getSkinGeometry(skinJoints) exportGroup.extend(skinGroup) for constrainNode in rrSklJ.getChildren(ad=True, type='constraint'): cmd.delete(constrainNode.name()) # get base bone to the top of the hiarachy for joint in skinJoints: if 'ROOTSHJnt' in joint.name(): cmd.parent(joint.name(), world=True) if exportGroup: pm.select(exportGroup) pm.mel.FBXExport(f=outputFile, s=True)
def J_excuteExport(fileName,outType,bakeFrame): cmds.loadPlugin ( "fbxmaya") allCam=cmds.ls(type='camera') allCam.remove(u'frontShape') allCam.remove(u'perspShape') allCam.remove(u'sideShape') allCam.remove(u'topShape') for cam in allCam: if bakeFrame: camTransform=cmds.listRelatives(cam,p=True) start=cmds.playbackOptions(query=True,minTime=True) end=cmds.playbackOptions(query=True,maxTime=True) cmds.bakeSimulation( cam, t=(start,end), sb=1, at=["focalLength"], hi="below" ) cmds.bakeSimulation( camTransform[0], t=(start,end), sb=1, at=["rx","ry","rz","tx","ty","tz"], hi="below" ) cmds.select(cam) cmds.file((fileName[0:-3]+"_"+cam.replace(':','_')+'.fbx'), force=True ,options= "fbx" ,type ="FBX export" ,es=True )
def bake_CAM_ani(): sourceCAM=cmds.select('cam_hcam:shot') #确定UI上选择的摄像机,取得摄像机名称 #确定烘焙范围 cmds.listCameras( p=True ) #场景中所有透视摄像机 cameraName = cmds.camera() #创建新摄像机 cameraShape = cameraName[1]#获得新摄像机名称 bakeCAMnode='baked_CAM' cmds.rename(cameraShape,bakeCAMnode) #修改bakecam的名字 sourceCAMtransfer=cmds.listHistory( sourceCAM, il=1)[1] cmds.parentConstraint(sourceCAMtransfer, bakeCAMnode) cmds.select(bakeCAMnode) cmds.bakeSimulation(selectCam,t=(starten,ende),hi='below') cmds.select(bakeCAMnode) cmds.file(*args, **kwargs) pass
def bakeSimulation(*args, **kwargs): for flag in ['t', 'time']: try: rawVal = kwargs[flag] except KeyError: continue else: kwargs[flag] = _factories.convertTimeValues(rawVal) res = cmds.bakeSimulation(*args, **kwargs) return res
def J_bakeModeltoMd(frameRange=''): sel = cmds.ls(sl=True) if frameRange == "": frameRange = (cmds.playbackOptions(query=True, minTime=True), cmds.playbackOptions(query=True, maxTime=True)) startTime = (frameRange[0] - 30) filePath = cmds.file(query=True, sceneName=True).replace( cmds.file(query=True, sceneName=True, shortName=True), '') if cmds.file(query=True, sceneName=True, shortName=True) == '': cmds.confirmDialog(title=u'错误', message=u'文件未保存,或者需要另存为mb格式', button='好吧') return curves = [] meshs = [] for item in sel: chs = cmds.listRelatives(item, f=True, c=True) if cmds.objectType(item, isType='mesh'): meshs.append(item) continue if cmds.objectType(item, isType='nurbsCurve'): curves.append(item) continue for i1 in chs: if cmds.objectType(i1, isType='mesh'): meshs.append(item) break if cmds.objectType(i1, isType='nurbsCurve'): curves.append(item) break if (len(curves)) > 0: cmds.bakeSimulation(curves, t=frameRange, at=["tx", "ty", "tz", "rx", "ry", "rz"]) cmds.playbackOptions(minTime=startTime) keyFrameAttr = [ 'translateX', 'translateY', 'translateZ', 'rotateX', 'rotateY', 'rotateZ' ] cmds.setKeyframe(curves, at=keyFrameAttr, v=0, t=[str(startTime)]) if len(meshs) > 0: JpyModules.vfx.J_CFXWorkFlow.J_CFXWorkFlow_outAbcGeo(meshs, '', 1) cmds.playbackOptions(minTime=frameRange[0])
def bakeDynChain_cmd(*args): #some basic inupt queries. checkDisNuc = cmds.checkBox('nucleusDisableBoul', q=True, v=True) rootJntFieldInput = cmds.textFieldGrp('lastDynChainRootName', q=True, tx=True) endJntCheck = cmds.checkBox('goToEndBoul', q=True, v=True) endJntFieldInput = cmds.textFieldGrp('endJntSelInput', q=True, tx=True) #bakes joints from input joint to end joint that might also be input. if rootJntFieldInput: cmds.select(rootJntFieldInput) findChild = cmds.listRelatives(ad=True, type='joint') totalJoints = [rootJntFieldInput] + findChild cmds.select(totalJoints) if not endJntCheck: cmds.select(endJntFieldInput) checkEndChild = cmds.listRelatives(ad=True, type='joint') checkEndChildLen = len(checkEndChild) if checkEndChildLen >= 1: totalEndJoints = [endJntFieldInput] + checkEndChild else: totalEndJoints = [endJntFieldInput] newTotalJnts = [] for i in range(len(totalJoints)): if totalJoints[i] not in totalEndJoints: newTotalJnts.append(totalJoints[i]) cmds.select(newTotalJnts) cmds.bakeSimulation(t=(0, 500)) #if disable nucleus was turned on, this would disable the nucleus. if checkDisNuc: findNuc = cmds.ls(type='nucleus') cmds.select(findNuc) cmds.setAttr(findNuc[0] + '.enable', 0) #output. sys.stdout.write('Dyn Chain baked. Smells like cookies.')
def particleLocators(particle, bakeSimulation=False, rotate=False, scale=False, start=0, end=-1, prefix=''): """ """ # Check Particle if not cmds.objExists(particle): raise Exception('Object "' + nParticle + '" is not a valid particle or nParticle object!') # Check Prefix if not prefix: prefix = particle # Get particle count count = cmds.getAttr(particle + '.count') if not count: raise Exception('Invalid particle count! (' + count + ')') # Create locators partiLocs = [cmds.spaceLocator(n=prefix + '_loc' + str(i))[0] for i in range(count)] partiLocsGrp = prefix + '_locGrp' if not cmds.objExists(partiLocsGrp): partiLocsGrp = cmds.group(em=True, n=partiLocsGrp) cmds.parent(partiLocs, partiLocsGrp) # For each particle, set locator position for i in range(count): pt = cmds.pointPosition(particle + '.pt[' + str(i) + ']') cmds.setAttr(partiLocs[i] + '.t', *pt) if rotate: rt = cmds.particle(particle, q=True, at='rotatePP', id=i) cmds.setAttr(partiLocs[i] + '.r', *rt) if scale: sc = cmds.particle(particle, q=True, at='scalePP', id=i) cmds.setAttr(partiLocs[i] + '.s', *sc) # Bake Simulation if (bakeSimulation): # Append particle expression expStr = '\n\n//--\n' expStr += 'int $id = id;\n' expStr += 'vector $pos = pos;\n' expStr += 'string $loc = ("' + prefix + '_loc"+$id);\n' expStr += 'if(`objExists $loc`){' expStr += '\t move -a ($pos.x) ($pos.y) ($pos.z) $loc;\n' if rotate: expStr += '\tvector $rot = rotatePP;\n' expStr += '\t rotate -a ($rot.x) ($rot.y) ($rot.z) $loc;\n' if scale: expStr += '\tvector $scl = scalePP;\n' expStr += '\t scale -a ($scl.x) ($scl.y) ($scl.z) $loc;\n' expStr += '}' # Old expression string oldRadStr = cmds.dynExpression(particle, q=True, s=True, rad=True) # Apply particle expression cmds.dynExpression(particle, s=oldRadStr + expStr, rad=True) # Bake to keyframes if end < start: start = cmds.playbackOptions(q=True, min=True) end = cmds.playbackOptions(q=True, max=True) bakeAttrs = ['tx', 'ty', 'tz'] if rotate: bakeAttrs.extend(['rx', 'ry', 'rz']) if scale: bakeAttrs.extend(['sx', 'sy', 'sz']) cmds.bakeSimulation(partiLocs, at=bakeAttrs, t=(start, end)) # Restore particle expression cmds.dynExpression(particle, s=oldRadStr, rad=True)
def particleLocators(particle, bakeSimulation=False, rotate=False, scale=False, start=0, end=-1, prefix=''): ''' ''' # Check Particle if not mc.objExists(particle): raise Exception('Object "' + nParticle + '" is not a valid particle or nParticle object!') # Check Prefix if not prefix: prefix = particle # Get particle count count = mc.getAttr(particle + '.count') if not count: raise Exception('Invalid particle count! (' + count + ')') # Create locators partiLocs = [ mc.spaceLocator(n=prefix + '_loc' + str(i))[0] for i in range(count) ] partiLocsGrp = prefix + '_locGrp' if not mc.objExists(partiLocsGrp): partiLocsGrp = mc.group(em=True, n=partiLocsGrp) mc.parent(partiLocs, partiLocsGrp) # For each particle, set locator position for i in range(count): pt = mc.pointPosition(particle + '.pt[' + str(i) + ']') mc.setAttr(partiLocs[i] + '.t', *pt) if rotate: rt = mc.particle(particle, q=True, at='rotatePP', id=i) mc.setAttr(partiLocs[i] + '.r', *rt) if scale: sc = mc.particle(particle, q=True, at='scalePP', id=i) mc.setAttr(partiLocs[i] + '.s', *sc) # Bake Simulation if (bakeSimulation): # Append particle expression expStr = '\n\n//--\n' expStr += 'int $id = id;\n' expStr += 'vector $pos = pos;\n' expStr += 'string $loc = ("' + prefix + '_loc"+$id);\n' expStr += 'if(`objExists $loc`){' expStr += '\t move -a ($pos.x) ($pos.y) ($pos.z) $loc;\n' if rotate: expStr += '\tvector $rot = rotatePP;\n' expStr += '\t rotate -a ($rot.x) ($rot.y) ($rot.z) $loc;\n' if scale: expStr += '\tvector $scl = scalePP;\n' expStr += '\t scale -a ($scl.x) ($scl.y) ($scl.z) $loc;\n' expStr += '}' # Old expression string oldRadStr = mc.dynExpression(particle, q=True, s=True, rad=True) # Apply particle expression mc.dynExpression(particle, s=oldRadStr + expStr, rad=True) # Bake to keyframes if end < start: start = mc.playbackOptions(q=True, min=True) end = mc.playbackOptions(q=True, max=True) bakeAttrs = ['tx', 'ty', 'tz'] if rotate: bakeAttrs.extend(['rx', 'ry', 'rz']) if scale: bakeAttrs.extend(['sx', 'sy', 'sz']) mc.bakeSimulation(partiLocs, at=bakeAttrs, t=(start, end)) # Restore particle expression mc.dynExpression(particle, s=oldRadStr, rad=True)
def bakeall(): amintime = cmds.playbackOptions(query=1, minTime=1) amaxtime = cmds.playbackOptions(query=1, maxTime=1) listtobake = selectallcontrols() cmds.bakeSimulation(listtobake, t=(amintime, amaxtime))