Mesh

Struct Mesh 

Source
pub struct Mesh {
Show 36 fields pub m_BindPose: Vec<Matrix4x4f>, pub m_CompressedMesh: CompressedMesh, pub m_IndexBuffer: Vec<u8>, pub m_LocalAABB: AABB, pub m_MeshCompression: u8, pub m_MeshUsageFlags: i32, pub m_Name: String, pub m_SubMeshes: Vec<SubMesh>, pub m_BakedConvexCollisionMesh: Option<Vec<u8>>, pub m_BakedTriangleCollisionMesh: Option<Vec<u8>>, pub m_BoneNameHashes: Option<Vec<u32>>, pub m_BonesAABB: Option<Vec<MinMaxAABB>>, pub m_CollisionTriangles: Option<Vec<u32>>, pub m_CollisionVertexCount: Option<i32>, pub m_Colors: Option<Vec<ColorRGBA>>, pub m_CookingOptions: Option<i32>, pub m_IndexFormat: Option<i32>, pub m_IsReadable: Option<bool>, pub m_KeepIndices: Option<bool>, pub m_KeepVertices: Option<bool>, pub m_MeshMetrics_0_: Option<f32>, pub m_MeshMetrics_1_: Option<f32>, pub m_Normals: Option<Vec<Vector3f>>, pub m_RootBoneNameHash: Option<u32>, pub m_ShapeVertices: Option<Vec<MeshBlendShapeVertex>>, pub m_Shapes: Option<Enum_Vec_MeshBlendShape___BlendShapeData>, pub m_Skin: Option<Vec<Enum_BoneInfluence__BoneWeights4>>, pub m_StreamCompression: Option<u8>, pub m_StreamData: Option<StreamingInfo>, pub m_Tangents: Option<Vec<Vector4f>>, pub m_UV: Option<Vec<Vector2f>>, pub m_UV1: Option<Vec<Vector2f>>, pub m_Use16BitIndices: Option<i32>, pub m_VariableBoneCountWeights: Option<VariableBoneCountWeights>, pub m_VertexData: Option<VertexData>, pub m_Vertices: Option<Vec<Vector3f>>,
}
Expand description

Mesh is a class of the Unity engine since version 3.4.0. Exert from Unity’s scripting documentation: A class that allows you to create or modify meshes. Meshes contain vertices and multiple triangle arrays.Conceptually, all vertex data is stored in separate arrays of the same size. For example, if you have

a mesh of 100 Vertices, and want to have a position, normal and two texture coordinates

for each vertex, then the mesh should have vertices, normals, uv and uv2

arrays, each being 100 in size. Data for i-th vertex is at index “i” in each array.For every vertex there can be a vertex position, normal, tangent, color and up to 8 texture coordinates.

Texture coordinates most often are 2D data (Vector2), but it is possible to make them

Vector3 or Vector4 if needed. This is most often used for holding arbitrary data in mesh

vertices, for special effects used in shaders. For skinned meshes, the vertex data can also

contain boneWeights.The mesh face data, i.e. the triangles it is made of, is simply three vertex indices for each triangle.

For example, if the mesh has 10 triangles, then the triangles array should be 30 numbers,

with each number indicating which vertex to use. The first three elements in the triangles array are

the indices for the vertices that make up that triangle; the second three elements make up

another triangle and so on.Note that while triangle meshes are the most common use case, Unity also supports other

mesh topology types, for example Line or Point meshes. For line meshes, each line

is composed of two vertex indices and so on. See SetIndices and MeshTopology. Simple vs Advanced Mesh APIThe Mesh class has two sets of methods for assigning data to a Mesh from script. The “simple” set of methods provide a basis for setting the indices, triangle, normals, tangents, etc. These methods include validation checks, for example to ensure that you are not passing in data that would include out-of-bounds indices. They represent the standard way to assign Mesh data from script in Unity.The “simple” methods are: SetColors, SetIndices, SetNormals, SetTangents, SetTriangles, SetUVs, SetVertices, SetBoneWeights.There is also an “advanced” set of methods, which allow you to directly write to the mesh data with control over whether any checks or validation should be performed. These methods are intended for advanced use cases which require maximum performance. They are faster, but allow you to skip the checks on the data you supply. If you use these methods you must make sure that you are not supplying invalid data, because Unity will not check for you.The “advanced” methods are: SetVertexBufferParams, SetVertexBufferData, SetIndexBufferParams, SetIndexBufferData, SetSubMesh, and you can use the MeshUpdateFlags to control which checks or validation are performed or omitted. Use AcquireReadOnlyMeshData to take a read-only snapshot of Mesh data that you can use with C# Jobs and Burst, and AllocateWritableMeshData with ApplyAndDisposeWritableMeshData to create Meshes from C# Jobs and Burst.Manipulating meshes from a scriptThere are three common tasks that might want to use the Mesh API for:1. Building a mesh from scratch:

should always be done in the following order:

a) Assign vertices

b) Assign triangles. 2. Modifying vertex attributes every frame:

a) Get vertices

b) Modify them

c) Assign them back to the mesh. 3. Continously changing the mesh triangles and vertices:

a) Call Clear to start fresh

b) Assign vertices and other attributes

c) 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.

Fields§

§m_BindPose: Vec<Matrix4x4f>§m_CompressedMesh: CompressedMesh§m_IndexBuffer: Vec<u8>§m_LocalAABB: AABB§m_MeshCompression: u8§m_MeshUsageFlags: i32§m_Name: String

The name of the object.

§m_SubMeshes: Vec<SubMesh>§m_BakedConvexCollisionMesh: Option<Vec<u8>>

Vec: (5.0.0f4 - 2022.3.2f1)

§m_BakedTriangleCollisionMesh: Option<Vec<u8>>

Vec: (5.0.0f4 - 2022.3.2f1)

§m_BoneNameHashes: Option<Vec<u32>>

Vec: (4.3.0 - 2022.3.2f1)

§m_BonesAABB: Option<Vec<MinMaxAABB>>

Vec: (2019.1.0b1 - 2022.3.2f1)

§m_CollisionTriangles: Option<Vec<u32>>

Vec: (3.4.0 - 3.4.2)

§m_CollisionVertexCount: Option<i32>

i32: (3.4.0 - 3.4.2)

§m_Colors: Option<Vec<ColorRGBA>>

Vertex colors of the Mesh. Vec: (3.4.0 - 3.4.2)

§m_CookingOptions: Option<i32>

i32: (2022.1.0b1 - 2022.3.2f1)

§m_IndexFormat: Option<i32>

Format of the mesh index buffer data. i32: (2017.3.0b1 - 2022.3.2f1)

§m_IsReadable: Option<bool>

Returns true if the Mesh is read/write enabled, or false if it is not. bool: (4.0.0 - 2022.3.2f1)

§m_KeepIndices: Option<bool>

bool: (4.0.0 - 2022.3.2f1)

§m_KeepVertices: Option<bool>

bool: (4.0.0 - 2022.3.2f1)

§m_MeshMetrics_0_: Option<f32>

f32: (2022.3.2f1 - 2022.3.2f1)

§m_MeshMetrics_1_: Option<f32>

f32: (2022.3.2f1 - 2022.3.2f1)

§m_Normals: Option<Vec<Vector3f>>

The normals of the Mesh. Vec: (3.4.0 - 3.4.2)

§m_RootBoneNameHash: Option<u32>

u32: (4.3.0 - 2022.3.2f1)

§m_ShapeVertices: Option<Vec<MeshBlendShapeVertex>>

Vec: (4.1.0 - 4.2.2)

§m_Shapes: Option<Enum_Vec_MeshBlendShape___BlendShapeData>

Vec: (4.1.0 - 4.2.2); BlendShapeData: (4.3.0 - 2022.3.2f1)

§m_Skin: Option<Vec<Enum_BoneInfluence__BoneWeights4>>

Vec: (3.4.0 - 5.6.7f1); Vec: (2017.1.0b1 - 2018.1.9f2)

§m_StreamCompression: Option<u8>

u8: (4.0.0 - 4.7.2)

§m_StreamData: Option<StreamingInfo>

StreamingInfo: (2018.3.0f2 - 2022.3.2f1)

§m_Tangents: Option<Vec<Vector4f>>

The tangents of the Mesh. Vec: (3.4.0 - 3.4.2)

§m_UV: Option<Vec<Vector2f>>

The texture coordinates (UVs) in the first channel. Vec: (3.4.0 - 3.4.2)

§m_UV1: Option<Vec<Vector2f>>

Vec: (3.4.0 - 3.4.2)

§m_Use16BitIndices: Option<i32>

i32: (3.4.0 - 3.4.2)

§m_VariableBoneCountWeights: Option<VariableBoneCountWeights>

VariableBoneCountWeights: (2019.1.0b1 - 2022.3.2f1)

§m_VertexData: Option<VertexData>

VertexData: (3.5.0 - 2022.3.2f1)

§m_Vertices: Option<Vec<Vector3f>>

Returns a copy of the vertex positions or assigns a new vertex positions array. Vec: (3.4.0 - 3.4.2)

Trait Implementations§

Source§

impl Debug for Mesh

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Mesh

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Mesh

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Mesh

§

impl RefUnwindSafe for Mesh

§

impl Send for Mesh

§

impl Sync for Mesh

§

impl Unpin for Mesh

§

impl UnwindSafe for Mesh

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,