public Path getPathFromCurve() { Path path = new Path(); for (int i = 0; i <= parametricObject.curve.Count - 1; i++) { if (i == parametricObject.curve.Count - 1 && P_Output.shapeState == ShapeState.Open) { break; } CurvePoint a = parametricObject.curve[i]; int next_i = (i == parametricObject.curve.Count - 1) ? 0 : i + 1; CurvePoint b = parametricObject.curve[next_i]; if (a.isPoint() && b.isPoint()) { if (i == 0) { path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(a.position)); } path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(b.position)); } else { int governor = 0; for (float t = 0; t <= (1 + .9f * timetick); t = t + timetick) { if (governor++ > 50) { Debug.Log("governor hit)"); break; } if (i == 0 || t > 0) { Vector2 pt = bezierValue(parametricObject.curve[i], parametricObject.curve[next_i], t); path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(pt)); } } } } return(path); }
public override void drawControlHandles(ref List <string> visited, Matrix4x4 consumerM, bool beingDrawnFromConsumer) { Matrix4x4 prevHandlesMatrix = Handles.matrix; FreeCurve gener = (FreeCurve)parametricObject.generator; base.drawControlHandles(ref visited, consumerM, true); if (alreadyVisited(ref visited, "FreeCurveHandler")) { return; } AXParameter p = parametricObject.getParameter("Output Shape"); if (p == null || p.getPaths() == null) { return; } parametricObject.model.addActiveFreeCurve(parametricObject); Event e = Event.current; if (ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint && e.type == EventType.keyDown && (e.keyCode == KeyCode.Escape || e.keyCode == KeyCode.Return)) { ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default); e.Use(); } handlePoints = new List <Vector2>(); bool handleHasChanged = false; /* * Matrix4x4 context = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; * if (generator.hasOutputsConnected() || parametricObject.is2D()) * context *= generator.localMatrix.inverse; * else * context *= parametricObject.getAxisRotationMatrix().inverse * generator.localMatrix.inverse * parametricObject.getAxisRotationMatrix(); * * Handles.matrix = context; */ Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix; // * generator.localMatrix.inverse; float gridDim = parametricObject.model.snapSizeGrid * 100; // axis Handles.color = Color.red; Handles.DrawLine(new Vector3(-gridDim / 2, 0, 0), new Vector3(gridDim / 2, 0, 0)); Handles.color = Color.green; Handles.DrawLine(new Vector3(0, -gridDim / 2, 0), new Vector3(0, gridDim / 2, 0)); // grid if (ArchimatixEngine.snappingOn()) { Handles.color = new Color(1, .5f, .65f, .15f); } else { Handles.color = new Color(1, .5f, .65f, .05f); } AXEditorUtilities.DrawGrid3D(gridDim, parametricObject.model.snapSizeGrid); //Handles.matrix = Matrix4x4.identity; CurvePoint newCurvePoint = null;; int newCurvePointIndex = -1; if (parametricObject.curve != null) { //if (Event.current.type == EventType.mouseDown) // selectedIndex = -1; //Vector3 pos; for (int i = 0; i < parametricObject.curve.Count; i++) { //Debug.Log (i + ": "+ parametricObject.curve[i].position); // Control points in Curve bool pointIsSelected = (generator.selectedIndices != null && generator.selectedIndices.Contains(i)); Vector3 pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0); Handles.color = (pointIsSelected) ? Color.white : Color.magenta; float capSize = .13f * HandleUtility.GetHandleSize(pos); if (pointIsSelected) { capSize = .17f * HandleUtility.GetHandleSize(pos); } // POSITION //pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0); // pos = Handles.FreeMoveHandle( // pos, // Quaternion.identity, // capSize, // Vector3.zero, // (controlID, positione, rotation, size) => // { // if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) // Debug.Log("YOP"); // Handles.SphereCap(controlID, positione, rotation, size); // }); pos = Handles.FreeMoveHandle( pos, Quaternion.identity, capSize, Vector3.zero, (controlID, position, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { //Debug.Log("*** " + e.type + " -" + e.keyCode + "-"); // MOUSE DOWN ON HANDLE! Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeCurve"); //Debug.Log(controlID + ": " + e.type); ArchimatixEngine.selectedFreeCurve = gener; //Debug.Log("SELECT NODE " +i + " ci="+controlID); if (i == 0 && ArchimatixEngine.sceneViewState == ArchimatixEngine.SceneViewState.AddPoint) { generator.P_Output.shapeState = ShapeState.Closed; ArchimatixEngine.setSceneViewState(ArchimatixEngine.SceneViewState.Default); } else if (e.shift && !ArchimatixEngine.mouseIsDownOnHandle) { generator.toggleItem(i); } else if (gener.selectedIndices == null || gener.selectedIndices.Count < 2) { if (!generator.isSelected(i)) { generator.selectOnlyItem(i); } } ArchimatixEngine.isPseudoDraggingSelectedPoint = i; // CONVERT TO BEZIER if (e.alt) { gener.convertToBezier(i); } for (int j = 0; j < generator.P_Output.Dependents.Count; j++) { generator.P_Output.Dependents [j].parametricObject.generator.adjustWorldMatrices(); } ArchimatixEngine.mouseDownOnSceneViewHandle(); } Handles.SphereCap(controlID, position, rotation, size); }); // MID_SEGEMNET HANDLE if (i < parametricObject.curve.Count) { //Handles.matrix = parametricObject.model.transform.localToWorldMatrix * generator.parametricObject.worldDisplayMatrix * generator.localMatrix.inverse; Handles.color = Color.cyan; //Debug.Log("mid handle "+i); CurvePoint a = parametricObject.curve[i]; int next_i = (i == parametricObject.curve.Count - 1) ? 0 : i + 1; CurvePoint b = parametricObject.curve[next_i]; if (a.isPoint() && b.isPoint()) { pos = Vector2.Lerp(a.position, b.position, .5f); } else { Vector2 pt = FreeCurve.bezierValue(a, b, .5f); pos = (Vector3)pt; } EditorGUI.BeginChangeCheck(); #if UNITY_5_6_OR_NEWER pos = Handles.FreeMoveHandle( pos, Quaternion.identity, .06f * HandleUtility.GetHandleSize(pos), Vector3.zero, (controlID, positione, rotation, size, eventType) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.selectedFreeCurve = gener; } Handles.CubeHandleCap(controlID, positione, rotation, size, eventType); }); #else pos = Handles.FreeMoveHandle( pos, Quaternion.identity, .06f * HandleUtility.GetHandleSize(pos), Vector3.zero, (controlID, positione, rotation, size) => { if (GUIUtility.hotControl > 0 && controlID == GUIUtility.hotControl) { ArchimatixEngine.selectedFreeCurve = gener; } Handles.CubeCap(controlID, positione, rotation, size); }); #endif if (EditorGUI.EndChangeCheck()) { // add point to spline at i using pos.x, pos.y Undo.RegisterCompleteObjectUndo(parametricObject.model, "New Midpoint"); //Debug.Log(pos); //Debug.Log(ArchimatixEngine.isPseudoDraggingSelectedPoint + " ::: " + (i)); //if (ArchimatixEngine.isPseudoDraggingSelectedPoint != (i+1)) if (ArchimatixEngine.isPseudoDraggingSelectedPoint == -1) { //Debug.Log("CREATE!!!!"); newCurvePoint = new CurvePoint(pos.x, pos.y); newCurvePointIndex = i + 1; parametricObject.curve.Insert(newCurvePointIndex, newCurvePoint); ArchimatixEngine.isPseudoDraggingSelectedPoint = newCurvePointIndex; generator.selectedIndex = newCurvePointIndex; generator.selectOnlyItem(newCurvePointIndex); } parametricObject.model.isAltered(); } } } // \loop // BEZIER HANDLES LOOP for (int i = 0; i < parametricObject.curve.Count; i++) { //Debug.Log (i + ": "+ parametricObject.curve[i].position); // Control points in Curve bool pointIsSelected = (generator.selectedIndices != null && generator.selectedIndices.Contains(i)); Vector3 pos = new Vector3(parametricObject.curve[i].position.x, parametricObject.curve[i].position.y, 0); Vector3 posA = new Vector3(parametricObject.curve[i].position.x + parametricObject.curve[i].localHandleA.x, parametricObject.curve[i].position.y + parametricObject.curve[i].localHandleA.y, 0); Vector3 posB = new Vector3(parametricObject.curve[i].position.x + parametricObject.curve[i].localHandleB.x, parametricObject.curve[i].position.y + parametricObject.curve[i].localHandleB.y, 0); Handles.color = (pointIsSelected) ? Color.white : Color.magenta; if (pointIsSelected) { Handles.color = Color.magenta; if (parametricObject.curve[i].isBezierPoint()) { Handles.color = Color.white; Handles.DrawLine(pos, posA); Handles.DrawLine(pos, posB); EditorGUI.BeginChangeCheck(); posA = Handles.FreeMoveHandle( posA, Quaternion.identity, .1f * HandleUtility.GetHandleSize(pos), Vector3.zero, Handles.SphereCap ); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeformShapee"); handleHasChanged = true; parametricObject.curve[i].setHandleA(new Vector2(posA.x, posA.y)); //parametricObject.curve[i].localHandleA = new Vector2(pos.x, pos.y) - parametricObject.curve[i].position; //parametricObject.model.generate("Move FreeForm Shape Handle"); parametricObject.model.isAltered(); } // HANDLE_B EditorGUI.BeginChangeCheck(); posB = Handles.FreeMoveHandle( posB, Quaternion.identity, .1f * HandleUtility.GetHandleSize(pos), Vector3.zero, Handles.SphereCap ); if (EditorGUI.EndChangeCheck()) { Undo.RegisterCompleteObjectUndo(parametricObject.model, "FreeformShapee"); handleHasChanged = true; //parametricObject.curve[i].localHandleB = new Vector2(pos.x, pos.y) - parametricObject.curve[i].position; parametricObject.curve[i].setHandleB(new Vector2(posB.x, posB.y)); //parametricObject.model.generate("Move FreeForm Shape Handle"); parametricObject.model.isAltered(); } } } // selected } // \bezier handles loop if (handleHasChanged) { } } Handles.matrix = prevHandlesMatrix; }
// GENERATE FREE_CURVE public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica) { parametricObject.transMatrix = Matrix4x4.TRS(new Vector3(transX, transY, 0), Quaternion.Euler(0, 0, rotZ), new Vector3(1, 1, 1)); //Debug.Log ("IntPoint = " + parametricObject.ip.X + " --- " + parametricObject.TestInt); if (P_Output != null && parametricObject.curve != null) { //Curve transformedCurve = parametricObject.getTransformedCurve(); //Output.spline = Archimatix.curve2Spline (transformedCurve); // ControlPaths P_Output.controlPaths = new Paths(); // not to be altered in base postprocessing for offset and wallthick // use the "curve" to generate the source path // bezier experiment // EACH SEGMENT Path path = new Path(); for (int i = 0; i <= parametricObject.curve.Count - 1; i++) { if (i == parametricObject.curve.Count - 1 && P_Output.shapeState == ShapeState.Open) { break; } CurvePoint a = parametricObject.curve[i]; int next_i = (i == parametricObject.curve.Count - 1) ? 0 : i + 1; CurvePoint b = parametricObject.curve[next_i]; if (a.isPoint() && b.isPoint()) { if (i == 0) { path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(a.position)); } path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(b.position)); } else { int governor = 0; for (float t = 0; t <= (1 + .9f * timetick); t = t + timetick) { if (governor++ > 50) { Debug.Log("governor hit)"); break; } if (i == 0 || t > 0) { Vector2 pt = bezierValue(parametricObject.curve[i], parametricObject.curve[next_i], t); path.Add(AXGeometryTools.Utilities.Vec2_2_IntPt(pt)); } } } } /* * if (P_Output.shapeState == ShapeState.Closed && (parametricObject.curve[0] || parametricObject.curve[parametricObject.curve.Count-1].isBezierPoint())) * { * // draw last Bezier curve * * * } */ // path = Clipper.CleanPolygon(path, .01f); // if (path != null) // { // if (! Clipper.Orientation(path)) // path.Reverse(); // // } P_Output.controlPaths.Add(path); P_Output.transformedControlPaths = P_Output.getTransformedControlPaths(); P_Output.paths = P_Output.getTransformedControlPaths(); // may be altered before generate is over... P_Output.polyTree = null; base.generate(false, initiator_po, isReplica); } else { Debug.Log("no path"); } base.generate(false, initiator_po, isReplica); calculateBounds(); return(null); }