示例#1
0
 def addDynamics(self,*args):
     for i in self.scene_before:
         self.obj = mc.listRelatives(i, p = True)
         mc.select(self.obj)
         mc.rigidBody( active = True, mass = 10, initialVelocity = (0.0,0.0,0.0), bounciness = 1, dynamicFriction = 0.8, damping = 0.2)
         self.G = mc.gravity(directionX = 0.0, directionY = -1.0, directionZ = 0.0, magnitude = 100)
         mc.connectDynamic(*self.obj, f = self.G)
示例#2
0
	def add_rigid_body( self, objects, magnitude = 50 ):
		
		cmds.rigidBody( objects, active = False, m = magnitude, collisions = False )
		
		cmds.gravity( pos = [0, 0, 0], m = magnitude, att = 0, dx = 0, dy = -1, dz = 0, mxd = -1, vsh = 'none', vex = 0, vof = [0, 0, 0], vsw = 360, tsr = 0.5 )
		gravity_dag = oopmaya.DAG_Node()
		cmds.connectDynamic( objects, fields = gravity_dag.name() )
示例#3
0
 def doIt(self,argList):
     cmds.polyPlane(n='myPlane', h=5, w=2)
     cmds.polySphere(n='mySphere', r=5)
     cmds.select('mySphere')
     cmds.move(0,5,0)
     cmds.rigidBody( n='myRigidBody', active=True, b=0.5, sf=0.4 )
     cmds.select(cl=True)
     cmds.gravity(n='myGravity')
     cmds.connectDynamic('mySphere', fields='myGravity')
示例#4
0
def _getRigidBody(obj):
    '''Restituisce il nodo di rigidBody.'''

    try:
        return cmds.rigidBody(obj, q=True, n=True)
    except:
        return None
def _getRigidBody(obj):
    '''Restituisce il nodo di rigidBody.'''

    try:
        return cmds.rigidBody(obj, q=True, n=True)
    except:
        return None
示例#6
0
    def add_rigid_body(self, objects, magnitude=50):

        cmds.rigidBody(objects, active=False, m=magnitude, collisions=False)

        cmds.gravity(pos=[0, 0, 0],
                     m=magnitude,
                     att=0,
                     dx=0,
                     dy=-1,
                     dz=0,
                     mxd=-1,
                     vsh='none',
                     vex=0,
                     vof=[0, 0, 0],
                     vsw=360,
                     tsr=0.5)
        gravity_dag = oopmaya.DAG_Node()
        cmds.connectDynamic(objects, fields=gravity_dag.name())
示例#7
0
 def importTerrain(self,*args):
     self.scene_before = mc.ls(type = "mesh")
     print self.scene_before
     mc.file(self.terrainName,i = True)
     self.scene_after = mc.ls(type = "mesh")
     print self.scene_after
     self.newObj = list(set(self.scene_after) - set(self.scene_before))
     print self.newObj
     mc.select(self.newObj)
     self.groundRS = mc.rigidSolver(create = True, name = "rigidSolver1", s = 1.0, ct = 1.0)
     self.groundRB = mc.rigidBody(passive = True, solver = "rigidSolver1", bounciness = 0.5, damping = 0.8, staticFriction = 1.0)
     mc.select(clear = True)
示例#8
0
def constrainAndRigibody():
    #store the current selection as the select list
    selectArray = cmds.ls( sl = True )

    #a loop that adds contrains and rigid bodies to the selected assets
    for mesh in selectArray:
        #store a temp mesh name
        origMeshName = str(mesh)
        #correct it to the original mesh name
        origMeshName = origMeshName.replace('D_', '')
        print (origMeshName)
        #store a reconstructed corresponding joint name
        jointName = (origMeshName + "_j")
        #add a constraint from the duplicate mesh (constrainor) to..
        # .. the joint (constrainee)
        cmds.parentConstraint( mesh, jointName, mo = 1 )
        #clear the selection
        cmds.select(cl=1)
        #select the duplicate mesh
        cmds.select(mesh)
        #add an active rigidbody
        cmds.rigidBody( active = 1)
        #clear the selection
        cmds.select(cl=1)
示例#9
0
文件: effects.py 项目: vondras/pymel
def rigidBody(*args, **kwargs):
    res = cmds.rigidBody(*args, **kwargs)
    if not kwargs.get('query', kwargs.get('q', False)):
        res = _factories.maybeConvert(res, _general.PyNode)
    return res
示例#10
0
        xp = cmds.getAttr(name)
        rnd = (0.8 + random.random())
        xp = xp * rnd
        cmds.setAttr(name, xp)
        name = n[0] + '.scaleZ'
        zp = cmds.getAttr(name)
        rnd = (0.8 + random.random())
        zp = zp * rnd
        cmds.setAttr(name, zp)
        offset = random.randint(0, altitude)
        raindrops.append(n[0])
        cmds.move(x, altitude + offset, z, n[0])
print raindrops
for drop in raindrops:
    rnd = -1 * (0.3 + random.random() * 0.2)
    rb = 'rb_' + drop
    print drop, ' ', rnd, ' ', rb
    cmds.select(drop)
    cmds.rigidBody(n=rb, active=True, iv=(0, rnd, 0))

#  polyPlane -ch on -o on -w 32.897207 -h 32.897207 -sw 1 -sh 1 -cuv 2 ;
cmds.polyPlane(n='ground',
               ch=True,
               o=True,
               w=32.29,
               h=32.29,
               sw=1,
               sh=1,
               cuv=2)
cmds.select('ground')
cmds.rigidBody(n='rb_ground', passive=True)
示例#11
0
def createLego(x, y, z, name, dimension, victime):

    g = cmds.radioButtonGrp("color", query=True, sl=True)

    #xlego=cmds.intSliderGrp('lLego', query=True, value=True)
    #zlego=cmds.intSliderGrp('loLego', query=True, value=True)

    #lego de base
    #Base
    cmds.polyCube(name="base", w=dimension, d=dimension, h=dimension)
    cmds.polyExtrudeFacet('base.f[3]', lsx=0.9, lsy=0.9, kft=True)
    cmds.polyExtrudeFacet('base.f[3]', ltz=-dimension, kft=True)
    cmds.delete("base.f[3]")

    if cmds.checkBox("bevel", query=True, value=True):
        cmds.polyBevel("base.e[0:11]",
                       "base.e[14]",
                       "base.e[16]",
                       "base.e[18]",
                       "base.e[19]",
                       offset=0.02 * dimension)

    #Cylindre
    cmds.polyCylinder(n="cercle0",
                      r=0.3 * dimension,
                      h=1.15 * dimension,
                      sx=20)
    cmds.move(0, 0.1 * dimension, 0, relative=True)
    cmds.polyExtrudeFacet('cercle0.f[20]', lsx=0.9, lsy=0.9, kft=True)
    cmds.polyExtrudeFacet('cercle0.f[20]', ltz=-dimension, kft=True)
    cmds.delete("cercle0.f[20]")

    if cmds.checkBox("bevel", query=True, value=True):
        cmds.polyBevel("cercle0.e[20:39]",
                       "cercle0.e[0:19]",
                       "cercle0.e[62:99]",
                       offset=0.02 * dimension)

    #Longueur, xLego
    '''for i in range (xlego-1):
        cmds.duplicate("cercle"+`i`, n="cercle"+`i+1`)
        cmds.select("cercle"+`i+1`)
        cmds.move(-2,0,0, relative=True)

    cmds.group("cercle*", name="cerclesx")'''

    # Largeur, zlego
    '''if zlego > 1 :
        for i in range (0, zlego):
            cmds.duplicate("cerclesx", n="cerclesz" +` i+1`)
            cmds.select("cerclesz"+`i+1`)
            cmds.move(0,0,2*i, relative=True)

        cmds.group("cerclesx", "cerclesz*", n="cercles")
        cmds.select("cercles")
        cmds.move(0,0,-zlego+1, relative=True)

    else :
        cmds.rename("cerclesx", "cercles")'''

    # Fin de creation du LEGO
    cmds.polyUnite("cercle0", "base", n="lego" + ` name `, ch=False)
    cmds.move(x, y, z)

    #Dynamique sur Lego
    if cmds.checkBox("physics", query=True, value=True) and cmds.checkBox(
            "animation", query=True, value=True) == False:
        cmds.rigidBody(n='RigidBodyLego', active=True, b=0.5, sf=0.4)

    #Shader
    cmds.shadingNode('blinn', name='legoBlinn' + ` name `, asShader=True)
    cmds.select("lego" + ` name `)
    cmds.hyperShade(assign="legoBlinn" + ` name `)
    cmds.textScrollList('colorblinn', query=True)

    #Selectionne la victime
    cmds.select(victime)

    #Couleur
    cmds.radioButtonGrp("color", query=True, sl=True)
    #Random
    if cmds.radioButtonGrp("color", query=True, sl=True) == 1:
        randIndClr = random.sample(indiceColor, 1)
        cmds.setAttr("legoBlinn" + ` name ` + ".color", randIndClr[0][0],
                     randIndClr[0][1], randIndClr[0][2])

    #Choice
    if cmds.radioButtonGrp("color", query=True, sl=True) == 3:
        colorChoice = cmds.textScrollList("colorblinn", query=True, sii=True)
        random.shuffle(colorChoice)
        cmds.setAttr("legoBlinn" + ` name ` + ".color",
                     indiceColor[colorChoice[0] - 1][0],
                     indiceColor[colorChoice[0] - 1][1],
                     indiceColor[colorChoice[0] - 1][2])

    if cmds.radioButtonGrp("color", query=True, sl=True) == 2:
        colorOther = cmds.colorSliderGrp("othrColor", query=True, rgb=True)
        cmds.setAttr("legoBlinn" + ` name ` + ".color", colorOther[0],
                     colorOther[1], colorOther[2])

    #Object
    if cmds.radioButtonGrp("color", query=True, sl=True) == 4:
        colorObject = colorClosestVertex(x, y, z)
        cmds.setAttr("legoBlinn" + ` name ` + ".color", colorObject[0],
                     colorObject[1], colorObject[2])
示例#12
0
def basicGround():
    cmds.polyPlane(name='Basic_Ground')
    cmds.select('Basic_Ground')
    cmds.rigidBody(active = False, passive = True)
    cmds.select(cl=1)
示例#13
0
def createBlocks(*args):
    ''' -Query GUI Values- '''
    horizontalCount = cmds.intField('horizontalCount', q=True, value=True)
    verticalCount = cmds.intField('verticalCount', q=True, value=True)
    blockScaling = cmds.floatField('blockScaling', q=True, value=True)
    blockSpacing = cmds.floatField('blockSpacing', q=True, value=True)
    blockBevel = cmds.intField('blockBevel', q=True, value=True)
    addCollision = cmds.checkBox('addCollision', q=True, value=True)
    ''' -Create Geo Grp- '''
    if cmds.objExists('blockMainGeo_grp'):
        blockMainGeoGrp = 'blockMainGeo_grp'

    else:
        blockMainGeoGrp = cmds.group(n='blockMainGeo_grp', em=True)
    ''' -Create Rig Grp- '''
    if cmds.objExists('blockMainRig_grp'):
        blockMainRigGrp = 'blockMainRig_grp'

    else:
        blockMainRigGrp = cmds.group(n='blockMainRig_grp', em=True)
    ''' -Create Controller Grp- '''
    if cmds.objExists('blockController_grp'):
        blockControllerGrp = 'blockController_grp'

    else:
        blockControllerGrp = cmds.group(n='blockController_grp', em=True)
    ''' -Create Geo Layer- '''
    if cmds.objExists('blockGeo_layer'):
        blockGeoLayer = 'blockGeo_layer'

    else:
        blockGeoLayer = cmds.createDisplayLayer(n='blockGeo_layer')
    ''' -Create Controller Layer- '''
    if cmds.objExists('blockController_layer'):
        blockControllerLayer = 'blockController_layer'

    else:
        blockControllerLayer = cmds.createDisplayLayer(
            n='blockController_layer')

    cmds.editDisplayLayerMembers(blockControllerLayer, blockControllerGrp)
    ''' -Build Controller- '''
    if cmds.objExists('blockTop*_controller'):
        cmds.select('blockTop*_controller')
        versionCount = cmds.ls(sl=True)
        versionCount = len(versionCount) + 1
        versionCount = str(versionCount)

    else:
        versionCount = '1'

    blockTopScaleX = (blockScaling * horizontalCount * 0.5) + (
        (horizontalCount - 1) * blockSpacing * 0.5) + blockScaling
    blockTopScaleZ = (blockScaling * verticalCount * 0.5) + (
        (verticalCount - 1) * blockSpacing * 0.5) + blockScaling

    blockTopController = cmds.curve(n='blockTop' + versionCount +
                                    '_controller',
                                    p=[(-blockTopScaleX, 0, -blockTopScaleZ),
                                       (blockTopScaleX, 0, -blockTopScaleZ),
                                       (blockTopScaleX, 0, blockTopScaleZ),
                                       (-blockTopScaleX, 0, blockTopScaleZ),
                                       (-blockTopScaleX, 0, -blockTopScaleZ)],
                                    d=1)

    blockController = cmds.circle(n='block' + versionCount + '_controller',
                                  nr=[0, 1, 0],
                                  r=blockScaling,
                                  ch=False)[0]
    radiusScaleAttr = createAttr(blockController, 'radiusScale', [0, 1])

    cmds.setAttr(blockController + '.translateY', blockScaling * 10)
    cmds.makeIdentity(blockController, apply=True, t=True, r=True, s=True, n=0)

    cmds.parent(blockController, blockTopController)
    cmds.parent(blockTopController, blockControllerGrp)

    blockRigTop = cmds.group(n='blockRigTop' + versionCount + '_grp',
                             p=blockMainRigGrp,
                             em=True)
    cmds.parentConstraint(blockTopController, blockRigTop, mo=True)
    cmds.scaleConstraint(blockTopController, blockRigTop, mo=True)

    blockCount = horizontalCount * verticalCount
    ''' -Progress Bar- '''
    progressName = progressBar('Building Blocks', blockCount)

    for block in range(blockCount):
        ''' -Block Count- '''
        if cmds.objExists('block*_geo'):
            cmds.select('block*_geo')
            blockVersion = cmds.ls(sl=True)
            blockVersion = len(blockVersion) + 1
            blockVersion = str(blockVersion)

        else:
            blockVersion = '1'

        blockGeoGrp = cmds.group(n='blockGeo' + blockVersion + '_grp',
                                 p=blockMainGeoGrp,
                                 em=True)
        blockRigGrp = cmds.group(n='blockRig' + blockVersion + '_grp',
                                 p=blockRigTop,
                                 em=True)
        ''' -Create Block- '''
        blockGeo = cmds.polyCube(n='block' + blockVersion + '_geo',
                                 w=blockScaling,
                                 h=blockScaling,
                                 d=blockScaling,
                                 ch=False)[0]

        cmds.parent(blockGeo, blockGeoGrp)
        cmds.editDisplayLayerMembers(blockGeoLayer, blockGeo)
        ''' -Extrude the Top poly- '''
        extrudeTop = cmds.polyExtrudeFacet(blockGeo + '.f[1]')[0]
        cmds.setAttr(extrudeTop + ".localScale", 0.7, 0.7, 0.7, type='double3')
        cmds.setAttr(extrudeTop + ".localTranslate",
                     0,
                     0,
                     blockScaling * 0.05,
                     type='double3')
        ''' -Translate Block to Ground Level- '''
        blockTop = cmds.xform(blockGeo + '.f[9]', ws=True, q=True, t=True)
        cmds.setAttr(blockGeo + '.translateY', -blockTop[1])
        ''' -Setup Distance- '''
        blockBaseLoc = cmds.spaceLocator(n='blockBase' + blockVersion +
                                         '_loc')[0]
        blockEndLoc = cmds.spaceLocator(n='blockEnd' + blockVersion +
                                        '_loc')[0]
        blockTopLoc = cmds.spaceLocator(n='blockTop' + blockVersion +
                                        '_loc')[0]
        blockLoc = cmds.spaceLocator(n='block' + blockVersion + '_loc')[0]

        cmds.parent(blockBaseLoc, blockEndLoc, blockLoc, blockTopLoc,
                    blockRigGrp)

        cmds.parentConstraint(blockController, blockTopLoc, blockEndLoc)
        cmds.setAttr(blockTopLoc + '.translateY', blockScaling * 10)
        ''' -Create Top Collision- '''
        if addCollision == True:

            collisionBlockGeo = cmds.duplicate(blockGeo,
                                               n='collisionBlock' +
                                               blockVersion + '_geo')[0]
            cmds.delete(collisionBlockGeo + '.f[0]',
                        collisionBlockGeo + '.f[2:5]')

            cmds.makeIdentity(collisionBlockGeo,
                              apply=True,
                              t=True,
                              r=True,
                              s=True,
                              n=0)
            cmds.makeIdentity(collisionBlockGeo)

            cmds.delete(collisionBlockGeo, ch=True)
            ''' -Collision Dynamics- '''
            collisionDyn = cmds.rigidBody(collisionBlockGeo,
                                          n='collisionBlock' + blockVersion +
                                          '_dyn',
                                          active=False)
            cmds.hide(collisionBlockGeo)

            cmds.pointConstraint(blockLoc, collisionBlockGeo)
        ''' -Zero Out Block Values- '''
        cmds.makeIdentity(blockGeo, apply=True, t=True, r=True, s=True, n=0)
        cmds.makeIdentity(blockGeo)

        cmds.delete(blockGeo, ch=True)
        ''' -Create and Place Joints- '''
        cmds.select(cl=True)
        blockBaseJnt = cmds.joint(n='blockBase' + blockVersion + '_jnt')
        blockBottom = cmds.xform(blockGeo + '.f[0]', ws=True, q=True, t=True)
        cmds.setAttr(blockBaseJnt + '.translateY', blockBottom[1])

        blockEndJnt = cmds.joint(n='blockEnd' + blockVersion + '_jnt')
        cmds.setAttr(blockEndJnt + '.translateY', -blockBottom[1])

        cmds.setAttr(blockBaseJnt + '.radius', blockScaling * 0.1)
        cmds.setAttr(blockEndJnt + '.radius', blockScaling * 0.1)

        cmds.parentConstraint(blockLoc, blockEndJnt)
        cmds.parent(blockBaseJnt, blockRigGrp)
        ''' -Skin Block to Joints- '''
        blockSkin = cmds.skinCluster(blockGeo,
                                     blockBaseJnt,
                                     blockEndJnt,
                                     n='block' + blockVersion + '_skin')[0]

        cmds.skinPercent(blockSkin,
                         blockGeo + '.vtx[0:1]',
                         blockGeo + '.vtx[6:7]',
                         transformValue=[(blockBaseJnt, 1), (blockEndJnt, 0)])

        cmds.skinPercent(blockSkin,
                         blockGeo + '.vtx[2:5]',
                         blockGeo + '.vtx[8:11]',
                         transformValue=[(blockBaseJnt, 0), (blockEndJnt, 1)])
        ''' -Bevel the Block- '''
        if blockBevel >= 1:
            cmds.polyBevel(blockGeo + '.e[0:19]',
                           offset=0.08,
                           offsetAsFraction=1,
                           autoFit=1,
                           segments=blockBevel,
                           worldSpace=1,
                           uvAssignment=0,
                           fillNgons=1,
                           mergeVertices=1,
                           mergeVertexTolerance=0.0001,
                           smoothingAngle=30,
                           miteringAngle=180,
                           angleTolerance=180,
                           ch=1)

            cmds.bakePartialHistory(blockGeo, prePostDeformers=True)
        ''' -Radius Scale- '''
        try:
            blockScaleCurve1 = blockScaleCurve1

            blockEndConstraint = cmds.parentConstraint(blockEndLoc,
                                                       name=True,
                                                       q=True)
            blockEndAlias = con = cmds.parentConstraint(blockEndLoc,
                                                        weightAliasList=True,
                                                        q=True)

            blockEndConstraint1 = blockEndConstraint + '.' + blockEndAlias[0]
            blockEndConstraint2 = blockEndConstraint + '.' + blockEndAlias[1]

            cmds.connectAttr(blockScaleCurve1 + '.output', blockEndConstraint1)
            cmds.connectAttr(blockScaleCurve2 + '.output', blockEndConstraint2)

        except:
            blockEndConstraint = cmds.parentConstraint(blockEndLoc,
                                                       name=True,
                                                       q=True)
            blockEndAlias = con = cmds.parentConstraint(blockEndLoc,
                                                        weightAliasList=True,
                                                        q=True)

            blockEndConstraint1 = blockEndConstraint + '.' + blockEndAlias[0]
            blockEndConstraint2 = blockEndConstraint + '.' + blockEndAlias[1]

            cmds.setDrivenKeyframe(blockEndConstraint1,
                                   cd=radiusScaleAttr,
                                   dv=0,
                                   v=1)
            cmds.setDrivenKeyframe(blockEndConstraint1,
                                   cd=radiusScaleAttr,
                                   dv=1,
                                   v=0)

            cmds.setDrivenKeyframe(blockEndConstraint2,
                                   cd=radiusScaleAttr,
                                   dv=0,
                                   v=0)
            cmds.setDrivenKeyframe(blockEndConstraint2,
                                   cd=radiusScaleAttr,
                                   dv=1,
                                   v=1)

            blockScaleCurve1 = cmds.listConnections(blockEndConstraint1,
                                                    source=True,
                                                    type="animCurve")[0]
            blockScaleCurve2 = cmds.listConnections(blockEndConstraint2,
                                                    source=True,
                                                    type="animCurve")[0]
        ''' -Find Distance- '''
        blockDistance = cmds.shadingNode('distanceBetween',
                                         asUtility=True,
                                         name='block' + blockVersion +
                                         '_distance')

        blockBaseLocShape = cmds.listRelatives(blockBaseLoc, shapes=True)[0]
        blockEndLocShape = cmds.listRelatives(blockEndLoc, shapes=True)[0]

        cmds.connectAttr(blockBaseLocShape + '.worldPosition [0]',
                         blockDistance + '.point1')
        cmds.connectAttr(blockEndLocShape + '.worldPosition [0]',
                         blockDistance + '.point2')
        ''' -Translate Box Anim- '''
        cmds.setDrivenKeyframe(blockLoc + '.translateY',
                               cd=blockDistance + '.distance',
                               dv=blockScaling * 10,
                               v=blockScaling * 0)
        cmds.setDrivenKeyframe(blockLoc + '.translateY',
                               cd=blockDistance + '.distance',
                               dv=blockScaling * 9.8,
                               v=-blockScaling * 0.2)

        cmds.setDrivenKeyframe(blockLoc + '.translateY',
                               cd=blockDistance + '.distance',
                               dv=blockScaling * 5.2,
                               v=blockScaling * 5.2)
        cmds.setDrivenKeyframe(blockLoc + '.translateY',
                               cd=blockDistance + '.distance',
                               dv=blockScaling * 5,
                               v=blockScaling * 5)

        cmds.setDrivenKeyframe(blockLoc + '.translateY',
                               cd=blockDistance + '.distance',
                               dv=blockScaling * 0.2,
                               v=-blockScaling * 0.2)
        cmds.setDrivenKeyframe(blockLoc + '.translateY',
                               cd=blockDistance + '.distance',
                               dv=blockScaling * 0,
                               v=blockScaling * 0)
        ''' -Block Layout- '''
        blockScaling2 = blockScaling + blockSpacing

        if block == 0:
            traX = ((horizontalCount - 1) * -0.5 * blockScaling2)
            traZ = ((verticalCount - 1) * -0.5 * blockScaling2)

            cmds.setAttr(blockRigGrp + '.translate', traX, 0, traZ)
            horizontalCountDown1 = horizontalCount - 1
            horizontalCountDown2 = horizontalCount
            verticalCountDown = 0

        else:
            if horizontalCountDown1 == 0:
                horizontalCountDown1 = horizontalCount
                horizontalCountDown2 = horizontalCount
                verticalCountDown = verticalCountDown - 1

            horizontalCountDown1 = horizontalCountDown1 - 1
            horizontalCountDown2 = horizontalCountDown2 - 1

            traX = (((horizontalCount - 1) * -0.5 + horizontalCountDown2) *
                    blockScaling2)
            traZ = (((verticalCount - 1) * -0.5 - verticalCountDown) *
                    blockScaling2)

            cmds.setAttr(blockRigGrp + '.translate', traX, 0, traZ)

        cmds.parentConstraint(blockController, blockTopLoc, mo=True)

        cmds.hide(blockRigGrp)
        cmds.progressBar(progressName, e=True, step=1)
    ''' -Close Progress Bar- '''
    progressBar('', 0)
示例#14
0
              h=0.10,
              d=100,
              sx=10,
              sy=1,
              sz=10,
              ax=(0, 1, 0),
              name='floor')
cmds.setAttr('floor.translateY', -15)
''' Initiate rigidSolvers 
mySphere should interact with shards created from myPlane
Shards created below by way of cutObject should interact
'''
cmds.rigidSolver(create=True, name='rigidSolver1')
cmds.select('floor')
cmds.rigidBody(passive=True,
               solver='rigidSolver1',
               name='passiveRigidBodyFloor')
cmds.gravity(pos=(0, 0, 0), m=9.8, dx=0, dy=-1, dz=0, name='gravityField')

fracturePosition = cmds.objectCenter(myPlane, gl=True)
print("Fracture position")
print(fracturePosition)

centerPoints = generateVoronoiPoints(fracturePosition)
shatteredPlane = cutObject(myPlane, centerPoints)

shards = cmds.listRelatives(shatteredPlane, children=True)

for i in range(len(shards)):
    cmds.select(shards[i])
    cmds.rigidBody(active=True, solver='rigidSolver1', name='shard' + str(i))
示例#15
0
def readK2P():
    mc.constructionHistory(toggle=False)
    mc.select(all=True)
    mc.delete()

    counterMin = 1;
    counter=counterMin;
    counterMax = 200;
    mc.playbackOptions(minTime=counterMin, maxTime=counterMax)

    skipCounterMin = 1;
    skipCounter=skipCounterMin;
    skipCounterMax = 6;


    path = "/Users/nick/Development/Maya/readxml"
    fileName = "mocapData1.xml"
    #trackPoint = ["l_foot","l_knee","l_hip","r_foot","r_knee","r_hip","l_hand","l_elbow","l_shoulder","r_hand","r_elbow","r_shoulder","torso","neck","head"]
    trackPoint = ["head"]
    scaler = 10
    grav = mc.gravity()

    xmlFile = xd.parse(path + "/" + fileName)
    print("loaded: " + fileName)

    for t in trackPoint:    
        joint = xmlFile.getElementsByTagName(t)
        jointCounter = 0;
        cubeName = t
        #mergeName = t + "Merge"

        for j in joint:
            counter=counterMin;
            x = scaler * float(j.getAttribute("x"))
            y = scaler * float(j.getAttribute("y"))
            z = scaler * float(j.getAttribute("z"))
            
            if(x!=0 and y!=0 and z!=0):
                mc.currentTime(counter)
                counter+=1
                if(skipCounter<skipCounterMax):
                    jointCounter+=1
                    mc.polyCube(name=cubeName+str(counter))
                    #polyCube(sx=2, sy=2, sz=2, name=cubeName+str(counter))
                    #polySmooth(dv=1)
                    mc.connectDynamic(f=grav) #adds gravity
                    mc.move(x, y, z)
                    mc.rotate(rnd.uniform(-1 * scaler, scaler),rnd.uniform(-1 * scaler, scaler),rnd.uniform(-1 * scaler, scaler))
                    skipCounter+=1
                else:
                    skipCounter=skipCounterMin

        print("cubes made: " + str(jointCounter))
        
        #select(all=True)
        #polyUnite(constructionHistory=False) #1=union, 2=difference, 3=intersection

    floor = mc.polyPlane(w=30,h=30)
    mc.rigidBody(passive=True)
    mc.move(0,0,0)

    print("...script complete.")