public void SelectProjector(int projectorIndex, bool animateIndex) { if (projectorCount <= projectorIndex) { return; } ProjectionMesh mesh = null; if (selectedMesh >= 0 && selectedMesh <= 7) { GetCurrentProjectionCamera().DeactivateSelection(); } selectedMesh = projectorIndex; mesh = GetCurrentProjectionCamera(); calibrationManager.currentProjectorText.text = (projectorIndex + 1).ToString(); if (animateIndex) { mesh.ShowProjectorIndex(); } //check to see if in blend, white balance or help mode if (calibrationManager.state == CalibrationManager.MenuState.BLEND || calibrationManager.state == CalibrationManager.MenuState.WHITE_BALANCE || calibrationManager.state == CalibrationManager.MenuState.HELP) { //cache the current mode CalibrationManager.MenuState state = calibrationManager.state; //reset selections SetEditMode(ProjectionMesh.MeshEditMode.NONE); //reapply current mode calibrationManager.SetButtonState(state); } else { //use last used edit mode SetEditMode(mesh.editMode); } //update UI values by applying only to sliders calibrationManager.topRangeSlider.value = mesh.topFadeRange; calibrationManager.topChokeSlider.value = mesh.topFadeChoke; calibrationManager.bottomRangeSlider.value = mesh.bottomFadeRange; calibrationManager.bottomChokeSlider.value = mesh.bottomFadeChoke; calibrationManager.leftRangeSlider.value = mesh.leftFadeRange; calibrationManager.leftChokeSlider.value = mesh.leftFadeChoke; calibrationManager.rightRangeSlider.value = mesh.rightFadeRange; calibrationManager.rightChokeSlider.value = mesh.rightFadeChoke; calibrationManager.redSlider.value = mesh.tint.r * 255; calibrationManager.greenSlider.value = mesh.tint.g * 255; calibrationManager.blueSlider.value = mesh.tint.b * 255; }
public override void OnInspectorGUI() { //DrawDefaultInspector(); serializedObject.Update(); myScript = (ProjectionMesh)target; EditorGUILayout.Space(); EditorGUILayout.LabelField("Reference Camera", EditorStyles.boldLabel); float planeDistance = EditorGUILayout.FloatField("Plane Distance", myScript.planeDistance); planeDistance = Mathf.Clamp(planeDistance, myScript.targetCamera.nearClipPlane + 0.01f, myScript.targetCamera.farClipPlane - 0.01f); myScript.planeDistance = planeDistance; float indexAppearDuration = EditorGUILayout.FloatField("Index Appear Duration", myScript.indexAppearDuration); indexAppearDuration = Mathf.Clamp(indexAppearDuration, 0, float.MaxValue); myScript.indexAppearDuration = indexAppearDuration; EditorGUILayout.Space(); EditorGUILayout.LabelField("Edit Mode", EditorStyles.boldLabel); myScript.editMode = (ProjectionMesh.MeshEditMode)EditorGUILayout.EnumPopup("Mesh Edit Mode", myScript.editMode); int selectedVertex = EditorGUILayout.IntField("Selected Vertex", myScript.selectedVertex); selectedVertex = Mathf.Clamp(selectedVertex, -1, (myScript.xDivisions + 1) * (myScript.yDivisions + 1) - 1); myScript.selectedVertex = selectedVertex; myScript.selectionActive = EditorGUILayout.Toggle("Selection Active", myScript.selectionActive); EditorGUILayout.BeginVertical(EditorStyles.helpBox); switch (myScript.editMode) { case ProjectionMesh.MeshEditMode.CORNERS: EditorGUILayout.LabelField("Corner Offsets", EditorStyles.boldLabel); for (int i = 0; i < 4; i++) { myScript.cornerOffset[i] = EditorGUILayout.Vector2Field("Corner Vertex " + i, myScript.cornerOffset[i]); } break; case ProjectionMesh.MeshEditMode.ROWS: /* * EditorGUILayout.LabelField("Row Offsets", EditorStyles.boldLabel); * for (int i = 0; i < myScript.yDivisions+1; i++) * { * myScript.rowOffset[i] = EditorGUILayout.Vector2Field("Row " + i, myScript.rowOffset[i]); * } */ EditorGUILayout.LabelField("Point Offsets", EditorStyles.boldLabel); for (int i = 0; i < myScript.yDivisions + 1; i++) { for (int j = 0; j < myScript.xDivisions + 1; j++) { int index = (i * (myScript.xDivisions + 1)) + j; myScript.pointOffset[index] = EditorGUILayout.Vector2Field("Point (" + i + "," + j + ")", myScript.pointOffset[index]); } } break; case ProjectionMesh.MeshEditMode.COLUMNS: /* * EditorGUILayout.LabelField("Column Offsets", EditorStyles.boldLabel); * for (int i = 0; i < myScript.xDivisions + 1; i++) * { * myScript.columnOffset[i] = EditorGUILayout.Vector2Field("Column " + i, myScript.columnOffset[i]); * } */ EditorGUILayout.LabelField("Point Offsets", EditorStyles.boldLabel); for (int i = 0; i < myScript.yDivisions + 1; i++) { for (int j = 0; j < myScript.xDivisions + 1; j++) { int index = (i * (myScript.xDivisions + 1)) + j; myScript.pointOffset[index] = EditorGUILayout.Vector2Field("Point (" + i + "," + j + ")", myScript.pointOffset[index]); } } break; case ProjectionMesh.MeshEditMode.POINTS: EditorGUILayout.LabelField("Point Offsets", EditorStyles.boldLabel); for (int i = 0; i < myScript.yDivisions + 1; i++) { for (int j = 0; j < myScript.xDivisions + 1; j++) { int index = (i * (myScript.xDivisions + 1)) + j; myScript.pointOffset[index] = EditorGUILayout.Vector2Field("Point (" + i + "," + j + ")", myScript.pointOffset[index]); } } break; default: break; } EditorGUILayout.Space(); if (GUILayout.Button("Reset All Offsets")) { myScript.ResetOffsets(); } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Fade Controls", EditorStyles.boldLabel); float topFadeRange = EditorGUILayout.FloatField("Top Fade Range", myScript.topFadeRange); topFadeRange = Mathf.Clamp(topFadeRange, 0f, 1f); myScript.topFadeRange = topFadeRange; float topFadeChoke = EditorGUILayout.FloatField("Top Fade Choke", myScript.topFadeChoke); topFadeChoke = Mathf.Clamp(topFadeChoke, 0f, 0.999f); myScript.topFadeChoke = topFadeChoke; float bottomFadeRange = EditorGUILayout.FloatField("Bottom Fade Range", myScript.bottomFadeRange);; bottomFadeRange = Mathf.Clamp(bottomFadeRange, 0f, 1f); myScript.bottomFadeRange = bottomFadeRange; float bottomFadeChoke = EditorGUILayout.FloatField("Bottom Fade Choke", myScript.bottomFadeChoke); bottomFadeChoke = Mathf.Clamp(bottomFadeChoke, 0f, 0.999f); myScript.bottomFadeChoke = bottomFadeChoke; float leftFadeRange = EditorGUILayout.FloatField("Left Fade Range", myScript.leftFadeRange); leftFadeRange = Mathf.Clamp(leftFadeRange, 0f, 1f); myScript.leftFadeRange = leftFadeRange; float leftFadeChoke = EditorGUILayout.FloatField("Left Fade Choke", myScript.leftFadeChoke); leftFadeChoke = Mathf.Clamp(leftFadeChoke, 0f, 0.999f); myScript.leftFadeChoke = leftFadeChoke; float rightFadeRange = EditorGUILayout.FloatField("Right Fade Range", myScript.rightFadeRange); rightFadeRange = Mathf.Clamp(rightFadeRange, 0f, 1f); myScript.rightFadeRange = rightFadeRange; float rightFadeChoke = EditorGUILayout.FloatField("Right Fade Choke", myScript.rightFadeChoke); rightFadeChoke = Mathf.Clamp(rightFadeChoke, 0f, 0.999f); myScript.rightFadeChoke = rightFadeChoke; EditorGUILayout.Space(); EditorGUILayout.LabelField("White Balance", EditorStyles.boldLabel); myScript.tint = EditorGUILayout.ColorField("Tint", myScript.tint); EditorGUILayout.Space(); EditorGUILayout.LabelField("Grid", EditorStyles.boldLabel); myScript.unselectedGridLineMaterial = (Material)EditorGUILayout.ObjectField("Unselected Grid Line Material", myScript.unselectedGridLineMaterial, typeof(Material), true); myScript.selectedGridLineMaterial = (Material)EditorGUILayout.ObjectField("Selected Grid Line Material", myScript.selectedGridLineMaterial, typeof(Material), true); myScript.activeGridLineMaterial = (Material)EditorGUILayout.ObjectField("Active Grid Line Material", myScript.activeGridLineMaterial, typeof(Material), true); /* * myScript.unselectedLineColor = EditorGUILayout.ColorField("Unselected Line Color", myScript.unselectedLineColor); * myScript.selectedLineColor = EditorGUILayout.ColorField("Selected Line Color", myScript.selectedLineColor); * myScript.activeLineColor = EditorGUILayout.ColorField("Active Line Color", myScript.activeLineColor); */ EditorGUILayout.Space(); EditorGUILayout.LabelField("Custom Options", EditorStyles.boldLabel); myScript.showGrid = EditorGUILayout.Toggle("Show Grid", myScript.showGrid); myScript.showSelectedGrid = EditorGUILayout.Toggle("Show Selected Grid", myScript.showSelectedGrid); myScript.showControlPoints = EditorGUILayout.Toggle("Show Control Points", myScript.showControlPoints); myScript.showSelectedControlPoints = EditorGUILayout.Toggle("Show Selected Control Points", myScript.showSelectedControlPoints); if (myScript.showControlPoints) { myScript.ShowControlPoints(); } else { myScript.HideControlPoints(); } EditorGUILayout.Space(); GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); foldoutStyle.fontStyle = FontStyle.Bold; showReferenceGameObjects = EditorGUILayout.Foldout(showReferenceGameObjects, "Reference Game Objects", foldoutStyle); if (showReferenceGameObjects) { myScript.targetCamera = (Camera)EditorGUILayout.ObjectField("Target Camera", myScript.targetCamera, typeof(Camera), true); myScript.projectorIndexText = (Text)EditorGUILayout.ObjectField("Projector Index Text", myScript.projectorIndexText, typeof(Text), true); myScript.controlPointsContainer = (Transform)EditorGUILayout.ObjectField("Control Points Container", myScript.controlPointsContainer, typeof(Transform), true); myScript.baseRowLinesContainer = (Transform)EditorGUILayout.ObjectField("Base Row Lines", myScript.baseRowLinesContainer, typeof(Transform), true); myScript.baseColumnLinesContainer = (Transform)EditorGUILayout.ObjectField("Base Column Lines", myScript.baseColumnLinesContainer, typeof(Transform), true); myScript.selectedRowLinesContainer = (Transform)EditorGUILayout.ObjectField("Selected Row Lines", myScript.selectedRowLinesContainer, typeof(Transform), true); myScript.selectedColumnLinesContainer = (Transform)EditorGUILayout.ObjectField("Selected Column Lines", myScript.selectedColumnLinesContainer, typeof(Transform), true); myScript.meshFilter = (MeshFilter)EditorGUILayout.ObjectField("Mesh Filter", myScript.meshFilter, typeof(MeshFilter), true); myScript.selectedControlPoint = (ControlPoint)EditorGUILayout.ObjectField("Selected Control Point", myScript.selectedControlPoint, typeof(ControlPoint), true); } if (GUI.changed) { myScript.ClearControlPoints(); myScript.ClearBaseGridLines(); myScript.CreateMesh(); myScript.BlendRefresh(); if (myScript.showControlPoints) { myScript.ShowControlPoints(); } else { myScript.HideControlPoints(); } if (myScript.showSelectedControlPoints) { myScript.ShowSelectedControlPoints(); } else { myScript.HideSelectedControlPoints(); } if (myScript.showGrid) { myScript.ShowBaseGrid(); } else { myScript.HideBaseGrid(); } if (myScript.showSelectedGrid) { myScript.ShowSelectedGrid(); } else { myScript.HideSelectedGrid(); } //show selections myScript.HighlightSelection(); myScript.UpdateSelectedLines(); //EditorUtility.SetDirty(myScript); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } serializedObject.ApplyModifiedProperties(); }
void OnEnable() { myScript = (ProjectionMesh)target; }
public bool LoadCalibration(string path) { if (path == null || path.Length == 0) { return(false); } string json = ""; try { string line; StreamReader theReader = new StreamReader(path, Encoding.Default); using (theReader) { do { line = theReader.ReadLine(); if (line != null) { json += line; } }while (line != null); theReader.Close(); } } catch (Exception e) { //Console.WriteLine("{0}\n", e.Message); Debug.Log(e.Message); return(false); } var N = JSON.Parse(json); fieldOfView = N["FieldOfView"].AsFloat; projectorCount = N["Cameras"].Count; renderTextureSize = new Vector2(N["TextureWidth"].AsInt, N["TextureHeight"].AsInt); xDivisions = N["XDivisions"].AsInt; yDivisions = N["YDivisions"].AsInt; arrangement = (CameraArragement)N["Arrangement"].AsInt; overlap = new Vector2(N["OverlapX"].AsFloat, N["OverlapY"].AsFloat); viewportSize = N["ViewportSize"].AsFloat; near = N["Near"].AsFloat; far = N["Far"].AsFloat; projectionCameraSpace = N["Spacing"].AsFloat; DestroyCameras(); InitCameras(); for (int i = 0; i < projectorCount; i++) { ProjectionMesh projectionMesh = projectionCameras[i]; JSONNode cameraNode = N["Cameras"][i]; projectionMesh.leftFadeRange = cameraNode["LeftFadeRange"].AsFloat; projectionMesh.leftFadeChoke = cameraNode["LeftFadeChoke"].AsFloat; projectionMesh.rightFadeRange = cameraNode["RightFadeRange"].AsFloat; projectionMesh.rightFadeChoke = cameraNode["RightFadeChoke"].AsFloat; projectionMesh.topFadeRange = cameraNode["TopFadeRange"].AsFloat; projectionMesh.topFadeChoke = cameraNode["TopFadeChoke"].AsFloat; projectionMesh.bottomFadeRange = cameraNode["BottomFadeRange"].AsFloat; projectionMesh.bottomFadeChoke = cameraNode["BottomFadeChoke"].AsFloat; projectionMesh.tint = new Color(cameraNode["Tint"]["r"].AsFloat, cameraNode["Tint"]["g"].AsFloat, cameraNode["Tint"]["b"].AsFloat); JSONNode cornerNode = cameraNode["Offset"]["Corner"]; for (int j = 0; j < 4; j++) { projectionMesh.cornerOffset[j] = new Vector2(cornerNode[j * 2].AsFloat, cornerNode[(j * 2) + 1].AsFloat); } /* * JSONNode rowNode = cameraNode["Offset"]["Row"]; * * for (int j = 0; j < yDivisions+1; j++) * { * projectionMesh.rowOffset[j] = new Vector2(rowNode[j * 2].AsFloat, rowNode[(j * 2) + 1].AsFloat); * } * * JSONNode columnNode = cameraNode["Offset"]["Column"]; * * for (int j = 0; j < xDivisions+1; j++) * { * projectionMesh.columnOffset[j] = new Vector2(columnNode[j * 2].AsFloat, columnNode[(j * 2) + 1].AsFloat); * } */ JSONNode pointNode = cameraNode["Offset"]["Point"]; for (int j = 0; j < (xDivisions + 1) * (yDivisions + 1); j++) { projectionMesh.pointOffset[j] = new Vector2(pointNode[j * 2].AsFloat, pointNode[(j * 2) + 1].AsFloat); } projectionMesh.CreateMesh(); projectionMesh.BlendRefresh(); //projectionMesh.OffsetRefresh(); projectionMesh.UpdateUI(); } defaultCalibrationFile = path; UpdateSourceCameras(); Debug.Log(path + " has been loaded."); return(true); }
public void SaveCalibration(string path) { if (path == null || path.Length == 0) { return; } // Debug.Log(Application.dataPath+"/"+path); string json = ""; json += "{"; #region Global Settings json += "\"Version\": \"" + "2.0.0" + "\","; json += "\"Arrangement\":" + (int)arrangement + ","; json += "\"TextureWidth\":" + (int)renderTextureSize.x + ","; json += "\"TextureHeight\":" + (int)renderTextureSize.y + ","; json += "\"XDivisions\":" + xDivisions + ","; json += "\"YDivisions\":" + yDivisions + ","; json += "\"OverlapX\":" + overlap.x + ","; json += "\"OverlapY\":" + overlap.y + ","; json += "\"ViewportSize\":" + viewportSize + ","; json += "\"FieldOfView\":" + fieldOfView + ","; json += "\"Near\":" + near + ","; json += "\"Far\":" + far + ","; json += "\"Spacing\":" + projectionCameraSpace + ","; json += "\"Cameras\":"; #endregion json += "["; for (int i = 0; i < projectorCount; i++) { ProjectionMesh projectionMesh = projectionCameras[i]; json += "{"; #region Edge Blending & White Balance json += "\"LeftFadeRange\":" + projectionMesh.leftFadeRange + ","; json += "\"LeftFadeChoke\":" + projectionMesh.leftFadeChoke + ","; json += "\"RightFadeRange\":" + projectionMesh.rightFadeRange + ","; json += "\"RightFadeChoke\":" + projectionMesh.rightFadeChoke + ","; json += "\"TopFadeRange\":" + projectionMesh.topFadeRange + ","; json += "\"TopFadeChoke\":" + projectionMesh.topFadeChoke + ","; json += "\"BottomFadeRange\":" + projectionMesh.bottomFadeRange + ","; json += "\"BottomFadeChoke\":" + projectionMesh.bottomFadeChoke + ","; json += "\"Tint\":" + "{ \"r\":" + projectionMesh.tint.r + ",\"g\":" + projectionMesh.tint.g + ",\"b\":" + projectionMesh.tint.b + "},"; #endregion #region Offsets json += "\"Offset\":"; json += "{"; json += "\"Corner\":"; json += "["; for (int j = 0; j < 4; j++) { json += projectionMesh.cornerOffset[j].x; json += ","; json += projectionMesh.cornerOffset[j].y; if (j < 3) { json += ","; } } json += "]"; json += ","; /* * json += "\"Row\":"; * json += "["; * for (int j = 0; j < yDivisions+1; j++) * { * json += projectionMesh.rowOffset[j].x; * json += ","; * json += projectionMesh.rowOffset[j].y; * if (j < yDivisions) json += ","; * } * json += "]"; * json += ","; * json += "\"Column\":"; * json += "["; * for (int j = 0; j < xDivisions+1; j++) * { * json += projectionMesh.columnOffset[j].x; * json += ","; * json += projectionMesh.columnOffset[j].y; * if (j < xDivisions) json += ","; * } * json += "]"; * json += ","; */ json += "\"Point\":"; json += "["; int pointCount = (xDivisions + 1) * (yDivisions + 1); for (int j = 0; j < pointCount; j++) { json += projectionMesh.pointOffset[j].x; json += ","; json += projectionMesh.pointOffset[j].y; if (j < pointCount - 1) { json += ","; } } json += "]"; #endregion json += "}"; json += "}"; if (i < projectorCount - 1) { json += ","; } } json += "]"; json += "}"; var sr = File.CreateText(Application.dataPath + "/../" + path); sr.WriteLine(json); sr.Close(); Debug.Log(path + " has been saved."); }
void Update() { //don't allow keyboard inputs when input field is focused CalibrationManager calibrationManager = system.calibrationManager; if (calibrationManager.topRangeInputField.isFocused || calibrationManager.topChokeInputField.isFocused || calibrationManager.bottomRangeInputField.isFocused || calibrationManager.bottomChokeInputField.isFocused || calibrationManager.leftRangeInputField.isFocused || calibrationManager.leftChokeInputField.isFocused || calibrationManager.rightRangeInputField.isFocused || calibrationManager.rightChokeInputField.isFocused || calibrationManager.redInputField.isFocused || calibrationManager.greenInputField.isFocused || calibrationManager.blueInputField.isFocused || calibrationManager.filename.isFocused) { return; } ProjectionMesh mesh = system.GetCurrentProjectionCamera(); #region Visibility Toggles if (Input.GetKeyDown(uiToggleKey)) { system.showProjectionWarpGUI = !system.showProjectionWarpGUI; system.UpdateProjectionWarpGUI(); } if (Input.GetKeyDown(mouseToggleKey)) { system.showMouseCursor = !system.showMouseCursor; system.UpdateCursor(); } if (Input.GetKeyDown(gridToggleKey)) { if (mesh != null) { mesh.ToggleBaseGrid(); } } if (Input.GetKeyDown(selectedGridToggleKey)) { if (mesh != null) { mesh.ToggleSelectedGrid(); } } if (Input.GetKeyDown(controlPointsToggleKey)) { if (mesh != null) { mesh.ToggleControlPoints(); } } if (Input.GetKeyDown(selectedControlPointsToggleKey)) { if (mesh != null) { mesh.ToggleSelectedControlPoints(); } } #endregion #region UI Toggles if (Input.GetKeyDown(helpKey)) { system.calibrationManager.OnToggleHelp(); } if (Input.GetKeyDown(noModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.NONE); } else if (Input.GetKeyDown(cornerModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.CORNERS); } else if (Input.GetKeyDown(rowModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.ROWS); } else if (Input.GetKeyDown(columnModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.COLUMNS); } else if (Input.GetKeyDown(pointModeKey)) { system.SetEditMode(ProjectionMesh.MeshEditMode.POINTS); } if (Input.GetKeyDown(blendingModeKey)) { system.calibrationManager.OnToggleBlend(); } else if (Input.GetKeyDown(whiteBalanceModeKey)) { system.calibrationManager.OnToggleWhiteBalance(); } #endregion #region Projector Selection if (Input.GetKeyDown(projectorAKey) || Input.GetKeyDown(projectorAAltKey)) { system.SelectProjector(0, true); } else if (Input.GetKeyDown(projectorBKey) || Input.GetKeyDown(projectorBAltKey)) { system.SelectProjector(1, true); } else if (Input.GetKeyDown(projectorCKey) || Input.GetKeyDown(projectorCAltKey)) { system.SelectProjector(2, true); } else if (Input.GetKeyDown(projectorDKey) || Input.GetKeyDown(projectorDAltKey)) { system.SelectProjector(3, true); } else if (Input.GetKeyDown(projectorEKey) || Input.GetKeyDown(projectorEAltKey)) { system.SelectProjector(4, true); } else if (Input.GetKeyDown(projectorFKey) || Input.GetKeyDown(projectorFAltKey)) { system.SelectProjector(5, true); } else if (Input.GetKeyDown(projectorGKey) || Input.GetKeyDown(projectorGAltKey)) { system.SelectProjector(6, true); } else if (Input.GetKeyDown(projectorHKey) || Input.GetKeyDown(projectorHAltKey)) { system.SelectProjector(7, true); } #endregion #region Selection Activation if (mesh != null) { if (mesh.editMode != ProjectionMesh.MeshEditMode.NONE) { if (Input.GetKeyDown(activateKey)) { if (mesh.selectionActive) { mesh.DeactivateSelection(); } else { mesh.ActivateSelection(); } } } } #endregion #region Point Selection and Adjustment //corner indexes are at - 0, xDivisions, (xDivisions+1) * yDivisions, (xDivisions+1) * (yDivisions+1)-1 float adjustmentScale = 0.1f; if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) { adjustmentScale = 0.001f; } if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) { adjustmentScale = 0.01f; } else if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { adjustmentScale = 0.1f; } if (mesh != null) { switch (mesh.editMode) { case ProjectionMesh.MeshEditMode.CORNERS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } //navigate control point corners if (!mesh.selectionActive) { if (Input.GetKeyDown(upKey)) { if (mesh.selectedVertex > system.xDivisions) { mesh.selectedVertex -= ((system.xDivisions + 1) * system.yDivisions); } } if (Input.GetKeyDown(downKey)) { if (mesh.selectedVertex < system.xDivisions + 1) { mesh.selectedVertex += ((system.xDivisions + 1) * system.yDivisions); } } if (Input.GetKeyDown(leftKey)) { if (mesh.selectedVertex == system.xDivisions || mesh.selectedVertex == ((system.xDivisions + 1) * (system.yDivisions + 1) - 1)) { mesh.selectedVertex -= system.xDivisions; } } if (Input.GetKeyDown(rightKey)) { if (mesh.selectedVertex == 0 || mesh.selectedVertex == ((system.xDivisions + 1) * system.yDivisions)) { mesh.selectedVertex += system.xDivisions; } } } //move control points else { int cornerIndex = -1; if (mesh.selectedVertex == 0) { cornerIndex = 0; } else if (mesh.selectedVertex == mesh.xDivisions) { cornerIndex = 1; } else if (mesh.selectedVertex == ((mesh.xDivisions + 1) * mesh.yDivisions)) { cornerIndex = 2; } else if (mesh.selectedVertex == ((mesh.xDivisions + 1) * (mesh.yDivisions + 1) - 1)) { cornerIndex = 3; } Vector2 point = mesh.cornerOffset[cornerIndex]; if (Input.GetKeyDown(upKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { mesh.cornerOffset[cornerIndex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { mesh.cornerOffset[cornerIndex] = Vector2.zero; } } break; case ProjectionMesh.MeshEditMode.ROWS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } //up and down selects row if (!mesh.selectionActive) { if (Input.GetKeyDown(upKey)) { if (mesh.selectedVertex > system.xDivisions) { mesh.selectedVertex -= (system.xDivisions + 1); } } if (Input.GetKeyDown(downKey)) { if (mesh.selectedVertex < ((system.xDivisions + 1) * system.yDivisions)) { mesh.selectedVertex += (system.xDivisions + 1); } } } //move row around else { //figured out which row is being moved int rowIndex = -1; rowIndex = (int)Mathf.Floor(mesh.selectedVertex / (mesh.xDivisions + 1)); Vector2 point; int index; //Vector2 point = mesh.rowOffset[rowIndex]; if (Input.GetKeyDown(upKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } //mesh.rowOffset[rowIndex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } //mesh.rowOffset[rowIndex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } //mesh.rowOffset[rowIndex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } //mesh.rowOffset[rowIndex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { for (var i = 0; i < mesh.xDivisions + 1; i++) { index = (rowIndex * (mesh.xDivisions + 1)) + i; mesh.pointOffset[index] = Vector2.zero; } } } break; case ProjectionMesh.MeshEditMode.COLUMNS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } //left and right selects column if (!mesh.selectionActive) { if (Input.GetKeyDown(leftKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != 0) { mesh.selectedVertex -= 1; } } if (Input.GetKeyDown(rightKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != system.xDivisions) { mesh.selectedVertex += 1; } } } //move column around else { //figured out which column is being moved int columnIndex = -1; columnIndex = mesh.selectedVertex % (mesh.xDivisions + 1); Vector2 point; int index; if (Input.GetKeyDown(upKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } //mesh.columnOffset[columnIndex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } //mesh.columnOffset[columnIndex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } //mesh.columnOffset[columnIndex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; point = mesh.pointOffset[index]; mesh.pointOffset[index] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } //mesh.columnOffset[columnIndex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { for (var i = 0; i < mesh.yDivisions + 1; i++) { index = (i * (mesh.xDivisions + 1)) + columnIndex; mesh.pointOffset[index] = Vector2.zero; } } } break; case ProjectionMesh.MeshEditMode.POINTS: if (mesh.selectedVertex < 0) { mesh.selectedVertex = 0; } if (!mesh.selectionActive) { if (Input.GetKeyDown(upKey)) { if (mesh.selectedVertex > system.xDivisions) { mesh.selectedVertex -= (system.xDivisions + 1); } } if (Input.GetKeyDown(downKey)) { if (mesh.selectedVertex < ((system.xDivisions + 1) * system.yDivisions)) { mesh.selectedVertex += (system.xDivisions + 1); } } if (Input.GetKeyDown(leftKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != 0) { mesh.selectedVertex -= 1; } } if (Input.GetKeyDown(rightKey)) { if (mesh.selectedVertex % (system.xDivisions + 1) != system.xDivisions) { mesh.selectedVertex += 1; } } } else { //figured out which row is being moved Vector2 point = mesh.pointOffset[mesh.selectedVertex]; if (Input.GetKeyDown(upKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x, point.y + (0.1f * adjustmentScale)); } if (Input.GetKeyDown(downKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x, point.y - (0.1f * adjustmentScale)); } if (Input.GetKeyDown(leftKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x - (0.1f * adjustmentScale), point.y); } if (Input.GetKeyDown(rightKey)) { mesh.pointOffset[mesh.selectedVertex] = new Vector2(point.x + (0.1f * adjustmentScale), point.y); } if (Input.GetKey(zeroOffsetKey)) { mesh.pointOffset[mesh.selectedVertex] = Vector2.zero; } } break; default: case ProjectionMesh.MeshEditMode.NONE: break; } } #endregion if (Input.anyKeyDown) { //only rebuild when keys have been pressed if (mesh != null) { mesh.UpdateMeshVertices(); mesh.CreateBaseGridLines(); mesh.HighlightSelection(); mesh.UpdateSelectedLines(); } } }