Search Unity

Question Bake mesh from vertex buffer

Discussion in 'General Graphics' started by Qleenie, Jun 21, 2022.

  1. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    870
    Hi,

    I am using the "new" Mesh API to load data from mesh with GetVertexBuffer() to Compute Shader and after processing I write back the data into SkinnedMeshRenderer in "OnBeginFrameRendering".
    This works well, but now I'd like to update Mesh Colliders based on the changes I did on the vertex buffer.
    How can I transform the buffer back to a mesh, same as SkinnedMeshRender.BakeMesh() would do?
     
  2. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    870
    I found a solution which somehow works:
    - do BakeMesh only once to get the initial layout of mesh
    - pull the vertex positions with GetData from ComputeBuffer and update only positions of the mesh.
    Not optimal due to the GetData, but there’s probably no way around this.