Exemple #1
0
        private void SlerpContacts(Deformer deformer, Mesh mesh, Contact[] contacts, Segment prev, Mesh prevMesh, Segment next, Mesh nextMesh)
        {
            Vector3[] normals     = null;
            Vector3[] prevNormals = null;
            Vector3[] nextNormals = null;
            if (mesh == null)
            {
                return;
            }

            if (prev != null || next != null)
            {
                normals = mesh.normals;
            }

            if (prevMesh != null && prev != null && (prev != this || deformer.SegmentsCount == 1 && deformer.IsLooping))
            {
                prevNormals = prevMesh.normals;
                for (int i = 0; i < contacts.Length; ++i)
                {
                    Contact contact    = contacts[i];
                    Vector3 prevNormal = prevNormals[contact.Index2];
                    Vector3 normal     = normals[contact.Index1];
                    Vector3 slerped    = Vector3.Slerp(prevNormal, normal, 0.5f);
                    prevNormals[contact.Index2] = slerped;
                    normals[contact.Index1]     = slerped;
                }
            }

            if (nextMesh != null && next != null && (next != this || deformer.SegmentsCount == 1 && deformer.IsLooping))
            {
                nextNormals = nextMesh.normals;
                for (int i = 0; i < contacts.Length; ++i)
                {
                    Contact contact    = contacts[i];
                    Vector3 normal     = normals[contact.Index2];
                    Vector3 nextNormal = nextNormals[contact.Index1];
                    Vector3 slerped    = Vector3.Slerp(normal, nextNormal, 0.5f);

                    normals[contact.Index2]     = slerped;
                    nextNormals[contact.Index1] = slerped;
                }
            }

            if (prev != null)
            {
                if (mesh != null)
                {
                    mesh.normals = normals;
                }

                if (this != prev)
                {
                    if (prevMesh != null)
                    {
                        prevMesh.normals = prevNormals;
                    }
                }

                if (next != null && next != prev)
                {
                    if (nextMesh != null)
                    {
                        nextMesh.normals = nextNormals;
                    }
                }
            }
            else if (next != null)
            {
                if (mesh != null)
                {
                    mesh.normals = normals;
                }

                if (prev != null && prev != next)
                {
                    if (prevMesh != null)
                    {
                        prevMesh.normals = prevNormals;
                    }
                }

                if (this != next)
                {
                    if (nextMesh != null)
                    {
                        nextMesh.normals = nextNormals;
                    }
                }
            }
        }
Exemple #2
0
        public void SlerpContacts(Deformer deformer, Mesh original, Mesh colliderOriginal, Segment prev, Segment next, bool isRigid)
        {
            if (isRigid)
            {
                return;
            }

            Mesh prevMesh = null;
            Mesh nextMesh = null;

            if (prev != null)
            {
                prevMesh = prev.Mesh;
            }

            if (next != null)
            {
                nextMesh = next.Mesh;
            }
            SlerpContacts(deformer, Mesh, deformer.Contacts, prev, prevMesh, next, nextMesh);


            if (colliderOriginal == null)
            {
                return;
            }
            if (prev != null)
            {
                prevMesh = prev.ColliderMesh;
            }

            if (next != null)
            {
                nextMesh = next.ColliderMesh;
            }
            SlerpContacts(deformer, ColliderMesh, deformer.ColliderContacts, prev, prevMesh, next, nextMesh);

            if (m_meshCollider != null)
            {
                Mesh colliderMesh = ColliderMesh;

                m_meshCollider.sharedMesh = null;
                m_meshCollider.sharedMesh = colliderMesh;
            }
        }