示例#1
0
        void OnSpatialMapping(NetworkInMessage msg)
        {
#if UNITY_EDITOR
            if (SpatialMappingManager.Instance == null)
            {
                return;
            }

            RemoteSpatialMappingSource rsms = SpatialMappingManager.Instance.GetComponent <RemoteSpatialMappingSource>();

            if (rsms == null)
            {
                return;
            }

            msg.ReadInt64();

            List <Vector3> vertices  = new List <Vector3>();
            List <Vector3> normals   = new List <Vector3>();
            List <int>     triangles = new List <int>();

            int vertexCount   = msg.ReadInt32();
            int normalCount   = msg.ReadInt32();
            int triangleCount = msg.ReadInt32();

            for (int i = 0; i < vertexCount; i++)
            {
                Vector3 vertex = SV_CustomMessages.Instance.ReadVector3(msg);
                vertices.Add(vertex);
            }

            for (int i = 0; i < normalCount; i++)
            {
                Vector3 normal = SV_CustomMessages.Instance.ReadVector3(msg);
                normals.Add(normal);
            }

            for (int i = 0; i < triangleCount; i++)
            {
                int index = msg.ReadInt32();
                triangles.Add(index);
            }

            SpatialMappingManager.Instance.transform.parent        = transform;
            SpatialMappingManager.Instance.transform.localPosition = Vector3.zero;
            SpatialMappingManager.Instance.transform.localRotation = Quaternion.identity;

            rsms.AddSurface(vertices, normals, triangles);
#endif
        }
        void Update()
        {
#if UNITY_EDITOR
            if (_createSpatialMapInEditor && smBytes.Count >= spatialMappingNumChunks)
            {
                _createSpatialMapInEditor = false;

                int    meshIndex = -1;
                byte[] bytes     = new byte[0];

                for (int i = 0; i < smBytes.Count; i++)
                {
                    if (smBytes[i].meshIndex != meshIndex)
                    {
                        meshIndex = smBytes[i].meshIndex;
                        if (bytes.Length != 0)
                        {
                            // Deserialize the old bytes.
                            IEnumerable <Mesh> meshes = SpectatorView.SV_SimpleMeshSerializer.Deserialize(bytes);
                            foreach (Mesh mesh in meshes)
                            {
                                GameObject sm = HoloToolkit.Unity.SpatialMapping.SpatialMappingManager.Instance.gameObject;
                                RemoteSpatialMappingSource src = sm.GetComponent <RemoteSpatialMappingSource>();
                                List <Vector3>             v   = new List <Vector3>(mesh.vertices);
                                List <Vector3>             n   = new List <Vector3>(mesh.normals);
                                List <int> t = new List <int>(mesh.triangles);

                                src.AddSurface(v, n, t, UNetAnchorManager.Instance.gameObject.transform);
                            }
                        }

                        // Update byte array with new mesh's size.
                        bytes = new byte[smBytes[i].totalMeshBytes];
                    }

                    // Copy network chunk to appropriate spot in the destination buffer.
                    System.Array.Copy(smBytes[i].bytes, 0, bytes, NetworkedChunkSize * smBytes[i].chunkIndex, smBytes[i].chunkLength);
                }
            }
#endif
        }