public void init()
    {
        meshProvider = new MeshProvider(patchSize);
        MeshFilter mf = (MeshFilter)PlanetMeshPrefab.GetComponent("MeshFilter");

        mf.sharedMesh = meshProvider.GetStandardMesh();
        mf.sharedMesh.RecalculateBounds();

        maxLevel  = (int)Mathf.Log(radius * 2f);
        maxLevel -= (int)Mathf.Log(Mathf.Pow(patchSize, 2));
        maxLevel  = maxLevel < 0 ? 0 : maxLevel;

        Vector3 nearCorner = (Vector3.right + Vector3.up + Vector3.forward) * radius;
        Vector3 farCorner  = -nearCorner;

        //near corner quads
        quadTrees.Add(new QuadTree(maxLevel, patchSize, radius, nearCorner, Vector3.back, Vector3.left, this, "Bottom"));       // Bottom
        quadTrees.Add(new QuadTree(maxLevel, patchSize, radius, nearCorner, Vector3.left, Vector3.down, this, "Front"));        // Front
        quadTrees.Add(new QuadTree(maxLevel, patchSize, radius, nearCorner, Vector3.down, Vector3.back, this, "Left"));         // Left

        //far corner quads
        quadTrees.Add(new QuadTree(maxLevel, patchSize, radius, farCorner, Vector3.right, Vector3.forward, this, "Top"));     // Top
        quadTrees.Add(new QuadTree(maxLevel, patchSize, radius, farCorner, Vector3.up, Vector3.right, this, "Back"));         // Back
        quadTrees.Add(new QuadTree(maxLevel, patchSize, radius, farCorner, Vector3.forward, Vector3.up, this, "Right"));      // Right
        //AssignNeighbors();
    }
Example #2
0
    void Start()
    {
        int     step          = 1;
        int     patchSize     = 50;
        Vector3 startPosition = new Vector3();

        for (int y = 0; y <= patchSize; y++)
        {
            for (int x = 0; x <= patchSize; x++)
            {
                Vector3 offset         = startPosition + (Vector3.right * step * x) + (Vector3.up * step * y);
                bool    buildTriangles = x > 0 && y > 0;
                Vector2 uv             = new Vector2();
                bool    swapOrder      = x % 2 == y % 2 ? true: false;
                ProceduralQuad.BuildQuadForGrid(_meshBuilder, offset, uv, buildTriangles, patchSize + 1, swapOrder);
            }
        }
        mesh = _meshBuilder.CreateMesh();
        MeshProvider mp = new MeshProvider(32);

        mesh  = mp.GetStandardMesh();
        mesh1 = Instantiate(PlanetMeshPrefab) as GameObject;
        mesh2 = Instantiate(PlanetMeshPrefab) as GameObject;

        go = new GameObject();
        go.AddComponent("MeshFilter");
        go.AddComponent("MeshRenderer");
//		go.transform.Translate (Vector3.right * 50);

//		mesh1.transform.Translate (Vector3.right * 100);
    }