Esempio n. 1
0
        public CMesh(AMesh lMesh)
        {
            V = new CVertex[lMesh.V.Length];
            for (int i = 0; i < lMesh.V.Length; i++)
            {
                V[i] = new CVertex(lMesh.V[i].Position);
            }

            E = new CEdge[lMesh.E.Length];
            for (int i = 0; i < lMesh.E.Length; i++)
            {
                int[] lVerts = new int[2] {
                    lMesh.E[i].Vertices[0], lMesh.E[i].Vertices[1]
                };
                int[] lFaces = new int[2] {
                    lMesh.E[i].Faces[0], lMesh.E[i].Faces[1]
                };
                E[i] = new CEdge(lVerts, lFaces);
            }

            F = new CFace[lMesh.F.Length];
            for (int i = 0; i < lMesh.F.Length; i++)
            {
                int[] lEdges = new int[lMesh.F[i].Edges.Length];

                for (int j = 0; j < lMesh.F[i].Edges.Length; j++)
                {
                    lEdges[j] = lMesh.F[i].Edges[j];
                }

                F[i] = new CFace(lEdges, lMesh.F[i].Plane);
            }
        }
Esempio n. 2
0
        private int[] GetOrderedVertices(CFace lFace)
        {
            List <int> lEdges = new List <int>(lFace.Edges.Length);

            for (int j = 0; j < lFace.Edges.Length; j++)
            {
                lEdges.Add(lFace.Edges[j]);
            }

            for (int i0 = 0, i1 = 1, lChoice = 1; i1 < lEdges.Count - 1; i0 = i1, i1++)
            {
                int lCurrent = E[lEdges[i0]].Vertices[lChoice];
                for (int j = i1; j < lEdges.Count; j++)
                {
                    //CEdge lEdge = E[lEdges[j]];
                    if (E[lEdges[j]].Vertices[0] == lCurrent)
                    {
                        int lTemp = lEdges[i1];
                        lEdges[i1] = lEdges[j];
                        lEdges[j]  = lTemp;

                        lChoice = 1;
                        break;
                    }
                    if (E[lEdges[j]].Vertices[1] == lCurrent)
                    {
                        int lTemp = lEdges[i1];
                        lEdges[i1] = lEdges[j];
                        lEdges[j]  = lTemp;

                        lChoice = 0;
                        break;
                    }
                }
            }

            List <int> lVerts = new List <int>(lEdges.Count + 1);

            lVerts.Add(E[lEdges[0]].Vertices[0]);
            lVerts.Add(E[lEdges[0]].Vertices[1]);

            for (int i = 1; i < lEdges.Count; i++)
            {
                if (E[lEdges[i]].Vertices[0] == lVerts[i])
                {
                    lVerts.Add(E[lEdges[i]].Vertices[1]);
                }
                else
                {
                    lVerts.Add(E[lEdges[i]].Vertices[0]);
                }
            }

            return(lVerts.ToArray());
        }
Esempio n. 3
0
        public void AppendFace(CFace lNewFace)
        {
            CFace[] lTemp = new CFace[F.Length + 1];

            for (int i = 0; i < F.Length; i++)
            {
                lTemp[i] = F[i];
            }

            lTemp[F.Length] = lNewFace;

            F = lTemp;
        }
Esempio n. 4
0
        private static void ProcessFaces(ref CMesh lCMesh, Plane lPlane)
        {
            CFace lNewFace = new CFace();

            lNewFace.Plane   = lPlane;
            lNewFace.Visible = true;

            int lNewFaceIndex = lCMesh.F.Length;

            for (int i = 0; i < lCMesh.F.Length; i++)
            {
                CFace lF = lCMesh.F[i];

                if (lF.Visible)
                {
                    for (int j = 0; j < lF.Edges.Length; j++)
                    {
                        int lEdgeIndex = lF.Edges[j];

                        lCMesh.V[lCMesh.E[lEdgeIndex].Vertices[0]].Occurs = 0;
                        lCMesh.V[lCMesh.E[lEdgeIndex].Vertices[1]].Occurs = 0;
                    }

                    int lStart, lEnd;
                    if (GetOpenPolyline(lCMesh, lF, out lStart, out lEnd))
                    {
                        CEdge lNewEdge      = new CEdge();
                        int   lNewEdgeIndex = lCMesh.E.Length;

                        lNewEdge.Vertices    = new int[2];
                        lNewEdge.Vertices[0] = lStart;
                        lNewEdge.Vertices[1] = lEnd;

                        lNewEdge.AddFace(i);
                        lNewEdge.AddFace(lNewFaceIndex);

                        lNewEdge.Visible = true;

                        lF.AddEdge(lNewEdgeIndex);
                        lNewFace.AddEdge(lNewEdgeIndex);

                        lCMesh.AppendEdge(lNewEdge);
                    }

                    lCMesh.F[i] = lF;
                }
            }

            lCMesh.AppendFace(lNewFace);
        }
Esempio n. 5
0
        private static bool GetOpenPolyline(CMesh lCMesh, CFace lF, out int lStart, out int lEnd)
        {
            for (int i = 0; i < lF.Edges.Length; i++)
            {
                int lEdgeIndex = lF.Edges[i];

                lCMesh.V[lCMesh.E[lEdgeIndex].Vertices[0]].Occurs++;
                lCMesh.V[lCMesh.E[lEdgeIndex].Vertices[1]].Occurs++;
            }

            lStart = -1;
            lEnd   = -1;

            for (int i = 0; i < lF.Edges.Length; i++)
            {
                int lEdgeIndex = lF.Edges[i];

                int lI0 = lCMesh.E[lEdgeIndex].Vertices[0];
                int lI1 = lCMesh.E[lEdgeIndex].Vertices[1];
                if (lCMesh.V[lI0].Occurs == 1)
                {
                    if (lStart == -1)
                    {
                        lStart = lI0;
                    }
                    else if (lEnd == -1)
                    {
                        lEnd = lI0;
                    }
                }

                if (lCMesh.V[lI1].Occurs == 1)
                {
                    if (lStart == -1)
                    {
                        lStart = lI1;
                    }
                    else if (lEnd == -1)
                    {
                        lEnd = lI1;
                    }
                }
            }

            return(lStart != -1);
        }
Esempio n. 6
0
        private static void ProcessEdges(ref CMesh lCMesh, Plane lPlane)
        {
            for (int i = 0; i < lCMesh.E.Length; i++)
            {
                CEdge lE = lCMesh.E[i];

                if (lE.Visible)
                {
                    float lD0 = lCMesh.V[lE.Vertices[0]].Distance;
                    float lD1 = lCMesh.V[lE.Vertices[1]].Distance;

                    if (lD0 <= 0f && lD1 <= 0f)
                    {
                        for (int j = 0; j < lE.Faces.Length; j++)
                        {
                            CFace lF = lCMesh.F[lE.Faces[j]];
                            lF.RemoveEdge(i);
                            if (lF.Edges.Length == 0)
                            {
                                lF.Visible = false;
                            }

                            lCMesh.F[lE.Faces[j]] = lF;
                        }

                        lE.Visible  = false;
                        lCMesh.E[i] = lE;

                        continue;
                    }

                    if (lD0 >= 0f && lD1 >= 0f)
                    {
                        lCMesh.E[i] = lE;
                        continue;
                    }

                    float   lT         = lD0 / (lD0 - lD1);
                    Vector3 lDelta0    = (1f - lT) * lCMesh.V[lE.Vertices[0]].Position;
                    Vector3 lDelta1    = lT * lCMesh.V[lE.Vertices[1]].Position;
                    Vector3 lIntersect = lDelta0 + lDelta1;

                    int lIndex = lCMesh.V.Length;

                    CVertex lNewVertex = new CVertex(lIntersect);

                    lCMesh.AppendVertex(lNewVertex);

                    if (lD0 > 0)
                    {
                        lE.Vertices[1] = lIndex;
                    }
                    else
                    {
                        lE.Vertices[0] = lIndex;
                    }

                    lCMesh.E[i] = lE;
                }
            }
        }