3Dの頂点情報は、テクスチャやシェーダーなどの位置を判別するのにUVというものを使ってまるみなどによる面のゆがみなどを調整することができます。
このUVを使ってテクスチャーを左右対称にしようって考え方です。
UVは、コンポーネントのMesh Filterを使ってmeshFilter.mesh.uvで
uvポイントの位置を調整する事ができます。
真ん中を中心に左側のUVを右側へ移動することで左右対称にする事ができます。
それでは、オブジェクトを用意しましょう。
Unityのデフォルトだとめっちゃたくさんメッシュがあって
UVを管理するのがメンドクサイので3Dソフトでシンプルなメッシュ数にします。
Unity以外に使えないよ!って初心者の方用にこのデータを
githubに上げておくので使って下さい。
https://github.com/amano-kiyoyuki/sample/model/plane.fbx
では、このモデルに以下のスクリプトを入れて下さい。
※UVを左右対称にする一個手前の事については、以下のサイトさんをご参考にして下さい。とても詳しく説明されています。
http://narudesign.com/devlog/unity-mesh-vertix-uv-1/
using UnityEngine;
using System.Collections;
public class SymmetrieUV : MonoBehaviour {
void Start()
{
//メッシュデータを調べる
Mesh mesh = gameObject.GetComponent<MeshFilter>().mesh;
for(int i = 0; i < mesh.vertices.Length; i++)
{
print("vertices[" + i + "] : " + mesh.vertices[i]);
}
for(int i = 0; i < mesh.uv.Length; i++)
{
print("uv[" + i + "] : " + mesh.uv[i]);
}
for(int i = 0; i < mesh.triangles.Length; i++)
{
print("triangles[" + i + "] : " + mesh.triangles[i]);
}
//メッシュフィルターに変更したUVを入れる
MeshFilter meshFilter = gameObject.GetComponent<MeshFilter>();
Vector2[] newUV = new Vector2[9];
/*そのまま貼付けた場合のUV
newUV [0] = new Vector2(0.0f, 0.0f);
newUV [1] = new Vector2(0.0f, 0.5f);
newUV [2] = new Vector2(0.5f, 0.0f);
newUV [3] = new Vector2(0.5f, 0.5f);
newUV [4] = new Vector2(1.0f, 0.0f);
newUV [5] = new Vector2(1.0f, 0.5f);
newUV [6] = new Vector2(0.0f, 1.0f);
newUV [7] = new Vector2(0.5f, 1.0f);
newUV [8] = new Vector2(1.0f, 1.0f);
*/
//左右対称にする。
newUV [0] = new Vector2(1.0f, 0.0f);//左下を右下へ移動
newUV [1] = new Vector2(1.0f, 0.5f);//左から右へ移動
newUV [2] = new Vector2(0.5f, 0.0f);
newUV [3] = new Vector2(0.5f, 0.5f);
newUV [4] = new Vector2(1.0f, 0.0f);
newUV [5] = new Vector2(1.0f, 0.5f);
newUV [6] = new Vector2(1.0f, 1.0f);//左上から右上へ移動
newUV [7] = new Vector2(0.5f, 1.0f);
newUV [8] = new Vector2(1.0f, 1.0f);
meshFilter.mesh.uv = newUV;
}
}
これを貼付ければ
っとこのようになります。