/// <summary> /// Actualizar escala de mesh en base a valores de inputs /// </summary> private void updateMeshScaleFromGui() { SceneEditorMeshObject meshObj = selectedMeshList[0]; Vector3 newScale = meshObj.mesh.Scale; //Nueva posicion en base a input de usuario if (ValidationUtils.validatePossitiveFloat(meshScaleX.Text)) { newScale.X = float.Parse(meshScaleX.Text); } else { meshScaleX.Text = newScale.X.ToString(); } if (ValidationUtils.validatePossitiveFloat(meshScaleY.Text)) { newScale.Y = float.Parse(meshScaleY.Text); } { meshScaleY.Text = newScale.Y.ToString(); } if (ValidationUtils.validatePossitiveFloat(meshScaleZ.Text)) { newScale.Z = float.Parse(meshScaleZ.Text); } else { meshScaleZ.Text = newScale.Z.ToString(); } //Actualizar escala meshObj.mesh.Scale = newScale; }
/// <summary> /// Crear el mesh y cargarlo en la tabla /// </summary> private void meshCreate_Click(object sender, EventArgs e) { if (meshFilePath == null || meshFilePath.Equals("")) { return; } try { //Parsear XML de mesh string mediaPath = meshFilePath.Substring(0, meshFilePath.LastIndexOf('\\') + 1); string xmlString = File.ReadAllText(meshFilePath); TgcSceneData sceneData = parser.parseSceneFromString(xmlString); //Crear el mesh tantas veces como se haya pedido int cantidad = (int)amountToCreate.Value; Vector3 initialPos = getInitialPos(); for (int i = 0; i < cantidad; i++) { TgcScene scene = sceneLoader.loadScene(sceneData, mediaPath); float radius = scene.Meshes[0].BoundingBox.calculateBoxRadius(); float posOffsetX = radius * 2; //cargar meshes en dataGrid foreach (TgcMesh mesh in scene.Meshes) { SceneEditorMeshObject mo = new SceneEditorMeshObject(); mo.mesh = mesh; mo.name = mesh.Name + meshCounter++; mo.userInfo = ""; mo.index = meshObjects.Count; mo.fileName = fileName.Text; mo.groupIndex = meshGroupCounter; mo.folderName = meshFolderName; //Mover mesh a la posicion correcta mesh.Position = new Vector3(initialPos.X + i * posOffsetX, initialPos.Y, initialPos.Z); meshObjects.Add(mo); dataGridMeshList.Rows.Add(dataGridMeshList.Rows.Count + 1, meshGroupCounter, mo.name); } meshGroupCounter++; } //seleccionar el primer mesh en la grilla seleccionarPrimerElementoDataGrid(); //pasar a modo camara con edicion de mesh radioButtonCameraMode.Checked = true; tabControl.SelectedTab = tabControl.TabPages["tabPageModify"]; } catch (Exception ex) { MessageBox.Show("Hubo un error al cargar el archivo " + fileName.Text, "Error al cargar Mesh", MessageBoxButtons.OK, MessageBoxIcon.Error); GuiController.Instance.Logger.logError("Error al cargar Mesh de TGC", ex); } }
/// <summary> /// Cambiar nombre de mesh /// </summary> private void meshName_Leave(object sender, EventArgs e) { SceneEditorMeshObject selectedMeshObj = selectedMeshList[0]; //cambiarlo en mesh selectedMeshObj.name = meshName.Text; //cambiarlo en dataGrid dataGridMeshList.Rows[selectedMeshObj.index].Cells["MeshColumnMeshName"].Value = selectedMeshObj.name; }
/// <summary> /// Informa si un objeto esta actualmente seleccionado /// </summary> private bool isMeshObjectSelected(SceneEditorMeshObject meshObj) { foreach (SceneEditorMeshObject selectMeshObj in selectedMeshList) { if (selectMeshObj == meshObj) { return(true); } } return(false); }
/// <summary> /// Hacer picking y seleccionar modelo si hay colision /// </summary> private void findSelectedMeshWithPicking() { pickingRay.updateRay(); Vector3 collisionP; //Hacer picking sobre todos los modelos y quedarse con el mas cerca float minDistance = float.MaxValue; SceneEditorMeshObject collisionMeshObj = null; foreach (SceneEditorMeshObject meshObj in meshObjects) { if (!meshObj.visible) { continue; } //Si ya está seleccionado ignorar if (isMeshObjectSelected(meshObj)) { continue; } TgcBoundingBox aabb = meshObj.mesh.BoundingBox; bool result = TgcCollisionUtils.intersectRayAABB(pickingRay.Ray, aabb, out collisionP); if (result) { float lengthSq = Vector3.Subtract(collisionP, pickingRay.Ray.Origin).LengthSq(); if (lengthSq < minDistance) { minDistance = lengthSq; collisionMeshObj = meshObj; } } } //Seleccionar objeto if (collisionMeshObj != null) { //Deseleccionar todo for (int i = 0; i < dataGridMeshList.Rows.Count; i++) { dataGridMeshList.Rows[i].Selected = false; } //Seleccionar objeto del dataGrid dataGridMeshList.Rows[collisionMeshObj.index].Selected = true; dataGridMeshList_RowEnter(null, null); } }
/// <summary> /// Cuando seleccionan un mesh del dataGrid. /// Obtener info y cargarla en el panel de edicion /// </summary> private void dataGridMeshList_RowEnter(object sender, DataGridViewCellEventArgs e) { if (dataGridMeshList.SelectedRows.Count > 0) { //cargar lista de seleccion, al revez selectedMeshList.Clear(); for (int i = dataGridMeshList.SelectedRows.Count - 1; i >= 0; i--) { int index = dataGridMeshList.SelectedRows[i].Index; selectedMeshList.Add(meshObjects[index]); } //Seleccionar primero de la lista SceneEditorMeshObject selectedMeshObj = selectedMeshList[0]; selectMeshObject(selectedMeshObj); } }
/// <summary> /// Actualizar rotación de malla seleccionada en base a los Inputs /// </summary> private void updateMeshRotationFromGui() { SceneEditorMeshObject meshObj = selectedMeshList[0]; Vector3 newRot = meshObj.mesh.Rotation; float minValue = 0; float maxValue = 360; //Nueva rotación en base a input de usuario if (ValidationUtils.validateFloatRange(meshRotX.Text, minValue, maxValue)) { newRot.X = float.Parse(meshRotX.Text); } else { meshRotX.Text = newRot.X.ToString(); } if (ValidationUtils.validateFloatRange(meshRotY.Text, minValue, maxValue)) { newRot.Y = float.Parse(meshRotY.Text); } else { meshRotY.Text = newRot.Y.ToString(); } if (ValidationUtils.validateFloatRange(meshRotZ.Text, minValue, maxValue)) { newRot.Z = float.Parse(meshRotZ.Text); } else { meshRotZ.Text = newRot.Z.ToString(); } //Actualizar las 3 trackbars de rotacion trackBarRotationX.Value = (int)newRot.X; trackBarRotationY.Value = (int)newRot.Y; trackBarRotationZ.Value = (int)newRot.Z; //Actualizar rotacion, pasar a Radianes newRot.X = Geometry.DegreeToRadian(newRot.X); newRot.Y = Geometry.DegreeToRadian(newRot.Y); newRot.Z = Geometry.DegreeToRadian(newRot.Z); meshObj.mesh.Rotation = newRot; }
/// <summary> /// Actualizar rotacion de mesh en base a los trackbars de rotacion /// </summary> private void updateMeshRotationFromTrackbars() { SceneEditorMeshObject meshObj = selectedMeshList[0]; Vector3 newRot = meshObj.mesh.Rotation; //Actualizar rotacion en base a los trackbars newRot.X = (float)trackBarRotationX.Value; newRot.Y = (float)trackBarRotationY.Value; newRot.Z = (float)trackBarRotationZ.Value; //Actualizar inputs de rotacion meshRotX.Text = newRot.X.ToString(); meshRotY.Text = newRot.Y.ToString(); meshRotZ.Text = newRot.Z.ToString(); //pasar a Radianes newRot.X = Geometry.DegreeToRadian(newRot.X); newRot.Y = Geometry.DegreeToRadian(newRot.Y); newRot.Z = Geometry.DegreeToRadian(newRot.Z); meshObj.mesh.Rotation = newRot; }
/// <summary> /// Acomodar Gizmo en base a un Mesh /// </summary> public void setMesh(SceneEditorMeshObject meshObj) { this.meshObj = meshObj; this.selectedAxis = Axis.None; /* * float aabbbR = meshObj.mesh.BoundingBox.calculateBoxRadius(); * float largeSize = LARGE_AXIS_SIZE * aabbbR; * float shortSize = SHORT_AXIS_SIZE; * * boxX.Size = new Vector3(largeSize, shortSize, shortSize); * boxY.Size = new Vector3(shortSize, largeSize, shortSize); * boxZ.Size = new Vector3(shortSize, shortSize, largeSize); * * Vector3 pos = meshObj.mesh.Position; * boxX.Position = pos + Vector3.Scale(boxX.Size, 0.5f); * boxY.Position = pos + Vector3.Scale(boxY.Size, 0.5f); * boxZ.Position = pos + Vector3.Scale(boxZ.Size, 0.5f); */ Vector3 meshCenter = meshObj.mesh.BoundingBox.calculateBoxCenter(); Vector3 axisRadius = meshObj.mesh.BoundingBox.calculateAxisRadius(); float largeX = axisRadius.X + LARGE_AXIS_MIN_SIZE; float largeY = axisRadius.Y + LARGE_AXIS_MIN_SIZE; float largeZ = axisRadius.Z + LARGE_AXIS_MIN_SIZE; boxX.Size = new Vector3(largeX, SHORT_AXIS_SIZE, SHORT_AXIS_SIZE); boxY.Size = new Vector3(SHORT_AXIS_SIZE, largeY, SHORT_AXIS_SIZE); boxZ.Size = new Vector3(SHORT_AXIS_SIZE, SHORT_AXIS_SIZE, largeZ); boxX.Position = meshCenter + Vector3.Multiply(boxX.Size, 0.5f); boxY.Position = meshCenter + Vector3.Multiply(boxY.Size, 0.5f); boxZ.Position = meshCenter + Vector3.Multiply(boxZ.Size, 0.5f); boxX.updateValues(); boxY.updateValues(); boxZ.updateValues(); }
/// <summary> /// Actualizar posicion de malla seleccionada en base a los Inputs /// </summary> private void updateMeshPositionFromGui() { SceneEditorMeshObject meshObj = selectedMeshList[0]; Vector3 newPos = meshObj.mesh.Position; //Nueva posicion en base a input de usuario if (ValidationUtils.validateFloat(meshPosX.Text)) { newPos.X = float.Parse(meshPosX.Text); } else { meshPosX.Text = newPos.X.ToString(); } if (ValidationUtils.validateFloat(meshPosY.Text)) { newPos.Y = float.Parse(meshPosY.Text); } { meshPosY.Text = newPos.Y.ToString(); } if (ValidationUtils.validateFloat(meshPosZ.Text)) { newPos.Z = float.Parse(meshPosZ.Text); } else { meshPosZ.Text = newPos.Z.ToString(); } //Actualizar posicion meshObj.mesh.Position = newPos; //Actualizar gizmo si corresponde if (currentState == GuiState.TranslateMode) { translateGizmo.setMesh(meshObj); } }
/// <summary> /// Actualizar valores de edicion de mesh de la interfaz /// </summary> private void updateEditMeshValues(SceneEditorMeshObject meshObj) { meshName.Text = meshObj.name; Vector3 pos = meshObj.mesh.Position; meshPosX.Text = pos.X.ToString(); meshPosY.Text = pos.Y.ToString(); meshPosZ.Text = pos.Z.ToString(); Vector3 rot = meshObj.mesh.Rotation; meshRotX.Text = rot.X.ToString(); meshRotY.Text = rot.Y.ToString(); meshRotZ.Text = rot.Z.ToString(); Vector3 scale = meshObj.mesh.Scale; meshScaleX.Text = scale.X.ToString(); meshScaleY.Text = scale.Y.ToString(); meshScaleZ.Text = scale.Z.ToString(); userInfo.Text = meshObj.userInfo; }
/// <summary> /// Seleccionar objeto /// </summary> private void selectMeshObject(SceneEditorMeshObject selectedMeshObj) { //Cargar valores del panel de edicion updateEditMeshValues(selectedMeshObj); enableEditMeshPanels(true); }
/// <summary> /// Acomodar Gizmo en base a un Mesh /// </summary> public void setMesh(SceneEditorMeshObject meshObj) { this.meshObj = meshObj; this.selectedAxis = Axis.None; /* float aabbbR = meshObj.mesh.BoundingBox.calculateBoxRadius(); float largeSize = LARGE_AXIS_SIZE * aabbbR; float shortSize = SHORT_AXIS_SIZE; boxX.Size = new Vector3(largeSize, shortSize, shortSize); boxY.Size = new Vector3(shortSize, largeSize, shortSize); boxZ.Size = new Vector3(shortSize, shortSize, largeSize); Vector3 pos = meshObj.mesh.Position; boxX.Position = pos + Vector3.Scale(boxX.Size, 0.5f); boxY.Position = pos + Vector3.Scale(boxY.Size, 0.5f); boxZ.Position = pos + Vector3.Scale(boxZ.Size, 0.5f); */ Vector3 meshCenter = meshObj.mesh.BoundingBox.calculateBoxCenter(); Vector3 axisRadius = meshObj.mesh.BoundingBox.calculateAxisRadius(); float largeX = axisRadius.X + LARGE_AXIS_MIN_SIZE; float largeY = axisRadius.Y + LARGE_AXIS_MIN_SIZE; float largeZ = axisRadius.Z + LARGE_AXIS_MIN_SIZE; boxX.Size = new Vector3(largeX, SHORT_AXIS_SIZE, SHORT_AXIS_SIZE); boxY.Size = new Vector3(SHORT_AXIS_SIZE, largeY, SHORT_AXIS_SIZE); boxZ.Size = new Vector3(SHORT_AXIS_SIZE, SHORT_AXIS_SIZE, largeZ); boxX.Position = meshCenter + Vector3.Multiply(boxX.Size, 0.5f); boxY.Position = meshCenter + Vector3.Multiply(boxY.Size, 0.5f); boxZ.Position = meshCenter + Vector3.Multiply(boxZ.Size, 0.5f); boxX.updateValues(); boxY.updateValues(); boxZ.updateValues(); }
/// <summary> /// Esconder Gizmo /// </summary> public void hide() { meshObj = null; }