예제 #1
0
파일: Split.cs 프로젝트: UseUnity/UnitySDK
    private void AssignTriangles(bool[] vertexAbovePlane, Vector3 pointOnPlane, Vector3 planeNormal, out IList <Vector3> cutEdges)
    {
        cutEdges = new List <Vector3>();

        int triangleCount = indices.Count / 3;

        for (int i = 0; i < triangleCount; i++)
        {
            int index0 = indices[i * 3 + 0];
            int index1 = indices[i * 3 + 1];
            int index2 = indices[i * 3 + 2];

            bool above0 = vertexAbovePlane[index0];
            bool above1 = vertexAbovePlane[index1];
            bool above2 = vertexAbovePlane[index2];

            if ((above0 && above1 && above2) || (!above0 && !above1 && !above2) || tri_backlist.Contains(i))
            {
                // 保持不变
                indices2.Add(index0);
                indices2.Add(index1);
                indices2.Add(index2);

                //Debug.LogFormat("{0} {1} {2}", index0, index1, index2);
            }
            else
            {
                //continue;

                // Split triangle
                int top, cw, ccw;

                if (above1 == above2 && above0 != above1)
                {
                    top = index0;
                    cw  = index1;
                    ccw = index2;
                }
                else if (above2 == above0 && above1 != above2)
                {
                    top = index1;
                    cw  = index2;
                    ccw = index0;
                }
                else
                {
                    top = index2;
                    cw  = index0;
                    ccw = index1;
                }

                Vector3 cutVertex0, cutVertex1;

                //Debug.LogFormat ("{0} above {1}", top, vertexAbovePlane[top]);
                if (vertexAbovePlane[top])
                {
                    SplitTriangle(pointOnPlane, planeNormal, i, top, cw, ccw, true, out cutVertex0, out cutVertex1);
                }
                else
                {
                    SplitTriangle(pointOnPlane, planeNormal, i, top, cw, ccw, false, out cutVertex1, out cutVertex0);
                }

                // Add cut edge
                if (cutVertex0 != cutVertex1)
                {
                    cutEdges.Add(cutVertex0);
                    cutEdges.Add(cutVertex1);

                    //Debug.LogFormat ("{0} cutedge {1} {2}", i, cutVertex0, cutVertex1);
                }

                // ADD remove springs
                softbody.RemoveMassSpring(top, cw);
                softbody.RemoveMassSpring(top, ccw);
            }
        }
    }