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 'bindposeCount' property gives the count of bind poses, which are transformations determining how Meshes move with joints, in a Mesh object. Unity's Mesh.bindposeCount 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. Unity's Mesh.blendShapeCount Documentation
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. Unity's Mesh.bounds 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. Unity's Mesh.isReadable 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. Unity's Mesh.subMeshCount Documentation
The 'vertexAttributeCount' property gives the count of vertex attributes like positions, normals, tangents, colors, and texture coordinates in the Mesh. Unity's Mesh.vertexAttributeCount Documentation
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. Unity's Mesh.vertexBufferCount 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. Unity's Mesh.vertexCount Documentation
Methods
The '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. Unity's Mesh.Clear Documentation
Returns
The '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. Unity's Mesh.Clear Documentation
Parameters
keepVertexLayout
Specifies whether to keep original layout of the vertex buffer.
Returns
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. Unity's Mesh.ClearBlendShapes Documentation
Returns
'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
Parameters
submesh
The index of the submesh to get the base vertex of.
Returns
The base vertex of the specified submesh.
'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. Unity's Mesh.GetBlendShapeFrameCount Documentation
Parameters
shapeIndex
The index of the blend shape to retrieve the frame count from.
Returns
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. Unity's Mesh.GetBlendShapeFrameWeight Documentation
Parameters
shapeIndex
The index of the blend shape to retrieve the weight from.
frameIndex
The index of the frame to retrieve the weight from.
Returns
The weight of the frame in 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
Parameters
blendShapeName
The name of the blend shape to get the index of.
Returns
The index of the blend shape.
'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. Unity's Mesh.GetBlendShapeName Documentation
Parameters
shapeIndex
The index of the blend shape to get the name of.
Returns
The name of the blend shape.
'GetIndexCount' gets the total number of indices in a specific submesh. This information can be helpful when altering the geometry of submeshes. Unity's Mesh.GetIndexCount Documentation
Parameters
submesh
The index of the submesh to get the index count of.
Returns
The number of indices in the given submesh.
'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. Unity's Mesh.GetIndexStart Documentation
Parameters
submesh
The index of the submesh to get the start index of.
Returns
The start index for the specified submesh.
Parameters
submesh
Returns
Parameters
submesh
applyBaseVertex
Returns
Parameters
submesh
Returns
Parameters
submesh
applyBaseVertex
Returns
'GetUVDistributionMetric' is a method that provides a UV metric for the Mesh, which is a key consideration for texture mapping and related operations. Unity's Mesh.GetUVDistributionMetric Documentation
Parameters
uvSetIndex
The index of the UV set whose distribution metric should be retrieved.
Returns
The UV distribution metric for the specified UV set.
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
The index of the vertex buffer we are querying.
Returns
The size of one vertex in bytes.
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. Unity's Mesh.MarkDynamic Documentation
Returns
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. Unity's Mesh.MarkModified Documentation
Returns
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. Unity's Mesh.Optimize Documentation
Returns
'OptimizeIndexBuffers' optimizes the index buffers of the Mesh. This reduces the size of the index buffer and speeds up rendering. Unity's Mesh.OptimizeIndexBuffers Documentation
Returns
The 'OptimizeReorderVertexBuffer' method optimizes the vertex buffer of the Mesh. This improves memory usage and rendering performance. Unity's Mesh.OptimizeReorderVertexBuffer Documentation
Returns
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. Unity's Mesh.RecalculateBounds Documentation
Returns
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. Unity's Mesh.RecalculateNormals Documentation
Returns
'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. Unity's Mesh.RecalculateTangents Documentation
Returns
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. Unity's Mesh.RecalculateUVDistributionMetric Documentation
Parameters
uvSetIndex
The index of the UV set to recalculate the distribution metric for.
uvAreaThreshold
The area threshold to consider in the UV recalculations.
Returns
The 'RecalculateUVDistributionMetrics' method recalculates UV distribution metrics. It improves texture quality by reducing distortions in the mapping from texture space to 3D. Unity's Mesh.RecalculateUVDistributionMetrics Documentation
Parameters
uvAreaThreshold
A threshold that defines what should be considered in the UV recalculations.
Returns
'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. Unity's Mesh.UploadMeshData Documentation
Parameters
markNoLongerReadable
Whether to mark the data as not readable by scripts after the upload.
Returns
Updated 9 days ago