In my blog about gettings cloth physics to work in UE4, i had tried to build my own working cloth in 3ds max and import it into UE4 using Apex and PhysX files.
Sadly this did not end well and i believe i know why. The computer i was using when i installed Apex and PhysX plug-ins for 3ds max kept crashing the program when i tried to export the file. I believe it just didnt export properly and thus ended in disaster. The resulting video will be posted soon. The good that came out of this is that i ended up learning the basics for 3ds max AND i know how to make convincing static cloth meshes. i can use this to create cool pieces like bed covers or static sheets of laundry.
However, i did not lose hope. I got two leads, the first is that a classmate of mine told me that i could reverse engineer the cloth from one of the example levels in UE4. Another friend told me that he did it in Maya2015, which is preferred to me. So lets try both!
First lets try to the Maya one.
You open maya 2015 and make sure the Apex and PhysX plug in is installed. The first thing you do when you open the scene is go to Windows ->Settings/Preferences –> Plug-In Manager. Turn on PhsyX.
Set up the scene to the correct sizes of what you need. So if you refer back to my previous blogs, i have the new sizes of the grid you need in Maya2015 to safely import objects into UE4.
Once your in, create a plane. Mine started as default size with 10×10 divisions.
I scaled it up by 400x1x250. Made sure it was centered and translated so the bottom is not touching the world 0.
Before i continue, i delete all history and freeze transformations.
Then i want to make several even divisions. Go to Mesh–>Smooth. After the first time, click ‘G’ 3 times to create more divisions.
This should look like it has a lot of polys but this allows us to get the flow of the cloth more smooth. You can add another smooth to get a smoother flow, but it might be too much.
At this point, you can unwrap the plane. This will get the cloth ready for a material.
Now we should add the bone.
I went into the 2×2 split view and clicked on the animation Tab at the top left. Click the Joint tool and create two node as such (starting from top to bottom).
Now we are going to smooth bind the plane to the bone. Click the Plane and select the bone and hit smooth bind. The default settings are enough. To test if its working, move the bottom node back and forth and parts of the plane should follow. Note: you might notice that a couple of vertices aren’t moving with it, this is fine, it’ll all come together soon.
Now we want to start painting the cloth so it can move the way we want. Select the cloth part and select the PhysX tab at the top. Click on Create Apex Clothing. With the cloth selected, click on the Paint button on the right. You can now paint the vertices to flow the way you want.
On the right there will be a new window. Under Paint Attributes, your going to change Value to 0 and hit Flood. This makes the whole plane the same value which means it doesn’t flow or move at all.
Now Change the Visible range to 0 and 120. Go back to the Value Slider and go to the far right (120). Now you can paint the whole cloth except the top row of polys. With the value of zero, these are going to be our anchors. If you want to attach these to a curtain rod, these won’t move.
Note: If you click off the objects accidentally, just select the cloth again and click on the Wrench Tool (Edit PhysX Object) under the PhysX tab and click Paint again and it’ll just continue where you left off.
At this point, its safe to export the file. Select the cloth and Export it as an .fbx file. Make sure smoothing groups are active. You also need to export it one more time but this time choose APEX/PhysX and make sure Export APEX Assets is checked on and its APB (not APX).
If you want to test your cloth, there is a simple way of making sure it works perfect. Select the top node of your bone and make a keyframe at 1. Then move over to frame 40 and move the bone to the left a bit and make it a keyframe. Under the Apex tab, there is a Play Button, if you press that, it’ll simulate the cloth physics for you. To go back to normal, remove the keys in reverse order of creating them, so your original stuff is at world 0 again.
Name these files the same so you dont get confused and since these are different files types, you wont get them mixed up.
Now open up UE4 and load a new, empty level.
Import the .fbx file of your cloth. Place it in the level.
Double click to open the editor for the cloth. Under the Clothing window, click on ‘Add Apex clothing file…’ and select the .apb file you created.
Then go to LOD0 window and beside ‘Clothing’ there should be a drop down menu, click it and add the .apb file there. Now save it and hit play. Tada! you now have cloth imported correctly to UE4. However it may not move because there is no wind.
Lets play around with this problem….
First there is a world node that you can probably implement that allows the wind to occur worldwide. But there are a couple of tutorials here that allow for wind control using materials.
So i created a Material for my cloth so i can work with the material editor.
I added a SimpleGrassWind node, and two Constant nodes.
I attached a constant of 0.4 to WindIntensity.
I attached a constant of 0.5 to WindWeight.
I attached the AdditionalWPO(v3) to the white node under the texture sample.
Okay so for me, the material way didnt work.
The second option is to go under the modes and search Wind Directional Source. Add one to the level. It should be a flag type node in the scene that you can edit. You can adjust the speeds and strength of the wind so it can affect the different cloth pieces.
One thing we can do is experiment with the different values we painted with in Maya using PhysX painter.
One thing i noticed is that if you scale the object in the scene, it’ll scale it by the areas that aren’t painted…and it changes the way the cloth flows. I can test different methods to see what works with what. What i know so far is that you would have to export external objects separately from the cloth so they don’t interfere.
Cheers,
Jason