Beispiel #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);
    }
Beispiel #2
0
    //calculate the noise values and mesh data for each child chunk
    public void splitCalc(LODPos pos)
    {
        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.calculateNoise();
                        //tobj.calculateMesh();
                    }
                }
            }
        }
    }