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.getBlockSmart(nextX, nextY, nextZ)); if (isCurrentVisible && !isNextOpacity) { BlockSurface surface = new BlockSurface(new Vector3(x, y, z), block, 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); }
public bool[] getEntityArray(BlockTypeFunBase blockType) { bool[] data = new bool[Const.ChunkSize * Const.ChunkSize * Const.ChunkSize]; for (int i = 0; i < blocks.Length; i++) { int x = i % Const.ChunkSize; int y = (i / Const.ChunkSize) % Const.ChunkSize; int z = i / (Const.ChunkSize * Const.ChunkSize); data[i] = blockType.isOpacity(blocks[x, y, z]); } return(data); }
private static float getVertexSmallAo(BlockChunk blocks, 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(blocks.getBlockSmart(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(blocks.getBlockSmart(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(blocks.getBlockSmart(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); }
public List <VecInt3>[] calcSurfaceList() { BlockTypeFunBase fun = blockTypeFun; if (isSurfaceDirty) { isSurfaceDirty = false; surfaceList = new List <VecInt3> [6]; for (int f = 0; f < 6; f++) { surfaceList[f] = new List <VecInt3>(); } for (int z = 0; z < Const.ChunkSize; z++) { for (int y = 0; y < Const.ChunkSize; y++) { bool bOldIsEntity = fun.isOpacity(getBlockSmart(-1, y, z)); for (int x = 0; x < Const.ChunkSize; x++) { bool bCurIsEntity = fun.isOpacity(getBlock(x, y, z)); if (bCurIsEntity && !bOldIsEntity) { surfaceList[(int)Face.FNI_x0].Add(new VecInt3(x, y, z)); } else if (bOldIsEntity && (!bCurIsEntity) && x >= 1) { surfaceList[(int)Face.FNI_x1].Add(new VecInt3(x - 1, y, z)); } bOldIsEntity = bCurIsEntity; } if (bOldIsEntity && !fun.isOpacity(getBlockSmart(Const.ChunkSize, y, z))) { surfaceList[(int)Face.FNI_x1].Add(new VecInt3(Const.ChunkSize - 1, y, z)); } } } for (int z = 0; z < Const.ChunkSize; z++) { for (int x = 0; x < Const.ChunkSize; x++) { bool bOldIsEntity = fun.isOpacity(getBlockSmart(x, -1, z)); for (int y = 0; y < Const.ChunkSize; y++) { bool bCurIsEntity = fun.isOpacity(getBlock(x, y, z)); if (bCurIsEntity && !bOldIsEntity) { surfaceList[(int)Face.FNI_y0].Add(new VecInt3(x, y, z)); } else if (bOldIsEntity && (!bCurIsEntity) && y >= 1) { surfaceList[(int)Face.FNI_y1].Add(new VecInt3(x, y - 1, z)); } bOldIsEntity = bCurIsEntity; } if (bOldIsEntity && !fun.isOpacity(getBlockSmart(x, Const.ChunkSize, z))) { surfaceList[(int)Face.FNI_y1].Add(new VecInt3(x, Const.ChunkSize - 1, z)); } } } for (int x = 0; x < Const.ChunkSize; x++) { for (int y = 0; y < Const.ChunkSize; y++) { bool bOldIsEntity = fun.isOpacity(getBlockSmart(x, y, -1)); for (int z = 0; z < Const.ChunkSize; z++) { bool bCurIsEntity = fun.isOpacity(getBlock(x, y, z)); if (bCurIsEntity && !bOldIsEntity) { surfaceList[(int)Face.FNI_z0].Add(new VecInt3(x, y, z)); } else if (bOldIsEntity && (!bCurIsEntity) && z >= 1) { surfaceList[(int)Face.FNI_z1].Add(new VecInt3(x, y, z - 1)); } bOldIsEntity = bCurIsEntity; } if (bOldIsEntity && !fun.isOpacity(getBlockSmart(x, y, Const.ChunkSize))) { surfaceList[(int)Face.FNI_z1].Add(new VecInt3(x, y, Const.ChunkSize - 1)); } } } } return(surfaceList); }