スクリプトからメッシュの作成や変更をできるようにするクラスです。
Meshes contain vertices and multiple triangle arrays.
See the Procedural example project
for examples of using the mesh interface.
三角配列は頂点配列のインデックスであり、おのおのの三角ごとに 3 つの頂点を使用します。
For every vertex there can be a normal, two texture coordinates, color and tangent.
These are optional though and can be removed at will. All vertex information is stored in separate
arrays of the same size, so if your mesh has 10 vertices, you would also have 10-size arrays
for normals and other attributes.
修正できるメッシュインターフェースを使用する目的は通常は 3 つほどあります。
1. Building a mesh from scratch:
should always be done in the following order:
a) assign vertices
b) assign triangles.
using UnityEngine;
public class Example : MonoBehaviour { Vector3[] newVertices; Vector2[] newUV; int[] newTriangles;
void Start() { Mesh mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; } }
2. Modifying vertex attributes every frame:
a) get vertices
b) modify them
c) assign them back to the mesh.
using UnityEngine;
public class Example : MonoBehaviour { void Update() { Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals;
for (var i = 0; i < vertices.Length; i++) { vertices[i] += normals[i] * Mathf.Sin(Time.time); }
mesh.vertices = vertices; } }
3. Continously changing the mesh triangles and vertices:
a) call Clear to start fresh
b) assign vertices and other attributes
c) assign triangle indices.
It is important to call Clear before assigning new vertices or triangles.
Unity always checks the supplied triangle indices whether they don't reference out of bounds vertices.
Calling Clear then assigning vertices then triangles makes sure you never have out of bounds data.
using UnityEngine;
public class ExampleClass : MonoBehaviour { Vector3[] newVertices; Vector2[] newUV; int[] newTriangles;
void Start() { Mesh mesh = GetComponent<MeshFilter>().mesh;
mesh.Clear();
// Do some calculations... mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; } }
bindposes | バインドポーズ。各インデックスのバインドポーズは同じインデックスのボーンを参照します。 |
blendShapeCount | メッシュの BlendShape 数を返します |
boneWeights | 各頂点のボーンウェイト |
bounds | メッシュのバウンズ |
colors | メッシュの頂点の色配列 |
colors32 | メッシュの頂点の色配列 |
indexFormat | Format of the mesh index buffer data. |
isReadable | Returns true if the Mesh is read/write enabled, or false if it is not. |
normals | メッシュの法線 |
subMeshCount | The number of sub-meshes inside the Mesh object. |
tangents | メッシュの接線 |
triangles | メッシュ内のすべての三角形を含む配列 |
uv | Mash のベースとなるテクスチャの座標 |
uv2 | 2 つめのテクスチャの座標 |
uv3 | 存在する場合、メッシュの 3 番目のテクスチャ座標設定 |
uv4 | 存在する場合、メッシュの 4 番目のテクスチャ座標設定 |
uv5 | The fifth texture coordinate set of the mesh, if present. |
uv6 | The sixth texture coordinate set of the mesh, if present. |
uv7 | The seventh texture coordinate set of the mesh, if present. |
uv8 | The eighth texture coordinate set of the mesh, if present. |
vertexBufferCount | Gets the number of vertex buffers present in the Mesh. (Read Only) |
vertexCount | メッシュの頂点の数 (読み取り専用) を返します。 |
vertices | 頂点の位置や、新しい頂点の位置の配列 |
Mesh | 空のメッシュを作成します |
AddBlendShapeFrame | 新しいブレンドシェイプのフレームを追加します |
Clear | すべての頂点データと三角形のインデックスを削除します |
ClearBlendShapes | メッシュからすべてのブレンドシェイプをクリアします |
CombineMeshes | メッシュに複数のメッシュを組み合わせます |
GetBaseVertex | Gets the base vertex index of the given sub-mesh. |
GetBindposes | Gets the bind poses for this instance. |
GetBlendShapeFrameCount | ブレンドシェイプのフレーム数を返します |
GetBlendShapeFrameVertices | ブレンドシェイプフレームの deltaTangents、deltaTangents、deltaTangents を取得します |
GetBlendShapeFrameWeight | ブレンドシェイプフレームの重みを返します |
GetBlendShapeIndex | 指定インデックスの BlendShape のインデックスを返します。 |
GetBlendShapeName | 指定インデックスの BlendShape 名を返します |
GetBoneWeights | Gets the bone weights for this instance. |
GetColors | Gets the vertex colors for this instance. |
GetIndexCount | Gets the index count of the given sub-mesh. |
GetIndexStart | Gets the starting index location within the Mesh's index buffer, for the given sub-mesh. |
GetIndices | Fetches the index list for the specified sub-mesh. |
GetNativeIndexBufferPtr | インデックスバッファへのネイティブ (規定のグラフィックス API) ポインターを探します。 |
GetNativeVertexBufferPtr | 頂点バッファを指すネイティブ (基底にあるグラフィックス API) ポインターを捜します。 |
GetNormals | Gets the vertex normals for this instance. |
GetTangents | Gets the tangents for this instance. |
GetTopology | Gets the topology of a sub-mesh. |
GetTriangles | Fetches the triangle list for the specified sub-mesh on this object. |
GetUVDistributionMetric | The UV distribution metric can be used to calculate the desired mipmap level based on the position of the camera. |
GetUVs | Gets the UVs of the Mesh. |
GetVertices | Gets the vertex positions for this instance. |
MarkDynamic | 頻繁な更新を行うためにメッシュを最適化します |
RecalculateBounds | 頂点からメッシュのバウンディングボリュームを再計算します |
RecalculateNormals | 三角形と頂点からメッシュの法線を再計算します |
RecalculateTangents | Recalculates the tangents of the Mesh from the normals and texture coordinates. |
SetColors | メッシュの頂点の色配列 |
SetIndices | Sets the index buffer for the sub-mesh. |
SetNormals | メッシュの法線を設定します。 |
SetTangents | メッシュの接線を設定します。 |
SetTriangles | Sets the triangle list for the sub-mesh. |
SetUVs | Sets the UVs of the Mesh. |
SetVertices | 新しい頂点位置の配列を割り当てます |
UploadMeshData | 以前行ったメッシュの変更をグラフィック API へアップロードします。 |
hideFlags | Should the object be hidden, saved with the Scene or modifiable by the user? |
name | オブジェクト名 |
GetInstanceID | オブジェクトのインスタンス ID を返します |
ToString | Returns the name of the GameObject. |
Destroy | ゲームオブジェクトやコンポーネント、アセットを削除します |
DestroyImmediate | Destroys the object obj immediately. You are strongly recommended to use Destroy instead. |
DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
FindObjectOfType | タイプ type から最初に見つけたアクティブのオブジェクトを返します |
FindObjectsOfType | タイプから見つけたすべてのアクティブのオブジェクト配列を返します |
Instantiate | original のオブジェクトをクローンします |
bool | オブジェクトが存在するかどうか |
operator != | 二つのオブジェクトが異なるオブジェクトを参照しているか比較します |
operator == | 2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。 |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.