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 void OnEnable() { ArchimatixEngine.establishPaths(); AXEditorUtilities.loadNodeIcons(); infoIconTexture = (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/GeneralIcons/zz-AXMenuIcons-InfoIcon.png", typeof(Texture2D)); }
// INSTANCE public static AXParametricObject instancePO(AXParametricObject po) { // make an instance AXParametricObject src_po = po; if (po.is2D()) { AXParameter output_p = po.generator.P_Output; if (output_p == null && po.generator is ShapeMerger) { ShapeMerger gener = (ShapeMerger)po.generator; output_p = gener.S_InputShape.getSelectedOutputParameter(); } if (output_p != null) { AXParametricObject instance_po = AXEditorUtilities.addNodeToCurrentModel("Instance2D", true, po); instance_po.getParameter("Input Shape").makeDependentOn(output_p); return(instance_po); } } else { if (src_po.generator is IReplica) { // get next PO from downstream AXParameter in_p = po.getParameter("Input Mesh"); if (in_p.DependsOn != null) { src_po = in_p.DependsOn.parametricObject; } } AXParameter out_p = src_po.getParameter("Output Mesh", "Output"); if (out_p != null) { AXParametricObject instance_po = AXEditorUtilities.addNodeToCurrentModel("Instance", true, src_po); instance_po.getParameter("Input Mesh").makeDependentOn(out_p); return(instance_po); } } return(null); }
public static void assertIntFieldKeyCodeValidity(string controlName) { if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode != KeyCode.None && !AXEditorUtilities.isValidNumericFieldKeyCode(Event.current.keyCode) && GUI.GetNameOfFocusedControl() == controlName) { clearFocus(); //GUI.FocusControl("dummy_label"); } } }
// REPLICATE public static void replicatePO(AXParametricObject po) { // make an instance AXParametricObject src_po = po; if (src_po.generator is IReplica) { // get next PO from downstream AXParameter in_p = po.getParameter("Input Mesh"); if (in_p.DependsOn != null) { src_po = in_p.DependsOn.parametricObject; } } AXParameter out_p = src_po.getParameter("Output Mesh"); if (out_p != null) { AXEditorUtilities.addNodeToCurrentModel("Replicant").getParameter("Input Mesh").makeDependentOn(out_p); } }
public static AXModel getOrMakeSelectedModel() { AXModel model; AXModel[] axModels = GameObject.FindObjectsOfType(typeof(AXModel)) as AXModel[]; //Log("** getOrMakeSelecteModel::" + axModels.Length); if (axModels != null) { if (axModels.Length == 1) { return(axModels[0]); } else if (axModels.Length > 1) { if (Selection.activeGameObject != null) { model = Selection.activeGameObject.GetComponent <AXModel>(); if (model != null) { return(model); } } else if (ArchimatixEngine.currentModel != null) { return(ArchimatixEngine.currentModel); } return(axModels[axModels.Length - 1]); } } GameObject axgo = AXEditorUtilities.createNewModel(); return(axgo.GetComponent <AXModel>()); }
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 void doPO(AXParametricObject po) { GUIStyle labelstyle = GUI.skin.GetStyle("Label"); //int fontSize = labelstyle.fontSize; labelstyle.fontSize = 20; GUILayout.BeginHorizontal(); GUILayout.Space(40); Rect rect = GUILayoutUtility.GetLastRect(); // NAME GUILayout.Label(po.Name); labelstyle.fontSize = 12; GUILayout.EndHorizontal(); if (po.is2D() && po.generator.hasOutputsReady()) { AXParameter output_p = po.generator.getPreferredOutputParameter(); GUIDrawing.DrawPathsFit(output_p, new Vector2(32, rect.y + 10), 32); } else if (ArchimatixEngine.nodeIcons != null && ArchimatixEngine.nodeIcons.ContainsKey(po.Type)) { GUI.DrawTexture(new Rect(16, rect.y - 5, 32, 32), ArchimatixEngine.nodeIcons[po.Type], ScaleMode.ScaleToFit, true, 1.0F); } if (showTitle(po)) { GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = 0; po.isActive = EditorGUILayout.Toggle(po.isActive, GUILayout.MaxWidth(20)); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "isActive value change for " + po.Name); po.model.autobuild(); po.generator.adjustWorldMatrices(); } EditorGUIUtility.labelWidth = 0; po.Name = GUILayout.TextField(po.Name); if (po.is3D()) { EditorGUIUtility.labelWidth = 35; 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... po.model.autobuild(); /* * int option = EditorUtility.DisplayDialogComplex("Change Static Flags?", * "Do you want to disable the Lightmap Static flag for all the child objects as well? ", * * "No, only this ParametricObject", * "Yes, change children", * "Cancel"); * * * switch( option ) * { * // Save Scene * case 0: * Debug.Log("ONLY"); * break; * * // Save and Quit. * * // SAVE THIS MASK FOR CHILDREN AS WELL. * case 1: * Debug.Log("CHILDREN"); * break; * * case 2: * Debug.Log("CANCEL"); * break; * * * default: * Debug.LogError( "Unrecognized option." ); * break; * } */ } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Select")) { po.model.selectAndPanToPO(po); } GUILayout.EndHorizontal(); } if (po.is3D()) { EditorGUIUtility.labelWidth = 35; GUILayout.BeginHorizontal(); // TAGS EditorGUI.BeginChangeCheck(); po.tag = EditorGUILayout.TagField("Tag:", po.tag); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "Tag value change for " + po.Name); } // 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; } GUILayout.EndHorizontal(); bool hasMeshRenderer = !po.noMeshRenderer; EditorGUI.BeginChangeCheck(); hasMeshRenderer = EditorGUILayout.ToggleLeft("Mesh Renderer", hasMeshRenderer); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "hasMeshRenderer"); po.noMeshRenderer = !hasMeshRenderer; } } 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(); } } AXParameter p; //EditorGUIUtility.labelWidth = 200;//EditorGUIUtility.currentViewWidth-16; if (po.geometryControls != null && po.geometryControls.children != null) { for (int i = 0; i < po.geometryControls.children.Count; i++) { p = po.geometryControls.children[i] as AXParameter; EditorGUIUtility.labelWidth = 150; // PARAMETERS switch (p.Type) { // ANIMATION_CURVE case AXParameter.DataType.AnimationCurve: EditorGUI.BeginChangeCheck(); EditorGUILayout.CurveField(p.animationCurve); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "ModifierCurve"); p.parametricObject.model.isAltered(28); } break; // FLOAT case AXParameter.DataType.Float: AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_" + p.Name); GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_" + p.Name); p.FloatVal = EditorGUILayout.FloatField(p.Name, p.FloatVal); if (EditorGUI.EndChangeCheck()) { //Debug.Log(p.FloatVal); Undo.RegisterCompleteObjectUndo(po.model, "value change for " + p.Name); p.parametricObject.initiateRipple_setFloatValueFromGUIChange(p.Name, p.FloatVal); p.parametricObject.model.isAltered(27); p.parametricObject.generator.adjustWorldMatrices(); } // 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; // INT case AXParameter.DataType.Int: GUILayout.BeginHorizontal(); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("IntField_" + p.Name); p.intval = EditorGUILayout.IntField(p.Name, p.intval); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "value change for " + p.Name); p.parametricObject.initiateRipple_setFloatValueFromGUIChange(p.Name, p.intval); p.parametricObject.model.isAltered(28); p.parametricObject.generator.adjustWorldMatrices(); } // 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; // 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(po.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(); } GUILayout.FlexibleSpace(); // 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(); } } break; } } //if (p.PType != AXParameter.ParameterType.None && p.PType != AXParameter.ParameterType.GeometryControl) // continue; } } // PROTOTYPE if (po.is3D()) { po.displayPrototypes = EditorGUILayout.Foldout(po.displayPrototypes, "Prototypes"); 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); } GUILayout.Space(30); }
public static int OnGUI_Spline(Rect pRect, AXNodeGraphEditorWindow editor, AXParameter p) { float cur_x = ArchimatixUtils.cur_x; //float box_w = ArchimatixUtils.paletteRect.width - cur_x - 3*ArchimatixUtils.indent; float box_w = pRect.width - cur_x - 1 * ArchimatixUtils.indent; int cur_y = (int)pRect.y; int lineHgt = (int)pRect.height; int gap = 5; int margin = 24; float wid = pRect.width - margin; Color shapeColor = editor.getDataColor(AXParameter.DataType.Spline); Color oldBackgroundColor = GUI.backgroundColor; Color dataColor = editor.getDataColor(p.Type); GUI.backgroundColor = dataColor; // INPUT if (editor.OutputParameterBeingDragged != null && editor.OutputParameterBeingDragged.Type != AXParameter.DataType.Spline) { GUI.enabled = false; } if (p.PType != AXParameter.ParameterType.Output) { if (GUI.Button(new Rect(-3, cur_y, ArchimatixEngine.buttonSize, ArchimatixEngine.buttonSize), "")) { if (editor.OutputParameterBeingDragged != null && editor.OutputParameterBeingDragged.Type != p.Type) { editor.OutputParameterBeingDragged = null; } else { editor.inputSocketClicked(p); } } } GUI.enabled = true; // OUTPUT if (editor.InputParameterBeingDragged == null || editor.InputParameterBeingDragged.Type == AXParameter.DataType.Spline) { if (GUI.Button(new Rect(pRect.width + 6, cur_y, ArchimatixEngine.buttonSize, ArchimatixEngine.buttonSize), "")) { if (editor.OutputParameterBeingDragged != null && editor.OutputParameterBeingDragged.Type != p.Type) { editor.OutputParameterBeingDragged = null; } else { editor.outputSocketClicked(p); } } } // LABEL Rect boxRect = new Rect(cur_x + ArchimatixUtils.indent + 3, cur_y, box_w, pRect.height); Rect lRect = boxRect; lRect.x += 3; lRect.width -= 10; GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; if (p.PType == AXParameter.ParameterType.Output) { labelstyle.alignment = TextAnchor.MiddleRight; labelstyle.fixedWidth = lRect.width - 13; } GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); //Debug.Log(p.Name + " - " + p.ParentNode+ " - " + p.ParentNode.Name); string label = p.Name; if (p.ParentNode != null && p.ParentNode is AXShape) { if (p.DependsOn != null) { if (p.DependsOn.Parent != null) { label = p.DependsOn.Parent.Name; } } } GUI.Label(lRect, label); // SOLID/VOID TOGGLE if (p.PType == AXParameter.ParameterType.Input && p.ParentNode != null && (p.ParentNode is AXShape)) { // Texture2D solidVoidIconTexture = (Texture2D) AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath+"/ui/GeneralIcons/"+iconname, typeof(Texture2D)); Texture2D solidVoidIconTexture = (p.polyType == PolyType.ptSubject) ? editor.solidIconTexture : editor.voidIconTexture; Rect svRect = new Rect(boxRect.x + boxRect.width - lineHgt, cur_y, lineHgt, lineHgt); if (GUI.Button(svRect, new GUIContent(solidVoidIconTexture, "Solid/Void"), GUIStyle.none)) //if(GUI.Button ( bRect, solidVoidIconTexture, GUIStyle.none)) { p.polyType = (p.polyType == PolyType.ptSubject) ? PolyType.ptClip : PolyType.ptSubject; p.parametricObject.model.autobuild(); } GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip); } // OPEN/CLOSED TOGGLE else { Texture2D solidOpenClosedTexture = (p.shapeState == ShapeState.Open) ? editor.shapeOpenIconTexture : editor.shapeClosedIconTexture; Rect svRect = new Rect(boxRect.x + boxRect.width - lineHgt - 2, cur_y, lineHgt + 2, lineHgt + 2); if (GUI.Button(svRect, new GUIContent(solidOpenClosedTexture, "Open/Closed"), GUIStyle.none)) //if(GUI.Button ( bRect, solidVoidIconTexture, GUIStyle.none)) { p.shapeState = (p.shapeState == ShapeState.Open) ? ShapeState.Closed : ShapeState.Open; p.parametricObject.model.autobuild(); } GUI.Label(new Rect(10, 40, 100, 40), GUI.tooltip); } // FOLDOUT (isOpen) GUI.backgroundColor = new Color(1, 1, 1, 1f); p.isOpen = EditorGUI.Foldout(new Rect(cur_x, cur_y, 15, lineHgt), p.isOpen, ""); GUI.backgroundColor = shapeColor; cur_y += lineHgt + gap; Rect tRect = pRect; tRect.x = 30; tRect.width = pRect.width - 20; if (p.isOpen) { ArchimatixUtils.cur_x += ArchimatixUtils.indent; lineHgt = ArchimatixUtils.lineHgtSmall; p.drawClosed = false; string[] options; tRect.x += 2; tRect.y = cur_y; tRect.width -= 11; tRect.height = 16; Rect cntlRect = tRect; // new Rect(x0, cur_y, wid, 16); cntlRect.height = 16; // EXPOSE AS RUNTIME Interface ------------ //EditorGUIUtility.labelWidth = wid-36; cntlRect = new Rect(tRect.x, cur_y, wid, 16); EditorGUI.BeginChangeCheck(); p.exposeAsInterface = EditorGUI.Toggle(cntlRect, "Runtime", 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; // BREAK MINMAXSLIDER tRect.y = cur_y; GUI.Label(tRect, "Break Geom|Norms"); cur_y += lineHgt; GUI.backgroundColor = Color.white; tRect.y = cur_y; EditorGUI.BeginChangeCheck(); #if UNITY_5_5_OR_NEWER EditorGUI.MinMaxSlider( tRect, GUIContent.none, ref p.breakGeom, ref p.breakNorm, 0, 100); #else EditorGUI.MinMaxSlider( GUIContent.none, tRect, ref p.breakGeom, ref p.breakNorm, 0, 100); #endif if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Max Min Slider"); p.parametricObject.model.isAltered(1); } cur_y += lineHgt + gap; cntlRect.y = cur_y; // REVERSE EditorGUI.BeginChangeCheck(); p.reverse = GUI.Toggle(cntlRect, p.reverse, "Reverse"); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Reverse"); p.parametricObject.model.autobuild(); } cur_y += lineHgt + gap; cntlRect.y = cur_y; // SYMMETRY EditorGUI.BeginChangeCheck(); p.symmetry = GUI.Toggle(cntlRect, p.symmetry, "Symetry"); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Symetry"); p.parametricObject.model.autobuild(); } cur_y += lineHgt + gap; cntlRect.y = cur_y; // SYMMETRY SEPERATION if (p.symmetry) { EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth = .5f * wid; GUI.SetNextControlName("FloatField_SymSeperation_Text_" + p.Guid + "_"); p.symSeperation = EditorGUI.FloatField(cntlRect, "Seperation", p.symSeperation); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "SymetrySeperation"); p.parametricObject.model.autobuild(); } cur_y += lineHgt + gap; cntlRect.y = cur_y; } // FLIP_X EditorGUI.BeginChangeCheck(); p.flipX = GUI.Toggle(cntlRect, p.flipX, "FlipX"); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Flip X"); p.parametricObject.model.autobuild(); p.parametricObject.generator.adjustWorldMatrices(); } cur_y += lineHgt + gap; tRect.y = cur_y; tRect.height = 16; // SHAPE_STATE options = ArchimatixUtils.getMenuOptions("ShapeState"); EditorGUIUtility.labelWidth = .5f * wid; //-50; EditorGUI.BeginChangeCheck(); p.shapeState = (ShapeState)EditorGUI.Popup( tRect, "ShapeState", (int)p.shapeState, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.parametricObject.model, "Shape State"); p.parametricObject.model.autobuild(); } cur_y += lineHgt + gap; cntlRect.y = cur_y; cntlRect.height = ArchimatixUtils.lineHgtSmall; // THICKNESS AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_Thickness"); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Thickness_Text_" + p.Guid + "_"); p.thickness = EditorGUI.FloatField(cntlRect, "Thickness", p.thickness); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for Thickness"); p.thickness = Mathf.Max(p.thickness, 0); p.parametricObject.model.isAltered(2); } cur_y += ArchimatixUtils.lineHgtSmall + gap; if (p.shapeState == ShapeState.Closed) { cntlRect.y = cur_y; cntlRect.height = ArchimatixUtils.lineHgtSmall; // ROUNDNESS AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_Roundness"); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Roundness_Text_" + p.Guid + "_"); p.roundness = EditorGUI.FloatField(cntlRect, "Roundness", p.roundness); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for Roundness"); p.parametricObject.model.isAltered(3); } cur_y += ArchimatixUtils.lineHgtSmall + gap; cntlRect.y = cur_y; cntlRect.height = ArchimatixUtils.lineHgtSmall; // OFFSET AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_Offset"); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Offset_Text_" + p.Guid + "_"); p.offset = EditorGUI.FloatField(cntlRect, "Offset", p.offset); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for Offset"); p.parametricObject.model.isAltered(3); } cur_y += ArchimatixUtils.lineHgtSmall + gap; } if (p.thickness > 0) { if (p.shapeState == ShapeState.Closed) { // CLOSED if (p.thickness > 0) { p.endType = AXClipperLib.EndType.etClosedLine; } else { p.endType = AXClipperLib.EndType.etClosedPolygon; } } else { // OPEN switch (p.openEndType) { case AXParameter.OpenEndType.Butt: p.endType = AXClipperLib.EndType.etOpenButt; break; case AXParameter.OpenEndType.Square: p.endType = AXClipperLib.EndType.etOpenSquare; break; case AXParameter.OpenEndType.Round: p.endType = AXClipperLib.EndType.etOpenRound; break; default: p.endType = AXClipperLib.EndType.etOpenSquare; break; } } } if (p.shapeState == ShapeState.Closed) { p.drawClosed = true; } if ((p.thickness > 0) || (p.roundness != 0) || (p.offset != 0)) { p.drawClosed = true; tRect.y = cur_y; options = ArchimatixUtils.getMenuOptions("JoinType"); EditorGUIUtility.labelWidth = .5f * wid; //-50; EditorGUI.BeginChangeCheck(); p.joinType = (AXClipperLib.JoinType)EditorGUI.Popup( tRect, "JoinType", (int)p.joinType, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for JoinType"); p.parametricObject.model.autobuild(); } cur_y += lineHgt + gap; if (p.joinType == AXClipperLib.JoinType.jtRound || p.endType == AXClipperLib.EndType.etOpenRound) { tRect.y = cur_y; AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_smoothness"); if (float.IsNaN(p.arcTolerance)) { p.arcTolerance = 50; } if (p.arcTolerance < .25f) { p.arcTolerance = .25f; } float tmp_arcTol = p.arcTolerance; float smoothness = (float)(120 / (p.arcTolerance * p.arcTolerance)); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_smoothness_Text_" + p.Guid + "_"); smoothness = EditorGUI.FloatField(tRect, "smoothness", smoothness); if (EditorGUI.EndChangeCheck()) { smoothness = Mathf.Clamp(smoothness, .048f, 2.0f); float smoothLOD = ((smoothness - .048f) * p.parametricObject.model.segmentReductionFactor) + .048f; p.arcTolerance = (float)(Math.Sqrt(120 / smoothLOD)); if (p.arcTolerance != tmp_arcTol && p.Parent.model.readyToRegisterUndo) { //Debug.Log ("REGISTER UNDO"); float newval = p.arcTolerance; p.arcTolerance = tmp_arcTol; Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); p.arcTolerance = newval; p.Parent.model.readyToRegisterUndo = false; } if (p.arcTolerance < .25f) { p.arcTolerance = .25f; } if (p.arcTolerance > 50) { p.arcTolerance = 50; } if (float.IsNaN(p.arcTolerance)) { p.arcTolerance = 50; } p.parametricObject.model.isAltered(4); } cur_y += lineHgt + gap; } } if (p.shapeState == ShapeState.Open && p.thickness > 0) { // OPEN_END_TYPE options = ArchimatixUtils.getMenuOptions("OpenEndType"); EditorGUIUtility.labelWidth = .5f * wid; //-50; tRect.y = cur_y; EditorGUI.BeginChangeCheck(); p.openEndType = (AXParameter.OpenEndType)EditorGUI.Popup( tRect, "EndType", (int)p.openEndType, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for EndType"); } cur_y += lineHgt + gap; } cur_y += lineHgt / 2; // SUBDIVISION cntlRect.y = cur_y; EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Subdivision_Text_" + p.Guid + "_"); p.subdivision = (float)EditorGUI.IntField(cntlRect, "Subdivision", (int)p.subdivision); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for Subdivision"); if (p.subdivision < 0) { p.subdivision = 0; } p.parametricObject.model.isAltered(3); } ArchimatixUtils.cur_x -= ArchimatixUtils.indent; cur_y += 2 * lineHgt; } GUI.backgroundColor = oldBackgroundColor; return(cur_y); }
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; }
// INDIVIDUAL LIBRARY ITEM public static void LibraryItemEdit_OnGUI(LibraryItem li) { // CLICKABLE THUMBNAIL EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); float rightMargin = 300; if (GUILayout.Button(li.icon, GUILayout.Width(thumbnailSize), GUILayout.Height(thumbnailSize))) { if (Event.current.shift) { //Make a new Model For Sure AXEditorUtilities.createNewModel(); } AX.Library.instantiateParametricObject(li.readIntoLibraryFromRelativeAXOBJPath); } EditorGUILayout.BeginVertical(); // NAME EditorGUILayout.BeginHorizontal(); GUILayout.Label("Name", LibraryEditorWindow.richRightLabelStyle); if (LibraryEditorWindow.editingLibraryItem != li) { GUILayout.Label(li.Name, LibraryEditorWindow.nameLabelStyle); } else { GUI.SetNextControlName("LibraryItemEdit_Text_" + li.guid + "_name"); li.Name = GUILayout.TextField(li.Name, LibraryEditorWindow.textfieldStyle, new GUILayoutOption[] { GUILayout.Width(LibraryEditorWindow.rect.width - rightMargin), GUILayout.MinWidth(200) }); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // AUTHOR EditorGUILayout.BeginHorizontal(); GUILayout.Label("Author", LibraryEditorWindow.richRightLabelStyle); if (string.IsNullOrEmpty(li.author)) { li.author = ""; } if (LibraryEditorWindow.editingLibraryItem != li) { GUILayout.Label(li.author); } else { GUI.SetNextControlName("LibraryItemEdit_Text_" + li.guid + "_author"); li.author = GUILayout.TextField(li.author, new GUILayoutOption[] { GUILayout.Width(LibraryEditorWindow.rect.width - rightMargin), GUILayout.MinWidth(200) }); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // DESCRIPTION EditorGUILayout.BeginHorizontal(); GUILayout.Label("Description", LibraryEditorWindow.richRightLabelStyle); if (string.IsNullOrEmpty(li.description)) { li.description = ""; } if (LibraryEditorWindow.editingLibraryItem != li) { GUILayout.Label(li.description, LibraryEditorWindow.descripLabelStyle, new GUILayoutOption[] { GUILayout.Height(50), GUILayout.Width(LibraryEditorWindow.rect.width - rightMargin), GUILayout.MinWidth(200) }); } else { GUI.SetNextControlName("LibraryItemEdit_Text_" + li.guid + "_description"); li.description = GUILayout.TextArea(li.description, LibraryEditorWindow.textareaStyle, new GUILayoutOption[] { GUILayout.Width(LibraryEditorWindow.rect.width - rightMargin), GUILayout.MinWidth(200), GUILayout.Height(50) }); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // TAGS EditorGUILayout.BeginHorizontal(); GUILayout.Label("Tags", LibraryEditorWindow.richRightLabelStyle); if (string.IsNullOrEmpty(li.tags)) { li.tags = ""; } if (LibraryEditorWindow.editingLibraryItem != li) { GUILayout.Label(li.tags); } else { GUI.SetNextControlName("LibraryItemEdit_Text_" + li.guid + "_tags"); li.tags = GUILayout.TextField(li.tags, new GUILayoutOption[] { GUILayout.Width(LibraryEditorWindow.rect.width - rightMargin), GUILayout.MinWidth(200) }); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // DOCUMENTATION_URL EditorGUILayout.BeginHorizontal(); GUILayout.Label("Documentation", LibraryEditorWindow.richRightLabelStyle); if (string.IsNullOrEmpty(li.documentationURL)) { li.documentationURL = ""; } if (LibraryEditorWindow.editingLibraryItem != li) { GUILayout.Label(li.documentationURL); } else { GUI.SetNextControlName("LibraryItemEdit_Text_" + li.guid + "_documentationURL"); li.documentationURL = GUILayout.TextField(li.documentationURL, new GUILayoutOption[] { GUILayout.Width(LibraryEditorWindow.rect.width - rightMargin) }); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); // VISIBLE IN SIDE_BAR EditorGUILayout.BeginHorizontal(); GUILayout.Label("In Sidebar Menu", LibraryEditorWindow.richRightLabelStyle); EditorGUI.BeginChangeCheck(); li.includeInSidebarMenu = EditorGUILayout.Toggle("", li.includeInSidebarMenu); if (EditorGUI.EndChangeCheck()) { ArchimatixEngine.library.saveLibraryMetadata(); li.saveToFile(); } EditorGUILayout.EndHorizontal(); // FOOTER MENU EditorGUILayout.BeginHorizontal(); if (LibraryEditorWindow.editingLibraryItem != li) { GUILayout.Label("", LibraryEditorWindow.richRightLabelStyle); // EDIT if (GUILayout.Button("Edit")) { li.cacheSelf(); LibraryEditorWindow.editingLibraryItem = li; } } else { // DELETE_ITEM GUILayout.Label("", LibraryEditorWindow.richRightLabelStyle, new GUILayoutOption[] { GUILayout.MaxWidth(16) }); if (GUILayout.Button("Delete Item")) { Library.removeLibraryItem(li); } EditorGUILayout.Space(); // CANCEL if (GUILayout.Button("Cancel")) { li.revertFromCache(); LibraryEditorWindow.editingLibraryItem = null; } EditorGUILayout.Space(); // REVERT if (GUILayout.Button("Revert")) { li.revertFromCache(); } EditorGUILayout.Space(); // SAVE if (GUILayout.Button("Save")) { li.saveToFile(); li.cacheSelf(); LibraryEditorWindow.editingLibraryItem = null; } EditorGUILayout.Space(); GUILayout.FlexibleSpace(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); }
// 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; }
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; }
public static void contextMenu(AXParameter p, Vector2 position) { AXModel model = p.parametricObject.model; GenericMenu menu = new GenericMenu(); //parametricObject.generator.addContextMenuItems(menu); menu.AddSeparator("Organizers ..."); menu.AddItem(new GUIContent("Grouper"), false, () => { AXParametricObject npo = AXEditorUtilities.addNodeToCurrentModel("Grouper"); AXParameter new_p = npo.addInputMesh(); new_p.makeDependentOn(p); model.isAltered(21); }); menu.AddSeparator(" "); menu.AddSeparator("Repeaters ..."); menu.AddItem(new GUIContent("Instance"), false, () => { AXEditorUtilities.addNodeToCurrentModel("Instance").getParameter("Input Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("Replicant"), false, () => { AXEditorUtilities.addNodeToCurrentModel("Replicant").getParameter("Input Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("PairRepeater"), false, () => { AXEditorUtilities.addNodeToCurrentModel("PairRepeater").getPreferredInputParameter().makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("RadialRepeater"), false, () => { AXEditorUtilities.addNodeToCurrentModel("RadialRepeater").getPreferredInputParameter().makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("FloorRepeater (Node)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("FloorRepeater").getParameter("Node Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("FloorRepeater (Node)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("FloorRepeater").getParameter("Story Mesh").makeDependentOn(p); model.autobuild(); }); // GRID_REPEATER menu.AddItem(new GUIContent("GridRepeater (Node)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("GridRepeater").getParameter("Node Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("GridRepeater (Cell)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("GridRepeater").getParameter("Cell Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("GridRepeater (Span)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("GridRepeater").getParameter("Bay Span").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("ShapeRepeater (Node Mesh)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("ShapeRepeater").getParameter("Node Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("ShapeRepeater (Bay Span Mesh)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("ShapeRepeater").getParameter("Bay Span Mesh").makeDependentOn(p); model.autobuild(); }); menu.AddItem(new GUIContent("ShapeRepeater (Corner Mesh)"), false, () => { AXEditorUtilities.addNodeToCurrentModel("ShapeRepeater").getParameter("Corner Mesh").makeDependentOn(p); model.autobuild(); }); menu.ShowAsContext(); }
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 void OnGUI(Rect position) { int displayedCount = 0; for (int i = 0; i < ArchimatixEngine.library.filteredResults.Count; i++) { LibraryItem li = ArchimatixEngine.library.filteredResults[i]; if (LibraryEditorWindow.showClass == 1 || (LibraryEditorWindow.showClass == 2 && li.is2D) || (LibraryEditorWindow.showClass == 3 && !li.is2D)) { displayedCount++; } } if (Event.current.type == EventType.Layout) { columnCount = (int)Math.Floor(position.width / (thumbnailSize)); if (columnCount == 0) { columnCount = 1; } rowCount = displayedCount / columnCount; rowCount++; cellCount = rowCount * columnCount; } // Grid int cursor = 0; EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); for (int i = 0; i < ArchimatixEngine.library.filteredResults.Count; i++) { if (i >= ArchimatixEngine.library.filteredResults.Count) { break; } LibraryItem li = ArchimatixEngine.library.filteredResults[i]; if (LibraryEditorWindow.showClass == 1 || (LibraryEditorWindow.showClass == 2 && li.is2D) || (LibraryEditorWindow.showClass == 3 && !li.is2D)) { if (columnCount > 0 && cursor % columnCount == 0 && cursor > 0) { GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); } // THE BIG CLICK if (GUILayout.Button(li.icon, GUILayout.Width(thumbnailSize), GUILayout.Height(thumbnailSize))) { if (Event.current.shift) { //Make a new Model For Sure AXEditorUtilities.createNewModel(); AX.Library.instantiateParametricObject(li.readIntoLibraryFromRelativeAXOBJPath); } else { AX.Library.instantiateParametricObject(li.readIntoLibraryFromRelativeAXOBJPath); } } cursor++; } } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); }
public static int GeometryControlsOnGUI(int cur_y, AXNodeGraphEditorWindow editor, AXParametricObject po) { int gap = ArchimatixUtils.gap; int lineHgt = ArchimatixUtils.lineHgt; float x1 = 10; float x2 = 20; float winMargin = ArchimatixUtils.indent; float innerWidth = po.rect.width - 2 * winMargin; AXParameter p = null; // Geometry (and other) controllers if (po.geometryControls != null && po.geometryControls.children != null) { for (int i = 0; i < po.geometryControls.children.Count; i++) { p = po.geometryControls.children[i] as AXParameter; if (p.PType != AXParameter.ParameterType.None && p.PType != AXParameter.ParameterType.GeometryControl) { continue; } // these points are world, not relative to the this GUIWindow p.inputPoint = new Vector2(po.rect.x, po.rect.y + cur_y + lineHgt / 2); p.outputPoint = new Vector2(po.rect.x + po.rect.width, po.rect.y + cur_y + lineHgt / 2); Rect pRect = new Rect(x1, cur_y, innerWidth, lineHgt); try { int hgt = ParameterGUI.OnGUI(pRect, editor, p); cur_y += hgt + gap; } catch { } } } if (po.is2D() || po.generator is Grouper) { if (GUI.Button(new Rect(x2, cur_y, lineHgt * 1.25f, lineHgt), new GUIContent("+", "Create a new Control Parameter"))) { Undo.RegisterCompleteObjectUndo(po.model, "New AXParameter"); AXParameter tmpP = po.addParameter(new AXParameter()); foreach (AXParameter pop in po.parameters) { if (pop != p) { pop.isOpen = false; } } po.model.indexedParameters.Add(tmpP.Guid, tmpP); po.doneEditing(); tmpP.isOpen = true; tmpP.isEditing = false; tmpP.shouldFocus = true; //po.isEditing = true; po.model.cleanGraph(); AXNodeGraphEditorWindow.repaintIfOpen(); } /* * if (GUI.Button (new Rect(x1+editButtonWid+6, cur_y, editButtonWid,lineHgt), "Done" )) * po.doneEditing(); * else * if (GUI.Button (new Rect(x1+editButtonWid+6, cur_y, editButtonWid,lineHgt), "Edit Controls" )) * po.isEditing = true; */ cur_y += lineHgt + gap + 5; } if (po.generator is MaterialTool) { MaterialTool materialTool = (po.generator as MaterialTool); GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; GUI.Label(new Rect(10, cur_y, 250, 32), " Texels/Unit: " + materialTool.texelsPerUnit.ToString("F0")); cur_y += 32; } else if (po.generator is ShapeOffsetter) { ShapeOffsetter offsetter = (po.generator as ShapeOffsetter); AXParameter output_p = offsetter.P_Output; if (output_p == null) { output_p = po.getParameter("Output Shape"); } if (output_p == null) { return(cur_y); } Rect tRect = new Rect(25, cur_y, 150, 16); GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; /* * if (p.PType == AXParameter.ParameterType.Output) * { * labelstyle.alignment = TextAnchor.MiddleRight; * labelstyle.fixedWidth = lRect.width+5; * } */ // JOIN_TYPE: Square, Round, Miter if (offsetter.offset != 0) { string[] options = ArchimatixUtils.getMenuOptions("JoinType"); EditorGUIUtility.labelWidth = 75; //-50; EditorGUI.BeginChangeCheck(); output_p.joinType = (JoinType)EditorGUI.Popup(tRect, "JoinType", (int)output_p.joinType, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(po.model, "value change for JoinType"); po.model.autobuild(); } cur_y += ArchimatixUtils.lineHgt + ArchimatixUtils.gap; } // ARC_TOLERANCE (for JoinType.Round) if (output_p.joinType == AXClipperLib.JoinType.jtRound || output_p.endType == AXClipperLib.EndType.etOpenRound) { tRect.y = cur_y; if (float.IsNaN(output_p.arcTolerance)) { output_p.arcTolerance = 50; } if (output_p.arcTolerance < .25f) { output_p.arcTolerance = .25f; } float smooth = (float)(120 / (output_p.arcTolerance * output_p.arcTolerance)); AXEditorUtilities.assertFloatFieldKeyCodeValidity("shapehandler_Text_smoothness_" + output_p.Guid + "_" + output_p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("shapehandler" + output_p.Name); smooth = EditorGUI.FloatField(tRect, "smoothness", smooth); if (EditorGUI.EndChangeCheck()) { output_p.arcTolerance = (float)(Mathf.Sqrt(120 / smooth)); Undo.RegisterCompleteObjectUndo(po.model, "value change for " + output_p.Name); if (output_p.arcTolerance < .25f) { output_p.arcTolerance = .25f; } if (output_p.arcTolerance > 50) { output_p.arcTolerance = 50; } if (float.IsNaN(output_p.arcTolerance)) { output_p.arcTolerance = 50; } po.model.isAltered(20); } cur_y += ArchimatixUtils.lineHgt + ArchimatixUtils.gap; } } return(cur_y); }
// return the height of this gui area public static void OnGUI(AXParameterAlias pa) { AXParameter p = pa.parameter; //Event e = Event.current; // if (Event.current.type == EventType.KeyUp) // { // if (p != null && ! GUI.GetNameOfFocusedControl().Contains("logicTextArea_") ) // { // p.parametricObject.model.autobuildDelayed(1000); // } // } //Color oldBackgroundColor = GUI.backgroundColor; if (p == null || p.parametricObject == null) { return; } //Color defcolor = GUI.color; GUILayout.BeginHorizontal(); // FOLDOUT GUIStyle toggleStyle = new GUIStyle(EditorStyles.foldout); toggleStyle.fixedWidth = 50; pa.isEditing = EditorGUILayout.Foldout(pa.isEditing, GUIContent.none); //Debug.Log(pa.isEditing); // SLIDER AND NUMBER FIELD GUIStyle textfieldStyle = new GUIStyle(GUI.skin.textField); textfieldStyle.fixedWidth = 150; GUIStyle labelWrap = new GUIStyle(GUI.skin.label); labelWrap.stretchWidth = true; labelWrap.wordWrap = true; labelWrap.fontSize = 9; labelWrap.fixedWidth = 150; if (pa.isEditing) { GUILayout.BeginVertical(); pa.alias = GUILayout.TextField(pa.alias, textfieldStyle); GUILayout.Label("You can edit the alias without altering the source parameter.", labelWrap); GUILayout.Label("Actual: ", labelWrap); if (GUILayout.Button(pa.parameter.parametricObject.Name + "." + pa.parameter.Name)) { pa.parameter.parametricObject.model.selectPO(pa.parameter.parametricObject); pa.parameter.ParentNode.isOpen = true; float framePadding = 200; Rect allRect = AXUtilities.getBoundaryRectFromPOs(pa.parameter.parametricObject.model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } GUILayout.Space(15); GUILayout.EndVertical(); } else { string nameString = pa.alias; switch (p.Type) { case AXParameter.DataType.Float: // FLOAT SLIDER if (p.PType != AXParameter.ParameterType.DerivedValue) { // VALIDATE INPUT - IF INVALID >> LOSE FOCUS AXEditorUtilities.assertFloatFieldKeyCodeValidity("FloatField_Text_" + p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("FloatField_Text_" + p.Guid + "_" + p.Name); p.val = EditorGUILayout.FloatField(nameString, 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(); } } else { GUILayout.Label(p.Name); GUILayout.Label("" + p.val); } 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 = EditorGUILayout.IntField(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(); } break; } case AXParameter.DataType.Bool: { EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("BoolToggle_" + p.Guid + "_" + p.Name); p.boolval = EditorGUILayout.Toggle(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.generator.adjustWorldMatrices(); } break; } case AXParameter.DataType.String: if (p.Parent.isEditing) { GUILayout.Label(nameString); } else { GUILayout.Label(nameString); } break; case AXParameter.DataType.Option: { // OPTION POPUP string[] options = ArchimatixUtils.getMenuOptions(p.Name); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("OptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUILayout.Popup( nameString, 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(); EditorGUI.BeginChangeCheck(); GUI.SetNextControlName("CustomOptionPopup_" + p.Guid + "_" + p.Name); p.intval = EditorGUILayout.Popup( nameString, p.intval, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(p.Parent.model, "value change for " + p.Name); if (p.PType == AXParameter.ParameterType.PositionControl) { p.parametricObject.generator.adjustWorldMatrices(); } p.parametricObject.model.autobuild(); } break; } case AXParameter.DataType.Spline: { GUILayout.Label(pa.alias); break; } } // END switch (Type) } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); //GUI.backgroundColor = oldBackgroundColor; //GUI.color = defcolor; }
// 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); 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.PType == AXParameter.ParameterType.Input) { 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)) { 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"; string[] dataType_options = dataType_menu.Split('|'); EditorGUI.BeginChangeCheck(); int typeOption = (int)p.Type; if (typeOption == (int)AXParameter.DataType.String) { typeOption = 3; } 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)) { 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); } GUILayout.EndArea(); 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(); } } 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(); } 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.generator.adjustWorldMatrices(); } 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.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 static int display(Rect pRect, AXNodeGraphEditorWindow editor, AXParameter p) { //Debug.Log("ParameterTextureGUI.DISPLAY "+p.Name); float cur_x = ArchimatixUtils.cur_x; //float box_w = ArchimatixUtils.paletteRect.width - cur_x - 3*ArchimatixUtils.indent; float box_w = pRect.width - cur_x - 1 * ArchimatixUtils.indent; int cur_y = (int)pRect.y; int lineHgt = (int)pRect.height; int gap = 5; //Color shapeColor = editor.getDataColor (AXParameter.DataType.Spline); Color dataColor = editor.getDataColor(p.Type); Color oldBackgroundColor = GUI.backgroundColor; GUI.backgroundColor = dataColor; // INPUT if (editor.OutputParameterBeingDragged == null || editor.OutputParameterBeingDragged.Type == p.Type) { if (p.PType != AXParameter.ParameterType.Output) { if (GUI.Button(new Rect(-3, cur_y, ArchimatixEngine.buttonSize, ArchimatixEngine.buttonSize), "")) { if (editor.OutputParameterBeingDragged != null && editor.OutputParameterBeingDragged.Type != p.Type) { editor.OutputParameterBeingDragged = null; } else { editor.inputSocketClicked(p); } } } } // OUTPUT if (editor.InputParameterBeingDragged == null || editor.InputParameterBeingDragged.Type == AXParameter.DataType.MaterialTool) { if (GUI.Button(new Rect(pRect.width + 6, cur_y, ArchimatixEngine.buttonSize, ArchimatixEngine.buttonSize), "")) { if (editor.InputParameterBeingDragged != null && editor.InputParameterBeingDragged.Type != p.Type) { editor.InputParameterBeingDragged = null; } else { editor.outputSocketClicked(p); } } } // LABEL BOX Rect boxRect = new Rect(cur_x + ArchimatixUtils.indent, cur_y, box_w, pRect.height); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); // LABEL Rect lRect = boxRect; lRect.x += 3; lRect.width -= 10; GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUI.Box(boxRect, " "); GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; if (p.PType == AXParameter.ParameterType.Output) { labelstyle.alignment = TextAnchor.MiddleRight; labelstyle.fixedWidth = lRect.width + 5; } string label = p.Name; if (p.ParentNode != null && p.ParentNode is AXShape) { if (p.DependsOn != null) { if (p.DependsOn.Parent != null) { label = p.DependsOn.Parent.Name; } } } GUI.Label(lRect, label); // Texture Thumbnail AXParameter src_p = p.DependsOn; AXParametricObject src_po = null; if (src_p != null) { src_po = src_p.parametricObject; } Rect texThumbRect; if (src_po != null) { if (src_po.generator is MaterialTool && src_po.axMat.mat != null && src_po.axMat.mat.mainTexture != null) { texThumbRect = new Rect((boxRect.x + boxRect.width - lineHgt + 1), cur_y + 1, lineHgt - 2, lineHgt - 2); EditorGUI.DrawTextureTransparent(texThumbRect, src_po.axMat.mat.mainTexture, ScaleMode.ScaleToFit, 1.0F); } else { texThumbRect = new Rect((boxRect.x + boxRect.width - lineHgt + 1), cur_y + 1, lineHgt - 2, lineHgt - 2); EditorGUI.DrawTextureTransparent(texThumbRect, ArchimatixEngine.nodeIcons[p.Type.ToString()], ScaleMode.ScaleToFit, 1.0F); } } else if (src_po == null) { if (src_p != null) { texThumbRect = new Rect((boxRect.x + boxRect.width - lineHgt + 1), cur_y + 1, lineHgt - 2, lineHgt - 2); EditorGUI.DrawTextureTransparent(texThumbRect, ArchimatixEngine.nodeIcons[p.Type.ToString()], ScaleMode.ScaleToFit, 1.0F); } else { // NEW TOOL texThumbRect = new Rect((boxRect.x + boxRect.width - lineHgt), cur_y - 1, lineHgt, lineHgt); if (GUI.Button(texThumbRect, ArchimatixEngine.nodeIcons[p.Type.ToString()])) //"+")) { src_po = AXEditorUtilities.addNodeToCurrentModel(p.Type.ToString()); src_po.Name = Regex.Replace(p.Name, @"\s+", ""); // remove spaces src_po.rect.x = p.parametricObject.rect.x - 220; src_po.rect.y = p.parametricObject.rect.y + 50; src_po.rect.height = 500; if (p.parametricObject.model.currentWorkingGroupPO != null) { p.parametricObject.model.currentWorkingGroupPO.addGroupee(src_po); } else { src_po.grouper = null; src_po.grouperKey = null; } //AXNodeGraphEditorWindow.zoomToRectIfOpen(src_po.rect); //src_po.inputControls.isOpen = true; src_po.geometryControls.isOpen = true; src_po.generator.pollInputParmetersAndSetUpLocalReferences(); //Debug.Log("here " + src_po.getParameter("Output")); p.makeDependentOn(src_po.getParameter("Output")); p.parametricObject.model.remapMaterialTools(); p.parametricObject.isAltered = true; p.parametricObject.model.autobuild(); } } } /* * // FOLDOUT (isOpen) * GUI.backgroundColor = new Color(1,1,1,1f); * * EditorGUI.BeginChangeCheck (); * p.isOpen = EditorGUI.Foldout (new Rect (cur_x, cur_y, 55, lineHgt), p.isOpen, ""); * if (EditorGUI.EndChangeCheck ()) * { * if (src_p == null) * { * src_po = AXEditorUtilities.addNodeToCurrentModel(p.Type.ToString(), false); * src_po.Name = Regex.Replace(p.Name, @"\s+", ""); // remove spaces * src_po.rect.x = p.parametricObject.rect.x - 200; * src_po.rect.y = p.parametricObject.rect.y + 50; * src_po.isOpen = false; * p.makeDependentOn(src_po.generator.P_Output); * p.parametricObject.model.autobuild(); * } * } * GUI.backgroundColor = shapeColor; * * if (p.DependsOn == null) * p.isOpen = false; * * cur_y += lineHgt+gap; * * if (p.isOpen) * { * * * * //Archimatix.cur_x += Archimatix.indent; * p.drawClosed = false; * * Rect tRect = pRect; * tRect.x = 20;//30; * tRect.width = pRect.width; * tRect.x += 2; * tRect.width -= 11; * * if (! src_po.isOpen) * { * foreach (AXParameter sp in src_po.getAllParametersOfPType(AXParameter.ParameterType.GeometryControl)) * { * * * * * * tRect.y = cur_y; * Rect cntlRect = tRect; // new Rect(x0, cur_y, wid, 16); * * * int hgt = ParameterGUI.OnGUI(cntlRect, editor, sp); * * cur_y += hgt + gap; * } * } * * * * * * * * * * //Archimatix.cur_x -= Archimatix.indent; * * * * } */ cur_y += lineHgt + gap; GUI.backgroundColor = oldBackgroundColor; return(cur_y); }
public static void display(float imagesize = 64, AXNodeGraphEditorWindow editor = null) { //Debug.Log("imagesise="+imagesize); // called from an OnGUI //imagesize = 64; scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUIStyle.none, GUIStyle.none); EditorGUILayout.BeginVertical(); string[] itemStrings = null; // Select menu item list if (editor.OutputParameterBeingDragged == null) { if (editor.model != null && editor.model.selectedPOs.Count > 1) { //if (editor.model.selectedPOs[0].is2D()) // itemStrings = ArchimatixEngine.nodeStringsFrom2DMultiSelect; //else itemStrings = ArchimatixEngine.nodeStringsFromMultiSelect; } else { itemStrings = ArchimatixEngine.nodeStrings; } } else if (editor.OutputParameterBeingDragged.parametricObject.is2D()) { itemStrings = ArchimatixEngine.nodeStringsFrom2DOutput; } else if (editor.OutputParameterBeingDragged.parametricObject.is3D()) { if (editor.OutputParameterBeingDragged.Type == AXParameter.DataType.Spline) { itemStrings = ArchimatixEngine.nodeStringsFrom2DOutput; } else { itemStrings = ArchimatixEngine.nodeStringsFrom3DOutput; } } else if (editor.OutputParameterBeingDragged.parametricObject.generator is RepeaterTool) { itemStrings = ArchimatixEngine.nodeStringsFromRepeaterTool; } /* * if (Library.last2DItem != null) * { * if (GUILayout.Button(new GUIContent(Library.last2DItem.icon, Library.last2DItem.po.Name), new GUILayoutOption[] {GUILayout.Width(imagesize), GUILayout.Height(imagesize)})) * { * * } * } */ List <string> stringList = null; if (itemStrings != null) { stringList = itemStrings.ToList(); } if (stringList != null) { stringList.AddRange(Archimatix.customNodeNames); } // Build Menu string poName; if (stringList != null) { for (int i = 0; i < stringList.Count; i++) { string nodeName = stringList[i]; Texture2D nodeIcon = null; if (ArchimatixEngine.nodeIcons.ContainsKey(nodeName)) { nodeIcon = ArchimatixEngine.nodeIcons[nodeName]; } else { if (ArchimatixEngine.nodeIcons.ContainsKey("CustomNode")) { nodeIcon = ArchimatixEngine.nodeIcons["CustomNode"]; } else { continue; } } if (nodeIcon != null) { if (GUILayout.Button(new GUIContent(nodeIcon, nodeName), new GUILayoutOption[] { GUILayout.Width(imagesize), GUILayout.Height(imagesize) })) { //if (editor.DraggingOutputParameter != null) //{ AXModel model = AXEditorUtilities.getOrMakeSelectedModel(); Undo.RegisterCompleteObjectUndo(model, "Node Menu Selection"); AXParametricObject mostRecentPO = model.recentlySelectedPO; int index = nodeName.IndexOf("_"); poName = (index > 0) ? nodeName.Substring(0, index) : nodeName; // Support multi-select operation List <AXParametricObject> selectedPOs = new List <AXParametricObject>(); if (model.selectedPOs.Count > 0) { selectedPOs.AddRange(model.selectedPOs); } // ADD NEW PO TO MODEL (only this new po is selected after this) AXParametricObject po = AXEditorUtilities.addNodeToCurrentModel(poName, false); if (po == null || po.generator == null) { return; } float max_x = -AXGeometryTools.Utilities.IntPointPrecision; if (poName == "FreeCurve") { ArchimatixEngine.sceneViewState = ArchimatixEngine.SceneViewState.AddPoint; } // DRAGGING A PARAMETER? THEN RIG'R UP! if (editor.OutputParameterBeingDragged != null) { AXParametricObject draggingPO = editor.OutputParameterBeingDragged.parametricObject; AXParameter new_input_p = null; switch (nodeName) { case "Instance2D": case "ShapeOffsetter": po.getParameter("Input Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); if (po.geometryControls != null) { po.geometryControls.isOpen = true; } break; case "ShapeDistributor": List <AXParameter> deps = new List <AXParameter>(); for (int dd = 0; dd < editor.OutputParameterBeingDragged.Dependents.Count; dd++) { deps.Add(editor.OutputParameterBeingDragged.Dependents[dd]); } for (int dd = 0; dd < deps.Count; dd++) { deps[dd].makeDependentOn(po.getParameter("Output Shape")); } po.getParameter("Input Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); if (po.geometryControls != null) { po.geometryControls.isOpen = true; } break; case "ShapeMerger": po.generator.getInputShape().addInput().makeDependentOn(editor.OutputParameterBeingDragged); if (editor.OutputParameterBeingDragged.axis != Axis.NONE) { po.intValue("Axis", (int)editor.OutputParameterBeingDragged.axis); } else { po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); } break; case "PlanRepeater2D": case "PlanRepeater2D_Corner": po.getParameter("Corner Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "PlanRepeater_Corner": po.getParameter("Corner Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "PairRepeater2D": case "RadialRepeater2D": case "RadialRepeater2D_Node": case "LinearRepeater2D": case "LinearRepeater2D_Node": case "GridRepeater2D": case "GridRepeater2D_Node": po.getParameter("Node Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "RadialRepeater2D_Cell": case "LinearRepeater2D_Cell": case "GridRepeater2D_Cell": po.getParameter("Cell Shape").makeDependentOn(editor.OutputParameterBeingDragged); po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); break; case "Grouper": //po.addInputMesh().makeDependentOn(editor.OutputParameterBeingDragged); po.addGroupee(editor.OutputParameterBeingDragged.parametricObject); break; case "PlanRepeater2D_Plan": case "Polygon_Plan": case "Extrude_Plan": case "PlanSweep_Plan": case "PlanRepeater_Plan": case "PlanDeformer_Plan": // SYNC AXES if (editor.OutputParameterBeingDragged.axis != Axis.NONE) { po.intValue("Axis", (int)editor.OutputParameterBeingDragged.axis); } else { po.intValue("Axis", editor.OutputParameterBeingDragged.parametricObject.intValue("Axis")); } if (nodeName == "Extrude_Plan" && po.intValue("Axis") != (int)Axis.Y) { po.floatValue("Bevel", 0); } // INSERT SHAPE_DISTRIBUTOR? new_input_p = po.getParameter("Plan", "Input Shape"); //if (draggingPO.is2D() && !(draggingPO.generator is ShapeDistributor) && editor.OutputParameterBeingDragged.Dependents != null && editor.OutputParameterBeingDragged.Dependents.Count > 0) // model.insertShapeDistributor(editor.OutputParameterBeingDragged, new_input_p); //else new_input_p.makeDependentOn(editor.OutputParameterBeingDragged); // the output of the new node should match the shapestate of the input if (po.generator.P_Output != null) { po.generator.P_Output.shapeState = new_input_p.shapeState; } AXNodeGraphEditorWindow.repaintIfOpen(); break; case "Lathe_Section": case "PlanSweep_Section": case "PlanRepeater_Section": //po.getParameter("Section").makeDependentOn(editor.OutputParameterBeingDragged); // INSERT SHAPE_DISTRIBUTOR? new_input_p = po.getParameter("Section"); if (draggingPO.is2D() && !(draggingPO.generator is ShapeDistributor) && draggingPO.hasDependents()) { model.insertShapeDistributor(editor.OutputParameterBeingDragged, new_input_p); } else { new_input_p.makeDependentOn(editor.OutputParameterBeingDragged); } // the output of the new node should match the shapestate of the input //if (po.generator.P_Output != null) //Debug.Log(new_input_p.Name+" "+new_input_p.shapeState + " :=: " +editor.OutputParameterBeingDragged.Name + " " + editor.OutputParameterBeingDragged.shapeState); AXNodeGraphEditorWindow.repaintIfOpen(); break; case "NoiseDeformer": case "ShearDeformer": case "TwistDeformer": case "DomicalDeformer": case "TaperDeformer": case "InflateDeformer": case "PlanDeformer": po.getParameter("Input Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; //case "PlanDeformer_Plan": case "PairRepeater": case "StepRepeater": case "RadialStepRepeater": po.getParameter("Node Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater_Node": AXParameter nodeMesh_p = po.getParameter("Node Mesh"); nodeMesh_p.makeDependentOn(editor.OutputParameterBeingDragged); // if the src is very long in x, assume you want to repeat in Z if (editor.OutputParameterBeingDragged.parametricObject.bounds.size.x > (6 * editor.OutputParameterBeingDragged.parametricObject.bounds.size.z)) { po.initiateRipple_setBoolParameterValueByName("zAxis", true); } break; case "LinearRepeater_Cell": case "PlanRepeater_Cell": po.getParameter("Cell Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater_Span": po.getParameter("Bay SpanU").makeDependentOn(editor.OutputParameterBeingDragged); break; case "LinearRepeater": po.getParameter("RepeaterU").makeDependentOn(editor.OutputParameterBeingDragged); break; case "FloorRepeater": po.getParameter("Floor Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "RadialRepeater": case "RadialRepeater_Node": case "GridRepeater_Node": case "PlanRepeater_Node": po.getParameter("Node Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "RadialRepeater_Span": case "GridRepeater_Span": po.getParameter("Bay SpanU", "SpanU Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "GridRepeater_Cell": po.getParameter("Cell Mesh").makeDependentOn(editor.OutputParameterBeingDragged); break; case "ShapeRepeater_Plan": AXEditorUtilities.addNodeToCurrentModel("ShapeRepeater").getParameter("Plan").makeDependentOn(editor.OutputParameterBeingDragged); break; default: AXEditorUtilities.addNodeToCurrentModel(nodeName); break; } if (editor.OutputParameterBeingDragged.parametricObject != null) { mostRecentPO = editor.OutputParameterBeingDragged.parametricObject; //po.rect = editor.OutputParameterBeingDragged.parametricObject.rect; //po.rect.x += 325; } /* * else * { * po.rect.x = (model.focusPointInGraphEditor.x)+100;// + UnityEngine.Random.Range(-100, 300); * po.rect.y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); * } */ } // NO DRAGGING - CONNECT ALL MULTI_SELECTED else if (selectedPOs != null && selectedPOs.Count > 0) { switch (nodeName) { case "ShapeMerger": AXShape shp = po.generator.getInputShape(); for (int j = 0; j < selectedPOs.Count; j++) { AXParametricObject poo = selectedPOs [j]; if (j == 0) { po.intValue("Axis", selectedPOs [j].intValue("Axis")); } max_x = Mathf.Max(max_x, poo.rect.x); if (poo.is2D()) { AXParameter out_p = poo.generator.getPreferredOutputParameter(); if (out_p != null) { shp.addInput().makeDependentOn(out_p); } } } po.rect.x = max_x + 250; break; case "Grouper": //Debug.Log("selectedPOs="+selectedPOs.Count); //if (model.currentWorkingGroupPO != null && ! selectedPOs.Contains(model.currentWorkingGroupPO)) //{ po.addGroupees(selectedPOs); Rect r = AXUtilities.getBoundaryRectFromPOs(selectedPOs); po.rect.x = r.center.x - po.rect.width / 2; po.rect.y = r.center.y - po.rect.height / 2; //} //po.rect.x = max_x+250; break; case "Channeler": //Debug.Log("selectedPOs="+selectedPOs.Count); //if (model.currentWorkingGroupPO != null && ! selectedPOs.Contains(model.currentWorkingGroupPO)) //{ foreach (AXParametricObject selpo in selectedPOs) { AXParameter inputer = po.addInputMesh(); inputer.makeDependentOn(selpo.generator.P_Output); } Rect cr = AXUtilities.getBoundaryRectFromPOs(selectedPOs); po.rect.x = cr.center.x - po.rect.width / 2; po.rect.y = cr.center.y - po.rect.height / 2; //} //po.rect.x = max_x+250; break; } } else { switch (nodeName) { case "ShapeMerger": po.assertInputControls(); //po.generator.getInputShape().addInput(); break; } } editor.OutputParameterBeingDragged = null; model.autobuild(); po.generator.adjustWorldMatrices(); if (mostRecentPO != null) { po.rect = mostRecentPO.rect; po.rect.x += (mostRecentPO.rect.width + 50); } else { po.rect.x = (model.focusPointInGraphEditor.x) + 100; // + UnityEngine.Random.Range(-100, 300); po.rect.y = (model.focusPointInGraphEditor.y - 250) + UnityEngine.Random.Range(-10, 0); } po.rect.height = 700; //AXNodeGraphEditorWindow.zoomToRectIfOpen(po.rect); //model.beginPanningToRect(po.rect); } } } } //GUILayout.Label (GUI.tooltip); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUILayout.EndScrollView(); /* Not sure why I was doing this - it took up a huge amount of CPU! * * * editor.Repaint(); * SceneView sv = SceneView.lastActiveSceneView; * if (sv != null) * sv.Repaint(); * */ }
// 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; } }