Esempio n. 1
0
    //a==dirt
    public static void DirtToGrass(DynamicMesh mesh, RenderTile a, RenderTile b, RenderTile c)
    {
        Vector3 abMid = (a.position + b.position) * 0.5f;
        Vector3 acMid = (a.position + c.position) * 0.5f;

        Vector3 abGround = new Vector3(abMid.x, a.position.y, abMid.z);
        Vector3 acGround = new Vector3(acMid.x, a.position.y, acMid.z);

        mesh.SimpleTriangle(a.position, abGround, acGround, a.color, a.color, a.color, a.normal, a.normal, a.normal);

        mesh.SimpleTriangle(acGround, abGround, abMid, a.color, a.color, b.color, c.normal, b.normal, b.normal);
        mesh.SimpleTriangle(acGround, abMid, acMid, a.color, b.color, c.color, c.normal, b.normal, c.normal);

        mesh.SimpleTriangle(acMid, abMid, b.position, c.color, b.color, b.color, c.normal, b.normal, b.normal);
        mesh.SimpleTriangle(acMid, b.position, c.position, c.color, b.color, c.color, c.normal, b.normal, c.normal);
    }
Esempio n. 2
0
    public static void RenderTriangle(DynamicMesh mesh, RenderTile a, RenderTile b, RenderTile c)
    {
        TerrainType tA = a.GetTerrain();
        TerrainType tB = b.GetTerrain();
        TerrainType tC = c.GetTerrain();

        if (tA == tB && tA == tC)
        {
            //No terrain transition
            mesh.SimpleTriangle(a.position, b.position, c.position, a.color, b.color, c.color, a.normal, b.normal, c.normal);
        }
        else
        {
            //NOTE: Currently I assume height goes: sand, dirt, grass. Height transitions could also be added

            //Terrain transition. TODO: cache all combination
            if (tB == tC)
            {
                //A unique
                if (tA == TerrainType.Grass && tB == TerrainType.Dirt)
                {
                    GrassToDirt(mesh, a, b, c);
                    return;
                }
                else if (tA == TerrainType.Dirt && tB == TerrainType.Grass)
                {
                    DirtToGrass(mesh, a, b, c);
                    return;
                }
            }
            else if (tA == tC)
            {
                //B unique
                if (tB == TerrainType.Grass && tC == TerrainType.Dirt)
                {
                    GrassToDirt(mesh, b, c, a);
                    return;
                }
                else if (tB == TerrainType.Dirt && tC == TerrainType.Grass)
                {
                    DirtToGrass(mesh, b, c, a);
                    return;
                }
            }
            else if (tA == tB)
            {
                //C unique
                if (tC == TerrainType.Grass && tA == TerrainType.Dirt)
                {
                    GrassToDirt(mesh, c, a, b);
                    return;
                }
                else if (tC == TerrainType.Dirt && tA == TerrainType.Grass)
                {
                    DirtToGrass(mesh, c, a, b);
                    return;
                }
            }
            else
            {
                //All unique
            }

            mesh.SimpleTriangle(a.position, b.position, c.position, a.color, b.color, c.color, a.normal, b.normal, c.normal);
        }
    }