~ ~ ~ ~ ~ ~ ~ ~
How I Did What I Did
~ ~ ~ ~ ~ ~ ~ ~
Seeing as that all of my previous posts are solely made up of my successes and fails whilst trying to get this to work, I've decided to write an easy-to-follow tutorial that explains all of the steps that I took to get to my end product. Here we go!
Part 1: Step 1: Clothimation
1. Open up Autodesk Maya and switch to the FX toolkit
2. Change the length of the timeline to a large number like 1000.
This will help us when creating the animation.
3. Create a plane and set the subdivision width and height to a high number.
I set mine to 40 and would suggest not setting it to anything under 25.
Keep in mind that lower subdivision values will speed up the process once you get to Part 2.
4. Create a piece of geometry that the nCloth will attach to. It doesn't matter what it is.
5. Move and scale the plane and the solid component to the desired location and size.
6. Select the plane and go to nCloth> Create nCloth.
I chose to make a flag and flagpole. I added textures to make it look good.
7. Select the vertices that are touching the solid component, then shift-select the solid component.
8. Go to nConstraint> Point to surface.
9. Edit the Gravity and Wind component on the nucleus and the Dynamic
Properties of the nCloth to get your desired effect.
The base nCloth animation.
Part 1: Step 2: Gotta cache 'em all
1. Start playing the animation. You will notice that the nCloth falls down initially,
but then gets picked up by the wind, eventually resulting an a stable animation.
This is where we will start the loop. Move the time slider to the start of that stable animation.
Examples of bad and good starting points
2. Select the nCloth and go to Fields/Solvers>Initial State>Set for Selected.
3. Change the length of the timeline to the desired animation length plus 50.
Mine's set to 550. I will explain why we do this later.
4. Move the time slider to frame one and select the nCloth.
5. Go to nCache>Create new Cache>nObject>Option Box.
6. Change the Cache directory to a memorable location.
You can also change the Cache name if you wish.
7. Leave all other settings default and press create. Wait until the cache is done being made.
8. Select the nCloth and find the nClothShape node in the Attribute Editor.
Uncheck the 'Enable' box.
Part 1: Step 3: Hit New Trax
1. The next part will be done in the Trax editor. Open it by going to
Windows>Animation Editors>Trax Editor
2. Select the nCloth and go to nCache>Attach Cache.
Find the cache you previously made and click open.
In the Trax Editor, you should see two nCaches.
3. Click on the top nCache and drag it to the left until there is a 50 in the bottom right corner.
This means that the last 50 frames of the nCache animation is
being played in the first 50 frames of the timeline.
4. Change the timeline length to the initial desired timeline length, cutting out the last 50 frames.
This means that the first frame and the last frame are both the 500th frame
of the cached animation, making it loop. We're not done yet, however. Those extra 50 frames will allow us to transition nicely.
5. Select either the first or the second nCache and you will see the cacheBlend node available in the Attribute Editor. Move the time slider to the first frame.
6. Set the first nCache's input weight to 1 and the second nCache's input weight to 0.
Right click on both of their names and set keys.
7. Move the time slider to 50 and change the first nCache's input weight to 0 and the second nCache's input weight to 1. Once again, set keys by right clicking on both of their names.
3. Click on the top nCache and drag it to the left until there is a 50 in the bottom right corner.
This means that the last 50 frames of the nCache animation is
being played in the first 50 frames of the timeline.
The nCaches are offset correctly. (50 frames)
4. Change the timeline length to the initial desired timeline length, cutting out the last 50 frames.
This means that the first frame and the last frame are both the 500th frame
of the cached animation, making it loop. We're not done yet, however. Those extra 50 frames will allow us to transition nicely.
5. Select either the first or the second nCache and you will see the cacheBlend node available in the Attribute Editor. Move the time slider to the first frame.
6. Set the first nCache's input weight to 1 and the second nCache's input weight to 0.
Right click on both of their names and set keys.
7. Move the time slider to 50 and change the first nCache's input weight to 0 and the second nCache's input weight to 1. Once again, set keys by right clicking on both of their names.
These nCaches are blended seamlessly.
The animation should loop seamlessly! Good job, now let's move into more uncharted territory.
The final looping animation.
Part 2: Step 1: The Bone Script
1. In this part, we'll add joints to every vertex on out mesh. Sounds spooky, right?
It actually works surprisingly well. The first step is to copy the following script:
string $sel[] = `ls -sl`;
float $selPos[3] = `xform -ws -q -t $sel`;
PolySelectConvert 3;
string $verts[] = `ls -sl -fl`;
select -clear;
//string $jParent = `joint -name "jParent" -p $selPos[0] $selPos[1] $selPos[2]`;
for ($v in $verts)
{
float $pos[3] = `xform -ws -q -t $v`;
//select $jParent;
joint -p $pos[0] $pos[1] $pos[2];
}
SelectAllJoints;
group -n BoneGroup; xform -os -piv 0 0 0;
float $rMin = `playbackOptions -q -min`;
float $rMax = `playbackOptions -q -max`;
int $frame;
for ($frame = $rMin; $frame <= $rMax; $frame++)
{
int $vjCounter = 0;
currentTime -e $frame;
for ($v in $verts)
{
// --get it's position..
float $vpos[3] = `xform -q -ws -t $v`;
// --get the name of the appropriate joint incremented by 1.
string $jName = "|BoneGroup|joint" + ++$vjCounter;
// --set the pos of the joint to the pos of the vertex..
move $vpos[0] $vpos[1] $vpos[2] $jName;
// --set keyframe
setKeyframe -at translate -t $frame $jName;
}
}
float $selPos[3] = `xform -ws -q -t $sel`;
PolySelectConvert 3;
string $verts[] = `ls -sl -fl`;
select -clear;
//string $jParent = `joint -name "jParent" -p $selPos[0] $selPos[1] $selPos[2]`;
for ($v in $verts)
{
float $pos[3] = `xform -ws -q -t $v`;
//select $jParent;
joint -p $pos[0] $pos[1] $pos[2];
}
SelectAllJoints;
group -n BoneGroup; xform -os -piv 0 0 0;
float $rMin = `playbackOptions -q -min`;
float $rMax = `playbackOptions -q -max`;
int $frame;
for ($frame = $rMin; $frame <= $rMax; $frame++)
{
int $vjCounter = 0;
currentTime -e $frame;
for ($v in $verts)
{
// --get it's position..
float $vpos[3] = `xform -q -ws -t $v`;
// --get the name of the appropriate joint incremented by 1.
string $jName = "|BoneGroup|joint" + ++$vjCounter;
// --set the pos of the joint to the pos of the vertex..
move $vpos[0] $vpos[1] $vpos[2] $jName;
// --set keyframe
setKeyframe -at translate -t $frame $jName;
}
}
2. This is a MEL script first created in 2003.
(source: http://www.creativecrash.com/forums/mel/topics/transforming-vertex-animation-to-joint-animation)
To use it, open up the script editor by going to Windows>General Editors> Script Editor.
3. Making sure that the language is MEL, paste the script
into the bottom window and hit the blue play arrow.
The script inside of the Script Editor
4. Now this is the scary part. Maya itself will be unresponsive for quite a long time while it calculates placing hundreds of joints that follow every vertex.
Wait it out. Maya hasn't crashed. This particular calculation took me 35 minutes,
and I'm on a pretty speedy computer.
If Maya actually froze, you'll have to manually delete some edge loops to make it easier on Maya
Part 2: Step 2: Love the Skin You're In
1. Once that's done, we'll want to remove all influence the nCloth has on the shape.
Select the cloth, move the time slider to the first frame, and go to Edit>Delete All by Type>History.
2. Next, we'll export it as an obj, which will remove all unnecessary information. Select the cloth and go to File>Export Selection. The file name is up to you, but make sure the file type is obj.
3. Delete the nCloth. You won't need it anymore. Go to File>Import, find the obj you exported,
then click import. You'll want to fix any thing wrong with the textures now if you have any.
4. Open up the rigging toolkit. Select all of the joints, then the imported cloth,
then go to Skin>Bind Skin>Option Box. Set 'Bind to:' to Selected joints and click Bind skin.
If your flag is waving and looking a-ok, then you've successfully rigged a waving flag!
In the next part, we'll import it to Unreal Engine 4.
The final rigged animation
Part 3: Step 1: Fbxport 'em
1. The first step here is to export all of the models you will want in the game engine.
First, click on the solid component that the flag is attached to.
Go to Modify>Freeze Transformations, then Modify>Reset Transformations.
2. With the solid component selected, go to File>Export Selection. Change the file type to fbx.
Make sure smoothing groups is on and the fbx file format is FBX 2014/2015.
Title the file, find a place to put it, and click Export Selection.
2. Now, select the flag's geometry and go to File>Export Selection.
Use the same settings as you did in the last step.
Title the file, find a place to put it, and click Export Selection.
Part 3: Step 2: Coming to an Unrealization
1. From now on, We will use the program Unreal Engine 4.
If you're using another game engine, I'm sorry,
but you'll have to look elsewhere on how to import animations.
Start by opening UE4.
2.Make a new project with no starter content.
Call it whatever you like and click Create Project.
3. Drag the fbx files from an open window into the content folder in UE4.
For the cloth component, be sure to import the mesh, skeleton, and animations.
For the solid component, only import the mesh.
4. Double click on the cloth's material and turn on two sided.
5. Drag both the cloth _anim file and the solid component into the viewport.
And you're done! Hit play to see that amazing piece of cloth you made flap in the wind!
I hope this helped you in whatever project you will use it in. So long for now.
The final animation in UE4