Version: 2022.1
言語: 日本語
public void Clear (bool keepVertexLayout= true);

パラメーター

keepVertexLayout True if the existing Mesh data layout should be preserved.

説明

すべての頂点データと三角形のインデックスを削除します

triangles の配列を再ビルドする前にこの関数を呼び出す必要があります。

// Convert any GameObject into a single triangle

using UnityEngine;

public class meshClear : MonoBehaviour { private bool once = false;

void Update() { if (Time.time > 2.0f) { convertMesh(); } }

void convertMesh() { if (once) return;

Mesh mesh = GetComponent<MeshFilter>().mesh;

// Clears all the data that the mesh currently has mesh.Clear();

// create 3 vertices for the triangle mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(1, 1, 0)}; mesh.uv = new Vector2[] {new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 1)}; mesh.triangles = new int[] {0, 1, 2};

once = true; } }

この関数のデフォルトの動作はすでにある頂点レイアウトを保持します。 メッシュが接ベクトルと頂点カラーを持っていた場合、たとえば、 新しい頂点データに入力すると接線と色はメッシュデータの一部になります。 完全にメッシュを消去し、空の頂点レイアウトで開始したい場合は keepVertexLayout パラメーターに False を渡します。 また、メッシュコンポーネントに空の配列を割り当てると頂点レイアウトからも削除されます。