/// <summary>
        /// Establishes a TCPListener to recieve a connection from the client
        /// Reads the byte stream and updates the mesh in the TangoDatabase.cs
        /// Terminates the Thread once finished
        /// </summary>
        /// <param name="id"></param>
        /// <param name="size"></param>
        void RecieveTangoMeshThread(int id, int size)
        {
            TcpListener receiveTcpListener = new TcpListener(IPAddress.Any, Port + 1);

            receiveTcpListener.Start();
            var client = receiveTcpListener.AcceptTcpClient();

            using (var stream = client.GetStream())
            {
                byte[] data = new byte[size];

                Debug.Log("Start receiving mesh");
                using (MemoryStream ms = new MemoryStream())
                {
                    int numBytesRead;
                    while ((numBytesRead = stream.Read(data, 0, data.Length)) > 0)
                    {
                        ms.Write(data, 0, numBytesRead);
                    }
                    Debug.Log("finish receiving mesh: size = " + ms.Length);
                    client.Close();
                    TangoDatabase.UpdateMesh(ms.ToArray(), id);
                }
            }
            client.Close();
            receiveTcpListener.Stop();

            Thread.CurrentThread.Join();
        }
        public override void ReceiveTangoMesh(int id)
        {
            // Setup TCPListener to wait and receive mesh
            this.DeleteLocalMesh();
            TcpListener receiveTcpListener = new TcpListener(IPAddress.Any, Port + 1);

            receiveTcpListener.Start();
            new Thread(() =>
            {
                var client = receiveTcpListener.AcceptTcpClient();
                using (var stream = client.GetStream())
                {
                    byte[] data = new byte[1024];

                    Debug.Log("Start receiving mesh");
                    using (MemoryStream ms = new MemoryStream())
                    {
                        int numBytesRead;
                        while ((numBytesRead = stream.Read(data, 0, data.Length)) > 0)
                        {
                            ms.Write(data, 0, numBytesRead);
                        }
                        Debug.Log("finish receiving mesh: size = " + ms.Length);
                        client.Close();
                        TangoDatabase.UpdateMesh(ms.ToArray());
                    }
                }
                client.Close();
                receiveTcpListener.Stop();
                photonView.RPC("ReceiveTangoMesh", PhotonTargets.Others, GetLocalIpAddress() + ":" + Port);
            }).Start();

            photonView.RPC("SendTangoMesh", PhotonPlayer.Find(id), GetLocalIpAddress() + ":" + (Port + 1));
        }
Example #3
0
        private void UpdateMesh()
        {
            var tangoApplication =
                GameObject.Find("Tango Manager")
                .GetComponent <TangoApplication>();
            List <Vector3> vertices  = new List <Vector3>();
            List <Vector3> normals   = new List <Vector3>();
            List <Color32> colors    = new List <Color32>();
            List <int>     triangles = new List <int>();

            tangoApplication.Tango3DRExtractWholeMesh(vertices, normals, colors,
                                                      triangles);
            Mesh mesh = new Mesh();

            mesh.vertices  = vertices.ToArray();
            mesh.normals   = normals.ToArray();
            mesh.colors32  = colors.ToArray();
            mesh.triangles = triangles.ToArray();
            List <Mesh> meshList = new List <Mesh>();

            meshList.Add(mesh);

            TangoDatabase.UpdateMesh(meshList);
            Debug.Log("Mesh Updated");
        }
        /// <summary>
        /// Gets all information from the Tango Dynamic Mesh and modifies it based on marker information.
        /// </summary>
        private void UpdateMesh()
        {
            //create lists and populate them with dynamic mesh info
            var tangoApplication =
                GameObject.Find("Tango Manager")
                .GetComponent <TangoApplication>();
            List <Vector3> vertices  = new List <Vector3>();
            List <Vector3> normals   = new List <Vector3>();
            List <Color32> colors    = new List <Color32>();
            List <int>     triangles = new List <int>();

            tangoApplication.Tango3DRExtractWholeMesh(vertices, normals, colors,
                                                      triangles);

            //get current marker tranform information and apply it to every vert
            Vector3    V;
            Quaternion Q;
            Transform  T = GameObject.Find("Dynamic_GameObjects").transform;

            V = T.transform.position;
            Q = T.transform.rotation;

            float   angle;
            Vector3 axis;

            Q.ToAngleAxis(out angle, out axis);
            Q = Quaternion.AngleAxis(-angle, axis);

            for (int i = 0; i < vertices.Count; i++)
            {
                vertices[i] -= V;
                vertices[i]  = Q * vertices[i]; //inverse Q
            }

            //write the info to the mesh
            Mesh mesh = new Mesh();

            mesh.vertices  = vertices.ToArray();
            mesh.normals   = normals.ToArray();
            mesh.colors32  = colors.ToArray();
            mesh.triangles = triangles.ToArray();
            List <Mesh> meshList = new List <Mesh>();

            meshList.Add(mesh);

            //update mesh with info
            TangoDatabase.UpdateMesh(meshList);
            Debug.Log("Mesh Updated");
        }
Example #5
0
        /// <summary>
        /// Listens for the TCP connection from the master client and recieves the room mesh
        /// </summary>
        /// <param name="T"></param>
        void RecieveTangoMeshThread(TangoDatabase.TangoData T)
        {
            TcpListener receiveTcpListener = new TcpListener(IPAddress.Any, (Port + 1));

            try
            {
                receiveTcpListener.Start();
            }
            catch (SocketException)
            {
                UnityEngine.Debug.Log("Error");
                _ThreadFinished = true;
                Thread.CurrentThread.Abort();
            }

            var client = receiveTcpListener.AcceptTcpClient();

            using (var stream = client.GetStream())
            {
                byte[] parentData = new byte[4];
                byte[] data       = new byte[T.size];

                UnityEngine.Debug.Log("Start receiving mesh " + data.Length);
                using (MemoryStream ms = new MemoryStream())
                {
                    //Get the parent of the mesh
                    stream.Read(parentData, 0, 4);
                    int parentID = BitConverter.ToInt32(parentData, 0);

                    int numBytesRead;
                    while ((numBytesRead = stream.Read(data, 0, data.Length)) > 0)
                    {
                        ms.Write(data, 0, numBytesRead);
                    }
                    UnityEngine.Debug.Log("finish receiving mesh: size = " + ms.Length);
                    TangoDatabase.UpdateMesh(ms.ToArray(), T.name, parentID);
                }
            }

            client.Close();

            receiveTcpListener.Stop();

            _ThreadFinished = true;

            UnityEngine.Debug.Log("Join Thread");
            Thread.CurrentThread.Join();
        }
        public override void ReceiveTangoMesh(string networkConfig)
        {
            this.DeleteLocalMesh();
            var networkConfigArray = networkConfig.Split(':');

            TcpClient client = new TcpClient();

            client.Connect(IPAddress.Parse(networkConfigArray[0]), Int32.Parse(networkConfigArray[1]));

            using (var stream = client.GetStream())
            {
                byte[] data = new byte[1024];

                Debug.Log("Start receiving mesh.");
                using (MemoryStream ms = new MemoryStream())
                {
                    int numBytesRead;
                    while ((numBytesRead = stream.Read(data, 0, data.Length)) > 0)
                    {
                        ms.Write(data, 0, numBytesRead);
                    }
                    Debug.Log("Finish receiving mesh: size = " + ms.Length);
                    client.Close();

                    //DONE RECIEVING MESH FROM THE MASTER SERVER, NOW UPDATE IT

                    TangoDatabase.UpdateMesh(ms.ToArray());
                    Debug.Log("You updated the meshes in the database");
                }
            }

            client.Close();


            //CREATE AND DRAW THEM MESHES------------------------------------------------------
            Debug.Log("Checking for them meshes in ze database");

            //goes into the if statement if the database is not NULL
            if (TangoDatabase.GetMeshAsList() != null)
            {
                //Create a material to apply to the mesh
                Material meshMaterial = new Material(Shader.Find("Diffuse"));

                //grab the meshes in the database
                IEnumerable <Mesh> temp = new List <Mesh>(TangoDatabase.GetMeshAsList());

                foreach (var mesh in temp)
                {
                    //for each mesh in the database, create a game object to represent
                    //and display the mesh in the scene
                    GameObject obj1 = new GameObject("mesh");

                    //add a mesh filter to the object and assign it the mesh
                    MeshFilter filter = obj1.AddComponent <MeshFilter>();
                    filter.mesh = mesh;

                    //add a mesh rendererer and add a material to it
                    MeshRenderer rend1 = obj1.AddComponent <MeshRenderer>();
                    rend1.material = meshMaterial;
                }
            }
            else
            {
                UnityEngine.Debug.Log("YO... your mesh is empty...");
            }
            //END OF CREATING AND DRAWING THE MEESHES------------------------------------------
        }