Example #1
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            Vector3ToHash other = (Vector3ToHash)obj;

            return(other.m_v == m_v);
        }
Example #2
0
        public static Contact[] FindContacts(this Mesh mesh, Vector3 from, Vector3 to, Axis axis, float threshold = 0.999f)
        {
            Vector3[] vertices = mesh.vertices;
            Vector3[] normals  = mesh.normals;

            Dictionary <Vector3ToHash, List <int> > vertexToIndices = new Dictionary <Vector3ToHash, List <int> >(vertices.Length);

            for (int i = 0; i < vertices.Length; ++i)
            {
                Vector3       vertex  = vertices[i];
                Vector3ToHash vToHash = new Vector3ToHash(vertex);
                if (!vertexToIndices.ContainsKey(vToHash))
                {
                    vertexToIndices.Add(vToHash, new List <int>());
                }

                List <int> indices = vertexToIndices[vToHash];
                indices.Add(i);
            }

            List <Contact> result = new List <Contact>();


            Vector3   offset = to - from;
            Matrix4x4 matrix = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one);

            for (int i1 = 0; i1 < vertices.Length; ++i1)
            {
                Vector3 norm1 = normals[i1];

                Vector3       vertex  = matrix.MultiplyPoint(vertices[i1]);
                Vector3ToHash vToHash = new Vector3ToHash(vertex);
                if (vertexToIndices.ContainsKey(vToHash))
                {
                    List <int> indices = vertexToIndices[vToHash];
                    for (int i = 0; i < indices.Count; ++i)
                    {
                        int     i2    = indices[i];
                        Vector3 norm2 = normals[i2];
                        if (Vector3.Dot(norm1, norm2) > threshold)
                        {
                            result.Add(new Contact(i1, i2));
                        }
                    }
                }
            }

            return(result.ToArray());
        }