IEnumerator Start()
        {
            var calc    = new ConvexHullCalculator();
            var verts   = new List <Vector3>();
            var tris    = new List <int>();
            var normals = new List <Vector3>();
            var points  = new List <Vector3>();
            var mf      = GetComponent <MeshFilter>();
            var mesh    = new Mesh();

            mf.sharedMesh = mesh;

            while (true)
            {
                points.Clear();

                for (int i = 0; i < 500; i++)
                {
                    points.Add(new Vector3(
                                   Random.value,
                                   Random.value,
                                   Random.value));
                }

                calc.GenerateHull(points, true, ref verts, ref tris, ref normals);

                mesh.Clear();
                mesh.SetVertices(verts);
                mesh.SetTriangles(tris, 0);
                mesh.SetNormals(normals);

                yield return(new WaitForSeconds(1.0f));
            }
        }
        IEnumerator Start()
        {
            var calc    = new ConvexHullCalculator();
            var verts   = new List <Vector3>();
            var tris    = new List <int>();
            var normals = new List <Vector3>();
            var points  = new List <Vector3>();

            while (true)
            {
                points.Clear();

                for (int i = 0; i < 200; i++)
                {
                    points.Add(Random.insideUnitSphere);
                }

                calc.GenerateHull(points, true, ref verts, ref tris, ref normals);

                var rock = Instantiate(RockPrefab);

                rock.transform.SetParent(transform, false);
                rock.transform.localPosition = Vector3.zero;
                rock.transform.localRotation = Quaternion.identity;
                rock.transform.localScale    = Vector3.one;

                var mesh = new Mesh();
                mesh.SetVertices(verts);
                mesh.SetTriangles(tris, 0);
                mesh.SetNormals(normals);

                rock.GetComponent <MeshFilter>().sharedMesh   = mesh;
                rock.GetComponent <MeshCollider>().sharedMesh = mesh;

                yield return(new WaitForSeconds(0.5f));
            }
        }
Exemple #3
0
        IEnumerator Start()
        {
            //Parametros necessarios para o algoritmo de Convex Hull

            var calc    = new ConvexHullCalculator();
            var verts   = new List <Vector3>();
            var tris    = new List <int>();
            var normals = new List <Vector3>();



            //pointsTrailRemote = receiveTrail.remotePoints;

            //Debug.Log(receiveTrail.remotePoints.Count);
            //Debug.Log(pointsTrailRemote.Count);

            while (true)
            {
                if (receiveTrail.remotePoints.Count > 0 && receiveTrail.receptionComplete && eval.localIsDemonstrator)                 //list is complete
                {
                    if (eval.condition == ConditionType.Veridical)
                    {
                        for (int i = 0; i < receiveTrail.remotePoints.Count - 1; i++)
                        {
                            float x = -(float)Math.Ceiling(receiveTrail.remotePoints[i].x * 10000000) / 10000000;
                            float y = (float)Math.Ceiling(receiveTrail.remotePoints[i].y * 10000000) / 10000000;
                            float z = -(float)Math.Ceiling(receiveTrail.remotePoints[i].z * 10000000) / 10000000;

                            Vector3 position = new UnityEngine.Vector3(x, y, z);

                            remotePointsAltered.Add(position);
                        }
                    }

                    receiveTrail.receptionComplete = false;
                    Debug.Log("Entrei na CH Remote");

                    //////////////////////////////////////////////////////////////////////////////////////

                    /*for (int i = 0; i < receiveTrail.remotePoints.Count - 1; i++)
                     * {
                     *
                     *      float x = (float)Math.Ceiling(receiveTrail.remotePoints[i].x * 10000000) / 10000000;
                     *      float y = (float)Math.Ceiling(receiveTrail.remotePoints[i].y * 10000000) / 10000000;
                     *      float z = (float)Math.Ceiling(receiveTrail.remotePoints[i].z * 10000000) / 10000000;
                     *
                     *      Vector3 position = new UnityEngine.Vector3(x, y, z);
                     *
                     *      Instantiate(ball, position, Quaternion.identity);
                     *
                     * }*/
                    //////////////////////////////////////////////////////////////////////////////////////


                    try
                    {
                        //Debug.Log("Remote points used for CH: " + receiveTrail.remotePoints.Count + "as:" + _listToString(receiveTrail.remotePoints));
                        if (eval.condition == ConditionType.Approach)
                        {
                            calc.GenerateHull(receiveTrail.remotePoints, true, ref verts, ref tris, ref normals);
                        }
                        if (eval.condition == ConditionType.Veridical)
                        {
                            calc.GenerateHull(remotePointsAltered, true, ref verts, ref tris, ref normals);
                        }


                        writeFile = true;
                        //calc.GenerateHull(saveTrailPoints.pointsTrail, true, ref verts, ref tris, ref normals);

                        //Create an initial transform that will evolve into our Convex Hull when altering the mesh

                        var initialHull = Instantiate(initialMesh);
                        //initialHull = Instantiate(initialMesh);

                        initialHull.transform.SetParent(ChParent, false);
                        initialHull.transform.position   = Vector3.zero;
                        initialHull.transform.rotation   = Quaternion.identity;
                        initialHull.transform.localScale = Vector3.one;

                        //Independentemente do tipo de mesh com que se começa (cubo, esfera..)
                        //a mesh é redefenida com as definiçoes abaixo

                        var mesh = new Mesh();
                        mesh.SetVertices(verts);
                        mesh.SetTriangles(tris, 0);
                        mesh.SetNormals(normals);

                        initialHull.GetComponent <MeshFilter>().sharedMesh   = mesh;
                        initialHull.GetComponent <MeshCollider>().sharedMesh = mesh;

                        //Calcular o volume da CH

                        volume = VolumeOfMesh(mesh) * 1000000;                         //convert to cm3
                        //Debug.Log("Volume of MESH: " + volume);

                        //Debug.Log("Verts: " + verts.Count + " Tris: " + tris.Count + " Normals: " + normals.Count);

                        //Send points of the mesh to the hashset containing all points for later Union

                        /*
                         *
                         * for (int i = 0; i < receiveTrail.remotePoints.Count; i++)
                         * {
                         *      checkInt.unionHash.Add(receiveTrail.remotePoints[i]);
                         * }
                         *
                         * Debug.Log("UnionHash Remote: " + checkInt.unionHash.Count);*/


                        //Limpar os pontos antigos da lista para o proximo convex hull e
                        //informar o programa de que já realizou esta função

                        receiveTrail.remotePoints.Clear();
                        remotePointsAltered.Clear();
                        generateHullDone = true;
                        //checkInt.intersectionDone = false;


                        nrCHremote++;
                        readyForIntersectionRemote = true;

                        //Debug.Log("Finish CH Remote");

                        Debug.Log("CH Hull Remote");

                        Debug.Log("nr ch remote:" + nrCHremote);

                        //////////////////////////////////////////////initialHull.SetActive(false);

                        if (chlocal.ChParent.childCount != chlocal.nrCHlocal)
                        {
                            Destroy(initialHull);
                            Debug.Log("destroyed exception object");
                            nrCHremote--;
                            chlocal.nrCHlocal--;
                            File.AppendAllText(startEnd._logIntersectionPath, eval.condition.ToString() + "\",\"" + eval.participantID.ToString() + "\",\"" + "T" + "\",\"" + System.DateTime.Now.ToString("HH:mm:ss:fff") + "\",\"" + "Couldn't generate Hull - Exception." + "\"\n");
                        }
                    }
                    catch (System.ArgumentException)
                    {
                        nrCHremote++;
                        receiveTrail.remotePoints.Clear();
                        remotePointsAltered.Clear();
                        generateHullDone      = true;
                        startEnd.getStartTime = true;


                        Debug.Log("Exception1");
                    }

                    catch (UnityEngine.Assertions.AssertionException)
                    {
                        nrCHremote++;
                        receiveTrail.remotePoints.Clear();
                        remotePointsAltered.Clear();
                        generateHullDone      = true;
                        startEnd.getStartTime = true;
                        Debug.Log("Exception2");
                    }
                }



                yield return(new WaitForSeconds(0.5f));
            }
        }
Exemple #4
0
        IEnumerator Start()
        {
            //Parametros necessarios para o algoritmo de Convex Hull

            var calc    = new ConvexHullCalculator();
            var verts   = new List <Vector3>();
            var tris    = new List <int>();
            var normals = new List <Vector3>();



            //pointsTrailRemote = udpListener.remotePoints;

            //Debug.Log(udpListener.remotePoints.Count);
            //Debug.Log(pointsTrailRemote.Count);

            while (true)
            {
                if (saveTrailPoints.pressed == false && generateHullDone == false && eval.localIsDemonstrator)
                {
                    try
                    {
                        calc.GenerateHull(saveTrailPoints.pointsTrail, true, ref verts, ref tris, ref normals);
                        writeFile = true;
                        //Create an initial transform that will evolve into our Convex Hull when altering the mesh

                        var initialHull = Instantiate(initialMesh);
                        //initialHull = Instantiate(initialMesh);

                        initialHull.transform.SetParent(ChParent, false);
                        initialHull.transform.position   = Vector3.zero;
                        initialHull.transform.rotation   = Quaternion.identity;
                        initialHull.transform.localScale = Vector3.one;

                        //Independentemente do tipo de mesh com que se começa (cubo, esfera..)
                        //a mesh é redefenida com as definiçoes abaixo

                        var mesh = new Mesh();
                        mesh.SetVertices(verts);
                        mesh.SetTriangles(tris, 0);
                        mesh.SetNormals(normals);

                        initialHull.GetComponent <MeshFilter>().sharedMesh   = mesh;
                        initialHull.GetComponent <MeshCollider>().sharedMesh = mesh;

                        //Calcular o volume da CH

                        volume = VolumeOfMesh(mesh) * 1000000;                         //convert to cm3
                        //Debug.Log("Volume of MESH: " + volume);

                        //Debug.Log("Verts: " + verts.Count + " Tris: " + tris.Count + " Normals: " + normals.Count);

                        //Send points of the mesh to the hashset containing all points for later Union


                        /*for (int i = 0; i < saveTrailPoints.pointsTrail.Count; i++)
                         * {
                         *      checkInt.unionHash.Add(saveTrailPoints.pointsTrail[i]);
                         * }
                         *
                         *
                         * Debug.Log("UnionHash Local: " + checkInt.unionHash.Count);*/


                        //Limpar os pontos antigos da lista para o proximo convex hull e
                        //informar o programa de que já realizou esta função

                        saveTrailPoints.pointsTrail.Clear();
                        //pointsTrailRemote.Clear();
                        //udpListener.remotePoints.Clear();

                        generateHullDone = true;
                        //checkInt.intersectionDone = false;



                        nrCHlocal++;
                        readyForIntersectionLocal = true;

                        Debug.Log("CH Hull Local");

                        /////////////////////////////////////////////////////initialHull.SetActive(false);

                        //Debug.Log("Local write = " + writeFile);

                        Debug.Log("nr ch local:" + nrCHlocal);

                        if (chremote.ChParent.childCount != chremote.nrCHremote)
                        {
                            Destroy(initialHull);
                            Debug.Log("destroyed exception object");
                            nrCHlocal--;
                            chremote.nrCHremote--;
                            File.AppendAllText(startEnd._logIntersectionPath, eval.condition.ToString() + "\",\"" + eval.participantID.ToString() + "\",\"" + "T" + "\",\"" + System.DateTime.Now.ToString("HH:mm:ss:fff") + "\",\"" + "Couldn't generate Hull - Exception." + "\"\n");
                        }
                    }
                    catch (System.ArgumentException)
                    {
                        nrCHlocal++;
                        saveTrailPoints.pointsTrail.Clear();
                        generateHullDone      = true;
                        startEnd.getStartTime = true;

                        Debug.Log("Exception1");
                    }

                    catch (UnityEngine.Assertions.AssertionException)
                    {
                        nrCHlocal++;
                        saveTrailPoints.pointsTrail.Clear();
                        generateHullDone      = true;
                        startEnd.getStartTime = true;

                        Debug.Log("Exception2");
                    }
                }



                yield return(new WaitForSeconds(0.5f));
            }
        }