Example #1
0
 /// <summary>
 /// Agrega un nuevo vertice a la lista si es que ya no hay otro igual.
 /// Devuelve el indice del nuevo vertice o del que ya estaba.
 /// </summary>
 public static int addVertexToListIfUnique(List <EditPolyVertex> vertices, EditPolyVertex v)
 {
     for (int i = 0; i < vertices.Count; i++)
     {
         if (EditablePolyUtils.sameVextex(vertices[i], v))
         {
             return(i);
         }
     }
     v.vbIndex = vertices.Count;
     v.edges   = new List <EditPolyEdge>();
     vertices.Add(v);
     return(v.vbIndex);
 }
        /// <summary>
        /// Activar
        /// </summary>
        public void setEnabled(bool enabled)
        {
            //Activar
            if (enabled)
            {
                editablePoly.CurrentState = EditablePoly.State.TranslateGizmo;
                currentState = State.Init;

                //Posicionar gizmo
                TgcBoundingBox aabb       = EditablePolyUtils.getSelectionBoundingBox(editablePoly.SelectionList);
                Vector3        aabbCenter = Vector3.TransformCoordinate(aabb.calculateBoxCenter(), editablePoly.Transform);
                gizmoMesh.setCenter(aabbCenter, editablePoly.Control.Camera);
            }
        }
Example #3
0
 /// <summary>
 /// Agrega una nueva arista a la lista si es que ya no hay otra igual.
 /// Devuelve el indice de la nuevo arista o de la que ya estaba.
 /// </summary>
 public static int addEdgeToListIfUnique(List <EditPolyEdge> edges, EditPolyEdge e, out bool newEdgeAdded)
 {
     for (int i = 0; i < edges.Count; i++)
     {
         if (EditablePolyUtils.sameEdge(edges[i], e))
         {
             newEdgeAdded = false;
             return(i);
         }
     }
     newEdgeAdded = true;
     e.faces      = new List <EditPolyPolygon>();
     edges.Add(e);
     return(edges.Count - 1);
 }
Example #4
0
        /// <summary>
        /// Procesar shorcuts de teclado
        /// </summary>
        private void processShortcuts()
        {
            TgcD3dInput input = GuiController.Instance.D3dInput;

            //Select
            if (input.keyPressed(Key.Q))
            {
                setSelectState();
            }
            //Select all
            else if (input.keyDown(Key.LeftControl) && input.keyPressed(Key.E))
            {
                selectAll();
            }
            //Delete
            else if (input.keyPressed(Key.Delete))
            {
                deleteSelectedPrimitives();
            }
            //Translate
            else if (input.keyPressed(Key.W))
            {
                activateTranslateGizmo();
            }
            //Zoom
            else if (input.keyPressed(Key.Z))
            {
                EditablePolyUtils.zoomPrimitives(control.Camera, selectionList, Transform);
            }
            //Top view
            else if (input.keyPressed(Key.T))
            {
                EditablePolyUtils.setCameraTopView(control.Camera, selectionList, Transform);
            }
            //Left view
            else if (input.keyPressed(Key.L))
            {
                EditablePolyUtils.setCameraLeftView(control.Camera, selectionList, Transform);
            }
            //Front view
            else if (input.keyPressed(Key.F))
            {
                EditablePolyUtils.setCameraFrontView(control.Camera, selectionList, Transform);
            }
        }
Example #5
0
 /// <summary>
 /// Busca si ambos poligonos tienen una arista igual.
 /// Si encontro retorna el indice de la arista igual de cada poligono.
 /// </summary>
 public static bool findShareEdgeBetweenPolygons(EditPolyPolygon p1, EditPolyPolygon p2, out int p1Edge, out int p2Edge)
 {
     for (int i = 0; i < p1.edges.Count; i++)
     {
         for (int j = 0; j < p2.edges.Count; j++)
         {
             if (EditablePolyUtils.sameEdge(p1.edges[i], p2.edges[j]))
             {
                 p1Edge = i;
                 p2Edge = j;
                 return(true);
             }
         }
     }
     p1Edge = -1;
     p2Edge = -1;
     return(false);
 }
Example #6
0
        /// <summary>
        /// Tomar un mesh cargar todas las estructuras internas necesarias para poder editarlo
        /// </summary>
        private void loadMesh(TgcMesh origMesh)
        {
            //Obtener vertices del mesh
            this.mesh = origMesh;
            List <EditPolyVertex> origVertices = getMeshOriginalVertexData(origMesh);
            int origTriCount = origVertices.Count / 3;

            //Iterar sobre los triangulos y generar data auxiliar unificada
            vertices    = new List <EditPolyVertex>();
            edges       = new List <EditPolyEdge>();
            polygons    = new List <EditPolyPolygon>();
            indexBuffer = new short[origTriCount * 3];
            int[] attributeBuffer = origMesh.D3dMesh.LockAttributeBufferArray(LockFlags.ReadOnly);
            origMesh.D3dMesh.UnlockAttributeBuffer(attributeBuffer);
            for (int i = 0; i < origTriCount; i++)
            {
                EditPolyVertex v1 = origVertices[i * 3];
                EditPolyVertex v2 = origVertices[i * 3 + 1];
                EditPolyVertex v3 = origVertices[i * 3 + 2];

                //Agregar vertices a la lista, si es que son nuevos
                int v1Idx = EditablePolyUtils.addVertexToListIfUnique(vertices, v1);
                int v2Idx = EditablePolyUtils.addVertexToListIfUnique(vertices, v2);
                int v3Idx = EditablePolyUtils.addVertexToListIfUnique(vertices, v3);
                v1 = vertices[v1Idx];
                v2 = vertices[v2Idx];
                v3 = vertices[v3Idx];

                //Crear edges
                EditPolyEdge e1 = new EditPolyEdge();
                e1.a = v1;
                e1.b = v2;
                EditPolyEdge e2 = new EditPolyEdge();
                e2.a = v2;
                e2.b = v3;
                EditPolyEdge e3 = new EditPolyEdge();
                e3.a = v3;
                e3.b = v1;

                //Crear poligono para este triangulo
                EditPolyPolygon p = new EditPolyPolygon();
                p.vertices = new List <EditPolyVertex>();
                p.vertices.Add(v1);
                p.vertices.Add(v2);
                p.vertices.Add(v3);
                p.edges = new List <EditPolyEdge>();
                p.edges.Add(e1);
                p.edges.Add(e2);
                p.edges.Add(e3);
                p.vbTriangles = new List <int>();
                p.vbTriangles.Add(i * 3);
                p.plane = Plane.FromPoints(v1.position, v2.position, v3.position);
                p.plane.Normalize();
                p.matId = attributeBuffer[i];

                //Agregar triangulo al index buffer
                indexBuffer[i * 3]     = (short)v1Idx;
                indexBuffer[i * 3 + 1] = (short)v2Idx;
                indexBuffer[i * 3 + 2] = (short)v3Idx;

                //Agregar a lista de poligonos
                polygons.Add(p);


                /*
                 * //Buscar si hay un poligono ya existente al cual sumarnos (coplanar y que compartan una arista)
                 * EditPolyPolygon coplanarP = null;
                 * for (int j = 0; j < polygons.Count; j++)
                 * {
                 *  //Coplanares y con igual material ID
                 *  EditPolyPolygon p0 = polygons[j];
                 *  if (p0.matId == p.matId && EditablePolyUtils.samePlane(p0.plane, p.plane))
                 *  {
                 *      //Buscar si tienen una arista igual
                 *      int p0SharedEdgeIdx;
                 *      int pSharedEdgeIdx;
                 *      if (EditablePolyUtils.findShareEdgeBetweenPolygons(p0, p, out p0SharedEdgeIdx, out pSharedEdgeIdx))
                 *      {
                 *          //Obtener el tercer vertice del triangulo que no es parte de la arista compartida
                 *          EditPolyEdge sharedEdge = p0.edges[p0SharedEdgeIdx];
                 *          EditPolyVertex thirdVert;
                 *          if (p.vertices[0] != sharedEdge.a && p.vertices[0] != sharedEdge.b)
                 *              thirdVert = p.vertices[0];
                 *          else if (p.vertices[1] != sharedEdge.a && p.vertices[1] != sharedEdge.b)
                 *              thirdVert = p.vertices[1];
                 *          else
                 *              thirdVert = p.vertices[2];
                 *
                 *          //Agregar el tercer vertice al poligno existente
                 *          EditablePolyUtils.addVertexToPolygon(p0, sharedEdge, thirdVert);
                 *
                 *          //Quitar arista compartida
                 *          p0.edges.Remove(sharedEdge);
                 *
                 *          //Agregar al poligono dos nuevas aristas que conectar los extremos de la arista compartida hacia el tercer vertice
                 *          EditPolyEdge newPolEdge1 = new EditPolyEdge();
                 *          newPolEdge1.a = sharedEdge.a;
                 *          newPolEdge1.b = thirdVert;
                 *          p0.edges.Add(newPolEdge1);
                 *
                 *          EditPolyEdge newPolEdge2 = new EditPolyEdge();
                 *          newPolEdge2.a = thirdVert;
                 *          newPolEdge2.b = sharedEdge.b;
                 *          p0.edges.Add(newPolEdge2);
                 *
                 *          //Agregar indice de triangulo del vertexBuffer que se sumo al poligono
                 *          p0.vbTriangles.Add(p.vbTriangles[0]);
                 *
                 *          coplanarP = p0;
                 *      }
                 *  }
                 * }
                 * //Es un nuevo poligono, agregarlo
                 * if (coplanarP == null)
                 * {
                 *  polygons.Add(p);
                 * }
                 */
            }


            //Unificar aristas de los poligonos
            foreach (EditPolyPolygon p in polygons)
            {
                for (int i = 0; i < p.edges.Count; i++)
                {
                    bool         newEdgeAdded;
                    int          eIdx = EditablePolyUtils.addEdgeToListIfUnique(edges, p.edges[i], out newEdgeAdded);
                    EditPolyEdge e    = edges[eIdx];

                    //Nueva arista incorporada a la lista
                    if (newEdgeAdded)
                    {
                        e.faces = new List <EditPolyPolygon>();

                        //Agregar referencia a vertices que usan la arista
                        e.a.edges.Add(e);
                        e.b.edges.Add(e);
                    }
                    //Se usa arista existente de la lista
                    else
                    {
                        //Reemplazar en poligono por la nueva
                        p.edges[i] = e;
                    }

                    //Indicar a la arista que pertenece al poligono actual
                    e.faces.Add(p);
                }
            }


            setDirtyValues(false);
        }