//When method is called it will make a call to the octree passing secondary Camera frustum
    //to the octree and fetch all points within the frustum
    //
    //Take the vector between each (point+camera.poisiton)/ conversionFactor
    //
    //Will then generate a triangle location for each point retrieved, and then bake mesh
    public void generateMesh()
    {
        timer = new Stopwatch();
        timer.Start();
        Octree.frustumCulling(visibleStars, GeometryUtility.CalculateFrustumPlanes(secondaryCamera));
        print("Fetch from Octree: " + timer.ElapsedMilliseconds);
        timer.Stop();
        myVertex[] array = listToArray(visibleStars);
        visibleStars.Clear();
        timer = new Stopwatch();
        timer.Start();
        mesh = new Mesh();
        GetComponent <MeshFilter>().mesh = mesh;

        meshSize = array.Length;

        int vertexLength = array.Length * 3;

        Vector3[] vertices = new Vector3[vertexLength];
        int[]     indecies = new int[vertexLength];
        Color[]   colours  = new Color[vertexLength];
        print("Triangle-Count: " + printTriangles());

        int y = 0;

        for (int i = 0; i < vertexLength; i += 3)
        {
            //Shrinking the stars gathered by the currentScale
            array[y].position = (array[y].position + Camera.main.transform.position) / conversionFactor;

            Vector3[] temp = pointsOfTriangle(array[y].position);
            vertices[i]     = temp[2];
            vertices[i + 1] = temp[1];
            vertices[i + 2] = temp[0];

            colours[i]     = array[y].color;
            colours[i + 1] = array[y].color;
            colours[i + 2] = array[y].color;

            indecies[i]     = i;
            indecies[i + 1] = i + 1;
            indecies[i + 2] = i + 2;
            y++;
        }
        mesh.vertices  = vertices;
        mesh.colors    = colours;
        mesh.triangles = indecies;
        print("Mesh Generated: " + timer.ElapsedMilliseconds);
        timer.Stop();
    }
Beispiel #2
0
    void unitTestOctreePutandGet()
    {
        OctreeObject[] randomStars = new OctreeObject[(int)(max - min)];
        Bounds         testBounds  = new Bounds();

        GameObject testCamera = GameObject.Find("testCamera");
        Camera     test       = testCamera.GetComponent <Camera>();

        List <OctreeObject[]> myList = new List <OctreeObject[]>();

        testBounds.SetMinMax(minV, maxV);

        for (int i = 0; i < randomStars.Length; i++)
        {
            randomStars[i] = new OctreeObject(new Vector3((float)rnd(min, max), (float)rnd(min, max), (float)rnd(min, max)), 1.0f, 1.0f);
        }

        //Expected 0 and 1 due to camera(near=0.3,far=3);
        //for (int i = 0; i < randomStars.Length; i++)
        //{
        //    randomStars[i] = new OctreeObject(new Vector3(i, i, i),1.0f,1.0f);
        //}

        OctreeDataStructure octree = new OctreeDataStructure(testBounds, randomStars);

        b = octree.divideAABB(testBounds);

        octree.init();
        octree.frustumCulling(myList, GeometryUtility.CalculateFrustumPlanes(test));

        foreach (OctreeObject[] oo in myList)
        {
            foreach (OctreeObject o in oo)
            {
                print("X:" + o.spatialPosition.x + " Y:" + o.spatialPosition.y + " Z:" + o.spatialPosition.z);
            }
        }
    }