예제 #1
0
파일: MeshTool.cs 프로젝트: wachel/block
        public static List <BlockSurface> getChunkSurface(BlockChunk chunk, BlockTypeFunBase blockFun, int normalIndex)
        {
            int stepX = normalIndex == 0 ? -1 : (normalIndex == 1 ? 1 : 0);
            int stepY = normalIndex == 2 ? -1 : (normalIndex == 3 ? 1 : 0);
            int stepZ = normalIndex == 4 ? -1 : (normalIndex == 5 ? 1 : 0);
            List <BlockSurface> surfacePoints = new List <BlockSurface>();

            for (int x = 0; x < Const.ChunkSize; x++)
            {
                for (int y = 0; y < Const.ChunkSize; y++)
                {
                    for (int z = 0; z < Const.ChunkSize; z++)
                    {
                        int   nextX            = x + stepX;
                        int   nextY            = y + stepY;
                        int   nextZ            = z + stepZ;
                        short block            = chunk.getBlock(x, y, z);
                        bool  isCurrentVisible = blockFun.isVisible(block);
                        bool  isNextOpacity    = blockFun.isOpacity(chunk.getBlock(nextX, nextY, nextZ));
                        if (isCurrentVisible && !isNextOpacity)
                        {
                            BlockSurface surface = new BlockSurface(new VecInt3(x, y, z), block, new float[4], new float[4], new float[4]);
                            for (int v = 0; v < 4; v++)
                            {
                                surface.smallAo[v] = getVertexSmallAo(chunk, blockFun, x, y, z, normalIndex, v);
                            }
                            surfacePoints.Add(surface);
                        }
                    }
                }
            }
            return(surfacePoints);
        }
예제 #2
0
파일: MeshTool.cs 프로젝트: wachel/block
        public static bool[, ,] GetVisibleBlocks(BlockChunk chunk, BlockTypeFunBase blockFun)
        {
            bool[, ,] blocks = new bool[Const.ChunkSize, Const.ChunkSize, Const.ChunkSize];
            for (int normalIndex = 0; normalIndex < 6; normalIndex++)
            {
                int stepX = normalIndex == 0 ? -1 : (normalIndex == 1 ? 1 : 0);
                int stepY = normalIndex == 2 ? -1 : (normalIndex == 3 ? 1 : 0);
                int stepZ = normalIndex == 4 ? -1 : (normalIndex == 5 ? 1 : 0);
                for (int x = 0; x < Const.ChunkSize; x++)
                {
                    for (int y = 0; y < Const.ChunkSize; y++)
                    {
                        for (int z = 0; z < Const.ChunkSize; z++)
                        {
                            int   nextX = x + stepX;
                            int   nextY = y + stepY;
                            int   nextZ = z + stepZ;
                            short block = chunk.getBlock(x, y, z);
                            if (block != 0)
                            {
                                bool  isCurrentVisible = blockFun.isCollider(block);
                                short nextBlock        = chunk.getBlock(nextX, nextY, nextZ);

                                bool isNextOpacity = blockFun.isCollider(nextBlock);
                                if (isCurrentVisible && !isNextOpacity)
                                {
                                    blocks[x, y, z] = true;
                                }
                            }
                        }
                    }
                }
            }
            return(blocks);
        }
예제 #3
0
파일: MeshTool.cs 프로젝트: wachel/block
        private static float getVertexSmallAo(BlockChunk chunk, BlockTypeFunBase blockFun, int x, int y, int z, int faceIndex, int vertixIndex)
        {
            float rlt = 1.0f;

            int  offset0X = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 0, 0];
            int  offset0Y = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 0, 1];
            int  offset0Z = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 0, 2];
            bool bBlock0  = blockFun.isOpacity(chunk.getBlock(x + offset0X, y + offset0Y, z + offset0Z));

            int  offset1X = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 1, 0];
            int  offset1Y = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 1, 1];
            int  offset1Z = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 1, 2];
            bool bBlock1  = blockFun.isOpacity(chunk.getBlock(x + offset1X, y + offset1Y, z + offset1Z));

            int  offset2X = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 2, 0];
            int  offset2Y = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 2, 1];
            int  offset2Z = Const.VertexAdjacencyOffset[faceIndex, vertixIndex, 2, 2];
            bool bBlock2  = blockFun.isOpacity(chunk.getBlock(x + offset2X, y + offset2Y, z + offset2Z));

            if (bBlock0 && bBlock2)  //如果两个共边对角块都是实体,则共点对角块存不存在已经无所谓,说明是三面内角
            {
                rlt *= 0.7f;
            }
            else if ((bBlock0 && bBlock1) || (bBlock1 && bBlock2))  //如果有一个共边对角块和一个共点对角块,则说明是阶梯的内角
            {
                rlt *= 0.8f;
            }
            else if (bBlock0 || bBlock1 || bBlock2)
            {
                rlt *= 0.8f;
            }
            else
            {
                rlt *= 1.0f;
            }
            return(rlt);
        }