当前位置: 首页>>代码示例>>C#>>正文


C# MeshBuilder.IsDegenerate方法代码示例

本文整理汇总了C#中MeshBuilder.IsDegenerate方法的典型用法代码示例。如果您正苦于以下问题:C# MeshBuilder.IsDegenerate方法的具体用法?C# MeshBuilder.IsDegenerate怎么用?C# MeshBuilder.IsDegenerate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MeshBuilder的用法示例。


在下文中一共展示了MeshBuilder.IsDegenerate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MeshSplit

        // Cut a mesh by the line origin->d and split it into two objects if necessary
        public static void MeshSplit(Mesh mesh, Vector2 origin, Vector2 direction)
        {
            Vector3[] vertices = mesh.vertices;
            MeshBuilder leftSide = new MeshBuilder(mesh, vertices);
            MeshBuilder rightSide = new MeshBuilder(mesh, vertices);
            
            // which side my vertices at?
            bool[] side = new bool[vertices.Length];
            bool allOnTheLeft = true, allOnTheRight = true;
            for (int i = 0; i < vertices.Length; i++)
            {
                side [i] = direction.x * (vertices [i].y - origin.y) > direction.y * (vertices [i].x - origin.x);
                if (side [i])
                    allOnTheRight = false;
                else
                    allOnTheLeft = false;
            }

            if (allOnTheLeft || allOnTheRight)
                return;
            
            // build the mesh by adding triangles (possibly cut)
            for (int i = 0; i < mesh.triangles.Length; i += 3)
            {
                int i1 = mesh.triangles [i], i2 = mesh.triangles [i + 1], i3 = mesh.triangles [i + 2];
                
                switch ((side [i1] ? 1 : 0) | (side [i2] ? 2 : 0) | (side [i3] ? 4 : 0))
                {
                    case 0 | 0 | 0:
                        leftSide.AddTri(i1, i2, i3);
                        break;
                    case 0 | 0 | 1:
                        MeshBuilder.AddCutTri(rightSide, leftSide, i1, i2, i3, origin, direction);
                        break;
                    case 0 | 2 | 0:
                        MeshBuilder.AddCutTri(rightSide, leftSide, i2, i3, i1, origin, direction);
                        break;
                    case 4 | 0 | 0:
                        MeshBuilder.AddCutTri(rightSide, leftSide, i3, i1, i2, origin, direction);
                        break;
                    case 4 | 2 | 0:
                        MeshBuilder.AddCutTri(leftSide, rightSide, i1, i2, i3, origin, direction);
                        break;
                    case 4 | 0 | 1:
                        MeshBuilder.AddCutTri(leftSide, rightSide, i2, i3, i1, origin, direction);
                        break;
                    case 0 | 2 | 1:
                        MeshBuilder.AddCutTri(leftSide, rightSide, i3, i1, i2, origin, direction);
                        break;
                    case 4 | 2 | 1:
                        rightSide.AddTri(i1, i2, i3);
                        break;
                }
            }
            
            // degenerate?
            if (leftSide.IsDegenerate(origin, direction))
                return;
            if (rightSide.IsDegenerate(origin, direction))
                return;

            mesh.Clear();

            int finLength = leftSide.pos.Count + rightSide.pos.Count;
            int finTrianglesLength = leftSide.tri.Count + rightSide.tri.Count;
            int leftSideLength = leftSide.pos.Count;
            int rightSideLength = rightSide.pos.Count;
            int leftSideTrianglesLength = leftSide.tri.Count;
            int rightSideTrianglesLength = rightSide.tri.Count;

            Vector3[] finVertices = new Vector3[finLength];
            Color32[] finColors = new Color32[finLength];
            Vector2[] finUv = new Vector2[finLength];
            Vector2[] finUv2 = new Vector2[finLength];
            int[] finTriangles = new int[finTrianglesLength];

            for(int i = 0; i < leftSideLength; i++)
            {
                finVertices[i] = leftSide.pos[i];
                finColors[i] = leftSide.col[i];
                finUv[i] = leftSide.uv[i];
                finUv2[i] = leftSide.uv2[i];
            }

            int offsetIndex;
            for(int i = 0; i < rightSideLength; i++)
            {
                offsetIndex = leftSideLength + i;
                finVertices[offsetIndex] = rightSide.pos[i];
                finColors[offsetIndex] = rightSide.col[i];
                finUv[offsetIndex] = rightSide.uv[i];
                finUv2[offsetIndex] = rightSide.uv2[i];
            }

            for(int i = 0; i < leftSideTrianglesLength; i++)
            {
                finTriangles[i] = leftSide.tri[i];
            }

//.........这里部分代码省略.........
开发者ID:GordeyChernyy,项目名称:CommuteRitual,代码行数:101,代码来源:SVGMeshCutter.cs


注:本文中的MeshBuilder.IsDegenerate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。