Example #1
0
def asymStretch(stringName):
    #Keyframe Hydrogen on assembly 2
    cmds.setKeyframe(stringName+"|realignGroup2|hydroAssembly2|hydrogen", at="translateX", t=0, v=HYDRO_OSC_START_POS)
    cmds.setKeyframe(stringName+"|realignGroup2|hydroAssembly2|hydrogen", at="translateX", t=OSC_RATE, v=HYDRO_OSC_END_POS)
    cmds.selectKey(stringName+"|realignGroup2|hydroAssembly2|hydrogen", at="translateX")#, t=['0sec', OSC_RATE+'sec'])
    cmds.setInfinity(stringName+"|realignGroup2|hydroAssembly2|hydrogen", at="translateX", pri='oscillate', poi='oscillate')
    cmds.keyTangent(stringName+"|realignGroup2|hydroAssembly2|hydrogen", itt='plateau')#, time=(0, OSC_RATE))
    
    #Keyframe the cylinder movement on assembly 2
    cmds.setKeyframe(stringName+"|realignGroup2|hydroAssembly2", at="translateX", t=0, v=0)
    cmds.setKeyframe(stringName+"|realignGroup2|hydroAssembly2", at="translateX", t=OSC_RATE_ASSEMBLY, v=-1)
    cmds.selectKey(stringName+"|realignGroup2|hydroAssembly2", at="translateX")#, t=['0sec', OSC_RATE_ASSEMBLY+'sec'])
    cmds.setInfinity(stringName+"|realignGroup2|hydroAssembly2", at="translateX", pri='oscillate', poi='oscillate')
    cmds.keyTangent(stringName+"|realignGroup2|hydroAssembly2", itt='plateau')#, time=(0, OSC_RATE_ASSEMBLY))
    
    #Keyframe the hydrogen on assembly 1
    cmds.setKeyframe(stringName+"|realignGroup1|hydroAssembly1|hydrogen", at="translateX", t=0, v=HYDRO_OSC_END_POS)
    cmds.setKeyframe(stringName+"|realignGroup1|hydroAssembly1|hydrogen", at="translateX", t=OSC_RATE, v=HYDRO_OSC_START_POS)
    cmds.selectKey(stringName+"|realignGroup1|hydroAssembly1|hydrogen", at="translateX")#, t=['0sec', OSC_RATE+'sec'])
    cmds.setInfinity(stringName+"|realignGroup1|hydroAssembly1|hydrogen", at="translateX", pri='oscillate', poi='oscillate')
    cmds.keyTangent(stringName+"|realignGroup1|hydroAssembly1|hydrogen", itt='plateau')#, time=(0, OSC_RATE))
    
    #Keyframe the cylinder movement on assembly 2
    cmds.setKeyframe(stringName+"|realignGroup1|hydroAssembly1", at="translateX", t=0, v=-1)
    cmds.setKeyframe(stringName+"|realignGroup1|hydroAssembly1", at="translateX", t=OSC_RATE_ASSEMBLY, v=0)
    cmds.selectKey(stringName+"|realignGroup1|hydroAssembly1", at="translateX")#, t=['0sec', OSC_RATE_ASSEMBLY+'sec'])
    cmds.setInfinity(stringName+"|realignGroup1|hydroAssembly1", at="translateX", pri='oscillate', poi='oscillate')
    cmds.keyTangent(stringName+"|realignGroup1|hydroAssembly1", itt='plateau')#, time=(0, OSC_RATE_ASSEMBLY))
Example #2
0
def bend(stringName):
    keyt = (0, OSC_RATE_ASSEMBLY)
    curRotation = cmds.getAttr(stringName+"|realignGroup1|hydroAssembly1.rotateZ")
    cmds.setKeyframe(stringName+"|realignGroup1|hydroAssembly1", at="rotateZ", t=0, v=-curRotation)
    cmds.setKeyframe(stringName+"|realignGroup1|hydroAssembly1", at="rotateZ", t=OSC_RATE_ASSEMBLY, v=BEND_SWING)
    cmds.selectKey(stringName+"|realignGroup1|hydroAssembly1", at="rotateZ")
    cmds.setInfinity(stringName+"|realignGroup1|hydroAssembly1", at="rotateZ", pri='oscillate', poi='oscillate')
    cmds.keyTangent(stringName+"|realignGroup1|hydroAssembly1", itt='plateau') #time=(0, OSC_RATE_ASSEMBLY))
    
    curRotation = cmds.getAttr(stringName+"|realignGroup2|hydroAssembly2.rotateZ")
    cmds.setKeyframe(stringName+"|realignGroup2|hydroAssembly2", at="rotateZ", t=0, v=-curRotation)
    cmds.setKeyframe(stringName+"|realignGroup2|hydroAssembly2", at="rotateZ", t=OSC_RATE_ASSEMBLY, v=-BEND_SWING)
    cmds.selectKey(stringName+"|realignGroup2|hydroAssembly2", at="rotateZ")
    cmds.setInfinity(stringName+"|realignGroup2|hydroAssembly2", at="rotateZ", pri='oscillate', poi='oscillate')
    cmds.keyTangent(stringName+"|realignGroup2|hydroAssembly2", itt='plateau') #time=(0, OSC_RATE_ASSEMBLY))
    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')