def extractFromRigidSet( *args, **kw ): rbSets = _findRigidSetsFromSelection() memberObjects = set(kw['members'] if kw.has_key('members') else maya.cmds.ls(sl=True, type='transform')) for rbSet in rbSets: extractObjects = memberObjects.intersection(set(maya.cmds.sets( rbSet, q=True ))) if len(extractObjects): CreateRigidSet.removeFromRigidSet([rbSet], members=list(extractObjects)) # read attributes from rigidset rbInitialState = _getInitialState(rbSet) kwArgs = {'bodyType':eBodyType.kDynamicRigidBody, 'autoFit':True, 'bAttachSelected':False} for attr, mappedAttr in CreateRigidSet.extractableAttrs.iteritems(): attrVal =_getAttr(rbInitialState,attr) # getAttr returns [()] for vector values if type(attrVal) in [types.ListType] and type(attrVal[0]) in [types.TupleType]: attrVal = attrVal[0] kwArgs[mappedAttr]=attrVal for object in extractObjects: kwArgs['transformName'] = object rtn = CreateRigidBody().command(**kwArgs) BulletUtils.setAsIntermediateObjects( extractObjects, 0 )
def clearRigidSets( *args, **kw ): rbSets = _findRigidSetsFromSelection(excludeTransforms=True) if len(rbSets)==0: OpenMaya.MGlobal.displayError(maya.stringTable[ 'y_RigidBody.kErrorClearNoRigidSetSelected' ]) return for rbSet in rbSets: members = maya.cmds.sets( rbSet, q=True ) maya.cmds.sets( e=True, clear=rbSet ) BulletUtils.setAsIntermediateObjects(members,0) return rbSets
def deleteRigidSets( *args, **kw ): from BulletUtils import removeBulletObjectsFromList rbSets = _findRigidSetsFromSelection(excludeTransforms=True) if len(rbSets)==0: OpenMaya.MGlobal.displayError(maya.stringTable[ 'y_RigidBody.kErrorDeleteNoRigidSetSelected' ]) return for rbSet in rbSets: members = maya.cmds.sets( rbSet, q=True ) BulletUtils.setAsIntermediateObjects(members,0) removeBulletObjectsFromList(list(rbSets)) return
def removeFromRigidSet( *args, **kw ): rbSets = args[0] if len(args) else _findRigidSetsFromSelection(excludeTransforms=True) removeObjects = kw['members'] if kw.has_key('members') else maya.cmds.ls(sl=True, type='transform') excludeSets = kw['excludeSets'] if kw.has_key('excludeSets') else [] if len(rbSets)==0: rbSets = _findRigidSetsFromMembers(removeObjects) # only remove from sets not in excludeSets rbSets = set(rbSets).difference(set(excludeSets)) for rbSet in rbSets: BulletUtils.setAsIntermediateObjects( removeObjects, 0 ) maya.cmds.sets( removeObjects, e=True, remove=rbSet ) return removeObjects
def command( **kwargs ): """ main entry point for command """ # To create an empty set pass an empty list for the objects # argument args=[] sl=True if kwargs.has_key('sl'): sl = kwargs['sl'] kwargs.pop('sl') hideShape = False if kwargs.has_key('hideShape'): hideShape = kwargs['hideShape'] kwargs.pop('hideShape') if not sl: args.append([]) objects = _getSelectedTransforms() if sl else [] # ensure exclusive if len(objects): rbSets = _findRigidSetsFromMembers(objects) if len(rbSets): CreateRigidSet.removeFromRigidSet( rbSets, members=objects) result = maya.cmds.bulletRigidSets( *args, **kwargs ) ''' return result from command ''' if result: # hide source objects if hideShape: BulletUtils.setAsIntermediateObjects( objects, 1, deferred=True ) # If command echoing is off, echo this short line. if (not maya.cmds.commandEcho(query=True, state=True)): print "// Result: %s //" % (string.join(result, " ")) return result
def addToRigidSet( *args, **kw ): rbSets = _findRigidSetsFromSelection(excludeTransforms=True) if len(rbSets)>1: OpenMaya.MGlobal.displayError(maya.stringTable['y_RigidBody.kAmbiguousAddToSet' ]) return if len(rbSets)==0: OpenMaya.MGlobal.displayError(maya.stringTable['y_RigidBody.kNoRigidSetToAddSelected' ]) return addObjects = kw['members'] if kw.has_key('members') else maya.cmds.ls(sl=True, type='transform') hideShape = kw['hideShape'] if kw.has_key('hideShape') else True # filter out objects with rigid body shapes filteredAddObjects = [] bulletObjects = [] for object in addObjects: if BulletUtils.getRigidBodyFromTransform(object): OpenMaya.MGlobal.displayInfo(maya.stringTable['y_RigidBody.kAlreadyRigidBody' ].format(object)) bulletObjects.append(object) else: filteredAddObjects.append(object) # ensure exclusive if len(filteredAddObjects): CreateRigidSet.removeFromRigidSet(members=filteredAddObjects, excludeSets=rbSets) # remove bullet rigid shape from objects if len(bulletObjects): BulletUtils.removeBulletObjectsFromList(bulletObjects) filteredAddObjects.extend( bulletObjects ) if len(filteredAddObjects): maya.cmds.sets( filteredAddObjects, e=True, addElement=rbSets[0] ) if hideShape: BulletUtils.setAsIntermediateObjects( filteredAddObjects, 1, deferred=True )