Hey, I’m struggling to understand how to use the SkinnedMeshRenderer API to append its vertices and indices onto the corresponding buffers. I do not understand how to use the information from this page with my C# script to use the buffer in my compute shader. How do I accomplish this?
private void SetBuffers() {
_meshObjects.Clear();
_vertices.Clear();
_indices.Clear();
//_debugRays.Clear();
foreach (var mf in _meshFilters) {
int firstVertex = _vertices.Count;
_vertices.AddRange(mf.sharedMesh.vertices);
int firstIndex = _indices.Count;
var indices = mf.sharedMesh.GetIndices(0);
_indices.AddRange(indices.Select(index => index + firstVertex));
_meshObjects.Add(new MeshObject() {
localToWorldMatrix = mf.transform.localToWorldMatrix,
indices_offset = firstIndex,
indices_count = indices.Length
});
}
foreach (var smr in _skinnedMeshRenderers) {
// How can I get the vertices and indices out and put them on the buffers?
}
CreateComputeBuffer(ref _meshObjectBuffer, _meshObjects, 72);
CreateComputeBuffer(ref _vertexBuffer, _vertices, 12);
CreateComputeBuffer(ref _indexBuffer, _indices, 4);
}
private static void CreateComputeBuffer<T>(ref ComputeBuffer buffer, List<T> data, int stride)
where T : struct {
// Do we already have a compute buffer?
if (buffer != null) {
// If no data or buffer doesn't match the given criteria, release it
if (data.Count == 0 || buffer.count != data.Count || buffer.stride != stride) {
buffer.Release();
buffer = null;
}
}
if (data.Count != 0) {
// If the buffer has been released or wasn't there to
// begin with, create it
if (buffer == null) {
buffer = new ComputeBuffer(data.Count, stride);
}
// Set data on the buffer
buffer.SetData(data);
}
}
Thanks.