Search Unity

Mesh.GetNativeVertexBufferPtr/GetNativeIndexBufferPtr layout question

Discussion in '5.5 Beta' started by ArtyBoomshaka, Sep 9, 2016.

  1. ArtyBoomshaka

    ArtyBoomshaka

    Joined:
    Mar 5, 2013
    Posts:
    226
    Hi there,

    I looked at the doc for those new methods and was wondering how they're supposed to be usable at all, given the lack of runtime-info on the vertex data layout.

    In my case I would use this to sample meshes in a native plugin (their surface/normals/colors, etc...), depending on what's available, but I think whether it's for mesh generation or to read the associated data, those methods are useless without any kind of data layout descriptor...

    Any chance for a demo project of this feature? I'm confused at the moment.

    Cheers,
     
  2. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,748
    Correct, currently the GetNativeVertexBufferPtr requires you to "somehow" know the vertex layout. You can query some of that (e.g. by checking whether mesh.normals returns a zero-length array or not), but it's a bit cumbersome.

    We are working on a more flexible Mesh API, but that's for another day.

    There's a demo project on buffer-ptr branch on this bitbucket repo: https://bitbucket.org/Unity-Technologies/graphicsdemos/src/buffer-ptr
     
  3. SonicBloomEric

    SonicBloomEric

    Joined:
    Sep 11, 2014
    Posts:
    950
    It looks like Aras has issued a Pull Request for some changes that show the API in use. Here's the change in the Pull Request (from this commit).

    In case that pointer is helpful for finding a good entry point...
     
  4. ArtyBoomshaka

    ArtyBoomshaka

    Joined:
    Mar 5, 2013
    Posts:
    226
    Thanks, the both of you.

    Good to know. Another day as in "not for Unity 5.5" or as in "later in this beta"?

    I think I'm gonna hold on implementing anything with these calls, especially if it's bound to change.
     
  5. Vanamerax

    Vanamerax

    Joined:
    Jan 12, 2012
    Posts:
    916
    Out of interest, can you elaborate this a bit more? Are there any plans or changes you can share yet? A new mesh api would be very interesting for procedurally generated content
     
  6. gapMindful

    gapMindful

    Joined:
    Jun 26, 2013
    Posts:
    17
    Thanks for linking the example Aras. In the native call example (SetMeshBufferesFromUnity) its providing a pointer to the vert array that was retrieved from mesh.vertices. Does that mean that Mesh.verticies no longer returns a copy of the mesh verts array but rather an actual reference to the mesh's underlying verts. Or is that array not actually used for the underlying modification in the native plugin code?
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,748
    Mesh.vertices just returns the system memory copy, if it exists. So yes, if you modify the underlying native 3D API buffer from your plugin code, that will not reflect in Mesh.vertices.
     
  8. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Can This plugin support android es 2.0?I build apk ,and change code,not work on mobile
    Code (CSharp):
    1. #if  !UNITY_IPHONE
    2.     //#if UNITY_IPHONE && !UNITY_EDITOR
    3.     [DllImport ("__Internal")]
    4. #else
    5.     [DllImport("RenderingPlugin")]
    6. #endif
    opengl2.png
    https://docs.unity3d.com/Manual/NativePluginInterface.html ,ahmm...Have plan to run on mobile plateform?
     
    Last edited: Oct 17, 2016
  9. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Hi Ares,With test 50k dynamic verteces update,It seems Mesh set and get cost little big performance,Can this increase in Native code plugin?and Have any plan to support on mobile ? mesh.jpg
     
    Last edited: Oct 18, 2016
  10. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    fps.png lowfps.png exe1.png 1. WHY so low FPS with this plugin.
    2.Build to exe,It seems not work.
    Any Help?
     
    Last edited: Oct 19, 2016
  11. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    very low fps.png OK,BUILD success.But why so bad performance using this plugin?Anybody used it?No Problem about performance?
     
    Last edited: Oct 20, 2016
  12. gapMindful

    gapMindful

    Joined:
    Jun 26, 2013
    Posts:
    17
    I haven't built this plug in yet. But, if your using visual studio, make sure your building as release. I've had a lot of performance issues around custom native code that just came down to that.
     
  13. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    It seems no way to increase performance:(
     
  14. ArtyBoomshaka

    ArtyBoomshaka

    Joined:
    Mar 5, 2013
    Posts:
    226
    Hey @dreamerflyer, You should probably start your own thread to get this issue noticed.
     
  15. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Got it.
     
  16. dmm_jbw

    dmm_jbw

    Joined:
    Apr 14, 2016
    Posts:
    4
    I'm trying to set up a fairly complex example of writing directly to the vertex and index buffers in a native plugin. I have some questions and this seems like an appropriate place to ask them.

    First off... I'm not much of a rendering expert so I'm sorta fumbling my way through this a little.

    Ok, so in my test I'm streaming in a mesh that includes point data, normals, tangents, 4 uv channels, and vertex color. There's also no guarantee that each frame has the same number of vertices, so it's quite dynamic.

    Previously, this all works by marshaling the data from the plugin and setting the arrays in a Mesh for vertices, normals, colors32, tangents, uv's, and SetIndices, followed by UploadMeshData.

    So, here's my questions:
    - If I create a Mesh, mark it as dynamic, and get "vertexBufferCount" it returns 0. Do I have to initialize something first? I can get around this by marshaling my data for one frame then switching to directly accessing the vertex and index buffers.
    - Is there a way to allocate a vertex buffer of a size that's big enough to accommodate any fluctuations in the number of vertices I have? I assume that re-allocating the buffer every frame would be a performance killer, but having unused space would be ok.
    - What should my vertex data look like? Does it matter? Is there any way to get some sort of descriptor? Right now I concocted this:

    struct MeshVertex
    {
    float pos[3];
    float normal[3];
    uint32_t color;
    float tangent[4];
    float uv[2];
    float uv2[2];
    float uv3[2];
    float uv4[2];
    };

    So, all that said. I've at least got an exploding mesh working. I'm confident that this WILL work, and I could probably do it if I knew more about rendering :(

    Any help is always appreciated.
     
  17. dmm_jbw

    dmm_jbw

    Joined:
    Apr 14, 2016
    Posts:
    4
    Nevermind... got everything working. HUGE performance impact vs marshalling all the data as I was before. This will be a big win.
     
unityunity