Exemple #1
0
        private void SplitThreePart(ref TriangleFace triangleFace, ref Stack <TriangleFace> faceStack)
        {
            Vector3 barycentric;

            triangleFace.ComputeBarycentric(out barycentric);
            VertexData newPointData = triangleFace.Interlopation(barycentric, true, true);

            faceStack.Push(new TriangleFace(triangleFace.pointA, triangleFace.pointB, newPointData));
            faceStack.Push(new TriangleFace(triangleFace.pointB, triangleFace.pointC, newPointData));
            faceStack.Push(new TriangleFace(triangleFace.pointC, triangleFace.pointA, newPointData));
        }
Exemple #2
0
        /// <summary>
        /// 切割后的三角形面积会小于areaUnit
        /// </summary>
        /// <param name="areaUnit"></param>
        /// <returns></returns>
        public void SplitByArea(ref TriangleFace triangleFace)
        {
            Stack <TriangleFace> faceStack = new Stack <TriangleFace>();

            faceStack.Push(triangleFace);
            float areaUnitLocal = areaUnit;

            if (infectedByCrossPoint)
            {
                Vector3 barycentric;
                triangleFace.ComputeBarycentric(out barycentric);
                areaUnitLocal = areaUnit * (crossPoint - barycentric).magnitude / distance2CrossPointPer;
                if (limitAreaUnit)
                {
                    if (maxAreaUnit < minAreaUnit)
                    {
                        maxAreaUnit = minAreaUnit;
                    }
                    if (areaUnitLocal > maxAreaUnit)
                    {
                        areaUnitLocal = maxAreaUnit;
                    }
                    else if (areaUnitLocal < minAreaUnit)
                    {
                        areaUnitLocal = minAreaUnit;
                    }
                }
            }
            while (faceStack.Count > 0)
            {
                var   curFace      = faceStack.Pop();
                float triangleArea = ComputeArea(ref curFace);
                int   count        = (int)(triangleArea / areaUnitLocal) + 1;
                if (count <= 1)
                {
                    splitTriangleFace.Add(curFace);
                    triangleAreaList.Add(triangleArea);
                    continue;
                }

                //能整除的优先
                if ((cutToPiecesPerTime & CutToPiecesPerTime.CutToFour) == CutToPiecesPerTime.CutToFour && count % 4 == 0)
                {
                    SplitFourPart(ref curFace, ref faceStack);
                }
                else if ((cutToPiecesPerTime & CutToPiecesPerTime.CutToThree) == CutToPiecesPerTime.CutToThree && count % 3 == 0)
                {
                    SplitThreePart(ref curFace, ref faceStack);
                }
                else if ((cutToPiecesPerTime & CutToPiecesPerTime.CutToTwo) == CutToPiecesPerTime.CutToTwo && count % 2 == 0)
                {
                    SplitTwoPart(ref curFace, ref faceStack);
                }
                else
                {
                    //优先级2》3》4
                    if ((cutToPiecesPerTime & CutToPiecesPerTime.CutToTwo) == CutToPiecesPerTime.CutToTwo && count / 2 > 0)
                    {
                        SplitTwoPart(ref curFace, ref faceStack);
                    }
                    else if ((cutToPiecesPerTime & CutToPiecesPerTime.CutToThree) == CutToPiecesPerTime.CutToThree && count / 3 > 0)
                    {
                        SplitThreePart(ref curFace, ref faceStack);
                    }
                    else
                    {
                        SplitFourPart(ref curFace, ref faceStack);
                    }
                }
            }
        }