blendShapeIndex | 要查找其数据的混合形状。 |
BlendShapeBufferRange 一个描述给定混合形状的数据的开始和结束索引的结构。
获取给定混合形状的混合形状顶点数据的位置。
当您用 Mesh.GetBlendShapeBuffer 调用 BlendShapeBufferLayout.PerShape 时,Unity 会返回一个 GraphicsBuffer,其中包含混合形状顶点数据,按混合形状排序。
当您调用此函数时,Unity 会为给定的混合形状返回 BlendShapeBufferRange。使用该范围可以在 GraphicsBuffer
中找到该混合形状的数据。
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(); } }
其他资源:UnityEngine.BlendShapeBufferRange、Mesh.GetBlendShapeBuffer、BlendShapeBufferLayout.PerShape