示例#1
0
    int NearestLine(out Vector3 position)
    {
        var near     = -1;
        var nearDist = float.MaxValue;

        position = keyPoints[0];
        var linePos = Vector3.zero;

        for (int i = 0; i < keyPoints.Count; i++)
        {
            var j      = (i + 1) % keyPoints.Count;
            var line   = keyPoints[j] - keyPoints[i];
            var offset = mousePosition - keyPoints[i];
            var dot    = Vector3.Dot(line.normalized, offset);
            if (dot >= 0 && dot <= line.magnitude)
            {
                if (isCurve[i])
                {
                    linePos = Bezier.Curve(keyPoints[i], Bezier.Control(keyPoints[i], keyPoints[j], curvePoints[i]), keyPoints[j], dot / line.magnitude);
                }
                else
                {
                    linePos = keyPoints[i] + line.normalized * dot;
                }
                var dist = Vector3.Distance(linePos, mousePosition);
                if (dist < nearDist)
                {
                    nearDist = dist;
                    position = linePos;
                    near     = i;
                }
            }
        }
        return(near);
    }
示例#2
0
文件: PolyMesh.cs 项目: ku4er/test1
    public List <Vector3> GetEdgePoints()
    {
        //Build the point list and calculate curves
        var points = new List <Vector3>();

        for (int i = 0; i < keyPoints.Count; i++)
        {
            if (isCurve[i])
            {
                //Get the curve control point
                var a = keyPoints[i];
                var c = keyPoints[(i + 1) % keyPoints.Count];
                var b = Bezier.Control(a, c, curvePoints[i]);

                //Build the curve
                var count = Mathf.Ceil(1 / curveDetail);
                for (int j = 0; j < count; j++)
                {
                    var t = (float)j / count;
                    points.Add(Bezier.Curve(a, b, c, t));
                }
            }
            else
            {
                points.Add(keyPoints[i]);
            }
        }
        return(points);
    }
示例#3
0
    void DrawSegment(int index)
    {
        var from = keyPoints[index];
        var to   = keyPoints[(index + 1) % keyPoints.Count];

        if (isCurve[index])
        {
            var control = Bezier.Control(from, to, curvePoints[index]);
            var count   = Mathf.Ceil(1 / polyMesh.curveDetail);
            for (int i = 0; i < count; i++)
            {
                Handles.DrawLine(Bezier.Curve(from, control, to, i / count), Bezier.Curve(from, control, to, (i + 1) / count));
            }
        }
        else
        {
            Handles.DrawLine(from, to);
        }
    }