Ejemplo n.º 1
0
    private void Start()
    {
        Initialize();

        #region SecondTestWithChunkClass
        var chunk1 = new Chunk <Voxel>(_heightMap.GetLength(0), 70, new Vector3(0, 0, 0));

        //Add voxels
        for (int z = 0; z < chunk1.Width; z++)
        {
            for (int x = 0; x < chunk1.Width; x++)
            {
                // Step 1: Create voxel and add it to a chunk
                int   y     = Mathf.Abs((int)(_heightMap[x, z]));
                Voxel voxel = new Voxel(x, y, z, BlockType.Grass);
                chunk1.AddAtPos(voxel, voxel.Position);
            }
        }

        int scale = 0;
        foreach (Voxel voxel in chunk1)
        {
            if (voxel.Type != BlockType.Air)
            {
                // Step 2: Get vertices of each voxel
                for (int i = 0; i < voxel.vertices.Length; i++)
                {
                    _vertexesList.Add(voxel.vertices[i]);
                }

                // Step 3: Get triangles of each voxel
                for (int direction = 0; direction < _directions.Length; direction++)
                {
                    if (DoesNeighbourExistOf(voxel.Position, direction, chunk1))
                    {
                        for (int i = 0; i < 6; i++)
                        {
                            _triangleList.Add(voxel.faces[direction, i] + scale);
                        }
                    }
                }
                scale += 24; // 24 Vertexes per voxel
            }
        }
        #endregion

        UpdateMesh(_vertexesList, _triangleList);
    }