Version: 5.3 (switch to 5.4b)
ЯзыкEnglish
  • C#
  • JS

Язык программирования

Выберите подходящий для вас язык программирования. Все примеры кода будут представлены на выбранном языке.

Mesh

class in UnityEngine

/

Наследует от:Object

Предложить изменения

Успех!

Благодарим вас за то, что вы помогаете нам улучшить качество документации по Unity. Однако, мы не можем принять любой перевод. Мы проверяем каждый предложенный вами вариант перевода и принимаем его только если он соответствует оригиналу.

Закрыть

Ошибка внесения изменений

По определённым причинам предложенный вами перевод не может быть принят. Пожалуйста <a>попробуйте снова</a> через пару минут. И выражаем вам свою благодарность за то, что вы уделяете время, чтобы улучшить документацию по Unity.

Закрыть

Отменить

Руководство

Описание

A class that allows creating or modifying meshes from scripts.

Meshes contain vertices and multiple triangle arrays. See the Procedural example project for examples of using the mesh interface.

The triangle arrays are simply indices into the vertex arrays; three indices for each triangle.

For every vertex there can be a normal, two texture coordinates, color and tangent. These are optional though and can be removed at will. All vertex information is stored in separate arrays of the same size, so if your mesh has 10 vertices, you would also have 10-size arrays for normals and other attributes.

There are probably 3 things you might want to use the modifyable mesh interface for:

1. Building a mesh from scratch: всегда должно идти в следующем порядке: 1) присвоение vertices 2) присвоение triangles.

var newVertices : Vector3[];
var newUV : Vector2[];
var newTriangles : int[];

function Start () { var mesh : Mesh = new Mesh (); GetComponent.<MeshFilter>().mesh = mesh; mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Vector3[] newVertices; public Vector2[] newUV; public int[] newTriangles; void Start() { Mesh mesh = new Mesh(); GetComponent<MeshFilter>().mesh = mesh; mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; } }

2. Modifying vertex attributes every frame: 1) get vertices, 2) modify them, 3) assign them back to the mesh.

function Update () {
	var mesh : Mesh = GetComponent.<MeshFilter>().mesh;
	var vertices : Vector3[] = mesh.vertices;
	var normals : Vector3[] = mesh.normals;

for (var i = 0; i < vertices.Length; i++) vertices[i] += normals[i] * Mathf.Sin(Time.time);

mesh.vertices = vertices; }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void Update() { Mesh mesh = GetComponent<MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; Vector3[] normals = mesh.normals; int i = 0; while (i < vertices.Length) { vertices[i] += normals[i] * Mathf.Sin(Time.time); i++; } mesh.vertices = vertices; } }

3. Continously changing the mesh triangles and vertices: 1) call Clear to start fresh, 2) assign vertices and other attributes, 3) assign triangle indices.

It is important to call Clear before assigning new vertices or triangles. Unity always checks the supplied triangle indices whether they don't reference out of bounds vertices. Calling Clear then assigning vertices then triangles makes sure you never have out of bounds data.

var newVertices : Vector3[];
var newUV : Vector2[];
var newTriangles : int[];

function Update () { var mesh : Mesh = GetComponent.<MeshFilter>().mesh;

mesh.Clear(); // Do some calculations... mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Vector3[] newVertices; public Vector2[] newUV; public int[] newTriangles; void Update() { Mesh mesh = GetComponent<MeshFilter>().mesh; mesh.Clear(); mesh.vertices = newVertices; mesh.uv = newUV; mesh.triangles = newTriangles; } }

Переменные

bindposesThe bind poses. The bind pose at each index refers to the bone with the same index.
blendShapeCountReturns BlendShape count on this mesh.
boneWeightsThe bone weights of each vertex.
boundsThe bounding volume of the mesh.
colorsVertex colors of the mesh.
colors32Vertex colors of the mesh.
isReadableReturns state of the Read/Write Enabled checkbox when model was imported.
normalsThe normals of the mesh.
subMeshCountThe number of submeshes. Every material has a separate triangle list.
tangentsThe tangents of the mesh.
trianglesAn array containing all triangles in the mesh.
uvThe base texture coordinates of the mesh.
uv2The second texture coordinate set of the mesh, if present.
uv3The third texture coordinate set of the mesh, if present.
uv4The fourth texture coordinate set of the mesh, if present.
vertexCountReturns the number of vertices in the mesh (Read Only).
verticesReturns a copy of the vertex positions or assigns a new vertex positions array.

Конструкторы

MeshCreates an empty mesh.

Открытые функции

AddBlendShapeFrameAdds a new blend shape frame.
ClearОчищает все данные о вершинах и треугольниках меша.
ClearBlendShapesClears all blend shapes from Mesh.
CombineMeshesCombines several meshes into this mesh.
GetBlendShapeFrameCountReturns the frame count for a blend shape.
GetBlendShapeFrameVerticesRetreives deltaVertices, deltaNormals and deltaTangents of a blend shape frame.
GetBlendShapeFrameWeightReturns the weight of a blend shape frame.
GetBlendShapeIndexReturns index of BlendShape by given name.
GetBlendShapeNameReturns name of BlendShape by given index.
GetIndicesReturns the index buffer for the submesh.
GetTopologyGets the topology of a submesh.
GetTrianglesReturns the triangle list for the submesh.
GetUVsGet the UVs for a given chanel.
MarkDynamicOptimize mesh for frequent updates.
OptimizeOptimizes the mesh for display.
RecalculateBoundsRecalculate the bounding volume of the mesh from the vertices.
RecalculateNormalsRecalculates the normals of the mesh from the triangles and vertices.
SetColorsVertex colors of the mesh.
SetIndicesSets the index buffer for the submesh.
SetNormalsSet the normals of the mesh.
SetTangentsSet the tangents of the mesh.
SetTrianglesSets the triangle list for the submesh.
SetUVsSet the UVs for a given chanel.
SetVerticesAssigns a new vertex positions array.
UploadMeshDataUpload previously done mesh modifications to the graphics API.

Унаследованные члены

Переменные

hideFlagsShould the object be hidden, saved with the scene or modifiable by the user?
nameThe name of the object.

Открытые функции

GetInstanceIDReturns the instance id of the object.
ToStringReturns the name of the game object.

Статические функции

DestroyRemoves a gameobject, component or asset.
DestroyImmediateDestroys the object obj immediately. You are strongly recommended to use Destroy instead.
DontDestroyOnLoadMakes the object target not be destroyed automatically when loading a new scene.
FindObjectOfTypeReturns the first active loaded object of Type type.
FindObjectsOfTypeReturns a list of all active loaded objects of Type type.
InstantiateReturns a copy of the object original.

Операторы

boolDoes the object exist?
operator !=Compares if two objects refer to a different object.
operator ==Compares two object references to see if they refer to the same object.