Search Unity

Bug SubMeshDescriptor.baseVertex doesn't seem to work.

Discussion in 'General Graphics' started by arkano22, May 23, 2023.

  1. arkano22

    arkano22

    Joined:
    Sep 20, 2012
    Posts:
    1,929
    Hi!

    I've got a triangles and a vertices array, result of combining multiple meshes together. I want to then extract one mesh from these uber-arrays, so I'm using SubMeshDescriptor.baseVertex with a negative value to offset the indices in the triangles array.

    Thing is, despite the extracted mesh having correct triangle indices, I get this error:

    This is the code I'm using:

    Code (CSharp):
    1.  
    2. mesh.SetVertexBufferParams(vCount, vertexLayout);
    3. mesh.SetIndexBufferParams(tCount, IndexFormat.UInt32);
    4.  
    5. //vOffset and tOffset are offsets into the vertices and triangles uber-arrays, respectively.
    6. mesh.SetVertexBufferData(uberVertexArray, vOffset, 0, vCount, 0, MeshUpdateFlags.DontRecalculateBounds | MeshUpdateFlags.DontValidateIndices);
    7. mesh.SetIndexBufferData(uberTrianglesArray, tOffset, 0, tCount, MeshUpdateFlags.DontRecalculateBounds | MeshUpdateFlags.DontValidateIndices);
    8.                  
    9. submeshInfo.baseVertex = -vOffset; //offset indices by amount of leading vertices in the uberVertexArray
    10. mesh.SetSubMesh(0, submeshInfo);
    I get the impression that SetSubMesh doesn't take into account the baseVertex when asserting that the largest index in the triangles array must be < than the vertexCount. Is this a bug, or am I misunderstanding baseVertex?
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    675
    I think you are understanding baseVertex correctly but it is an unusual use case that you have. Usually, you'd use it for the opposite case, when you have multiple combined meshes with unadjusted index buffers in which case baseVertex would be positive.

    I've checked the D3D11 DrawIndexed method and BaseVertexLocation is signed indeed, so I think it is a bug.
     
    arkano22 likes this.