示例#1
0
        public void OnSceneGUI()
        {
            BezierNode bn = (BezierNode)target;

            Undo.RecordObject(bn, "Edit Bezier Handles");
            Quaternion _lookH1 = Quaternion.identity;
            Quaternion _lookH2 = Quaternion.identity;
            // 'Local' mode doesn't work - results in spiral behaviour on transverse handle movement

            /*
             * if (Tools.pivotRotation == PivotRotation.Local){
             *      _lookH1 = Quaternion.LookRotation(bn.h1 - bn.transform.position, bn.transform.up);
             *      _lookH2 = Quaternion.LookRotation(bn.h2 - bn.transform.position, bn.transform.up);
             * }
             */
            Vector3 h1 = Handles.PositionHandle(bn.h1, _lookH1);

            if (h1 != bn.h1)
            {
                bn.h1 = h1;
                EditorUtility.SetDirty(bn);
            }
            Vector3 h2 = Handles.PositionHandle(bn.h2, _lookH2);

            if (h2 != bn.h2)
            {
                bn.h2 = h2;
                EditorUtility.SetDirty(bn);
            }
        }
示例#2
0
    public void SaveJson()
    {
        JsonData jd = new JsonData();

        JsonData Arr = new JsonData();


        foreach (RawImageWarp item in rawImageWarps)
        {
            CornerNode cornerNode = new CornerNode(item.cornerOffsetTL, item.cornerOffsetTR, item.cornerOffsetBR, item.cornerOffsetBL);
            BezierNode bezierNode = new BezierNode(true, item.topBezierHandleA, item.topBezierHandleB, item.leftBezierHandleA, item.leftBezierHandleB, item.rightBezierHandleA, item.rightBezierHandleB, item.bottomBezierHandleA, item.bottomBezierHandleB);

            Display temp = new Display(rawImageWarps.IndexOf(item) + 1, cornerNode, bezierNode);

            Arr.Add(ConvertClassToJsonData(temp));
        }
        jd["Display"] = Arr;//标题

        JsonData data = new JsonData();

        data["info"] = jd;//大分类

        string json = data.ToJson();

        List <string> tempJsonStringArray = new List <string>();

        tempJsonStringArray.Add(json);

        UpdateJson(tempJsonStringArray.ToArray());
    }
    void DrawNode(BezierNode start, BezierNode end, Vector3 position, int linecount = 16)
    {
        var a    = start.NodePos + position;
        var b    = a + start.NextDir;
        var d    = end.NodePos + position;
        var c    = d + end.LastDir;
        var last = a;

        for (int i = 1; i <= linecount; i++)
        {
            float r = i;
            r /= linecount;
            var p = MathH.BezierPoint(r, ref a, ref b, ref c, ref d);
            Handles.DrawLine(last, p);
            last = p;
        }
    }
    public Vector3 CalculateFullBezier(float input)
    {
        input = Mathf.Clamp(input, 0, NodeLength - 1);

        if (input == 0)
        {
            return(StartNode.RootNode.position);
        }
        if (input == NodeLength - 1)
        {
            return(EndNode.RootNode.position);
        }

        int firstNode = Mathf.FloorToInt(input);

        BezierNode NodeA = GetClosestNode(firstNode);
        BezierNode NodeB = GetClosestNode(firstNode + 1);

        return(Vector3Bezier(input % 1, NodeA.RootNode.position, NodeA.AfterNode.position, NodeB.BeforeNode.position, NodeB.RootNode.position));
    }
 void AddNode(List <BezierNode> nodes)
 {
     if (nodes.Count > 0)
     {
         var        last = nodes[nodes.Count - 1];
         BezierNode node = new BezierNode();
         node.NodePos    = last.LastDir;
         node.LastDir    = last.LastDir;
         node.NextDir    = last.NextDir;
         node.NodePos.x += 20;
         node.NodePos.y += 20;
         nodes.Add(node);
     }
     else
     {
         BezierNode node = new BezierNode();
         node.LastDir.y = -10;
         node.NextDir.x = 10;
         nodes.Add(node);
     }
 }
示例#6
0
	public void Add(BezierNode Node){
		if (closed){
			if (mapped){
				length -= Curve[Curve.Count - 1].Length;
			}
			Curve.RemoveAt(Curve.Count - 1);
			closed = false;
		}
		if (Curve.Count > 0){
			BezierSegment segment = new BezierSegment(Curve[Curve.Count - 1].End, Node);
			Curve.Add(segment);
		}
		else if (firstNode != null) {
			BezierSegment segment = new BezierSegment(firstNode, Node);
			Curve.Add(segment);
		}
		else {
			firstNode = Node;
		}
		if (mapped){
			Curve[Curve.Count - 1].Map(resolution);
			length += Curve[Curve.Count - 1].Length;
		}
	}
    private void OnDrawGizmos()
    {
        OnDrawGizmosSelected();
        for (int i = 0; i < NodeLength - 1; i++)
        {
            BezierNode NodeA = GetClosestNode(i);
            BezierNode NodeB = GetClosestNode(i + 1);


            Handles.DrawBezier(NodeA.RootNode.position, NodeB.RootNode.position, NodeA.AfterNode.position, NodeB.BeforeNode.position, Color.green, null, 2f);
        }

        if (UnityEditor.Selection.activeGameObject == gameObject)
        {
            return;
        }

        Handles.Label(StartNode.RootNode.transform.position, "0");
        Handles.Label(EndNode.RootNode.transform.position, (MidNodes.Count + 1).ToString());
        for (int i = 0; i < MidNodes.Count; i++)
        {
            Handles.Label(MidNodes[i].RootNode.transform.position, (i + 1).ToString());
        }
    }
示例#8
0
文件: Curves.cs 项目: Juhlinus/Comora
 public static Vector2 Bezier(float time, BezierNode start, BezierNode end)
 {
     return(Bezier(time, start.Point, start.Direction, end.Point, end.Direction));
 }
示例#9
0
 public Display(int _index, CornerNode _cornerNode, BezierNode _bezierNodes)
 {
     index       = _index;
     cornerNode  = _cornerNode;
     bezierNodes = _bezierNodes;
 }
示例#10
0
	public BezierSegment(BezierNode Start, BezierNode End){
		this.Start = Start;
		this.End = End;
	}