コード例 #1
0
ファイル: z_CommonEdge.cs プロジェクト: 10jade0070/VR
 public z_CommonEdge(int _x, int _y, int _cx, int _cy)
 {
     this.edge   = new z_Edge(_x, _y);
     this.common = new z_Edge(_cx, _cy);
 }
コード例 #2
0
        /**
         *	Returns a dictionary where each z_Edge is mapped to a list of triangle indices that share that edge.
         *	To translate triangle list to vertex indices, multiply by 3 and take those indices (ex, triangles[index+{0,1,2}])
         */
        public static Dictionary <z_Edge, List <int> > GetAdjacentTriangles(z_Mesh m)
        {
            int len = m.GetTriangles().Length;

            if (len % 3 != 0 || len / 3 == m.vertexCount)
            {
                return(new Dictionary <z_Edge, List <int> >());
            }

            Dictionary <z_Edge, List <int> > lookup = null;

            // @todo - should add some checks to make sure triangle structure hasn't changed
            if (adjacentTrianglesCache.TryGetValue(m, out lookup))
            {
                return(lookup);
            }

            int smc = m.subMeshCount;

            lookup = new Dictionary <z_Edge, List <int> >();
            List <int> connections;

            for (int n = 0; n < smc; n++)
            {
                int[] tris = m.GetIndices(n);

                for (int i = 0; i < tris.Length; i += 3)
                {
                    int index = i / 3;

                    z_Edge a = new z_Edge(tris[i], tris[i + 1]);
                    z_Edge b = new z_Edge(tris[i + 1], tris[i + 2]);
                    z_Edge c = new z_Edge(tris[i + 2], tris[i]);

                    if (lookup.TryGetValue(a, out connections))
                    {
                        connections.Add(index);
                    }
                    else
                    {
                        lookup.Add(a, new List <int>()
                        {
                            index
                        });
                    }

                    if (lookup.TryGetValue(b, out connections))
                    {
                        connections.Add(index);
                    }
                    else
                    {
                        lookup.Add(b, new List <int>()
                        {
                            index
                        });
                    }

                    if (lookup.TryGetValue(c, out connections))
                    {
                        connections.Add(index);
                    }
                    else
                    {
                        lookup.Add(c, new List <int>()
                        {
                            index
                        });
                    }
                }
            }

            adjacentTrianglesCache.Add(m, lookup);

            return(lookup);
        }