public static MeshData BoxData(int x, int y, int z, MeshData meshData, MeshEntry meshPrfb)
    {
        float bottom = 0.5f;
        float yVals  = meshPrfb.ySize - bottom;//
        float xVals  = meshPrfb.xSize / 2f;
        float zVals  = meshPrfb.zSize / 2f;

        //List<float> deformations = new List<float>(8);
        //for(int i = 0; i < meshPrfb.deformPointCount; i++)
        //{
        //    //set a random entry to random dformation
        //    SetRandomIndexValue(meshPrfb, deformations);
        //}

        //Trunk
        //North
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z + zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));

        //East
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));

        //South
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));

        //West
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z - zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));

        //Up
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z - zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));

        return(meshData);
    }
Exemplo n.º 2
0
    static MeshData WestFaceBottomTriangleReversed
        (int x, int y, int z, MeshData meshData, Biome biome, int[,] heightGrid, float steepness, int LODLevel)
    {
        meshData.AddVertex(new Vector3(x, y, z + LODLevel));
        meshData.AddVertex(new Vector3(x, y + LODLevel, z + LODLevel));
        meshData.AddVertex(new Vector3(x, y + LODLevel, z));
        meshData.AddVertex(new Vector3(x, y, z));

        meshData.AddReverseTriTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(biome.geography.GetType(y, steepness)));
        return(meshData);
    }
Exemplo n.º 3
0
    static MeshData SouthFace
        (int x, int y, int z, MeshData meshData, Biome biome, int[,] heightGrid, float steepness, int LODLevel)
    {
        meshData.AddVertex(new Vector3(x, y, z));
        meshData.AddVertex(new Vector3(x, y + LODLevel, z));
        meshData.AddVertex(new Vector3(x + LODLevel, y + LODLevel, z));
        meshData.AddVertex(new Vector3(x + LODLevel, y, z));

        meshData.AddQuadTriangles();
        meshData.uv.AddRange(GetUVs.FaceUVs(biome.geography.GetType(y, steepness)));
        return(meshData);
    }
Exemplo n.º 4
0
    static MeshData UpFace
        (int x, int y, int z, MeshData meshData, Biome biome, int[,] heightGrid, out bool slopedTop, float steepness, int LODLevel)
    {
        slopedTop = false;
        bool nedown = false;
        bool sedown = false;
        bool nwdown = false;
        bool swdown = false;

        Vector3[] vertCollection = new Vector3[4];

        //TODO
        //This can be uncommented again! Is temporarily disabled to have straight blocks without sloped tops
        #region disabled sloped tops
        //if (heightGrid == null)
        //{
        //    if (Chance.GetHeight(x, z + LODLevel, biome, heightGrid) < y + 1 || Chance.GetHeight(x + LODLevel, z, biome, heightGrid) < y + 1 || Chance.GetHeight(x + LODLevel, z + LODLevel, biome, heightGrid) < y + 1)
        //    {
        //        vertCollection[1] = new Vector3(0, -1f, 0);
        //        slopedTop = true;
        //        //steepness = 0.(chunkSize-1)5f;
        //        nedown = true;
        //        //if(Chance.GetHeight(x + LODLevel, z + LODLevel, biome, heightGrid) < y)
        //        //vertCollection[1] = new Vector3(0, -2f, 0);
        //    }
        //    if (Chance.GetHeight(x + LODLevel, z, biome, heightGrid) < y + 1 || Chance.GetHeight(x, z - LODLevel, biome, heightGrid) < y + 1 || Chance.GetHeight(x + LODLevel, z - LODLevel, biome, heightGrid) < y + 1)
        //    {
        //        vertCollection[2] = new Vector3(0, -1f, 0);
        //        slopedTop = true;
        //        //steepness = 0.(chunkSize-1)5f;
        //        sedown = true;
        //        //if(Chance.GetHeight(x + LODLevel, z - LODLevel, biome, heightGrid) < y)
        //        //vertCollection[2] = new Vector3(0, -2f, 0);
        //    }
        //    if (Chance.GetHeight(x - LODLevel, z, biome, heightGrid) < y + 1 || Chance.GetHeight(x, z - LODLevel, biome, heightGrid) < y + 1 || Chance.GetHeight(x - LODLevel, z - LODLevel, biome, heightGrid) < y + 1)
        //    {
        //        vertCollection[3] = new Vector3(0, -1f, 0);
        //        slopedTop = true;
        //        //steepness = 0.(chunkSize-1)5f;
        //        swdown = true;
        //        //if(Chance.GetHeight(x - LODLevel, z - LODLevel, biome, heightGrid) < y)
        //        //vertCollection[3] = new Vector3(0, -2f, 0);
        //    }
        //    if (Chance.GetHeight(x - LODLevel, z, biome, heightGrid) < y + 1 || Chance.GetHeight(x, z + LODLevel, biome, heightGrid) < y + 1 || Chance.GetHeight(x - LODLevel, z + LODLevel, biome, heightGrid) < y + 1)
        //    {
        //        vertCollection[0] = new Vector3(0, -1f, 0);
        //        slopedTop = true;
        //        //steepness = 0.(chunkSize-1)5f;
        //        nwdown = true;
        //        //if(Chance.GetHeight(x - LODLevel, z + LODLevel, biome, heightGrid) < y + 1)
        //        //vertCollection[0] = new Vector3(0, -2f, 0);
        //    }
        //}

        //TODO
        //These were already commented before disabling the sloped tops
        //if (nedown)
        //{
        //    if (Chance.GetHeight(x - LODLevel, z, biome, heightGrid) >= y)
        //        meshData = NorthFaceBottomTriangle(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //    if (Chance.GetHeight(x, z - LODLevel, biome, heightGrid) >= y)
        //        meshData = EastFaceBottomTriangleReversed(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //}

        //if (sedown)
        //{
        //    if (Chance.GetHeight(x, z + LODLevel, biome, heightGrid) >= y)
        //        meshData = EastFaceBottomTriangle(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //    if (Chance.GetHeight(x - LODLevel, z, biome, heightGrid) >= y)
        //        meshData = SouthFaceBottomTriangleReversed(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //}
        //if (swdown)
        //{
        //    if (Chance.GetHeight(x + LODLevel, z, biome, heightGrid) >= y)
        //        meshData = SouthFaceBottomTriangle(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //    if (Chance.GetHeight(x, z + LODLevel, biome, heightGrid) >= y)
        //        meshData = WestFaceBottomTriangleReversed(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //}
        //if (nwdown)
        //{
        //    if (Chance.GetHeight(x, z - LODLevel, biome, heightGrid) >= y)
        //        meshData = WestFaceBottomTriangle(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //    if (Chance.GetHeight(x + LODLevel, z, biome, heightGrid) >= y)
        //        meshData = NorthFaceBottomTriangleReversed(x, y, z, meshData, biome, heightGrid, steepness, LODLevel);
        //}
        #endregion
        int heightRoundedToLod = RoundToLodFrequency(y, LODLevel);
        vertCollection[0] += (new Vector3(x, heightRoundedToLod, z + LODLevel));
        vertCollection[1] += (new Vector3(x + LODLevel, heightRoundedToLod, z + LODLevel));
        vertCollection[2] += (new Vector3(x + LODLevel, heightRoundedToLod, z));
        vertCollection[3] += (new Vector3(x, heightRoundedToLod, z));

        //Add to meshdata
        foreach (Vector3 vert in vertCollection)
        {
            meshData.AddVertex(vert);
        }

        meshData.AddQuadTriangles();
        if (heightGrid == null)
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(biome.geography.GetType(y, steepness)));
        }
        else
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(Cube.Type.Birch_Planks));
        }
        return(meshData);
    }
    public static MeshData BoxData(int x, int y, int z, MeshData meshData, MeshEntry meshPrfb, Cube.Type optionalFace)
    {
        float bottom = 0.5f;
        float yVals  = meshPrfb.ySize - bottom;//
        float xVals  = meshPrfb.xSize / 2f;
        float zVals  = meshPrfb.zSize / 2f;


        //Trunk
        //North
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z + zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        if (meshPrfb.face == Cube.Type.None)
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(optionalFace));
        }
        else
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));
        }

        //East
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        if (meshPrfb.face == Cube.Type.None)
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(optionalFace));
        }
        else
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));
        }

        //South
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        if (meshPrfb.face == Cube.Type.None)
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(optionalFace));
        }
        else
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));
        }

        //West
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y - bottom + meshPrfb.yPos + meshPrfb.difLeftRightYBottom, z - zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        if (meshPrfb.face == Cube.Type.None)
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(optionalFace));
        }
        else
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));
        }

        //Up
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z + zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x + xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos, z - zVals + meshPrfb.zPos));
        meshData.AddVertex(new Vector3(x - xVals + meshPrfb.xPos, y + yVals + meshPrfb.yPos + meshPrfb.difLeftRightYTop, z - zVals + meshPrfb.zPos));
        meshData.AddQuadTriangles();
        if (meshPrfb.face == Cube.Type.None)
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(optionalFace));
        }
        else
        {
            meshData.uv.AddRange(GetUVs.FaceUVs(meshPrfb.face));
        }
        return(meshData);
    }