DesktopMMD3:Miss Fish

DesktopMMD3:Miss Fish

Not enough ratings
How To use Unity to convert your PMX and Add Magica Cloth/Dynamic Bones
By PW
This is the guide that I wanted to share for some time. In MMD3 if you want to solve the penetration problem, you have to use Magica Cloth in Unity, but it's not so easy to do it properly. I went through lots of trial and error to get things done. There are just so much need to know. I am afraid this guide might not cover all. So in this guide I will only cover the basic, and you still need to figure out lots of details in Unity. Yet, believe me. It took me a long time to learn how to do this, you are actually taking a shortcut here.
   
Award
Favorite
Favorited
Unfavorite
1. Prepare Your Unity 2019.4.4f1
Go to https://unity.com/download and download the latest Unity Hub for windows ( but not the latest Unity version!!) . For DesktopMMD3, you have to download the 2019.4.4.f1 version. Don't bother to download anything else. Yeah, it took me lots of time to know 2019.4.4.f1 is the best one to use for MMD3. You are welcome to try the other fancy 2021/2020 version, but I already know it won't work.

After your Unity 2019 is ready, download my MMD package here[drive.google.com] Extract the "MMD" folder under "Documents\Unity\" so your folder should look something like this:

There are actually 5 packages pre-installed in this 7zip file:
* MMD4Mecanim, for import PMX into Unity. It will use an old 2017 "pmx2fbx.exe" program to convert your PMX model. It also comes with nice shaders which are supported by DesktopMMD3.
Note: Don't use the bullet physics engine that comes with it though, your MMD3 is not using it anyway.
* Dynamic Bone, for short tails, ear rings and other short and "linked" objects. It's much easier to setup than Magica Cloth, and it is much more fitting to use on chain like objects. Unlike Magica, it will not turn the object "soft".
* Magica Cloth. This plug-in is like real magic. It turns game objects soft like silk. It's designed to use on hair braids and clothes. For beginners, it's not easy to set things right, a lot of parameters to consider. You can go to their website [magicasoft.jp] and learn how to use it. It will take lots of practice to make your model's cloth and hair perfect, but the result will be great.
* Asset Bundle. It will pack your generated model or dance into asset files, which can be read by DesktopMMD3.
* RedBlueGames BulkRenamer. For the best result, you need to bulk rename game objects with "hair" or "skirt" in it. This way DesktopMMD3 will not assign its own Magica properties to those objects. I usually rename all "hair" to "haair", and all "skirt" to "skiirt". Of course it's up to you to do the renaming, or you don't need to do it at all.

Of course if you find those plug-in useful, you should pay the developers. Their great work deserve every penny.

Now in Unity Hub, in Projects, open the MMD folder you just extracted.
If everything works, you should see this:


Notice that on the left "MagicaPhysicsManger" should have a pink star. If you don't see the pink star, you need to open "Windows"->"Package Manager" and install "Jobs preview.11 - 0.2.10"
Well, this concludes the first step. A lot to sink in, right? Wait until you read the next section.
2. Import your PMX
Now your Unity 2019 is ready, time to import a PMX model.
Here is an example PMX, Pulao Universal from Punishing Gray Raven.
Downloaded from xCallme-Luxx
https://www.deviantart.com/xcallme-luxx/art/MMD-Punishing-Gray-Raven-Pulao-Universal-DL-904453879

The folder of Pulao looks like this:


And before you import it, it's a good idea to open the model with PmxEditor first. Make sure it looks right.

Tip: For PmxEditor, if you are using 4k monitors, you need to manually set its "High DPI Settings" -> "Scaling Performed by" to "system" like below:

If the PMX looks OK under PmxEditor, it should be OK in Unity as well. Otherwise, it's better to fix it under PmxEditor.

Now drag the whole "Pulao" folder into the "Assets" folder like below:


In Unity, open the "Pulao" folder and click on the strange icon with a blue cube, then check all three on the right and click on "Agree". It's all policy, you just sign your rights away. :D


Once in the MMD4Mechanim settings, check on "Advance Mode" and uncheck the "Bullet Physics", then click on "Process":


The PMX2FBX will run. It will take some time. Once it's finished, you will need to click on the new FBX in Assets, which is a gray rectangle with an right arrow, then on the right, click on "Rig" then change the "Animation Type" to "Humanoid", then click on "Apply", like below.


Now you should see the Pulao FBX has change and it should look "normal". Time to click on "Configure" on the right to start the Avatar configuring.


This section now it's over. Avatar configuring needs to have its own section. A lot to cover.
Do you have a headache yet? If not, continue.
3. Configure the Avatar
Congrats on reading so far ! Avatar configuring is fun ! I think you should really pay great attention to it. So it has a separate section.

Avatar configuring is so important, that I was not realized it until quite late. Properly using it, you will save a lot of time later on.

Now continue from last section, our little angel Pulao is now ready for the inspection. We do need to know some bone names from her.

As you can see, there are a lot to learn in this screen. On the left it's Pulao's objects hierarchy tree, in the middle is Pulao's preview with bones, on the right is Pulao's avatar configuration. There is simply so much need to know here. I cannot cover them all. So I just tell you 2 ways: the easy way and my way.

The easy way: You don't really care about Magica or Dynamic bones, you just want your model be able to use in DesktopMMD3. Then you can just click on "Pose->Enforce T-Pose", then "Apply", you are all done. You can go directly to next section.


My way:
After Enfore T-Pose like above, I start to check the bones on the right and see if any bones was wrongly assigned, like middle finger assigned to the index finger, or chest bone assigned to spine bone... etc. It takes practice, but you should get it quick.

Then it's time to get the hair bones and skirt bones numbers.
For example, I click on the first bone of the long hair braid, on the left that bone's name instantly turns yellow:

So now I know the long hair braid is 106. I will need this number later on for Magica and Dynamic Bones.
Continue clicking other hair braids, I got their first numbers:
Long hair: 106
Short hair: 89, 90, 96, 102, 104, 118, 122, 125, 127, 128, 129
Latern: 125
Latern is a perfect example of dynamic bone. It's not soft like hair, but it should be able to move around.
But in the end Latern does not move as I expected, so I haven't use Dynamic Bone with it after all.

Now check the cloth bones, starting with the clothes on her back:

I got 173, you can easily see there is a pattern of numbers to it. So I write them down:
Back Cloth: 173, 174, 175, 176, 177, 178, 179, 180, 181,182,183,184,185,186,187,188
Skirt: 303 - 322
Side Braid: 464
The side braid can be Magica Cloth, or Dynamic bone. It should depends on which one looks better visually. Sometimes Dynamic bone wins, sometimes Magica wins. ( In this case Magica wins all, of course. )

The reason to record all the numbers here, is to easily assign those numbers to Magica and Dynamic bones later on. Otherwise, once you are out of Avatar configure, you will not see how those bones work so easily.

Also, some PMX comes with bones in strange positions. Here you can rotate the bones to align them properly. Or you can help Unity recognize the bones the correct way by assigning those bones manually.

Once it's all set, you can apply the avatar settings:



OK, the next section is about Magica and Dynamic bones. I will do it another time. To be continue...
4. Create new Pre-Fab
After you finish setting up the avatar, which is part of the fbx file, you now need to create a Pre-Fab to add your own stuff in it.

What is Pre-Fab? You can read here [docs.unity3d.com]if you have spare time. To me a prefab is a package of game objects including bones and meshes. Usually I won't change any meshes. So from what we see here, a prefab is like a package of bones.

What's the use of those bones? I'm a Unity newbie, so my answer probably is wrong. To me, bones are like the bones in your body, and they attach to your fresh, which are meshes in Unity. So when a bone moves, the mesh attached to it also moves. Also bones defines how the body is structured and how hands and legs move.

To load a model, DesktopMMD3 will only accept an Unity prefab packaged by Asset Bundler. So you will need to create a prefab. It's actually quite easy.

1. Drag the FBX to the left next to the camera and light. A "Pulao Universal" model will appear in the middle.


What happened is, you just dragged a FBX into a scene.
A FBX file is similar to a prefab, but it's not exactly the same. Besides the bones and meshes like in a prefab, it also contains materials, animation and avatar settings, but they are not natively used by Unity. Every time you change the materials, animation or avatar settings, Unity will need to import the settings all over again.
Prefabs, on the other hand, seem to be working natively. The changes you made will show up instantly without any import delays.

2. Drag the "Pulao Universal" on the left panel back to the assets folder. In the dialog, Choose "Original Prefab".


Now an original prefab is created. It looks similar to the FBX, but not the same, as below:



This original prefab will be the one we work on. This prefab is also the same "Pulao Universal" in the left panel.
There is one important point here: Don't edit the prefab on the left panel when the characters are blue !
When the characters are blue, it means any changes you make are external to the prefab. You are not really changing the prefab, you are just adding settings to the prefab. So when Asset Bundler packs your prefab, the additional settings will be ignored.
Therefore, to really change the prefab, you should either highlight the prefab, then click on "Open Prefab" on the right panel, or you can click on the ">" on the left panel:


Now the middle turns blue, which means you are editing the prefab. In the left panel, the characters are black instead of blue. As below:



Now you are ready to add your own settings, including Magica Cloth and Dynamic Bones.
5. Add your first Magica Bone Cloth
Once you are in the prefab editing mode, you can start adding fancy stuff like Magica Cloth and Dynamic Bones.
Remember I made notes in the previous section about hair and skirts ? Now those notes come in handy.
First you need to rename all the "hair" and "skirt" to "haair" and "skiirt". This way DesktopMMD3 will not add its own Magica Cloth properties to it, and you will have full control of how the hair flows and how the skirt flutters.

1. Type "hair" in the left top section. All bones with the name "hair" will show up.
2. Select all the bones show up on the left.
3. Click on the menu "Asset -> Bulk Renamer"
4. All the selected bones will be added to the "Mulligan Renamer". You just need to type in "hair" for "Search for String", and "Haair" for "Replace with".
5. Click on "Rename" to do it.



Now all the bones with "Hair" are renamed. Do the same thing with "Skirt".

Finally time to create your first Magica Cloth.
Right click on "486.!Root" and choose "Create Other -> Magica Cloth -> Magica Bone Cloth"
Then rename it to "Magica Bone Cloth (Short Hair)". This one will handle the short hair.

Now you may ask why separate the short hair from long hair. Because the short hair will only collide with Pulao's head, while the long hair might collide with Pulao's head, back, and arms. So by separating the long hair from the short, it will reduce the Magica's calculation.

Highlight the "Magica Bone Cloth (Short Hair)" you just created, and click on the little lock icon on the right panel:

This way the inspector will not switch to other properties, which is annoying.

Remember there are 11 first bones of short hair? So let's change the Root Size to 11 and hit enter. You will have an list of empty elements from 0 to 10.


From left panel, you drag the bones with number: 89, 90, 96, 102, 104, 118, 122, 125, 127, 128, 129 into the element list. When you are done, it should look like this:


What do those yellow cubes and white cubes mean? Click on the "Start Point Selection" and you will see:

* The red dots are fixed points, which were the yellow cubes. The green dots are movable points, which were the white cubes.
* Each chain of bones needs at least one fixed point, otherwise the whole chain will drop below the floor.
* Sometimes it's a good idea to add additional fixed points to a chain, to keep the hair maintains "the shape". In Pulao's example here, all hair chains are vertical and no "shape" to maintain. So all of them just need the first points to be fixed.

Now click on "End Point Selection", it will goes back to the yellow and white cubes.

There is a lot of other settings, but for now you just need to change the "Radius" to "Start: 0.015 , End: 0.02, No Curve" and "Mass" to "Start: 10, End: 5, No Curve" as shown below.


( Sorry, I forgot to add the check on "Collider Collision" like below: )


Then scroll all the way down to the bottom and click on the red "Create" button:


The yellow and white cubes are gone, and now scroll up to the top in inspector, you will see the "Magica Bone Cloth" component now has data.
Highlight the "Magica Bone Cloth (Short Hair) " on the left panel, and click on "Open Cloth Monitor", you will see how the Magica Cloth works:


OK, since we don't want the short hair penetrate the face, now it's time to add a "Magica Cloth Capsule Collide" to the head.
* Click on the little "Lock" icon on the right panel, so the inspector can be unlocked.
* Right click on the "88.joint_head" bone on the left and click on "Create Other -> Magica Cloth -> Magica Capsule Collider" like below:


A big collider shows up, you need to change its axis to "Y" then adjust the "Length", "Start Radius" and "End Radius". And you also need to look from different angles to see if the collider fits. So finally I got the collider fit like below:



I am quite conservative when it comes to hair colliders, because hair bones tends to be overly affected by colliders. It's up to you how you set the numbers. I am just showing your my way. You need to do your own experiments for your own satisfaction.

Time to add this collider to the "Magica Bone Cloth ( Short Hair )"
1. On the left, highlight the "Magica Bone Cloth (Short Hair)".
2. Click on the lock icon to lock the inspector.
3. Scroll down and set the "Collider List -> Size" to 1, then hit Enter
4. Click on the collider icon in the head, the collider will be highlighted on the left panel, drag that collider to the "Element 0" on the right panel.


To check the result, highlight the "Magica Bone Cloth (Short Hair)" on the left again. and open the Cloth Monitor, you will see this:


I am happy with the result. So I unlock the inspector and click on the "<" in the top left to back to the scene. The background turns back to gray from blue. Time to package the prefab into an Asset Bundle.
6. Package the model into an Asset Bundle
Before packing Pulao, I want to do a quick check under Unity, this step is optional.
<optional>
First I will right click on an empty space in "Assets > Pulao" and create an Animation Controller, like below:


I just named it "AC". Then I highlight "Pulao Universal" on the left and drag the "AC" to the "Controller" on the right, as below:


Now click on the "Play" button of the scene, you will have a quick check on how the collider works with the bone cloth.


Pulao is now in a strange position, but she's actually OK. This is what she's supposed to look like, not flying to the sky or anything falling below the floor.
</optional>


OK, time to pack her into an Asset Bundle, but first click on the "Play" button again to back to the normal mode.

Click on the menu "Window -> AssetBundle Browser" like below:


Drag the prefab, not the FBX, to the "AssetBundles" window.


Then click on "Build", check the "Clear Folders" before you click on "Build". Answer "Yes" to clear the folder. Be patient, it will take a while to build the asset.


Now you can launch DesktopMMD3 and create a new model:


Model name? "Pulao" of course, then for the "Model File", you can browse to "Documents\Unity\MMD\AssetBundles\StandaloneWindows" and choose "Pulao Universal", which is now 3281 kb.


Click on "OK" and now you have a new "Pulao" model. Click on "Add" and see how she looks.


As you can see, her short hair works, but the long hair and skirt are stiff. This is actually a good sign. Now it's up you to go back to Unity and add the other Magica Bone Cloth components for her.

It will be a long process and you will do a lot of back-and-forth between Unity and DesktopMMD3. My end result is somewhat like this:


As you can see, I made 5 Magica Cloth plugins and 9 Magica Capsule Colliders. The end result is not perfect. She is putting her hands inside her thighs. The skirt sometimes goes to the wrong way. Still, it's a lot better than before. When she dances, you will clearly see the huge difference.

Click here to see the workshop item of the final result.

Here are some tips:
* For her back cloth, the "Connection Mode" should be "Mesh Automatic" or "Mesh Sequential No Loop".
* The back cloth should only collide with a Magica Capsule Collider attached to her chest.
* For her skirt, the "Connection Mode" should be "Mesh Sequential Loop"
* Her skirt should collide with two Magica Capsule Colliders attached to her legs. Then I added one collider for the center hip so the skirt front will not slip over her legs and disappear.
* The Radius size of the Magica Bone Cloth is important. Use "Cloth Monitor" to check the size. Don't over size it or under size it. I usually set the start to be 0.015 and the end to 0.02-0.05.
* If you set the "Mass -> End" to 1, like the default, the end of the cloth will become too light. Most of the time it's not actually what you want. For short cloth I will set it to 5 and for long one I will set it to 2 or 3.
* Don't forget to check on "Collider Collision" near the end of the Magica Bone Cloth settings. If you are setting properties to skirts, check the "Penetration" below it, and set the "Penetration Mode" to "Collider Penetration". This way the skirt is a lot more penetration-proof.
* If your model have a really long skirt, you can consider increase the "Clamp Distance -> Max Distance Ratio" to 1.1 or even 1.2. This way the skirt will look more "elastic" and can be more resistant against penetration.
* If your PMX model has a texture problem, that all or some materials are white, that's a completely different beast to slay. This guide cannot cover it.
My hint is that you need to extract the materials from the FBX, then manually assign TGA or PNG to it.
1. Unity doesn't support DDS texture files. So you need to convert DDS files to TGAs by a program called "Paint.Net" then assign the TGAs to the materials.
2. If your texture filename is messed up, you use the wrong zip program. You should use Bandi_Zip to handle it. 7zip is the wrong tool to use here.

Important: If you want to make a model perfect and penetration-proof, it will take a lot of practices. This guide shows only the first step. You need to figure out how to set the long hair, skirt and back cloth properly following the short hair example. It's all about the patience and perseverance. At least you don't need to experience what I had gone through to make all those things worked together.

Also you can see that I didn't put Dynamic Bone in this course, because
1. In this case I didn't use any Dynamic Bone.
2. Dynamic Bones is much easier to figure it out.
3. I left enough clues in this guide.
So you need to figure this component yourself. You can do it.

OK, this concludes the whole guide. I hope you find it useful. Happy MMDing !
1 Comments
lvljob Jan 18 @ 2:56pm 
Philip, Thank you very much for such a detailed first lesson! Much time has passed and the archive for Unity specified in the article is no longer available. Could you update the link to this archive for the version of Unity specified in this article?