Exemple #1
0
 public void StartSave()
 {
     findedTriangles = RayCasting_Expansion.GetFindedTriangles();
     triangleSize    = RayCasting_Expansion.GetTriangleSize() / 3;
     cubes           = CubeManaging.GetCubesArray();
     Save();
 }
Exemple #2
0
    private string CreateStringCubes()
    {
        StringBuilder sb = new StringBuilder();

        sb.AppendFormat("{0} Cubes", cubes.Count).Append("\n");
        for (int i = 0; i < cubes.Count; i++)
        {
            GameObject aCube    = CubeManaging.GetCubeinArray(i);
            Vector3    position = aCube.transform.position;
            Vector3    scale    = aCube.transform.lossyScale;

            sb.AppendFormat("{0} , {1} , {2} , {3} , {4} , {5} , {6}", i, position.x, position.y, position.z, scale.x, scale.y, scale.z).Append("\n");
        }
        sb.Append("\n");
        return(sb.ToString());
    }
Exemple #3
0
    private void Rays(double lasthitround, double total)
    {
        var chrono = System.Diagnostics.Stopwatch.StartNew();

        ArrayList volumes = CubeManaging.GetVolumesArray();

        Debug.Log(totalRays);
        Debug.Log(minRaysNoHit);
        Debug.Log(maxTime);

        for (int i = 0; i < totalRays; i++)
        {
            if (!(lasthitround % minRaysNoHit == 0) && !MaxTimeExcdeeded(chrono))
            {
                //Vector3 randomXY = Random.rotation.eulerAngles;
                Vector3 randomXY = UnityEngine.Random.insideUnitSphere;
                //Debug.Log(randomXY);
                //Debug.Log(sphere.transform.position);
                //Ray ray = new Ray(sphere.transform.position, new Vector3(randomXY.x, -1, randomXY.z));
                float randvolume = UnityEngine.Random.Range(0.1f, CubeManaging.GetTotalVolume() - 1);

                //Debug.Log("randV" + randvolume);
                int   k             = 0;
                float volsdescarted = 0;
                //Debug.Log("vol de " + k + ":" + volumes[k]);
                while ((volsdescarted + (float)volumes[k]) < randvolume)
                {
                    volsdescarted += (float)volumes[k];
                    k++;
                    //Debug.Log("vol de " + k + ":" + volumes[k]);
                    //Debug.Log("totalVuntilnow" + volsdescarted);
                }
                //Debug.Log(volumes);
                //Debug.Log(k);
                //Debug.Log("agafo el cub: " + k);
                GameObject cube = CubeManaging.GetCubeinArray(k);
                //Debug.Log("raig:" + i);
                //Collider coll = cube.GetComponent<Collider>();
                //coll.enabled = true;
                //Bounds b = cube.GetComponent<Collider>().bounds;
                Bounds b = cube.GetComponent <Renderer>().bounds;
                //Bounds b = someMesh.bounds;
                Vector3 max = b.max;
                Vector3 min = b.min;
                //Debug.Log("MAX" + max);
                //Debug.Log("MIN" + min);
                Vector3 point = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), Random.Range(min.z, max.z));
                while (!b.Contains(point) || IsUnderground(point))
                {
                    point = new Vector3(Random.Range(min.x, max.x), Random.Range(min.y, max.y), Random.Range(min.z, max.z));
                }
                //Debug.Log("POINT: "+point);
                //Debug.Log("DIR: "+randomXY);
                Ray        ray = new Ray(point, randomXY);
                RaycastHit hitInfo;
                //Part del codi per a retornar el triangle amb el que ha colisionat
                if (Physics.Raycast(ray, out hitInfo))
                {
                    total += 1;
                    if (findedTriangles[hitInfo.triangleIndex] == false)
                    {
                        findedTriangles[hitInfo.triangleIndex] = true;
                        lasthitround = 1;
                    }
                    else
                    {
                        lasthitround += 1;
                    }
                }
                else
                {
                    lasthitround += 1;
                }
            }
            else
            {
                Debug.Log("Rajos Llançats" + i);
                i = totalRays;
            }
        }
        chrono.Stop();

        Debug.Log("Total Hits " + total);
        Debug.Log("Total Time " + chrono.ElapsedMilliseconds);
        Debug.Log("Rounds without hit " + lasthitround);
    }