Version: 2019.4
Anatomía de una Malla (Mesh)
Example - Creating a quad

Utilizando la clase Mesh

The Mesh class is the basic script interface to an object’s mesh geometry. It uses arrays to represent the triangles, vertex positions, normals and texture coordinates and also supplies a number of other useful properties and functions to assist mesh generation.

Accediendo al mesh de un Objeto

The mesh data is attached to an object using the Mesh Filter component (and the object will also need a MeshRenderer to make the geometry visible). This component is accessed using the familiar GetComponent function:

using UnityEngine;
public class ExampleScript : MonoBehaviour
{
    MeshFilter mf;
    void Start()
    {
        //if this gameObject has a MeshFilter, mf will reference the component
        mf = GetComponent<MeshFilter>();    
    }
}

Agregando la información del Mesh

The Mesh object has properties for the vertices and their associated data (normals and UV coordinates) and also for the triangle data. The vertices may be supplied in any order but the arrays of normals and UVs must be ordered so that the indices all correspond with the vertices (ie, element 0 of the normals array supplies the normal for vertex 0, etc). The vertices are Vector3s representing points in the object’s local space. The normals are normalised Vector3s representing the directions, again in local coordinates. The UVs are specified as Vector2s, but since the Vector2 type doesn’t have fields called U and V, you must mentally convert them to X and Y respectively.

Los triángulos se especifican como triples de números enteros que actúan como índices en el arreglo del vértice. En vez de utilizar una clase especial para representar un triángulo, el arreglo es simplemente un lista simple de indices enteros. Estos son tomados en grupos de tres para cada triángulo, entonces los primeros tres elementos definen el primer triángulo, los siguientes tres definen el segundo triángulo, y así. Un detalle importante de los triángulos es el orden de las esquines de los vértices. Ellas deberían estar asignadas para que las esquinas vayan alrededor de la manija del reloj justo cuando usted mira abajo de la superficie externa visible del triángulo, aunque realmente no importa con qué esquina usted comience con.

Advanced Mesh API

The Mesh class also has a lower-level advanced API that enables you to work with raw mesh vertex and index buffer data. This is useful in situations that require maximum performance or the lowest amount of memory allocations.

Véase también


  • 2019–08–14 Page amended
Anatomía de una Malla (Mesh)
Example - Creating a quad
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961