Unity - Scripting API: Mesh.GetBlendShapeBufferRange
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Parameters
| Parameter | Description |
|---|---|
| blendShapeIndex | Which blend shape to locate the data for. |
Returns
BlendShapeBufferRange A struct that describes the start and end index of the data for the given blend shape.
Description
Get the location of blend shape vertex data for a given blend shape.
using UnityEngine; using UnityEngine.Rendering;public class Example : MonoBehaviour { public Mesh mesh; public ComputeShader computeShader;
void Start() { // Fetch GraphicsBuffer with Blend Shape data, ordered per shape, from the mesh var perShapeBuffer = mesh.GetBlendShapeBuffer(BlendShapeBufferLayout.PerShape);
// Iterate over all Blend Shapes in a mesh for(int blendShapeIndex = 0; blendShapeIndex < mesh.blendShapeCount; ++blendShapeIndex) { // Fetch which indices in the buffer that are part of this Blend Shape var blendShapeRange = mesh.GetBlendShapeBufferRange(blendShapeIndex);
// Set the start and end indices of the Blend Shape in the compute shader computeShader.SetInt("_StartIndex", (int)blendShapeRange.startIndex); computeShader.SetInt("_EndIndex", (int)blendShapeRange.endIndex);
// Dispatch compute shader and access data between start and end index for this Blend Shape computeShader.Dispatch(0, 64, 1, 1); }
// Dispose of GraphicsBuffer to avoid leak memory perShapeBuffer.Dispose(); } }