예제 #1
0
    def run(self):
        """ This method is where your nimble script should be implemented. Prior to Nimble calling
            this method the class receives the arguments passed through Nimble needed by the
            your method implementation. """

        # Retrieve the arguments passed by Nimble using the fetch method, which includes a default
        # value to assign if the argument was not specified in the Nimble call
        sphereCount = self.fetch('count', 6)
        ringRadius  = self.fetch('radius', 10)
        yOffset     = self.fetch('y', 0)

        # Create the spheres using Maya commands imported through Nimble, which allows this script
        # to be run flexibly both inside and outside of Maya
        sphereNames = []
        for i in range(sphereCount):
            result = cmds.sphere()
            sphereNames.append(result[0])

            # Position the sphere in the ring
            cmds.move(
                ringRadius*math.cos(2.0*math.pi*i/sphereCount),
                0,
                ringRadius*math.sin(2.0*math.pi*i/sphereCount),
                result[0])

        # Place the spheres within a group node to represent the ring and move the group up the
        # y-axis by the value specified by the script arguments
        ringGroupNode = cmds.group(*sphereNames, name='sphereRing1')
        cmds.move(0, yOffset, 0, ringGroupNode)

        # Set the results of the script with the put command for returning to the Nimble calling
        # environment
        self.put('ringName', ringGroupNode)
        self.put('sphereNames', sphereNames)
예제 #2
0
    def _makeMolecule(self):
        #H2O
        O = cmds.polySphere(r=1, n='O', ax = [0,0,0]);
        H1 = cmds.polySphere(r=0.8, n='H1', ax=[0,0,0]);
        H2 = cmds.polySphere(r=0.8, n='H2', ax=[0,0,0]);
        cmds.move(0.0,0.0,1,H1, r=True)
        cmds.move(0.0,0.0,-1,H2, r=True)
        cmds.xform(H1, piv=[0,0,0], ws=True)
        cmds.xform(H2, piv=[0,0,0], ws=True)
        cmds.rotate(0,'60',0, H1);

        #group O, H1, H2 as a water molecule
        H2O = cmds.group( empty=True, name='H2O' )
        cmds.parent(H1,H2,O,H2O)

        #paint on colors for the water molecule
        #create red lambert
        cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name='O_WhiteSG' )
        cmds.shadingNode( 'lambert', asShader=True, name='O_White' )
        cmds.setAttr( 'O_White.color', 1, 1, 1, type='double3')
        cmds.connectAttr('O_White.outColor', 'O_WhiteSG.surfaceShader')
        #create red lambert
        cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name='H_RedSG' )
        cmds.shadingNode( 'lambert', asShader=True, name='H_Red' )
        cmds.setAttr( 'H_Red.color', 1, 0, 0, type='double3')
        cmds.connectAttr('H_Red.outColor', 'H_RedSG.surfaceShader')

        #assign the material
        cmds.sets('H1', edit=True, forceElement='H_RedSG')
        cmds.sets('H2', edit=True, forceElement='H_RedSG')
        cmds.sets('O', edit=True, forceElement='O_WhiteSG')
        return H2O
예제 #3
0
    def run(self):
        """ This method is where your nimble script should be implemented. Prior to Nimble calling
            this method the class receives the arguments passed through Nimble needed by the
            your method implementation. """

        # Retrieve the arguments passed by Nimble using the fetch method, which includes a default
        # value to assign if the argument was not specified in the Nimble call
        sphereCount = self.fetch('count', 6)
        ringRadius  = self.fetch('radius', 10)
        yOffset     = self.fetch('y', 0)

        # Create the spheres using Maya commands imported through Nimble, which allows this script
        # to be run flexibly both inside and outside of Maya
        sphereNames = []
        for i in range(sphereCount):
            result = cmds.sphere()
            sphereNames.append(result[0])

            # Position the sphere in the ring
            cmds.move(
                ringRadius*math.cos(2.0*math.pi*i/sphereCount),
                0,
                ringRadius*math.sin(2.0*math.pi*i/sphereCount),
                result[0])

        # Place the spheres within a group node to represent the ring and move the group up the
        # y-axis by the value specified by the script arguments
        ringGroupNode = cmds.group(*sphereNames, name='sphereRing1')
        cmds.move(0, yOffset, 0, ringGroupNode)

        # Set the results of the script with the put command for returning to the Nimble calling
        # environment
        self.put('ringName', ringGroupNode)
        self.put('sphereNames', sphereNames)
예제 #4
0
 def _handleRoadButton(self):
     exist = cmds.ls('road')
     if(len(exist) != 0):
         cmds.delete('road')
     road=cmds.group(empty=True, name='road')
     transformName = cmds.ls('brick', typ='transform')[0]
     num = int(self.bricksNum.text())
     for i in range(0, num):
         instanceResult = cmds.instance(transformName, name=transformName + '_instance#')
         #print 'instanceResult: ' + str(instanceResult)
         x = random.uniform(-3, 34)
         z = random.uniform(-3,3)
         cmds.move(x, 0, z, instanceResult)
         yRot = random.uniform(0,360)
         cmds.rotate(0, yRot, 0, instanceResult)
         cmds.parent(instanceResult, road)
예제 #5
0
 def _handleDuplicatedButton(self):
     random.seed(1234)
     exist = cmds.ls('dust')
     if(len(exist) != 0):
         cmds.delete('dust')
     dust=cmds.group(empty=True, name='dust')
     transformName = cmds.ls('pie', typ='transform')[0]
     num = int(self.dustNum.text())
     for i in range(0, num):
         instanceResult = cmds.instance(transformName, name=transformName + '_instance#')
         #print 'instanceResult: ' + str(instanceResult)
         x = random.uniform(-3, 34)
         y = random.uniform(0,4)
         z = random.uniform(-3,3)
         cmds.move(x, y, z, instanceResult)
         xRot = random.uniform(0,360)
         yRot = random.uniform(0,360)
         zRot = random.uniform(0,360)
         cmds.rotate(xRot, yRot, zRot, instanceResult)
         cmds.parent(instanceResult, dust)
예제 #6
0
    def _handleExampleButton(self):
        """
        This callback creates a polygonal cylinder in the Maya scene.

        """

        random.seed(1234)

        #check
        sphereList = cmds.ls('hydrogen1', 'hydrogen2', 'oxygen', 'H2O')

        if len(sphereList) > 0:
            cmds.delete(sphereList)

        #create 2 hydrogen and oxygen
        h1 = cmds.polySphere(r=12.0, name='hydrogen1')
        h2 = cmds.polySphere(r=12.0, name='hydrogen2')
        oxygen = cmds.polySphere(r=15.0, name='oxygen')

        #move
        cmds.move(-15, 0, 0, h1)
        cmds.move(15, 0, 0, h2)
        cmds.xform(h1, piv=[0, 0, 0], ws=True)
        cmds.xform(h2, piv=[0, 0, 0], ws=True)
        cmds.rotate(0, '75', 0, h1)

        #group hydrogen and oxygen together
        H2O = cmds.group(empty=True, name='H2O#')
        cmds.parent('hydrogen1', 'hydrogen2', 'oxygen', 'H2O1')

        #add color
        def createMaterial(name, color, type):
            cmds.sets(renderable=True,
                      noSurfaceShader=True,
                      empty=True,
                      name=name + 'SG')
            cmds.shadingNode(type, asShader=True, name=name)
            cmds.setAttr(name + '.color',
                         color[0],
                         color[1],
                         color[2],
                         type='double3')
            cmds.connectAttr(name + '.outColor', name + 'SG.surfaceShader')

        def assignMaterial(name, object):
            cmds.sets(object, edit=True, forceElement=name + 'SG')

        def assignNewMaterial(name, color, type, object):
            createMaterial(name, color, type)
            assignMaterial(name, object)

        #H is white and O is red
        assignNewMaterial('Red', (1, 0, 0), 'lambert', 'oxygen')
        assignNewMaterial('White', (1, 1, 1), 'lambert', 'hydrogen1')
        assignMaterial('White', 'hydrogen2')

        #key frame
        def keyFullRotation(pObjectName, pStartTime, pEndTime,
                            pTargetAttribute, pValueStart, pvalueEnd):
            keyt = (pStartTime[0], pStartTime[0])
            cmds.cutKey(pObjectName,
                        time=(keyt, keyt),
                        attribute=pTargetAttribute)
            cmds.setKeyframe(pObjectName,
                             time=pStartTime,
                             attribute=pTargetAttribute,
                             value=pValueStart)
            cmds.setKeyframe(pObjectName,
                             time=pEndTime,
                             attribute=pTargetAttribute,
                             value=pvalueEnd)
            #cmds.selectKey( pObjectName, time=(pStartTime, [pEndTime]), attribute=pTargetAttribute, keyframe=True )

        #duplicate H2O
        for i in range(1, 52):
            cmds.duplicate(H2O)
            #get random coord
            x = random.uniform(-200, 200)
            y = random.uniform(0, 300)
            z = random.uniform(-200, 200)

            cmds.move(x, y, z, H2O)

            xRot = random.uniform(0, 360)
            yRot = random.uniform(0, 360)
            zRot = random.uniform(0, 360)

            cmds.rotate(xRot, yRot, zRot, H2O)

            startTime = cmds.playbackOptions(minTime=1)
            endTime = cmds.playbackOptions(maxTime=30)

            h2o = "H2O" + str(i)

            for y in range(3):
                coordsX = cmds.getAttr(h2o + '.translateX')
                coordsY = cmds.getAttr(h2o + '.translateY')
                coordsZ = cmds.getAttr(h2o + '.translateZ')

                ranStartX = int(random.uniform(0, 15))
                ranStartY = int(random.uniform(0, 15))
                ranStartZ = int(random.uniform(0, 15))

                ranEndX = int(random.uniform(15, 30))
                ranEndY = int(random.uniform(15, 30))
                ranEndZ = int(random.uniform(15, 30))

                x = random.uniform(coordsX - 50, coordsX + 50)
                y = random.uniform(coordsY, coordsY + 50)
                z = random.uniform(coordsZ - 50, coordsZ + 50)
                #print x,y,z

                keyFullRotation(h2o, ranStartZ, 15, 'translateZ', coordsZ, z)
                keyFullRotation(h2o, ranStartX, 15, 'translateX', coordsX, x)
                keyFullRotation(h2o, ranStartY, 15, 'translateY', coordsY, y)

                keyFullRotation(h2o, 15, ranEndZ, 'translateZ', z, coordsZ)
                keyFullRotation(h2o, 15, ranEndX, 'translateX', x, coordsX)
                keyFullRotation(h2o, 15, ranEndY, 'translateY', y, coordsY)

                RcoordsX = cmds.getAttr(h2o + '.rotateX')
                RcoordsY = cmds.getAttr(h2o + '.rotateY')
                RcoordsZ = cmds.getAttr(h2o + '.rotateZ')

                xRot = random.uniform(0, 360)
                yRot = random.uniform(0, 360)
                zRot = random.uniform(0, 360)

                keyFullRotation(h2o, ranStartZ, 15, 'rotateZ', RcoordsZ, zRot)
                keyFullRotation(h2o, ranStartX, 15, 'rotateX', RcoordsX, xRot)
                keyFullRotation(h2o, ranStartY, 15, 'rotateY', RcoordsY, zRot)

                keyFullRotation(h2o, 15, ranEndZ, 'rotateZ', zRot, RcoordsZ)
                keyFullRotation(h2o, 15, ranEndX, 'rotateX', xRot, RcoordsX)
                keyFullRotation(h2o, 15, ranEndY, 'rotateY', zRot, RcoordsY)

        print 'done'
        cmds.delete('H2O52')
예제 #7
0
    def _handleExampleButton(self):
        """
        This callback creates a polygonal cylinder in the Maya scene.

        """

        random.seed(1234)

        #check
        sphereList = cmds.ls('hydrogen1','hydrogen2', 'oxygen','H2O')

        if len(sphereList)>0:
            cmds.delete(sphereList)

        #create 2 hydrogen and oxygen
        h1 = cmds.polySphere(r=12.0, name='hydrogen1')
        h2 = cmds.polySphere(r=12.0, name='hydrogen2')
        oxygen = cmds.polySphere(r=15.0, name='oxygen')


        #move
        cmds.move(-15,0,0,h1)
        cmds.move(15,0,0,h2)
        cmds.xform(h1, piv=[0,0,0],ws=True)
        cmds.xform(h2, piv=[0,0,0],ws=True)
        cmds.rotate(0,'75',0,h1)

        #group hydrogen and oxygen together
        H2O = cmds.group(empty=True, name='H2O#')
        cmds.parent('hydrogen1','hydrogen2','oxygen','H2O1')

        #add color
        def createMaterial( name, color, type ):
            cmds.sets( renderable=True, noSurfaceShader=True, empty=True, name=name + 'SG' )
            cmds.shadingNode( type, asShader=True, name=name )
            cmds.setAttr( name+'.color', color[0], color[1], color[2], type='double3')
            cmds.connectAttr(name+'.outColor', name+'SG.surfaceShader')

        def assignMaterial (name, object):
            cmds.sets(object, edit=True, forceElement=name+'SG')

        def assignNewMaterial( name, color, type, object):
            createMaterial (name, color, type)
            assignMaterial (name, object)

        #H is white and O is red
        assignNewMaterial('Red', (1,0,0), 'lambert', 'oxygen');
        assignNewMaterial('White',(1,1,1),'lambert', 'hydrogen1');
        assignMaterial('White', 'hydrogen2');

        #key frame
        def keyFullRotation( pObjectName, pStartTime, pEndTime, pTargetAttribute,pValueStart, pvalueEnd ):
            keyt = (pStartTime[0], pStartTime[0])
            cmds.cutKey( pObjectName, time=(keyt, keyt), attribute=pTargetAttribute )
            cmds.setKeyframe( pObjectName, time=pStartTime, attribute=pTargetAttribute, value=pValueStart )
            cmds.setKeyframe( pObjectName, time=pEndTime, attribute=pTargetAttribute, value=pvalueEnd )
            #cmds.selectKey( pObjectName, time=(pStartTime, [pEndTime]), attribute=pTargetAttribute, keyframe=True )

        #duplicate H2O
        for i in range(1,52):
            cmds.duplicate(H2O)
            #get random coord
            x = random.uniform(-200,200)
            y = random.uniform(0,300)
            z = random.uniform(-200,200)

            cmds.move(x,y,z, H2O)


            xRot = random.uniform(0,360)
            yRot = random.uniform(0,360)
            zRot = random.uniform(0,360)

            cmds.rotate(xRot,yRot,zRot,H2O)

            startTime = cmds.playbackOptions(minTime=1 )
            endTime = cmds.playbackOptions( maxTime=30 )

            h2o = "H2O"+str(i)

            for y in range(3):
                coordsX = cmds.getAttr( h2o+'.translateX' )
                coordsY = cmds.getAttr( h2o+'.translateY' )
                coordsZ = cmds.getAttr( h2o+'.translateZ' )

                ranStartX = int(random.uniform(0,15))
                ranStartY = int(random.uniform(0,15))
                ranStartZ = int(random.uniform(0,15))

                ranEndX = int(random.uniform(15,30))
                ranEndY = int(random.uniform(15,30))
                ranEndZ = int(random.uniform(15,30))

                x = random.uniform(coordsX-50,coordsX+50)
                y = random.uniform(coordsY,coordsY+50)
                z = random.uniform(coordsZ-50,coordsZ+50)
                #print x,y,z

                keyFullRotation( h2o, ranStartZ, 15, 'translateZ',coordsZ,z)
                keyFullRotation( h2o, ranStartX, 15, 'translateX', coordsX,x)
                keyFullRotation( h2o, ranStartY, 15, 'translateY', coordsY,y)

                keyFullRotation( h2o, 15, ranEndZ, 'translateZ',z,coordsZ)
                keyFullRotation( h2o, 15, ranEndX, 'translateX', x,coordsX)
                keyFullRotation( h2o, 15, ranEndY, 'translateY', y,coordsY)

                RcoordsX = cmds.getAttr( h2o+'.rotateX' )
                RcoordsY = cmds.getAttr( h2o+'.rotateY' )
                RcoordsZ = cmds.getAttr( h2o+'.rotateZ' )

                xRot = random.uniform(0,360)
                yRot = random.uniform(0,360)
                zRot = random.uniform(0,360)

                keyFullRotation( h2o, ranStartZ, 15, 'rotateZ',RcoordsZ,zRot)
                keyFullRotation( h2o, ranStartX, 15, 'rotateX', RcoordsX,xRot)
                keyFullRotation( h2o, ranStartY, 15, 'rotateY', RcoordsY,zRot)

                keyFullRotation( h2o, 15, ranEndZ, 'rotateZ',zRot,RcoordsZ)
                keyFullRotation( h2o, 15, ranEndX, 'rotateX', xRot,RcoordsX)
                keyFullRotation( h2o, 15, ranEndY, 'rotateY', zRot,RcoordsY)

        print 'done'
        cmds.delete('H2O52')
예제 #8
0
    def _handleCreateH2o(self):
        """

        """
        #Sets the animation end time
        cmds.playbackOptions(max=240, aet=240)

        #this number sets the number of molecules to create
        molecules = 10

        #Creates each atom in the h2o molecule, aligns them properly, then groups them together .
        cmds.polySphere(name="oxygen", r=1.2)
        cmds.polySphere(name="hydrogenA", r=1.06)
        cmds.select("hydrogenA")
        cmds.move(0, -1.3, 0)
        cmds.group('oxygen', 'hydrogenA', n='oxygenHydrogenA')

        cmds.select('hydrogenA')
        cmds.rotate(0, 0, '-52.5', p=(0, 0, 0))

        cmds.polySphere(name="hydrogenB", r=1.06)
        cmds.select("hydrogenB")
        cmds.move(0, -1.3, 0)
        cmds.group('oxygen', 'hydrogenB', n='oxygenHydrogenB')

        cmds.select('hydrogenB')
        cmds.rotate(0, 0, '52.5', p=(0, 0, 0))

        cmds.select('hydrogenA', 'hydrogenB')
        cmds.polyColorPerVertex(rgb=(1, 1, 1), cdo=True)

        cmds.select('oxygen')
        cmds.polyColorPerVertex(rgb=(1, 0, 0), cdo=True)

        cmds.group('oxygenHydrogenB', 'oxygenHydrogenA', n='h2o')

        #duplicates the original molecule
        for i in range(1, molecules):
            cmds.duplicate('h2o')

        #list of planes for movement
        xyz = ['X', 'Y']

        #Sets movement for the original h2o molecule
        cmds.select("h2o")
        plane = random.choice(xyz)
        cmds.setKeyframe('h2o',
                         at='translate' + plane,
                         v=float(cmds.getAttr('h2o.translate' + plane)),
                         t=1)
        cmds.setKeyframe('h2o', at='translate' + plane, v=5, t=240)

        #Iterates through each h2o group and assigns a random position and orientation for each molecule.
        #It also randomly choose a direction for the molecule to move in.
        for i in range(1, molecules):
            #random plane
            plane = random.choice(xyz)
            cmds.select("h2o" + str(i))
            #random position
            cmds.move(random.randrange(-9, 9), random.randrange(-9, 9),
                      random.randrange(-9, 9))
            #random orientation
            cmds.rotate(random.randrange(0, 350), random.randrange(0, 350),
                        random.randrange(0, 350))
            #sets the start and end position for movement
            cmds.setKeyframe(
                'h2o' + str(i),
                at='translate' + plane,
                v=float(cmds.getAttr('h2o' + str(i) + '.translate' + plane)),
                t=1)
            cmds.setKeyframe('h2o' + str(i),
                             at='translate' + plane,
                             v=5,
                             t=240)
            plane = random.choice(xyz)

        #Selects all the h2o molecules
        cmds.select("h2o", add=True)
        for i in range(1, molecules):
            cmds.select("h2o" + str(i))

        #Creates a new animation layer called vibrate and adds all the h2o molecules to it.
        cmds.animLayer('vibrate', aso=True)

        #Sets oscillation for original molecule
        cmds.setKeyframe('h2o',
                         at='translateZ',
                         v=float(cmds.getAttr('h2o.translateZ')),
                         t=1)
        cmds.setKeyframe('h2o',
                         at='translateZ',
                         v=float(cmds.getAttr('h2o.translateZ')) + .2,
                         t=2)
        #cmds.selectKey('h2o', t=(1,2), at="translateZ")
        cmds.selectKey('h2o', at='translateZ')
        cmds.setInfinity(pri='oscillate', poi='oscillate')

        #Sets oscillation for all other molecules
        for i in range(1, molecules):
            cmds.setKeyframe('h2o' + str(i),
                             at='translateZ',
                             v=float(
                                 cmds.getAttr('h2o' + str(i) + '.translateZ')),
                             t=1)
            cmds.setKeyframe(
                'h2o' + str(i),
                at='translateZ',
                v=float(cmds.getAttr('h2o' + str(i) + '.translateZ')) + .2,
                t=2)
            #cmds.selectKey('h2o'+str(i), t=(1,2), at="translateZ")
            cmds.selectKey('h2o' + str(i), at="translateZ")
            cmds.setInfinity(pri='oscillate', poi='oscillate')
예제 #9
0
def setUpMolecule():
    #Adjust time slider
    cmds.playbackOptions( minTime='1', maxTime='300', mps=1)

    # Create the oxygen part of the larger bond (cylinder)
    cmds.polyCylinder(n='oxyCylinder', r=1, h=2, sx=20, sy=1, sz=1, ax=(1, 0, 0), rcp=0, cuv=3, ch=1)

    #Set scale for oxyCylinder
    cmds.setAttr("oxyCylinder.translateX", 6)
    cmds.setAttr("oxyCylinder.scaleZ", 2)
    cmds.setAttr("oxyCylinder.scaleX", 2)
    cmds.setAttr("oxyCylinder.scaleY", 2)

    #-------Set up shader and shade cylinder----------
    redShader = cmds.shadingNode('blinn', asShader=True, n='redBlinn')
    cmds.setAttr("redBlinn.color", 0.772, 0, 0, type="double3")

    cmds.select('oxyCylinder')

    cmds.hyperShade(assign=redShader)

    #--------------White Cylinder-------------

    # Create the oxygen part of the larger bond (cylinder)
    cmds.polyCylinder(n='hydroCylinder', r=1, h=2, sx=20, sy=1, sz=1, ax=(1, 0, 0), rcp=0, cuv=3, ch=1)

    #Set scale for oxyCylinder
    cmds.setAttr("hydroCylinder.translateX", 10)
    cmds.setAttr("hydroCylinder.scaleZ", 2)
    cmds.setAttr("hydroCylinder.scaleX", 2)
    cmds.setAttr("hydroCylinder.scaleY", 2)

    #-------Set up shader and shade cylinder----------
    whiteShader = cmds.shadingNode('blinn', asShader=True, n='whiteBlinn')
    cmds.setAttr("whiteBlinn.color", 1, 1, 1, type="double3")

    #Select the cylinder to color
    cmds.select('hydroCylinder')
    # Assign shader
    cmds.hyperShade(assign=whiteShader)

    #----------------------------------------------------------
    #-----------Group two cylinders together as "cylinder"-----
    #----------------------------------------------------------
    cmds.group(em=True, n='cylinder')
    cmds.parent('oxyCylinder', 'cylinder')
    cmds.parent('hydroCylinder', 'cylinder')

    #------------Oxygen-------------

    # Create the Oxygen sphere
    cmds.polySphere(n='oxygen', r=1, sx=20, sy=20, ax=(0, 1, 0), cuv=2, ch=1)

    #Set scale for oxygen
    cmds.setAttr("oxygen.scaleZ", 5)
    cmds.setAttr("oxygen.scaleX", 5)
    cmds.setAttr("oxygen.scaleY", 5)

    #-------Assign shader--------
    cmds.select('oxygen')

    cmds.hyperShade(assign=redShader)

    #------------Hydrogen-------------

    # Create the Hydrogen sphere
    cmds.polySphere(n='hydrogen', r=1, sx=20, sy=20, ax=(0, 1, 0), cuv=2, ch=1)

    #Set scale for oxygen
    cmds.setAttr("hydrogen.translateX", 14)
    cmds.setAttr("hydrogen.scaleZ", 4)
    cmds.setAttr("hydrogen.scaleX", 4)
    cmds.setAttr("hydrogen.scaleY", 4)

    #-------Assign shader--------
    cmds.select('hydrogen')

    cmds.hyperShade(assign=whiteShader)

    #----------------------------------------------------------
    #-----------Group 'cylinder' and hydrogen together as "hydroAssembly"-----
    #----------------------------------------------------------
    cmds.group(em=True, n='hydroAssembly1')
    cmds.parent('cylinder', 'hydroAssembly1')
    cmds.parent('hydrogen', 'hydroAssembly1')

    #----------------------------------------------------------
    #-----------Group into realign group
    #----------------------------------------------------------
    cmds.group(em=True, n='realignGroup1')
    cmds.parent('hydroAssembly1', 'realignGroup1')

    #-------------------------------------------------------------
    #------------Duplicate the assembly--------------------------
    #-------------------------------------------------------------
    cmds.duplicate('realignGroup1', n='realignGroup2')
    cmds.setAttr('realignGroup2.rotateZ', 180)
    cmds.rename('realignGroup2|hydroAssembly1','hydroAssembly2')

    #----------------------------------------------------------
    #-----------Make entire thing a group "molecule"-----
    #----------------------------------------------------------
    cmds.group(em=True, n='molecule')
    cmds.parent('oxygen', 'molecule')
    cmds.parent('realignGroup1', 'molecule')
    cmds.parent('realignGroup2', 'molecule')

    #-------Move entire molecule up-------
    cmds.setAttr("molecule.translateY", 10)
예제 #10
0
    def buildScene(self):
        """Doc..."""

        groupItems = []
        hinds      = []
        fores      = []

        for c in self._data.getChannelsByKind(ChannelsEnum.POSITION):
            isHind = c.target in [TargetsEnum.LEFT_HIND, TargetsEnum.RIGHT_HIND]
            radius = 20 if isHind else 15
            res    = cmds.polySphere(radius=radius, name=c.target)
            groupItems.append(res[0])
            if isHind:
                hinds.append(res[0])
            else:
                fores.append(res[0])

            if c.target == TargetsEnum.LEFT_HIND:
                self._leftHind = res[0]
            elif c.target == TargetsEnum.RIGHT_HIND:
                self._rightHind = res[0]
            elif c.target == TargetsEnum.RIGHT_FORE:
                self._rightFore = res[0]
            elif c.target == TargetsEnum.LEFT_FORE:
                self._leftFore = res[0]

            for k in c.keys:
                frames = [
                    ['translateX', k.value.x, k.inTangentMaya[0], k.outTangentMaya[0]],
                    ['translateY', k.value.y, k.inTangentMaya[1], k.outTangentMaya[1]],
                    ['translateZ', k.value.z, k.inTangentMaya[2], k.outTangentMaya[2]]
                ]
                for f in frames:
                    cmds.setKeyframe(
                        res[0],
                        attribute=f[0],
                        time=k.time,
                        value=f[1],
                        inTangentType=f[2],
                        outTangentType=f[3]
                    )

                if k.event == 'land':
                    printResult = cmds.polyCylinder(
                        name=c.target + '_print1',
                        radius=radius,
                        height=(1.0 if isHind else 5.0)
                    )
                    cmds.move(k.value.x, k.value.y, k.value.z, printResult[0])
                    groupItems.append(printResult[0])

        cfg = self._data.configs
        name = 'cyc' + str(int(cfg.get(GaitConfigEnum.CYCLES))) + \
               '_ph' + str(int(cfg.get(GaitConfigEnum.PHASE))) + \
               '_gad' + str(int(cfg.get(SkeletonConfigEnum.FORE_OFFSET).z)) + \
               '_step' + str(int(cfg.get(SkeletonConfigEnum.STRIDE_LENGTH)))

        cube        = cmds.polyCube(name='pelvic_reference', width=20, height=20, depth=20)
        self._hips  = cube[0]
        groupItems.append(cube[0])
        cmds.move(0, 100, 0, cube[0])

        backLength = self._data.configs.get(SkeletonConfigEnum.FORE_OFFSET).z - \
                     self._data.configs.get(SkeletonConfigEnum.HIND_OFFSET).z

        cube2 = cmds.polyCube(name='pectoral_comparator', width=15, height=15, depth=15)
        cmds.move(0, 115, backLength, cube2[0])
        cmds.parent(cube2[0], cube[0], absolute=True)

        cmds.expression(
            string="%s.translateZ = 0.5*abs(%s.translateZ - %s.translateZ) + min(%s.translateZ, %s.translateZ)" %
            (cube[0], hinds[0], hinds[1], hinds[0], hinds[1])
        )

        cube = cmds.polyCube(name='pectoral_reference', width=15, height=15, depth=15)
        self._pecs = cube[0]
        groupItems.append(cube[0])
        cmds.move(0, 100, 0, cube[0])
        cmds.expression(
            string="%s.translateZ = 0.5*abs(%s.translateZ - %s.translateZ) + min(%s.translateZ, %s.translateZ)" %
            (cube[0], fores[0], fores[1], fores[0], fores[1])
        )

        self._group = cmds.group(*groupItems, world=True, name=name)

        cfg = self._data.configs
        info = 'Gait Phase: ' + \
                str(cfg.get(GaitConfigEnum.PHASE)) + \
                '\nGleno-Acetabular Distance (GAD): ' + \
                str(cfg.get(SkeletonConfigEnum.FORE_OFFSET).z) + \
                '\nStep Length: ' + \
                str(cfg.get(SkeletonConfigEnum.STRIDE_LENGTH)) + \
                '\nHind Duty Factor: ' + \
                str(cfg.get(GaitConfigEnum.DUTY_FACTOR_HIND)) + \
                '\nFore Duty Factor: ' + \
                str(cfg.get(GaitConfigEnum.DUTY_FACTOR_FORE)) + \
                '\nCycles: ' + \
                str(cfg.get(GaitConfigEnum.CYCLES))

        cmds.select(self._group)
        if not cmds.attributeQuery('notes', node=self._group, exists=True):
            cmds.addAttr(longName='notes', dataType='string')
            cmds.setAttr(self._group + '.notes', info, type='string')

        self.createShaders()
        self.createRenderEnvironment()

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

        deltaTime = cfg.get(GeneralConfigEnum.STOP_TIME) - cfg.get(GeneralConfigEnum.START_TIME)
        maxTime = max(
            int(float(cfg.get(GaitConfigEnum.CYCLES))*float(deltaTime)),
            int(cmds.playbackOptions(query=True, maxTime=True))
        )

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

        cmds.currentTime(0, update=True)

        cmds.select(self._group)