Mesh.bounds 包围体

var bounds : Bounds

Description描述

The bounding volume of the mesh.

网格的包围体。

This is the axis-aligned bounding box of the mesh in its local space (that is, not affected by the transform). See also Renderer.bounds property that returns bounds in world space.

这是在网格局部坐标空间中轴对齐的边界框 (不会受到转换的影响)。参考世界空间中Renderer.bounds属性。

另见: Bounds 类, Renderer.bounds 属性.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void Start() {
		Mesh mesh = GetComponent<MeshFilter>().mesh;
		Vector3[] vertices = mesh.vertices;
		Vector2[] uvs = new Vector2[vertices.Length];
		Bounds bounds = mesh.bounds;
		int i = 0;
		while (i < uvs.Length) {
			uvs[i] = new Vector2(vertices[i].x / bounds.size.x, vertices[i].z / bounds.size.x);
			i++;
		}
		mesh.uv = uvs;
	}
}
// Generates planar UV coordinates independent of mesh size
// 形成一个与网格尺寸无关的平面纹理坐标
// by scaling vertices by the bounding box size
// 通过缩放边界框尺寸的顶点

function Start () {
	var mesh : Mesh = GetComponentMeshFilter.mesh;
	var vertices : Vector3[] = mesh.vertices;
	var uvs : Vector2[] = new Vector2[vertices.Length];
	var bounds : Bounds = mesh.bounds;

	for (var i = 0; i < uvs.Length; i++)
		uvs[i] = Vector2 (vertices[i].x / bounds.size.x,vertices[i].z / bounds.size.x);
	mesh.uv = uvs;
}
最后修改:2010年12月9日 Thursday 16:54

本脚本参考基于Unity 3.4.1f5

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