public virtual void initRepeaterTools() { parametricObject.addParameter(new AXParameter(AXParameter.DataType.RepeaterTool, AXParameter.ParameterType.Input, "RepeaterU")); AXParametricObject repeaterToolU = parametricObject.model.createNode("RadialRepeaterTool"); repeaterToolU.rect.x = parametricObject.rect.x - 200; repeaterToolU.isOpen = false; parametricObject.getParameter("RepeaterU").makeDependentOn(repeaterToolU.getParameter("Output")); }
// 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 void initRepeaterTools() { parametricObject.addParameter(new AXParameter(AXParameter.DataType.RepeaterTool, AXParameter.ParameterType.Input, "Repeater")); AXParametricObject repeaterTool = parametricObject.model.createNode("RepeaterTool"); repeaterTool.rect.x = parametricObject.rect.x - 200; repeaterTool.isOpen = false; repeaterTool.intValue("Edge_Count", 100); parametricObject.getParameter("Repeater").makeDependentOn(repeaterTool.getParameter("Output")); }
// INIT EXTRUDE GENERATOR public override void init_parametricObject() { base.init_parametricObject(); // INPUT MESH parametricObject.addParameter(new AXParameter(AXParameter.DataType.Mesh, AXParameter.ParameterType.Input, "Node Mesh")); parametricObject.addParameter(new AXParameter(AXParameter.DataType.Mesh, AXParameter.ParameterType.Input, "SpanU Mesh")); // MATERIAL parametricObject.addParameter(new AXParameter(AXParameter.DataType.MaterialTool, AXParameter.ParameterType.Input, "Material")); // JITTER parametricObject.addParameter(new AXParameter(AXParameter.DataType.JitterTool, AXParameter.ParameterType.Input, "Jitter Translation")); parametricObject.addParameter(new AXParameter(AXParameter.DataType.JitterTool, AXParameter.ParameterType.Input, "Jitter Rotation")); parametricObject.addParameter(new AXParameter(AXParameter.DataType.JitterTool, AXParameter.ParameterType.Input, "Jitter Scale")); // REPEATER P_RepeaterU = parametricObject.addParameter(new AXParameter(AXParameter.DataType.RepeaterTool, AXParameter.ParameterType.Input, "RepeaterU")); P_Rise = parametricObject.addParameter(AXParameter.DataType.Float, "Rise", 0f, 0, 5000); P_Riser = parametricObject.addParameter(AXParameter.DataType.Float, "Riser", 0f, .01f, 5000); P_ProgressiveRotationX = parametricObject.addParameter(AXParameter.DataType.Float, "IncrRotX", 0f); P_ProgressiveRotationY = parametricObject.addParameter(AXParameter.DataType.Float, "IncrRotY", 0f); P_ProgressiveRotationZ = parametricObject.addParameter(AXParameter.DataType.Float, "IncrRotZ", 0f); // OUTPUT parametricObject.addParameter(new AXParameter(AXParameter.DataType.Mesh, AXParameter.ParameterType.Output, "Output Mesh")); // ADD A REPEATER TOOL AXParametricObject radialRepeaterTool = parametricObject.model.createNode("RadialRepeaterTool"); radialRepeaterTool.rect.x = parametricObject.rect.x - 200; radialRepeaterTool.isOpen = false; P_RepeaterU.makeDependentOn(radialRepeaterTool.getParameter("Output")); }
// 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 void processExpressionsAfterHandleChange() { //Debug.Log("processExpressionsAfterHandleChange"); // ASSUME THAT han_x, han_y, or han_z have just been rest in the vars. // Ripple to set any parameters based on these new handle values. for (int i = 0; i < expressions.Count; i++) { if (expressions[i] == "") { continue; } string expression = Regex.Replace(expressions[i], @"\s+", ""); string paramName = expression.Substring(0, expression.IndexOf("=")); string definition = expression.Substring(expression.IndexOf("=") + 1); //Debug.Log (param + " --- " + definition); try { if (parametricObject.getParameter(paramName).Type == AXParameter.DataType.Int) { parametricObject.initiateRipple_setIntValueFromGUIChange(paramName, Mathf.RoundToInt((float)parametricObject.parseMath(definition))); } else { parametricObject.initiateRipple_setFloatValueFromGUIChange(paramName, (float)parametricObject.parseMath(definition)); } } catch (System.Exception e) { parametricObject.codeWarning = "10. Handle error: Please check syntax of: \"" + definition + "\" " + e.Message; } } // Now that the parmaseters are all updated, reset the // X, Y, and Z values... calculatePosition(); }
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 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); }
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 render(AXParametricObject po, bool makeTexture = false) { AXModel model = po.model; if (model == null) { return; } model.assertThumnailSupport(); // THUMBNAIL BACKGROUND COLOR if (po.generator != null && makeTexture) { model.thumbnailCamera.backgroundColor = po.generator.ThumbnailColor; } // WHY ARE THE THUMNAIL AND RenTex null? if (po.renTex == null) { po.renTex = new RenderTexture(256, 256, 24); } if (!po.renTex.IsCreated()) { po.renTex.antiAliasing = 8; po.renTex.Create(); } // This started giving an error in 5.3 and did not seem to be needed anyway! if (makeTexture) { RenderTexture.active = po.renTex; } model.thumbnailCamera.targetTexture = po.renTex; model.thumbnailCameraGO.transform.position = po.getThumbnailCameraPosition(); model.thumbnailCameraGO.gameObject.transform.LookAt(po.getThumbnailCameraTarget()); // USE THIS MATRIX TO DRAW THE PO's MESHES SOMEWHERE FAR, FAR AWAY //Debug.Log("RENDER: " + po.Name); Material tmpMat = null; if (po.generator is MaterialTool) { if (po.axMat != null && po.axMat.mat != null) { tmpMat = po.axMat.mat; } else if (po.grouper != null && po.grouper.axMat != null && po.grouper.axMat.mat != null) { tmpMat = po.grouper.axMat.mat; } else { tmpMat = model.axMat.mat; } //Debug.Log("RENDER TEXTURETOOL " + model.thumbnailCameraGO.transform.position + " mesh-> " + model.thumbnailMaterialMesh.vertices.Length + " -- " + tmpMat); Graphics.DrawMesh(model.thumbnailMaterialMesh, model.remoteThumbnailLocation, tmpMat, 0, model.thumbnailCamera); model.thumbnailCamera.Render(); } else { AXParameter op = po.getParameter("Output Mesh"); if (op != null) { // RE-RENDER // After a save or reload, the RenterTextures are empty if (op.meshes != null) { for (int mi = 0; mi < op.meshes.Count; mi++) { AXMesh axmesh = op.meshes [mi]; if (axmesh.mat != null) { tmpMat = axmesh.mat; } else if (po.axMat != null && po.axMat.mat != null) { tmpMat = po.axMat.mat; } else if (po.grouper != null && po.grouper.axMat != null && po.grouper.axMat.mat != null) { tmpMat = po.grouper.axMat.mat; } else { tmpMat = model.axMat.mat; } Graphics.DrawMesh(axmesh.drawMesh, (model.remoteThumbnailLocation * axmesh.transMatrix), tmpMat, 0, model.thumbnailCamera); } } model.thumbnailCamera.Render(); } } // write to texture if (makeTexture) { if (po.thumbnail == null) { po.thumbnail = new Texture2D(256, 256); } po.thumbnail.ReadPixels(new Rect(0, 0, po.renTex.width, po.renTex.height), 0, 0); po.thumbnail.Apply(); } if (makeTexture) { RenderTexture.active = null; } // 3. Set helper objects to inactive model.thumbnailLightGO.SetActive(false); model.thumbnailCameraGO.SetActive(false); }
public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { if (parametricObject == null || !parametricObject.isActive) { return(null); } if (P_PrototypePlan == null || P_Prototype == null) { return(null); } preGenerate(); // PLAN planSrc_p = P_Plan.DependsOn; // getUpstreamSourceParameter(P_Plan); planSrc_po = (planSrc_p != null) ? planSrc_p.parametricObject : null; P_Plan.polyTree = null; AXShape.thickenAndOffset(ref P_Plan, planSrc_p); planPaths = P_Plan.getPaths(); if (planPaths == null || planPaths.Count == 0) { return(null); } prototypePlanSrc_p = P_PrototypePlan.DependsOn; prototypePlanSrc_po = (prototypePlanSrc_p != null) ? prototypePlanSrc_p.parametricObject : null; prototypeSrc_p = P_Prototype.DependsOn; prototypePlanSrc_po = (prototypeSrc_p != null) ? prototypeSrc_p.parametricObject : null; if (prototypePlanSrc_p == null || prototypePlanSrc_po == null || prototypeSrc_po == null) { return(null); } AXParameter srcSrc_p = prototypePlanSrc_p.DependsOn; if (srcSrc_p == null) { return(null); } // AX_MESHES List <AXMesh> ax_meshes = new List <AXMesh>(); GameObject go = null; if (makeGameObjects && !parametricObject.combineMeshes) { go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject); } Perlin perlin = new Perlin(); perlin.OctaveCount = 1; perlin.Frequency = .05f; GameObject replicant = null; foreach (Path plan in planPaths) { // 1. cache source object //prototypeSrc_po.cacheParameterValues(); Paths tmpPaths = new Paths(); tmpPaths.Add(plan); IntPoint planCenter = AXGeometryTools.Utilities.getCenter(tmpPaths); Vector3 centerPt = AXGeometryTools.Utilities.IntPt2Vec3(planCenter); //Debug.Log("Center: " + centerPt); srcSrc_p.paths = tmpPaths; float area = ((float)Clipper.Area(plan)) / 1000000000; //Debug.Log(area); float perlinVal = (float)perlin.GetValue(centerPt); float h = 3 + 100 * (float)Math.Exp(-(.1f * area)) + 5 * perlinVal; // (float) perlin.GetValue(2,3,4); AXParameter sHeight = prototypeSrc_po.getParameter("Height"); sHeight.initiateRipple_setFloatValueFromGUIChange(h); prototypeSrc_po.generator.pollControlValuesFromParmeters(); prototypeSrc_po.isAltered = true; replicant = prototypeSrc_po.generateOutputNow(makeGameObjects, parametricObject, true); if (replicant != null) { replicant.transform.parent = go.transform; } AXParameter output_p = prototypeSrc_po.getParameter("Output Mesh"); foreach (AXMesh amesh in output_p.meshes) { ax_meshes.Add(amesh.Clone(amesh.transMatrix)); } } // FINISH AX_MESHES parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica); if (makeGameObjects) { return(go); } return(null); }
// Update is called once per frame void Update() { if (!Application.isPlaying) { return; } bool byPlane = true; if (handle == null) { return; } AXParametricObject parametricObject = handle.parametricObject; // GET POSITION if (parametricObject.is2D()) { context = parametricObject.model.transform.localToWorldMatrix * parametricObject.worldDisplayMatrix; if (parametricObject.generator.hasOutputsConnected() || parametricObject.is2D()) { context *= parametricObject.generator.localMatrix.inverse; } else { context *= parametricObject.getAxisRotationMatrix().inverse *parametricObject.generator.localMatrix.inverse *parametricObject.getAxisRotationMatrix(); } } else { // GROUPER MATRIX NOT WORKING.... context = parametricObject.model.transform.localToWorldMatrix * parametricObject.generator.parametricObject.worldDisplayMatrix * (parametricObject.getAxisRotationMatrix() * parametricObject.generator.getLocalAlignMatrix()).inverse * parametricObject.generator.localMatrix.inverse; } // position handle by parmeters. positionHandleGameObject(); double h_diff = 0; double v_diff = 0; if (mouseIsDown) { if (Input.touchCount == 1) { // touch input - works better with deltaPosition var touch = Input.GetTouch(0); //var dx = touch.deltaPosition.x; h_diff = (100.0 / Screen.width) * touch.deltaPosition.x; v_diff = (100.0 / Screen.width) * touch.deltaPosition.y; } else { // 0 touches: must be mouse input h_diff = (5000 / Screen.width) * Input.GetAxis("Mouse X"); v_diff = (5000 / Screen.width) * Input.GetAxis("Mouse Y"); } h_diff /= 5; v_diff /= 5; //Debug.Log(h_diff +", " + v_diff); //using plane if (byPlane) { establishDrawingSurface(); //Vector3 prevPosition = transform.position; } // BASED ON PLANE Vector3 world_pos = transform.position; if (byPlane) { Vector3 hit_position3D = sampleHitPoint(); world_pos = hit_position3D - mouseDownDiff; transform.position = world_pos; } Vector3 localPosition = context.inverse.MultiplyPoint3x4(world_pos); //transform.position = world_pos; //if (transform.position != prevPosition) if (h_diff != 0 || v_diff != 0) { //Debug.Log("moved"); // Determine the orientation of the camera //The normal OperatingSystemFamily the handle plane //Debug.Log (lookV); float threshold = .707f; double diffX = -v_diff; double diffZ = h_diff; // This logic works with a normal vector if (!byPlane) { if (lookV.x > 0 && lookV.z < 0) { diffX = (1 - lookV.x) * h_diff - lookV.x * v_diff; diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff; } else if (lookV.x > 0 && lookV.z > 0) { diffX = -((lookV.x)) * h_diff - lookV.x * v_diff; diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff; } else if (lookV.x < 0 && lookV.z > 0) { diffX = (1 + lookV.x) * h_diff + lookV.x * v_diff; diffZ = (1 - lookV.z) * h_diff + lookV.z * v_diff; } else if (lookV.x > 0 && lookV.z > 0) { diffX = -((lookV.x)) * h_diff - (lookV.x) * v_diff; diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff; //(-lookV.x + lookV.z) * v_diff; } else if (lookV.z > threshold) // pointing forwards { diffX = -h_diff; diffZ = -v_diff; } else if (lookV.z < -threshold) { // pointing backwards diffX = h_diff; diffZ = v_diff; } else if (lookV.x > 0) { // pointing right diffX = -h_diff; diffZ = v_diff; } else { // pointing left diffX = v_diff; diffZ = -h_diff; } } AXHandle han = handle; string hanString = "han_y"; float posV = localPosition.y; if (parametricObject.is3D()) { hanString = "han_z"; posV = localPosition.z; } if (byPlane) { parametricObject.setVar("han_x", (localPosition.x)); if (parametricObject.is3D()) { parametricObject.setVar("han_z", world_pos.z); } else { parametricObject.setVar("han_y", localPosition.y); } } else { // Relative slide of cursor parametricObject.setVar("han_x", (localPosition.x + (float)diffX)); parametricObject.setVar(hanString, (posV + (float)diffZ)); } // From plane // parametricObject.setVar("han_x", localPosition.x); // parametricObject.setVar("han_y", localPosition.y); // parametricObject.setVar("han_z", localPosition.z); // EACH EXPRESSION for (int i = 0; i < han.expressions.Count; i++) { if (han.expressions [i] == "") { continue; } string expression = Regex.Replace(han.expressions [i], @"\s+", ""); string paramName = expression.Substring(0, expression.IndexOf("=")); string definition = expression.Substring(expression.IndexOf("=") + 1); //Debug.Log (param + " --- " + definition); try { if (parametricObject.getParameter(paramName).Type == AXParameter.DataType.Int) { parametricObject.initiateRipple_setIntValueFromGUIChange(paramName, Mathf.RoundToInt((float)parametricObject.parseMath(definition))); } else { parametricObject.initiateRipple_setFloatValueFromGUIChange(paramName, (float)parametricObject.parseMath(definition)); } } catch (System.Exception e) { parametricObject.codeWarning = "10. Handle error: Please check syntax of: \"" + definition + "\" " + e.Message; } } parametricObject.model.isAltered(); //parametricObject.model.autobuild(); } } }
// COPY OPERATION public static string allSelectedPOsAsJson(AXModel m) { Debug.Log("allSelectedPOsAsJson"); //List<string> registry = new List<string>(); // gather relations as you go... List <AXRelation> rels = new List <AXRelation>(); StringBuilder sb = new StringBuilder(); sb.Append("{"); sb.Append("\"model_guid\": \"" + m.Guid + "\""); sb.Append(", \"parametric_objects\": ["); // begin parametric_objects for (int i = 0; i < m.selectedPOs.Count; i++) { AXParametricObject po = m.selectedPOs[i]; // if this po is an instance, get its source as json to store in the clipboard if (po.Type == "Instance") { AXParametricObject src_po = po.getParameter("Input Mesh").DependsOn.Parent; if (!m.isSelected(src_po)) { po = src_po; } } sb.Append(((i > 0)?",":"") + JSONSerializersAX.ParametricObjectAsJSON(po)); foreach (AXParameter p in po.parameters) { foreach (AXRelation rr in p.relations) { if (!rels.Contains(rr)) { rels.Add(rr); } } } // SUB_NODES if (po.inputsStowed) { // copy them too! po.gatherSubnodes(); foreach (AXParametricObject spo in po.subnodes) { sb.Append(',' + JSONSerializersAX.ParametricObjectAsJSON(spo)); // gather relations foreach (AXParameter p in spo.parameters) { foreach (AXRelation rr in p.relations) { if (!rels.Contains(rr)) { rels.Add(rr); } } } } } } sb.Append("]"); // end parametric_objects // add relations to json string thecomma; // RELATIONS if (m.relations != null && m.relations.Count > 0) { sb.Append(", \"relations\": ["); // begin parametric_objects thecomma = ""; foreach (AXRelation rr in m.relations) { sb.Append(thecomma + rr.asJSON()); thecomma = ", "; } } sb.Append("]"); /* to retrieve later... * if (jn["relations"] != null) * { * foreach(AX.SimpleJSON.JSONNode jn_r in jn["relations"].AsArray) * model.addRelationJSON(jn_r); * } */ sb.Append("}"); // end collection return(sb.ToString()); }