Mesh
Inherits from: Object
In the realm of Unity 3D game development, the 'Mesh' class is a fundamentally important tool. It's like the nuts and bolts enabling the creation and modification of graphical meshes - the fundamental building blocks of 3D modeling. The Mesh class is what shapes the tangible elements of your game, giving form to everything from the detailed terrain of a sprawling landscape, to the intricate contours of characters and objects.
The distinguishing feature of the 'Mesh' class is its proficient control over vertex transformations, empowering developers to fine-tune the look and feel of their 3D models down to the minutest detail. Whether you're crafting the subtle curve of a racing car, the rough crags of a mountain range, or the smooth surface of a futuristic gadget, the Mesh class is the instrument of such creation.
For a comprehensive understanding of the 'Mesh' class, the official Unity Mesh Documentation expands on how this essential tool is crucial in creating immersive and visually rewarding 3D game environments.
Properties
The 'vertexBufferCount' property holds the count of vertex buffers, which are containers for all vertex related data like positions, normals, UVs etc, in a Mesh object. More details about it are in Unity's Mesh.vertexBufferCount Documentation.
The 'blendShapeCount' property keeps track of the number of blend shapes found within a Mesh object. Blend shapes allow for smooth transitions between different facial expressions or body positions. Refer to Unity's Mesh.blendShapeCount Documentation for more details.
The 'bindposeCount' property gives the count of bind poses, which are transformations determining how Meshes move with joints, in a Mesh object. To learn more about this property, check Unity's Mesh.bindposeCount Documentation.
The 'isReadable' property informs whether the Mesh data is available for reading by scripting. For instance, you may want this to be true if you're creating procedural Meshes. Learn how to use this property effectively in Unity's Mesh.isReadable Documentation.
The 'vertexCount' property allows you to retrieve the amount of vertices present in the Mesh object. It's helpful for debugging or when performing operations on every vertex. More info can be found in Unity's Mesh.vertexCount Documentation.
The 'subMeshCount' property provides the number of submeshes in a Mesh object. Submeshes can be useful when you want to apply different materials to different parts of a Mesh. Visit Unity's Mesh.subMeshCount Documentation for more about this property.
The 'bounds' property represents the axis-aligned bounding box of the Mesh in its local space (i.e., not affected by the transform). This can be useful for things like collision detection and visibility testing. Learn more from Unity's Mesh.bounds Documentation.
The 'vertexAttributeCount' property gives the count of vertex attributes like positions, normals, tangents, colors, and texture coordinates in the Mesh. To know more about these, see Unity's Mesh.vertexAttributeCount Documentation.
Methods
The 'GetVertexBufferStride' method retrieves the byte size of one vertex in a vertex buffer. Information like this can be useful for advanced manipulation of Graphics APIs. Learn more in Unity's Mesh.GetVertexBufferStride Documentation.
Parameters
stream
number
The index of the vertex buffer we are querying.
Returns
number
The size of one vertex in bytes.
The 'ClearBlendShapes' method deletes all blend shapes from the Mesh object. This might be useful in cases where you need to redefine the blend shapes on an existing Mesh object. Visit Unity's Mesh.ClearBlendShapes Documentation to learn more.
Returns
void
Returns nothing.
'GetBlendShapeName' is a method that retrieves the name of a blend shape based on its index. This could be useful when rearranging or altering blend shapes programmatically. Refer to Unity's Mesh.GetBlendShapeName Documentation for more info.
Parameters
shapeIndex
number
The index of the blend shape to get the name of.
Returns
string
The name of the blend shape.
'GetBlendShapeIndex' method fetches the index of a blend shape given its name. This is useful when you need to manipulate blend shapes but only know their names. Unity's Mesh.GetBlendShapeIndex Documentation provides more details.
Parameters
blendShapeName
string
The name of the blend shape to get the index of.
Returns
number
The index of the blend shape.
'GetBlendShapeFrameCount' retrieves the number of frames in a blend shape of a given index. BlendShape frames are points of transition in blend shape animation sequences. Learn how to use this method in Unity's Mesh.GetBlendShapeFrameCount Documentation.
Parameters
shapeIndex
number
The index of the blend shape to retrieve the frame count from.
Returns
number
The number of frames in the blend shape.
'GetBlendShapeFrameWeight' method returns the weight of a specific frame given the indices of blend shape and frame. BlendShape weights determine the influence of a BlendShape in the final outcome. Refer to Unity's Mesh.GetBlendShapeFrameWeight Documentation for more details.
Parameters
shapeIndex
number
The index of the blend shape to retrieve the weight from.
frameIndex
number
The index of the frame to retrieve the weight from.
Returns
number
The weight of the frame in the blend shape.
The 'MarkModified' method explicitly marks the Mesh as modified, which can be used to trigger certain updates. This is used mainly to optimize drawing by helping Unity understand what needs to be redrawn. Learn more about it in Unity's Mesh.MarkModified Documentation.
Returns
void
'GetUVDistributionMetric' is a method that provides a UV metric for the Mesh, which is a key consideration for texture mapping and related operations. Find out more in this Unity documentation.
Parameters
uvSetIndex
number
The index of the UV set whose distribution metric should be retrieved.
Returns
number
The UV distribution metric for the specified UV set.
'GetIndexStart' is a method that returns the start index of a specific submesh. This is useful when looping through individual submeshes in a Mesh object. More information is available in Unity's Mesh.GetIndexStart Documentation.
Parameters
submesh
number
The index of the submesh to get the start index of.
Returns
number
The start index for the specified submesh.
'GetIndexCount' gets the total number of indices in a specific submesh. This information can be helpful when altering the geometry of submeshes. See Unity's Mesh.GetIndexCount Documentation for additional insights.
Parameters
submesh
number
The index of the submesh to get the index count of.
Returns
number
The number of indices in the given submesh.
'GetBaseVertex' is a method that retrieves the base vertex of a specific submesh. This can be useful when you're manipulating vertices at a low level, for example, in some procedural generation algorithms. Unity's Mesh.GetBaseVertex Documentation provides more details.
Parameters
submesh
number
The index of the submesh to get the base vertex of.
Returns
number
The base vertex of the specified submesh.
'Clear' method removes all vertex and index data from the Mesh. It's useful for cleaning up Meshes or if you need to rebuild a Mesh from scratch. Learn how to use the Clear(keepVertexLayout) method effectively in Unity's Mesh.Clear Documentation.
Parameters
keepVertexLayout
boolean
Specifies whether to keep original layout of the vertex buffer.
Returns
void
The 'RecalculateBounds' method recalculates the bounding volume of the Mesh from the vertices. This is useful when modifications have been made to the vertex positions and the bounding volume needs to be updated. More can be found out in Unity's Mesh.RecalculateBounds Documentation.
Returns
void
The 'RecalculateNormals' method recomputes the normals of the Mesh from the vertices and triangles. This is useful when changes are made to vertex positions and the normals need to correspond to the new shape. Find more details in Unity's Mesh.RecalculateNormals Documentation.
Returns
void
'RecalculateTangents' is a method that recalculates the tangents of the Mesh, which are used in normal mapping and other techniques. It's most useful when changes have been made to the vertex positions or texture coordinates and the tangents need to be updated. More can be learned from Unity's Mesh.RecalculateTangents Documentation.
Returns
void
The 'RecalculateUVDistributionMetric' method recalculates the UV distribution metric for a specified UV set. This helps bring uniformity to the UV mapping which prevents texture distortion. Learn more in Unity's Mesh.RecalculateUVDistributionMetric Documentation.
Parameters
uvSetIndex
number
The index of the UV set to recalculate the distribution metric for.
uvAreaThreshold
number
The area threshold to consider in the UV recalculations.
Returns
void
The 'RecalculateUVDistributionMetrics' method recalculates UV distribution metrics. It improves texture quality by reducing distortions in the mapping from texture space to 3D. Learn about its usage in Unity's Mesh.RecalculateUVDistributionMetrics Documentation.
Parameters
uvAreaThreshold
number
A threshold that defines what should be considered in the UV recalculations.
Returns
void
The 'MarkDynamic' method marks the Mesh as dynamic, hinting the engine that this Mesh will be updated frequently. This speeds up certain operations but uses slightly more memory. To learn more, refer to Unity's Mesh.MarkDynamic Documentation.
Returns
void
'UploadMeshData' uploads Mesh data to the GPU, making it available for rendering. It's crucial when creating procedural Meshes that need to be drawn in the scene. To know more, see Unity's Mesh.UploadMeshData Documentation.
Parameters
markNoLongerReadable
boolean
Whether to mark the data as not readable by scripts after the upload.
Returns
void
The 'Optimize' method optimizes the Mesh for rendering according to its usage patterns. This includes operations like reordering vertices and triangles for better vertex cache utilization. Learn more from Unity's Mesh.Optimize Documentation.
Returns
void
'OptimizeIndexBuffers' optimizes the index buffers of the Mesh. This reduces the size of the index buffer and speeds up rendering. Visit Unity's Mesh.OptimizeIndexBuffers Documentation to learn more about this method.
Returns
void
The 'OptimizeReorderVertexBuffer' method optimizes the vertex buffer of the Mesh. This improves memory usage and rendering performance. More information on how this method operates can be found in Unity's Mesh.OptimizeReorderVertexBuffer Documentation.
Returns
void
Updated 6 months ago