bool GenerateTiles(MapDataStore data, out CPUMesh tiles, out CPUMesh stencilTiles, out CPUMesh transparentTiles, out CPUMesh topTiles, out CPUMesh topStencilTiles, out CPUMesh topTransparentTiles, out CPUMesh collisionTiles, TempBuffers temp)
    {
        int block_x                = data.SliceOrigin.x / GameMap.blockSize;
        int block_y                = data.SliceOrigin.y / GameMap.blockSize;
        int block_z                = data.SliceOrigin.z;
        int bufferIndex            = 0;
        int stencilBufferIndex     = 0;
        int transparentBufferIndex = 0;
        int collisionIndex         = 0;

        for (int xx = (block_x * GameMap.blockSize); xx < (block_x + 1) * GameMap.blockSize; xx++)
        {
            for (int yy = (block_y * GameMap.blockSize); yy < (block_y + 1) * GameMap.blockSize; yy++)
            {
                if (!data.InSliceBounds(new DFCoord(xx, yy, block_z)))
                {
                    throw new UnityException("OOB");
                }
                if (data[xx, yy, block_z] == null)
                {
                    continue;
                }

                for (int i = 0; i < (int)MeshLayer.Count; i++)
                {
                    if (i < (int)MeshLayer.StaticCutout)
                    {
                        FillMeshBuffer(out temp.meshBuffer[bufferIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        bufferIndex++;
                    }
                    else if (i < (int)MeshLayer.StaticTransparent)
                    {
                        FillMeshBuffer(out temp.stencilMeshBuffer[stencilBufferIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        stencilBufferIndex++;
                    }
                    else if (i < (int)MeshLayer.Collision)
                    {
                        FillMeshBuffer(out temp.transparentMeshBuffer[transparentBufferIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        transparentBufferIndex++;
                    }
                    else
                    {
                        FillMeshBuffer(out temp.collisionMeshBuffer[collisionIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        collisionIndex++;
                    }
                }
            }
        }
        bool dontCare, success;

        stencilTiles        = MeshCombineUtility.ColorCombine(temp.stencilMeshBuffer, out dontCare, false);
        topStencilTiles     = MeshCombineUtility.ColorCombine(temp.stencilMeshBuffer, out dontCare, true);
        transparentTiles    = MeshCombineUtility.ColorCombine(temp.transparentMeshBuffer, out dontCare, false);
        topTransparentTiles = MeshCombineUtility.ColorCombine(temp.transparentMeshBuffer, out dontCare, true);
        topTiles            = MeshCombineUtility.ColorCombine(temp.meshBuffer, out dontCare, true);
        tiles          = MeshCombineUtility.ColorCombine(temp.meshBuffer, out success, false);
        collisionTiles = MeshCombineUtility.ColorCombine(temp.collisionMeshBuffer, out dontCare, false);

        return(success);
    }
Example #2
0
    bool GenerateTiles(
        MapDataStore data,
        out CPUMesh tiles,
        out CPUMesh stencilTiles,
        out CPUMesh transparentTiles,
        out CPUMesh topTiles,
        out CPUMesh topStencilTiles,
        out CPUMesh topTransparentTiles,
        out CPUMesh collisionTiles,
        out CPUMesh terrainTiles,
        out CPUMesh topTerrainTiles)
    {
        int block_x                = data.SliceOrigin.x / GameMap.blockSize;
        int block_y                = data.SliceOrigin.y / GameMap.blockSize;
        int block_z                = data.SliceOrigin.z;
        int bufferIndex            = 0;
        int stencilBufferIndex     = 0;
        int transparentBufferIndex = 0;
        int collisionIndex         = 0;
        int terrainIndex           = 0;

        GameMap.BeginSample("Fill Mesh Buffer");
        for (int i = 0; i < (int)MeshLayer.Count; i++)
        {
            for (int xx = (block_x * GameMap.blockSize); xx < (block_x + 1) * GameMap.blockSize; xx++)
            {
                for (int yy = (block_y * GameMap.blockSize); yy < (block_y + 1) * GameMap.blockSize; yy++)
                {
                    if (!data.InSliceBounds(new DFCoord(xx, yy, block_z)))
                    {
                        throw new UnityException("OOB");
                    }
                    if (data[xx, yy, block_z] == null)
                    {
                        continue;
                    }

                    if (i < (int)MeshLayer.StaticCutout)
                    {
                        FillMeshBuffer(
                            out meshBuffer[bufferIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                                                   yy - (block_y * GameMap.blockSize),
                                                   -GameMap.MapZOffset));
                        bufferIndex++;
                    }
                    else if (i < (int)MeshLayer.StaticTransparent)
                    {
                        FillMeshBuffer(
                            out stencilMeshBuffer[stencilBufferIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                                                   yy - (block_y * GameMap.blockSize),
                                                   -GameMap.MapZOffset));
                        stencilBufferIndex++;
                    }
                    else if (i < (int)MeshLayer.Collision)
                    {
                        FillMeshBuffer(
                            out transparentMeshBuffer[transparentBufferIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                                                   yy - (block_y * GameMap.blockSize),
                                                   -GameMap.MapZOffset));
                        transparentBufferIndex++;
                    }
                    else if (i < (int)MeshLayer.NaturalTerrain)
                    {
                        FillMeshBuffer(
                            out collisionMeshBuffer[collisionIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                                                   yy - (block_y * GameMap.blockSize),
                                                   -GameMap.MapZOffset));
                        collisionIndex++;
                    }
                    else if (i == (int)MeshLayer.NaturalTerrain)
                    {
                        FillMeshBuffer(out terrainMeshBuffer[terrainIndex],
                                       (MeshLayer)i,
                                       data[xx, yy, block_z],
                                       GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                                                              yy - (block_y * GameMap.blockSize),
                                                              -GameMap.MapZOffset));
                        terrainIndex++;
                    }
                }
            }
        }
        GameMap.EndSample();
        bool dontCare, success;

        GameMap.BeginSample("Generate Voxels");
        VoxelGenerator voxelGen = new VoxelGenerator();

        if (block_z == 0)
        {
            voxelGen.bottomless = true;
        }
        var naturalTerrain = voxelGen.Triangulate(data);

        GameMap.EndSample();
        GameMap.BeginSample("Combine Meshes");
        terrainTiles        = MeshCombineUtility.ColorCombine(terrainMeshBuffer, out dontCare, false, naturalTerrain);
        topTerrainTiles     = MeshCombineUtility.ColorCombine(terrainMeshBuffer, out dontCare, true);
        stencilTiles        = MeshCombineUtility.ColorCombine(stencilMeshBuffer, out dontCare, false);
        topStencilTiles     = MeshCombineUtility.ColorCombine(stencilMeshBuffer, out dontCare, true);
        transparentTiles    = MeshCombineUtility.ColorCombine(transparentMeshBuffer, out dontCare, false);
        topTransparentTiles = MeshCombineUtility.ColorCombine(transparentMeshBuffer, out dontCare, true);
        topTiles            = MeshCombineUtility.ColorCombine(meshBuffer, out dontCare, true);
        tiles          = MeshCombineUtility.ColorCombine(meshBuffer, out success, false);
        collisionTiles = MeshCombineUtility.ColorCombine(collisionMeshBuffer, out dontCare, false, naturalTerrain);
        GameMap.EndSample();

        return(success);
    }
Example #3
0
    bool GenerateTiles(MapDataStore data, out CPUMesh tiles, out CPUMesh stencilTiles, out CPUMesh transparentTiles, out CPUMesh topTiles, out CPUMesh topStencilTiles, out CPUMesh topTransparentTiles, TempBuffers temp)
    {
        int block_x = data.SliceOrigin.x / GameMap.blockSize;
        int block_y = data.SliceOrigin.y / GameMap.blockSize;
        int block_z = data.SliceOrigin.z;
        int bufferIndex = 0;
        int stencilBufferIndex = 0;
        int transparentBufferIndex = 0;
        for (int xx = (block_x * GameMap.blockSize); xx < (block_x + 1) * GameMap.blockSize; xx++)
            for (int yy = (block_y * GameMap.blockSize); yy < (block_y + 1) * GameMap.blockSize; yy++)
            {
                if (!data.InSliceBounds(new DFCoord(xx, yy, block_z))) throw new UnityException("OOB");
                if (data[xx, yy, block_z] == null) continue;

                for (int i = 0; i < (int)MeshLayer.Count; i++)
                {
                    if (i < (int)MeshLayer.StaticCutout)
                    {
                        FillMeshBuffer(out temp.meshBuffer[bufferIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        bufferIndex++;
                    }
                    else if (i < (int)MeshLayer.StaticTransparent)
                    {
                        FillMeshBuffer(out temp.stencilMeshBuffer[stencilBufferIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        stencilBufferIndex++;
                    }
                    else
                    {
                        FillMeshBuffer(out temp.transparentMeshBuffer[transparentBufferIndex], (MeshLayer)i, data[xx, yy, block_z], GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize), yy - (block_y * GameMap.blockSize), -GameMap.MapZOffset));
                        transparentBufferIndex++;
                    }
                }
            }
        bool dontCare, success;
        stencilTiles = MeshCombineUtility.ColorCombine(temp.stencilMeshBuffer, out dontCare, false);
        topStencilTiles = MeshCombineUtility.ColorCombine(temp.stencilMeshBuffer, out dontCare, true);
        transparentTiles = MeshCombineUtility.ColorCombine(temp.transparentMeshBuffer, out dontCare, false);
        topTransparentTiles = MeshCombineUtility.ColorCombine(temp.transparentMeshBuffer, out dontCare, true);
        topTiles = MeshCombineUtility.ColorCombine(temp.meshBuffer, out dontCare, true);
        tiles = MeshCombineUtility.ColorCombine(temp.meshBuffer, out success, false);

        return success;
    }
    bool GenerateTiles(MapDataStore data, out MeshData tiles, out MeshData stencilTiles, TempBuffers temp)
    {
        int block_x = data.SliceOrigin.x / GameMap.blockSize;
        int block_y = data.SliceOrigin.y / GameMap.blockSize;
        int block_z = data.SliceOrigin.z;
        int bufferIndex = 0;
        int stencilBufferIndex = 0;
        for (int xx = (block_x * GameMap.blockSize); xx < (block_x + 1) * GameMap.blockSize; xx++)
            for (int yy = (block_y * GameMap.blockSize); yy < (block_y + 1) * GameMap.blockSize; yy++)
            {
                if (!data.InSliceBounds(new DFCoord(xx, yy, block_z))) throw new UnityException("OOB");
                if (data[xx, yy, block_z] == null) continue;

                for (int i = 0; i < (int)MeshLayer.Count; i++)
                {
                    MeshLayer layer = (MeshLayer)i;
                    switch (layer)
                    {
                        case MeshLayer.StaticMaterial:
                        case MeshLayer.BaseMaterial:
                        case MeshLayer.LayerMaterial:
                        case MeshLayer.VeinMaterial:
                        case MeshLayer.NoMaterial:
                            FillMeshBuffer(out temp.meshBuffer[bufferIndex], layer, data[xx, yy, block_z].Value);
                            bufferIndex++;
                            break;
                        case MeshLayer.StaticCutout:
                        case MeshLayer.BaseCutout:
                        case MeshLayer.LayerCutout:
                        case MeshLayer.VeinCutout:
                        case MeshLayer.Growth0Cutout:
                        case MeshLayer.Growth1Cutout:
                        case MeshLayer.Growth2Cutout:
                        case MeshLayer.Growth3Cutout:
                        case MeshLayer.NoMaterialCutout:
                            FillMeshBuffer(out temp.stencilMeshBuffer[stencilBufferIndex], layer, data[xx, yy, block_z].Value);
                            stencilBufferIndex++;
                            break;
                        default:
                            break;
                    }
                }
            }
        bool dontCare, success;
        stencilTiles = MeshCombineUtility.ColorCombine(temp.stencilMeshBuffer, out dontCare);
        tiles = MeshCombineUtility.ColorCombine(temp.meshBuffer, out success);

        return success;
    }
Example #5
0
    bool GenerateTiles(MapDataStore data, out CPUMesh tiles, out CPUMesh stencilTiles, out CPUMesh transparentTiles, out CPUMesh topTiles, out CPUMesh topStencilTiles, out CPUMesh topTransparentTiles, out CPUMesh collisionTiles, out CPUMesh terrainTiles, out CPUMesh topTerrainTiles)
    {
        int block_x = data.SliceOrigin.x / GameMap.blockSize;
        int block_y = data.SliceOrigin.y / GameMap.blockSize;
        int block_z = data.SliceOrigin.z;
        int bufferIndex = 0;
        int stencilBufferIndex = 0;
        int transparentBufferIndex = 0;
        int collisionIndex = 0;
        int terrainIndex = 0;
        for (int xx = (block_x * GameMap.blockSize); xx < (block_x + 1) * GameMap.blockSize; xx++)
            for (int yy = (block_y * GameMap.blockSize); yy < (block_y + 1) * GameMap.blockSize; yy++)
            {
                if (!data.InSliceBounds(new DFCoord(xx, yy, block_z))) throw new UnityException("OOB");
                if (data[xx, yy, block_z] == null) continue;

                for (int i = 0; i < (int)MeshLayer.Count; i++)
                {
                    if (i < (int)MeshLayer.StaticCutout)
                    {
                        FillMeshBuffer(
                            out meshBuffer[bufferIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                            yy - (block_y * GameMap.blockSize),
                            -GameMap.MapZOffset));
                        bufferIndex++;
                    }
                    else if (i < (int)MeshLayer.StaticTransparent)
                    {
                        FillMeshBuffer(
                            out stencilMeshBuffer[stencilBufferIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                            yy - (block_y * GameMap.blockSize),
                            -GameMap.MapZOffset));
                        stencilBufferIndex++;
                    }
                    else if (i < (int)MeshLayer.Collision)
                    {
                        FillMeshBuffer(
                            out transparentMeshBuffer[transparentBufferIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                            yy - (block_y * GameMap.blockSize),
                            -GameMap.MapZOffset));
                        transparentBufferIndex++;
                    }
                    else if (i < (int)MeshLayer.NaturalTerrain)
                    {
                        FillMeshBuffer(
                            out collisionMeshBuffer[collisionIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                            yy - (block_y * GameMap.blockSize),
                            -GameMap.MapZOffset));
                        collisionIndex++;
                    }
                    else if(i == (int)MeshLayer.NaturalTerrain)
                    {
                        FillMeshBuffer(out terrainMeshBuffer[terrainIndex],
                            (MeshLayer)i,
                            data[xx, yy, block_z],
                            GameMap.DFtoUnityCoord(xx - (block_x * GameMap.blockSize),
                            yy - (block_y * GameMap.blockSize),
                            -GameMap.MapZOffset));
                        terrainIndex++;
                    }
                }
            }
        bool dontCare, success;
        VoxelGenerator voxelGen = new VoxelGenerator();
        if (block_z == 0)
            voxelGen.bottomless = true;
        terrainTiles = voxelGen.Triangulate(data);
        terrainTiles = MeshCombineUtility.ColorCombine(terrainMeshBuffer, out dontCare, false, terrainTiles);
        topTerrainTiles = MeshCombineUtility.ColorCombine(terrainMeshBuffer, out dontCare, true);
        stencilTiles = MeshCombineUtility.ColorCombine(stencilMeshBuffer, out dontCare, false);
        topStencilTiles = MeshCombineUtility.ColorCombine(stencilMeshBuffer, out dontCare, true);
        transparentTiles = MeshCombineUtility.ColorCombine(transparentMeshBuffer, out dontCare, false);
        topTransparentTiles = MeshCombineUtility.ColorCombine(transparentMeshBuffer, out dontCare, true);
        topTiles = MeshCombineUtility.ColorCombine(meshBuffer, out dontCare, true);
        tiles = MeshCombineUtility.ColorCombine(meshBuffer, out success, false);
        collisionTiles = MeshCombineUtility.ColorCombine(collisionMeshBuffer, out dontCare, false);

        return success;
    }
    bool GenerateTiles(MapDataStore data, out MeshData tiles, out MeshData stencilTiles, TempBuffers temp)
    {
        int block_x            = data.SliceOrigin.x / GameMap.blockSize;
        int block_y            = data.SliceOrigin.y / GameMap.blockSize;
        int block_z            = data.SliceOrigin.z;
        int bufferIndex        = 0;
        int stencilBufferIndex = 0;

        for (int xx = (block_x * GameMap.blockSize); xx < (block_x + 1) * GameMap.blockSize; xx++)
        {
            for (int yy = (block_y * GameMap.blockSize); yy < (block_y + 1) * GameMap.blockSize; yy++)
            {
                if (!data.InSliceBounds(new DFCoord(xx, yy, block_z)))
                {
                    throw new UnityException("OOB");
                }
                if (data[xx, yy, block_z] == null)
                {
                    continue;
                }

                for (int i = 0; i < (int)MeshLayer.Count; i++)
                {
                    MeshLayer layer = (MeshLayer)i;
                    switch (layer)
                    {
                    case MeshLayer.StaticMaterial:
                    case MeshLayer.BaseMaterial:
                    case MeshLayer.LayerMaterial:
                    case MeshLayer.VeinMaterial:
                    case MeshLayer.NoMaterial:
                        FillMeshBuffer(out temp.meshBuffer[bufferIndex], layer, data[xx, yy, block_z].Value);
                        bufferIndex++;
                        break;

                    case MeshLayer.StaticCutout:
                    case MeshLayer.BaseCutout:
                    case MeshLayer.LayerCutout:
                    case MeshLayer.VeinCutout:
                    case MeshLayer.Growth0Cutout:
                    case MeshLayer.Growth1Cutout:
                    case MeshLayer.Growth2Cutout:
                    case MeshLayer.Growth3Cutout:
                    case MeshLayer.NoMaterialCutout:
                        FillMeshBuffer(out temp.stencilMeshBuffer[stencilBufferIndex], layer, data[xx, yy, block_z].Value);
                        stencilBufferIndex++;
                        break;

                    default:
                        break;
                    }
                }
            }
        }
        bool dontCare, success;

        stencilTiles = MeshCombineUtility.ColorCombine(temp.stencilMeshBuffer, out dontCare);
        tiles        = MeshCombineUtility.ColorCombine(temp.meshBuffer, out success);

        return(success);
    }