public void OnPointerUp(PointerEventData data) { if (model != null) { model.autobuild(); } }
// Use this for initialization protected void InitializeController() { // Assume that this controller is attached to a GameObject // under the AXModel's GameObject. if (model == null && transform.parent != null) { model = transform.parent.gameObject.GetComponent <AXModel>(); } // Build the model to make sure its // starting form reflects all its internal parameters. if (model != null) { // BIND THE EXPOSED RUNTIME PARAMETERS // This way you don't have to do the model lookup with // each seting or getting of the parameter value. InitializeParameterReferences(); // Make sure the model is built with current parameter values. model.autobuild(); } }
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 static int OnGUI(AXHandle han, Rect pRect, AXNodeGraphEditorWindow editor) { int cur_y = (int)pRect.y; int lineHgt = 16; int margin = 24; int wid = (int)pRect.width - margin; int gap = 5; int indent = (int)pRect.x + 16; int indent2 = indent + 12; int indentWid = wid - indent; if (han.Name == null || han.Name == "") { han.Name = "Handle"; } if (han.isEditing) { if (han.expressions == null) { han.expressions = new List <string>(); } GUI.Box(new Rect(pRect.x, cur_y - 4, (pRect.width - 20), ((12 + han.expressions.Count) * lineHgt)), ""); // TITLE GUI.SetNextControlName("HanTitle_Text_" + han.parametricObject.Guid + "_" + han.param); han.Name = GUI.TextField(new Rect(pRect.x + 4, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt), han.Name); cur_y += lineHgt; //if (expressions != null) //GUI.Box (new Rect(pRect.x, cur_y, wid, lineHgt*(8+expressions.Count)), GUIContent.none); // HANDLE_TYPE //EditorGUI.PropertyField( new Rect(indent, cur_y, pRect.width-3*lineHgt-14, lineHgt), hProperty.FindPropertyRelative("m_type"), GUIContent.none); AXModel model = han.parametricObject.model; //string[] options = Archimatix.getMenuOptions(p.Name); cur_y += gap * 2; // HANDLE TYPE string[] options = System.Enum.GetNames(typeof(AXHandle.HandleType)); EditorGUIUtility.labelWidth = wid - 50; EditorGUI.BeginChangeCheck(); han.Type = (AXHandle.HandleType)EditorGUI.Popup( new Rect(indent, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt), "", (int)han.Type, options); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "value change for handle type"); model.autobuild(); } cur_y += lineHgt + gap; GUIStyle labelstyle = GUI.skin.GetStyle("Label"); labelstyle.alignment = TextAnchor.MiddleLeft; // RUNTIME HANDLE: expose in Model interface ------------ Rect cntlRect = new Rect(indent, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt); EditorGUI.BeginChangeCheck(); han.exposeForRuntime = EditorGUI.Toggle(cntlRect, "Runtime", han.exposeForRuntime); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Runtime Handle"); if (han.exposeForRuntime) { //Debug.Log(ArchimatixEngine.RuntimeHandlePrefab_PlanarKnob); //AXHandleRuntimeAlias rtHandleAlias = model.addHandleRuntimeAlias(han); if (ArchimatixEngine.RuntimeHandlePrefab_PlanarKnob != null) { // CREATE A GAME_OBJECT GameObject tmp = GameObject.Instantiate(ArchimatixEngine.RuntimeHandlePrefab_PlanarKnob); //GameObject tmp = GameObject.Instantiate(model.RuntimeHandlePrefab_PlanarKnob); tmp.name = han.Name; Debug.Log("han.Name=" + han.Name); if (tmp != null) { tmp.transform.parent = model.runtimeHandlesGameObjects.transform; AXRuntimeHandleBehavior rtHandleBehavior = tmp.GetComponent <AXRuntimeHandleBehavior>(); rtHandleBehavior.handleGuid = han.Guid; rtHandleBehavior.handle = han; } } } else { model.removeHandleRuntimeAlias(han); AXRuntimeHandleBehavior[] rhbs = model.runtimeHandlesGameObjects.GetComponentsInChildren <AXRuntimeHandleBehavior> (); for (int j = 0; j < rhbs.Length; j++) { if (rhbs[j] != null && rhbs[j].gameObject != null && rhbs[j].handleGuid == han.Guid) { // This GameObject and all its children... if (Application.isPlaying) { GameObject.Destroy(rhbs[j].gameObject); } else { GameObject.DestroyImmediate(rhbs[j].gameObject); } break; } } Resources.UnloadUnusedAssets(); } } cur_y += lineHgt + gap; // POSITION HEADER ------- GUI.Label(new Rect(indent, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt), new GUIContent("Position", "Use a number, parameter name, or a mathematical expressions to define the handle position")); cur_y += lineHgt; // X_POS GUI.Label(new Rect(indent, cur_y, 12, lineHgt), "X"); GUI.SetNextControlName("x_Text_" + han.parametricObject.Guid + "_" + han.param); han.pos_x = EditorGUI.TextField(new Rect(indent2, cur_y, indentWid, lineHgt), han.pos_x); cur_y += lineHgt; // Y_POS GUI.Label(new Rect(indent, cur_y, 12, lineHgt), "Y"); GUI.SetNextControlName("y_Text_" + han.parametricObject.Guid + "_" + han.param); han.pos_y = EditorGUI.TextField(new Rect(indent2, cur_y, indentWid, lineHgt), han.pos_y); cur_y += lineHgt; // Z_POS GUI.Label(new Rect(indent, cur_y, 12, lineHgt), "Z"); GUI.SetNextControlName("z_Text_" + han.parametricObject.Guid + "_" + han.param); han.pos_z = EditorGUI.TextField(new Rect(indent2, cur_y, indentWid, lineHgt), han.pos_z); cur_y += lineHgt + gap; if (han.Type == AXHandle.HandleType.Circle) { // RADIUS GUI.Label(new Rect(indent, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt), new GUIContent("Radius", "Use a number, parameter name, or a mathematical expressions to define the handle radius")); cur_y += lineHgt; GUI.Label(new Rect(indent, cur_y, 12, lineHgt), "R"); han.radius = EditorGUI.TextField(new Rect(indent2, cur_y, indentWid, lineHgt), han.radius); cur_y += lineHgt + gap; // TANGENT Color prevColor = Handles.color; Handles.color = Color.cyan; GUI.Label(new Rect(indent, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt), new GUIContent("Tangent", "Use a number, parameter name, or a mathematical expressions to define the handle tangent")); cur_y += lineHgt; GUI.Label(new Rect(indent, cur_y, 12, lineHgt), "T"); han.tangent = EditorGUI.TextField(new Rect(indent2, cur_y, indentWid, lineHgt), han.tangent); cur_y += lineHgt + gap; /* * // OFFSET ANGLE * GUI.Label(new Rect(indent, cur_y, pRect.width-3*lineHgt-14, lineHgt), new GUIContent("Angle", "Use a number, parameter name, or a mathematical expressions to define the handle angle")); * cur_y += lineHgt; * * GUI.Label(new Rect(indent, cur_y, 12, lineHgt), "Z"); * angle = EditorGUI.TextField(new Rect(indent2, cur_y, indentWid, lineHgt), angle); * cur_y += lineHgt+gap; */ Handles.color = prevColor; } // EXPRESSIONS HEADER ------- GUI.Label(new Rect(indent, cur_y, pRect.width - 3 * lineHgt - 14, lineHgt), new GUIContent("Expressions", "These mathematical expressions interpret the handle's values.")); cur_y += lineHgt; if (han.expressions == null) { han.expressions = new List <string>(); } if (han.expressions.Count == 0) { han.expressions.Add(""); } for (int i = 0; i < han.expressions.Count; i++) { GUI.SetNextControlName("HandleExp_Text_" + han.parametricObject.Guid + "_" + han.param); han.expressions[i] = EditorGUI.TextField(new Rect(indent, cur_y, indentWid, 16), han.expressions[i]); if (GUI.Button(new Rect(pRect.width - lineHgt * 1.5f, cur_y - 1, lineHgt * 1.25f, lineHgt), "-")) { han.expressions.Remove(han.expressions[i]); //p.expressions.RemoveAt(i); } cur_y += lineHgt; } if (GUI.Button(new Rect(pRect.width - lineHgt * 1.5f, cur_y, lineHgt * 1.25f, lineHgt), new GUIContent("+", "Add an expression to this Handle"))) { han.expressions.Add(""); } cur_y += gap * 5; if (GUI.Button(new Rect(pRect.width - 3 * lineHgt - 5, cur_y, 3 * lineHgt, lineHgt), "Done")) { if (han.parametricObject != null) { han.parametricObject.stopEditingAllHandles(); } han.isEditing = false; } cur_y += lineHgt; } else { if (GUI.Button(new Rect(pRect.x, pRect.y, wid - 16, 16), new GUIContent(han.Name, "Click to edit this handle."))) { han.parametricObject.stopEditingAllHandlesExcept(han); han.isEditing = true; } } if (GUI.Button(new Rect(wid + 6, pRect.y, lineHgt, lineHgt), "-")) { //Debug.Log ("REMOVE HANDLE..."); if (han.parametricObject != null) { han.parametricObject.removeHandleFromReplicantsControlsWithName(han.Name); han.parametricObject.handles.Remove(han); } } cur_y += lineHgt; return(cur_y - (int)pRect.y); }
public override void OnInspectorGUI() { //if (Event.current.type != EventType.Layout) // return; AXModel model = (AXModel)target; Event e = Event.current; //GUI.skin = axskin; //GUI.skin = null; //Debug.Log(evt.type); switch (e.type) { case EventType.Layout: if (doAutobuild) { doAutobuild = false; //model.autobuild (); ArchimatixEngine.scheduleBuild(); } break; case EventType.MouseDown: //Debug.Log("Down"); break; case EventType.MouseUp: //doAutobuild = true; break; case EventType.KeyUp: if (e.keyCode == KeyCode.Return || e.keyCode == KeyCode.KeypadEnter) { Undo.RegisterCompleteObjectUndo(model, "Enter"); doAutobuild = true; } //Debug.Log("KeyUp"); //doAutobuild = true; break; case EventType.DragUpdated: UnityEngine.Debug.Log("Dragging"); break; case EventType.DragPerform: //DragAndDrop.AcceptDrag(); UnityEngine.Debug.Log("Drag and Drop not supported... yet"); Undo.RegisterCompleteObjectUndo(model, "Default material scale"); doAutobuild = true; break; } if (richLabelStyle == null) { richLabelStyle = new GUIStyle(GUI.skin.label); richLabelStyle.richText = true; richLabelStyle.wordWrap = true; } //if (infoIconTexture = null) String rubricColor = (EditorGUIUtility.isProSkin) ? "#bbbbff" : "#bbbbff"; GUIStyle gsTest = new GUIStyle(); gsTest.normal.background = ArchimatixEngine.nodeIcons ["Blank"]; // //Color.gray; gsTest.normal.textColor = Color.white; Color textColor = new Color(.82f, .80f, .85f); Color textColorSel = new Color(.98f, .95f, 1f); GUIStyle rubric = new GUIStyle(GUI.skin.label); rubric.normal.textColor = textColor; GUIStyle foldoutStyle = new GUIStyle(EditorStyles.foldout); foldoutStyle.normal.textColor = textColor; foldoutStyle.active.textColor = textColorSel; foldoutStyle.hover.textColor = textColor; foldoutStyle.focused.textColor = textColorSel; foldoutStyle.onNormal.textColor = textColor; foldoutStyle.onActive.textColor = textColorSel; foldoutStyle.onHover.textColor = textColor; foldoutStyle.onFocused.textColor = textColorSel; GUILayout.Space(10); GUILayout.BeginVertical(gsTest); EditorGUI.indentLevel++; EditorGUIUtility.labelWidth = 150; model.displayModelDefaults = EditorGUILayout.Foldout(model.displayModelDefaults, "Model Defaults", true, foldoutStyle); if (model.displayModelDefaults) { // PRECISION LEVEL EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label("Precision Level", rubric); GUILayout.FlexibleSpace(); model.precisionLevel = (PrecisionLevel)EditorGUILayout.EnumPopup("", model.precisionLevel); EditorGUILayout.EndHorizontal(); if (!AXNodeGraphEditorWindow.IsOpen) { GUILayout.Space(10); if (GUILayout.Button("Open in Node Graph")) { AXNodeGraphEditorWindow.Init(); } } //GUILayout.Space(20); // -- RUBRIC - MATERIAL -- EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label("Material (Default)", rubric); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/materials"); } EditorGUILayout.EndHorizontal(); // -------- if (model.axMat.mat.name == "AX_GridPurple") { EditorGUILayout.HelpBox("Set the default Material for this model.", MessageType.Info); } // Material EditorGUI.BeginChangeCheck(); model.axMat.mat = (Material)EditorGUILayout.ObjectField(model.axMat.mat, typeof(Material), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.remapMaterialTools(); model.autobuild(); } GUILayout.Space(10); // Texture // model.showDefaultMaterial = EditorGUILayout.Foldout(model.showDefaultMaterial, "Texture Scaling", true, foldoutStyle); if (model.showDefaultMaterial) { EditorGUI.BeginChangeCheck(); model.axTex.scaleIsUnified = EditorGUILayout.Toggle("Unified Scaling", model.axTex.scaleIsUnified); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material scale"); model.axTex.scale.y = model.axTex.scale.x; model.isAltered(); } if (model.axTex.scaleIsUnified) { EditorGUI.BeginChangeCheck(); model.axTex.scale.x = EditorGUILayout.FloatField("Scale", model.axTex.scale.x); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.axTex.scale.y = model.axTex.scale.x; model.isAltered(); ArchimatixEngine.scheduleBuild(); } } else { // Scale X EditorGUI.BeginChangeCheck(); model.axTex.scale.x = EditorGUILayout.FloatField("Scale X", model.axTex.scale.x); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.isAltered(); ArchimatixEngine.scheduleBuild(); } // Scale Y EditorGUI.BeginChangeCheck(); model.axTex.scale.y = EditorGUILayout.FloatField("Scale Y", model.axTex.scale.y); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.isAltered(); ArchimatixEngine.scheduleBuild(); } } EditorGUI.BeginChangeCheck(); model.axTex.runningU = EditorGUILayout.Toggle("Running U", model.axTex.runningU); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Running U"); model.isAltered(); ArchimatixEngine.scheduleBuild(); } } GUILayout.Space(10); // PhysicMaterial // model.axMat.showPhysicMaterial = EditorGUILayout.Foldout(model.axMat.showPhysicMaterial, "Physics Material", true, foldoutStyle); if (model.axMat.showPhysicMaterial) { // PHYSIC MATERIAL EditorGUI.BeginChangeCheck(); model.axMat.physMat = (PhysicMaterial)EditorGUILayout.ObjectField(model.axMat.physMat, typeof(PhysicMaterial), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default PhysicMaterial for " + model.name); model.remapMaterialTools(); ArchimatixEngine.scheduleBuild(); } // DENSITY EditorGUI.BeginChangeCheck(); model.axMat.density = EditorGUILayout.FloatField("Density", model.axMat.density); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Material Density for " + model.name); model.isAltered(); ArchimatixEngine.scheduleBuild(); } } GUILayout.Space(20); model.automaticModelRegeneration = EditorGUILayout.ToggleLeft("Automatic Model Regeneration", model.automaticModelRegeneration); GUILayout.Space(20); // -- RUBRIC - LIGHTING -- EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); GUILayout.Label("Lighting", rubric); //GUILayout.Label ("<color=" + rubricColor + "> <size=13>Lighting</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/lightmapping-with-archimatix"); } EditorGUILayout.EndHorizontal(); // -------- // LIGHTMAP FLAGS ENABLED EditorGUI.BeginChangeCheck(); model.staticFlagsEnabled = EditorGUILayout.ToggleLeft("Lightmap Flags Enabled", model.staticFlagsEnabled); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Static Masks Enabled change for " + model.name); model.staticFlagsJustEnabled = true; ArchimatixEngine.scheduleBuild(); } // SECONDARY UVs if (model.staticFlagsEnabled) { //if (model.buildStatus == AXModel.BuildStatus.Generated) EditorGUI.BeginChangeCheck(); model.createSecondaryUVs = EditorGUILayout.ToggleLeft("Create Secondary UVs (for Baked GI)", model.createSecondaryUVs); if (EditorGUI.EndChangeCheck()) { //if (model.createSecondaryUVs) // AXEditorUtilities.makeLightMapUVs (model); model.createSecondaryUVsJustEnabled = true; } } GUILayout.Space(20); } // displayModelDefaults /* * if (GUILayout.Button("Set All Objects as Lightmap Static")) * { * Debug.Log("Set all"); * model.setLightmapStaticForAllPOs(); * } */ if (ArchimatixEngine.plevel == 3) { // RUNTIME // string countString = ""; if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { countString = " (" + model.exposedParameterAliases.Count + ")"; } model.displayModelRuntimeParameters = EditorGUILayout.Foldout(model.displayModelRuntimeParameters, "Runtime Parameters" + countString, true, foldoutStyle); if (model.displayModelRuntimeParameters) { //GUILayout.Label("<color="+rubricColor+"> <size=13>Pro Runtime Features</size></color>", richLabelStyle); // EXPOSED PARAMETERS //if (model.cycleSelectedAXGO != null) // GUILayout.Label("Consumer Address: "+model.cycleSelectedAXGO.consumerAddress); //GUILayout.Label("Runtime Parameters"); if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { EditorGUI.BeginChangeCheck(); foreach (AXParameterAlias pa in model.exposedParameterAliases) { ParameterAliasGUILayout.OnGUI(pa); } if (EditorGUI.EndChangeCheck()) { model.isAltered(); } } else { // GUIStyle labelSty = new GUIStyle("Label"); // labelSty.wordWrap = true; // labelSty.richText = true; EditorGUILayout.HelpBox("You can add runntime parameters by opening any parameter in the graph and checking \"Enable Runtime\"", MessageType.Info); //GUILayout.Label ("<color=\"gray\">You can add runntime parameters by opening any parameter in the graph and checking \"Enable Runtime\"</color>", labelSty); } GUILayout.Space(15); if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { if (GUILayout.Button("Create Runtime Controller", GUILayout.Width(200))) { ArchimatixEngine.createControllerForModel = model; } } // RUNTIME HANDLES //if (model.cycleSelectedAXGO != null) // GUILayout.Label("Consumer Address: "+model.cycleSelectedAXGO.consumerAddress); if (model.runtimeHandleAliases != null && model.runtimeHandleAliases.Count > 0) { //GUILayout.Label("Runtime Handles"); foreach (AXHandleRuntimeAlias rth in model.runtimeHandleAliases) { AXRuntimeHandlesGUI.OnGUI(rth); } } GUILayout.Space(20); } } // RUNTIME // RELATIONS if (model.selectedRelationInGraph != null) { GUILayout.Space(20); GUILayout.Label("<color=" + rubricColor + "> <size=13>Selected Relation</size></color>", richLabelStyle); AXRelation r = model.selectedRelationInGraph; RelationEditorGUI.OnGUI(r); } //GUILayout.Space(20); model.displayModelSelectedNodes = EditorGUILayout.Foldout(model.displayModelSelectedNodes, "Selected Node Controls", true, foldoutStyle); if (model.displayModelSelectedNodes) { // -- RUBRIC - SELECTED NODES -- EditorGUILayout.BeginHorizontal(); //GUILayout.Label("<color="+rubricColor+"> <size=13>Selected Nodes</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/node-selection"); } EditorGUILayout.EndHorizontal(); // -------- //GUILayout.Space(10); if (model.selectedPOs != null && model.selectedPOs.Count > 0) { for (int i = 0; i < model.selectedPOs.Count; i++) { //Debug.Log(i); AXParametricObject po = model.selectedPOs [i]; //Debug.Log(i+" ------------------------ po.Name="+po.Name+ " -- " + po.generator.AllInput_Ps.Count); doPO(po); // for subnodes... if (po.generator.AllInput_Ps != null) { for (int j = po.generator.AllInput_Ps.Count - 1; j >= 0; j--) { AXParameter p = po.generator.AllInput_Ps [j]; if (p.DependsOn != null) { AXParametricObject spo = p.DependsOn.parametricObject; doPO(spo); // sub-sub nodes... for (int k = spo.generator.AllInput_Ps.Count - 1; k >= 0; k--) { if (spo.generator.AllInput_Ps [k].DependsOn != null) { doPO(spo.generator.AllInput_Ps [k].DependsOn.parametricObject); } } } } } } } else { GUILayout.Label("<color=\"gray\">...no nodes selected</color>", richLabelStyle); } GUILayout.Space(50); } EditorGUI.indentLevel--; GUILayout.EndVertical(); // Editor currentTransformEditor = Editor.CreateEditor(model.gameObject.); // if (currentTransformEditor != null) { // currentTransformEditor.OnInspectorGUI (); // } //model.controls[0].val = EditorGUILayout.Slider(model.controls[0].val, 0, 100); /* * switch (e.type) * { * case EventType.KeyUp: * case EventType.mouseUp: * * model.autobuild(); * //e.Use (); * * //return; * break; * * case EventType.mouseDown: * * //model.autobuild(); * //e.Use (); * break; * * } */ //DrawDefaultInspector (); }
public override void OnSceneGUI() { AXModel model = ArchimatixEngine.currentModel; FreeCurve gener = (FreeCurve)generator; Event e = Event.current; if (model != null) { Matrix4x4 context = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; // * generator.localMatrix; drawGUIControls(); if ((ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint || (e.type == EventType.mouseDrag && ArchimatixEngine.isPseudoDraggingSelectedPoint >= 0)) && !e.alt) { Vector3 v1 = context.MultiplyPoint3x4(Vector3.zero); Vector3 v2 = context.MultiplyPoint3x4(new Vector3(100, 0, 0)); Vector3 v3 = context.MultiplyPoint3x4(new Vector3(0, 100, 0)); //Debug.Log ("-"+ArchimatixEngine.sceneViewState + "- plane points: " + v1 + ", " + v2+ ", " + v3 ); Plane drawingSurface = new Plane(v1, v2, v3); //Matrix4x4 = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix;// * generator.localMatrix.inverse; Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); float rayDistance = 0; Vector3 hitPoint; // Point on Plane if (drawingSurface.Raycast(ray, out rayDistance)) { hitPoint = ray.GetPoint(rayDistance); Vector3 hit_position3D = new Vector3(hitPoint.x, hitPoint.y, hitPoint.z); if (ArchimatixEngine.snappingOn()) { hit_position3D = AXGeometryTools.Utilities.SnapToGrid(hit_position3D, parametricObject.model.snapSizeGrid); } int nearId = HandleUtility.nearestControl; if (nearId == 0) { Color cyan = Color.cyan; cyan.a = .1f; float hScale = .09f * HandleUtility.GetHandleSize(hit_position3D); float lScale = 5 * hScale; Handles.color = cyan; Handles.DrawSolidDisc(hit_position3D, Vector3.up, hScale); cyan.a = .8f; Handles.color = cyan; Handles.DrawWireDisc(hit_position3D, Vector3.up, 2 * hScale); Handles.DrawLine(hit_position3D + lScale * Vector3.forward, hit_position3D - lScale * Vector3.forward); //Handles.color = Color.white; Handles.DrawLine(hit_position3D + lScale * Vector3.right, hit_position3D - lScale * Vector3.right); // put visual cue under mouse.... //Debug.Log (hitPoint); } hitPoint = context.inverse.MultiplyPoint3x4(hitPoint); Vector2 hit_position2D = new Vector2(hitPoint.x, hitPoint.y); if (ArchimatixEngine.snappingOn()) { hit_position2D = AXGeometryTools.Utilities.SnapToGrid(hit_position2D, parametricObject.model.snapSizeGrid); } // EVENTS if (e.type == EventType.MouseDown && !e.alt && nearId == 0 && e.button == 0) { ArchimatixEngine.isPseudoDraggingSelectedPoint = -1; if (gener != null) { if (!e.control) // add to end of line { // ADD POINT AT END gener.parametricObject.curve.Add(new CurvePoint(hit_position2D.x, hit_position2D.y)); gener.selectedIndex = gener.parametricObject.curve.Count - 1; } else // ADD POINT TO BEGINNING { gener.parametricObject.curve.Insert(0, new CurvePoint(hit_position2D.x, hit_position2D.y)); gener.selectedIndex = 0; } ArchimatixEngine.isPseudoDraggingSelectedPoint = gener.selectedIndex; model.autobuild(); } } else if (e.type == EventType.mouseDrag) { //Debug.Log("Dragging "+ ArchimatixEngine.isPseudoDraggingSelectedPoint + " :: " + generator.selectedIndices); if (gener == ArchimatixEngine.selectedFreeCurve && ArchimatixEngine.isPseudoDraggingSelectedPoint >= 0) { if (gener.parametricObject.curve.Count > ArchimatixEngine.isPseudoDraggingSelectedPoint && generator.selectedIndices != null) { // The actual point being dragged: Vector2 displ = hit_position2D - gener.parametricObject.curve[ArchimatixEngine.isPseudoDraggingSelectedPoint].position; gener.parametricObject.curve[ArchimatixEngine.isPseudoDraggingSelectedPoint].position = hit_position2D; for (int i = 0; i < model.activeFreeCurves.Count; i++) { FreeCurve fc = (FreeCurve)model.activeFreeCurves[i].generator; if (fc != null && fc.selectedIndices != null) { for (int j = 0; j < fc.selectedIndices.Count; j++) { if (!(fc == gener && fc.selectedIndices[j] == ArchimatixEngine.isPseudoDraggingSelectedPoint)) { fc.parametricObject.curve[fc.selectedIndices[j]].position += displ; } } } } //Debug.Log ("DRAGGING"); parametricObject.setAltered(); model.isAltered(); generator.adjustWorldMatrices(); } } } if (e.type == EventType.mouseUp) { //if (ArchimatixEngine.isPseudoDraggingSelectedPoint > -1) ArchimatixEngine.isPseudoDraggingSelectedPoint = -1; ArchimatixEngine.draggingNewPointAt = -1; //model.autobuild(); //Debug.Log("mouse up"); } if ((e.type == EventType.mouseDown) || (e.type == EventType.mouseDrag && ArchimatixEngine.isPseudoDraggingSelectedPoint >= 0) || (e.type == EventType.mouseUp)) { //e.Use(); } SceneView sv = SceneView.lastActiveSceneView; if (sv != null) { sv.Repaint(); } } } } } // \OnScenView
public static void processEventCommand(Event e, AXModel model) { if (e.type == EventType.ValidateCommand) { e.Use(); } //Debug.Log("-> processEventCommand 1: PROCESS COMMAND "+e.commandName); var view = SceneView.lastActiveSceneView; string focusedControlName = GUI.GetNameOfFocusedControl(); if (model != null) { // intercept this command and use for po's switch (e.commandName) { case "UndoRedoPerformed": //Debug.Log ("UndoRedoPerformed"); model.cleanGraph(); model.autobuild(); for (int i = 0; i < model.selectedPOs.Count; i++) { model.selectedPOs[i].generator.adjustWorldMatrices(); } // SCENEVIEW if (SceneView.lastActiveSceneView != null) { SceneView.lastActiveSceneView.Repaint(); } //model.setRenderMode( AXModel.RenderMode.GameObjects ); model.cacheThumbnails("AXGeometryTools.Utilities::processEventCommand::UndoRedoPerformed"); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case "SelectAll": Debug.Log("SelectAll"); model.selectAll(); e.Use(); break; case "Copy": //Debug.Log ("COPY ..."+ GUI.GetNameOfFocusedControl()); //Debug.Log ("buf: " + EditorGUIUtility.systemCopyBuffer); //Debug.Log("-"+focusedControlName+"-"); //Debug.Log((string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_"))); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { if (model.selectedPOs.Count > 0) { EditorGUIUtility.systemCopyBuffer = LibraryEditor.poWithSubNodes_2_JSON(model.selectedPOs[0], true); } if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case "Paste": //Debug.Log ("PASTE"); //Debug.Log(GUI.GetNameOfFocusedControl()); //if (string.IsNullOrEmpty(GUI.GetNameOfFocusedControl())) //{ Undo.RegisterCompleteObjectUndo(model, "Paste"); string focusedControlNameBeforePaste = GUI.GetNameOfFocusedControl(); if (string.IsNullOrEmpty(focusedControlNameBeforePaste) || !focusedControlNameBeforePaste.Contains("_Text_")) { //model.deselectAll(); Library.pasteParametricObjectFromString(EditorGUIUtility.systemCopyBuffer); model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } model.autobuild(); break; case "Duplicate": Undo.RegisterCompleteObjectUndo(model, "Duplicate"); //Debug.Log ("Duplicate Command"); if (model.selectedPOs.Count > 0) { AXParametricObject selectedPO = model.selectedPOs[0]; instancePO(selectedPO); } model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } break; case "Cut": Undo.RegisterCompleteObjectUndo(model, "Cut"); //EditorGUIUtility.systemCopyBuffer = JSONSerializersAX.allSelectedPOsAsJson(model); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { if (model.selectedPOs.Count > 0) { EditorGUIUtility.systemCopyBuffer = LibraryEditor.poWithSubNodes_2_JSON(model.selectedPOs[0], true); } if (e.shift) { model.deleteSelectedPOsAndInputs(); } else { model.deleteSelectedPOs(); } model.autobuild(); if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; case "SoftDelete": case "Delete": //Debug.Log("DELETE"); // see if it is a selected point on a curve //if (ArchimatixEngine /* * FreeCurve selectedFreeCurve = null; * * if ( model.selectedPOs != null && model.selectedPOs.Count == 1 && model.selectedPOs[0] != null && model.selectedPOs[0].generator != null && model.selectedPOs[0].generator is FreeCurve) * { * selectedFreeCurve = (FreeCurve) model.selectedPOs[0].generator; * } * * if (selectedFreeCurve != null && selectedFreeCurve.selectedIndices != null && selectedFreeCurve.selectedIndices.Count > 0) * { * // delete points * selectedFreeCurve.deleteSelected(); * } */ // SELECTED POINTS TO DELETE? //Debug.Log("focusedControlName="+focusedControlName); if (string.IsNullOrEmpty(focusedControlName) || !focusedControlName.Contains("_Text_")) { bool foundSelectedPoints = false; if (model.activeFreeCurves.Count > 0) { for (int i = 0; i < model.activeFreeCurves.Count; i++) { FreeCurve gener = (FreeCurve)model.activeFreeCurves[i].generator; //Debug.Log("gener.hasSelectedPoints()="+gener.hasSelectedPoints()); if (gener.hasSelectedPoints()) { foundSelectedPoints = true; gener.deleteSelected(); } } } //Debug.Log("foundSelectedPoints="+foundSelectedPoints); if (foundSelectedPoints) { ArchimatixEngine.mouseIsDownOnHandle = false; } else if (e.shift) { Undo.RegisterCompleteObjectUndo(model, "Delete Nodes"); model.deleteSelectedPOsAndInputs(); } // [S.Darkwell: changed else to this else if to fix bug: "Fix pressing Delete key without Node selected still registers undo event" https://archimatixbeta.slack.com/files/s.darkwell/F1DJRQ3LL/fix_pressing_delete_key_without_node_selected_still_registers_undo_event.cs - 2016.06.02] else if (model.selectedPOs.Count > 0) { Undo.RegisterCompleteObjectUndo(model, "Delete Node"); model.deleteSelectedPOs(); } else if (model.selectedParameterInputRelation != null) { Undo.RegisterCompleteObjectUndo(model, "Delete Dependancy"); model.selectedParameterInputRelation.makeIndependent(); model.selectedParameterInputRelation = null; } else if (model.selectedRelationInGraph != null) { Undo.RegisterCompleteObjectUndo(model, "Delete Relation"); model.unrelate(model.selectedRelationInGraph); model.selectedRelationInGraph = null; } //Debug.Log("*********************************** DELETE"); model.remapMaterialTools(); model.autobuild(); //Debug.Log("caching here G"); model.cacheThumbnails(); e.Use(); } break; case "FrameSelected": if (view != null) { float framePadding = 400; if (model.selectedPOs == null || model.selectedPOs.Count == 0) { //model.selectAll(); model.selectAllVisibleInGroup(model.currentWorkingGroupPO); Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); model.deselectAll(); } else if (model.selectedPOs.Count > 1) { Rect allRect = AXUtilities.getBoundaryRectFromPOs(model.selectedPOs); allRect.x -= framePadding; allRect.y -= framePadding; allRect.width += framePadding * 2; allRect.height += framePadding * 2; AXNodeGraphEditorWindow.zoomToRectIfOpen(allRect); } else { //frame first po AXParametricObject currPO = model.cycleSelectedPO; // model.selectedPOs[0]; if (currPO == null) { currPO = model.mostRecentlySelectedPO; } if (currPO == null && model.selectedPOs != null && model.selectedPOs.Count > 0) { currPO = model.selectedPOs[0]; } if (currPO == null) { currPO = model.selectFirstHeadPO(); } if (currPO != null) { Matrix4x4 m = model.transform.localToWorldMatrix * currPO.worldDisplayMatrix; // * currPO.getLocalMatrix(); if (m.isIdentity) { m = currPO.generator.localMatrix; } Vector3 position = m.MultiplyPoint(currPO.bounds.center); if (currPO.bounds.size.magnitude > .005 && currPO.bounds.size.magnitude < 10000) { view.LookAt(position, view.camera.transform.rotation, currPO.bounds.size.magnitude * 1.01f); } else { //Debug.Log("FrameSelected - select ParametricObjectObject bounds not good: "+currPO.bounds.size.magnitude); } //if (currPO.grouper != null ) //{ AXNodeGraphEditorWindow.displayGroupIfOpen(currPO.grouper); //} //model.beginPanningToPoint(currPO.rect.center); AXNodeGraphEditorWindow.zoomToRectIfOpen(currPO.rect); } } if (e.type != EventType.Repaint && e.type != EventType.Layout) { e.Use(); } } break; } } // EDITOR WINDOW ArchimatixEngine.repaintGraphEditorIfExistsAndOpen(); // SCENEVIEW if (view != null) { view.Repaint(); } lastCommand = e.commandName; }
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 override void OnInspectorGUI() { //if (Event.current.type != EventType.Layout) // return; AXModel model = (AXModel)target; Event e = Event.current; //Debug.Log(evt.type); switch (e.type) { case EventType.Layout: if (doAutobuild) { doAutobuild = false; model.autobuild(); } break; case EventType.MouseDown: //Debug.Log("Down"); break; case EventType.MouseUp: doAutobuild = true; break; case EventType.KeyUp: Undo.RegisterCompleteObjectUndo(model, "Key Up"); //Debug.Log("KeyUp"); doAutobuild = true; break; case EventType.DragUpdated: //Debug.Log("Dragging"); break; case EventType.DragPerform: //DragAndDrop.AcceptDrag(); //Debug.Log("Drag and Drop not supported... yet"); Undo.RegisterCompleteObjectUndo(model, "Default material scale"); doAutobuild = true; break; } /* * switch (e.type) * { * case EventType.mouseUp: * * model.autobuild(); * //e.Use (); * break; * * case EventType.mouseDown: * * model.autobuild(); * //e.Use (); * break; * * } */ //myTarget.MyValue = EditorGUILayout.IntSlider("Val-you", myTarget.MyValue, 1, 10); if (richLabelStyle == null) { richLabelStyle = new GUIStyle(GUI.skin.label); richLabelStyle.richText = true; richLabelStyle.wordWrap = true; } //if (infoIconTexture = null) String rubricColor = (EditorGUIUtility.isProSkin) ? "#bbbbff" : "#660022"; EditorGUIUtility.labelWidth = 150; model.precisionLevel = (PrecisionLevel)EditorGUILayout.EnumPopup("Precision Level", model.precisionLevel); if (!AXNodeGraphEditorWindow.IsOpen) { GUILayout.Space(10); if (GUILayout.Button("Open in Node Graph")) { AXNodeGraphEditorWindow.Init(); } } GUILayout.Space(20); // -- RUBRIC - MATERIAL -- EditorGUILayout.BeginHorizontal(); GUILayout.Label("<color=" + rubricColor + "> <size=13>Material (Default)</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/materials"); } EditorGUILayout.EndHorizontal(); // -------- // Material EditorGUI.BeginChangeCheck(); model.axMat.mat = (Material)EditorGUILayout.ObjectField(model.axMat.mat, typeof(Material), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.remapMaterialTools(); model.autobuild(); } // Texture // model.showDefaultMaterial = EditorGUILayout.Foldout(model.showDefaultMaterial, "Texture Scaling"); if (model.showDefaultMaterial) { EditorGUI.BeginChangeCheck(); model.axTex.scaleIsUnified = EditorGUILayout.Toggle("Unified Scaling", model.axTex.scaleIsUnified); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material scale"); model.axTex.scale.y = model.axTex.scale.x; model.isAltered(); } if (model.axTex.scaleIsUnified) { EditorGUI.BeginChangeCheck(); model.axTex.scale.x = EditorGUILayout.FloatField("Scale", model.axTex.scale.x); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.axTex.scale.y = model.axTex.scale.x; model.isAltered(); } } else { // Scale X EditorGUI.BeginChangeCheck(); model.axTex.scale.x = EditorGUILayout.FloatField("Scale X", model.axTex.scale.x); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.isAltered(); } // Scale Y EditorGUI.BeginChangeCheck(); model.axTex.scale.y = EditorGUILayout.FloatField("Scale Y", model.axTex.scale.y); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default material for " + model.name); model.isAltered(); } } EditorGUI.BeginChangeCheck(); model.axTex.runningU = EditorGUILayout.Toggle("Running U", model.axTex.runningU); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Running U"); model.isAltered(); } } // PhysicMaterial // model.axMat.showPhysicMaterial = EditorGUILayout.Foldout(model.axMat.showPhysicMaterial, "Physics Material"); if (model.axMat.showPhysicMaterial) { // PHYSIC MATERIAL EditorGUI.BeginChangeCheck(); model.axMat.physMat = (PhysicMaterial)EditorGUILayout.ObjectField(model.axMat.physMat, typeof(PhysicMaterial), true); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Default PhysicMaterial for " + model.name); model.remapMaterialTools(); model.autobuild(); } // DENSITY EditorGUI.BeginChangeCheck(); model.axMat.density = EditorGUILayout.FloatField("Density", model.axMat.density); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Material Density for " + model.name); model.isAltered(); } } GUILayout.Space(20); // -- RUBRIC - LIGHTING -- EditorGUILayout.BeginHorizontal(); GUILayout.Label("<color=" + rubricColor + "> <size=13>Lighting</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/lightmapping-with-archimatix"); } EditorGUILayout.EndHorizontal(); // -------- // LIGHTMAP FLAGS ENABLED EditorGUI.BeginChangeCheck(); model.staticFlagsEnabled = EditorGUILayout.ToggleLeft("Lightmap Flags Enabled", model.staticFlagsEnabled); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(model, "Static Masks Enabled change for " + model.name); model.staticFlagsJustEnabled = true; model.autobuild(); } // SECONDARY UVs if (model.staticFlagsEnabled) { //if (model.buildStatus == AXModel.BuildStatus.Generated) EditorGUI.BeginChangeCheck(); model.createSecondaryUVs = EditorGUILayout.ToggleLeft("Create Secondary UVs (for Baked GI)", model.createSecondaryUVs); if (EditorGUI.EndChangeCheck()) { //if (model.createSecondaryUVs) // AXEditorUtilities.makeLightMapUVs (model); model.createSecondaryUVsJustEnabled = true; } } GUILayout.Space(20); /* * if (GUILayout.Button("Set All Objects as Lightmap Static")) * { * Debug.Log("Set all"); * model.setLightmapStaticForAllPOs(); * } */ if (ArchimatixEngine.plevel == 3) { // RUNTIME // GUILayout.Label("<color=" + rubricColor + "> <size=13>Pro Runtime Features</size></color>", richLabelStyle); // EXPOSED PARAMETERS //if (model.cycleSelectedAXGO != null) // GUILayout.Label("Consumer Address: "+model.cycleSelectedAXGO.consumerAddress); GUILayout.Label("Runtime Parameters"); EditorGUI.BeginChangeCheck(); foreach (AXParameterAlias pa in model.exposedParameterAliases) { ParameterAliasGUILayout.OnGUI(pa); } if (EditorGUI.EndChangeCheck()) { model.isAltered(); } GUILayout.Space(30); if (model.exposedParameterAliases != null && model.exposedParameterAliases.Count > 0) { if (GUILayout.Button("Create Runtime Controller", GUILayout.Width(200))) { ArchimatixEngine.createControllerForModel = model; } } // RUNTIME HANDLES //if (model.cycleSelectedAXGO != null) // GUILayout.Label("Consumer Address: "+model.cycleSelectedAXGO.consumerAddress); if (model.runtimeHandleAliases != null && model.runtimeHandleAliases.Count > 0) { GUILayout.Label("Runtime Handles"); foreach (AXHandleRuntimeAlias rth in model.runtimeHandleAliases) { AXRuntimeHandlesGUI.OnGUI(rth); } } GUILayout.Space(20); } // RUNTIME // RELATIONS if (model.selectedRelationInGraph != null) { GUILayout.Space(20); GUILayout.Label("<color=" + rubricColor + "> <size=13>Selected Relation</size></color>", richLabelStyle); AXRelation r = model.selectedRelationInGraph; RelationEditorGUI.OnGUI(r); } GUILayout.Space(20); // -- RUBRIC - SELECTED NODES -- EditorGUILayout.BeginHorizontal(); GUILayout.Label("<color=" + rubricColor + "> <size=13>Selected Nodes</size></color>", richLabelStyle); GUILayout.FlexibleSpace(); //if (GUILayout.Button ( infoIconTexture, GUIStyle.none)) if (GUILayout.Button(infoIconTexture, GUIStyle.none, new GUILayoutOption[] { GUILayout.Width(16), GUILayout.Height(16) })) { Application.OpenURL("http://www.archimatix.com/manual/node-selection"); } EditorGUILayout.EndHorizontal(); // -------- GUILayout.Space(10); if (model.selectedPOs != null && model.selectedPOs.Count > 0) { for (int i = 0; i < model.selectedPOs.Count; i++) { //Debug.Log(i); AXParametricObject po = model.selectedPOs[i]; //Debug.Log(i+" ------------------------ po.Name="+po.Name+ " -- " + po.generator.AllInput_Ps.Count); doPO(po); // for subnodes... if (po.generator.AllInput_Ps != null) { for (int j = po.generator.AllInput_Ps.Count - 1; j >= 0; j--) { AXParameter p = po.generator.AllInput_Ps[j]; if (p.DependsOn != null) { AXParametricObject spo = p.DependsOn.parametricObject; doPO(spo); // sub-sub nodes... for (int k = spo.generator.AllInput_Ps.Count - 1; k >= 0; k--) { if (spo.generator.AllInput_Ps[k].DependsOn != null) { doPO(spo.generator.AllInput_Ps[k].DependsOn.parametricObject); } } } } } } } else { GUILayout.Label("...no nodes selected"); } GUILayout.Space(50); //model.controls[0].val = EditorGUILayout.Slider(model.controls[0].val, 0, 100); /* * switch (e.type) * { * case EventType.KeyUp: * case EventType.mouseUp: * * model.autobuild(); * //e.Use (); * * //return; * break; * * case EventType.mouseDown: * * //model.autobuild(); * //e.Use (); * break; * * } */ //DrawDefaultInspector (); }