private async void AnalizarFuente_Click(object sender, RoutedEventArgs e)
        {
            if (App.currentParser != null)
            {
                if (!string.IsNullOrEmpty(EntradaFuente.Text))
                {
                    TablaAcciones.ItemsSource = null;

                    if (App.currentParser.EvalString(EntradaFuente.Text))
                    {
                        Log.Text       = "La cadena de entrada es valida!";
                        Log.Foreground = new SolidColorBrush(Color.FromRgb(51, 204, 51));
                        QuadGenerator quadGenerator = new QuadGenerator();
                        CurrentQuads = quadGenerator.Generate(App.currentParser.NodeStack.Peek());
                    }
                    else
                    {
                        Log.Text       = "La cadena de entrada no es valida. :( ";
                        Log.Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                    }

                    TablaAcciones.ItemsSource = App.currentParser.Log;
                }
                else
                {
                    MessageBox.Show("Introduzca código fuente");
                }
            }
            else
            {
                MessageBox.Show("Primero Cree una tabla de Analisis Sintáctico en la sección Gramática");
            }
        }
 private static void DestroyConfirm(QuadGenerator quadGenerator)
 {
     if (EditorUtility.DisplayDialog("Destroy all quad game objects?", "Destroy all quad game objects?\nThis action cannot be undone!", "Destroy All", "Cancel"))
     {
         quadGenerator.DestroyAll();
     }
 }
Пример #3
0
    void Start()
    {
        Mesh cube = new Mesh();

        //Front
        cube = MeshBuilder.Combine
                   (cube, QuadGenerator.MakeQuad
                   (
                       new Vector3(0, 1, 0),
                       new Vector3(1, 0, 0)
                   ));
        //Left
        cube = MeshBuilder.Combine
                   (cube, QuadGenerator.MakeQuad
                   (
                       new Vector3(0, 0, 1),
                       new Vector3(0, 1, 0)
                   ));

        //Right
        cube = MeshBuilder.Combine
                   (cube, MeshBuilder.Offset(QuadGenerator.MakeQuad
                                             (
                                                 new Vector3(0, 1, 0),
                                                 new Vector3(0, 0, 1)
                                             ), new Vector3(1, 0, 0)));

        //Bottom
        cube = MeshBuilder.Combine
                   (cube, QuadGenerator.MakeQuad
                   (
                       new Vector3(1, 0, 0),
                       new Vector3(0, 0, 1)
                   ));

        //Rear
        cube = MeshBuilder.Combine
                   (cube, MeshBuilder.Offset(QuadGenerator.MakeQuad
                                             (
                                                 new Vector3(0, -1, 0),
                                                 new Vector3(1, 0, 0)
                                             ), new Vector3(0, 1, 1)));

        //Top
        cube = MeshBuilder.Combine
                   (cube, MeshBuilder.Offset(QuadGenerator.MakeQuad
                                             (
                                                 new Vector3(0, 0, 1),
                                                 new Vector3(1, 0, 0)
                                             ), new Vector3(0, 1, 0)));

        cube = MeshBuilder.Offset(cube, new Vector3(-.5f, -.5f, -.5f));

        MeshFilter mf = GetComponent <MeshFilter>();

        mf.mesh = cube;
    }
Пример #4
0
    private void UpdateQuad()
    {
        Mesh mesh = GetComponent <MeshFilter>().sharedMesh;

        if (mesh == null)
        {
            return;
        }
        mesh.vertices = QuadGenerator.GenerateVertices(size);
    }
    public override void OnInspectorGUI()
    {
        QuadGenerator quadGenerator = target as QuadGenerator;

        DrawDefaultInspector();
        if (GUILayout.Button("Generate Quad"))
        {
            quadGenerator.GenerateQuad();
        }
        ShowAdvanced = EditorGUILayout.Foldout(ShowAdvanced, "Advanced");
        if (ShowAdvanced)
        {
            if (GUILayout.Button("Destroy All"))
            {
                DestroyConfirm(quadGenerator);
            }
        }
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        QuadGenerator quadGeneratorScript = (QuadGenerator)target;

        GUILayout.BeginHorizontal();

        GUILayout.BeginVertical();
        if (GUILayout.Button("Build Quad"))
        {
            quadGeneratorScript.GenerateQuad();
        }
        if (GUILayout.Button("Save Quad"))
        {
            MeshSaverEditor.SaveMeshInPlace(quadGeneratorScript.GetComponent <MeshFilter>());
        }
        GUILayout.EndVertical();

        GUILayout.BeginVertical();
        if (GUILayout.Button("Build GameObject Quad"))
        {
            quadGeneratorScript.GenerateNewGOQuad();
        }
        if (GUILayout.Button("Save GO Quad"))
        {
            MeshSaverEditor.SaveMeshInPlace(quadGeneratorScript.generatedGO.GetComponent <MeshFilter>());
        }
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();

        EditorGUILayout.Space();
        if (GUILayout.Button("Clear Generator"))
        {
            quadGeneratorScript.ClearGenerator();
        }
    }
Пример #7
0
    void Start()
    {
        MeshFilter mf   = GetComponent <MeshFilter>();
        Mesh       cube = new Mesh();

        List <Vector2> uvs = new List <Vector2>();

        // Front
        cube = MeshBuilder.Combine(cube, QuadGenerator.MakeQuad(
                                       new Vector3(0, 1, 0),
                                       new Vector3(1, 0, 0)
                                       ));
        uvs.Add(new Vector2(0f, 1f / 3f));          //A
        uvs.Add(new Vector2(0f, 2f / 3f));          //B
        uvs.Add(new Vector2(1f / 4f, 2f / 3f));     //C
        uvs.Add(new Vector2(1f / 4f, 1f / 3f));     //D

        // Left
        cube = MeshBuilder.Combine(cube, MeshBuilder.Offset(QuadGenerator.MakeQuad(
                                                                new Vector3(0, 1, 0),
                                                                new Vector3(0, 0, -1)
                                                                ), new Vector3(0, 0, 1)));
        uvs.Add(new Vector2(3f / 4f, 1f / 3f));
        uvs.Add(new Vector2(3f / 4f, 2f / 3f));
        uvs.Add(new Vector2(1f, 2f / 3f));
        uvs.Add(new Vector2(1f, 1f / 3f));

        // Down
        cube = MeshBuilder.Combine(cube, MeshBuilder.Offset(QuadGenerator.MakeQuad(
                                                                new Vector3(0, 0, -1),
                                                                new Vector3(1, 0, 0)
                                                                ), new Vector3(0, 0, 1)));
        uvs.Add(new Vector2(0f, 0f));
        uvs.Add(new Vector2(0f, 1f / 3f));
        uvs.Add(new Vector2(1f / 4f, 1f / 3f));
        uvs.Add(new Vector2(1f / 4f, 0f));

        // Right
        cube = MeshBuilder.Combine(cube, MeshBuilder.Offset(QuadGenerator.MakeQuad(
                                                                new Vector3(0, 1, 0),
                                                                new Vector3(0, 0, 1)
                                                                ), new Vector3(1, 0, 0)));
        uvs.Add(new Vector2(1f / 4f, 1f / 3f));
        uvs.Add(new Vector2(1f / 4f, 2f / 3f));
        uvs.Add(new Vector2(1f / 2f, 2f / 3f));
        uvs.Add(new Vector2(1f / 2f, 1f / 3f));

        // Up
        cube = MeshBuilder.Combine(cube, MeshBuilder.Offset(QuadGenerator.MakeQuad(
                                                                new Vector3(0, 0, 1),
                                                                new Vector3(1, 0, 0)
                                                                ), new Vector3(0, 1, 0)));
        uvs.Add(new Vector2(0f, 2f / 3f));
        uvs.Add(new Vector2(0f, 1f));
        uvs.Add(new Vector2(1f / 4f, 1f));
        uvs.Add(new Vector2(1f / 4f, 2f / 3f));

        // Back
        cube = MeshBuilder.Combine(cube, MeshBuilder.Offset(QuadGenerator.MakeQuad(
                                                                new Vector3(0, 1, 0),
                                                                new Vector3(-1, 0, 0)
                                                                ), new Vector3(1, 0, 1)));
        uvs.Add(new Vector2(1f / 2f, 1f / 3f));
        uvs.Add(new Vector2(1f / 2f, 2f / 3f));
        uvs.Add(new Vector2(3f / 4f, 2f / 3f));
        uvs.Add(new Vector2(3f / 4f, 1f / 3f));

        cube    = MeshBuilder.Offset(cube, new Vector3(-0.5f, -0.5f, -0.5f));
        cube.uv = uvs.ToArray();
        cube.RecalculateBounds();
        cube.RecalculateNormals();

        mf.mesh = cube;
    }
Пример #8
0
    public void Generate(Mesh mesh)
    {
        int nvertices = 4 * 6;

        Vector3[] vertices = new Vector3[nvertices];
        int vertexIdx = 0;

        Vector2[] uv = new Vector2[nvertices];
        int uvsIdx = 0;

        Vector3[] normals = new Vector3[nvertices];
        int normalIdx = 0;

        int [] indices = new int[6 * 8];
        int indexIdx = 0;

        Mesh tempMesh = new Mesh();
        QuadGenerator quadGenerator = new QuadGenerator();
        QuadGenerator.QuadProperties quadProperties;

        Vector2 HalfSizeXZ = new Vector2(_properties.HalfSize.x, _properties.HalfSize.z);
        Vector2 HalfSizeXY = new Vector2(_properties.HalfSize.x, _properties.HalfSize.y);
        Vector2 HalfSizeZY = new Vector2(_properties.HalfSize.z, _properties.HalfSize.y);

        // Bottom
        Vector3 position = -_properties.Up * _properties.HalfSize.y;
        Vector3 front = -_properties.Up;
        Vector3 up = Vector3.Cross(_properties.Right, front);
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXZ, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx += AddIndices(indices, tempMesh.triangles, indexIdx, 0);
        uvsIdx += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Top
        position = _properties.Up * _properties.HalfSize.y;
        front = _properties.Up;
        up = Vector3.Cross(_properties.Right, front);
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXZ, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx += AddIndices(indices, tempMesh.triangles, indexIdx, 4);
        uvsIdx += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Left
        position = -_properties.Right * _properties.HalfSize.x;
        front = -_properties.Right;
        up = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeZY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx += AddIndices(indices, tempMesh.triangles, indexIdx, 8);
        uvsIdx += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Right
        position = _properties.Right * _properties.HalfSize.x;
        front = _properties.Right;
        up = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeZY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx += AddIndices(indices, tempMesh.triangles, indexIdx, 12);
        uvsIdx += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Front
        position = _properties.Front * _properties.HalfSize.z;
        front = _properties.Front;
        up = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx += AddIndices(indices, tempMesh.triangles, indexIdx, 16);
        uvsIdx += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Bottom
        position = -_properties.Front * _properties.HalfSize.z;
        front = -_properties.Front;
        up = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx += AddIndices(indices, tempMesh.triangles, indexIdx, 20);
        uvsIdx += AddUVs(uv, tempMesh.uv, uvsIdx);

        mesh.vertices = vertices;
        mesh.normals = normals;
        mesh.triangles = indices;
        mesh.uv = uv;
    }
Пример #9
0
    public void Generate(Mesh mesh)
    {
        int nvertices = 4 * 6;

        Vector3[] vertices  = new Vector3[nvertices];
        int       vertexIdx = 0;

        Vector2[] uv     = new Vector2[nvertices];
        int       uvsIdx = 0;

        Vector3[] normals   = new Vector3[nvertices];
        int       normalIdx = 0;

        int [] indices  = new int[6 * 8];
        int    indexIdx = 0;

        Mesh          tempMesh      = new Mesh();
        QuadGenerator quadGenerator = new QuadGenerator();

        QuadGenerator.QuadProperties quadProperties;

        Vector2 HalfSizeXZ = new Vector2(_properties.HalfSize.x, _properties.HalfSize.z);
        Vector2 HalfSizeXY = new Vector2(_properties.HalfSize.x, _properties.HalfSize.y);
        Vector2 HalfSizeZY = new Vector2(_properties.HalfSize.z, _properties.HalfSize.y);

        // Bottom
        Vector3 position = -_properties.Up * _properties.HalfSize.y;
        Vector3 front    = -_properties.Up;
        Vector3 up       = Vector3.Cross(_properties.Right, front);

        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXZ, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx  += AddIndices(indices, tempMesh.triangles, indexIdx, 0);
        uvsIdx    += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Top
        position       = _properties.Up * _properties.HalfSize.y;
        front          = _properties.Up;
        up             = Vector3.Cross(_properties.Right, front);
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXZ, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx  += AddIndices(indices, tempMesh.triangles, indexIdx, 4);
        uvsIdx    += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Left
        position       = -_properties.Right * _properties.HalfSize.x;
        front          = -_properties.Right;
        up             = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeZY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx  += AddIndices(indices, tempMesh.triangles, indexIdx, 8);
        uvsIdx    += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Right
        position       = _properties.Right * _properties.HalfSize.x;
        front          = _properties.Right;
        up             = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeZY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx  += AddIndices(indices, tempMesh.triangles, indexIdx, 12);
        uvsIdx    += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Front
        position       = _properties.Front * _properties.HalfSize.z;
        front          = _properties.Front;
        up             = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx  += AddIndices(indices, tempMesh.triangles, indexIdx, 16);
        uvsIdx    += AddUVs(uv, tempMesh.uv, uvsIdx);

        // Bottom
        position       = -_properties.Front * _properties.HalfSize.z;
        front          = -_properties.Front;
        up             = _properties.Up;
        quadProperties = new QuadGenerator.QuadProperties(position, HalfSizeXY, front, up);
        quadGenerator.SetProperties(quadProperties);
        quadGenerator.Generate(tempMesh);
        vertexIdx += AddVector3(vertices, tempMesh.vertices, vertexIdx);
        normalIdx += AddVector3(normals, tempMesh.normals, normalIdx);
        indexIdx  += AddIndices(indices, tempMesh.triangles, indexIdx, 20);
        uvsIdx    += AddUVs(uv, tempMesh.uv, uvsIdx);

        mesh.vertices  = vertices;
        mesh.normals   = normals;
        mesh.triangles = indices;
        mesh.uv        = uv;
    }