Esempio n. 1
0
 public void HandleMeshMessage(OIMSG msg)
 {
     if (msg.msgFamily != (byte)OI_MSGFAMILY.XR)
     {
         return;
     }
     if (msg.msgType == (byte)OI_MSGTYPE_XR.SPATIAL_MESH_ADD)
     {
         MeshStruct ms       = OIMeshSerializer.OIDeserialize(msg.data);
         Transform  existing = GetMeshObject(ms.ID);
         if (existing != null)   // update
         {
             GameObject.Destroy(existing.gameObject);
         }
         AddMeshObject(ms.mesh, ms.ID);
     }
     else if (msg.msgType == (byte)OI_MSGTYPE_XR.SPATIAL_MESH_REMOVE)
     {
         List <int> remove_ids = new List <int>(IdsSerializer.Deserialize(msg.data));
         foreach (int ID in remove_ids)
         {
             Transform existing = GetMeshObject(ID);
             if (existing != null)
             {
                 Destroy(existing.gameObject);
             }
         }
     }
 }
        private void SendMeshes()
        {
#if !UNITY_EDITOR && UNITY_METRO
            List <ObjectSurfaceObserver.SurfaceObject> surfaces = new List <SpatialMappingSource.SurfaceObject>();
            surfaces.AddRange(send_new);
            send_new.Clear();

            for (int index = 0; index < surfaces.Count; index++)
            {
                MeshFilter     filter = surfaces[index].Filter;
                Mesh           source = filter.sharedMesh;
                Mesh           clone  = new Mesh();
                List <Vector3> verts  = new List <Vector3>();
                verts.AddRange(source.vertices);

                for (int vertIndex = 0; vertIndex < verts.Count; vertIndex++)
                {
                    verts[vertIndex] = filter.transform.TransformPoint(verts[vertIndex]);
                }

                clone.SetVertices(verts);
                clone.SetTriangles(source.triangles, 0);

                OIMSG msg = new OIMSG((byte)OI_MSGFAMILY.XR, (byte)OI_MSGTYPE_XR.SPATIAL_MESH_ADD, OIMeshSerializer.OISerialize(surfaces[index].ID, clone));

                connector.SendData(msg);
            }

            if (remove_ids.Count > 0)
            {
                OIMSG msg = new OIMSG((byte)OI_MSGFAMILY.XR, (byte)OI_MSGTYPE_XR.SPATIAL_MESH_REMOVE, IdsSerializer.Serialize(remove_ids));

                remove_ids.Clear();
                connector.SendData(msg);
            }
#endif
        }