Ejemplo n.º 1
0
        public object RegisterSnapItem(SnapItem Item)
        {
            if (Item == null)
            {
                return(null);
            }
            if (RegisterLocked)
            {
                return(null);
            }
            if ((Device.RenderKind != RenderKind.SnapBuffer) &&
                (!Entity.Compiling))
            {
                return(null);
            }
            if (CurrentSnapItem == null)
            {
                OpenGlDevice.CheckError();
                CurrentSnapItem = Item;
                if (!Item.Udated)
                {
                    Item.Device      = Device;
                    Item.ModelMatrix = Device.ModelMatrix;
                    if (Item.PolygonMode != PolygonMode.Point)
                    {
                        Item.PolygonMode = Device.PolygonMode;
                    }
                    Item.Object = Entity.CurrentEntity;
                    //if ((Item.Object != null) && (Item.Object is Entity))
                    //    (Item.Object as Entity).MySnapItem = Item;
                    Item.Udated = true;
                }
                else
                {
                }
                if (Tags.Count > 0)
                {
                    Item.Tag = Tags.Peek();
                }

                StoredSnapItems.Add(Item);

                GLShader S = Device.Shader;
                if (Entity.Compiling)
                {
                    //MeshCreator.SnapItem = Item;
                    //if (MeshCreator.MeshCurrent != null)
                    //    MeshCreator.MeshCurrent.ObjectNumber = (int)CurrentObject;
                }
                OpenGlDevice.CheckError();
                if (Device.Shader == PickingShader)
                {
                    S.SetVar(CurrentObjectIndex, (int)CurrentObject);
                }
                OpenGlDevice.CheckError();
                return(Item);
            }
            return(null);
        }
Ejemplo n.º 2
0
 public void UnRegisterSnapItem(object Handle)
 {
     if ((Handle != CurrentSnapItem) || (CurrentSnapItem == null))
     {
         return;
     }
     if (Device.RenderKind == RenderKind.SnapBuffer)
     {
     }
     // if (Entity.Compiling) MeshCreator.Renew();
     CurrentSnapItem = null;
 }
Ejemplo n.º 3
0
        bool intersectPlaneWithLine(SnapItem Plane, SnapItem Line, xyzArray LineArray, ref double Lam, ref xyz Result)
        {
            TriangleF T = Plane.GetTriangle();

            if (T == null)
            {
                return(false);
            }
            xyz N1 = ((T.B - T.A) & (T.C - T.A)).Toxyz();

            if (LineArray == null)
            {
            }
            xyz N2 = LineArray.cross();

            if ((N1 & N2).length() < 0.00001)   // Parallel
            {
                xyzArray A = Plane.getxyzArray();
                if (A != null)
                {
                    xyzArray         B = LineArray;
                    List <CrossTag1> L = CrossTag1.GetCrossList(A, B);

                    for (int i = 0; i < L.Count; i++)
                    {
                        if (A.Value(L[i].Lam1).dist(Plane.Point) <= SnapItem.Snapdist)
                        {
                            Lam = L[i].Lam1;

                            Result = A.Value(L[i].Lam1);
                            return(true);
                        }
                    }
                }
            }

            int Object = StoredSnapItems.IndexOf(Plane);
            int siz    = SnapDistance * 2 + 1;

            //  int siz = SnapDistance;
            Drawing3d.PrimIdObj[,] P = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);
            List <TriangleF> LT = GetTriangles(P, Object);

            Lam = -1;



            bool R = Cross(LT, LineArray, ref Lam, ref Result);

            return(R);
        }
Ejemplo n.º 4
0
        void IntersectPlaneWithLine(SnapItem Plane, SnapItem Line, LineType ViewLine)
        {
            double Lam    = -1;
            xyz    Result = new xyz(0, 0, 0);

            if (intersectPlaneWithLine(Plane, Line, Line.getxyzArray(), ref Lam, ref Result))
            {
                if (Result.dist(Plane.Point) <= SnapItem.Snapdist)
                {
                    Plane.Point   = Result;
                    Line.Point    = Plane.Point;
                    Line.Crossed  = true;
                    Plane.Crossed = true;
                }
            }
        }
Ejemplo n.º 5
0
        bool IntersectLineWithLine(SnapItem Line1, SnapItem Line2, LineType ViewLine)
        {
            xyzArray A  = Line1.getxyzArray();
            int      h  = A.Count;
            xyzArray B  = Line2.getxyzArray();
            double   d1 = 1e10;
            int      i1 = -1;
            double   d2 = 1e10;
            int      i2 = -1;

            for (int i = 0; i < A.Count; i++)
            {
                double d = Line1.Point.dist(A[i]);
                if (d < d1)
                {
                    d1 = d;
                    i1 = i;
                }
            }
            for (int i = 0; i < B.Count; i++)
            {
                double d = Line1.Point.dist(B[i]);
                if (d < d2)
                {
                    d2 = d;
                    i2 = i;
                }
            }
            if ((A == null) || (B == null))
            {
                return(false);
            }
            xyz CrossPoint = new xyz(0, 0, 0);

            if (IntersectLines(A, B, Line1.Point, ref CrossPoint))
            {
                Line1.Point   = CrossPoint;
                Line2.Point   = CrossPoint;
                Line1.Crossed = true;
                Line2.Crossed = true;
                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        List <TriangleF> GetTriangles(Drawing3d.PrimIdObj[,] P, int Object)
        {
            List <TriangleF> Result  = new List <TriangleF>();
            List <PrimIdObj> PrimIds = new List <PrimIdObj>();

            SnapItem SI = CopySI(Device.Selector.SnapList[Object]);
            Matrix   M  = SI.ModelMatrix;

            for (int i = 0; i < P.GetLength(0); i++)
            {
                for (int j = 0; j < P.GetLength(1); j++)
                {
                    if (P[i, j].Object >= 0)
                    {
                        int ll = P[i, j].Object;
                    }
                    if (P[i, j].Object == 2)
                    {
                    }
                    if ((PrimIds.IndexOf(P[i, j]) < 0))
                    {
                        if ((P[i, j].Object == Object) && (SI.TriangleInfo != null))
                        {
                            TriangleF T = new TriangleF(SI.ModelMatrix * SI.TriangleInfo.Points[SI.TriangleInfo.Indices[P[i, j].PrimId * 3]],
                                                        SI.ModelMatrix * SI.TriangleInfo.Points[SI.TriangleInfo.Indices[P[i, j].PrimId * 3 + 1]],
                                                        SI.ModelMatrix * SI.TriangleInfo.Points[SI.TriangleInfo.Indices[P[i, j].PrimId * 3 + 2]]);

                            {
                                PrimIds.Add(P[i, j]);
                                Result.Add(T);
                            }
                        }
                    }
                }
            }
            return(Result);
        }
Ejemplo n.º 7
0
        public bool IntersectPlaneWithPlane(SnapItem Plane1, SnapItem Plane2, LineType ViewLine)
        {
            int Object1 = StoredSnapItems.IndexOf(Plane1);
            int Object2 = StoredSnapItems.IndexOf(Plane2);
            int siz     = 2 * SnapDistance + 1;

            PrimIdObj[,] P   = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);
            ListOfTriangles1 = GetTriangles(P, Object1);
            ListOfTriangles1.Clear();
            Matrix M = Plane1.ModelMatrix;

            for (int i = 0; i < Plane1.TriangleInfo.Indices.Length; i++)
            {
                TriangleInfo TI = Plane1.TriangleInfo;
                TriangleF    T  = new TriangleF(M * TI.Points[TI.Indices[i]], M * TI.Points[TI.Indices[i + 1]], M * TI.Points[TI.Indices[i + 2]]);
                i = i + 2;
                //   if (T.Inside(ViewLine.P.toXYZF()))
                ListOfTriangles1.Add(T);
            }
            for (int i = 0; i < ListOfTriangles1.Count; i++)
            {
                if (ListOfTriangles1[i].Inside(ViewLine.P.toXYZF()))
                {
                    TriangleF F = ListOfTriangles1[i];
                    ListOfTriangles1.RemoveAt(i);
                    ListOfTriangles1.Insert(0, F);
                }
            }
            ListOfTriangles2 = GetTriangles(P, Object2);
            ListOfTriangles2.Clear();
            M = Plane2.ModelMatrix;
            for (int i = 0; i < Plane2.TriangleInfo.Indices.Length; i++)
            {
                TriangleInfo TI = Plane2.TriangleInfo;
                TriangleF    T  = new TriangleF(M * TI.Points[TI.Indices[i]], M * TI.Points[TI.Indices[i + 1]], M * TI.Points[TI.Indices[i + 2]]);
                i = i + 2;
                //  if (T.Inside(ViewLine.P.toXYZF()))
                ListOfTriangles2.Add(T);
            }
            for (int i = 0; i < ListOfTriangles2.Count; i++)
            {
                if (ListOfTriangles2[i].Inside(ViewLine.P.toXYZF()))
                {
                    TriangleF F = ListOfTriangles2[i];
                    ListOfTriangles2.RemoveAt(i);
                    ListOfTriangles2.Insert(0, F);
                }
            }
            List <Line3D> Lines = Cross(ListOfTriangles1, ListOfTriangles2, ViewLine);
            xyz           P1    = new xyz(0, 0, 0);
            xyz           P2    = new xyz(0, 0, 0);

            if (Lines.Count < 2)
            {
                double           Lam = -1;
                double           Mue = -1;
                List <TriangleF> L1  = new List <TriangleF>();
                List <TriangleF> L2  = new List <TriangleF>();
                for (int i = 0; i < ListOfTriangles1.Count; i++)
                {
                    if (ListOfTriangles1[i].Inside(ViewLine.P.toXYZF()))
                    {
                        L1.Add(ListOfTriangles1[i]);
                    }
                }
                for (int i = 0; i < ListOfTriangles2.Count; i++)
                {
                    if (ListOfTriangles2[i].Inside(ViewLine.P.toXYZF()))
                    {
                        L2.Add(ListOfTriangles2[i]);
                    }
                }
                L1 = ListOfTriangles1;
                L2 = ListOfTriangles2;
                for (int i = 0; i < L1.Count; i++)
                {
                    for (int j = 0; j < L2.Count; j++)
                    {
                        if (TriangleF.Cross(L1[i], L2[j], out Lam, out Mue, out P1, out P2))
                        {
                            int _lam = (int)Lam;
                            switch (_lam)
                            {
                            case 0:
                                Lines.Add(new Line3D(L1[i].A.Toxyz(), L1[i].B.Toxyz()));
                                break;

                            case 1:
                                Lines.Add(new Line3D(L1[i].B.Toxyz(), L1[i].C.Toxyz()));
                                break;

                            case 2:
                                Lines.Add(new Line3D(L1[i].C.Toxyz(), L1[i].A.Toxyz()));
                                break;

                            default:
                                break;
                            }
                            int _mue = (int)Mue;
                            switch (_mue)
                            {
                            case 0:
                                Lines.Add(new Line3D(L2[j].A.Toxyz(), L2[j].B.Toxyz()));
                                break;

                            case 1:
                                Lines.Add(new Line3D(L2[j].B.Toxyz(), L2[j].C.Toxyz()));
                                break;

                            case 2:
                                Lines.Add(new Line3D(L2[j].C.Toxyz(), L2[j].A.Toxyz()));
                                break;

                            default:
                                break;
                            }
                        }
                        break;
                    }
                }
                //if (TriangleF.Cross(ListOfTriangles1[0], ListOfTriangles2[0], out Lam, out Mue, out P1, out P2))
                //{
                //    int _lam = (int)Lam;
                //    switch (_lam)
                //    {case  0: Lines.Add(new Line3D(ListOfTriangles1[0].A.Toxyz(),ListOfTriangles1[0].B.Toxyz()));
                //           break;
                //        case 1: Lines.Add(new Line3D(ListOfTriangles1[0].B.Toxyz(), ListOfTriangles1[0].C.Toxyz()));
                //            break;
                //        case 2: Lines.Add(new Line3D(ListOfTriangles1[0].C.Toxyz(), ListOfTriangles1[0].A.Toxyz()));
                //            break;
                //        default:
                //            break;
                //    }
                //    int _mue = (int)Mue;
                //    switch (_mue)
                //    {
                //        case 0:
                //            Lines.Add(new Line3D(ListOfTriangles2[0].A.Toxyz(), ListOfTriangles2[0].B.Toxyz()));
                //            break;
                //        case 1: Lines.Add(new Line3D(ListOfTriangles2[0].B.Toxyz(), ListOfTriangles2[0].C.Toxyz()));
                //            break;
                //        case 2: Lines.Add(new Line3D(ListOfTriangles2[0].C.Toxyz(), ListOfTriangles2[0].A.Toxyz()));
                //            break;
                //        default:
                //            break;
                //    }
                //}
            }

            double di  = 1e10;
            xyz    Pos = new xyz(0, 0, 0);
            int    Id  = -1;

            for (int i = 0; i < Lines.Count; i++)
            {
                LineType L   = new LineType(Lines[i].A, Lines[i].B - Lines[i].A);
                double   Lam = -1;

                double d       = ViewLine.Distance(L, SnapItem.Snapdist, false, false, out Lam);
                xyz    Nearest = L.Value(Lam);
                if ((Lam >= -0.00001) && (Lam <= 1.00001))
                {
                    if (d < di)
                    {
                        Pos = Nearest;
                        di  = d;
                        Id  = i;
                    }
                }
            }
            if ((di < 1e10) && (di <= SnapItem.Snapdist))
            {
                Plane1.Crossed = true;
                Plane1.Point   = Pos;
                Plane2.Crossed = true;
                Plane2.Point   = Pos;
                return(true);
            }

            xyzArray A = Plane1.getxyzArray();
            xyzArray B = Plane2.getxyzArray();

            if ((A != null) && (B != null))
            {
                return(IntersectLineWithLine(Plane1, Plane2, ViewLine));
            }



            return(false);
        }
Ejemplo n.º 8
0
        public void CreateSnapList()
        {
            if (!Device.SnapEnable)
            {
                return;
            }
            Device.Emission = Color.Black;

            try
            {
                {
                    SnapList.Clear();
                    LineType ViewLine = Device.FromScr(Device.MousePos);
                    VL = ViewLine;
                    int siz = SnapDistance * 2 + 1;

                    Drawing3d.PrimIdObj[,] P = SubArray(Device.MousePos.X - siz / 2, (int)Device.ViewPort.Height - Device.MousePos.Y - siz / 2, siz, siz);


                    Intermediate.Clear();

                    for (int i = 0; i <= siz / 2; i++)
                    {
                        ReadKonzentrisch(Device, P, siz / 2, siz / 2, i);
                    }
                    SnapItem[] BB = new SnapItem[Intermediate.Count];

                    SnapItem.Snapdist = (double)SnapDistance / Device.PixelsPerUnit / Device.Camera.ZoomFactor;
                    for (int i = 0; i < Intermediate.Count; i++)
                    {
                        if (Intermediate.Count > 0)
                        {
                        }
                        SnapItem SI    = null;
                        int      Index = Intermediate[i].Object;
                        if (Index < 0)
                        {
                            continue;
                        }
                        if (StoredSnapItems.Count > Index)
                        {
                            SI = StoredSnapItems[Index];
                        }
                        if (SI == null)
                        {
                            continue;
                        }
                        if ((((SI != null) && (i == 0)) || (SI.PolygonMode == PolygonMode.Line)) ||
                            ((SI != null) && (i == 1) && (SI.PolygonMode == PolygonMode.Line)) ||
                            (((SI != null) && (i == 1)) && (((SnapList.Count > 0) && (SnapList[0].OfObject == null)) || (SI.OfObject == null) || (SnapList[0].OfObject != SI.OfObject))))
                        {
                            SI.PrimId = (short)Intermediate[i].PrimId;
                            Matrix   ToLocal = SI.ModelMatrix.invert();
                            LineType L       = ViewLine * ToLocal;
                            SI.Crossed    = false;
                            SI.doExchange = false;
                            SI.Device     = Device;
                            SI.Point      = SI.ModelMatrix * SI.Cross(L);
                            SI.PtCrossed  = false;
                            double lam = -1;
                            xyz    Pt  = new xyz(0, 0, 0);
                            ViewLine.Distance(SI.Point, out lam, out Pt);
                            SI.Depth = ViewLine.Q.dist(Pt);
                            SI.Depth = lam;
                            int Id = 0;


                            for (int k = 0; k < SnapList.Count; k++)
                            {
                                if (SI is PointSnapItem)
                                {
                                    Id = 0; break;
                                }
                                ;
                                if (SnapList[k].Depth > SI.Depth)
                                {
                                    Id = k; break;
                                }
                                Id = k + 1;
                            }

                            SnapList.Insert(Id, SI);
                        }
                    }
                    double dummy = -1;
                    xyz    _P    = new xyz(0, 0, 0);
                    if (SnapList.Count >= 2)
                    {
                        if (SnapList[1].doExchange)
                        {
                            if ((ViewLine.Distance(SnapList[1].Point, out dummy, out _P) < ViewLine.Distance(SnapList[0].Point, out dummy, out _P)))
                            {
                                SnapItem Ex = SnapList[0];
                                SnapList[0] = SnapList[1];
                                SnapList[1] = Ex;
                            }
                        }
                    }

                    CheckIntersect(ViewLine);
                    if (SnapList.Count > 0)
                    {
                    }
                    if (SnapList.Count > 0)
                    {
                        Setxyz(ViewLine, SnapList[0].Point);
                    }
                    else
                    {
                        double lam;
                        Base   B  = Device.getProjectionBase();
                        Plane  pl = new Plane(Device.Camera.Anchor, B.BaseZ);
                        xyz    Pt;
                        pl.Cross(ViewLine, out lam, out Pt);
                        Setxyz(ViewLine, Pt);
                    }
                }
            }
            finally
            {
            }
        }
Ejemplo n.º 9
0
 public _CtrlRectMrkered.SnapItem CopySI(Drawing3d.SnapItem SI)
 {
     _CtrlRectMrkered.SnapItem Result = new SnapItem();
     Result.TriangleInfo = CopyTr(SI.TriangleInfo);
     return(Result);
 }