Beispiel #1
0
        /// <summary>
        /// Actualizar que objetos estan seleccionados y cuales no
        /// </summary>
        public void updateSelection()
        {
            //Limpiar seleccion
            control.SelectionRectangle.clearSelection();

            //Marcar como seleccionados todos los objetos del tree con check
            foreach (TreeNode node in treeViewObjects.Nodes)
            {
                foreach (TreeNode childNode in node.Nodes)
                {
                    if (childNode.Checked)
                    {
                        EditorPrimitive p = (EditorPrimitive)childNode.Tag;
                        if (p.Visible)
                        {
                            control.SelectionRectangle.selectObject(p);
                        }
                    }
                    childNode.BackColor = getMeshNodeColor(childNode);
                }
            }

            //Actualizar paneles
            control.updateModifyPanel();

            //Quitar gizmo actual
            control.CurrentGizmo = null;

            //Pasar a modo seleccion
            control.CurrentState = MeshCreatorControl.State.SelectObject;
        }
        /// <summary>
        ///     Hacer picking para seleccionar el objeto mas cercano del ecenario.
        /// </summary>
        /// <param name="additive">En True agrega/quita el objeto a la seleccion actual</param>
        public void doDirectSelection(bool additive)
        {
            control.PickingRay.updateRay();

            //Buscar menor colision con objetos
            var             minDistSq        = float.MaxValue;
            EditorPrimitive closestPrimitive = null;
            TGCVector3      q;

            foreach (var p in control.Meshes)
            {
                //Solo los visibles
                if (p.Visible)
                {
                    if (TgcCollisionUtils.intersectRayAABB(control.PickingRay.Ray, p.BoundingBox, out q))
                    {
                        var lengthSq = TGCVector3.Subtract(control.PickingRay.Ray.Origin, q).LengthSq();
                        if (lengthSq < minDistSq)
                        {
                            minDistSq        = lengthSq;
                            closestPrimitive = p;
                        }
                    }
                }
            }

            //Agregar
            if (closestPrimitive != null)
            {
                //Sumar a la lista de seleccion
                if (additive)
                {
                    selectOrRemoveObjectIfPresent(closestPrimitive);
                }
                //Seleccionar uno solo
                else
                {
                    clearSelection();
                    selectObject(closestPrimitive);
                }
                activateCurrentGizmo();
            }
            //Nada seleccionado
            else
            {
                //Limpiar seleccion
                clearSelection();
            }

            //Pasar a modo seleccion
            control.setSelectObjectState();
            control.UpdateModifyPanel();
        }
Beispiel #3
0
        private Color getMeshNodeColor(TreeNode n)
        {
            EditorPrimitive p = (EditorPrimitive)n.Tag;

            if (p.Selected)
            {
                return(Color.Yellow);
            }
            else
            {
                return(p.Visible ? Color.White : Color.LightGray);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Clic en "Delete"
        /// </summary>
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            //Obtener objetos a borrar
            List <EditorPrimitive> objectsToDelete = new List <EditorPrimitive>();

            foreach (TreeNode node in treeViewObjects.Nodes)
            {
                foreach (TreeNode childNode in node.Nodes)
                {
                    if (childNode.Checked)
                    {
                        EditorPrimitive p = (EditorPrimitive)childNode.Tag;
                        objectsToDelete.Add(p);
                    }
                }
            }

            //Confirmacion
            if (objectsToDelete.Count > 0)
            {
                if (MessageBox.Show(this, "¿Do you want to delete " + objectsToDelete.Count + " objects?", "Delete objects", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    //Borrar meshes
                    control.deleteObjects(objectsToDelete);

                    //Borrar layers y objetos seleccionados del tree
                    for (int i = 0; i < treeViewObjects.Nodes.Count; i++)
                    {
                        TreeNode node = treeViewObjects.Nodes[i];
                        for (int j = 0; j < node.Nodes.Count; j++)
                        {
                            TreeNode childNode = node.Nodes[j];
                            if (childNode.Checked)
                            {
                                node.Nodes.RemoveAt(j);
                                j--;
                            }
                        }
                        if (node.Checked)
                        {
                            treeViewObjects.Nodes.RemoveAt(i);
                            i--;
                        }
                    }

                    updateSelection();
                }
            }
        }
 /// <summary>
 ///     Selecciona un solo objeto pero antes se fija si ya no estaba en la lista de seleccion.
 ///     Si ya estaba, entonces lo quita de la lista de seleccion
 /// </summary>
 public void selectOrRemoveObjectIfPresent(EditorPrimitive p)
 {
     //Ya existe, quitar
     if (control.SelectionList.Contains(p))
     {
         p.setSelected(false);
         control.SelectionList.Remove(p);
     }
     //No existe, agregar
     else
     {
         p.setSelected(true);
         control.SelectionList.Add(p);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Mostrar u ocultar los objetos con check
        /// </summary>
        public void showHideObjects(bool show)
        {
            List <EditorPrimitive> objectsToShowHide = new List <EditorPrimitive>();

            foreach (TreeNode node in treeViewObjects.Nodes)
            {
                foreach (TreeNode childNode in node.Nodes)
                {
                    if (childNode.Checked)
                    {
                        EditorPrimitive p = (EditorPrimitive)childNode.Tag;
                        objectsToShowHide.Add(p);
                    }
                }
            }
            control.showHideObjects(objectsToShowHide, show);
            updateSelection();
        }
Beispiel #7
0
        /// <summary>
        /// Clic en "Move"
        /// </summary>
        private void buttonMove_Click(object sender, EventArgs e)
        {
            //Mostrar popup para elegir layer destino
            List <string> layerNames = new List <string>();

            foreach (TreeNode node in treeViewObjects.Nodes)
            {
                layerNames.Add(node.Text);
            }
            selectLayerDialog.loadLayers(layerNames);

            if (selectLayerDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
            {
                //Buscar el nodo layer destino elegido
                TreeNode dstLayer = getLayerWithName(selectLayerDialog.SelectedLayer);
                if (dstLayer != null)
                {
                    //Recorrer todos los nodos chequeados y moverlos al layer destino
                    foreach (TreeNode node in treeViewObjects.Nodes)
                    {
                        for (int i = 0; i < node.Nodes.Count; i++)
                        {
                            //Evitar moverlo al mismo destino
                            TreeNode childNode = node.Nodes[i];
                            if (childNode.Checked && node.Text != dstLayer.Text)
                            {
                                //Cambiar layer del mesh
                                EditorPrimitive p = (EditorPrimitive)childNode.Tag;
                                p.Layer = dstLayer.Text;

                                //Mover de nodo del tree
                                node.Nodes.RemoveAt(i);
                                i--;

                                //Agregar al nuevo nodo
                                dstLayer.Nodes.Add(childNode);
                            }
                        }
                    }

                    updateSelection();
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// Clic en "Rename"
        /// </summary>
        private void buttonRename_Click(object sender, EventArgs e)
        {
            TreeNode node = treeViewObjects.SelectedNode;

            if (node != null)
            {
                inputBox.Text       = "Rename";
                inputBox.InputLabel = "Object name:";
                inputBox.InputText  = node.Text;
                if (inputBox.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    //Es un layer
                    if (node.Tag == null)
                    {
                        //Cambiar nombre de layer
                        node.Text = inputBox.InputText;

                        //Cambiar layer a todos sus hijos
                        foreach (TreeNode childNode in node.Nodes)
                        {
                            EditorPrimitive p = (EditorPrimitive)childNode.Tag;
                            p.Layer = node.Text;
                        }
                    }
                    //Es un mesh
                    else
                    {
                        EditorPrimitive p = (EditorPrimitive)node.Tag;
                        p.Name    = inputBox.InputText;
                        node.Text = p.Name;
                    }

                    updateSelection();
                }

                treeViewObjects.Focus();
            }
        }
Beispiel #9
0
 /// <summary>
 /// Mover gizmo
 /// </summary>
 public override void move(EditorPrimitive selectedPrimitive, Vector3 movement)
 {
     moveGizmo(movement);
 }
Beispiel #10
0
 /// <summary>
 ///     Mover gizmo de lugar para acomodarse a la nueva posicion del objeto seleccionado
 /// </summary>
 public abstract void move(EditorPrimitive selectedPrimitive, TGCVector3 movement);
Beispiel #11
0
 /// <summary>
 ///     Selecciona un solo objeto
 /// </summary>
 public void selectObject(EditorPrimitive p)
 {
     p.setSelected(true);
     control.SelectionList.Add(p);
 }
Beispiel #12
0
 /// <summary>
 ///     Mover gizmo
 /// </summary>
 public override void move(EditorPrimitive selectedPrimitive, TGCVector3 movement)
 {
     gizmoMesh.moveGizmo(movement);
 }