本日は Unity の調査枠です。
UnityEngine の Mesh クラスのドキュメントを理解のため、少しずつ読み進めていきます。
前回記事の続きです。
bluebirdofoz.hatenablog.com
Simple Mesh APIクラスのドキュメント
今回は Mesh クラスで利用する Simple Mesh API の以下の関数ドキュメントを読み進めていきます。
docs.unity3d.com
docs.unity3d.com
docs.unity3d.com
docs.unity3d.com
SetVertices
public void SetVertices (Vector3[] inVertices);
public void SetVertices (List inVertices);
public void SetVertices (NativeArray inVertices);
引数 | 説明 |
---|---|
inVertices | 頂点座標 |
新しい頂点座標の配列を割り当てます。
public void SetVertices (Vector3[] inVertices, int start, int length);
public void SetVertices (List inVertices, int start, int length);
public void SetVertices (NativeArray inVertices, int start, int length);
引数 | 説明 |
---|---|
inVertices | 頂点座標 |
start | 入力配列から取得する最初の要素のインデックス |
lengh | 入力配列から取得する要素の数 |
入力配列の一部を使用して、メッシュの頂点位置を設定します。
このメソッドは入力配列の一部を使用して SetVertices を呼び出したかのように動作します。
指定の start インデックスから始まり、指定された length 長が取得されます。
結果のメッシュには length 数の頂点があります。
SetTriangles
public void SetTriangles (int[] triangles, int submesh, bool calculateBounds= true, int baseVertex= 0);
public void SetTriangles (List triangles, int submesh, bool calculateBounds= true, int baseVertex= 0);
public void SetTriangles (ushort[] triangles, int submesh, bool calculateBounds, int baseVertex);
public void SetTriangles (List triangles, int submesh, bool calculateBounds, int baseVertex);
引数 | 説明 |
---|---|
triangles | 三角形を定義するインデックスのリスト |
submesh | 変更するサブメッシュ |
calculateBounds | 三角形を設定した後、メッシュの境界ボックスを計算するか否か 既存の境界ボックスを使用して三角形を設定するCPUコストを削減する場合は false を使用する |
baseVertex | 全ての三角形の頂点インデックスに追加されるオプションの頂点オフセット |
サブメッシュの三角形リストを設定します。
サブメッシュは単一の Material を使用してレンダリングされる三角形のリストを表します。
複数のマテリアルがあるレンダラーでメッシュを使用する場合、マテリアルごとに1つのサブメッシュが必要です。
境界エラーを避けるために Vertices 配列を割り当てた後に、Triangles の配列を代入することをお勧めします。
baseVertex 引数を使用すると、16ビットのインデックスバッファで、頂点数が 65535 より大きいメッシュを実現できます。
ただし、各サブメッシュが独自の 65535 頂点数の領域内に収まる必要があります。
例えば、SetTriangles に渡されるインデックスバッファに 10,11,12 を設定し、baseVertex を 100000 に設定した場合。
レンダリングには頂点インデックスの 100010, 100011, 100012 が使用されます。
メッシュはデフォルトで16ビットの indexFormat を使用することに注意してください。
つまり、インデックスバッファでサポートされる最大値は 65535 です。
より大きなインデックスバッファを使用するには、最初に indexFormat を IndexFormat.UInt32 に設定する必要があります。
public void SetTriangles (int[] triangles, int trianglesStart, int trianglesLength, int submesh, bool calculateBounds, int baseVertex);
public void SetTriangles (List triangles, int trianglesStart, int trianglesLength, int submesh, bool calculateBounds, int baseVertex);
public void SetTriangles (ushort[] triangles, int trianglesStart, int trianglesLength, int submesh, bool calculateBounds, int baseVertex);
public void SetTriangles (List triangles, int trianglesStart, int trianglesLength, int submesh, bool calculateBounds, int baseVertex);
引数 | 説明 |
---|---|
triangles | 三角形を定義するインデックスのリスト |
trianglesStart | 入力配列から取得する最初の要素のインデックス |
trianglesLength | 入力配列から取得する要素の数 |
submesh | 変更するサブメッシュ |
calculateBounds | 三角形を設定した後、メッシュの境界ボックスを計算するか否か 既存の境界ボックスを使用して三角形を設定するCPUコストを削減する場合は false を使用する |
baseVertex | 全ての三角形の頂点インデックスに追加されるオプションの頂点オフセット |
入力配列の一部を使用して、メッシュの三角形のリストを設定します。
このメソッドは入力配列の一部を使用して SetTriangles を呼び出したかのように動作します。
指定の trianglesStart インデックスから始まり、指定された trianglesLength 長が取得されます。
結果のメッシュには trianglesLength 数の頂点があり、trianglesLength/3 数の三角形があります。
SetIndices
public void SetIndices (int[] indices, MeshTopology topology, int submesh, bool calculateBounds= true, int baseVertex= 0);
public void SetIndices (List indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (ushort[] indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (List indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (NativeArray indices, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
引数 | 説明 |
---|---|
indices | 三角形を定義するインデックスのリスト |
topology | メッシュのトポロジ(例:三角形、線、四角形、点など) |
submesh | 変更するサブメッシュ |
calculateBounds | 三角形を設定した後、メッシュの境界ボックスを計算するか否か 既存の境界ボックスを使用して三角形を設定するCPUコストを削減する場合は false を使用する |
baseVertex | 全ての三角形の頂点インデックスに追加されるオプションの頂点オフセット |
サブメッシュのインデックスバッファを設定します。
サブメッシュは単一の Material を使用してレンダリングされる三角形(または MeshTopology が異なるインデックス)のリストを表します。
複数のマテリアルがあるレンダラーでメッシュを使用する場合、マテリアルごとに1つのサブメッシュが必要です。
SetTriangles と triangles は、常にメッシュを三角形の面で構成されるように設定します。
SetIndices を使用することで、線または点で構成されるメッシュを作成することができます。
baseVertex 引数を使用すると、16ビットのインデックスバッファで、頂点数が 65535 より大きいメッシュを実現できます。
ただし、各サブメッシュが独自の 65535 頂点数の領域内に収まる必要があります。
例えば、SetTriangles に渡されるインデックスバッファに 10,11,12 を設定し、baseVertex を 100000 に設定した場合。
レンダリングには頂点インデックスの 100010, 100011, 100012 が使用されます。
メッシュはデフォルトで16ビットの indexFormat を使用することに注意してください。
つまり、インデックスバッファでサポートされる最大値は 65535 です。
より大きなインデックスバッファを使用するには、最初に indexFormat を IndexFormat.UInt32 に設定する必要があります。
public void SetIndices (int[] indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (List indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (ushort[] indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (List indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
public void SetIndices (NativeArray indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds, int baseVertex);
引数 | 説明 |
---|---|
indices | 三角形を定義するインデックスのリスト |
indicesStart | 入力配列から取得する最初の要素のインデックス |
indicesLength | 入力配列から取得する要素の数 |
topology | メッシュのトポロジ(例:三角形、線、四角形、点など) |
submesh | 変更するサブメッシュ |
calculateBounds | 三角形を設定した後、メッシュの境界ボックスを計算するか否か 既存の境界ボックスを使用して三角形を設定するCPUコストを削減する場合は false を使用する |
baseVertex | 全ての三角形の頂点インデックスに追加されるオプションの頂点オフセット |
入力配列の一部を使用して、サブメッシュのインデックスバッファを設定します。
このメソッドは入力配列の一部を使用して SetIndices を呼び出したかのように動作します。
指定の indicesStart インデックスから始まり、指定された indicesLength 長が取得されます。
結果のメッシュには indicesLength 数の頂点があります。
SetColors
public void SetColors (Color32[] inColors);
public void SetColors (Color[] inColors);
public void SetColors (List inColors);
public void SetColors (List inColors);
public void SetColors (NativeArray inColors);
引数 | 説明 |
---|---|
inColors | 頂点ごとの色 |
メッシュの頂点ごとの色を設定します。
Unityは内部的に指定したデータに一致する形式でメッシュデータを保存します。
例えば、Color32 配列を渡すと、Unityは各色を4バイト(低精度、0..1の範囲)で保存します。
一方、Color 配列を渡すと、Unity は各色を 16 バイトで格納します(カラーチャネルごとに完全な32bit float)。
public void SetColors (Color32[] inColors, int start, int length);
public void SetColors (Color[] inColors, int start, int length);
public void SetColors (List inColors, int start, int length);
public void SetColors (List inColors, int start, int length);
public void SetColors (NativeArray inColors, int start, int length);
引数 | 説明 |
---|---|
inColors | 頂点ごとの色 |
start | 入力配列から取得する最初の要素のインデックス |
lengh | 入力配列から取得する要素の数 |
入力配列の一部を使用して、メッシュの頂点ごとの色を設定します。
このメソッドは入力配列の一部を使用して SetColors を呼び出したかのように動作します。
指定の start インデックスから始まり、指定された length 長が取得されます。
結果のメッシュには length 数の頂点があります。