Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Better mesh buffers manipulation

Discussion in 'Graphics Experimental Previews' started by MrDyrektor, Jun 20, 2018.

  1. MrDyrektor

    MrDyrektor

    Joined:
    Nov 13, 2016
    Posts:
    14
    Hello everyone!
    Question to Unity Team! Are there any plans to give programmers more features for manipulating meshes? I mean, GetNativeVertexBufferPtr and GetNativeIndexBufferPtr are nice for optimization, but there is still no way to create big mesh without huge overhead on main thread. There would be nice, if there was method to cast vertex/index buffer created in native plugin to Mesh component, or maybe even a method on Mesh component e.g. Mesh.SetVertexBufferSize which would only create buffer with desired size without any additional copy?

    This is example for what I'm talking about. If I want to update vertex buffer through native plugin to get rid of overhead from copying vertices, etc., there is no way to initialize such mesh without setting Mesh.vertices property

    Code (CSharp):
    1. Mesh m = new Mesh();
    2. m.vertices = new Vector3[100000]; // 10ms overhead
    3. IntPtr bufferPtr = m.GetNativeVertexBufferPtr(0);
    4. myNativePlugin_updateMesh(bufferPtr);
    The first option what I was talking about

    Code (CSharp):
    1. IntPtr bufferPtr = myNativePlugin_createVertexBuffer(100000);
    2. Mesh m = new Mesh();
    3. m.SetVertexBuffer(bufferPtr); // not copying empty vertex array = no overhead
    4. myNativePlugin_updateMesh(bufferPtr);
    The second option

    Code (CSharp):
    1. Mesh m = new Mesh();
    2. m.SetVertexBufferSize(100000); // no copy, just create vertex buffer with desired size
    3. IntPtr bufferPtr = m.GetNativeVertexBufferPtr(0);
    4. myNativePlugin_updateMesh(bufferPtr);
    If this is incorrect section for this thread, I'm sorry, please move it.