def locatorParticles(locList, particle, radius=1, selfCollide=False, rotatePP=False, scalePP=False): """ """ # Check locator list if not locList: return # Check particles if not particle: particle = 'particle1' if not cmds.objExists(particle): particle = cmds.nParticle(n=particle)[0] # Set Particle Object Attrs cmds.setAttr(particle + '.particleRenderType', 4) cmds.setAttr(particle + '.radius', cmds.floatSliderGrp('locParticle_radiusFSG', q=True, v=True)) cmds.setAttr( particle + '.selfCollide', cmds.checkBoxGrp('locParticle_selfCollideCBG', q=True, v1=True)) # Create particles ptList = [cmds.pointPosition(i) for i in locList] cmds.emit(o=particle, pos=ptList) # Add and Set RotatePP/ScalePP Values if rotatePP: # Check rotatePP attrs if not cmds.objExists(particle + '.rotatePP'): addRotatePP(particle) # Set rotatePP attrs for i in range(len(locList)): rot = cmds.getAttr(locList[i] + '.r') cmds.particle(particle, e=True, at='rotatePP', id=i, vv=rot[0]) if scalePP: # Check scalePP attrs if not cmds.objExists(particle + '.scalePP'): addScalePP(particle) # Set scalePP attrs for i in range(len(locList)): scl = cmds.getAttr(locList[i] + '.s') cmds.particle(particle, e=True, at='scalePP', id=i, vv=scl[0]) # Save Initial State cmds.saveInitialState(particle)
def locatorParticles(locList, particle, radius=1, selfCollide=False, rotatePP=False, scalePP=False): """ """ # Check locator list if not locList: return # Check particles if not particle: particle = 'particle1' if not cmds.objExists(particle): particle = cmds.nParticle(n=particle)[0] # Set Particle Object Attrs cmds.setAttr(particle + '.particleRenderType', 4) cmds.setAttr(particle + '.radius', cmds.floatSliderGrp('locParticle_radiusFSG', q=True, v=True)) cmds.setAttr(particle + '.selfCollide', cmds.checkBoxGrp('locParticle_selfCollideCBG', q=True, v1=True)) # Create particles ptList = [cmds.pointPosition(i) for i in locList] cmds.emit(o=particle, pos=ptList) # Add and Set RotatePP/ScalePP Values if rotatePP: # Check rotatePP attrs if not cmds.objExists(particle + '.rotatePP'): addRotatePP(particle) # Set rotatePP attrs for i in range(len(locList)): rot = cmds.getAttr(locList[i] + '.r') cmds.particle(particle, e=True, at='rotatePP', id=i, vv=rot[0]) if scalePP: # Check scalePP attrs if not cmds.objExists(particle + '.scalePP'): addScalePP(particle) # Set scalePP attrs for i in range(len(locList)): scl = cmds.getAttr(locList[i] + '.s') cmds.particle(particle, e=True, at='scalePP', id=i, vv=scl[0]) # Save Initial State cmds.saveInitialState(particle)
def createParticleSystem_goal(): # Create a constant sized particle object following a deformed torus shape (using goal) cmds.file(new=True, force=True) # Create a torus, we will use it as goal xrez = 14 yrez = 8 goalTorus = cmds.polyTorus( r=1, sr=0.5, tw=0, sx=xrez, sy=yrez, ax=(0, 1, 0), cuv=1, ch=0)[0] # nParticle creation depends on an optoinVar value, make sure we use the default one cmds.optionVar( sv=("NParticleStyle","Points") ) # Emit a lot of particle, the actual number will be limited to the max particle attribute in the particleShape emitter = cmds.emitter(dx=1, dy=0, dz=0, sp=0.1, pos=(0, 5, 0),rate=2500)[0] particleSystem, particleSystemShape = cmds.nParticle(n="nParticle_test_goal") cmds.setAttr('%s.lfm' % particleSystemShape, 0) # live forever cmds.setAttr('%s.particleRenderType' % particleSystemShape, 7) # Blobby, to see radius cmds.setAttr('%s.maxCount' % particleSystemShape, xrez*yrez) # max count is the number of vertices on the torus cmds.connectDynamic( particleSystemShape, em=emitter) # Create Goal cmds.goal(particleSystem, w=1, utr=0, g=goalTorus); # Create Initial state to we start with the correct amount of particle # NOTE: When using this script in command line, the first frame is not correctly evaluated and the particleShape is empty # This doesn't happens in interactive maya for i in range(1, 10): cmds.currentTime(i) cmds.saveInitialState(particleSystemShape) cmds.currentTime(1) bend, bendHandle = cmds.nonLinear( goalTorus, type="bend", lowBound=-1, highBound=1, curvature=0) cmds.setAttr( "%s.rotateZ" % bendHandle, 90) cmds.setKeyframe( "%s.curvature" % bend, v=0, t=1, inTangentType="flat", outTangentType="flat") cmds.setKeyframe( "%s.curvature" % bend, v=-130, t=12, inTangentType="flat", outTangentType="flat") cmds.setKeyframe( "%s.curvature" % bend, v=130, t=24, inTangentType="flat", outTangentType="flat") # Make the bend animation loop cmds.setInfinity( bend, poi="oscillate", attribute="curvature") return particleSystem, particleSystemShape
def createParticleSystem_goal(): # Create a constant sized particle object following a deformed torus shape (using goal) cmds.file(new=True, force=True) # Create a torus, we will use it as goal xrez = 14 yrez = 8 goalTorus = cmds.polyTorus(r=1, sr=0.5, tw=0, sx=xrez, sy=yrez, ax=(0, 1, 0), cuv=1, ch=0)[0] # nParticle creation depends on an optoinVar value, make sure we use the default one cmds.optionVar(sv=("NParticleStyle", "Points")) # Emit a lot of particle, the actual number will be limited to the max particle attribute in the particleShape emitter = cmds.emitter(dx=1, dy=0, dz=0, sp=0.1, pos=(0, 5, 0), rate=2500)[0] particleSystem, particleSystemShape = cmds.nParticle(n="nParticle_test_goal") cmds.setAttr('%s.lfm' % particleSystemShape, 0) # live forever cmds.setAttr('%s.particleRenderType' % particleSystemShape, 7) # Blobby, to see radius cmds.setAttr('%s.maxCount' % particleSystemShape, xrez * yrez) # max count is the number of vertices on the torus cmds.connectDynamic(particleSystemShape, em=emitter) # Create Goal cmds.goal(particleSystem, w=1, utr=0, g=goalTorus); # Create Initial state to we start with the correct amount of particle # NOTE: When using this script in command line, the first frame is not correctly evaluated and the particleShape is empty # This doesn't happens in interactive maya for i in range(1, 10): cmds.currentTime(i) cmds.saveInitialState(particleSystemShape) cmds.currentTime(1) bend, bendHandle = cmds.nonLinear(goalTorus, type="bend", lowBound=-1, highBound=1, curvature=0) cmds.setAttr("%s.rotateZ" % bendHandle, 90) cmds.setKeyframe("%s.curvature" % bend, v=0, t=1, inTangentType="flat", outTangentType="flat") cmds.setKeyframe("%s.curvature" % bend, v=-130, t=12, inTangentType="flat", outTangentType="flat") cmds.setKeyframe("%s.curvature" % bend, v=130, t=24, inTangentType="flat", outTangentType="flat") # Make the bend animation loop cmds.setInfinity(bend, poi="oscillate", attribute="curvature") return particleSystem, particleSystemShape
def qsEmit(object, position, attributes, clearAndSaveState=True, **kwargs): '''{'del_path':'Dynamics/Particles/qsEmit("particleShape", position=posLi, attributes=(("cus_bbsi", "vectorValue", bbsiLi), ("cus_area", "floatValue", areaLi) ), clearAndSaveState=True )ONLYSE', 'icon':':/particle.svg', 'tip':'创建粒子', 'usage':'\ objects = cmds.listRelatives(cmds.ls(sl=True, exactType="transform", l=True), type="transform",f=True)\\n\ posLi, radiusLi, atULi, atVLi = [], [], [], []\\n\ for tfNode in objects:\\n\ objPos = cmds.objectCenter(tfNode)\\n\ bbsize = cmds.getAttr(tfNode+".bbsi")[0]\\n\ radius = qm.vectorLen(bbsize)/2\\n\ atU = cmds.getAttr(tfNode+".atU")\\n\ atV = cmds.getAttr(tfNode+".atV")\\n\ posLi.append(objPos)\\n\ radiusLi.append(radius)\\n\ atULi.append(atU)\\n\ atVLi.append(atV)\\n\ $fun(object = "new", position=posLi, attributes=[("cus_bbsi", "floatValue", radiusLi), ("cus_area", "floatValue", areaLi) ] )', 'help':'对emit command重新进行了一下打包', } ''' createNew = True parType = ('particle', 'nParticle') if cmds.objExists(object): if cmds.objectType(object) in parType: createNew = False else: shapes = cmds.listRelatives(object, shapes=True)[0] if cmds.objExists(shapes) in parType: object = shapes createNew = False if createNew: if kwargs.get('type', None) == 'particle': nPar = cmds.particle() else: nPar = cmds.nParticle() object = nPar[1] #if cmds.objectType(object) != 'nParticle': #raise IOError('%s is not nParticle object'%object) posLen = len(position) for attr in list(attributes): if len(attr[2]) != posLen: if createNew: cmds.delete(cmds.listRelatives(object, parent)) raise IOError('%s count is difence with position count' % (attr[0])) for attr in attributes: if cmds.attributeQuery(attr[0], node=object, exists=True) == False: print attr[1] if attr[1] == 'floatValue': attrType = 'doubleArray' elif attr[1] == 'vectorValue': attrType = 'vectorArray' else: raise IOError('value type is not floatValue or vectorValue') cmds.addAttr(object, ln=attr[0] + '0', dt=attrType) cmds.addAttr(object, ln=attr[0], dt=attrType) emitStr = 'emit -object %s ' % (object) for data in position: emitStr += ' -pos %s %s %s ' % (data[0], data[1], data[2]) if clearAndSaveState: startF = cmds.playbackOptions(q=True, min=True) cmds.currentTime(startF + 1, e=True) mel.eval("clearParticleStartState %s" % (object)) cmds.currentTime(startF, e=True) for attr in attributes: emitStr += '\n\n-attribute %s ' % (attr[0]) if attr[1] == 'floatValue': for data in attr[2]: emitStr += ' -%s %s ' % (attr[1], data) elif attr[1] == 'vectorValue': for data in attr[2]: emitStr += ' -%s %s %s %s ' % (attr[1], data[0], data[1], data[2]) else: raise IOError('value type is not floatValue or vectorValue') #return emitStr mel.eval(emitStr) if clearAndSaveState: cmds.saveInitialState(object) return object
def doIt( self, argList ): """Processes a SpeedTree SWA file for forest instance locations""" mc.select( clear=True ) #define variables swaFile = swaName = '' SpeedTreeForest = SpeedTreeAsset = '' SpeedTreeForestAssets = [] arrObjects = [] arrObjNames = [] arrObjCount = [] arrTranslate = [] upRot = [] rightRot = [] outRot = [] arrScale = [] arrInstances = [] partCloud = [] treeArray = [] oCount = tCount = 0 objTotalCount = 0 swaCount = 0 treeCount = 0 objLen = 0 processMode = 2 argsLen = argList.length() startInd = 2 #process mode if argsLen > 1: processMode = argList.asInt(0) swaFile = argList.asString(1) if processMode == 1: SpeedTreeForest = argList.asString(2) startInd = 3 if argsLen > startInd: for a in range( startInd, argsLen ): treeArray.append( argList.asString(a) ) treeCount = len( treeArray ) #get SWA file if processMode == 2 and swaFile == '': if MayaVersion >= 2012: try: swaFile = mc.fileDialog2( fileMode=1, caption="Select a SpeedTree SWA file", okc="Load", fileFilter="*.swa", dialogStyle=2 )[0] except: swaFile = '' else: swaFile = mc.fileDialog( mode=0, title='Select a SpeedTree SWA file', directoryMask='*.swa' ) swaExists = ( os.path.exists( swaFile ) and not os.path.isdir( swaFile ) ) if swaExists: swaName = swaFile.rpartition("/")[2] swaName = swaName[:-4] #reloading forest node if processMode == 1: if MayaVersion >= 2012: SpeedTreeForest = mc.rename( SpeedTreeForest, swaName + '_Forest' ) oldParticleSets = [] particleSetInds = mc.getAttr( SpeedTreeForest + '.particleSets', mi=1 ) if particleSetInds != None: for p in particleSetInds: particleSet = mc.connectionInfo( SpeedTreeForest + '.particleSets[' + str(p) + ']', sfd=1 ).split( '.' )[0] forestObject = mc.connectionInfo( SpeedTreeForest + '.forestObjects[' + str(p) + ']', sfd=1 ).split( '.' )[0] if particleSet != '': mc.removeMultiInstance( SpeedTreeForest + '.particleSets[' + str(p) + ']', b=True ) mc.removeMultiInstance( SpeedTreeForest + '.forestObjects[' + str(p) + ']', b=True ) if mc.objExists( forestObject ): mc.setAttr( forestObject + '.visibility', 1 ) oldParticleSets.append( particleSet ) particleSetShapes = mc.listRelatives( particleSet, s=1 ) if particleSetShapes != None and len( particleSetShapes ) > 0: particleSetShape = particleSetShapes[0] cons = mc.listConnections( particleSetShape, d=1 ) if cons != None and len( cons ) > 0: for c in cons: if ( mc.nodeType( c ) == 'instancer' ): oldParticleSets.append( c ) for s in oldParticleSets: if mc.objExists( s ): mc.delete( s ) else: SpeedTreeForest = mc.createNode( 'SpeedTreeForest', name=swaName + '_Forest' ) mc.setAttr( SpeedTreeForest + '.swaFile', swaFile, type='string' ) SpeedTreeForestAssets.append( SpeedTreeForest ) #create asset if MayaVersion >= 2009: if processMode == 1: SpeedTreeAsset = mc.container( q=True, findContainer=[ SpeedTreeForest ] ) if SpeedTreeAsset != '': if MayaVersion >= 2012: SpeedTreeAsset = mc.rename( SpeedTreeAsset, swaName ) mc.container( SpeedTreeAsset, edit=True, addNode=SpeedTreeForest, force=True ) else: #create container SpeedTreeAsset = mc.container( name=swaName, addNode=SpeedTreeForest, force=True ) #asset settings SpeedTreeFbxPath = mc.pluginInfo( 'SpeedTreeForest.py', path=True, query=True ) SpeedTreeFbxPart = SpeedTreeFbxPath.rpartition( '/' ) if MayaVersion >= 2011: SpeedTreeIconPath = SpeedTreeFbxPart[0] + '/icons/SpeedTreeForest.png' else: SpeedTreeIconPath = SpeedTreeFbxPart[0] + 'icons/out_SpeedTreeForest.xpm' if os.path.isfile( SpeedTreeIconPath ): mc.setAttr( SpeedTreeAsset + '.iconName', SpeedTreeIconPath, type='string' ) elif mc.objExists( SpeedTreeAsset + '.isAsset' ): mc.setAttr( SpeedTreeAsset + '.isAsset', 1 ) mc.setAttr( SpeedTreeAsset + '.viewMode', 0 ) #open SWA file swaData = open(swaFile, 'r') while True: line = swaData.readline() if len(line) == 0: break #EOF while len(line) == 1 or line == "\r\n": line = swaData.readline() if line != "" and line != "\t" and line != "\n" and line!= "\r\n": if line[(len(line) - 2):] == "\r\n": line = line[:(len(line) - 2)] elif line[(len(line) - 1):] == "\n": line = line[:(len(line) - 1)] arrObjNames.append( self.stStripIllegalChars( line ) ) line = swaData.readline() swaCount = int( line ) arrObjCount.append( swaCount ) for t in range(0, swaCount): line = swaData.readline() swa_instance = line.split(' ') #flip Y and Z and negate Z (Y-up conversion) arrTranslate.append( [float( swa_instance[0]), float( swa_instance[2] ), float( swa_instance[1] ) * -1] ) upRot.append( [float( swa_instance[3] ), float( swa_instance[4] ), float( swa_instance[5] )] ) rightRot.append( [float( swa_instance[6] ), float( swa_instance[7] ), float( swa_instance[8] )] ) outRot.append( self.stCross ( upRot[tCount], rightRot[tCount] ) ) arrScale.append( float( swa_instance[9][:-1] ) ) tCount = tCount + 1 j = 0 objLen = len( arrObjNames ) #handle tree entries for t in range( 0, objLen ): objName = arrObjNames[t][1:-1] arrInstances = [] #particle object partCloud = mc.particle( p=arrTranslate[objTotalCount:( objTotalCount + arrObjCount[t] )] ) partCloud[0] = mc.rename( partCloud[0], objName ) partCloud[1] = mc.listRelatives( partCloud[0], s=1 )[0] particleCons = mc.listConnections( partCloud[1], p=1, c=1 ) if len( particleCons ) == 4: mc.disconnectAttr( particleCons[0], particleCons[1] ) mc.disconnectAttr( particleCons[3], particleCons[2] ) mc.addAttr( partCloud[1], ln = 'rotationPP', dt='vectorArray', h=1 ) mc.addAttr( partCloud[1], ln = 'UserVector1PP', dt='vectorArray', h=1 ) if MayaVersion >= 2009 and SpeedTreeAsset != '': mc.container( SpeedTreeAsset, edit=True, addNode=partCloud, force=True ) connectedSets = mc.getAttr( SpeedTreeForest + '.particleSets', mi=1 ) setIndex = 0 if connectedSets != None: setIndex = len( connectedSets ) mc.connectAttr( partCloud[0] + '.message', SpeedTreeForest + '.particleSets[' + str( setIndex ) + ']' ) #handle instances objTotalCount = objTotalCount + arrObjCount[t] for i in range(0, arrObjCount[t]): #transpose the Z-up matrix mMatrix = om.MMatrix() toYupMatrix = om.MMatrix() instRotation = [ rightRot[j][0], rightRot[j][1], rightRot[j][2], 0, outRot[j][0], outRot[j][1], outRot[j][2], 0, upRot[j][0], upRot[j][1], upRot[j][2], 0, 0, 0, 0, 1 ] toYup = [ 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1 ] om.MScriptUtil.createMatrixFromList( instRotation, mMatrix ) om.MScriptUtil.createMatrixFromList( toYup, toYupMatrix ) yUpMatrix = mMatrix * toYupMatrix mTransformMtx = om.MTransformationMatrix( yUpMatrix ) eulerRot = mTransformMtx.eulerRotation() angles = [ math.degrees( angle ) for angle in ( eulerRot.x, eulerRot.y, eulerRot.z ) ] angles[0] += 90 mc.particle( e=True, attribute='rotationPP', order=i, vectorValue=angles ) mc.particle( e=True, attribute='UserVector1PP', order=i, vectorValue=( arrScale[j], arrScale[j], arrScale[j] ) ) j += 1 #create cache cacheDir = sceneCacheDir = swaDir = '' sceneFullPath = mc.file( q=True, sn=True ) projectDir = mc.workspace( q=True, rd=True ) if sceneFullPath != '': sceneName = sceneFullPath.rpartition( '/' )[2].rpartition( '.' )[0] else: strDateTime = 'tmp' dateTime = str( datetime.datetime.now() ) dateTime = dateTime.rpartition( ':' )[0] dateTime = re.split( '-| |:', dateTime ) if len( dateTime ) >= 5: strDateTime = dateTime[0] + dateTime[1] + dateTime[2] + '.' + dateTime[3] + dateTime[4] sceneName = getpass.getuser() + '.' + strDateTime particleDir = projectDir + 'particles' if not os.path.exists( particleDir ): os.mkdir( particleDir ) swaSceneDir = sceneName dynGlobalsNode = mc.dynGlobals( q=True, a=True ) curCacheDir = mc.getAttr( dynGlobalsNode + '.cacheDirectory' ) #copy cache from previous file save if curCacheDir != '' and curCacheDir != None and not os.path.exists( particleDir + '/' + swaSceneDir ): shutil.copytree( particleDir + '/' + curCacheDir, particleDir + '/' + swaSceneDir ) #or make a new folder for current scene cache elif not os.path.exists( particleDir + '/' + swaSceneDir ): os.mkdir( particleDir + '/' + swaSceneDir ) #saving over an old file, so keep cache folder else: swaSceneDir = curCacheDir if swaSceneDir != None and swaSceneDir != '': mc.dynExport( partCloud[0], atr=( 'position', 'rotationPP', 'UserVector1PP' ), f='cache', p=swaSceneDir ) mc.saveInitialState( partCloud[1] ) #add trees if treeCount > t: mc.assignSpeedTreeForestEntry( SpeedTreeForest, partCloud[1], treeArray[t], setIndex, objName ) if mc.getAttr( SpeedTreeForest + '.hs' ) == 1 and mc.objExists( treeArray[t] + '.visibility' ): #hide skeleton if there is one rootBone = '' treeHistory = mc.listHistory( treeArray[t] ) for h in treeHistory: if mc.nodeType( h ) == 'skinCluster': bindPose = mc.connectionInfo( h + '.bindPose', sfd=True ).split( '.' )[0] if bindPose != None and bindPose != '' and mc.objExists( bindPose ): rootBone = mc.connectionInfo( bindPose + '.members[0]', sfd=True ).split( '.' )[0] if rootBone != '' and mc.objExists( rootBone ): mc.setAttr( rootBone + '.visibility', 0 ) #hide source object mc.setAttr( treeArray[t] + '.visibility', 0 ) #if processMode == 0: mc.select( SpeedTreeForest ) if mel.eval( 'exists refreshEditorTemplates' ) and processMode == 0: mc.refreshEditorTemplates()
def miSequence(start=None, end=None): '''{'path':'Rendering/Render/miSequence()ONLYSE', 'icon' : ':/menuIconRender.png', 'tip' : '将物体转为mentalray代理的粒子替代', 'usage':'$fun( start=0, end=100)', } ''' projDir = cmds.workspace(q=1, rootDirectory=1) proxyFolder = os.path.join(projDir, 'data/mrProxyFiles') if os.path.exists(proxyFolder) == False: os.makedirs(proxyFolder) exportObjs = cmds.ls(sl=True) if start == None: start = cmds.playbackOptions(q=True, min=True) if end == None: end = cmds.playbackOptions(q=True, max=True) end = end + 1 pad = 5 padStr = '%0' + '%sd' % (pad) #print padStr subFolder = exportObjs[0] finalFolder = proxyFolder + '/' + subFolder if os.path.exists(finalFolder) == False: os.makedirs(finalFolder) import mentalray.renderProxyUtils proxyObjs = [] for i in range(start, end): cmds.currentTime(i) exec('frameStr = padStr%(i)') miName = '%s_s.%s.mi' % (exportObjs[0], frameStr) miFilePath = finalFolder + '/' + miName print miFilePath #miFilePath = 'F:/t.mi' cmds.select(exportObjs, r=True) mel.eval( 'Mayatomr -mi -exportFilter 721600 -active -binary -fe -fem -fma -fis -fcd -pcm -as -asn "%s" -xp "3313333333" -file "%s";' % (exportObjs[0] + "_s", miFilePath)) proxyName = miName.replace('.', '-') proxyObj = cmds.polyCube(ch=False, name=proxyName)[0] proxyObjs.append(proxyObj) boxShape = cmds.listRelatives(proxyObj, shapes=True)[0] cmds.setAttr(proxyObj + '.miProxyFile', miFilePath, type='string') mentalray.renderProxyUtils.resizeToBoundingBox(boxShape) cmds.setAttr(proxyObj + ".t", lock=True) cmds.setAttr(proxyObj + ".r", lock=True) cmds.setAttr(proxyObj + ".s", lock=True) cmds.currentTime(start) nPar, parShape = cmds.nParticle() cmds.setAttr(parShape + '.collide', 0) cmds.setAttr(parShape + ".conserve", 0) cmds.setAttr(parShape + ".dynamicsWeight", 0) cmds.setAttr(parShape + ".particleRenderType", 2) #cmds.setAttr( parShape+".selectedOnly", 1) cmds.addAttr(parShape, ln="cus_index0", dt="doubleArray") cmds.addAttr(parShape, ln="cus_index", dt="doubleArray") mel.eval('emit -object nParticle1 -pos 0 0 0') expString = "cus_index = clamp(0, %i, frame-%i);" % (end - start - 1, start) cmds.dynExpression(parShape, s=expString, c=True) cmds.dynExpression(parShape, s=expString, rbd=True) instancerObj = cmds.particleInstancer(parShape, addObject=True, object=proxyObjs, cycle='None', cycleStep=1, cycleStepUnits='Frames', levelOfDetail='Geometry', rotationUnits='Degrees', rotationOrder='XYZ', position='worldPosition', age='age') cmds.particleInstancer(parShape, e=True, name=instancerObj, objectIndex='cus_index') cmds.saveInitialState(parShape) miGrp = cmds.group(proxyObjs, n=exportObjs[0] + '_s_mi') cmds.setAttr(miGrp + '.v', False) cmds.setAttr(miGrp + '.v', lock=True) papaGrp = cmds.group([nPar, miGrp, instancerObj], n=exportObjs[0] + '_mi_group') for obj in (nPar, miGrp, instancerObj, papaGrp): cmds.setAttr(obj + ".t", lock=True) cmds.setAttr(obj + ".r", lock=True) cmds.setAttr(obj + ".s", lock=True)
def importPointCloudX(self, filePath): """ Read data from file - old method. Kept here for completeness. """ if os.path.isfile(filePath): # Check file exists # Read data into numpy array data = np.genfromtxt(filePath) count = data.shape[0] # Initialise progress bar and start timer mc.progressBar(self.gMainProgressBar, edit=True, beginProgress=True, isInterruptable=True, maxValue=count) # Initialise progress bar startTime = time.time() # Create group and particles etc. fileName = os.path.splitext(os.path.basename(filePath))[0] pCloudGroup = mc.group(name="%s_pointCloud_GRP" % fileName, empty=True) pCloudParticle = mc.particle(name="pCloud_%s" % fileName) #mel.eval('addAttr -ln "rgbPP" -dt vectorArray %s' %pCloudParticle[1]) #mel.eval('addAttr -ln "rgbPP0" -dt vectorArray %s' %pCloudParticle[1]) mc.addAttr(pCloudParticle[1], longName="rgbPP", dataType="vectorArray") mc.addAttr(pCloudParticle[1], longName="rgbPP0", dataType="vectorArray") for i in range(count): # # Progress bar # if mc.progressBar(self.gMainProgressBar, query=True, isCancelled=True): # Cancel operation if esc key pressed # mc.progressBar(self.gMainProgressBar, edit=True, endProgress=True) # Complete progress bar # mc.warning("Operation interrupted. You may wish to undo.") # return False # else: # mc.progressBar(self.gMainProgressBar, edit=True, step=1, status="Generating point cloud...") # Increment progress bar pX = data[i, 0] pY = data[i, 1] pZ = data[i, 2] pR = data[i, 3] / 255.0 pG = data[i, 4] / 255.0 pB = data[i, 5] / 255.0 # xyz = data[i,0:3] # rgb = data[i,3:6]/255 mel.eval('emit -o %s -at "rgbPP" -pos %s %s %s -vv %s %s %s' % (pCloudParticle[0], pX, pY, pZ, pR, pG, pB)) #mc.emit(object=pCloudParticle[0], position=xyz, attribute="rgbPP", vectorValue=rgb) mc.saveInitialState(pCloudParticle[0]) mc.setAttr("%s.isDynamic" % pCloudParticle[1], 0) mc.parent(pCloudParticle[0], pCloudGroup) # Complete progress bar and end clock mc.progressBar(self.gMainProgressBar, edit=True, endProgress=True) # Complete progress bar totalTime = time.time() - startTime print "Read %d points in %f seconds.\n" % (count, totalTime) return pCloudGroup else: mc.error("File doesn't exist: %s" % filePath) return False