Search Unity

Resolved XR SDK Question - Aquired Meshes have no indices on OSX in Unity Editor ? MeshDataAllocator_SetMesh

Discussion in 'AR/VR (XR) Discussion' started by marwi, Sep 18, 2020.

  1. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    Hello, I'm currently working on a XR Meshing Plugin for simulating ARMeshManager in the Unity Editor. I got a working version running on windows and marshalling data to my native plugin works as intended.

    Now I tried building on OSX, but the Aquired meshes has no index array (thus no triangles).

    I tried marshalling the data back to managed land and the data seems to be there and alright.

    Here is an example.

    upload_2020-9-18_19-5-4.png


    The following mesh was aquired and created by ARMeshManager on osx

    upload_2020-9-18_19-6-4.png

    But the data is fine (this is what I get when I marshal the indices data back to c# and log them)

    upload_2020-9-18_19-9-38.png

    The same code on windows
    upload_2020-9-18_19-8-36.png
     

    Attached Files:

    Last edited: Sep 19, 2020
  2. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    Here is another screenshot on windows - this is working:

    upload_2020-9-18_19-12-33.png


    Again: on ios I'm only getting vertices but no indices?
    I'm marshalling indices as UInt16[]
     
  3. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
  4. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138

    Hi I have the XR SDK and a native plugin. This is my AquireMesh implementation. "Existing" is the mesh data I set from C#. Works fine on windows, on OSX I only get vertices and no indices in Unity (so meshes without triangles)

    unknown.png
     
    Last edited: Sep 19, 2020
  5. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    I just tried again using hardcoded vertices and indices before calling MeshDataAllocator_SetMesh and I get the same result.
     
  6. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
  7. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    I just created a simple plugin for osx that reports a hard-coded quad and then prints out the vertex count in C#, and it worked as expected. What are the fields of your
    UnityXRMeshDescriptor
    ? Mine looks like this:

    Code (CSharp):
    1.     UnityXRMeshDescriptor descriptor = {};
    2.     descriptor.positions = s_Positions.data();
    3.     descriptor.vertexCount = 4;
    4.     descriptor.indices16 = s_Indices.data();
    5.     descriptor.indexFormat = kUnityXRIndexFormat16Bit;
    6.     descriptor.indexCount = 6;
    7.     descriptor.topology = kUnityXRMeshTopologyTriangles;
    8.     s_Interface->MeshDataAllocator_SetMesh(allocator, &descriptor);
    9.  
    Where positions and indices are defined like this:
    Code (CSharp):
    1. std::vector<UnityXRVector3> s_Positions = {
    2.     {-1, -1, 1},
    3.     {+1, -1, 1},
    4.     {+1, +1, 1},
    5.     {-1, +1, 1}
    6. };
    7.  
    8. std::vector<uint16_t> s_Indices = {
    9.     0, 3, 1,
    10.     3, 2, 1
    11. };
     
    marwi likes this.
  8. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138

    Thanks for looking into it!

    I assume youre also getting the indices/triangles? Vertices did work for me as well.

    Ill try your code tomorrow, i didnt hardcode the descriptor completely (just the position and index array so maybe there is actually something missing).
     
  9. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    Sorry, I meant to say: yes, vertices & indices and they match what I provided from the C++ code. I can also see the mesh in the scene view.
     
  10. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    Alright your code is working with static vertex and index data. I'll try to figure out when it stops working for me
     
  11. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    Ok I actually forgot to set the topology and index format when registering my descriptors. Weird that it still worked as expected on windows? But glad it works now on osx too. Thanks again for your help! Greatly appreciated! :)
     
    tdmowrer likes this.
  12. tdmowrer

    tdmowrer

    Joined:
    Apr 21, 2017
    Posts:
    605
    You need to set those fields, so that is strange that it worked on windows. Maybe Windows has slightly different defaults, or if it was uninitialized memory maybe you "got lucky" with the right value. Glad it works for you now!
     
  13. marwi

    marwi

    Joined:
    Aug 13, 2014
    Posts:
    138
    I guess the defaults just work(?) because I tried the windows plugin on different machines and they all worked.