void OnEnable() { if (ArchimatixEngine.library == null) { ArchimatixEngine.library = Library.loadLibraryMetadata(); } showFilters = new AnimBool(false, Repaint); showDetailItem = new AnimBool(false, Repaint); libraryScrollPosition = Vector2.zero; if (ArchimatixEngine.ArchimatixAssetPath == null) { ArchimatixEngine.establishPaths(); } bgTex = (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/GeneralIcons/zz_AXIcons-Shadow.png", typeof(Texture2D)); bgTexUp = (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/GeneralIcons/zz_AXIcons-ShadowUp.png", typeof(Texture2D)); //richLeftLabelStyle.wordWrap = true; }
public static void launch3DLibraryItem(string itemName) { if (ArchimatixEngine.currentModel == null) { AXEditorUtilities.createNewModel(itemName + " (AX)"); } ArchimatixEngine.establishPaths(); // AXParametricObject po = null; // po = ArchimatixEngine.library.getFirstItemByName(Regex.Replace(itemName, @"\s+", "")); // if (po != null) // { // po = Library.instantiateParametricObject (po.readIntoLibraryFromRelativeAXOBJPath); // SceneView.FrameLastActiveSceneView(); // } LibraryItem li = ArchimatixEngine.library.getLibraryItem(itemName); if (li != null) { Library.instantiateParametricObject(li.readIntoLibraryFromRelativeAXOBJPath); } }
public static GameObject createNewModel(string m_name = null) { GameObject modelGO = new GameObject(); AXModel model = modelGO.AddComponent <AXModel>(); ArchimatixEngine.currentModel = model; if (String.IsNullOrEmpty(m_name)) { // for auto naming, get highest count... // (can't use static variable for this, since it is cleared when scene reloads). int highestnum = 0; AXModel[] axModels = GameObject.FindObjectsOfType(typeof(AXModel)) as AXModel[]; foreach (AXModel m in axModels) { String[] numbers = Regex.Split(m.name, @"\D+"); if (numbers != null && numbers.Length > 0) { string numString = numbers[numbers.Length - 1]; if (!string.IsNullOrEmpty(numString)) { int num = int.Parse(numString); if (num > highestnum) { highestnum = num; } } } } highestnum++; modelGO.name = "AXModel_" + highestnum; } else { modelGO.name = m_name; } Selection.activeGameObject = modelGO; model.axMat = new AXMaterial(); model.axMat.mat = (Material)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/Materials/AX_GridPurple.mat", typeof(Material)); model.axMat.physMat = (PhysicMaterial)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/Materials/AX_DefaultPhysicMaterial.physicMaterial", typeof(PhysicMaterial)); model.axMat.density = 1; //if (ArchimatixEngine.graphEditorIsOpen()) if (ArchimatixEngine.useKyle) { ArchimatixEngine.createScalingFigure(); } return(modelGO); }
public void OnEnable() { ArchimatixEngine.establishPaths(); AXEditorUtilities.loadNodeIcons(); infoIconTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/GeneralIcons/zz-AXMenuIcons-InfoIcon.png", typeof(Texture2D)); }
public void drawGUIControls() { //FreeCurve gener = (FreeCurve) generator; //AXModel model = ArchimatixEngine.currentModel; // 2D GUI Handles.BeginGUI(); GUIStyle buttonStyle = GUI.skin.GetStyle("Button"); buttonStyle.alignment = TextAnchor.MiddleCenter; float prevFixedWidth = buttonStyle.fixedWidth; float prevFixedHeight = buttonStyle.fixedHeight; buttonStyle.fixedHeight = 30; //GUIStyle areaStyle = new GUIStyle(); //areaStyle. = MakeTex(600, 1, new Color(1.0f, 1.0f, 1.0f, 0.1f)); float windowWidth = (SceneView.lastActiveSceneView != null) ? SceneView.lastActiveSceneView.position.width : Screen.width; float buttonWid = 100; if (ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.Default) { if (GUI.Button(new Rect(((windowWidth - buttonWid) / 2), 20, buttonWid, 30), "Add Point")) { ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.AddPoint); } } else { buttonWid = 200; if (GUI.Button(new Rect(((windowWidth - buttonWid) / 2), 20, buttonWid, 30), "Done Adding Points")) { ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default); } } EditorGUIUtility.labelWidth = 40; Handles.EndGUI(); buttonStyle.fixedWidth = prevFixedWidth; buttonStyle.fixedHeight = prevFixedHeight; }
public static AXParametricObject addNodeToCurrentModel(string nodeName, bool panTo = true, AXParametricObject basedOnPO = null) { AXModel model = getOrMakeSelectedModel(); Undo.RegisterCompleteObjectUndo(model, "Add Generator named " + nodeName); AXParametricObject npo = model.createNode(nodeName, panTo, basedOnPO); if (npo == null) { return(null); } if (basedOnPO != null) { //Debug.Log("basedOnPO.Name="+basedOnPO.Name); basedOnPO.copyTransformTo(npo); } ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); bool isInstanceofCurrentGrouper = ((npo.generator is IReplica) && model.currentWorkingGroupPO != null && basedOnPO == model.currentWorkingGroupPO); if (model.currentWorkingGroupPO != null) { List <AXParametricObject> npos = new List <AXParametricObject>(); npos.Add(npo); if (!isInstanceofCurrentGrouper) { model.currentWorkingGroupPO.addGroupees(npos); } } if (isInstanceofCurrentGrouper) { model.currentWorkingGroupPO = model.currentWorkingGroupPO.grouper; } return(npo); }
void OnEnable() { ArchimatixEngine.establishPaths(); // Is all in order with the Archimatix install? if (string.IsNullOrEmpty(ArchimatixEngine.pathChangelog)) { return; } pathImages = ArchimatixEngine.ArchimatixAssetPath + "/ui/StartupImages/"; string StartupImagesPrefix = "zz_AXStartup_"; //Debug.Log("AXStartupWindowProcessor SCREEN"); string versionColor = EditorGUIUtility.isProSkin ? "#ffffffee" : "#000000ee"; TextAsset changelogAsset = LoadAssetAt <TextAsset>(ArchimatixEngine.pathChangelog); if (changelogAsset == null) { return; } changelogText = changelogAsset.text; changelogText = Regex.Replace(changelogText, @"^[0-9].*", "<color=" + versionColor + "><size=13><b>Version $0</b></size></color>", RegexOptions.Multiline); changelogText = Regex.Replace(changelogText, @"^- (\w+:)", " <color=" + versionColor + ">$0</color>", RegexOptions.Multiline); headerPic = AssetDatabase.LoadAssetAtPath <Texture2D>(pathImages + StartupImagesPrefix + "EditorWindowBanner.jpg"); icon3DLibrary = LoadAssetAt <Texture2D>(pathImages + StartupImagesPrefix + "icon3DLibrary.jpg"); icon2DLibrary = LoadAssetAt <Texture2D>(pathImages + StartupImagesPrefix + "icon2DLibrary.jpg"); iconAXEditor = LoadAssetAt <Texture2D>(pathImages + StartupImagesPrefix + "iconEditor.jpg"); }
static void InitLibrary() { ArchimatixEngine.openLibrary3D(); }
public static void OnGUI(List <AXNode> parameters) { for (int i = 0; i < parameters.Count; i++) { AXParameter p = parameters [i] as AXParameter; EditorGUIUtility.labelWidth = 150; AXModel model = p.parametricObject.model; // PARAMETERS switch (p.Type) { // ANIMATION_CURVE case AXParameter.DataType.AnimationCurve: EditorGUI.BeginChangeCheck(); EditorGUILayout.CurveField(p.animationCurve); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "ModifierCurve"); model.isAltered(28); } break; case AXParameter.DataType.Color: EditorGUI.BeginChangeCheck(); p.colorVal = EditorGUILayout.ColorField(p.colorVal); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Color"); model.isAltered(28); } break; // FLOAT case AXParameter.DataType.Float: AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_" + p.Name); // GUI.color = Color.white; // GUI.contentColor = Color.white; // if (p.isOpen) { EditorGUILayout.BeginHorizontal("Box"); } else { EditorGUILayout.BeginHorizontal(); } EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatFieldInsp_" + p.Name); p.FloatVal = EditorGUILayout.FloatField(p.Name, p.FloatVal); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "value change for " + p.Name); p.parametricObject.initiateRipple_setFloatValueFromGUIChange(p.Name, p.FloatVal); model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } p.isOpen = EditorGUILayout.Foldout(p.isOpen, GUIContent.none); EditorGUILayout.EndHorizontal(); if (p.isOpen) { EditorGUI.indentLevel++; InspectorParameterEditGUI.OnGUI(p); EditorGUI.indentLevel--; } break; // INT case AXParameter.DataType.Int: //GUI.backgroundColor = new Color(.6f,.6f,.9f,.1f) ; // if (p.isOpen) // EditorGUILayout.BeginHorizontal ("Box"); // else EditorGUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("IntFieldFieldInsp_" + p.Name); p.IntVal = EditorGUILayout.IntField(p.Name, p.IntVal); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "value change for " + p.Name); p.parametricObject.initiateRipple_setIntValueFromGUIChange(p.Name, p.IntVal); model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } p.isOpen = EditorGUILayout.Foldout(p.isOpen, GUIContent.none); EditorGUILayout.EndHorizontal(); if (p.isOpen) { EditorGUI.indentLevel++; InspectorParameterEditGUI.OnGUI(p); EditorGUI.indentLevel--; } break; // BOOL case AXParameter.DataType.Bool: //EditorGUIUtility.currentViewWidth-16; GUILayout.BeginHorizontal(); //EditorGUIUtility.labelWidth = 150; EditorGUI.BeginChangeCheck(); p.boolval = EditorGUILayout.Toggle(p.Name, p.boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, " value change for " + p.Name); p.parametricObject.initiateRipple_setBoolParameterValueByName(p.Name, p.boolval); //p.parametricObject.model.autobuild(); p.parametricObject.model.isAltered(27); //p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } GUILayout.FlexibleSpace(); p.isOpen = EditorGUILayout.Foldout(p.isOpen, GUIContent.none); // Expose EditorGUI.BeginChangeCheck(); p.exposeAsInterface = EditorGUILayout.Toggle(p.exposeAsInterface, GUILayout.MaxWidth(20)); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Expose Parameter"); if (p.exposeAsInterface) { p.parametricObject.model.addExposedParameter(p); } else { p.parametricObject.model.removeExposedParameter(p); } } GUILayout.EndHorizontal(); break; case AXParameter.DataType.CustomOption: { // OPTION POPUP string[] options = p.optionLabels.ToArray(); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("CustomOptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUILayout.Popup( p.Name, p.intval, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.parametricObject.model.autobuild(); if (p.PType == AXParameter.ParameterType.PositionControl) { p.parametricObject.generator.adjustWorldMatrices(); } ArchimatixEngine.scheduleBuild(); } break; } } //if (p.PType != AXParameter.ParameterType.None && p.PType != AXParameter.ParameterType.GeometryControl) // continue; } }
public static void processEventCommand(Event e, AXModel model) { if (e.type == EventType.ValidateCommand) { e.Use(); } //Debug.Log("-> processEventCommand 1: PROCESS COMMAND "+e.commandName); var view = SceneView.lastActiveSceneView; string focusedControlName = GUI.GetNameOfFocusedControl(); if (model != null) { // intercept this command and use for po's switch (e.commandName) { case "UndoRedoPerformed": //Debug.Log ("UndoRedoPerformed"); model.cleanGraph(); model.autobuild(); for (int i = 0; i < model.selectedPOs.Count; i++) { model.selectedPOs[i].generator.adjustWorldMatrices(); } // SCENEVIEW if (SceneView.lastActiveSceneView != null) { SceneView.lastActiveSceneView.Repaint(); } //model.setRenderMode( AXModel.RenderMode.GameObjects ); model.cacheThumbnails("AXGeometryTools.Utilities::processEventCommand::UndoRedoPerformed"); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case "SelectAll": Debug.Log("SelectAll"); model.selectAll(); e.Use(); break; case "Copy": //Debug.Log ("COPY ..."+ GUI.GetNameOfFocusedControl()); //Debug.Log ("buf: " + EditorGUIUtility.systemCopyBuffer); //Debug.Log("-"+focusedControlName+"-"); //Debug.Log((string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_"))); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { if (model.selectedPOs.Count > 0) { EditorGUIUtility.systemCopyBuffer = LibraryEditor.poWithSubNodes_2_JSON(model.selectedPOs[0], true); } if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case "Paste": //Debug.Log ("PASTE"); //Debug.Log(GUI.GetNameOfFocusedControl()); //if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) //{ Undo.RegisterCompleteObjectUndo(model, "Paste"); string focusedControlNameBeforePaste = GUI.GetNameOfFocusedControl(); if (string.IsNullOrEmpty(focusedControlNameBeforePaste) || !focusedControlNameBeforePaste.Contains("_Text_")) { //model.deselectAll(); Library.pasteParametricObjectFromString(EditorGUIUtility.systemCopyBuffer); model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } model.autobuild(); break; case "Duplicate": Undo.RegisterCompleteObjectUndo(model, "Duplicate"); //Debug.Log ("Duplicate Command"); if (model.selectedPOs.Count > 0) { AXParametricObject selectedPO = model.selectedPOs[0]; instancePO(selectedPO); } model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case "Cut": Undo.RegisterCompleteObjectUndo(model, "Cut"); //EditorGUIUtility.systemCopyBuffer = JSONSerializersAX.allSelectedPOsAsJson(model); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { if (model.selectedPOs.Count > 0) { EditorGUIUtility.systemCopyBuffer = LibraryEditor.poWithSubNodes_2_JSON(model.selectedPOs[0], true); } if (e.shift) { model.deleteSelectedPOsAndInputs(); } else { model.deleteSelectedPOs(); } model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case "SoftDelete": case "Delete": //Debug.Log("DELETE"); // see if it is a selected point on a curve //if (ArchimatixEngine /* * FreeCurve selectedFreeCurve = null; * * if ( model.selectedPOs != null && model.selectedPOs.Count == 1 && model.selectedPOs[0] != null && model.selectedPOs[0].generator != null && model.selectedPOs[0].generator is FreeCurve) * { * selectedFreeCurve = (FreeCurve) model.selectedPOs[0].generator; * } * * if (selectedFreeCurve != null && selectedFreeCurve.selectedIndices != null && selectedFreeCurve.selectedIndices.Count > 0) * { * // delete points * selectedFreeCurve.deleteSelected(); * } */ // SELECTED POINTS TO DELETE? //Debug.Log("focusedControlName="+focusedControlName); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { bool foundSelectedPoints = false; if (model.activeFreeCurves.Count > 0) { for (int i = 0; i < model.activeFreeCurves.Count; i++) { FreeCurve gener = (FreeCurve)model.activeFreeCurves[i].generator; //Debug.Log("gener.hasSelectedPoints()="+gener.hasSelectedPoints()); if (gener.hasSelectedPoints()) { foundSelectedPoints = true; gener.deleteSelected(); } } } //Debug.Log("foundSelectedPoints="+foundSelectedPoints); if (foundSelectedPoints) { ArchimatixEngine.mouseIsDownOnHandle = false; } else if (e.shift) { Undo.RegisterCompleteObjectUndo(model, "Delete Nodes"); model.deleteSelectedPOsAndInputs(); } // [S.Darkwell: changed else to this else if to fix bug: "Fix pressing Delete key without Node selected still registers undo event" https://archimatixbeta.slack.com/files/s.darkwell/F1DJRQ3LL/fix_pressing_delete_key_without_node_selected_still_registers_undo_event.cs - 2016.06.02] else if (model.selectedPOs.Count > 0) { Undo.RegisterCompleteObjectUndo(model, "Delete Node"); model.deleteSelectedPOs(); } else if (model.selectedParameterInputRelation != null) { Undo.RegisterCompleteObjectUndo(model, "Delete Dependancy"); model.selectedParameterInputRelation.makeIndependent(); model.selectedParameterInputRelation = null; } else if (model.selectedRelationInGraph != null) { Undo.RegisterCompleteObjectUndo(model, "Delete Relation"); model.unrelate(model.selectedRelationInGraph); model.selectedRelationInGraph = null; } //Debug.Log("*********************************** DELETE"); model.remapMaterialTools(); model.autobuild(); //Debug.Log("caching here G"); model.cacheThumbnails(); e.Use(); } break; case "FrameSelected": if (view != null) { float framePadding = 400; if (model.selectedPOs == null || model.selectedPOs.Count == 0) { //model.selectAll(); model.selectAllVisibleInGroup(model.currentWorkingGroupPO); Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); model.deselectAll(); } else if (model.selectedPOs.Count > 1) { Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } else { //frame first po AXParametricObject currPO = model.cycleSelectedPO; // model.selectedPOs[0]; if (currPO == null) { currPO = model.mostRecentlySelectedPO; } if (currPO == null && model.selectedPOs != null && model.selectedPOs.Count > 0) { currPO = model.selectedPOs[0]; } if (currPO == null) { currPO = model.selectFirstHeadPO(); } if (currPO != null) { Matrix4x4 m = model.transform.localToWorldMatrix * currPO.worldDisplayMatrix; // * currPO.getLocalMatrix(); if (m.isIdentity) { m = currPO.generator.localMatrix; } Vector3 position = m.MultiplyPoint(currPO.bounds.center); if (currPO.bounds.size.magnitude > .005 && currPO.bounds.size.magnitude < 10000) { view.LookAt(position, view.camera.transform.rotation, currPO.bounds.size.magnitude * 1.01f); } else { //Debug.Log("FrameSelected - select ParametricObjectObject bounds not good: "+currPO.bounds.size.magnitude); } //if (currPO.grouper != null ) //{ AXNodeGraphEditorWindow.displayGroupIfOpen(currPO.grouper); //} //model.beginPanningToPoint(currPO.rect.center); AXNodeGraphEditorWindow.zoomToRectIfOpen(currPO.rect); } } if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; } } // EDITOR WINDOW ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); // SCENEVIEW if (view != null) { view.Repaint(); } lastCommand = e.commandName; }
// DO THE ACTUAL SAVE public static void saveParametricObject(AXParametricObject po, bool withInputSubparts, string filepathname) { //Debug.Log(filepathname); //EditorUtility.DisplayDialog("Archimatix Library", "Saving to Library: This may take a few moments.", "Ok"); po.readIntoLibraryFromRelativeAXOBJPath = ArchimatixUtils.getRelativeFilePath(filepathname); Library.recentSaveFolder = System.IO.Path.GetDirectoryName(filepathname); // If this head po has a grouperKey, lose it! // This is because when it is later instantiated, // that grouper may not exist or may not be the desired place for this. po.grouperKey = null; // gather relations as you go... List <AXRelation> rels = new List <AXRelation>(); // BUILD JSON STRING StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"parametric_objects\":["); sb.Append(JSONSerializersAX.ParametricObjectAsJSON(po)); // gather rels foreach (AXParameter p in po.parameters) { foreach (AXRelation rr in p.relations) { if (!rels.Contains(rr)) { rels.Add(rr); } } } // SUB NODES if (withInputSubparts) { // GATHER SUB_NODES //Debug.Log("Start gather"); po.gatherSubnodes(); //Debug.Log("End gather"); foreach (AXParametricObject spo in po.subnodes) { //Debug.Log("-- " + spo.Name); sb.Append(',' + JSONSerializersAX.ParametricObjectAsJSON(spo)); // gather rels foreach (AXParameter p in spo.parameters) { foreach (AXRelation rr in p.relations) { if (!rels.Contains(rr)) { rels.Add(rr); } } } } } sb.Append("]"); // add relations to json string thecomma; // RELATIONS if (rels != null && rels.Count > 0) { sb.Append(", \"relations\": ["); // begin parametric_objects thecomma = ""; foreach (AXRelation rr in rels) { sb.Append(thecomma + rr.asJSON()); thecomma = ", "; } sb.Append("]"); } sb.Append("}"); // *** SAVE AS ASSET *** // Since we have added the newItem to the live library, // generating this new file will not force a recreation of the library from the raw JSON file. File.WriteAllText(filepathname, sb.ToString()); // THUMBNAIL TO PNG if (po.is2D()) { Library.cache2DThumbnail(po); } else { Thumbnail.BeginRender(); Thumbnail.render(po, true); Thumbnail.EndRender(); } //string thumb_filename = System.IO.Path.ChangeExtension(filepathname, ".png"); string filename = System.IO.Path.GetFileNameWithoutExtension(filepathname); string prefix = (po.is2D()) ? "zz-AX-2DLib-" : "zz-AX-3DLib-"; string thumb_filename = System.IO.Path.ChangeExtension(filepathname, ".jpg"); thumb_filename = thumb_filename.Replace(filename, prefix + filename); byte[] bytes = po.thumbnail.EncodeToJPG(); //File.WriteAllBytes(libraryFolder + "data/"+ po.Name + ".png", bytes); File.WriteAllBytes(thumb_filename, bytes); //AssetDatabase.Refresh(); string thumbnailRelativePath = ArchimatixUtils.getRelativeFilePath(thumb_filename); //Debug.Log(path); AssetDatabase.ImportAsset(thumbnailRelativePath); TextureImporter importer = AssetImporter.GetAtPath(thumbnailRelativePath) as TextureImporter; if (importer != null) { importer.textureType = TextureImporterType.GUI; importer.maxTextureSize = 256; #if UNITY_5_5_OR_NEWER importer.textureCompression = TextureImporterCompression.Uncompressed; #else importer.textureFormat = TextureImporterFormat.AutomaticTruecolor; #endif } AssetDatabase.WriteImportSettingsIfDirty(thumbnailRelativePath); // Save the recent path to prefs EditorPrefs.SetString("LastLibraryPath", System.IO.Path.GetDirectoryName(filepathname)); EditorUtility.DisplayDialog("Archimatix Library", "ParametricObject saved to " + System.IO.Path.GetDirectoryName(thumbnailRelativePath) + " as " + filename, "Great, thanks!"); Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath(thumbnailRelativePath, typeof(Texture2D)); LibraryItem newItem = new LibraryItem(po); newItem.icon = tex; ArchimatixEngine.library.addLibraryItemToList(newItem); ArchimatixEngine.library.sortLibraryItems(); ArchimatixEngine.saveLibrary(); AssetDatabase.Refresh(); //Debug.Log("yo 2"); //ArchimatixEngine.library.readLibraryFromFiles(); }
public static void processEventCommandKeyDown(Event e, AXModel model) { switch (e.keyCode) { case KeyCode.L: if (model.selectedPOs != null && model.selectedPOs.Count == 1) { LibraryEditor.doSave_MenuItem(model.selectedPOs[0]); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case KeyCode.V: // this paste waste uncaught by EventType.ExecuteCommand or EventType.ValidateCommand // beacuse alt or command were held down Undo.RegisterCompleteObjectUndo(model, "Paste"); if (e.shift) { if (e.alt) { model.duplicateSelectedPOs(); } else { model.replicateSelectedPOs(); } model.isAltered(6); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case KeyCode.D: Undo.RegisterCompleteObjectUndo(model, "Duplicate"); //Debug.Log ("DUPLICATE.....KeyCode.D"); if (model.selectedPOs.Count > 0) { AXParametricObject selectedPO = model.selectedPOs[0]; if (e.shift) { replicatePO(selectedPO); } else if (e.alt) { duplicatePO(selectedPO); } else { //Debug.Log ("instancePO"); instancePO(selectedPO); } } // "Duplicate" is caught by the validateCommand and processed here in processEventCommand() model.isAltered(7); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case KeyCode.Backspace: string focusedControlName = GUI.GetNameOfFocusedControl(); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { Undo.RegisterCompleteObjectUndo(model, "Delete"); if (e.shift) { model.deleteSelectedPOsAndInputs(); } else { model.deleteSelectedPOs(); } model.isAltered(8); e.Use(); } break; } // Update EditorWindow ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); }
// return the height of this gui area public static int OnGUI(Rect pRect, AXNodeGraphEditorWindow editor, AXParameter p) { Event e = Event.current; if (Event.current.type == EventType.KeyUp) { if (p != null && !GUI.GetNameOfFocusedControl().Contains("logicTextArea_")) { p.parametricObject.model.autobuildDelayed(1000); } } int hgt = (int)pRect.height; float foldoutWidth = 20; float boxWidth = pRect.width - foldoutWidth - ArchimatixUtils.indent; float cur_x = ArchimatixUtils.cur_x; float box_w = ArchimatixUtils.paletteRect.width - cur_x - 3 * ArchimatixUtils.indent; int cur_y = (int)pRect.y; Color inactiveColor = new Color(.7f, .7f, .7f); Color oldBackgroundColor = GUI.backgroundColor; Color dataColor = editor.getDataColor(p.Type); // PERSONAL if (!EditorGUIUtility.isProSkin) { dataColor = new Color(dataColor.r, dataColor.b, dataColor.g, .3f); } GUI.color = dataColor; Rect boxRect = new Rect(cur_x + ArchimatixUtils.indent, cur_y, box_w, ArchimatixUtils.lineHgt); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.color = Color.white; int margin = 24; float x0 = pRect.x + 14; float xTF = pRect.x + 12; float wid = pRect.width - margin; int indent = (int)x0 + 2; int lineHgt = 16; int gap = 2; if (p.isEditing) { hgt *= 5; hgt += 8; GUI.Box(new Rect(pRect.x - 6, pRect.y - 3, boxWidth, lineHgt * (8 + p.expressions.Count)), GUIContent.none); } if (p.Parent == null) { return(0); } if (p.Parent != null && p.to_delete == true) { p.Parent.removeParameter(p); return(0); } Color defcolor = GUI.color; // input/ouput sockets GUI.backgroundColor = dataColor; // INPUT SOCKET string buttonLabel = null; Rect buttonRect; if (p.isEditing || p.hasInputSocket) { if (p.isEditing && !p.hasInputSocket) { GUI.color = new Color(defcolor.r, defcolor.g, defcolor.b, .3f); } buttonLabel = (editor.InputParameterBeingDragged == p) ? "-" : ""; buttonRect = new Rect(-3, pRect.y, ArchimatixEngine.buttonSize, ArchimatixEngine.buttonSize); // button color if (editor.OutputParameterBeingDragged != null) { if (editor.OutputParameterBeingDragged.Type != p.Type) { GUI.backgroundColor = inactiveColor; } else if (buttonRect.Contains(Event.current.mousePosition)) { GUI.backgroundColor = Color.white; } } else if (editor.InputParameterBeingDragged != null) { if (editor.InputParameterBeingDragged == p) { GUI.backgroundColor = Color.white; } else { GUI.backgroundColor = inactiveColor; } } // Input Button if (editor.OutputParameterBeingDragged != null && (editor.OutputParameterBeingDragged.parametricObject == p.parametricObject || editor.OutputParameterBeingDragged.Type != p.Type)) { GUI.enabled = false; } if (GUI.Button(buttonRect, buttonLabel)) { if (p.isEditing) { p.hasOutputSocket = (!p.hasOutputSocket); } else { if (Event.current.command) { Debug.Log("CONTEXT"); } else if (editor.OutputParameterBeingDragged != null && editor.OutputParameterBeingDragged.Type != p.Type) { editor.OutputParameterBeingDragged = null; } else { editor.inputSocketClicked(p); } } } GUI.enabled = true; } GUI.backgroundColor = editor.getDataColor(p.Type); GUI.color = defcolor; // INPUT SOCKET // OUTPUT SOCKET if (p.isEditing || p.hasOutputSocket) { if (p.isEditing && !p.hasOutputSocket) { GUI.color = new Color(defcolor.r, defcolor.g, defcolor.b, .3f); } buttonLabel = (editor.OutputParameterBeingDragged == p) ? "-" : ""; buttonRect = new Rect(p.Parent.rect.width - pRect.height + 3, pRect.y, ArchimatixEngine.buttonSize, ArchimatixEngine.buttonSize); // button color if (editor.InputParameterBeingDragged != null) { if (editor.InputParameterBeingDragged.Type != p.Type) { GUI.backgroundColor = inactiveColor; } else if (buttonRect.Contains(Event.current.mousePosition)) { GUI.backgroundColor = Color.white; } } else if (editor.OutputParameterBeingDragged != null) { if (editor.OutputParameterBeingDragged == p) { GUI.backgroundColor = Color.white; } else { GUI.backgroundColor = inactiveColor; } } // Output Button if (editor.InputParameterBeingDragged != null && (editor.InputParameterBeingDragged.parametricObject == p.parametricObject || editor.InputParameterBeingDragged.Type != p.Type)) { GUI.enabled = false; } if (GUI.Button(buttonRect, buttonLabel)) { if (p.isEditing) { p.hasOutputSocket = (!p.hasOutputSocket); } else { if (Event.current.control) { // DISPLAY CONTEXT MENU FOR THINGS YOU CAN USE THIS OUTPUT FOR Debug.Log("context"); //model.selectPO(parametricObject); MeshOuputMenu.contextMenu(p, e.mousePosition); e.Use(); } else if (editor.InputParameterBeingDragged != null && editor.InputParameterBeingDragged.Type != p.Type) { editor.InputParameterBeingDragged = null; } else { editor.outputSocketClicked(p); } } } GUI.enabled = true; } GUI.color = defcolor; // OUTPUT SOCKET // SLIDER AND NUMBER FIELD Rect nameLabelRect = new Rect(x0, pRect.y, wid - 30, 16); Rect cntlRect = new Rect(x0, pRect.y, wid, 16); //Rect boxRect = new Rect(xb, pRect.y+vMargin, boxWidth, pRect.height-vMargin*2); /* * if (hasInputSocket && ! hasOutputSocket) * boxRect = new Rect(xb, pRect.y+vMargin, inputwid, pRect.height-vMargin*2); * else if(! hasInputSocket && hasOutputSocket) * boxRect = new Rect(xb+x_output, pRect.y+vMargin, inputwid+4, pRect.height-vMargin*2); */ Rect textFieldRect = new Rect(xTF + 3, pRect.y, wid - 60, pRect.height + 2); // -- DON'T USE PROPERTY DRAWER TO HANDLE UNDO WITH SLIDER // we need o get the updated value atomically, which the propertydrawer does not seem to do (slower update) // BINDING HIGHLIGHT BACKGROUND BOX //Handles.yAxisColor; //GUI.color = Handles.yAxisColor; /* * if (p.sizeBindingAxis > 0) * { * switch(p.sizeBindingAxis) * { * case Axis.X: * GUI.color = Handles.xAxisColor; break; * case Axis.Y: * GUI.color = Handles.yAxisColor; break; * case Axis.Z: * GUI.color = Handles.zAxisColor; break; * * } * * GUI.Box (new Rect(boxRect.x-m, boxRect.y-m, boxRect.width+4*m, boxRect.height+2*m), GUIContent.none); * GUI.Box (new Rect(boxRect.x-m, boxRect.y-m, boxRect.width+4*m, boxRect.height+2*m), GUIContent.none); * GUI.Box (new Rect(boxRect.x-m, boxRect.y-m, boxRect.width+4*m, boxRect.height+2*m), GUIContent.none); * GUI.Box (new Rect(boxRect.x-m, boxRect.y-m, boxRect.width+4*m, boxRect.height+2*m), GUIContent.none); * GUI.Box (new Rect(boxRect.x-m, boxRect.y-m, boxRect.width+4*m, boxRect.height+2*m), GUIContent.none); * GUI.Box (new Rect(boxRect.x-m, boxRect.y-m, boxRect.width+4*m, boxRect.height+2*m), GUIContent.none); * } */ /* * if (EditorGUIUtility.isProSkin) * GUI.color = new Color(defcolor.r, defcolor.b, defcolor.g, 1f); * else * GUI.color = new Color(defcolor.r, defcolor.b, defcolor.g, .4f); * * GUI.Box (boxRect, GUIContent.none); * GUI.color = defcolor; * * if (EditorGUIUtility.isProSkin) * { * GUI.Box (boxRect, GUIContent.none); * GUI.Box (boxRect, GUIContent.none); * if (p.Parent.model.isSelected(p.Parent)) * GUI.Box (boxRect, GUIContent.none); * } */ // BINDING HIGHLIGHT BACKGROUND BOX // PROPERTYDRAWER //EditorGUI.PropertyField(pRect, pProperty); //OR... GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; GUIStyle buttonstyle = GUI.skin.GetStyle("Button"); buttonstyle.alignment = TextAnchor.MiddleLeft; // NAME string nameString = p.Name; // + "_" + Guid; if (p.Type == AXParameter.DataType.Mesh || p.Type == AXParameter.DataType.Spline || p.Type == AXParameter.DataType.Generic) { labelstyle.alignment = TextAnchor.MiddleLeft; labelstyle.fixedWidth = boxRect.width - 10; GUI.Label(nameLabelRect, nameString); } else if (p.PType == AXParameter.ParameterType.Output) { labelstyle.alignment = TextAnchor.MiddleRight; labelstyle.fixedWidth = boxRect.width - 10; GUI.Label(nameLabelRect, nameString); } else if ((p.hasInputSocket && !p.hasOutputSocket)) { labelstyle.alignment = TextAnchor.MiddleLeft; if (p.Parent.isEditing) { GUI.Label(nameLabelRect, nameString); } else { GUI.Label(nameLabelRect, nameString); } } else if (p.PType == AXParameter.ParameterType.Output) //(!hasInputSocket && hasOutputSocket) { labelstyle.alignment = TextAnchor.MiddleRight; if (p.Parent.isEditing) { GUI.Label(nameLabelRect, nameString + " .... "); } else { GUI.Label(cntlRect, nameString); } } else if (p.Type == AXParameter.DataType.Plane) { labelstyle.alignment = TextAnchor.MiddleRight; if (p.Parent.isEditing) { GUI.Label(nameLabelRect, nameString); } else { GUI.Label(cntlRect, nameString); } } else if (p.Type == AXParameter.DataType.MaterialTool) { labelstyle.alignment = TextAnchor.MiddleLeft; if (p.Parent.isEditing) { GUI.Label(nameLabelRect, nameString); } else { GUI.Label(cntlRect, nameString); } } else if ((p.hasInputSocket && p.hasOutputSocket) || (p.Type == AXParameter.DataType.Float || p.Type == AXParameter.DataType.Int || p.Type == AXParameter.DataType.FloatList)) { EditorGUIUtility.fieldWidth = wid / 3.2f; //36; EditorGUIUtility.labelWidth = wid - EditorGUIUtility.fieldWidth; GUI.backgroundColor = Color.white; EditorGUI.BeginChangeCheck(); p.isOpen = EditorGUI.Foldout(new Rect(pRect.x, cur_y, 20, lineHgt), p.isOpen, ""); if (EditorGUI.EndChangeCheck()) { if (p.isOpen) { foreach (AXParameter pop in p.parametricObject.parameters) { if (pop != p) { pop.isOpen = false; } } } } if (p.isOpen) { // NAME GUI.SetNextControlName("ParameterName_Text_NameField" + p.Guid + "_" + p.Name); p.Name = EditorGUI.TextField(textFieldRect, p.Name); if (p.shouldFocus) { GUI.FocusControl("ParameterName_Text_NameField" + p.Guid + "_" + p.Name); p.shouldFocus = false; } // DELETE PARAMETER if (GUI.Button(new Rect(pRect.width - 2 * lineHgt * 1.5f, cur_y - 1, lineHgt * 1.25f, lineHgt), "-")) { //Debug.Log("remove..."); p.parametricObject.removeParameter(p); //p.expressions.RemoveAt(i); } // MOVE PARAMETER UP if (GUI.Button(new Rect(pRect.width - lineHgt * 1.5f, cur_y - 1, lineHgt * 1.25f, lineHgt), "^")) { //Debug.Log("remove..."); p.parametricObject.moveParameterUp(p); //p.expressions.RemoveAt(i); } cur_y += lineHgt + gap * 3; GUI.Box(new Rect((x0 - 4), cur_y - 4, (pRect.width - 20), ((6 + p.expressions.Count) * lineHgt)), " "); // DATA_TYPE //EditorGUI.PropertyField( new Rect((textFieldRect.x+textFieldRect.width)+6, textFieldRect.y, 60, 22), pProperty.FindPropertyRelative("m_type"), GUIContent.none); //EditorGUI.PropertyField( new Rect((textFieldRect.x+textFieldRect.width)+6, textFieldRect.y, 60, 22), m_type, GUIContent.none); //Rect rec = new Rect((textFieldRect.x+textFieldRect.width)+6, textFieldRect.y, 60, 22); Rect rec = new Rect(x0, cur_y, 60, 22); //m_type = (DataType) EditorGUI.EnumPopup(rec, m_type, "YUP"); string dataType_menu = "Float|Int|Bool|String|Color|FloatList"; string[] dataType_options = dataType_menu.Split('|'); EditorGUI.BeginChangeCheck(); int typeOption = (int)p.Type; if (typeOption == (int)AXParameter.DataType.String) { typeOption = 3; } else if (typeOption == (int)AXParameter.DataType.Color) { typeOption = 4; } else if (typeOption == (int)AXParameter.DataType.FloatList) { typeOption = 5; } typeOption = (int)EditorGUI.Popup( rec, "", typeOption, dataType_options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Parameter Type"); p.Type = (AXParameter.DataType)typeOption; if (p.Type == AXParameter.DataType.Spline) { p.Type = AXParameter.DataType.String; } } cur_y += lineHgt + gap * 3; // EXPOSE AS RUNTIME Interface ------------ //EditorGUIUtility.labelWidth = wid-36; cntlRect = new Rect(x0, cur_y, wid, 16); EditorGUI.BeginChangeCheck(); p.exposeAsInterface = EditorGUI.Toggle(cntlRect, "Expose", p.exposeAsInterface); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Expose Parameter"); if (p.exposeAsInterface) { p.parametricObject.model.addExposedParameter(p); } else { p.parametricObject.model.removeExposedParameter(p); } } cur_y += lineHgt + gap; /* * if (p.Type == AXParameter.DataType.Float) * { * EditorGUI.BeginChangeCheck (); * * //EditorGUIUtility.labelWidth = 20; * GUI.backgroundColor = Color.white; * GUI.Label(new Rect(indent, cur_y, 200,16), "Bind externally in: "); * p.sizeBindingAxis = EditorGUI.Popup( * new Rect((textFieldRect.x+textFieldRect.width)+6, cur_y, 60,16), * "", * p.sizeBindingAxis, * new string[] { * "None", * "X", * "Y", * "Z" * }); * if (EditorGUI.EndChangeCheck ()) { * Undo.RegisterCompleteObjectUndo (p.parametricObject.model, "Size bind Axis"); * Debug.Log ("sizeBindingAxis changed to "+p.sizeBindingAxis ); * * } * cur_y += lineHgt; * } */ // STRING if (p.Type == AXParameter.DataType.String) { p.StringVal = EditorGUI.TextField(new Rect(indent, cur_y, wid - 10, lineHgt), p.StringVal); cur_y += lineHgt; } // NUMBER else if (p.Type == AXParameter.DataType.Float || (p.Type == AXParameter.DataType.Int)) { // MIN/MAX cntlRect = new Rect(x0, cur_y, wid, 16); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Text_MIN" + p.Guid + "_" + p.Name); if (p.Type == AXParameter.DataType.Float) { p.min = EditorGUI.FloatField(cntlRect, "Min", p.min); } else { p.intmin = EditorGUI.IntField(cntlRect, "Min", p.intmin); } if (EditorGUI.EndChangeCheck()) { //Debug.Log(val); Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); if (p.Type == AXParameter.DataType.Float) { p.Parent.initiateRipple_setFloatValueFromGUIChange(p.Name, p.min); } else { p.Parent.initiateRipple_setIntValueFromGUIChange(p.Name, p.intmin); } p.parametricObject.model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } cur_y += lineHgt; cntlRect = new Rect(x0, cur_y, wid, 16); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Text_MAX" + p.Guid + "_" + p.Name); if (p.Type == AXParameter.DataType.Float) { p.max = EditorGUI.FloatField(cntlRect, "Max", p.max); } else { p.intmax = EditorGUI.IntField(cntlRect, "Max", p.intmax); } if (EditorGUI.EndChangeCheck()) { //Debug.Log(val); Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); if (p.Type == AXParameter.DataType.Float) { p.Parent.initiateRipple_setFloatValueFromGUIChange(p.Name, p.max); } else { p.Parent.initiateRipple_setIntValueFromGUIChange(p.Name, p.intmax); } p.parametricObject.model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); } cur_y += lineHgt; GUI.Label(new Rect(indent, cur_y, 200, 16), new GUIContent("Expressions", "When the value of this parameter changes, define its effect on other paramters with mathematical descriptions using this parameter.")); cur_y += lineHgt; // EXPRESSIONS if (p.expressions == null) { p.expressions = new List <string>(); } if (p.expressions.Count == 0) { p.expressions.Add(""); } for (int i = 0; i < p.expressions.Count; i++) { GUI.SetNextControlName("ParameterExpression_" + i + "_Text_" + p.Guid + "_" + p.Name); p.expressions[i] = EditorGUI.TextField(new Rect(indent, cur_y, wid - 30, lineHgt), p.expressions[i]); if (GUI.Button(new Rect(pRect.width - lineHgt * 1.5f, cur_y - 1, lineHgt * 1.25f, lineHgt), "-")) { p.expressions.RemoveAt(i); } cur_y += lineHgt + gap * 2; } if (GUI.Button(new Rect(pRect.width - lineHgt * 1.5f, cur_y, lineHgt * 1.25f, lineHgt), new GUIContent("+", "Add an expression to this Parameter"))) { p.expressions.Add(""); } cur_y += lineHgt; } cur_y += lineHgt; // DONE if (GUI.Button(new Rect((wid - 30 - lineHgt * 1.5f), cur_y - 1, 50, pRect.height), "Done")) { p.isOpen = false; p.shouldFocus = false; AXEditorUtilities.clearFocus(); } // MOVE PARAMETER UP if (GUI.Button(new Rect(pRect.width - lineHgt * 1.5f, cur_y - 1, lineHgt * 1.25f, lineHgt), "v")) { //Debug.Log("remove..."); p.parametricObject.moveParameterDown(p); //p.expressions.RemoveAt(i); } cur_y += lineHgt; } else // (not open) { // NOT EDITING, RATHER USING string bindingLabel = ""; switch (p.sizeBindingAxis) { case Axis.X: bindingLabel = " [X]"; break; case Axis.Y: bindingLabel = " [Y]"; break; case Axis.Z: bindingLabel = " [Z]"; break; } switch (p.Type) { case AXParameter.DataType.AnimationCurve: GUILayout.BeginArea(new Rect(indent, cur_y, wid - 10, 2 * lineHgt)); EditorGUI.BeginChangeCheck(); EditorGUILayout.CurveField(p.animationCurve); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "ModifierCurve"); p.parametricObject.model.isAltered(28); ArchimatixEngine.scheduleBuild(); } GUILayout.EndArea(); break; // COLOR case AXParameter.DataType.Color: p.colorVal = EditorGUI.ColorField(cntlRect, p.colorVal); break; case AXParameter.DataType.Float: // FLOAT SLIDER if (p.PType != AXParameter.ParameterType.DerivedValue) { // VALIDATE INPUT - IF INVALID >> LOSE FOCUS AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_Text_FloatField_" + p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Text_" + p.Guid + "_" + p.Name); p.val = EditorGUI.FloatField(cntlRect, nameString + bindingLabel, p.val); if (EditorGUI.EndChangeCheck()) { //Debug.Log(val); Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.Parent.initiateRipple_setFloatValueFromGUIChange(p.Name, p.val); p.parametricObject.model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } } else { Rect labelRect = cntlRect; labelRect.width = cntlRect.width - 25; GUI.Label(labelRect, p.Name); GUI.Label(new Rect(cntlRect.width - 10, cntlRect.y, 18, cntlRect.height), "" + p.val); } if (p.shouldFocus) { GUI.FocusControl("FloatField_Text_" + p.Guid + "_" + p.Name); p.shouldFocus = false; } break; case AXParameter.DataType.Int: { // INT SLIDER // VALIDATE INPUT - IF INVALID >> LOSE FOCUS /* * if (Event.current.type == EventType.KeyDown) * { * if(Event.current.keyCode != KeyCode.None && !AXEditorUtilities.isValidIntFieldKeyCode(Event.current.keyCode) && GUI.GetNameOfFocusedControl() == ("IntField_" + p.Name)) * { * Event.current.Use(); * GUI.FocusControl("dummy_label"); * } * } */ AXEditorUtilities.assertIntFieldKeyCodeValidity("IntField_" + p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("IntField_" + p.Guid + "_" + p.Name); p.intval = EditorGUI.IntField(cntlRect, nameString, p.intval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.initiateRipple_setIntValueFromGUIChange(p.intval); p.parametricObject.model.isAltered(28); p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } break; } case AXParameter.DataType.Bool: { EditorGUIUtility.labelWidth = wid - 16; EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("BoolToggle_" + p.Guid + "_" + p.Name); p.boolval = EditorGUI.Toggle(cntlRect, nameString, p.boolval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.parametricObject.initiateRipple_setBoolParameterValueByName(p.Name, p.boolval); //p.parametricObject.model.autobuild(); p.parametricObject.model.isAltered(); p.parametricObject.generator.adjustWorldMatrices(); ArchimatixEngine.scheduleBuild(); } break; } case AXParameter.DataType.String: labelstyle.alignment = TextAnchor.MiddleLeft; if (p.Parent.isEditing) { GUI.Label(nameLabelRect, nameString); } else { GUI.Label(nameLabelRect, nameString); } break; case AXParameter.DataType.FloatList: labelstyle.alignment = TextAnchor.MiddleLeft; if (p.Parent.isEditing) { GUI.Label(nameLabelRect, nameString); } else { GUI.Label(nameLabelRect, nameString + " (" + p.floats.Count + ")"); } break; case AXParameter.DataType.Option: { // OPTION POPUP string[] options = ArchimatixUtils.getMenuOptions(p.Name); EditorGUIUtility.labelWidth = wid - 50; EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("OptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUI.Popup( cntlRect, p.Name, p.intval, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.parametricObject.model.autobuild(); if (p.PType == AXParameter.ParameterType.PositionControl) { p.parametricObject.generator.adjustWorldMatrices(); } } break; } case AXParameter.DataType.CustomOption: { // OPTION POPUP string[] options = p.optionLabels.ToArray(); EditorGUIUtility.labelWidth = wid * .5f; EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("CustomOptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUI.Popup( cntlRect, p.Name, p.intval, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.parametricObject.model.autobuild(); if (p.PType == AXParameter.ParameterType.PositionControl) { p.parametricObject.generator.adjustWorldMatrices(); } } break; } } // END switch (Type) } } cur_y += lineHgt; GUI.backgroundColor = oldBackgroundColor; /* * if(GUI.changed && ! editor.codeChanged) * { * Debug.Log ("generate " + Parent.Name + " :: " + Name); * //Parent.generateOutput("guid01"); * * * } */ GUI.color = defcolor; return(cur_y - (int)pRect.y); }
public override void OnInspectorGUI() { //if (Event.current.type != EventType.Layout) // return; AXModel model = (AXModel)target; Event e = Event.current; //GUI.skin = axskin; //GUI.skin = null; //Debug.Log(evt.type); switch (e.type) { case EventType.Layout: if (doAutobuild) { doAutobuild = false; //model.autobuild (); ArchimatixEngine.scheduleBuild(); } break; case EventType.MouseDown: //Debug.Log("Down"); break; case EventType.MouseUp: //doAutobuild = true; break; case EventType.KeyUp: if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter) { Undo.RegisterCompleteObjectUndo(model, "Enter"); doAutobuild = true; } //Debug.Log("KeyUp"); //doAutobuild = true; break; case EventType.DragUpdated: UnityEngine.Debug.Log("Dragging"); break; case EventType.DragPerform: //DragAndDrop.AcceptDrag(); UnityEngine.Debug.Log("Drag and Drop not supported... yet"); Undo.RegisterCompleteObjectUndo(model, "Default material scale"); doAutobuild = true; break; } if (richLabelStyle == null) { richLabelStyle = new GUIStyle(GUI.skin.label); richLabelStyle.richText = true; richLabelStyle.wordWrap = true; } //if (infoIconTexture = null) String rubricColor = (EditorGUIUtility.isProSkin) ? "#bbbbff" : "#bbbbff"; GUIStyle gsTest = new GUIStyle(); gsTest.normal.background = ArchimatixEngine.nodeIcons ["Blank"]; // //Color.gray; gsTest.normal.textColor = Color.white; Color textColor = new Color(.82f, .80f, .85f); Color textColorSel = new Color(.98f, .95f, 1f); GUIStyle rubric = new GUIStyle(GUI.skin.label); rubric.normal.textColor = textColor; GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); foldoutStyle.normal.textColor = textColor; foldoutStyle.active.textColor = textColorSel; foldoutStyle.hover.textColor = textColor; foldoutStyle.focused.textColor = textColorSel; foldoutStyle.onNormal.textColor = textColor; foldoutStyle.onActive.textColor = textColorSel; foldoutStyle.onHover.textColor = textColor; foldoutStyle.onFocused.textColor = textColorSel; GUILayout.Space(10); GUILayout.BeginVertical(gsTest); EditorGUI.indentLevel++; EditorGUIUtility.labelWidth = 150; model.displayModelDefaults = EditorGUILayout.Foldout(model.displayModelDefaults, "Model Defaults", true, foldoutStyle); if (model.displayModelDefaults) { // PRECISION LEVEL EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label("Precision Level", rubric); GUILayout.FlexibleSpace(); model.precisionLevel = (PrecisionLevel)EditorGUILayout.EnumPopup("", model.precisionLevel); EditorGUILayout.EndHorizontal(); if (!AXNodeGraphEditorWindow.IsOpen) { GUILayout.Space(10); if (GUILayout.Button("Open in Node Graph")) { AXNodeGraphEditorWindow.Init(); } } //GUILayout.Space(20); // -- RUBRIC - MATERIAL -- EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label("Material (Default)", rubric); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/materials"); } EditorGUILayout.EndHorizontal(); // -------- if (model.axMat.mat.name == "AX_GridPurple") { EditorGUILayout.HelpBox("Set the default Material for this model.", MessageType.Info); } // Material EditorGUI.BeginChangeCheck(); model.axMat.mat = (Material)EditorGUILayout.ObjectField(model.axMat.mat, typeof(Material), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.remapMaterialTools(); model.autobuild(); } GUILayout.Space(10); // Texture // model.showDefaultMaterial = EditorGUILayout.Foldout(model.showDefaultMaterial, "Texture Scaling", true, foldoutStyle); if (model.showDefaultMaterial) { EditorGUI.BeginChangeCheck(); model.axTex.scaleIsUnified = EditorGUILayout.Toggle("Unified Scaling", model.axTex.scaleIsUnified); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material scale"); model.axTex.scale.y = model.axTex.scale.x; model.isAltered(); } if (model.axTex.scaleIsUnified) { EditorGUI.BeginChangeCheck(); model.axTex.scale.x = EditorGUILayout.FloatField("Scale", model.axTex.scale.x); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.axTex.scale.y = model.axTex.scale.x; model.isAltered(); ArchimatixEngine.scheduleBuild(); } } else { // Scale X EditorGUI.BeginChangeCheck(); model.axTex.scale.x = EditorGUILayout.FloatField("Scale X", model.axTex.scale.x); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.isAltered(); ArchimatixEngine.scheduleBuild(); } // Scale Y EditorGUI.BeginChangeCheck(); model.axTex.scale.y = EditorGUILayout.FloatField("Scale Y", model.axTex.scale.y); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.isAltered(); ArchimatixEngine.scheduleBuild(); } } EditorGUI.BeginChangeCheck(); model.axTex.runningU = EditorGUILayout.Toggle("Running U", model.axTex.runningU); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Running U"); model.isAltered(); ArchimatixEngine.scheduleBuild(); } } GUILayout.Space(10); // PhysicMaterial // model.axMat.showPhysicMaterial = EditorGUILayout.Foldout(model.axMat.showPhysicMaterial, "Physics Material", true, foldoutStyle); if (model.axMat.showPhysicMaterial) { // PHYSIC MATERIAL EditorGUI.BeginChangeCheck(); model.axMat.physMat = (PhysicMaterial)EditorGUILayout.ObjectField(model.axMat.physMat, typeof(PhysicMaterial), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default PhysicMaterial for " + model.name); model.remapMaterialTools(); ArchimatixEngine.scheduleBuild(); } // DENSITY EditorGUI.BeginChangeCheck(); model.axMat.density = EditorGUILayout.FloatField("Density", model.axMat.density); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Material Density for " + model.name); model.isAltered(); ArchimatixEngine.scheduleBuild(); } } GUILayout.Space(20); model.automaticModelRegeneration = EditorGUILayout.ToggleLeft("Automatic Model Regeneration", model.automaticModelRegeneration); GUILayout.Space(20); // -- RUBRIC - LIGHTING -- EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label("Lighting", rubric); //GUILayout.Label ("<color=" + rubricColor + "> <size=13>Lighting</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/lightmapping-with-archimatix"); } EditorGUILayout.EndHorizontal(); // -------- // LIGHTMAP FLAGS ENABLED EditorGUI.BeginChangeCheck(); model.staticFlagsEnabled = EditorGUILayout.ToggleLeft("Lightmap Flags Enabled", model.staticFlagsEnabled); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Static Masks Enabled change for " + model.name); model.staticFlagsJustEnabled = true; ArchimatixEngine.scheduleBuild(); } // SECONDARY UVs if (model.staticFlagsEnabled) { //if (model.buildStatus == AXModel.BuildStatus.Generated) EditorGUI.BeginChangeCheck(); model.createSecondaryUVs = EditorGUILayout.ToggleLeft("Create Secondary UVs (for Baked GI)", model.createSecondaryUVs); if (EditorGUI.EndChangeCheck()) { //if (model.createSecondaryUVs) // AXEditorUtilities.makeLightMapUVs (model); model.createSecondaryUVsJustEnabled = true; } } GUILayout.Space(20); } // displayModelDefaults /* * if (GUILayout.Button("Set All Objects as Lightmap Static")) * { * Debug.Log("Set all"); * model.setLightmapStaticForAllPOs(); * } */ if (ArchimatixEngine.plevel == 3) { // RUNTIME // string countString = ""; if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { countString = " (" + model.exposedParameterAliases.Count + ")"; } model.displayModelRuntimeParameters = EditorGUILayout.Foldout(model.displayModelRuntimeParameters, "Runtime Parameters" + countString, true, foldoutStyle); if (model.displayModelRuntimeParameters) { //GUILayout.Label("<color="+rubricColor+"> <size=13>Pro Runtime Features</size></color>", richLabelStyle); // EXPOSED PARAMETERS //if (model.cycleSelectedAXGO != null) // GUILayout.Label("Consumer Address: "+model.cycleSelectedAXGO.consumerAddress); //GUILayout.Label("Runtime Parameters"); if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { EditorGUI.BeginChangeCheck(); foreach (AXParameterAlias pa in model.exposedParameterAliases) { ParameterAliasGUILayout.OnGUI(pa); } if (EditorGUI.EndChangeCheck()) { model.isAltered(); } } else { // GUIStyle labelSty = new GUIStyle("Label"); // labelSty.wordWrap = true; // labelSty.richText = true; EditorGUILayout.HelpBox("You can add runntime parameters by opening any parameter in the graph and checking \"Enable Runtime\"", MessageType.Info); //GUILayout.Label ("<color=\"gray\">You can add runntime parameters by opening any parameter in the graph and checking \"Enable Runtime\"</color>", labelSty); } GUILayout.Space(15); if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { if (GUILayout.Button("Create Runtime Controller", GUILayout.Width(200))) { ArchimatixEngine.createControllerForModel = model; } } // RUNTIME HANDLES //if (model.cycleSelectedAXGO != null) // GUILayout.Label("Consumer Address: "+model.cycleSelectedAXGO.consumerAddress); if (model.runtimeHandleAliases != null && model.runtimeHandleAliases.Count > 0) { //GUILayout.Label("Runtime Handles"); foreach (AXHandleRuntimeAlias rth in model.runtimeHandleAliases) { AXRuntimeHandlesGUI.OnGUI(rth); } } GUILayout.Space(20); } } // RUNTIME // RELATIONS if (model.selectedRelationInGraph != null) { GUILayout.Space(20); GUILayout.Label("<color=" + rubricColor + "> <size=13>Selected Relation</size></color>", richLabelStyle); AXRelation r = model.selectedRelationInGraph; RelationEditorGUI.OnGUI(r); } //GUILayout.Space(20); model.displayModelSelectedNodes = EditorGUILayout.Foldout(model.displayModelSelectedNodes, "Selected Node Controls", true, foldoutStyle); if (model.displayModelSelectedNodes) { // -- RUBRIC - SELECTED NODES -- EditorGUILayout.BeginHorizontal(); //GUILayout.Label("<color="+rubricColor+"> <size=13>Selected Nodes</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/node-selection"); } EditorGUILayout.EndHorizontal(); // -------- //GUILayout.Space(10); if (model.selectedPOs != null && model.selectedPOs.Count > 0) { for (int i = 0; i < model.selectedPOs.Count; i++) { //Debug.Log(i); AXParametricObject po = model.selectedPOs [i]; //Debug.Log(i+" ------------------------ po.Name="+po.Name+ " -- " + po.generator.AllInput_Ps.Count); doPO(po); // for subnodes... if (po.generator.AllInput_Ps != null) { for (int j = po.generator.AllInput_Ps.Count - 1; j >= 0; j--) { AXParameter p = po.generator.AllInput_Ps [j]; if (p.DependsOn != null) { AXParametricObject spo = p.DependsOn.parametricObject; doPO(spo); // sub-sub nodes... for (int k = spo.generator.AllInput_Ps.Count - 1; k >= 0; k--) { if (spo.generator.AllInput_Ps [k].DependsOn != null) { doPO(spo.generator.AllInput_Ps [k].DependsOn.parametricObject); } } } } } } } else { GUILayout.Label("<color=\"gray\">...no nodes selected</color>", richLabelStyle); } GUILayout.Space(50); } EditorGUI.indentLevel--; GUILayout.EndVertical(); // Editor currentTransformEditor = Editor.CreateEditor(model.gameObject.); // if (currentTransformEditor != null) { // currentTransformEditor.OnInspectorGUI (); // } //model.controls[0].val = EditorGUILayout.Slider(model.controls[0].val, 0, 100); /* * switch (e.type) * { * case EventType.KeyUp: * case EventType.mouseUp: * * model.autobuild(); * //e.Use (); * * //return; * break; * * case EventType.mouseDown: * * //model.autobuild(); * //e.Use (); * break; * * } */ //DrawDefaultInspector (); }
public override void drawControlHandles(ref List <string> visited, Matrix4x4 consumerM, bool beingDrawnFromConsumer) { Matrix4x4 prevHandlesMatrix = Handles.matrix; FreeCurve gener = (FreeCurve)parametricObject.generator; base.drawControlHandles(ref visited, consumerM, true); if (alreadyVisited(ref visited, "FreeCurveHandler")) { return; } AXParameter p = parametricObject.getParameter("Output Shape"); if (p == null || p.getPaths() == null) { return; } parametricObject.model.addActiveFreeCurve(parametricObject); Event e = Event.current; if (ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint && e.type == EventType.keyDown && (e.keyCode == KeyCode.Escape || e.keyCode == KeyCode.Return)) { ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default); e.Use(); } handlePoints = new List <Vector2>(); bool handleHasChanged = false; /* * Matrix4x4 context = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; * if (generator.hasOutputsConnected() || parametricObject.is2D()) * context *= generator.localMatrix.inverse; * else * context *= parametricObject.getAxisRotationMatrix().inverse * generator.localMatrix.inverse * parametricObject.getAxisRotationMatrix(); * * Handles.matrix = context; */ Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; // * generator.localMatrix.inverse; float gridDim = parametricObject.model.snapSizeGrid * 100; // axis Handles.color = Color.red; Handles.DrawLine(new Vector3(-gridDim / 2, 0, 0), new Vector3(gridDim / 2, 0, 0)); Handles.color = Color.green; Handles.DrawLine(new Vector3(0, -gridDim / 2, 0), new Vector3(0, gridDim / 2, 0)); // grid if (ArchimatixEngine.snappingOn()) { Handles.color = new Color(1, .5f, .65f, .15f); } else { Handles.color = new Color(1, .5f, .65f, .05f); } AXEditorUtilities.DrawGrid3D(gridDim, parametricObject.model.snapSizeGrid); //Handles.matrix = Matrix4x4.identity; CurvePoint newCurvePoint = null;; int newCurvePointIndex = -1; if (parametricObject.curve != null) { //if (Event.current.type == EventType.mouseDown) // selectedIndex = -1; //Vector3 pos; for (int i = 0; i < parametricObject.curve.Count; i++) { //Debug.Log (i + ": "+ parametricObject.curve[i].position); // Control points in Curve bool pointIsSelected = (generator.selectedIndices != null && generator.selectedIndices.Contains(i)); Vector3 pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0); Handles.color = (pointIsSelected) ? Color.white : Color.magenta; float capSize = .13f * HandleUtility.GetHandleSize(pos); if (pointIsSelected) { capSize = .17f * HandleUtility.GetHandleSize(pos); } // POSITION //pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0); // pos = Handles.FreeMoveHandle( // pos, // Quaternion.identity, // capSize, // Vector3.zero, // (controlID, positione, rotation, size) => // { // if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) // Debug.Log("YOP"); // Handles.SphereCap(controlID, positione, rotation, size); // }); pos = Handles.FreeMoveHandle( pos, Quaternion.identity, capSize, Vector3.zero, (controlID, position, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { //Debug.Log("*** " + e.type + " -" + e.keyCode + "-"); // MOUSE DOWN ON HANDLE! Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeCurve"); //Debug.Log(controlID + ": " + e.type); ArchimatixEngine.selectedFreeCurve = gener; //Debug.Log("SELECT NODE " +i + " ci="+controlID); if (i == 0 && ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint) { generator.P_Output.shapeState = ShapeState.Closed; ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default); } else if (e.shift && !ArchimatixEngine.mouseIsDownOnHandle) { generator.toggleItem(i); } else if (gener.selectedIndices == null || gener.selectedIndices.Count < 2) { if (!generator.isSelected(i)) { generator.selectOnlyItem(i); } } ArchimatixEngine.isPseudoDraggingSelectedPoint = i; // CONVERT TO BEZIER if (e.alt) { gener.convertToBezier(i); } for (int j = 0; j < generator.P_Output.Dependents.Count; j++) { generator.P_Output.Dependents [j].parametricObject.generator.adjustWorldMatrices(); } ArchimatixEngine.mouseDownOnSceneViewHandle(); } Handles.SphereCap(controlID, position, rotation, size); }); // MID_SEGEMNET HANDLE if (i < parametricObject.curve.Count) { //Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix * generator.localMatrix.inverse; Handles.color = Color.cyan; //Debug.Log("mid handle "+i); CurvePoint a = parametricObject.curve[i]; int next_i = (i == parametricObject.curve.Count - 1) ? 0 : i + 1; CurvePoint b = parametricObject.curve[next_i]; if (a.isPoint() && b.isPoint()) { pos = Vector2.Lerp(a.position, b.position, .5f); } else { Vector2 pt = FreeCurve.bezierValue(a, b, .5f); pos = (Vector3)pt; } EditorGUI.BeginChangeCheck(); #if UNITY_5_6_OR_NEWER pos = Handles.FreeMoveHandle( pos, Quaternion.identity, .06f * HandleUtility.GetHandleSize(pos), Vector3.zero, (controlID, positione, rotation, size, eventType) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.selectedFreeCurve = gener; } Handles.CubeHandleCap(controlID, positione, rotation, size, eventType); }); #else pos = Handles.FreeMoveHandle( pos, Quaternion.identity, .06f * HandleUtility.GetHandleSize(pos), Vector3.zero, (controlID, positione, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.selectedFreeCurve = gener; } Handles.CubeCap(controlID, positione, rotation, size); }); #endif if (EditorGUI.EndChangeCheck()) { // add point to spline at i using pos.x, pos.y Undo.RegisterCompleteObjectUndo(parametricObject.model, "New Midpoint"); //Debug.Log(pos); //Debug.Log(ArchimatixEngine.isPseudoDraggingSelectedPoint + " ::: " + (i)); //if (ArchimatixEngine.isPseudoDraggingSelectedPoint != (i+1)) if (ArchimatixEngine.isPseudoDraggingSelectedPoint == -1) { //Debug.Log("CREATE!!!!"); newCurvePoint = new CurvePoint(pos.x, pos.y); newCurvePointIndex = i + 1; parametricObject.curve.Insert(newCurvePointIndex, newCurvePoint); ArchimatixEngine.isPseudoDraggingSelectedPoint = newCurvePointIndex; generator.selectedIndex = newCurvePointIndex; generator.selectOnlyItem(newCurvePointIndex); } parametricObject.model.isAltered(); } } } // \loop // BEZIER HANDLES LOOP for (int i = 0; i < parametricObject.curve.Count; i++) { //Debug.Log (i + ": "+ parametricObject.curve[i].position); // Control points in Curve bool pointIsSelected = (generator.selectedIndices != null && generator.selectedIndices.Contains(i)); Vector3 pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0); Vector3 posA = new Vector3(parametricObject.curve[i].position.x + parametricObject.curve[i].localHandleA.x, parametricObject.curve[i].position.y + parametricObject.curve[i].localHandleA.y, 0); Vector3 posB = new Vector3(parametricObject.curve[i].position.x + parametricObject.curve[i].localHandleB.x, parametricObject.curve[i].position.y + parametricObject.curve[i].localHandleB.y, 0); Handles.color = (pointIsSelected) ? Color.white : Color.magenta; if (pointIsSelected) { Handles.color = Color.magenta; if (parametricObject.curve[i].isBezierPoint()) { Handles.color = Color.white; Handles.DrawLine(pos, posA); Handles.DrawLine(pos, posB); EditorGUI.BeginChangeCheck(); posA = Handles.FreeMoveHandle( posA, Quaternion.identity, .1f * HandleUtility.GetHandleSize(pos), Vector3.zero, Handles.SphereCap ); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeformShapee"); handleHasChanged = true; parametricObject.curve[i].setHandleA(new Vector2(posA.x, posA.y)); //parametricObject.curve[i].localHandleA = new Vector2(pos.x, pos.y) - parametricObject.curve[i].position; //parametricObject.model.generate("Move FreeForm Shape Handle"); parametricObject.model.isAltered(); } // HANDLE_B EditorGUI.BeginChangeCheck(); posB = Handles.FreeMoveHandle( posB, Quaternion.identity, .1f * HandleUtility.GetHandleSize(pos), Vector3.zero, Handles.SphereCap ); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeformShapee"); handleHasChanged = true; //parametricObject.curve[i].localHandleB = new Vector2(pos.x, pos.y) - parametricObject.curve[i].position; parametricObject.curve[i].setHandleB(new Vector2(posB.x, posB.y)); //parametricObject.model.generate("Move FreeForm Shape Handle"); parametricObject.model.isAltered(); } } } // selected } // \bezier handles loop if (handleHasChanged) { } } Handles.matrix = prevHandlesMatrix; }
void OnGUIOld() { Library library = ArchimatixEngine.library; Event e = Event.current; switch (e.type) { case EventType.MouseDown: //Debug.Log("Down"); break; case EventType.DragUpdated: //Debug.Log("Drag and Drop sorting not supported... yet"); break; case EventType.DragPerform: Debug.Log("Drag and Drop sorting not supported... yet"); break; } //showDetailItem.target = EditorGUILayout.ToggleLeft("Show extra fields", showDetailItem.target); GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.UpperLeft; labelstyle.fixedWidth = 300; //GUILayout.BeginHorizontal(); // WINDOW TITLE string libtype = (showClass == 3 ? "3D":"2D"); EditorGUILayout.BeginHorizontal(); labelstyle.fontSize = 24; GUILayout.Label("Archimatix " + libtype + " Library"); labelstyle.fontSize = 12; EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { ArchimatixEngine.createLibraryFromJSONFiles(); } EditorGUILayout.Space(); if (showClass == 3) { if (GUILayout.Button("Switch to 2D")) { showClass = 2; } } else { if (GUILayout.Button("Switch to 3D")) { showClass = 3; } } EditorGUILayout.EndHorizontal(); //GUILayout.FlexibleSpace(); //GUILayout.Space(10); //GUILayout.EndHorizontal(); //labelstyle.fontSize = 9; //GUILayout.Space(16); // SCROLL_VIEW GUIStyle shadowDown = new GUIStyle(); shadowDown.normal.background = bgTex; GUIStyle shadowUp = new GUIStyle(); shadowUp.normal.background = bgTexUp; // BEGIN FILTER BAR EditorGUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(100), GUILayout.Height(25)); GUILayout.EndVertical(); GUILayout.Space(20); // FILTERS EditorGUI.BeginChangeCheck(); showFilters.target = EditorGUILayout.ToggleLeft("Show Filters", showFilters.target); if (EditorGUI.EndChangeCheck()) { ArchimatixEngine.library.isFiltered = showFilters.target; } GUILayout.FlexibleSpace(); // SEARCH GUILayout.Label("Search"); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("TF_SEARCH"); searchString = GUILayout.TextField(searchString, GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { string[] words = searchString.Split(' '); ArchimatixEngine.library.filterResultsUsingSearch(new List <string>(words)); lastTextField = "TF_SEARCH"; } if (GUILayout.Button("x", GUILayout.Width(20))) { GUI.FocusControl("dummy"); searchString = ""; ArchimatixEngine.library.filteredResults = null; } if (Event.current.type == EventType.KeyDown && (Event.current.keyCode == KeyCode.Return)) { GUI.FocusControl(lastTextField); e.Use(); } GUILayout.Space(20); EditorGUILayout.EndHorizontal(); // \ END FILTER BAR if (EditorGUILayout.BeginFadeGroup(showFilters.faded) && ArchimatixEngine.library.categories != null) { // COLUMN LABELS GUILayout.BeginHorizontal(); foreach (KeyValuePair <string, List <string> > kv in ArchimatixEngine.library.categories) { GUILayout.Label(kv.Key, GUILayout.Width(130)); } GUILayout.EndHorizontal(); GUILayout.Label(" ", shadowDown); filtersScrollPosition = EditorGUILayout.BeginScrollView(filtersScrollPosition, GUILayout.Width(position.width), GUILayout.Height(filtersHeight)); // TAG CATEGORIES GUILayout.BeginHorizontal(); if (queryTags == null) { queryTags = new List <string>(); } foreach (KeyValuePair <string, List <string> > kv in library.categories) { GUILayout.BeginVertical(GUILayout.Width(130)); //GUILayout.Label (kv.Key); foreach (string tag in kv.Value) { //GUILayout.Label ("- "+tag); EditorGUI.BeginChangeCheck(); EditorGUILayout.ToggleLeft(tag, queryTags.Contains(tag), GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { if (queryTags.Contains(tag)) { queryTags.Remove(tag); } else { queryTags.Add(tag); } library.filterResultsUsing(queryTags); } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); // TAG CATEGORIES EditorGUILayout.EndScrollView(); GUILayout.Label(" ", shadowUp); GUILayout.Space(16); } EditorGUILayout.EndFadeGroup(); // CATALOG List <LibraryItem> libraryItems = null; //if (showClass == 1) /* * if (ArchimatixEngine.library.filteredResults.Count > 0) * { * * * libraryItems = ArchimatixEngine.library.filteredResults; * } */ GUILayout.Label(" ", shadowDown); int currentFiltersHeight = (showFilters.target ? filtersHeight + 36 : 0); Vector2 scrollPos = EditorGUILayout.BeginScrollView(libraryScrollPosition, GUILayout.Width(position.width), GUILayout.Height(position.height - 120 - currentFiltersHeight)); if (Vector2.Distance(scrollPos, libraryScrollPosition) > 1) { //Debug.Log ("NOT SCROLLING TO TARGET"); scrollingToTarget = false; libraryScrollPosition = scrollPos; } else if (scrollingToTarget) { libraryScrollPosition = Vector2.Lerp(libraryScrollPosition, libraryScrollTargetPosition, .05f); //Debug.Log ("SCROLLING TO TARGET "+Vector2.Distance(libraryScrollPosition, libraryScrollTargetPosition)); if (Vector2.Distance(libraryScrollPosition, libraryScrollTargetPosition) < 50) { scrollingToTarget = false; } } if (Event.current.type == EventType.Layout) { columnCount = (int)Math.Floor(position.width / (thumbnailSize + 20)); if (columnCount == 0) { columnCount = 1; } rowCount = libraryItems.Count / columnCount; rowCount++; cellCount = rowCount * columnCount; } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); bool showDetailRow = false; LibraryItem libraryItem; for (int i = 0; i < cellCount; i++) { if (i >= libraryItems.Count) { break; } libraryItem = libraryItems[i]; if (i % columnCount == 0 && i > 0) { GUILayout.EndHorizontal(); if (showDetailRow) { showDetailRow = false; doDetailView(); } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); } // MENU BUTTON EditorGUILayout.BeginVertical(); // ---------------------------- //Debug.Log("LIBRARY: " + poList.Count); if (i < libraryItems.Count) { if (detailItem == libraryItem) { showDetailRow = true; } // THE BIG CLICK if (GUILayout.Button(libraryItems[i].icon, GUILayout.Width(thumbnailSize), GUILayout.Height(thumbnailSize))) { if (Event.current.shift) { //Make a new Model For Sure AXEditorUtilities.createNewModel(); Library.instantiateParametricObject(libraryItem.readIntoLibraryFromRelativeAXOBJPath); } else { Library.instantiateParametricObject(libraryItem.readIntoLibraryFromRelativeAXOBJPath); } } } // LABEL AND DELETE BUTTON EditorGUILayout.BeginHorizontal(); string name = ""; if (i < libraryItems.Count) { name = libraryItem.Name; } GUILayout.Label(name, GUILayout.Width(thumbnailSize - 20), GUILayout.Height(16)); if (i < libraryItems.Count) { if (editingLibrary) { if (GUILayout.Button("-", GUILayout.Width(16))) { Library.removeLibraryItem(libraryItem); } } else { if (GUILayout.Button("i", GUILayout.Width(16))) { if (detailItem == libraryItem && showDetailItem.faded == 1) { //detailItem = ""; showDetailItem.target = false; libraryScrollTargetPosition = libraryScrollPosition + new Vector2(0, -thumbnailSize); scrollingToTarget = true; } else { detailScreen(libraryItem); showDetailItem.target = true; int row = (int)Mathf.Floor(i / columnCount); //if (row != currentRow) //{ libraryScrollTargetPosition = libraryScrollPosition + new Vector2(0, +thumbnailSize * 2); scrollingToTarget = true; //} //else //scrollingToTarget = false; currentRow = row; } } } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.Space(8); // ------------------------------ EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); if (showDetailRow) { showDetailRow = false; doDetailView(); } GUILayout.Space(256); EditorGUILayout.EndScrollView(); //GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); if (editingLibrary) { if (GUILayout.Button("Done", GUILayout.Width(32))) { editingLibrary = false; } } else { if (GUILayout.Button("Edit", GUILayout.Width(32))) { editingLibrary = true; } } GUILayout.FlexibleSpace(); EditorGUI.BeginChangeCheck(); thumbnailSize = EditorGUILayout.IntSlider(thumbnailSize, 32, 256, GUILayout.Width(300)); if (EditorGUI.EndChangeCheck()) { showDetailRow = false; detailItem = null; } EditorGUILayout.EndHorizontal(); labelstyle.fixedWidth = 0; }
// HEADER GUI void HeaderOnGui() { GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.UpperLeft; labelstyle.fixedWidth = 300; // WINDOW TITLE string libtype = (showClass == 3 ? "3D":"2D"); EditorGUILayout.BeginHorizontal(); labelstyle.fontSize = 24; GUILayout.Label("Archimatix " + libtype + " Library"); labelstyle.fontSize = 12; EditorGUILayout.Space(); if (GUILayout.Button("Refresh")) { ArchimatixEngine.createLibraryFromJSONFiles(); } EditorGUILayout.Space(); if (showClass == 3) { if (GUILayout.Button("Switch to 2D")) { showClass = 2; } } else { if (GUILayout.Button("Switch to 3D")) { showClass = 3; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // SEARCH FIELD GUILayout.Label("Search", richRightLabelStyle); if (string.IsNullOrEmpty(searchString)) { searchString = ""; } EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("TF_SEARCH"); searchString = GUILayout.TextField(searchString, GUILayout.Width(130)); if (EditorGUI.EndChangeCheck()) { string[] words = searchString.Split(' '); ArchimatixEngine.library.filterResultsUsingSearch(new List <string>(words)); lastTextField = "TF_SEARCH"; } if (GUILayout.Button("x", GUILayout.Width(20))) { GUI.FocusControl("dummy"); searchString = ""; ArchimatixEngine.library.filteredResults = null; } GUILayout.FlexibleSpace(); if (viewLayout == ViewLayout.EditList) { if (GUILayout.Button("Grid", GUILayout.Width(100))) { viewLayout = ViewLayout.Grid; } } else { if (GUILayout.Button("Edit", GUILayout.Width(100))) { viewLayout = ViewLayout.EditList; } } EditorGUILayout.EndHorizontal(); }
public static Library loadLibraryMetadata() { //Debug.Log("Loading Binary Library"); string filename = getLibraryPath() + "axlibrary.dat"; if (File.Exists(filename)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(filename, FileMode.Open); Library library = (Library)bf.Deserialize(file); file.Close(); if (library == null || library.libraryItems == null || library.libraryItems.Count == 0) { ArchimatixEngine.createLibraryFromJSONFiles(); } if (library == null || library.libraryItems == null || library.libraryItems.Count == 0) { Debug.Log("reloading library"); ArchimatixEngine.createLibraryFromJSONFiles(); } // check if the number of axfiles is different than the number of library items if (library != null && library.libraryItems != null) { DirectoryInfo info = new DirectoryInfo(Application.dataPath); FileInfo[] files = info.GetFiles("*.axobj", SearchOption.AllDirectories); if (files.Length != library.libraryItems.Count) { // this might be the case after you reinstall AX and the user has her own library items somewhere else in the asset folder. ArchimatixEngine.createLibraryFromJSONFiles(); } } if (library != null && library.libraryItems != null && library.libraryItems.Count > 0) { // check to make sure that the libraryItems have the right path // if not, then reread from JSON files. // if ( File.Exists(library.libraryItems[0].readIntoLibraryFromAbsoluteAXOBJPath)) // ArchimatixEngine.createLibraryFromJSONFiles(); library.cacheLibraryItems(); library.sortLibraryItems(); return(library); } } // no existing library ArchimatixEngine.createLibraryFromJSONFiles(); return(ArchimatixEngine.library); }
public static AXParametricObject pasteParametricObjectFromString(String json_string) { if (string.IsNullOrEmpty(json_string)) { json_string = EditorGUIUtility.systemCopyBuffer; } if (string.IsNullOrEmpty(json_string)) { return(null); } AXModel model = null; // 1. First choice is to use a selected model.... if (ArchimatixEngine.currentModel != null) { model = ArchimatixEngine.currentModel; } bool doInstantiation = true; if (model == null) { // ok, are there other models in the scene that the user doesn't realize arene't selected? AXModel[] axModels = GameObject.FindObjectsOfType(typeof(AXModel)) as AXModel[]; if (axModels != null) { if (axModels.Length == 1) { // Offer this model as a button, but also give opportunity to create a new one... int option = EditorUtility.DisplayDialogComplex("Instantiating Library Item", "There is no AX model currently selected", "Cancel", "Add to " + axModels[0], "Create a new Model"); switch (option) { // Save Scene case 0: doInstantiation = false; break; // Save and Quit. case 1: model = axModels[0]; break; case 2: GameObject axgo = AXEditorUtilities.createNewModel(); model = axgo.GetComponent <AXModel>(); doInstantiation = false; break; default: doInstantiation = false; break; } } else if (axModels.Length > 1) { // Throw up a dialog to see if use wants to go select one of the existing models or create a new one. if (EditorUtility.DisplayDialog("Instantiating Library Item", "There is no AX model currently selected", "Select and Existing Model", "Create a new Model")) { return(null); } } } } if (!doInstantiation) { return(null); } if (model == null) { // Well, then, we tried everything.... GameObject axgo = AXEditorUtilities.createNewModel(); model = axgo.GetComponent <AXModel>(); } List <AXParametricObject> poList = new List <AXParametricObject>(); List <AXRelation> relationList = new List <AXRelation>(); AX.SimpleJSON.JSONNode json = null; try { json = AX.SimpleJSON.JSON.Parse(json_string); } catch { return(null); } if (json == null) { return(null); } if (json["parametric_objects"] != null) { foreach (AX.SimpleJSON.JSONNode poNode in json["parametric_objects"].AsArray) { poList.Add(JSONSerializersAX.ParametricObjectFromJSON(poNode)); } } foreach (AX.SimpleJSON.JSONNode rNode in json["relations"].AsArray) { relationList.Add(AXRelation.fromJSON(rNode)); } //Debug.Log (rNode); // make sure there is a game object ready to instantiate this on if (model == null) { // check if the user really wants to create a new model... GameObject axgo = AXEditorUtilities.createNewModel(); model = axgo.GetComponent <AXModel>(); } Undo.RegisterCompleteObjectUndo(model, "Add Library Object"); AXParametricObject head_po = poList[0]; if (model.currentWorkingGroupPO != null && model.currentWorkingGroupPO.Name != head_po.Name) { head_po.grouperKey = model.currentWorkingGroupPO.Guid; } else { head_po.grouperKey = null; } // ADD AND RIGUP // !!! Actually add the library item (as a list of PO's and Relations) to the model model.addAndRigUp(poList, relationList); head_po.startStowInputs(); //if (poList[0].is2D() && ArchimatixEngine.workingAxis != (int) Axis.NONE) // poList[0].intValue ("Axis", ArchimatixEngine.workingAxis); model.setRenderMode(AXModel.RenderMode.GameObjects); model.generate(); ArchimatixEngine.currentModel = model; Selection.activeGameObject = model.gameObject; model.selectOnlyPO(head_po); head_po.focusMe = true; //AXParametricObject mostRecentPO = model.recentlySelectedPO; AXParametricObject mostRecentPO = model.recentlySelectedPO; //getPOSelectedBefore(head_po); //Debug.Log ("model.focusPointInGraphEditor="+model.focusPointInGraphEditor); float pos_x = (model.focusPointInGraphEditor.x) + 100; // + UnityEngine.Random.Range(-100, 300); float pos_y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); if (mostRecentPO != null) { //pos_x = mostRecentPO.rect.x + 200; //pos_y = mostRecentPO.rect.y; } //Debug.Log (new Rect(pos_x, pos_y, 150, 100)); head_po.rect = new Rect(pos_x, pos_y, 150, 500); //Debug.Log ("OK "+po.Name+".focusMe = " + po.focusMe); // make sure it is in view in the editor window.... //model.startPanningToRect(head_po.rect); //model.cleanGraph(); model.autobuild(); head_po.generator.adjustWorldMatrices(); model.selectOnlyPO(head_po); // Paste inside grouper? if (model.currentWorkingGroupPO != null && model.currentWorkingGroupPO.Name != head_po.Name) { model.currentWorkingGroupPO.addGroupee(head_po); } if (model.currentWorkingGroupPO != null && model.currentWorkingGroupPO.Name == head_po.Name) { model.currentWorkingGroupPO = model.currentWorkingGroupPO.grouper; } //model.beginPanningToRect(head_po.rect); //AXNodeGraphEditorWindow.zoomToRectIfOpen(head_po.rect); //Debug.Log(" 1 model.selectedPOs.Count="+model.selectedPOs.Count + " " + model.selectedPOs[0].Name ); // EDITOR WINDOW ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); // SCENEVIEW if (SceneView.lastActiveSceneView != null) { //Debug.Log("REPAINT"); SceneView.lastActiveSceneView.Repaint(); } //Debug.Log("--> ArchimatixEngine.currentModel=" + ArchimatixEngine.currentModel); return(head_po); }
public static string getLibraryPath() { ArchimatixEngine.establishPaths(); return(Application.dataPath + "/" + ArchimatixEngine.ArchimatixAssetPath.Replace("Assets/", "") + "/Library/"); }
void OnGUI() { // Is all in order with the Archimatix install? if (string.IsNullOrEmpty(ArchimatixEngine.pathChangelog) || string.IsNullOrEmpty(changelogText)) { return; } if (richLabelStyle == null) { richLabelStyle = new GUIStyle(GUI.skin.label); richLabelStyle.richText = true; richLabelStyle.wordWrap = true; richButtonStyle = new GUIStyle(GUI.skin.button); richButtonStyle.richText = true; textLabelStyle = new GUIStyle(GUI.skin.label); textLabelStyle.richText = true; textLabelStyle.wordWrap = true; textLabelStyle.alignment = TextAnchor.MiddleLeft; textLabelStyle.fixedWidth = 510; iconButtonStyle = new GUIStyle(GUI.skin.button); iconButtonStyle.normal.background = null; iconButtonStyle.imagePosition = ImagePosition.ImageOnly; iconButtonStyle.fixedWidth = 128; iconButtonStyle.fixedHeight = 128; } Rect headerRect = new Rect(0, 0, 530, 200); EditorGUI.DrawTextureTransparent(headerRect, headerPic, ScaleMode.StretchToFill); GUILayout.Space(200); GUILayout.BeginVertical(); { // What to do next.... horizontalRule(0, 2); /* * GUILayout.BeginHorizontal(); * GUILayout.FlexibleSpace(); * GUILayout.Label ("Version " +ArchimatixEngine.version, richLabelStyle); * GUILayout.FlexibleSpace(); * GUILayout.EndHorizontal(); */ // TOP BUTTONS GUILayout.BeginHorizontal(); GUILayout.Space(5); // User GUIDE if (GUILayout.Button("<b>User Guide </b>\n<size=12>The best way to get started</size>", richButtonStyle, GUILayout.MaxWidth(400), GUILayout.Height(36))) { string file = "file:///" + Application.dataPath + "/Archimatix/Documentation/UserGuide.pdf"; Application.OpenURL(file); } // TUTORIALS if (GUILayout.Button("<b>Tutorial Videos </b>\n<size=12>Watch a range of how-tos</size>", richButtonStyle, GUILayout.MaxWidth(400), GUILayout.Height(36))) { Application.OpenURL("http://www.archimatix.com/tutorials"); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(4); GUILayout.Label("Or, click on one of these to jump right in!", textLabelStyle, new GUILayoutOption[] { GUILayout.MinWidth(450) }); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (GUILayout.Button(icon3DLibrary, iconButtonStyle)) { ArchimatixEngine.openLibrary3D(); } if (GUILayout.Button(icon2DLibrary, iconButtonStyle)) { ArchimatixEngine.openLibrary2D(); } //if (ArchimatixEngine.NodeGraphEditorIsInstalled) //{ if (GUILayout.Button(iconAXEditor, iconButtonStyle)) { AXNodeGraphEditorWindow.Init(); } //} GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); } horizontalRule(4, 1); // CHANGE_LOG GUILayout.BeginHorizontal(); changelogScroll = GUILayout.BeginScrollView(changelogScroll, GUIStyle.none, new GUIStyle(GUI.skin.verticalScrollbar)); GUILayout.Label(changelogText, textLabelStyle); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); horizontalRule(0, 4); GUILayout.BeginHorizontal(); { showAcknowledgements = EditorGUILayout.Foldout(showAcknowledgements, "Acknowledgments", true); if (showAcknowledgements) { GUILayout.BeginHorizontal(); { GUILayout.TextArea("Special thanks to Unity community members in the Beta Team: @elbows, @S_Darkwell, @HeliosDoubleSix, @Teila, @wetcircuit, @radimoto @puzzlekings, @mangax, @sarum, @Sheriziya, @Voronoi, @steveR, @manpower13, @vrpostcard, @Whippets, @pixelstream, @Damien-Delmarle, @recursive, @sloopidoopi, @KWaldt, @pcg, @Hitch42, @Bitstream, @CognitiveCode, @ddutchie, @JacooGamer, @razmot, @angrypenguin, @Paylo, @AdamGoodrich. Also, for much needed feedback and support, many thanks to Eden Muir, Andrew Cortese, Lucas Meijer, Sanjay Mistry, Dominic Laflamme, Rune Skovbo, Alan Robles, Luke Noonan, Anton Hand, Lucas Miller, and Joachim Holmér"); } GUILayout.EndHorizontal(); } } GUILayout.EndHorizontal(); // BOTTOM BUTTON - DOCUMENTATION GUILayout.BeginHorizontal(); { if (GUILayout.Button("<b>Documentation</b>\n<size=12>Manual, examples and tips</size>", richButtonStyle, GUILayout.MaxWidth(260), GUILayout.Height(36))) { Application.OpenURL("http://archimatix.com/documentation"); } if (GUILayout.Button("<b>Rate it</b>\n<size=12>on the Asset Store</size>", richButtonStyle, GUILayout.Height(36))) { Application.OpenURL("http://u3d.as/qYW"); //Application.OpenURL("com.unity3d.kharma:content/?"); } if (GUILayout.Button("<b>Join the Community!</b>\n<size=12>We're are building worlds.</size>", richButtonStyle, GUILayout.Height(36))) { Application.OpenURL("http://community.archimatix.com"); //Application.OpenURL("com.unity3d.kharma:content/?"); } } GUILayout.EndHorizontal(); // Contact horizontalRule(4, 2); GUILayout.BeginHorizontal(); { if (GUILayout.Button("<b>E-mail</b>\n<size=12>[email protected]</size>", richButtonStyle, GUILayout.MaxWidth(172), GUILayout.Height(36))) { Application.OpenURL("mailto:[email protected]"); } if (GUILayout.Button("<b>Twitter</b>\n<size=12>@archimatix</size>", richButtonStyle, GUILayout.Height(36))) { Application.OpenURL("http://twitter.com/archimatix"); } // UNITY FORUM if (GUILayout.Button("<b>Unity Forum</b>\n<size=12>The Original!</size>", richButtonStyle, GUILayout.MaxWidth(172), GUILayout.Height(36))) { Application.OpenURL("http://bit.ly/2gj4oax"); } } GUILayout.EndHorizontal(); GUILayout.Space(5); GUILayout.EndVertical(); }
// return the height of this gui area public static void OnGUI(Rect headerRect, AXNodeGraphEditorWindow editor) { Event e = Event.current; AXModel model = editor.model; // DO HEADER MENU BAR -- MODEL MENU GUILayout.BeginArea(headerRect); GUILayout.BeginHorizontal(); GUIStyle labelstyle = new GUIStyle(GUI.skin.label); labelstyle.alignment = TextAnchor.LowerLeft; labelstyle.fixedWidth = 150; GUILayout.Space(5); if (GUILayout.Button("2D")) { ArchimatixEngine.openLibrary2D(); } if (GUILayout.Button("3D")) { ArchimatixEngine.openLibrary3D(); } // NEW MODEL GUILayout.Space(10); if (GUILayout.Button("▼")) { AXModel[] allModels = ArchimatixUtils.getAllModels(); GenericMenu menu = new GenericMenu(); //menu.AddSeparator("Library ..."); if (allModels != null && allModels.Length > 0) { for (int i = 0; i < allModels.Length; i++) { AXModel m = allModels [i]; menu.AddItem(new GUIContent(m.gameObject.name), false, () => { Selection.activeGameObject = m.gameObject; ArchimatixEngine.currentModel = m; }); } } menu.AddSeparator(""); menu.AddItem(new GUIContent("New Model"), false, () => { AXEditorUtilities.createNewModel(); }); menu.ShowAsContext(); } Color bgc = GUI.backgroundColor; GUI.backgroundColor = Color.clear; if (model != null) { // SELECTED MODEL if (GUILayout.Button(model.name)) { model.currentWorkingGroupPO = null; model.selectAllVisibleInGroup(null); float framePadding = 50; Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } if (model.currentWorkingGroupPO != null) { if (model.currentWorkingGroupPO.grouper != null) { // Make breadcrumb trail List <AXParametricObject> crumbs = new List <AXParametricObject>(); AXParametricObject cursor = model.currentWorkingGroupPO; while (cursor.grouper != null) { crumbs.Add(cursor.grouper); cursor = cursor.grouper; } crumbs.Reverse(); // model button frames for (int i = 0; i < crumbs.Count; i++) { if (GUILayout.Button("> " + crumbs[i].Name)) { model.currentWorkingGroupPO = crumbs[i]; Rect grouperCanvasRect = model.currentWorkingGroupPO.getBoundsRect(); editor.zoomToRect(grouperCanvasRect); } } } GUILayout.Button("> " + model.currentWorkingGroupPO.Name); } } GUILayout.FlexibleSpace(); if (model != null) { Color buildBG = Color.Lerp(Color.cyan, Color.white, .8f); string buildLabel = "Rebuild"; if (model.buildStatus == AXModel.BuildStatus.Generated) { buildBG = Color.red; buildLabel = "Build"; } GUI.backgroundColor = buildBG; if (GUILayout.Button(buildLabel)) { model.build(); } GUI.backgroundColor = Color.cyan; if (model.generatedGameObjects != null && model.generatedGameObjects.transform.childCount == 0) { GUI.enabled = false; } if (GUILayout.Button("Stamp")) { model.stamp(); } if (GUILayout.Button("Prefab")) { string startDir = Application.dataPath; string path = EditorUtility.SaveFilePanel( "Save Prefab", startDir, ("" + model.name), "prefab"); if (!string.IsNullOrEmpty(path)) { AXPrefabWindow.makePrefab(model, path, editor); } } GUI.enabled = true; GUILayout.Space(4); } GUILayout.EndHorizontal(); GUILayout.EndArea(); GUI.backgroundColor = bgc; }
public override void OnSceneGUI() { AXModel model = ArchimatixEngine.currentModel; FreeCurve gener = (FreeCurve)generator; Event e = Event.current; if (model != null) { Matrix4x4 context = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; // * generator.localMatrix; drawGUIControls(); if ((ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint || (e.type == EventType.mouseDrag && ArchimatixEngine.isPseudoDraggingSelectedPoint >= 0)) && !e.alt) { Vector3 v1 = context.MultiplyPoint3x4(Vector3.zero); Vector3 v2 = context.MultiplyPoint3x4(new Vector3(100, 0, 0)); Vector3 v3 = context.MultiplyPoint3x4(new Vector3(0, 100, 0)); //Debug.Log ("-"+ArchimatixEngine.sceneViewState + "- plane points: " + v1 + ", " + v2+ ", " + v3 ); Plane drawingSurface = new Plane(v1, v2, v3); //Matrix4x4 = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix;// * generator.localMatrix.inverse; Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); float rayDistance = 0; Vector3 hitPoint; // Point on Plane if (drawingSurface.Raycast(ray, out rayDistance)) { hitPoint = ray.GetPoint(rayDistance); Vector3 hit_position3D = new Vector3(hitPoint.x, hitPoint.y, hitPoint.z); if (ArchimatixEngine.snappingOn()) { hit_position3D = AXGeometryTools.Utilities.SnapToGrid(hit_position3D, parametricObject.model.snapSizeGrid); } int nearId = HandleUtility.nearestControl; if (nearId == 0) { Color cyan = Color.cyan; cyan.a = .1f; float hScale = .09f * HandleUtility.GetHandleSize(hit_position3D); float lScale = 5 * hScale; Handles.color = cyan; Handles.DrawSolidDisc(hit_position3D, Vector3.up, hScale); cyan.a = .8f; Handles.color = cyan; Handles.DrawWireDisc(hit_position3D, Vector3.up, 2 * hScale); Handles.DrawLine(hit_position3D + lScale * Vector3.forward, hit_position3D - lScale * Vector3.forward); //Handles.color = Color.white; Handles.DrawLine(hit_position3D + lScale * Vector3.right, hit_position3D - lScale * Vector3.right); // put visual cue under mouse.... //Debug.Log (hitPoint); } hitPoint = context.inverse.MultiplyPoint3x4(hitPoint); Vector2 hit_position2D = new Vector2(hitPoint.x, hitPoint.y); if (ArchimatixEngine.snappingOn()) { hit_position2D = AXGeometryTools.Utilities.SnapToGrid(hit_position2D, parametricObject.model.snapSizeGrid); } // EVENTS if (e.type == EventType.MouseDown && !e.alt && nearId == 0 && e.button == 0) { ArchimatixEngine.isPseudoDraggingSelectedPoint = -1; if (gener != null) { if (!e.control) // add to end of line { // ADD POINT AT END gener.parametricObject.curve.Add(new CurvePoint(hit_position2D.x, hit_position2D.y)); gener.selectedIndex = gener.parametricObject.curve.Count - 1; } else // ADD POINT TO BEGINNING { gener.parametricObject.curve.Insert(0, new CurvePoint(hit_position2D.x, hit_position2D.y)); gener.selectedIndex = 0; } ArchimatixEngine.isPseudoDraggingSelectedPoint = gener.selectedIndex; model.autobuild(); } } else if (e.type == EventType.mouseDrag) { //Debug.Log("Dragging "+ ArchimatixEngine.isPseudoDraggingSelectedPoint + " :: " + generator.selectedIndices); if (gener == ArchimatixEngine.selectedFreeCurve && ArchimatixEngine.isPseudoDraggingSelectedPoint >= 0) { if (gener.parametricObject.curve.Count > ArchimatixEngine.isPseudoDraggingSelectedPoint && generator.selectedIndices != null) { // The actual point being dragged: Vector2 displ = hit_position2D - gener.parametricObject.curve[ArchimatixEngine.isPseudoDraggingSelectedPoint].position; gener.parametricObject.curve[ArchimatixEngine.isPseudoDraggingSelectedPoint].position = hit_position2D; for (int i = 0; i < model.activeFreeCurves.Count; i++) { FreeCurve fc = (FreeCurve)model.activeFreeCurves[i].generator; if (fc != null && fc.selectedIndices != null) { for (int j = 0; j < fc.selectedIndices.Count; j++) { if (!(fc == gener && fc.selectedIndices[j] == ArchimatixEngine.isPseudoDraggingSelectedPoint)) { fc.parametricObject.curve[fc.selectedIndices[j]].position += displ; } } } } //Debug.Log ("DRAGGING"); parametricObject.setAltered(); model.isAltered(); generator.adjustWorldMatrices(); } } } if (e.type == EventType.mouseUp) { //if (ArchimatixEngine.isPseudoDraggingSelectedPoint > -1) ArchimatixEngine.isPseudoDraggingSelectedPoint = -1; ArchimatixEngine.draggingNewPointAt = -1; //model.autobuild(); //Debug.Log("mouse up"); } if ((e.type == EventType.mouseDown) || (e.type == EventType.mouseDrag && ArchimatixEngine.isPseudoDraggingSelectedPoint >= 0) || (e.type == EventType.mouseUp)) { //e.Use(); } SceneView sv = SceneView.lastActiveSceneView; if (sv != null) { sv.Repaint(); } } } } } // \OnScenView
/* * [MenuItem("GameObject/3D Object/Archimatix Nodes/Meshers/Lathe")] * static void Init() { * AXEditorUtilities.addNodeToCurrentModel("Lathe"); * } */ public override void drawControlHandlesofInputParametricObjects(ref List <string> visited, Matrix4x4 consumerM) { Lathe gener = (generator as Lathe); //if (visited.Contains ("c_"+parametricObject.Guid)) // return; //visited.Add ("c_"+parametricObject.Guid); // SECTION if (gener.sectionSrc_po != null && gener.sectionSrc_po.generator != null) { GeneratorHandler gh = getGeneratorHandler(gener.sectionSrc_po); if (gh != null) { Matrix4x4 localSecM = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; // * generator.getLocalConsumerMatrixPerInputSocket(gener.sectionSrc_po); if (gener.sectionSrc_po.is2D()) { gh.drawTransformHandles(visited, localSecM, true); } gh.drawControlHandles(ref visited, localSecM, true); } } // PLAN Matrix4x4 prevHandlesMatrix = Handles.matrix; float y = .5f * HandleUtility.GetHandleSize(Vector3.zero); float yd = 0.5f * HandleUtility.GetHandleSize(Vector3.zero) + .2f * parametricObject.bounds.extents.y; float handleSizer = .15f * HandleUtility.GetHandleSize(Vector3.zero); Handles.matrix *= Matrix4x4.TRS(new Vector3(0, -yd, 0), Quaternion.identity, Vector3.one); Vector3 pos; Color lightLineColor = new Color(1, .8f, .6f, .7f); Color brightOrange = new Color(1, .8f, 0, .9f); // RADIUS // Handles.color = brightOrange; //Handles.DrawLine(new Vector3(gener.radius, y, 0), new Vector3(gener.radius, -y, 0)); Handles.DrawLine(new Vector3(0, 0, 0), new Vector3(0, -y, 0)); //Handles.DrawLine(new Vector3(0, -y*.66f, 0), new Vector3(gener.radius, -y*.66f, 0)); // RADIUS LABEL GUIStyle labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.white; Handles.Label(new Vector3(gener.radius + handleSizer, -y / 4, 0), "rad=" + System.Math.Round(gener.radius, 2), labelStyle); // RADIUS HANDLE pos = new Vector3(gener.radius, 0, 0); EditorGUI.BeginChangeCheck(); pos = Handles.FreeMoveHandle( pos, Quaternion.identity, .15f * HandleUtility.GetHandleSize(pos), Vector3.zero, (controlID, positione, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.mouseDownOnSceneViewHandle(); } Handles.SphereCap(controlID, positione, rotation, size); }); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "Radius"); //.parametricObject.setAltered(); gener.P_Radius.initiateRipple_setFloatValueFromGUIChange(pos.x); gener.radius = pos.x; gener.parametricObject.model.isAltered(23); for (int i = 0; i < generator.P_Output.Dependents.Count; i++) { generator.P_Output.Dependents [i].parametricObject.generator.adjustWorldMatrices(); } generator.adjustWorldMatrices(); } Handles.color = new Color(1, .8f, .6f, .05f); Handles.DrawSolidArc(Vector3.zero, Vector3.up, Vector2.right, -gener.sweepAngle, gener.radius + .2f); Handles.color = lightLineColor; Handles.DrawLine(new Vector3(0, 0, 0), new Vector3(gener.radius, 0, 0)); // TOTAL ANGLE SWEEP Handles.color = new Color(1, .5f, 0f, .3f); Quaternion rot = Quaternion.Euler(0, 360 - gener.sweepAngle, 0); EditorGUI.BeginChangeCheck(); rot = Handles.Disc(rot, Vector3.zero, Vector3.up, gener.radius, false, 1); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "RadialRepeat Total Angle"); gener.P_SweepAngle.initiateRipple_setFloatValueFromGUIChange(360 - rot.eulerAngles.y); gener.parametricObject.model.isAltered(23); for (int i = 0; i < generator.P_Output.Dependents.Count; i++) { generator.P_Output.Dependents [i].parametricObject.generator.adjustWorldMatrices(); } } Handles.color = new Color(1, .5f, 0f, 1f); Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.right, (-gener.sweepAngle), gener.radius); Handles.matrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 360 - gener.sweepAngle, 0), Vector3.one); // SEGMENT CLICKERS // (-) /* * Handles.color = new Color(.7f, .7f, 1, .9f); * pos = new Vector3(gener.radius, 0, -handleSizer*2); * if(Handles.Button(pos, Quaternion.Euler(0,180,0), handleSizer, handleSizer, Handles.ConeCap)) * { * Undo.RegisterCompleteObjectUndo (parametricObject.model, "Segs"); * * gener.P_Segs.intiateRipple_setIntValueFromGUIChange(gener.segs-1); * * gener.parametricObject.model.autobuild(); * for (int i = 0; i < generator.P_Output.Dependents.Count; i++) * generator.P_Output.Dependents [i].parametricObject.generator.adjustWorldMatrices (); * } * * // [+] * Handles.color = new Color(.7f, 1f, .7f, .9f); * pos = new Vector3(gener.radius, 0, handleSizer*2); * if(Handles.Button(pos, Quaternion.Euler(0,0,0), handleSizer, handleSizer, Handles.ConeCap)) * { * Undo.RegisterCompleteObjectUndo (parametricObject.model, "Segs"); * * gener.P_Segs.intiateRipple_setIntValueFromGUIChange(gener.segs+1); * * gener.parametricObject.model.autobuild(); * for (int i = 0; i < generator.P_Output.Dependents.Count; i++) * generator.P_Output.Dependents [i].parametricObject.generator.adjustWorldMatrices (); * } * * Handles.Label(new Vector3(gener.radius, -y/4, -handleSizer*4), ""+(gener.segs) + " segs", labelStyle); */ // ANGLESWEEP KNOB /* * Handles.color = brightOrange; * Handles.SphereCap(0, * new Vector3(gener.radius, 0, 0), * Quaternion.identity, * .15f*HandleUtility.GetHandleSize(pos)); */ Handles.Label(new Vector3(0, -y, 0), "" + System.Math.Round(gener.snappedSweepAngle, 0) + " degs", labelStyle); Handles.matrix = prevHandlesMatrix; }
public void doPO(AXParametricObject po) { Color guiColorOrig = GUI.color; Color guiContentColorOrig = GUI.contentColor; GUI.color = Color.white; GUI.contentColor = Color.white; Color textColor = new Color(.82f, .80f, .85f); Color textColorSel = new Color(.98f, .95f, 1f); GUIStyle labelstyle = new GUIStyle(GUI.skin.label); //int fontSize = labelstyle.fontSize; labelstyle.fixedHeight = 30; labelstyle.alignment = TextAnchor.UpperLeft; labelstyle.normal.textColor = textColorSel; labelstyle.fontSize = 20; // GUIStyle labelstyleTmp = GUI.skin.GetStyle("Label"); // labelstyleTmp.normal.textColor = Color.red; Color bgcolorOrig = GUI.backgroundColor; //GUI.backgroundColor = Color.cyan; GUIStyle gsTest = new GUIStyle(); gsTest.normal.background = ArchimatixEngine.nodeIcons ["Blank"]; // //Color.gray; gsTest.normal.textColor = Color.white; GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); foldoutStyle.normal.textColor = textColor; foldoutStyle.active.textColor = textColorSel; foldoutStyle.hover.textColor = textColor; foldoutStyle.focused.textColor = textColorSel; foldoutStyle.onNormal.textColor = textColor; foldoutStyle.onActive.textColor = textColorSel; foldoutStyle.onHover.textColor = textColor; foldoutStyle.onFocused.textColor = textColorSel; GUIStyle smallFoldoutStyle = new GUIStyle(EditorStyles.foldout); smallFoldoutStyle.fixedWidth = 0; GUILayout.BeginVertical(gsTest); GUILayout.BeginHorizontal(gsTest); GUILayout.Space(40); Rect rect = GUILayoutUtility.GetLastRect(); //GUI.DrawTexture(new Rect(position.x, rect.y, EditorGUIUtility.currentViewWidth, 100), ArchimatixEngine.nodeIcons["Blank"], ScaleMode.ScaleToFit, true, 1.0F); GUILayout.Space(10); // TITLE GUILayout.Label(po.Name, labelstyle); labelstyle.fontSize = 12; GUILayout.EndHorizontal(); if (po.is2D() && po.generator.hasOutputsReady()) { AXParameter output_p = po.generator.getPreferredOutputParameter(); GUIDrawing.DrawPathsFit(output_p, new Vector2(42, rect.y + 15), 28, ArchimatixEngine.AXGUIColors ["ShapeColor"]); } else if (ArchimatixEngine.nodeIcons != null && ArchimatixEngine.nodeIcons.ContainsKey(po.Type)) { //Rect thumbRect = new Rect (28, rect.y - 0, 36, 36); //GUI.DrawTexture(thumbRect, po.renTex, ScaleMode.ScaleToFit, true, 1.0F); EditorGUI.DrawTextureTransparent(new Rect(28, rect.y - 0, 36, 36), ArchimatixEngine.nodeIcons [po.Type], ScaleMode.ScaleToFit, 1.0F); } Rect rectthumb2 = GUILayoutUtility.GetLastRect(); if (po.is3D() && po.renTex != null) { GUIStyle thumbLgStyle = new GUIStyle(); float thumbLgSize = 64; thumbLgStyle.fixedHeight = thumbLgSize; GUILayout.BeginHorizontal(thumbLgStyle); GUILayout.Space(thumbLgSize); Rect thumbRectLG = new Rect(40, rectthumb2.y + 35, thumbLgSize, thumbLgSize); EditorGUI.DrawTextureTransparent(thumbRectLG, po.renTex, ScaleMode.ScaleToFit, 1.0F); GUILayout.EndHorizontal(); } EditorGUI.indentLevel++; //GUILayout.Space(20); GUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = 35; EditorGUI.BeginChangeCheck(); //EditorGUIUtility.labelWidth = 65; po.isActive = EditorGUILayout.ToggleLeft("Enabled", po.isActive); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "isActive value change for " + po.Name); po.model.autobuild(); po.generator.adjustWorldMatrices(); } GUILayout.FlexibleSpace(); if (GUILayout.Button("Select in Node Graph")) { po.model.selectAndPanToPO(po); } GUILayout.EndHorizontal(); // FLAGS, TAGS & LAYERS if (po.is3D()) { po.displayFlagsTagsLayers = EditorGUILayout.Foldout(po.displayFlagsTagsLayers, "Name, Flags, Tags & Layers", true, foldoutStyle); } else { po.displayFlagsTagsLayers = EditorGUILayout.Foldout(po.displayFlagsTagsLayers, "Name", true, foldoutStyle); } if (po.displayFlagsTagsLayers) { //EDIT TITLE // if (showTitle(po)) // { //GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(35); GUILayout.Label("Name: "); EditorGUIUtility.labelWidth = 65; po.Name = GUILayout.TextField(po.Name); GUILayout.EndHorizontal(); if (po.is3D()) { EditorGUIUtility.labelWidth = 75; EditorGUI.BeginChangeCheck(); po.axStaticEditorFlags = (AXStaticEditorFlags)EditorGUILayout.EnumMaskField("Static: ", po.axStaticEditorFlags); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "Static value change for " + po.Name); po.setUpstreamersToYourFlags(); // post dialog to change all children... ArchimatixEngine.scheduleBuild(); } GUI.backgroundColor = bgcolorOrig; EditorGUIUtility.labelWidth = 75; // TAGS EditorGUI.BeginChangeCheck(); po.tag = EditorGUILayout.TagField("Tag:", po.tag); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "Tag value change for " + po.Name); ArchimatixEngine.scheduleBuild(); } // LAYERS EditorGUI.BeginChangeCheck(); int intval = EditorGUILayout.LayerField("Layer:", po.layer); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "Layer value change for " + po.Name); po.layer = intval; ArchimatixEngine.scheduleBuild(); } bool hasMeshRenderer = !po.noMeshRenderer; EditorGUI.BeginChangeCheck(); hasMeshRenderer = EditorGUILayout.ToggleLeft("Mesh Renderer", hasMeshRenderer); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "hasMeshRenderer"); po.noMeshRenderer = !hasMeshRenderer; ArchimatixEngine.scheduleBuild(); } } else if (po.generator is MaterialTool) { EditorGUI.BeginChangeCheck(); //float thumbSize = 16; po.axMat.mat = (Material)EditorGUILayout.ObjectField(po.axMat.mat, typeof(Material), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "Material"); po.model.remapMaterialTools(); po.model.autobuild(); } } } // FLAGS< TAGS & LAYERS // POSITION CONTROLS if (po.positionControls != null && po.positionControls.children != null) { po.positionControls.isOpenInInspector = EditorGUILayout.Foldout(po.positionControls.isOpenInInspector, "Transform", true, foldoutStyle); if (po.positionControls.isOpenInInspector) { InspectorParameterGUI.OnGUI(po.positionControls.children); } } // GEOMETRY CONTROLS if (po.geometryControls != null && po.geometryControls.children != null) { po.geometryControls.isOpenInInspector = EditorGUILayout.Foldout(po.geometryControls.isOpenInInspector, "Geometry Controls", true, foldoutStyle); if (po.geometryControls.isOpenInInspector) { InspectorParameterGUI.OnGUI(po.geometryControls.children); } } // PROTOTYPES if (po.is3D()) { po.displayPrototypes = EditorGUILayout.Foldout(po.displayPrototypes, "Prototypes", true, foldoutStyle); if (po.displayPrototypes) { EditorGUI.BeginChangeCheck(); po.prototypeGameObject = (GameObject)EditorGUILayout.ObjectField(po.prototypeGameObject, typeof(GameObject), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "Prototype GameObject set for " + po.model.name); if (po.prototypeGameObject != null) { AXPrototype proto = (AXPrototype)po.prototypeGameObject.GetComponent("AXPrototype"); if (proto == null) { proto = po.prototypeGameObject.AddComponent <AXPrototype> (); } if (!proto.parametricObjects.Contains(po)) { proto.parametricObjects.Add(po); } } po.model.autobuild(); } } } if (po.selectedAXGO != null) { GUILayout.Label(po.selectedAXGO.consumerAddress); } // if (po.is3D() && po.renTex != null) // { // GUIStyle thumbLgStyle = new GUIStyle(); // float thumbLgSize = 194; // // thumbLgStyle.fixedHeight = thumbLgSize; // GUILayout.BeginHorizontal(thumbLgStyle); // GUILayout.Space(40); // Rect rectthumb = GUILayoutUtility.GetLastRect(); // Rect thumbRectLG = new Rect(28, rectthumb.y-0, thumbLgSize, thumbLgSize); // GUI.DrawTexture(thumbRectLG, po.renTex, ScaleMode.ScaleToFit, true, 1.0F); // // GUILayout.EndHorizontal(); // } // EditorGUI.indentLevel--; GUILayout.EndVertical(); GUILayout.Space(30); GUI.color = guiColorOrig; GUI.contentColor = guiContentColorOrig; }
// public override int customNodeGUIZone_2(int cur_y, AXNodeGraphEditorWindow editor, AXParametricObject po) // { // // int gap = ArchimatixUtils.gap; // int lineHgt = ArchimatixUtils.lineHgt; // float winMargin = ArchimatixUtils.indent; // float innerWidth = po.rect.width - 2*winMargin; // // Rect pRect = new Rect(winMargin, cur_y, innerWidth, lineHgt); // EditorGUI.TextField(pRect, "YUBBA"); // //GUI.Button(pRect, "HALLO"); // // cur_y += lineHgt; // // return cur_y; // } public override void drawControlHandlesofInputParametricObjects(ref List <string> visited, Matrix4x4 consumerM, bool beingDrawnFromConsumer) { Extrude gener = (generator as Extrude); if (gener.P_Plan == null || gener.planSrc_p == null) { return; } if (gener.parametricObject == null || !gener.parametricObject.isActive) { return; } GeneratorHandler gh = getGeneratorHandler(gener.planSrc_po); if (gh != null) { Matrix4x4 localSecM = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix * generator.getLocalConsumerMatrixPerInputSocket(gener.planSrc_po); gh.drawControlHandles(ref visited, localSecM, true); if (gener.planSrc_po != null && gener.planSrc_po.is2D() || gener.planSrc_po.generator is Grouper) { gh.drawTransformHandles(visited, localSecM, true); } // BEVEL HANDLE Matrix4x4 prevHM = Handles.matrix; Color prevColor = Handles.color; Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix * AXGeometryTools.Utilities.getFirstSegmentHandleMatrix(gener.P_Plan.getPaths()); float handlesMatrixScaleAdjuster = AXEditorUtilities.getHandlesMatrixScaleAdjuster(); if (!gener.bevelOut) { //float bevelMax = (gener.bevelTop > gener.bevelBottom) ? gener.bevelTop : gener.bevelBottom; //Handles.matrix *= Matrix4x4.TRS(new Vector3(-bevelMax, 0, 0), Quaternion.identity, Vector3.one); } float x = 0; //(gener.bevelOut) ? gener.bevelTop : 0; x += gener.P_Plan.thickness + gener.P_Plan.offset; Handles.matrix *= Matrix4x4.TRS(new Vector3(0, 0, 0), Quaternion.Euler(90, 0, 0), Vector3.one); Vector3 posR1 = new Vector3((gener.bevelBottom > gener.bevelTop)? 0 :gener.bevelTop - gener.bevelBottom, gener.bevelBottom, 0); posR1.x += gener.P_Plan.offset; float r2X = (gener.bevelBottom > gener.bevelTop) ? (gener.bevelBottom - gener.bevelTop - gener.taper) : -gener.taper; Vector3 posR2 = new Vector3(r2X, (gener.extrude - gener.bevelTop), 0); posR2.x += gener.P_Plan.offset; // WIRE DISCS Handles.color = Color.red; Handles.DrawWireDisc(posR1, Vector3.forward, gener.bevelBottom); Handles.DrawWireDisc(posR2, Vector3.forward, gener.bevelTop); Handles.color = Color.green; // BEVEL RADIUS 1 // R1 EditorGUI.BeginChangeCheck(); posR1 = Handles.FreeMoveHandle( posR1, Quaternion.identity, .1f * HandleUtility.GetHandleSize(posR1), Vector3.zero, (controlID, positione, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.mouseDownOnSceneViewHandle(); } Handles.SphereCap(controlID, positione, rotation, size); }); if (EditorGUI.EndChangeCheck()) { parametricObject.initiateRipple_setFloatValueFromGUIChange("Bevel Bottom", posR1.y); if (Event.current.alt && gener.bevelsUnified) { gener.P_Bevels_Unified.boolval = false; } // OFFSET float ox = posR1.x; if (gener.bevelBottom < gener.bevelTop) { ox -= (gener.bevelTop - gener.bevelBottom); } gener.P_Plan.offset = (Math.Abs(ox) < (.08f) * HandleUtility.GetHandleSize(posR1)) ? 0 : ox; parametricObject.model.isAltered(32); } // R2 & TAPER EditorGUI.BeginChangeCheck(); posR2 = Handles.FreeMoveHandle( posR2, Quaternion.identity, .1f * HandleUtility.GetHandleSize(posR2), Vector3.zero, (controlID, positione, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.mouseDownOnSceneViewHandle(); } Handles.SphereCap(controlID, positione, rotation, size); }); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "Bevel Radius Changed"); if (Event.current.alt) { parametricObject.initiateRipple_setFloatValueFromGUIChange("Extrude", "Height", (gener.bevelTop + posR2.y)); gener.taper = (gener.bevelBottom > gener.bevelTop) ? gener.bevelBottom - gener.bevelTop - posR2.x : -posR2.x; gener.taper = (Math.Abs(gener.taper) < (.08f) * HandleUtility.GetHandleSize(posR2) * handlesMatrixScaleAdjuster) ? 0 : gener.taper; parametricObject.initiateRipple_setFloatValueFromGUIChange("Taper", gener.taper + gener.P_Plan.offset); } else { parametricObject.initiateRipple_setFloatValueFromGUIChange("Bevel Top", (gener.extrude - posR2.y)); } //parametricObject.model.latestEditedParameter = gener.P_Taper; parametricObject.model.isAltered(32); } /* * EditorGUI.BeginChangeCheck(); * pos1 = Handles.Slider(pos1, Vector3.down, .6f*HandleUtility.GetHandleSize(pos1), Handles.ArrowCap, 0); * * if(EditorGUI.EndChangeCheck()) * { * parametricObject.intiateRipple_setFloatValueFromGUIChange("Bevel Radius Bottom", pos1.y); * parametricObject.model.isAltered(32); * } */ Handles.color = Color.cyan; /* * // TAPER * EditorGUI.BeginChangeCheck(); * //Vector3 taperV = Handles.Slider(new Vector3(-gener.taper, gener.extrude-gener.bevelTop, 0), Vector3.right, .6f*HandleUtility.GetHandleSize(pos1), Handles.ArrowCap, 0); * * Vector3 taperV = Handles.Slider(new Vector3(gener.P_Plan.offset, gener.extrude-gener.bevelTop, 0), Vector3.right, .6f*HandleUtility.GetHandleSize(pos1), Handles.ArrowCap, 0); * if(EditorGUI.EndChangeCheck()) * { * * * // TAPER * //float px = (Math.Abs(taperV.x) < (.08f)*HandleUtility.GetHandleSize(posR2)) ? 0 : -taperV.x; * * Undo.RegisterCompleteObjectUndo (parametricObject.model, "Offset parameter changed"); * * float px = (Math.Abs(taperV.x) < (.08f)*HandleUtility.GetHandleSize(posR2)) ? 0 : taperV.x; * //parametricObject.intiateRipple_setFloatValueFromGUIChange("Taper", px); * //parametricObject.intiateRipple_setFloatValueFromGUIChange("Taper", px); * gener.P_Plan.offset = px; * * parametricObject.model.isAltered(32); * * * } */ /* * // BEVEL_RADIUS_1 ANGLED * float c45 = .70710678f; * EditorGUI.BeginChangeCheck(); * Vector3 bevel2V = Handles.Slider(new Vector3(-gener.taper - (gener.bevelTop*c45), gener.extrude-gener.bevelTop - (gener.bevelTop*c45), 0), new Vector3(-1, -1, 0), .6f*HandleUtility.GetHandleSize(pos1), Handles.ArrowCap, 0); * if(EditorGUI.EndChangeCheck()) * { * * float px = (-bevel2V.x - gener.taper)/c45; * parametricObject.intiateRipple_setFloatValueFromGUIChange("Bevel Radius Top", px); * parametricObject.model.isAltered(32); * } */ /* * * // BEVEL TOP RADIUS * EditorGUI.BeginChangeCheck(); * GUI.SetNextControlName("Bevel Top Radius"); * Vector3 r2V = Handles.Slider(new Vector3(-gener.taper, gener.extrude-gener.bevelTop, 0), Vector3.up, .6f*HandleUtility.GetHandleSize(pos1), Handles.ArrowCap, 0); * //Vector3 r2V = Handles.Slider(new Vector3(-gener.taper, gener.extrude-gener.bevelTop, 0), Vector3.up); * if(EditorGUI.EndChangeCheck()) * { * // TAPER * parametricObject.intiateRipple_setFloatValueFromGUIChange("Bevel Radius Top", gener.extrude-r2V.y); * parametricObject.model.isAltered(32); * * * } * */ // BEVEL SEGS if (gener.bevelTop > 0) { float handleSize = .55f * HandleUtility.GetHandleSize(posR1) * handlesMatrixScaleAdjuster; float adjustedSegs = (gener.bevelHardEdge && gener.bevelSegs == 1) ? 0 : gener.bevelSegs; //Vector3 posSegs = new Vector3(-gener.taper, gener.extrude - gener.bevelTop +handleSize + (.025f*HandleUtility.GetHandleSize(posR1)* gener.bevelSegs), 0); Vector3 posSegs = new Vector3(-gener.taper + handleSize + (.04f * HandleUtility.GetHandleSize(posR1) * adjustedSegs * handlesMatrixScaleAdjuster), gener.extrude - gener.bevelTop, 0); Handles.DrawLine(posR2, posSegs); EditorGUI.BeginChangeCheck(); posSegs = Handles.FreeMoveHandle( posSegs, Quaternion.identity, .1f * HandleUtility.GetHandleSize(posSegs), Vector3.zero, (controlID, positione, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.mouseDownOnSceneViewHandle(); } Handles.SphereCap(controlID, positione, rotation, size); }); if (EditorGUI.EndChangeCheck()) { // BEVEL_TOP_RADIUS //int conv = Mathf.CeilToInt( (posSegs.y + gener.bevelTop - gener.extrude - handleSize) / (.025f*HandleUtility.GetHandleSize(posR1))); Undo.RegisterCompleteObjectUndo(parametricObject.model, "Bevel Segs Changed"); int conv = Mathf.CeilToInt((posSegs.x + gener.taper - handleSize) / (.04f * HandleUtility.GetHandleSize(posR2))); if (conv <= 0) { conv = 1; gener.bevelHardEdge = true; gener.P_BevelHardEdge.boolval = true; } else { gener.bevelHardEdge = false; gener.P_BevelHardEdge.boolval = false; } if (gener.bevelTop == 0) { parametricObject.initiateRipple_setFloatValueFromGUIChange("Bevel Segs", .02f); } parametricObject.initiateRipple_setIntValueFromGUIChange("Bevel Segs", conv); parametricObject.model.isAltered(32); } } /* * * // LIP_TOP * Handles.color = Color.magenta; * * EditorGUI.BeginChangeCheck(); * Vector3 lipTopV = Handles.Slider(new Vector3(-gener.taper-gener.lipTop, gener.extrude, 0), Vector3.left, .6f*HandleUtility.GetHandleSize(posR2), Handles.ArrowCap, 0); * if(EditorGUI.EndChangeCheck()) * { * parametricObject.intiateRipple_setFloatValueFromGUIChange("Lip Top", -lipTopV.x-gener.taper); * parametricObject.model.isAltered(32); * } * * // LIP_EDGE * EditorGUI.BeginChangeCheck(); * lipTopV = Handles.Slider(new Vector3(-gener.taper-gener.lipTop, gener.extrude-gener.lipEdge, 0), Vector3.down, .6f*HandleUtility.GetHandleSize(posR2), Handles.ArrowCap, 0); * if(EditorGUI.EndChangeCheck()) * { * parametricObject.intiateRipple_setFloatValueFromGUIChange("Lip Edge", -lipTopV.y+gener.extrude); * parametricObject.model.isAltered(32); * } * */ //drawBevelHandle(parametricObject, "Bevel Radius Top", gener.bevelTop, "Taper", gener.taper, .06f); Handles.matrix = prevHM; Handles.color = prevColor; } }