Exemplo n.º 1
0
    void DisplayAxis(GameObject obj)
    {
        PlotMeshT plotMesh = MeshGenerator.MakePlot(obj, axesBounds, axesBounds, 100, ShadingMode.heightmap);

        Transform frameT = obj.transform.Find("TopFrame");

        if (frameT == null)
        {
            Debug.LogError("Object has no child with this name");
            return;
        }
        frameT.GetComponent <Wireframe>().Init(plotMesh.topMesh.vertices, plotMesh.topMesh.triangles, 50, 50, 0, WireframeMode.Grid);
        frameT.GetComponent <Renderer>().material = axesMat;
    }
Exemplo n.º 2
0
    public void Display(string inpTxt)
    {
        Tuple <Function, Function> Equations = Parser.Parse(inpTxt);

        Equation          = Equations.Item1;
        IndicatorEquation = Equations.Item2;

        if (Equation == null)
        {
            return;
        }

        PlotMeshT plotMesh = MeshGenerator.MakePlot(gameObject, XBound, ZBound, 100, ShadingMode.heightmap);

        MeshGenerator.CopyMesh(topMesh, plotMesh.topMesh);
        MeshGenerator.CopyMesh(botMesh, plotMesh.botMesh);

        topFrame.Init(plotMesh.topMesh.vertices, plotMesh.topMesh.triangles, 50, 50);
        botFrame.Init(plotMesh.botMesh.vertices, plotMesh.topMesh.triangles, 50, 50, hoverOffset: -0.01f);
    }
Exemplo n.º 3
0
    /*
     *
     * smoothness = numX + numY
     */
    public static PlotMeshT MakePlot(GameObject obj, Tuple <float, float> xBound, Tuple <float, float> zBound, int smoothness, ShadingMode mode)
    {
        float diffX = xBound.Item2 - xBound.Item1;
        float diffZ = zBound.Item2 - zBound.Item1;

        int numX = (int)(diffX * smoothness / (diffX + diffZ));
        int numZ = smoothness - numX;

        float deltaX = diffX / numX;
        float deltaZ = diffZ / numZ;

        float curX = xBound.Item1;
        float curZ = zBound.Item1;

        List <Vector3> vertices = new List <Vector3>();
        List <int>     faces    = new List <int>();
        List <Color32> colors   = new List <Color32>();

        Function func = obj.GetComponent <Plot>().Equation;

        for (int i = 0; i <= numX; i++)
        {
            for (int j = 0; j <= numZ; j++)
            {
                Vector3 newVertex = obj.transform.InverseTransformVector(new Vector3(curX, (float)func.calculate(curX, curZ), curZ));
                vertices.Add(newVertex);

                colors.Add(GetColor(newVertex, mode));

                curX += deltaX;
            }
            curX  = xBound.Item1;
            curZ += deltaZ;
        }

        int k = 0;

        for (int i = 0; i < numX; i++)
        {
            for (int j = 0; j < numZ; j++)
            {
                faces.Add(k + 1);
                faces.Add(k);
                faces.Add(k + numX + 1);

                faces.Add(k + 1);
                faces.Add(k + numX + 1);
                faces.Add(k + numX + 2);

                k++;
            }
            k++;
        }

        List <Vector3> normals = new List <Vector3>();

        for (int i = 0; i < vertices.Count; i++)
        {
            normals.Add(new Vector3(0, 1, 0));
        }

        Mesh top = new Mesh();

        top.Clear();
        top.SetVertices(vertices);
        top.SetTriangles(faces, 0);
        top.SetNormals(normals);
        top.SetColors(colors);

        Mesh bot = new Mesh();

        bot.Clear();
        bot.SetVertices(vertices);

        faces.Reverse();
        bot.SetTriangles(faces, 0);

        for (int i = 0; i < normals.Count; i++)
        {
            normals[i] = -normals[i];
        }

        bot.SetNormals(normals);
        bot.SetColors(colors);

        PlotMeshT ret = new PlotMeshT {
            topMesh = top,
            botMesh = bot,
        };

        return(ret);
    }