# Mesh in Unity

## What is Mesh?

* Mesh is a **polygon that the Unity makes the image deformation.**&#x20;
* When you open the PSB through the <mark style="color:purple;">`sprite editor`</mark>, the **Unity2D system will create the polygons automatically**.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FOvNr3bFslqBmXvaIBOdW%2FImage%20-%2029.png?alt=media&#x26;token=e7802da3-35c5-4a11-8117-b1a4f962ebfd" alt=""><figcaption><p>Mesh will be created automatically by clinking 'Opne Sprite editior'</p></figcaption></figure>

### When do we need Mesh?

* Like a human body, we need to add bones to the image.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FcHRXx5M0XXD97Z5VAimd%2FImage%20-%2030.png?alt=media&#x26;token=9575f979-083c-4ad8-ae2b-436e26a6c472" alt=""><figcaption></figcaption></figure>

* With skeletal animation, you can make all the animations from a single sprite.
* When the polygon is defined inside the image, then its vertices can be manipulated to deform the image with the Unity Bone system.

## How to apply Mesh

1\. To create a mesh, you might need to select a <mark style="color:purple;">`PSB`</mark> in your project, when you see the inspector tab. Clicking the <mark style="color:purple;">`sprite editor`</mark> button will show the sprite editor popup window.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FuoqhQfL0lK5POMFIm6Nr%2F5.png?alt=media&#x26;token=32fa8321-6418-4f03-b441-7f3f23542fd5" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2F65815RQJuRBhUsRjLXya%2F6.png?alt=media&#x26;token=75f5d0ff-2fbb-4e40-883b-60fccb70b119" alt=""><figcaption></figcaption></figure>

2\. Once you get the popup window, you will need to change the <mark style="color:purple;">`Sprite Editor`</mark> to the <mark style="color:purple;">`Skinning editor`</mark>.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FgqdnsiHUiF6a0flSTwOI%2F7.gif?alt=media&#x26;token=85491848-985d-4147-847d-7fd92bdce734" alt=""><figcaption></figcaption></figure>

3\. You will see the auto-generated mesh when you tap the <mark style="color:purple;">`Auto Geometry`</mark> button. You can also Re-Generate the mesh if you don’t like it. In the options menu, you could choose the **detail of the outline**, **alpha tolerance** and **subdivide**. The options could be different for each image.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2Fia1Mh1GlEkWSCfYTdRzk%2F8.png?alt=media&#x26;token=331e7969-6e5d-4480-9d68-58bb93fb817f" alt=""><figcaption></figcaption></figure>

4\. Because of the performance, **we recommend you manually adjust all the mashes as much as possible.**

For example, you might need to **clean up the useless vertexes**. This will helps you set the bone much easier. You can add or delete the vertexes through the <mark style="color:purple;">`Create Vertex`</mark> button.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2F13WTBqIK60BCaA9lR704%2F11.gif?alt=media&#x26;token=fa630582-d1e1-4286-8a5b-112a9de1fad7" alt=""><figcaption><p>Process of adjusting vertexes</p></figcaption></figure>

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FeGEawSOTM7mJa8Qu47TL%2FImage%20-%2031.png?alt=media&#x26;token=dc87af97-2e01-4977-a59c-dd1ca4b45f3a" alt=""><figcaption><p>(Left) Automatic generated mesh , (Right) Manually adjusted mesh</p></figcaption></figure>

5\. How to add bone?&#x20;

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2F9j1C2eeUSyPtL9M3tOQv%2F12.png?alt=media&#x26;token=2da3bf52-ded6-47bf-8a88-69060a88cb33" alt=""><figcaption></figcaption></figure>

Once you have finished your mesh, the next stage is **adding bones**. Click and drag to create the first bone, following your design.

Furthermore, if you want to adjust the Weights, click the <mark style="color:purple;">`Auto weights`</mark> button.

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FCqzEWOViTNJvC40hfWPL%2F13.png?alt=media&#x26;token=0afbf9a2-a731-4719-a22f-b901a3dadc82" alt=""><figcaption><p>Automatically applied weights</p></figcaption></figure>

<figure><img src="https://1381431913-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F6CBs7vCLqptAiFUTrCYl%2Fuploads%2FHpUo0sMWegSCm2pZFyi8%2F14.gif?alt=media&#x26;token=81f4ca5c-017c-47d4-a620-0293895cd985" alt=""><figcaption><p>A sprite that moves along a bone with a weight applied</p></figcaption></figure>

6\. **Always, you will need to adjust weights for the vertex.** It’s up to you but remember, no pain no gain 🙂. There are two more useful tools that you can use for adjusting.&#x20;

* The <mark style="color:purple;">`Weight Slider`</mark> will help you if you want to set the value accuracy.
* <mark style="color:purple;">`Weight Brush`</mark> would be great if you don’t want to spend much time doing the rigging.
