Version: 2017.2

Mesh

class in UnityEngine

/

継承:Object

マニュアルに切り替える

説明

スクリプトからメッシュの作成や変更をできるようにするクラスです。

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;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Vector3[] newVertices; public Vector2[] newUV; public 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;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals; int i = 0; while (i < vertices.Length) { vertices[i] += normals[i] * Mathf.Sin(Time.time); i++; } 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メッシュの頂点の色配列
isReadableモデルがインポートされたときの読み取り/書き込みの有効ステータス
normalsメッシュの法線
subMeshCountサブメッシュの数。すべてのメッシュは個別の三角形のリストを持ちます。
tangentsメッシュの接線
trianglesメッシュ内のすべての三角形を含む配列
uvMash のベースとなるテクスチャの座標
uv22 つめのテクスチャの座標
uv3存在する場合、メッシュの 3 番目のテクスチャ座標設定
uv4存在する場合、メッシュの 4 番目のテクスチャ座標設定
vertexBufferCountメッシュの頂点バッファの数を取得します(読み取り専用)。
vertexCountメッシュの頂点の数 (読み取り専用) を返します。
vertices頂点の位置や、新しい頂点の位置の配列

コンストラクタ

Mesh空のメッシュを作成します

Public 関数

AddBlendShapeFrame新しいブレンドシェイプのフレームを追加します
Clearすべての頂点データと三角形のインデックスを削除します
ClearBlendShapesメッシュからすべてのブレンドシェイプをクリアします
CombineMeshesメッシュに複数のメッシュを組み合わせます
GetBindposesGets the bind poses for this instance.
GetBlendShapeFrameCountブレンドシェイプのフレーム数を返します
GetBlendShapeFrameVerticesブレンドシェイプフレームの deltaTangents、deltaTangents、deltaTangents を取得します
GetBlendShapeFrameWeightブレンドシェイプフレームの重みを返します
GetBlendShapeIndex指定インデックスの BlendShape のインデックスを返します。
GetBlendShapeName指定インデックスの BlendShape 名を返します
GetBoneWeightsGets the bone weights for this instance.
GetColorsGets the vertex colors for this instance.
GetIndexCountGets the index count of the given submesh.
GetIndexStartGets the starting index location within the Mesh's index buffer, for the given submesh.
GetIndicesGets the index buffer for the specified sub mesh on this instance.
GetNativeIndexBufferPtrインデックスバッファへのネイティブ (規定のグラフィックス API) ポインターを探します。
GetNativeVertexBufferPtr頂点バッファを指すネイティブ (基底にあるグラフィックス API) ポインターを捜します。
GetNormalsGets the vertex normals for this instance.
GetTangentsGets the tangents for this instance.
GetTopologyサブメッシュのトポロジーを取得します
GetTrianglesGets the triangle list for the specified sub mesh on this instance.
GetUVs指定されたチャンネルの UV を取得します
GetVerticesGets the vertex positions for this instance.
MarkDynamic頻繁な更新を行うためにメッシュを最適化します
RecalculateBounds頂点からメッシュのバウンディングボリュームを再計算します
RecalculateNormals三角形と頂点からメッシュの法線を再計算します
RecalculateTangentsRecalculates the tangents of the Mesh from the normals and texture coordinates.
SetColorsメッシュの頂点の色配列
SetIndicesサブメッシュのインデックスバッファを設定します。
SetNormalsメッシュの法線を設定します。
SetTangentsメッシュの接線を設定します。
SetTrianglesサブメッシュの三角形のリストを設定します。
SetUVs指定されたチャンネルの UV を設定します
SetVertices新しい頂点位置の配列を割り当てます
UploadMeshData以前行ったメッシュの変更をグラフィック API へアップロードします。

継承メンバー

変数

hideFlagsオブジェクトは非表示、シーンに保存、ユーザーが編集可能、などを設定する。
nameオブジェクト名

Public 関数

GetInstanceIDオブジェクトのインスタンス ID を返します
ToStringゲームオブジェクトの名前を返します

Static 関数

Destroyゲームオブジェクトやコンポーネント、アセットを削除します
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoad新しいシーンを読み込んでもオブジェクトが自動で破壊されないように設定します
FindObjectOfTypeタイプ type から最初に見つけたアクティブのオブジェクトを返します
FindObjectsOfTypeタイプから見つけたすべてのアクティブのオブジェクト配列を返します
Instantiateoriginal のオブジェクトをクローンします

Operator

boolオブジェクトが存在するかどうか
operator !=二つのオブジェクトが異なるオブジェクトを参照しているか比較します
operator ==2つのオブジェクト参照が同じオブジェクトを参照しているか比較します。