예제 #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);
            }
        }
예제 #2
0
        public void AppendVertex(CVertex lNewVertex)
        {
            CVertex[] lTemp = new CVertex[V.Length + 1];

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

            lTemp[V.Length] = lNewVertex;

            V = lTemp;
        }
예제 #3
0
        private static ClipOperationResult ProcessVertices(ref CMesh lCMesh, Plane lPlane)
        {
            int lPosCount = 0;
            int lNegCount = 0;

            for (int i = 0; i < lCMesh.V.Length; i++)
            {
                CVertex lV = lCMesh.V[i];

                if (lV.Visible)
                {
                    lV.Distance = Vector3.Dot(lPlane.Normal, lCMesh.V[i].Position) - lPlane.C;

                    if (lV.Distance >= s_Epsilon)
                    {
                        lPosCount++;
                    }
                    else if (lV.Distance <= -s_Epsilon)
                    {
                        lNegCount++;
                        lV.Visible = false;
                    }
                    else
                    {
                        lV.Distance = 0f;
                    }

                    lCMesh.V[i] = lV;
                }
            }

            if (lNegCount == 0)
            {
                return(ClipOperationResult.AllPositive);
            }

            if (lPosCount == 0)
            {
                return(ClipOperationResult.AllNegative);
            }

            return(ClipOperationResult.Mixed);
        }
예제 #4
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;
                }
            }
        }