예제 #1
0
        public override void doIt(MArgList args)
        {
            // parse the command arguments
            //
            parseArgs(args);

            uint count = 0;
            // if the character flag was used, create the clip on the specified
            // character, otherwise, create a character
            //
            MFnCharacter fnCharacter = new MFnCharacter();

            if (fCharacter.isNull)
            {
                MSelectionList activeList = new MSelectionList();
                MGlobal.getActiveSelectionList(activeList);
                if (0 == activeList.length)
                {
                    throw new ApplicationException("Empty Active Selection List.");
                }

                // create a character using the selection list
                //
                fCharacter = fnCharacter.create(activeList, MFnSet.Restriction.kNone);
            }
            else
            {
                fnCharacter.setObject(fCharacter);
            }

            // Get the array of members of the character. We will create a clip
            // for them.
            //
            MPlugArray plugs = new MPlugArray();

            fnCharacter.getMemberPlugs(plugs);

            // Now create a animCurves to use as a clip for the character.
            // The curves will be set up between frames 0 and 10;
            //
            MTime        start      = new MTime(0.0);
            MTime        duration   = new MTime(10.0);
            MObjectArray clipCurves = new MObjectArray();

            for (count = 0; count < plugs.length; ++count)
            {
                // Now create a bunch of animCurves to use as a clip for the
                // character
                //
                MFnAnimCurve fnCurve = new MFnAnimCurve();
                MObject      curve   = fnCurve.create(MFnAnimCurve.AnimCurveType.kAnimCurveTL);          // plugType);
                fnCurve.addKeyframe(start, 5.0);
                fnCurve.addKeyframe(duration, 15.0);
                clipCurves.append(curve);
            }

            // Create a source clip node and add the animation to it
            //
            MFnClip fnClipCreate = new MFnClip();
            MObject sourceClip   = fnClipCreate.createSourceClip(start, duration, fMod);

            fnCharacter.attachSourceToCharacter(sourceClip, fMod);
            for (count = 0; count < plugs.length; ++count)
            {
                MPlug animPlug = plugs[(int)count];
                fnCharacter.addCurveToClip(clipCurves[(int)count], sourceClip, animPlug, fMod);
            }


            // instance the clip
            //
            MTime   schedStart    = new MTime(15.0);
            MObject instancedClip = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);

            fnCharacter.attachInstanceToCharacter(instancedClip, fMod);

            // instance the clip a second time, at time 30
            //
            schedStart.value = 30.0;
            MObject instancedClip2 = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);

            fnCharacter.attachInstanceToCharacter(instancedClip2, fMod);

            return;
        }
예제 #2
0
		public override void doIt(MArgList args)
		{
			// parse the command arguments
			//
			parseArgs(args);

			uint count = 0;
			// if the character flag was used, create the clip on the specified
			// character, otherwise, create a character
			//
			MFnCharacter fnCharacter = new MFnCharacter();
			if (fCharacter.isNull)
			{
				MSelectionList activeList = new MSelectionList();
				MGlobal.getActiveSelectionList(activeList);
				if (0 == activeList.length)
				{
					throw new ApplicationException("Empty Active Selection List.");
				}

				// create a character using the selection list
				//
				fCharacter = fnCharacter.create(activeList, MFnSet.Restriction.kNone);
			}
			else
				fnCharacter.setObject(fCharacter);

			// Get the array of members of the character. We will create a clip
			// for them.
			//
			MPlugArray plugs = new MPlugArray();
			fnCharacter.getMemberPlugs(plugs);

			// Now create a animCurves to use as a clip for the character.
			// The curves will be set up between frames 0 and 10;
			//
			MTime start = new MTime(0.0);
			MTime duration = new MTime(10.0);
			MObjectArray clipCurves = new MObjectArray();

			for (count = 0; count < plugs.length; ++count)
			{
				// Now create a bunch of animCurves to use as a clip for the
				// character
				//
				MFnAnimCurve fnCurve = new MFnAnimCurve();
				MObject curve = fnCurve.create(MFnAnimCurve.AnimCurveType.kAnimCurveTL); // plugType);
				fnCurve.addKeyframe(start, 5.0);
				fnCurve.addKeyframe(duration, 15.0);
				clipCurves.append(curve);
			}

			// Create a source clip node and add the animation to it
			//
			MFnClip fnClipCreate = new MFnClip();
			MObject sourceClip = fnClipCreate.createSourceClip(start, duration, fMod);
			fnCharacter.attachSourceToCharacter(sourceClip, fMod);
			for (count = 0; count < plugs.length; ++count)
			{
				MPlug animPlug = plugs[(int)count];
				fnCharacter.addCurveToClip(clipCurves[(int)count], sourceClip, animPlug, fMod);
			}


			// instance the clip
			//
			MTime schedStart = new MTime(15.0);
			MObject instancedClip = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);
			fnCharacter.attachInstanceToCharacter(instancedClip, fMod);

			// instance the clip a second time, at time 30
			//
			schedStart.value = 30.0;
			MObject instancedClip2 = fnClipCreate.createInstancedClip(sourceClip, schedStart, fMod);
			fnCharacter.attachInstanceToCharacter(instancedClip2, fMod);

			return;
		}