MeshFilter.mesh 网格

var mesh : Mesh

Description描述

Returns the instantiated Mesh assigned to the mesh filter.
返回赋予网格过滤器的实例化的Mesh。

If no mesh is assigned to the mesh filter a new mesh will be created and assigned.
If the mesh assigned to the mesh filter is shared, it will be automatically duplicated and the instantiated mesh will be returned.

如果没有网格被赋予网格过滤器,一个新的网格将会被创建并且被指定。如果赋予网格过滤器的网格被共享,它将被自动赋值并且示例化的网格将会被返回。

By using mesh property you can modify the mesh for a single object only. The other objects that used the same mesh will not be modified.

通过使用网格属性,您只能修改单个物体中的网格。其它使用相同网格的物体不会被修改。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Update() {
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		Vector3[] vertices = mesh.vertices;
		int p = 0;
		while (p < vertices.Length) {
			vertices[p] += new Vector3(0, Random.Range(-0.3F, 0.3F), 0);
			p++;
		}
		mesh.vertices = vertices;
		mesh.RecalculateNormals();
	}
}
function Update () {
	// Get instantiated mesh
	// 获取示例化的网格
	var mesh : Mesh = GetComponent(MeshFilter).mesh;
	// Randomly change vertices
	// 随机改变顶点
	var vertices : Vector3[] = mesh.vertices;
	for (var p : int = 0; p < vertices.Length; p++) {
		vertices[p] += Vector3(0, Random.Range(-0.3, 0.3), 0);
	}
	mesh.vertices = vertices;
	mesh.RecalculateNormals();
}

参考: Mesh

Page last updated: 2010-12-12