Mesh.RecalculateNormals 重新计算法线

function RecalculateNormals () : void

Description描述

Recalculates the normals of the mesh from the triangles and vertices.

重新计算网格的法线

After modifying the vertices it is often useful to update the normals to reflect the change. Normals are calculated from all shared vertices. Imported meshes sometimes don't share all vertices. For example a vertex at a uv seam will be split into two vertices. Thus the RecalculateNormals function will create normals that are not smooth at the uv seam. Also note that RecalculateNormals does not generate tangents automatically thus bumpmap shaders will not work with the mesh after calling RecalculateNormals. You can provide your own tangents however.

在修改完顶点后,通常会更新法线来反映新的变化。法线是根据共享的顶点计算出来的。导入到网格有时不共享所有的顶点。例如:一个顶点在一个纹理坐标的接缝处将会被分成两个顶点。因此这个RecalculateNormals函数将会在纹理坐标接缝处创建一个不光滑的法线。RecalculateNormals不会自动产生切线,因此bumpmap着色器在调用RecalculateNormals之后不会工作。然而你可以提取你自己的切线。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		mesh.RecalculateNormals();
	}
}
function Start () {
	var mesh : Mesh = GetComponent(MeshFilter).mesh;
	mesh.RecalculateNormals();
}
最后修改:2010年12月9日 Thursday 19:09

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。