返回介绍

Mesh.vertices 顶点

发布于 2019-12-18 15:38:02 字数 1949 浏览 1159 评论 0 收藏 0

JavaScript => public var vertices: Vector3[];
C# => public Vector3[] vertices;

Description 描述

Returns a copy of the vertex positions or assigns a new vertex positions array.

返回顶点位置的拷贝或指定新顶点位置的数组。

The number of vertices in the mesh is changed by assigning a vertex array with a different number of vertices. Note that if you resize the vertex array then all other vertex attributes (normals, colors, tangents, UVs) will be automatically resized too. RecalculateBounds will automatically be invoked if no vertices have been assigned to the mesh when setting the vertices.

网格中顶点数量是通过赋予一个不同数量的顶点数组来改变。注意,如果你调整了顶点数组的大小,那么所有其他顶点的属性(法线,颜色,切线,纹理坐标)将自动地调节大小。在为顶点赋值时,如果这个网格的顶点有没有被赋值的那么RecalculateBounds将自动被调用。

JavaScript:

	function Update () {
		var mesh : Mesh = GetComponent.<MeshFilter>().mesh;
		var vertices : Vector3[] = mesh.vertices;
 
		for (var i = 0; i < vertices.Length; i++)
			vertices[i] += Vector3.up * Time.deltaTime;
 
		mesh.vertices = vertices;
		mesh.RecalculateBounds();
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    void Update() {
        Mesh mesh = GetComponent<MeshFilter>().mesh;
        Vector3[] vertices = mesh.vertices;
        int i = 0;
        while (i < vertices.Length) {
            vertices[i] += Vector3.up * Time.deltaTime;
            i++;
        }
        mesh.vertices = vertices;
        mesh.RecalculateBounds();
    }
}

Mesh

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文