Example #1
0
    //creates (instantiates) a terrain chunk (but does not render it yet)
    public void CreateChunk(LODPos pos, bool render)
    {
        //if the chunk has aready been created, dont build it again!
        if (chunks.ContainsKey(pos))
        {
            return;
        }

        totalChunks++;

        //build the terrainobject and add its gameobject to the chunks list(may remove this last thing later)
        //TerrainObject chunk = Build.buildObject<TerrainObject>(pos.toVector3(), Quaternion.identity);
        GameObject terrainGO = Pool.getTerrain();

        terrainGO.name = "Terrain Chunk " + pos.ToString();
        TerrainObject chunk = terrainGO.GetComponent <TerrainObject>();

        chunk.init(pos, planet);
        chunks.Add(pos, chunk);
        //Debug.Log("chunks added key :" + pos.ToString());
        visChunks.Add(pos);

        if (render)
        {
            chunk.calculateNoise();
            chunk.Render();            //renders the chunk immediately
        }
        //RequestSystem.terrainToRender.Add(chunk);
    }
Example #2
0
    //renders the pieces of a chunk that has already been split
    public void splitRender(LODPos pos)
    {
        //if(!chunks.ContainsKey(pos))
        //	return;


        //Debug.Log("Chunks contains key :" + pos.ToString() + " " + chunks.ContainsKey(pos));
        //hide this terrain object but don't delete it
        //chunks[pos].gameObject.SetActive(false);

        //now find all of its pieces and render them

        //1 level lower
        int newLev = pos.level - 1;
        //the position of the first subchunk in this chunk
        WorldPos newStart = new WorldPos(pos.x * 2, pos.y * 2, pos.z * 2);

        //render all 8 chunks (that exist)
        for (int x = 0; x <= 1; x++)
        {
            for (int y = 0; y <= 1; y++)
            {
                for (int z = 0; z <= 1; z++)
                {
                    LODPos        newChunk = new LODPos(newLev, newStart.x + x, newStart.y + y, newStart.z + z);
                    TerrainObject tobj     = null;
                    if (chunks.TryGetValue(newChunk, out tobj))
                    {
                        tobj.Render();
                    }
                }
            }
        }

        //splitChunks.
        //Debug.Log(pos.ToString() + " is being splitrendered " + chunksToSplitRender.IndexOf(pos) + " " + chunksToSplitRender.LastIndexOf(pos));
        chunks[pos].gameObject.SetActive(false);
        //Debug.Log(pos.ToString() + " was deactivated");
    }