コード例 #1
0
    protected override void OnDraw(LineCanvas canvas)
    {
        var     e  = GetEntity(0);
        Vector3 p0 = e.PointOnInPlane(0.0, null).Eval();
        Vector3 p1 = e.PointOnInPlane(1.0, null).Eval();

        Vector3 t0    = e.TangentAtInPlane(0.0, null).Eval().normalized;
        Vector3 t1    = e.TangentAtInPlane(1.0, null).Eval().normalized;
        Vector3 n     = e.plane.n.normalized;
        Vector3 perp0 = Vector3.Cross(t0, n);
        Vector3 perp1 = Vector3.Cross(t1, n);
        float   pix   = getPixelSize();

        canvas.DrawLine(p0, p0 + perp0 * 25f * pix);
        canvas.DrawLine(p1, p1 + perp1 * 25f * pix);

        e.DrawParamRange(canvas, 20f * pix, 0.0, 1.0, 0.05, null);
        pos = e.OffsetAtInPlane(0.5, 30f * pix, null).Eval();

        var  ap0    = e.OffsetAtInPlane(0.0, 20f * pix, null).Eval();
        var  ap1    = e.OffsetAtInPlane(1.0, 20f * pix, null).Eval();
        bool stroke = (ap0 - ap1).magnitude < (R_ARROW_W * 2f + 1f) * pix;

        drawArrow(canvas, ap0, -e.TangentAtInPlane(0.0, null).Eval(), stroke);
        drawArrow(canvas, ap1, e.TangentAtInPlane(1.0, null).Eval(), stroke);
    }
コード例 #2
0
    void drawTangentCross(LineCanvas renderer, Vector3 pos, Vector3 dir, Vector3 pn, float pix)
    {
        float   size = 10f * pix;
        Vector3 perp = Vector3.Cross(dir, pn);

        renderer.DrawLine(pos - perp * size, pos + perp * size);
        renderer.DrawLine(pos - dir * size, pos + dir * size);
    }
コード例 #3
0
    public static List <Vector3> Triangulate(List <Vector3> points, LineCanvas canvas = null)
    {
        List <Vector3> result    = new List <Vector3>();
        bool           processed = true;

        while (points.Count > 2 && processed)
        {
            processed = false;
            for (int i = 0; i < points.Count; i++)
            {
                var a = points[(i - 1 + points.Count) % points.Count];
                var b = points[i];
                var c = points[(i + 1) % points.Count];

                if (IsConvex(a, b, c))
                {
                    bool contains = false;
                    for (int j = 0; j < points.Count; j++)
                    {
                        if (j == i || j == i - 1 || j == i + 1)
                        {
                            continue;
                        }
                        if (!TriangleContains2d(a, b, c, points[j]))
                        {
                            continue;
                        }
                        contains = true;
                        break;
                    }
                    if (!contains)
                    {
                        if (canvas)
                        {
                            canvas.DrawLine(a, b);
                            canvas.DrawLine(b, c);
                            canvas.DrawLine(c, a);
                        }
                        result.Add(a);
                        result.Add(b);
                        result.Add(c);
                        points.RemoveAt(i--);
                        processed = true;
                        if (points.Count < 3)
                        {
                            break;
                        }
                    }
                }
            }
        }
        return(result);
    }
コード例 #4
0
    protected void drawBasis(LineCanvas canvas)
    {
        var     basis = GetBasis();
        var     pix   = getPixelSize();
        Vector3 vx    = basis.GetColumn(0);
        Vector3 vy    = basis.GetColumn(1);
        //Vector3 vz = basis.GetColumn(2);
        Vector3 p = basis.GetColumn(3);

        canvas.DrawLine(p, p + vx * 10f * pix);
        canvas.DrawLine(p, p + vy * 10f * pix);
    }
コード例 #5
0
    void DrawStroke(LineCanvas canvas, IEntity line, int rpt)
    {
        var     p0   = line.GetPointAtInPlane(0, null).Eval();
        var     p1   = line.GetPointAtInPlane(1, null).Eval();
        float   len  = (p1 - p0).magnitude;
        float   size = Mathf.Min(len, 10f * getPixelSize());
        Vector3 dir  = (p1 - p0).normalized * size / 2f;
        Vector3 perp = Vector3.Cross(p1 - p0, Vector3.forward).normalized * 3f * getPixelSize();
        Vector3 pos  = (p1 + p0) / 2f;

        ref_points[rpt] = sketch.plane.ToPlane(pos);
        canvas.DrawLine(pos + dir + perp, pos - dir + perp);
        canvas.DrawLine(pos + dir - perp, pos - dir - perp);
    }
コード例 #6
0
ファイル: Diameter.cs プロジェクト: mmiscool/NoteCAD
    protected override void OnDraw(LineCanvas canvas)
    {
        var pl  = getPlane();
        var p   = GetEntity(0).CenterInPlane(null).Eval();
        var lo  = getPlane().projectVectorInto(getLabelOffset());
        var dir = (lo - p).normalized;

        float r = (float)value.exp.Eval() / 2f;



        if (showAsRadius)
        {
            var rpt  = p + dir * r;
            var rdir = lo - rpt;
            drawPointsDistance(p, p + dir * r, canvas, Camera.main, arrow0: false, arrow1: true);
            canvas.DrawLine(rpt, lo);
        }
        else
        {
            drawPointsDistance(p - dir * r, p + dir * r, canvas, Camera.main);
        }

        //drawLabel(renderer, camera, "Ø" + getValueString());
    }
コード例 #7
0
 protected override void OnDraw(LineCanvas canvas)
 {
     canvas.SetStyle("entities");
     ForEachSegment((a, b) => {
         canvas.DrawLine(a, b);
     });
 }
コード例 #8
0
ファイル: HVConstraint.cs プロジェクト: ttldtor/NoteCAD
    void DrawStroke(LineCanvas canvas, LineEntity line)
    {
        Vector3 dir  = (line.p1.GetPosition() - line.p0.GetPosition()).normalized;
        Vector3 perp = Vector3.Cross(dir, Vector3.forward);
        Vector3 pos  = (line.p1.GetPosition() + line.p0.GetPosition()) / 2f;

        canvas.DrawLine(pos + perp, pos - perp);
    }
コード例 #9
0
ファイル: Constraint.cs プロジェクト: lUllLabs/NoteCAD
    protected void drawArrow(LineCanvas canvas, Vector3 pos, Vector3 dir, bool stroke = false)
    {
        dir = dir.normalized;
        var f   = getVisualPlaneDir(Camera.main.transform.forward);
        var n   = Vector3.Cross(dir, f).normalized;
        var pix = getPixelSize();

        // if label ourside distance area or sceren distance not too small, draw arrows
        if (!stroke)
        {
            canvas.DrawLine(pos, pos - n * R_ARROW_H * pix - dir * R_ARROW_W * pix);
            canvas.DrawLine(pos, pos + n * R_ARROW_H * pix - dir * R_ARROW_W * pix);
        }
        else
        {
            canvas.DrawLine(pos - n * R_ARROW_H * pix + dir * R_ARROW_H * pix, pos + n * R_ARROW_H * pix - dir * R_ARROW_H * pix);
        }
    }
コード例 #10
0
    void drawGrounding(LineCanvas renderer, Camera camera, Vector3 pos, float size)
    {
        Vector3 x = camera.transform.right * size;
        Vector3 y = -camera.transform.up * size;

        renderer.DrawLine(pos, pos + y * 5f);
        renderer.DrawLine(pos + y * 5f + x * 5f, pos + y * 5f - x * 3f);

        // physical ground
        for (float i = -3f; i <= 5f; i += 2f)
        {
            renderer.DrawLine(pos + y * 5f + x * i, pos + y * 8f + x * (i - 2f));
        }

        // electronic ground
        // renderer.DrawLine(pos + y * 8f + x * 3f, pos + y * 8f - x * 3f);
        // renderer.DrawLine(pos + y * 11f + x * 1f, pos + y * 11f - x * 1f);
    }
コード例 #11
0
    void DrawStroke(LineCanvas canvas, Vector3 p0, Vector3 p1, int rpt)
    {
        float   len  = (p1 - p0).magnitude;
        float   size = Mathf.Min(len, 20f * getPixelSize());
        Vector3 dir  = (p1 - p0).normalized * size / 2f;
        Vector3 pos  = (p1 + p0) / 2f;

        ref_points[rpt] = sketch.plane.ToPlane(pos);
        canvas.DrawLine(pos + dir, pos - dir);
    }
コード例 #12
0
ファイル: EqualLineLine.cs プロジェクト: ttldtor/NoteCAD
    void DrawStroke(LineCanvas canvas, IEntity line, int rpt)
    {
        var     p0   = line.GetPointAtInPlane(0, null).Eval();
        var     p1   = line.GetPointAtInPlane(1, null).Eval();
        Vector3 dir  = (p1 - p0).normalized;
        Vector3 perp = Vector3.Cross(dir, Vector3.forward) * 5f * getPixelSize();
        Vector3 pos  = (p1 + p0) / 2f;

        ref_points[rpt] = pos;
        canvas.DrawLine(pos + perp, pos - perp);
    }
コード例 #13
0
    protected void drawCameraCircle(LineCanvas renderer, Camera camera, Vector3 pos, float size, int num_segments = 32)
    {
        float   angle = 2f * Mathf.PI / (float)num_segments;
        Vector3 r0    = camera.transform.right * size;

        for (int i = 0; i < num_segments; i++)
        {
            Vector3 r1 = rotatedAbout(r0, camera.transform.forward, angle);
            renderer.DrawLine(pos + r0, pos + r1);
            r0 = r1;
        }
    }
コード例 #14
0
    protected override void OnDraw(LineCanvas canvas)
    {
        var l0  = GetEntity(0);
        var dir = l0.TangentAt(t0).Eval();

        dir = l0.plane.DirFromPlane(dir).normalized;
        var perp = Vector3.Cross(dir, sketch.plane.n).normalized;
        var pos  = l0.PointOnInPlane(t0, null).Eval();

        ref_points[0] = ref_points[1] = sketch.plane.ToPlane(pos);
        var size = getPixelSize() * 10f;

        perp *= size;
        dir  *= size;

        canvas.DrawLine(pos + dir, pos - dir);
        canvas.DrawLine(pos - perp, pos + perp);

        //GetEntity(0).DrawExtend(canvas, t0.value, 0.05);
        //GetEntity(1).DrawExtend(canvas, t1.value, 0.05);
    }
コード例 #15
0
ファイル: HVConstraint.cs プロジェクト: mmiscool/NoteCAD
    void DrawStroke(LineCanvas canvas, IEntity pt0, IEntity pt1, int rpt)
    {
        var     p0   = pt0.GetPointAtInPlane(0, null).Eval();
        var     p1   = pt1.GetPointAtInPlane(0, null).Eval();
        float   len  = (p1 - p0).magnitude;
        float   size = Mathf.Min(len, 20f * getPixelSize());
        Vector3 dir  = (p1 - p0).normalized * size / 2f;
        Vector3 pos  = (p1 + p0) / 2f;

        ref_points[rpt] = sketch.plane.ToPlane(pos);
        canvas.DrawLine(pos + dir, pos - dir);
    }
コード例 #16
0
    void DrawStroke(LineCanvas canvas, IEntity e, int rpt)
    {
        Vector3 dir  = e.TangentAtInPlane(0.5, null).Eval();
        Vector3 perp = Vector3.Cross(dir, Camera.main.transform.forward).normalized * 5f * getPixelSize();
        Vector3 pos  = e.PointOnInPlane(0.5, null).Eval();

        ref_points[rpt] = sketch.plane.ToPlane(pos);
        if (rpt == 0)
        {
            this.pos = e.OffsetAtInPlane(0.5, 20f * getPixelSize(), null).Eval();
        }
        canvas.DrawLine(pos + perp, pos - perp);
    }
コード例 #17
0
    protected void drawDottedLine(Vector3 p0, Vector3 p1, LineCanvas renderer, float step)
    {
        if (step == 0f)
        {
            renderer.DrawLine(p0, p1);
            return;
        }
        float   len   = length(p1 - p0);
        Vector3 dir   = normalize(p1 - p0);
        Vector3 p     = p0;
        int     count = (int)Math.Floor(len / step);

        if (count > 1000)
        {
            count = 1000;
            step  = len / (count - 1f);
        }

        bool draw = 0 % 2 == 0;

        for (int i = 0; i < count; i++)
        {
            if (draw)
            {
                renderer.DrawLine(p, p + dir * step);
            }
            p   += dir * step;
            draw = (i + 1) % 2 == 0;
        }
        if (draw)
        {
            float frac = len - count * step;
            if (draw)
            {
                renderer.DrawLine(p, p + dir * frac);
            }
        }
    }
コード例 #18
0
    void DrawPointStroke(LineCanvas canvas, Vector3 p0, Vector3 p1, int rpt)
    {
        if (rpt == 1)
        {
            var t = p0;
            p0 = p1;
            p1 = t;
        }
        float   size = 20f * getPixelSize();
        Vector3 dir  = (p1 - p0).normalized * size / 2f;

        ref_points[rpt] = sketch.plane.ToPlane(p0);
        canvas.DrawLine(p0, p0 + dir);
    }
コード例 #19
0
ファイル: Entity.cs プロジェクト: lUllLabs/NoteCAD
 protected override void OnDraw(LineCanvas canvas)
 {
     if (isError)
     {
         canvas.SetStyle("error");
     }
     else
     {
         canvas.SetStyle("entities");
     }
     ForEachSegment((a, b) => {
         canvas.DrawLine(a, b);
     });
 }
コード例 #20
0
    protected void drawArc(LineCanvas renderer, Vector3 p0, Vector3 p1, Vector3 c, Vector3 vz, bool dash = false, float step = 0f)
    {
        float angle  = Mathf.Acos(Vector3.Dot(normalize(p0 - c), normalize(p1 - c)));
        float subdiv = 32f;

        if (step > 0f)
        {
            float len = length(p0 - c) * angle;
            subdiv = len / step;
            if (subdiv > 1000f)
            {
                subdiv = 1000f;
            }
        }

        if (Vector3.Dot(Vector3.Cross(p0 - c, p1 - c), vz) < 0f)
        {
            angle = -angle;
        }

        Vector3 rv  = p0 - c;
        Vector3 orv = rv;

        float i     = 0f;
        int   index = 0;

        while (i < subdiv)
        {
            i += 1f;
            if (i > subdiv)
            {
                i = subdiv;
            }
            Vector3 nrv = rotatedAbout(rv, vz, angle / subdiv * i);
            if (!dash || index % 2 == 0)
            {
                renderer.DrawLine(orv + c, nrv + c);
            }
            orv    = nrv;
            index += 1;
        }
    }
コード例 #21
0
    public static void DrawParamRange(this IEntity e, LineCanvas canvas, double offset, double begin, double end, double step, IPlane plane)
    {
        Vector3 prev    = Vector3.zero;
        bool    first   = true;
        int     count   = (int)Math.Ceiling(Math.Abs(end - begin) / step);
        Param   t       = new Param("t");
        var     PointOn = e.OffsetAtInPlane(t, offset, plane);

        for (int i = 0; i <= count; i++)
        {
            t.value = begin + (end - begin) * i / count;
            var p = PointOn.Eval();
            if (!first)
            {
                canvas.DrawLine(prev, p);
            }
            first = false;
            prev  = p;
        }
    }
コード例 #22
0
 protected override void OnUpdateDirty()
 {
     if (edges == null)
     {
         if (canvas == null)
         {
             go     = new GameObject("MeshImportFeature");
             canvas = GameObject.Instantiate(EntityConfig.instance.lineCanvas, go.transform);
         }
         else
         {
             canvas.Clear();
         }
         canvas.SetStyle("entities");
         if (useThreshold)
         {
             edges = meshCheck.GenerateEdges(thresholdAngle);
         }
         else
         {
             edges = new List <Pair <Vector3, Vector3> >();
             var indices  = mesh.GetIndices(0);
             var vertices = mesh.vertices;
             for (int i = 0; i < indices.Length / 3; i++)
             {
                 for (int j = 0; j < 3; j++)
                 {
                     edges.Add(new Pair <Vector3, Vector3>(vertices[indices[i * 3 + j]], vertices[indices[i * 3 + (j + 1) % 3]]));
                 }
             }
         }
         foreach (var edge in edges)
         {
             canvas.DrawLine(edge.a, edge.b);
         }
         meshCheck.drawErrors(canvas);
     }
     go.transform.SetMatrix(basis.matrix);
     go.SetActive(visible);
 }
コード例 #23
0
    public void drawErrors(LineCanvas renderer)
    {
        int i = 0;

        int num_errors = 0;

        foreach (Edge e in edges.Values)
        {
            if (e.triangles.Count == 2)
            {
                continue;
            }
            i++;
            num_errors++;
            //switch(e.triangles.size()) {
            switch (e.triangles.Count)
            {
            case 1:
                renderer.SetStyle("error");
                break;

            case 2: {
                renderer.SetStyle("entities");
                break;
            }

            default:
                renderer.SetStyle("hovered");
                break;
            }
            renderer.DrawLine(e.a.pos, e.b.pos);
        }
        if (num_errors != 0)
        {
            //Debug.Log("Achtung!!! STL check num_errors = %d\n", num_errors);
        }
    }
コード例 #24
0
    protected void drawAngleArc(LineCanvas renderer, Vector3 p0, Vector3 c, float angle, Vector3 vz, bool dash = false, float step = 0f)
    {
        float subdiv = 32f;

        if (step > 0f)
        {
            float len = length(p0 - c) * angle;
            subdiv = len / step;
            if (subdiv > 1000f)
            {
                subdiv = 1000f;
            }
        }

        Vector3 rv  = p0 - c;
        Vector3 orv = rv;

        float i     = 0f;
        int   index = 0;

        while (i < subdiv)
        {
            i += 1f;
            if (i > subdiv)
            {
                i = subdiv;
            }
            Vector3 nrv = rotatedAbout(rv, vz, angle / subdiv * i);
            if (!dash || index % 2 == 0)
            {
                renderer.DrawLine(orv + c, nrv + c);
            }
            orv    = nrv;
            index += 1;
        }
    }
コード例 #25
0
 protected override void OnUpdateDirty()
 {
     if (edges == null)
     {
         if (canvas == null)
         {
             go     = new GameObject("MeshImportFeature");
             canvas = GameObject.Instantiate(EntityConfig.instance.lineCanvas, go.transform);
         }
         else
         {
             canvas.Clear();
         }
         canvas.SetStyle("entities");
         edges = meshCheck.GenerateEdges(thresholdAngle);
         foreach (var edge in edges)
         {
             canvas.DrawLine(edge.a, edge.b);
         }
         meshCheck.drawErrors(canvas);
     }
     go.transform.SetMatrix(basis.matrix);
     go.SetActive(visible);
 }
コード例 #26
0
    protected void drawPointLineDistance(Vector3 lip0_, Vector3 lip1_, Vector3 p0_, LineCanvas renderer, Camera camera)
    {
        float pix = getPixelSize();

        Vector3 lip0 = drawPointProjection(renderer, lip0_, R_DASH * pix);
        Vector3 lip1 = drawPointProjection(renderer, lip1_, R_DASH * pix);
        Vector3 p0   = drawPointProjection(renderer, p0_, R_DASH * pix);

        if (lip0 != lip0_ || lip1 != lip1_)
        {
            drawDottedLine(lip0, lip1, renderer, R_DASH * pix);
        }

        Matrix4x4 basis = getPointLineDistanceBasis(lip0, lip1, p0, getPlane());

        Vector3 lid = normalize(lip1 - lip0);

        Vector3 p1 = lip0 + lid * Vector3.Dot(p0 - lip0, lid);

        Vector3 vx = basis.GetColumn(0);
        Vector3 vy = basis.GetColumn(1);
        Vector3 vp = basis.GetColumn(3);

        Vector3 label_offset = getLabelOffset();
        Vector3 offset       = Vector3.zero;

        offset.x = Vector3.Dot(label_offset - vp, vx);
        offset.y = Vector3.Dot(label_offset - vp, vy);

        // sgn label y
        float sy = ((offset.y > EPSILON) ? 1f : 0f) - ((offset.y < -EPSILON) ? 1f : 0f);

        Vector3 lp0 = p0 + vy * offset.y;
        Vector3 lp1 = p1 + vy * offset.y;

        // vertical lines
        renderer.DrawLine(p0, lp0 + vy * 8f * pix * sy);

        float lk = Vector3.Dot(lp1 - lip0, lid);

        if (lk < 0f)
        {
            renderer.DrawLine(lip0, lp1 + normalize(lp1 - lip0) * 8f * pix);
        }
        else if (lk > length(lip1 - lip0))
        {
            renderer.DrawLine(lip1, lp1 + normalize(lp1 - lip1) * 8f * pix);
        }

        // distance line
        renderer.DrawLine(lp0, lp1);

        // sgn arrow x
        float sx = 1f;

        // half distance
        float half_dist = length(p0 - p1) * 0.5f;

        if (Mathf.Abs(offset.x) > half_dist)
        {
            sx = -1f;
        }

        if (sx < 0f || length(lp0 - lp1) > (R_ARROW_W * 2f + 1f) * pix)
        {
            // arrow lp0
            renderer.DrawLine(lp0, lp0 - vy * R_ARROW_H * pix + vx * R_ARROW_W * pix * sx);
            renderer.DrawLine(lp0, lp0 + vy * R_ARROW_H * pix + vx * R_ARROW_W * pix * sx);

            // arrow lp1
            renderer.DrawLine(lp1, lp1 - vy * R_ARROW_H * pix - vx * R_ARROW_W * pix * sx);
            renderer.DrawLine(lp1, lp1 + vy * R_ARROW_H * pix - vx * R_ARROW_W * pix * sx);
        }
        else
        {
            // stroke lp0
            renderer.DrawLine(lp0 - vy * R_ARROW_H * pix + vx * R_ARROW_H * pix, lp0 + vy * R_ARROW_H * pix - vx * R_ARROW_H * pix);

            // stroke lp1
            renderer.DrawLine(lp1 - vy * R_ARROW_H * pix + vx * R_ARROW_H * pix, lp1 + vy * R_ARROW_H * pix - vx * R_ARROW_H * pix);
        }

        Vector3 lv0 = lp0;
        Vector3 lv1 = lp1;

        //bool da1 = arrow1;

        // if label lays from other side
        if (offset.x > half_dist)
        {
            lv0 = lp1;
            lv1 = lp0;
            //da1 = arrow0;
        }

        // if label is ouside
        if (Mathf.Abs(offset.x) > half_dist)
        {
            Vector3 dir = vp + vy * offset.y + vx * offset.x - lv0;
            float   len = Mathf.Max(length(dir), 21f * pix);

            // line to the label
            renderer.DrawLine(lv0, lv0 + normalize(dir) * len);

            // opposite arrow line
            /*if(da1)*/ renderer.DrawLine(lv1, lv1 - normalize(dir) * 21f * pix);
            setRefPoint(lv0 + normalize(dir) * (len + 16f * pix));
        }
        else
        {
            setRefPoint(basis.MultiplyPoint(offset) + vy * sy * 13f * pix);
        }

        //drawLabel(renderer, camera);
    }
コード例 #27
0
    /*
     * protected override void OnDraw(LineCanvas canvas) {
     *      var l0 = GetEntityOfType(IEntityType.Line, 0);
     *      var l1 = GetEntityOfType(IEntityType.Line, 1);
     *      DrawStroke(canvas, l0, 0);
     *      DrawStroke(canvas, l1, 1);
     *      if(DetailEditor.instance.hovered == this) {
     *              DrawReferenceLink(canvas, Camera.main);
     *      }
     * }
     */
    protected override void OnDraw(LineCanvas canvas)
    {
        var line0 = GetEntityOfType(IEntityType.Line, 0);
        var line1 = GetEntityOfType(IEntityType.Line, 1);

        ExpVector p0 = null;
        ExpVector p1 = null;
        ExpVector p2 = null;

        for (int i = 0; i < 2; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                if (line0.GetPointAtInPlane(i, null).ValuesEquals(line1.GetPointAtInPlane(j, null), 1e-6))
                {
                    p0 = line0.GetPointAtInPlane(i, null);
                    p1 = line0.GetPointAtInPlane((i + 1) % 2, null);
                    p2 = line1.GetPointAtInPlane((j + 1) % 2, null);
                }
            }
        }

        float pix = getPixelSize();

        if (p0 != null)
        {
            Vector3 p    = p0.Eval();
            Vector3 dir1 = p1.Eval() - p;
            Vector3 dir2 = p2.Eval() - p;
            dir1 = dir1.normalized * pix * 13f;
            dir2 = dir2.normalized * pix * 13f;
            Vector3 corner = p + dir1 + dir2;
            canvas.DrawLine(p + dir1, corner);
            canvas.DrawLine(p + dir2, corner);
            ref_points[0] = ref_points[1] = sketch.plane.ToPlane(corner);
        }
        else
        {
            for (int i = 0; i < 2; i++)
            {
                var     line   = GetEntityOfType(IEntityType.Line, i);
                Vector3 a      = line.GetPointAtInPlane(0, null).Eval();
                Vector3 b      = line.GetPointAtInPlane(1, null).Eval();
                Vector3 dir    = normalize(a - b);
                Vector3 center = a + (b - a) * 0.5f;

                Vector3 plane = getVisualPlaneDir(Camera.main.transform.forward);

                Vector3 perp = normalize(Vector3.Cross(dir, plane));
                Vector3 p    = center - perp * pix * 8.0f;
                canvas.DrawLine(p - dir * pix * 8.0f, p + dir * pix * 8.0f);
                canvas.DrawLine(p, p - perp * pix * 13.0f);
                ref_points[i] = sketch.plane.ToPlane(p - perp * pix * 6.0f);
            }

            if (DetailEditor.instance.hovered == this)
            {
                DrawReferenceLink(canvas, Camera.main);
            }
        }
    }
コード例 #28
0
ファイル: AngleConstraint.cs プロジェクト: ttldtor/NoteCAD
    protected override void OnDraw(LineCanvas renderer)
    {
        //drawBasis(renderer, camera);
        var basis = GetBasis();
        //Vector3 vy = basis.GetColumn(1);
        Vector3 vz = basis.GetColumn(2);
        Vector3 p  = basis.GetColumn(3);

        float pix = getPixelSize();

        var plane  = getPlane();
        var value  = GetValue();
        var offset = localPos;

        if (Math.Abs(value) > EPSILON)
        {
            Vector3[] pts = GetPointsInPlane(null);

            Vector3 dir0 = plane.projectVectorInto(pts[0]) - plane.projectVectorInto(pts[1]);
            Vector3 dir1 = plane.projectVectorInto(pts[3]) - plane.projectVectorInto(pts[2]);

            Vector3 rref = pos;
            float   size = (length(p - rref) - 15f * pix);
            size = Mathf.Max(15f * pix, size);
            float y_sgn = 1f;            //(offset.y < 0f) ? -1f : 1f;

            Vector3 pt0 = p + normalize(dir0) * size * y_sgn;
            Vector3 pt1 = p + normalize(dir1) * size * y_sgn;
            Vector3 spt = pt0;
            if (offset.x * y_sgn < 0.0)
            {
                spt = pt1;
            }

            // arc to the label
            drawArc(renderer, spt, rref, p, vz);

            if (HasEntitiesOfType(IEntityType.Arc, 1))
            {
                renderer.DrawLine(pts[0], pt0);
                renderer.DrawLine(pts[3], pt1);
            }
            else
            {
                drawLineExtendInPlane(plane, renderer, pts[1], pts[0], pt0, 0f, 4f * pix, false);
                drawLineExtendInPlane(plane, renderer, pts[2], pts[3], pt1, 0f, 4f * pix, false);
            }
            double angle = value;

            bool less180 = Math.Abs(angle) < 180.0 - EPSILON;

            if (length(pt0 - pt1) > (2.0 * R_ARROW_W + 4.0) * pix || !less180)
            {
                Vector3 dd = normalize(pt0 - pt1);
                if (length(pt0 - pt1) < EPSILON)
                {
                    dd = normalize(Vector3.Cross(dir1, vz));
                }

                // arrow 0
                Vector3 perp0 = normalize(Vector3.Cross(Vector3.Cross(dd, dir0), dir0)) * ((less180) ? 1f : -1f);
                Vector3 pc0   = normalize(pt0 + perp0 * R_ARROW_W * pix - p) * size + p;

                Vector3 bx0 = normalize(pc0 - pt0);
                Vector3 by0 = normalize(Vector3.Cross(bx0, vz));
                renderer.DrawLine(pt0, pt0 - by0 * R_ARROW_H * pix + bx0 * R_ARROW_W * pix);
                renderer.DrawLine(pt0, pt0 + by0 * R_ARROW_H * pix + bx0 * R_ARROW_W * pix);

                // arrow 1
                Vector3 perp1 = -normalize(Vector3.Cross(Vector3.Cross(dd, dir1), dir1)) * ((less180) ? 1f : -1f);
                Vector3 pc1   = normalize(pt1 + perp1 * R_ARROW_W * pix - p) * size + p;

                Vector3 bx1 = normalize(pc1 - pt1);
                Vector3 by1 = normalize(Vector3.Cross(bx1, vz));
                renderer.DrawLine(pt1, pt1 - by1 * R_ARROW_H * pix + bx1 * R_ARROW_W * pix);
                renderer.DrawLine(pt1, pt1 + by1 * R_ARROW_H * pix + bx1 * R_ARROW_W * pix);
            }

            // angle arc
            if (less180)
            {
                drawArc(renderer, pt0, pt1, p, vz);
            }
            else
            {
                drawAngleArc(renderer, pt0, p, (float)angle * Mathf.PI / 180f, -vz);
            }

            Vector3 refp = offset;
            refp.z = 0f;
            refp   = basis * refp;
            setRefPoint(p + normalize(refp - p) * (size + 15f * pix));
        }
        //drawLabel(renderer, camera);
    }
コード例 #29
0
    protected void drawPointsDistance(Vector3 pp0, Vector3 pp1, LineCanvas renderer, Camera camera, bool label, bool arrow0 = true, bool arrow1 = true, int style = 0)
    {
        float pix = getPixelSize();

        Vector3 p0 = drawPointProjection(renderer, pp0, R_DASH * pix);
        Vector3 p1 = drawPointProjection(renderer, pp1, R_DASH * pix);

        Matrix4x4 basis;

        if (getPlane() == null)
        {
            Vector3 p = getLabelOffset();
            Vector3 x = normalize(p1 - p0);
            Vector3 y;
            y = p - projectPointLine(p, p0, p1);
            if (length(y) < EPSILON)
            {
                y = Vector3.Cross(camera.transform.forward, x);
            }
            y = normalize(y);
            Vector3 z = Vector3.Cross(x, y);
            basis = UnityExt.Basis(x, y, z, (p0 + p1) * 0.5f);
        }
        else
        {
            basis = getPointsDistanceBasis(p0, p1, getPlane());
        }

        Vector3 vx = basis.GetColumn(0);
        Vector3 vy = basis.GetColumn(1);
        Vector3 vp = basis.GetColumn(3);

        Vector3 label_offset = getLabelOffset();
        Vector3 offset       = Vector3.zero;

        offset.x = Vector3.Dot(label_offset - vp, vx);
        offset.y = Vector3.Dot(label_offset - vp, vy);

        // sgn label y
        float sy = ((offset.y > EPSILON) ? 1f : 0f) - ((offset.y < -EPSILON) ? 1f : 0f);

        offset.y = sy * Mathf.Max(15f * pix, Mathf.Abs(offset.y));

        // distance line points
        Vector3 lp0 = p0 + vy * offset.y;
        Vector3 lp1 = p1 + vy * offset.y;

        // vertical lines
        if (Mathf.Abs(sy) > EPSILON)
        {
            Vector3 salient = vy * 8f * pix * sy;
            if (style == 0)
            {
                renderer.DrawLine(p0, lp0 + salient);
                renderer.DrawLine(p1, lp1 + salient);
            }
            else
            {
                renderer.DrawLine(lp0 - salient, lp0 + salient);
                renderer.DrawLine(lp1 - salient, lp1 + salient);
            }
        }

        // distance line
        renderer.DrawLine(lp0, lp1);

        // sgn arrow x
        float sx = 1f;

        // half distance
        float half_dist = length(p0 - p1) * 0.5f;

        // if label ouside
        if (Mathf.Abs(offset.x) > half_dist)
        {
            sx = -1f;
        }

        // if label ourside distance area or sceren distance not too small, draw arrows
        if ((sx < 0f || length(lp0 - lp1) > (R_ARROW_W * 2f + 1f) * pix) && style != 1)
        {
            // arrow lp0
            if (arrow0)
            {
                renderer.DrawLine(lp0, lp0 - vy * R_ARROW_H * pix + vx * R_ARROW_W * pix * sx);
                renderer.DrawLine(lp0, lp0 + vy * R_ARROW_H * pix + vx * R_ARROW_W * pix * sx);
            }

            // arrow lp1
            if (arrow1)
            {
                renderer.DrawLine(lp1, lp1 - vy * R_ARROW_H * pix - vx * R_ARROW_W * pix * sx);
                renderer.DrawLine(lp1, lp1 + vy * R_ARROW_H * pix - vx * R_ARROW_W * pix * sx);
            }
        }
        else
        {
            // stroke lp0
            renderer.DrawLine(lp0 - vy * R_ARROW_H * pix + vx * R_ARROW_H * pix, lp0 + vy * R_ARROW_H * pix - vx * R_ARROW_H * pix);

            // stroke lp1
            renderer.DrawLine(lp1 - vy * R_ARROW_H * pix + vx * R_ARROW_H * pix, lp1 + vy * R_ARROW_H * pix - vx * R_ARROW_H * pix);
        }

        Vector3 lv0 = lp0;
        Vector3 lv1 = lp1;
        bool    da1 = arrow1;

        // if label lays from other side
        if (offset.x > half_dist)
        {
            lv0 = lp1;
            lv1 = lp0;
            da1 = arrow0;
        }

        // if label is ouside
        if (Mathf.Abs(offset.x) > half_dist)
        {
            Vector3 dir = vp + vy * offset.y + vx * offset.x - lv0;
            float   len = Mathf.Max(length(dir), 21f * pix);

            // line to the label
            renderer.DrawLine(lv0, lv0 + normalize(dir) * len);

            // opposite arrow line
            if (da1)
            {
                renderer.DrawLine(lv1, lv1 - normalize(dir) * 21f * pix);
            }
            setRefPoint(lv0 + normalize(dir) * (len + 16f * pix));
        }
        else
        {
            setRefPoint(basis.MultiplyPoint(offset) + vy * sy * 13f * pix);
        }

        //drawCameraCircle(renderer, camera, getLabelOffset(), 3f * pix);
        //if(label) drawLabel(renderer, camera);
    }