Welcome to Custom Clothing (v.0.21)!

This is an advanced feature of Monkey allowing you to create and import custom clothing.

The following tutorial assumes that you are familiar with Blender and how to skin a character.  It focuses on
'how' to get custom clothing working into the game.  

If you are new to game development and Blender, creating your own clothing will require a lot of patience and
dedication.   I've outlined the overall fitting process below, and recommend you seek out Blender tutorials on
YouTube to learn the specifics of each step.


-- Limitations --

The game was not designed to support custom clothing.  It makes assumptions on the number and type of garments
available and how it render and deform them.  

Monkey's current approach is to replace an existing game asset with a custom one.  This is done in a way to 
make the game believe it is still dealing with its own assets.  

While this 'works' it comes with several drawbacks:
- Cloth replaced is unavailable until restored
- Only one garment per type can be replaced
- Garment types not supported by the game may not work well
	- Loose clothing will not deform properly
	- Heels will require custom poses 
	- Game has broken jackets assets
- Materials may require manual remapping
- Custom garments cannot be saved, shared or displaced

I've sent detailed notes to the developer of all the techniques I used and limitations I encountered.  My hope 
is that he preserves the mechanism used and with time, fixes the outfit system to better support custom clothing.



-- Process outline --

Creating clothes for SMA is similar to what you would do for any other game.

1. Create it    Use tools like marvelous designer, or get pre-made garments from site like Sketchfab
2. Fit it       Use the sculpt tool to fit the garment onto the female skin
3. Skin it      Attach your cloth to the game armature
4. Paint it     Use the weight painter to paint the deformation of each vertex group.  You can transfer weight
                from a similar game asset or from the female skin to get you started.
5. Shape it     Define and sculpt the shape keys to conform to the deformed female skin (do at least BODY_Fat p).
6. Texture it   Most Blender materials will not work with Unity.  Create a custom material and remap it with the
                Autodesk shader.
7. Import it    Follow the steps in this tutorial to bring your asset in game

Blender is very complicated and has several bugs that can corrupt your data.  I lost count on how many times
I had to 'revert' to a previous version because either i broke the asset, or it got corrupted.  Save, test 
often and keep backups!



-- Step by step --

1. Setup Unity

Go through the asset tutorial, and make sure you successfully import a cube into the game.  We will be using
the same project and technique to import/export clothing.  


2. Setup Blender

Install the most recent version of Blender (3.4+)
   
Locate and download the body_reference.blend tutorial file.  This will be posted separately to limit the mod
size and allow quick revision as necessary.

The Blender file should contain the following elements:

- Armature (CC_Base_BoneRoot)
  This is the game armature used to animate the female skin and clothes.  The 'skin' and clothing are attached
  (bound) to the armature, and deform as the bones move. 

  Note: the armature is a work in progress.  The asset extractor cannot recover it properly.  If you can help
  improve it, pm me.

- Female skin (CC_Base_Body)

  This contains the female skin used by the game.  This is provided so you can tailor and sculpt clothing to
  conform to the model and define the compatible shape keys for your clothing.

- Game example shirt (top_henley)

  This contains the game henley for reference.  It is pre-skinned with correct weights.  You can use this to
  transfer the weights to your custom top as a starting point.  You can extract the other game assets via asset
  ripper.
  
- Leather jacket example (top_leather)

  This is the best 'free to distribute' asset I've found on Sketchfab.  Thank you so much Kendell!
	"Leather Jacket" (https://skfb.ly/o6GQJ) by KendellRummage is licensed under 
    Creative Commons Attribution (http://creativecommons.org/licenses/by/4.0/).

  The adaptation of this asset is a work in progress and contains several issues. If you can provide a better 
  version with accessories, pm me.


3. Name your assets

Monkey will replace garments based on their prefix name.  The game supports the following asset type:
	bra, bottom, glove, jacket, jewelry, lens, panty, shoe, sock, swimsuit, top

Your Blender file can contain any number of garments.  Only the selected ones during the export will be used.

Note that the leather jacket uses a 'top' prefix.  This is because the game jackets are broken and unused.
While you can use any prefix you want, always try to match your garment to what the game supports.  

In general:
	Pieces covering the breasts: use top
	Pieces covering the buttock: use bottom
	Pieces covering both: use swimsuit
	
Experimentation will be required if you have unusual pieces, say a bunny suit that covers the model from head
to toe.
	

4. Blender export to FBX

- Select the layout workspace then object mode.  Shift click the garment(s) you want to export in the 
  workspace then the armature.  Do this in the workspace window as selecting those from the scene browser 
  never worked well.

- With the objects selected, click File->Export->Fbx.

- Configuring the export parameters is critical.  Always verify those settings as Blender often resets them.  

  If this is your first-time exporting: select Operator Preset -> Restore defaults

  See blender_export_settings.webp for the full settings.  From default settings, the following needs 
  to be changed:

	Include: 
		Limit to - Selected Objects: On
	Geometry: 
		Apply Modifiers Off
	Armature: 
		Primary Z Axis
		Only Deform Bones: On
		Add Leaf Bones: Off
	Bake Animation: Off


5. Unity import from FBX 

Load unity with the test project that successfully exported a cube.  

Select Asset->Import New Asset, then select the fbx file you created and click import.

In the inspector, select the 'model' tab then turn the toggle Read/Write on, then click apply.

If your garment has ligthing issues in game, you can also try 'Generate Lightmap UV', then click apply.


6. Material setup (optional)

By default, Unity will try to remap the Blender materials to the HDRP/Lit shader.  

If your garment uses a simple albedo map, this will work fine. 

However, many garments now use PBR textures and normal maps.  Those will not work properly in the game.  
This is because the developer modified all standard shaders in a way that is no longer compatible.

The way around this is to create your own custom materials and remap the textures manually using 
HDRP->Autodesk Interactive shaders.  Those are the only shader still working with a default setup.

You can work with the color map or omit it if you want to have the user change the color from a white base.

Once you have created your custom material, just drag and drop it to the 'On demand' slot in the material tab.


7. Export to the game

Once ready, drag and drop the fbx asset into the asset bundle window and build.

Make sure to save the asset in the Monkey/Clothing folder and add a .unity3d extension.



-- References --

- Game asset extraction: Asset Ripper (https://github.com/AssetRipper/AssetRipper)
- Mask map creator: https://assetstore.unity.com/packages/tools/utilities/texture-channel-mixer-180690

