Beispiel #1
0
        /// <summary>
        /// Done while BuildVBO generating
        /// </summary>
        void GenOcclusionForChunk(CubeChunk3D _chunk, int _chX, int _chY, int _chZ)
        {
            int x, y, z;

            //Reset occlusion map
            Array.Clear(m_abyOcclusionCubeMap, 0, m_abyOcclusionCubeMap.Length);

            //Make occlusion
            SmallCube c;

            for (x = 0; x < CubeArray3D.CHUNKSIZE; x++)
            {
                for (y = 0; y < CubeArray3D.CHUNKSIZE; y++)
                {
                    for (z = 0; z < CubeArray3D.CHUNKSIZE; z++)
                    {
                        _chunk.GetCube(x, y, z, out c);

                        //Opaque
                        if (c.byMatL0 != 0)
                        {
                            _GenOcclusionPerCube(_chX + x, _chY + y, _chZ + z, x, y, z);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Get Cube vvalue at coords
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="_c"></param>
        public void GetCube(int x, int y, int z, out SmallCube _c)
        {
            //Get chunk
            int chX    = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
            int chY    = y >> CHUNKSIZE_OPSHIFT; //y / CHUNKSIZE;
            int chZ    = z >> CHUNKSIZE_OPSHIFT; //z / CHUNKSIZE;
            int offset = (chX * FlattenOffset) + (chZ * CHUNKSIZEY) + chY;

            CubeChunk3D chunk = m_arrayChunks[offset];

            if (chunk == null)
            {
                _c = m_emptyCube;
                return;
            }

            if (chunk.m_array == null)
            {
                _c = chunk.m_solidChunkCube;
                return;
            }

            //Return Cube into chunk
            chX = x - (chX << CHUNKSIZE_OPSHIFT); //x - (bx * CHUNKSIZE);
            chY = y - (chY << CHUNKSIZE_OPSHIFT); //(by * CHUNKSIZE);
            chZ = z - (chZ << CHUNKSIZE_OPSHIFT); //(bz * CHUNKSIZE);

            offset = (chX << FlattenOffsetChunk_OPSHIFT) + (chZ << CHUNKSIZE_OPSHIFT) + chY;

            _c = chunk.m_array[offset];
        }
Beispiel #3
0
        public GenMesh GenerateMesh()
        {
            //VBO
            m_genMesh.Clear();  //Set Dirty too

            int x, y, z;

            for (x = 0; x < m_array.CHUNKSIZEX; x++)
            {
                for (y = 0; y < m_array.CHUNKSIZEY; y++)
                {
                    for (z = 0; z < m_array.CHUNKSIZEZ; z++)
                    {
                        CubeChunk3D chunk = m_array.GetChunk(x, y, z);
                        if (chunk != null)
                        {
                            // PASS 1=> precalcul des occlusions par voxel
                            GenOcclusionForChunk(chunk, x << CubeArray3D.CHUNKSIZE_OPSHIFT, y << CubeArray3D.CHUNKSIZE_OPSHIFT, z << CubeArray3D.CHUNKSIZE_OPSHIFT);

                            // PASS 2=> Calcul des VBO
                            GenChunkVBO(chunk, x << CubeArray3D.CHUNKSIZE_OPSHIFT, y << CubeArray3D.CHUNKSIZE_OPSHIFT, z << CubeArray3D.CHUNKSIZE_OPSHIFT);
                        }
                    }
                }
            }

            m_genMesh.CreateGPUMesh(Game.GraphicsDevice, false);


            return(m_genMesh);
        }
Beispiel #4
0
        //Generate cubes for a chunk
        //.position in chunk idx
        void GenChunkVBO(CubeChunk3D _chunk, int _chX, int _chY, int _chZ)
        {
            SmallCube c;
            int       x, y, z;

            for (x = 0; x < CubeArray3D.CHUNKSIZE; x++)
            {
                for (y = 0; y < CubeArray3D.CHUNKSIZE; y++)
                {
                    for (z = 0; z < CubeArray3D.CHUNKSIZE; z++)
                    {
                        _chunk.GetCube(x, y, z, out c);
                        if (c.byMatL0 != 0)
                        {
                            GenCubeVBO2(c, _chX + x, _chY + y, _chZ + z, x, y, z);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Set Cube value at coords
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <param name="st"></param>
        public void SetCube(int x, int y, int z, SmallCube st)
        {
            int         chX    = x >> CHUNKSIZE_OPSHIFT; //x / CHUNKSIZE;
            int         chY    = y >> CHUNKSIZE_OPSHIFT; //y / CHUNKSIZE;
            int         chZ    = z >> CHUNKSIZE_OPSHIFT; //z / CHUNKSIZE;
            int         offset = (chX * FlattenOffset) + (chZ * CHUNKSIZEY) + chY;
            CubeChunk3D chunk  = m_arrayChunks[offset];

            if (chunk == null)
            {
                chunk = new CubeChunk3D();
                m_arrayChunks[offset] = chunk;
            }

            chX = x - (chX << CHUNKSIZE_OPSHIFT); //x - (bx * CHUNKSIZE);
            chY = y - (chY << CHUNKSIZE_OPSHIFT); //y - (by * CHUNKSIZE);
            chZ = z - (chZ << CHUNKSIZE_OPSHIFT); //z - (bz * CHUNKSIZE);

            chunk.SetCube(chX, chY, chZ, st);
        }