public MeshCreatorControl(TgcMeshCreator creator) { InitializeComponent(); this.creator = creator; this.meshes = new List<EditorPrimitive>(); this.selectionList = new List<EditorPrimitive>(); this.pickingRay = new TgcPickingRay(); this.grid = new Grid(this); this.selectionRectangle = new SelectionRectangle(this); creatingPrimitive = null; primitiveNameCounter = 0; currentGizmo = null; mediaPath = GuiController.Instance.ExamplesMediaDir + "MeshCreator\\"; defaultTexturePath = mediaPath + "Textures\\Madera\\cajaMadera1.jpg"; checkBoxShowObjectsBoundingBox.Checked = true; popupOpened = false; fpsCameraEnabled = false; lastSavePath = null; //meshBrowser //defaultMeshPath = mediaPath + "Meshes\\Vegetacion\\Arbusto\\Arbusto-TgcScene.xml"; defaultMeshPath = mediaPath + "\\Meshes\\Vegetacion"; meshBrowser = new TgcMeshBrowser(); meshBrowser.setSelectedMesh(defaultMeshPath); //Export scene dialog exportSceneSaveDialog = new SaveFileDialog(); exportSceneSaveDialog.DefaultExt = ".xml"; exportSceneSaveDialog.Filter = ".XML |*.xml"; exportSceneSaveDialog.AddExtension = true; exportSceneSaveDialog.Title = "Export scene to a -TgcScene.xml file"; //Camara camera = new MeshCreatorCamera(); camera.Enable = true; camera.setCamera(new Vector3(0, 0, 0), 500); camera.BaseRotX = -FastMath.PI / 4f; GuiController.Instance.CurrentCamera.Enable = false; //Gizmos translateGizmo = new TranslateGizmo(this); scaleGizmo = new ScaleGizmo(this); //Tab inicial tabControl.SelectedTab = tabControl.TabPages["tabPageCreate"]; currentState = State.SelectObject; radioButtonSelectObject.Checked = true; //Tab Create textBoxCreateCurrentLayer.Text = "Default"; //Tab Modify textureBrowser = new TgcTextureBrowser(); textureBrowser.ShowFolders = true; textureBrowser.setSelectedImage(defaultTexturePath); textureBrowser.AsyncModeEnable = true; textureBrowser.OnSelectImage += new TgcTextureBrowser.SelectImageHandler(textureBrowser_OnSelectImage); textureBrowser.OnClose += new TgcTextureBrowser.CloseHandler(textureBrowser_OnClose); pictureBoxModifyTexture.ImageLocation = defaultTexturePath; pictureBoxModifyTexture.Image = MeshCreatorUtils.getImage(defaultTexturePath); updateModifyPanel(); //ObjectPosition Text objectPositionText = new TgcText2d(); objectPositionText.Align = TgcText2d.TextAlign.LEFT; objectPositionText.Color = Color.Yellow; objectPositionText.Size = new Size(500, 12); objectPositionText.Position = new Point(GuiController.Instance.Panel3d.Width - objectPositionText.Size.Width, GuiController.Instance.Panel3d.Height - 20); //Snap to grid snapToGridCellSize = (float)numericUpDownCellSize.Value; //ObjectBrowser objectBrowser = new ObjectBrowser(this); //TextureBrowser para EditablePoly textureBrowserEPoly = new TgcTextureBrowser(); textureBrowserEPoly.ShowFolders = true; textureBrowserEPoly.setSelectedImage(defaultTexturePath); textureBrowserEPoly.AsyncModeEnable = true; textureBrowserEPoly.OnSelectImage += new TgcTextureBrowser.SelectImageHandler(textureBrowserEPoly_OnSelectImage); textureBrowserEPoly.OnClose += new TgcTextureBrowser.CloseHandler(textureBrowserEPoly_OnClose); //Tooltips toolTips.SetToolTip(radioButtonSelectObject, "Select object (Q)"); toolTips.SetToolTip(buttonSelectAll, "Select all objects (CTRL + E)"); toolTips.SetToolTip(checkBoxShowObjectsBoundingBox, "Show objects BoundingBox"); toolTips.SetToolTip(checkBoxSnapToGrid, "Toogle snap to grid"); toolTips.SetToolTip(numericUpDownCellSize, "Snap to grid cell size"); toolTips.SetToolTip(buttonZoomObject, "Zoom selected object (Z)"); toolTips.SetToolTip(buttonHideSelected, "Hide selected objects (H)"); toolTips.SetToolTip(buttonUnhideAll, "Unhide all hidden objects"); toolTips.SetToolTip(buttonDeleteObject, "Delete selected objects (DEL)"); toolTips.SetToolTip(buttonCloneObject, "Clone selected objects (CTRL + V)"); toolTips.SetToolTip(radioButtonFPSCamera, "Toogle First-person camera (C)"); toolTips.SetToolTip(numericUpDownFPSCameraSpeed, "First-person camera speed factor"); toolTips.SetToolTip(buttonObjectBrowser, "Open Object Browser (O)"); toolTips.SetToolTip(buttonTopView, "Set camera in Top-view (T)"); toolTips.SetToolTip(buttonLeftView, "Set camera in Left-view (L)"); toolTips.SetToolTip(buttonMergeSelected, "Merge selected objects (G)"); toolTips.SetToolTip(buttonSaveScene, "Save scene in last used path (CTRL + S)"); toolTips.SetToolTip(buttonSaveSceneAs, "Save scene in a new path (CTRL + SHIFT + S)"); toolTips.SetToolTip(checkBoxAttachExport, "If selected all the scene is exported as one single mesh"); toolTips.SetToolTip(buttonHelp, "Open Help (F1)"); toolTips.SetToolTip(radioButtonPrimitive_Box, "Create a new Box (B)"); toolTips.SetToolTip(radioButtonPrimitive_Sphere, "Create a new Sphere"); toolTips.SetToolTip(radioButtonPrimitive_PlaneXZ, "Create a new XZ-plane (P)"); toolTips.SetToolTip(radioButtonPrimitive_PlaneXY, "Create a new XY-plane"); toolTips.SetToolTip(radioButtonPrimitive_PlaneYZ, "Create a new YZ-plane"); toolTips.SetToolTip(buttonImportMesh, "Import an existing mesh (M)"); toolTips.SetToolTip(textBoxCreateCurrentLayer, "Default layer for new created objects"); toolTips.SetToolTip(buttonModifyConvertToMesh, "Conver to Mesh primitive"); toolTips.SetToolTip(radioButtonModifySelectAndMove, "Move selected objects (W)"); toolTips.SetToolTip(radioButtonModifySelectAndRotate, "Rotate selected objects (E)"); toolTips.SetToolTip(radioButtonModifySelectAndScale, "Scale selected objects (R)"); toolTips.SetToolTip(pictureBoxModifyTexture, "Change primitive texture"); toolTips.SetToolTip(buttonModifyRecomputeAABB, "Compute a new BoundingBox for the primitive"); toolTips.SetToolTip(radioButtonEPolyPrimitiveVertex, "Vertex primitve"); toolTips.SetToolTip(radioButtonEPolyPrimitiveEdge, "Edge primitve"); toolTips.SetToolTip(radioButtonEPolyPrimitivePolygon, "Polygon primitve"); toolTips.SetToolTip(radioButtonEPolySelect, "Select primitive (Q)"); toolTips.SetToolTip(buttonEPolySelectAll, "Select all primitives (CTRL + E)"); toolTips.SetToolTip(radioButtonEPolyTranslate, "Move selected primitives (W)"); toolTips.SetToolTip(buttonEPolyDelete, "Delete selected primitives (DEL)"); toolTips.SetToolTip(buttonEPolyAddTexture, "Add new texture to mesh"); toolTips.SetToolTip(buttonEPolyDeleteTexture, "Remove current texture"); toolTips.SetToolTip(pictureBoxEPolyTexture, "Change current texture"); }
/// <summary> /// Setear estado EditablePoly /// </summary> /// <param name="enabled"></param> public void setEditablePolyEnable(bool enabled, EditablePoly.PrimitiveType primitiveType) { if (enabled) { currentState = State.EditablePoly; groupBoxEPolyCommon.Enabled = true; creatingPrimitive = null; currentGizmo = null; MeshPrimitive m = (MeshPrimitive)selectionList[0]; m.enableEditablePoly(true, primitiveType); } else { if (currentState == State.EditablePoly) { MeshPrimitive m = (MeshPrimitive)selectionList[0]; m.enableEditablePoly(false, primitiveType); radioButtonEPolyPrimitiveVertex.Checked = false; radioButtonEPolyPrimitiveEdge.Checked = false; radioButtonEPolyPrimitivePolygon.Checked = false; groupBoxEPolyCommon.Enabled = false; groupBoxEPolyEditVertices.Enabled = false; groupBoxEPolyEditEdges.Enabled = false; groupBoxEPolyEditPolygons.Enabled = false; setSelectObjectState(); } } }
/// <summary> /// Setear estado de Seleccion de Objetos /// </summary> public void setSelectObjectState() { untoggleAllRadioButtons(radioButtonSelectObject); currentState = State.SelectObject; creatingPrimitive = null; currentGizmo = null; }
/// <summary> /// Clic en "Crear Sphere" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void radioButtonPrimitive_Sphere_CheckedChanged(object sender, EventArgs e) { if (radioButtonPrimitive_Sphere.Checked) { untoggleAllRadioButtons(radioButtonPrimitive_Sphere); currentState = State.CreatePrimitiveSelected; creatingPrimitive = new SpherePrimitive(this); } }
/// <summary> /// Agregar mesh creado /// </summary> public void addMesh(EditorPrimitive mesh) { this.meshes.Add(mesh); }
/// <summary> /// Clic en "Seleccionar y Escalar" /// </summary> private void radioButtonModifySelectAndScale_CheckedChanged(object sender, EventArgs e) { if (radioButtonModifySelectAndScale.Checked) { untoggleAllRadioButtons(radioButtonModifySelectAndScale); currentState = State.SelectObject; creatingPrimitive = null; currentGizmo = scaleGizmo; //Activar gizmo si hay seleccion if (selectionList.Count > 0) { selectionRectangle.activateCurrentGizmo(); } } }
/// <summary> /// Mover gizmo de lugar para acomodarse a la nueva posicion del objeto seleccionado /// </summary> public abstract void move(EditorPrimitive selectedPrimitive, Vector3 movement);
/// <summary> /// Mover gizmo /// </summary> public override void move(EditorPrimitive selectedPrimitive, Vector3 movement) { gizmoMesh.moveGizmo(movement); }
/// <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); } }
/// <summary> /// Selecciona un solo objeto /// </summary> public void selectObject(EditorPrimitive p) { p.setSelected(true); control.SelectionList.Add(p); }