Esempio n. 1
0
        /// <summary>
        /// Clears the current mesh and recalculates it from scratch.
        /// Does all required culling based on the chunks passed into it.
        /// Does not create the actual mesh yet; this only calculates it.
        /// </summary>
        private void CreateFaces()
        {
            List <BlockLight> lightList = RenderService.GetAllLightsWithinMaxRange(
                associatedChunkMeshCluster.chunk.WorldPosition());

            // Resist the urge to remove the lists and convert this all to a two-step system of counting the faces and
            // then initializing the arrays to the proper size. Adjacent chunks can change while this calculation is
            // happening, which can result in mis-counts.
            verticesList.Clear();
            uvList.Clear();
            trianglesList.Clear();
            normalsList.Clear();
            colorList.Clear();

            meshArraysIndex = 0;
            for (byte xIttr = 0; xIttr < Chunk.SIZE; xIttr++)
            {
                for (byte zIttr = 0; zIttr < Chunk.SIZE; zIttr++)
                {
                    for (int yIttr = Chunk.SIZE - 1; yIttr >= 0; yIttr--)
                    {
                        CreateFacesAtPosition(xIttr, yIttr, zIttr, lightList);
                    }
                }
            }
        }