def _handleCreateBall(self):
     cmds.polySphere(name='ball', r=2, sx=20, sy=20, ax=[0, 1, 0])
     cmds.polyColorPerVertex(rgb=(1, 1, 1), cdo=True)
     cmds.select('ball.f[380:399]', 'ball.f[320:339]', 'ball.f[280:299]', 'ball.f[240:259]', 'ball.f[200:219]', 'ball.f[160:179]', 'ball.f[120:139]', 'ball.f[80:99]', 'ball.f[40:59]', 'ball.f[0:19]')
     cmds.polyColorPerVertex(rgb=(1, 0, 0), cdo=True)
     cmds.select('ball')
     cmds.nonLinear( type='squash')
    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')
Beispiel #3
0
    def _handleExample2Button(self):
        """
        This callback creates a polygonal cylinder in the Maya scene.


        r = 50
        a = 2.0*r
        y = (0, 1, 0)
        c = cmds.polyCylinder(
            r=r, h=5, sx=40, sy=1, sz=1, ax=y, rcp=0, cuv=2, ch=1, n='exampleCylinder')[0]
        cmds.select(c)
        response = nimble.createRemoteResponse(globals())
        response.put('name', c)
        """

        # creat the transparent container
        cmds.polyCylinder(name='container', r=1.6, axis=(0, 1, 0), height=3.2)
        cmds.select('container')
        cmds.polyColorPerVertex(r=0.4,
                                g=1,
                                b=1,
                                a=0.05,
                                colorDisplayOption=True)
        cmds.move(0.0, 1.6, 0, relative=True)

        # create a bubble
        cmds.polySphere(name='bubble', radius=0.01)
        pos_x = 0
        pos_y = 0
        pos_z = 0
        total_bubbles = 50
        for nth_num in xrange(0, total_bubbles):
            bubble = 'bubble' + str(nth_num)
            cmds.duplicate('bubble', n=bubble)
            cmds.select(bubble)
            cmds.polyColorPerVertex(r=1,
                                    g=1,
                                    b=0.75,
                                    a=1,
                                    colorDisplayOption=True)
            x_vib = random.uniform(-1.0, 1.0)
            z_vib = random.uniform(-1.0, 1.0)
            cmds.move(x_vib, 0.0, z_vib, bubble)
            start_frame = int(random.uniform(0, 124 - 30))
            print start_frame
            xRot = random.uniform(0, 360)
            yRot = random.uniform(0, 360)
            zRot = random.uniform(0, 360)
            for frame in xrange(0, 124):
                if (
                        frame - start_frame >= 0 and frame - start_frame < 30
                ):  # the first 40 frames, the bubble remains at the bottom while growing bigger
                    cmds.setKeyframe(bubble,
                                     attribute='scaleX',
                                     value=0.5 *
                                     ((frame - start_frame) / 30.0),
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='scaleY',
                                     value=0.3 *
                                     ((frame - start_frame) / 30.0),
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='scaleZ',
                                     value=0.5 *
                                     ((frame - start_frame) / 30.0),
                                     t=frame)
                elif (frame - start_frame >= 30):
                    pos_y = 3.0 * (
                        (frame - start_frame - 30) / 84.0
                    )  # from frame 40, the bubble getting bigger and ascend to the top
                    pos_x = x_vib + random.uniform(-0.03, 0.03)
                    pos_z = z_vib + random.uniform(-0.03, 0.03)
                    xRot = xRot + 0.3
                    yRot = yRot + 0.03
                    zRot = zRot + 0.3
                    factor = 1.1 * math.tan(3.14 / 4 * frame / 124.0)
                    #cmds.blendShape(edit=True,en=0.8)
                    cmds.setKeyframe(bubble,
                                     attribute='translateX',
                                     value=pos_x,
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='translateY',
                                     value=pos_y,
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='translateZ',
                                     value=pos_z,
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='scaleX',
                                     value=0.5 + 3.0 * factor *
                                     ((frame - start_frame) / 84.0),
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='scaleY',
                                     value=0.3 + 1.8 * factor *
                                     ((frame - start_frame) / 84.0),
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='scaleZ',
                                     value=0.5 + 2.4 * factor *
                                     ((frame - start_frame) / 84.0),
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='rotateX',
                                     value=xRot,
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='rotateY',
                                     value=yRot,
                                     t=frame)
                    cmds.setKeyframe(bubble,
                                     attribute='rotateZ',
                                     value=zRot,
                                     t=frame)
        cmds.delete('bubble')
Beispiel #4
0
    def _handleExample1Button(self):
        """
        This callback creates a polygonal cylinder in the Maya scene.


        r = 50
        a = 2.0*r
        y = (0, 1, 0)
        c = cmds.polyCylinder(
            r=r, h=5, sx=40, sy=1, sz=1, ax=y, rcp=0, cuv=2, ch=1, n='exampleCylinder')[0]
        cmds.select(c)
        response = nimble.createRemoteResponse(globals())
        response.put('name', c)
        """
        cmds.polySphere(name='bubble', radius=0.01)
        cmds.polyCylinder(name='container', r=1.6, axis=(0, 1, 0), height=3.2)
        cmds.select('container')
        cmds.polyColorPerVertex(r=0.4,
                                g=1,
                                b=1,
                                a=0.05,
                                colorDisplayOption=True)
        cmds.move(0.0, 1.6, 0, relative=True)
        pos_x = 0
        pos_y = 0
        pos_z = 0
        for frame in xrange(0, 124):
            if frame < 40:  # the first 40 frames, the bubble remains at the bottom while growing bigger
                cmds.setKeyframe('bubble',
                                 attribute='scaleX',
                                 value=0.5 * (frame / 40.0),
                                 t=frame)
                cmds.setKeyframe('bubble',
                                 attribute='scaleY',
                                 value=0.5 * (frame / 40.0),
                                 t=frame)
                cmds.setKeyframe('bubble',
                                 attribute='scaleZ',
                                 value=0.5 * (frame / 40.0),
                                 t=frame)
            else:
                pos_y = 3.0 * (
                    (frame - 40) / 84.0
                )  # from frame 40, the bubble getting bigger and ascend to the top
                cmds.setKeyframe('bubble',
                                 attribute='translateY',
                                 value=pos_y,
                                 t=frame)
                cmds.setKeyframe('bubble',
                                 attribute='translateX',
                                 value=pos_x,
                                 t=frame)
                cmds.setKeyframe('bubble',
                                 attribute='scaleX',
                                 value=0.5 + 2.5 * (frame / 84.0),
                                 t=frame)
                cmds.setKeyframe('bubble',
                                 attribute='scaleY',
                                 value=0.5 + 2.3 * (frame / 84.0),
                                 t=frame)
                cmds.setKeyframe('bubble',
                                 attribute='scaleZ',
                                 value=0.5 + 2.5 * (frame / 84.0),
                                 t=frame)