Esempio n. 1
0
        static bool IsSoftEdge(Vector3[] normals, EdgeLookup left, EdgeLookup right, float threshold)
        {
            Vector3 lx = normals[left.local.a];
            Vector3 ly = normals[left.local.b];
            Vector3 rx = normals[right.common.a == left.common.a ? right.local.a : right.local.b];
            Vector3 ry = normals[right.common.b == left.common.b ? right.local.b : right.local.a];

            lx.Normalize();
            ly.Normalize();
            rx.Normalize();
            ry.Normalize();
            return(Mathf.Abs(Vector3.Dot(lx, rx)) > threshold && Mathf.Abs(Vector3.Dot(ly, ry)) > threshold);
        }
Esempio n. 2
0
        /// <summary>
        /// Given two adjacent triangle wings, attempt to create a single quad.
        /// </summary>
        /// <param name="left"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        internal static int[] MakeQuad(WingedEdge left, WingedEdge right)
        {
            // Both faces must be triangles in order to be considered a quad when combined
            if (left.Count() != 3 || right.Count() != 3)
            {
                return(null);
            }

            EdgeLookup[] all = new EdgeLookup[6]
            {
                left.edge,
                left.next.edge,
                left.next.next.edge,
                right.edge,
                right.next.edge,
                right.next.next.edge
            };

            int[] dup     = new int[6];
            int   matches = 0;

            for (int i = 0; i < 3; i++)
            {
                for (int n = 3; n < 6; n++)
                {
                    if (all[i].Equals(all[n]))
                    {
                        matches++;
                        dup[i] = 1;
                        dup[n] = 1;
                        break;
                    }
                }
            }

            // Edges are either not adjacent, or share more than one edge
            if (matches != 1)
            {
                return(null);
            }

            int qi = 0;

            EdgeLookup[] edges = new EdgeLookup[4];

            for (int i = 0; i < 6; i++)
            {
                if (dup[i] < 1)
                {
                    edges[qi++] = all[i];
                }
            }

            int[] quad = new int[4] {
                edges[0].local.a, edges[0].local.b, -1, -1
            };

            int c1 = edges[0].common.b, c2 = -1;

            if (edges[1].common.a == c1)
            {
                quad[2] = edges[1].local.b;
                c2      = edges[1].common.b;
            }
            else if (edges[2].common.a == c1)
            {
                quad[2] = edges[2].local.b;
                c2      = edges[2].common.b;
            }
            else if (edges[3].common.a == c1)
            {
                quad[2] = edges[3].local.b;
                c2      = edges[3].common.b;
            }

            if (edges[1].common.a == c2)
            {
                quad[3] = edges[1].local.b;
            }
            else if (edges[2].common.a == c2)
            {
                quad[3] = edges[2].local.b;
            }
            else if (edges[3].common.a == c2)
            {
                quad[3] = edges[3].local.b;
            }

            if (quad[2] == -1 || quad[3] == -1)
            {
                return(null);
            }

            return(quad);
        }