Esempio n. 1
0
 /// <summary>
 /// Writes a boolean array of which points are active
 /// </summary>
 /// <param name="size">Vector3 of the Chunk size to be generated</param>
 void VertexWrite(Vector3 size)
 {
     for (int i = 0; i < size.x; i++)
     {
         for (int j = 0; j < size.y; j++)
         {
             for (int k = 0; k < size.z; k++)
             {
                 HexCell       center        = new HexCell(i, j, k);
                 HexWorldCoord shiftedCenter = HexToWorldHex(center.ToHexCoord());
                 if (world.GradientCheck(shiftedCenter))
                 {
                     vertexes[i, j, k] = true;
                     if (world.pointMode == PointMode.Gradient)
                     {
                         CreatePoint(center.ToHexCoord());
                     }
                 }
                 if (world.pointMode == PointMode.All)
                 {
                     CreatePoint(center.ToHexCoord());
                 }
             }
         }
     }
 }
Esempio n. 2
0
    /// <summary>
    /// Send mesh data to the mesh and apply after affects
    /// </summary>
    void MeshProcedure()
    {
        List <Vector3> posVerts = new List <Vector3>();

        foreach (HexCell hexCell in verts)
        {
            HexCoord      hex   = hexCell.ToHexCoord();
            HexWorldCoord point = HexToWorldHex(hex);
            normals.Add(GetNormal(hex));
            Vector3 offset = new Vector3();
            Vector3 smooth = new Vector3();
            if (world.smoothLand)
            {
                Vector3 norm = GetNormal(hex);
                norm = norm.normalized * sqrt3 / 2;
                float A = GetNoise(PosToHex(World.HexToPos(point) + norm));
                float B = GetNoise(PosToHex(World.HexToPos(point) - norm));
                float T = 0;
                smooth = norm.normalized * ((A + B) / 2 - T) / ((A - B) / 2) * -sqrt3 / 2;
            }
            if (world.offsetLand)
            {
                offset = .4f * World.GetNormalNonTerrain((HexToPos(hexCell) + smooth) * 27);
            }
            posVerts.Add(HexToPos(hexCell) + offset + smooth);
        }
        mesh.SetVertices(posVerts);
        mesh.SetTriangles(tris, 0);
        mesh.SetNormals(normals);
    }
Esempio n. 3
0
    /// <summary>
    /// Checks if a point is on the edge of a surface using IVT and gradients
    /// </summary>
    /// <param name="point">Hex point to check</param>
    /// <returns>Boolean</returns>
    public bool GradientCheck(HexWorldCoord point)
    {
        Vector3 pos = HexToPos(point);

        if (pos.y <= heightBoundary + 1 && pos.y > heightBoundary - 1)
        {
            return(BoundaryGradientCheck(point));
        }
        Vector3 gradient = GetNormal(point);

        gradient = gradient.normalized;
        if (!Land(point + PosToHex(gradient)) && Land(point - PosToHex(gradient)))
        {
            return(true);
        }

        //Vector3 gradientHigh = GetNormal(point + PosToHex(gradient * 0.5f));
        //Vector3 gradientLow = GetNormal(point - PosToHex(gradient * 0.5f));
        //gradientHigh = gradientHigh.normalized * Chunk.sqrt3 * 0.25f;
        //gradientLow = gradientLow.normalized * Chunk.sqrt3 * 0.25f;
        //if (!Land(point + PosToHex(gradient * 0.5f) + PosToHex(gradientHigh)) && Land(point - PosToHex(gradient * 0.5f) + PosToHex(gradientLow)))
        //    return true;

        return(false);
    }
Esempio n. 4
0
    public HexWorldCoord ToHexWorldCoord()
    {
        HexWorldCoord output = new HexWorldCoord();

        output.x = x;
        output.y = y;
        output.z = z;
        return(output);
    }
Esempio n. 5
0
    public static Vector3 HexToPos(HexWorldCoord point)
    {
        Vector3 output;

        output.x = h2P[0].x * point.x + h2P[0].y * point.y + h2P[0].z * point.z;
        output.y = h2P[1].x * point.x + h2P[1].y * point.y + h2P[1].z * point.z;
        output.z = h2P[2].x * point.x + h2P[2].y * point.y + h2P[2].z * point.z;
        return(output);
    }
Esempio n. 6
0
    public static Vector3 ChunkToPos(ChunkCoord chunkCoord)
    {
        HexWorldCoord output;

        output.x = chunkCoord.x * Chunk.chunkSize;
        output.y = chunkCoord.y * Chunk.chunkSize;
        output.z = chunkCoord.z * Chunk.chunkSize;
        output  += new HexWorldCoord(1, 1, 1);
        return(HexToPos(output));
    }
Esempio n. 7
0
    public static ChunkCoord PosToChunk(Vector3 point)
    {
        HexWorldCoord hex = PosToHex(point);
        ChunkCoord    output;

        output.x = Mathf.FloorToInt((hex.x + .5f) / Chunk.chunkSize);
        output.y = Mathf.FloorToInt((hex.y + .5f) / Chunk.chunkSize);
        output.z = Mathf.FloorToInt((hex.z + .5f) / Chunk.chunkSize);
        return(output);
    }
Esempio n. 8
0
    float GetNoiseAbove(HexWorldCoord hex)
    {
        Vector3 pos   = HexToPos(hex);
        float   noise = Procedural.Noise.noiseMethods[2][2](hex.ToVector3(), noiseScale, worldName.GetHashCode()).value * 20 + hex.y * thresDropOff;

        if (island)
        {
            noise += 100 * Mathf.Pow(islandDropOff, (Mathf.Pow(pos.x, 2) + Mathf.Pow(pos.z, 2)) - 10386);
        }
        return(noise);
    }
Esempio n. 9
0
    Vector3 GetNormalAbove(HexWorldCoord hex)
    {
        Vector3 pos = HexToPos(hex);
        Vector3 gradient;

        gradient = Procedural.Noise.noiseMethods[2][2](hex.ToVector3(), noiseScale, worldName.GetHashCode()).derivative * 20 + new Vector3(0, thresDropOff, 0);
        if (island)
        {
            gradient += 100 * new Vector3(pos.x * Mathf.Log(islandDropOff) * Mathf.Pow(islandDropOff, (Mathf.Pow(pos.x, 2) + Mathf.Pow(pos.z, 2)) - 10386), 0, pos.z * Mathf.Log(islandDropOff) * Mathf.Pow(islandDropOff, (Mathf.Pow(pos.x, 2) + Mathf.Pow(pos.z, 2)) - 10386));
        }
        return(gradient);
    }
Esempio n. 10
0
    public float GetNoise(HexWorldCoord hex)
    {
        Vector3 pos = HexToPos(hex);

        if (pos.y > heightBoundary)
        {
            return(GetNoiseAbove(hex));
        }
        else
        {
            return(GetNoiseBelow(hex));
        }
    }
Esempio n. 11
0
    bool BoundaryGradientCheck(HexWorldCoord point)
    {
        Vector3 pos           = HexToPos(point);
        Vector3 gradientAbove = GetNormalAbove(point).normalized;
        Vector3 gradientBelow = GetNormalBelow(point).normalized;
        Vector3 gradientDown  = -GetNormal(point);

        gradientDown = new Vector3(gradientDown.x, 0, gradientDown.z).normalized;
        if ((!Land(point + PosToHex(gradientAbove)) || !Land(point + PosToHex(gradientBelow))) && Land(point + PosToHex(gradientDown)))
        {
            return(true);
        }
        return(false);
    }
Esempio n. 12
0
    public bool Land(HexWorldCoord point, int forcedLocation = 0)
    {
        switch (forcedLocation)
        {
        case -1:
            return(GetNoiseBelow(point) < threshold);

        case 1:
            return(GetNoiseAbove(point) < threshold);

        default:
            return(GetNoise(point) < threshold);
        }
    }
Esempio n. 13
0
    float GetNoiseBelow(HexWorldCoord hex)
    {
        Vector3       pos     = HexToPos(hex);
        Vector3       basePos = new Vector3(pos.x, heightBoundary, pos.z);
        HexWorldCoord baseHex = PosToHex(basePos);
        float         noise   = Procedural.Noise.noiseMethods[2][2](baseHex.ToVector3(), noiseScale, worldName.GetHashCode()).value * 20 + baseHex.y * thresDropOff;

        if (island)
        {
            noise += 100 * Mathf.Pow(islandDropOff, (Mathf.Pow(basePos.x, 2) + Mathf.Pow(basePos.z, 2)) - 10386);
        }
        noise += 5 * (Mathf.Pow(-pos.y + heightBoundary, 0.35f));
        return(noise);
    }
Esempio n. 14
0
    Vector3 GetNormalBelow(HexWorldCoord hex)
    {
        Vector3       pos = HexToPos(hex);
        Vector3       gradient;
        Vector3       basePos = new Vector3(pos.x, heightBoundary, pos.z);
        HexWorldCoord baseHex = PosToHex(basePos);

        gradient = Procedural.Noise.noiseMethods[2][2](baseHex.ToVector3(), noiseScale, worldName.GetHashCode()).derivative * 20 + new Vector3(0, thresDropOff, 0);
        if (island)
        {
            gradient += 100 * new Vector3(basePos.x * Mathf.Log(islandDropOff) * Mathf.Pow(islandDropOff, (Mathf.Pow(basePos.x, 2) + Mathf.Pow(basePos.z, 2)) - 10386), 0, pos.z * Mathf.Log(islandDropOff) * Mathf.Pow(islandDropOff, (Mathf.Pow(basePos.x, 2) + Mathf.Pow(basePos.z, 2)) - 10386));
        }
        gradient = new Vector3(gradient.x, -1.75f * Mathf.Pow(-pos.y + heightBoundary, -0.65f), gradient.z);
        return(gradient);
    }
Esempio n. 15
0
    public Vector3 GetNormalInterp(HexCoord pos)
    {
        HexWorldCoord low  = HexOffset;
        HexWorldCoord high = HexOffset + new HexCoord(chunkSize, chunkSize, chunkSize);

        float xD = (pos.x - low.x) / (high.x - low.x);
        float yD = (pos.y - low.y) / (high.y - low.y);
        float zD = (pos.z - low.z) / (high.z - low.z);

        Vector3 c00 = Vector3.Lerp(cornerNormals[0, 0, 0], cornerNormals[1, 0, 0], xD);
        Vector3 c01 = Vector3.Lerp(cornerNormals[0, 0, 1], cornerNormals[1, 0, 1], xD);
        Vector3 c10 = Vector3.Lerp(cornerNormals[0, 1, 0], cornerNormals[1, 1, 0], xD);
        Vector3 c11 = Vector3.Lerp(cornerNormals[0, 1, 1], cornerNormals[1, 1, 1], xD);

        Vector3 c0 = Vector3.Lerp(c00, c10, yD);
        Vector3 c1 = Vector3.Lerp(c01, c11, yD);

        Vector3 c = Vector3.Lerp(c0, c1, zD);

        return(c);
    }
Esempio n. 16
0
    public float GetInterp(HexCoord pos)
    {
        HexWorldCoord low  = HexOffset;
        HexWorldCoord high = HexOffset + new HexCoord(chunkSize, chunkSize, chunkSize);

        float xD = (pos.x - low.x) / (high.x - low.x);
        float yD = (pos.y - low.y) / (high.y - low.y);
        float zD = (pos.z - low.z) / (high.z - low.z);

        float c00 = Mathf.Lerp(corners[0, 0, 0], corners[1, 0, 0], xD);
        float c01 = Mathf.Lerp(corners[0, 0, 1], corners[1, 0, 1], xD);
        float c10 = Mathf.Lerp(corners[0, 1, 0], corners[1, 1, 0], xD);
        float c11 = Mathf.Lerp(corners[0, 1, 1], corners[1, 1, 1], xD);

        float c0 = Mathf.Lerp(c00, c10, yD);
        float c1 = Mathf.Lerp(c01, c11, yD);

        float c = Mathf.Lerp(c0, c1, zD);

        return(c);
    }
Esempio n. 17
0
    public Vector3 GetNormal(HexWorldCoord hex, int forcedLocation = 0)
    {
        switch (forcedLocation)
        {
        case -1:
            return(GetNormalBelow(hex));

        case 1:
            return(GetNormalAbove(hex));

        default:
            Vector3 pos = HexToPos(hex);
            if (pos.y > heightBoundary)
            {
                return(GetNormalAbove(hex));
            }
            else
            {
                return(GetNormalBelow(hex));
            }
        }
    }