Mesh.triangles 三角形

var triangles : int[]

Description描述

An array containing all triangles in the mesh.

在网格里,一个包含所有三角形的数组。

The array is a list of triangles that contains indices into the vertex array. The size of the triangle array must always be a multiple of 3. Vertices can be shared by simply indexing into the same vertex. If the mesh contains multiple sub meshes (materials) the triangle list will contain all triangles of all submeshes. When you assign triangle array, subMeshCount is set to 1. If you want to have multiple sub meshes, use subMeshCount and SetTriangles.

这个数组是包含顶点数组索引的三角形列表。三角形数组的大小是3的倍数。顶点可以通过简单的索引同一顶点来共享。如果网格包含多个子网格(材质),三角形列表将包含所有子网格的所有三角形。当你赋值三角形数组,subMeshCount设置为1。如果你想要有多个子网格,使用subMeshCount and SetTriangles。

It is recommended to assign a the triangle array after assigning the vertex array in order to avoid out of bounds errors.

建议先赋值顶点数组之后再赋值三角形数组,为了避免越界的错误。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		gameObject.AddComponent("MeshFilter");
		gameObject.AddComponent("MeshRenderer");
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		mesh.Clear();
		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};
	}
}
// Builds a mesh containing a single triangle with uv's.
// 构建一个只包含单个三角形及纹理坐标的网格。
function Start () {
	gameObject.AddComponent("MeshFilter");
	gameObject.AddComponent("MeshRenderer");
	var mesh : Mesh = GetComponent(MeshFilter).mesh;

	mesh.Clear();
	mesh.vertices = [Vector3(0,0,0), Vector3(0,1,0), Vector3(1, 1, 0)];
	mesh.uv = [Vector2 (0, 0), Vector2 (0, 1), Vector2 (1, 1)];
	mesh.triangles = [0, 1, 2];
}
Page last updated: 2010-12-9