Exemple #1
0
    // ApplySkinBlend
    private bool ApplySkinBlend(Mesh a_rSourceMesh, Mesh a_rUsedMesh, ref Mesh a_rPoseMesh, ref ReferenceContainer a_rRefManipulatedMesh)
    {
        if (EnsureMeshValidity(a_rSourceMesh, a_rUsedMesh, ref a_rPoseMesh, ref a_rRefManipulatedMesh))
        {
            // Renderer
            Vector3[] oVertices = a_rPoseMesh.vertices;
            Uni2DSkinningUtils.ApplySkinBlend(ref oVertices, a_rPoseMesh, m_oBones, transform, quality);
            Mesh rManipulatedMesh = a_rRefManipulatedMesh.Reference as Mesh;
            (rManipulatedMesh).vertices = oVertices;
            rManipulatedMesh.RecalculateBounds();

            return(true);
        }
        else
        {
            return(false);
        }
    }
Exemple #2
0
    // Update Physics Skinning
    public void UpdatePhysicsSkinning()
    {
        if (m_oMeshColliders != null)
        {
            if (m_oBones != null)
            {
                int iColliderCount = MeshColliders.Count;
                if (iColliderCount > 0)
                {
                    // Create Collider meshes arrays if needed
                    if (m_oPoseColliderMeshes == null || m_oPoseColliderMeshes.Length != iColliderCount)
                    {
                        m_oPoseColliderMeshes = new Mesh[iColliderCount];
                    }
                    if (m_oRefManipulatedColliderMeshes == null || m_oRefManipulatedColliderMeshes.Length != iColliderCount)
                    {
                        // Destroy old references
                        DestroyManipulatedColliderMeshReferences();

                        // Recreate
                        m_oRefManipulatedColliderMeshes = new ReferenceContainer[iColliderCount];
                        for (int i = 0; i < iColliderCount; ++i)
                        {
                            ReferenceContainer rReferenceContainer = new ReferenceContainer();
                            rReferenceContainer.Initialize(this, true);
                            m_oRefManipulatedColliderMeshes[i] = rReferenceContainer;
                        }
                    }

                    // Apply the skin blend on each collider
                    int         iColliderIndex  = 0;
                    List <Mesh> rColliderMeshes = m_rSprite.SpriteData.meshCollidersList;
                    foreach (MeshCollider rMeshCollider in m_oMeshColliders)
                    {
                        if (rMeshCollider != null)
                        {
                            // Get The pose and manipulated mesh
                            Mesh rPoseMesh = m_oPoseColliderMeshes[iColliderIndex];
                            ReferenceContainer rRefManipulatedMesh = m_oRefManipulatedColliderMeshes[iColliderIndex];

                            if (ApplySkinBlend(rColliderMeshes[iColliderIndex], rMeshCollider.sharedMesh, ref rPoseMesh, ref rRefManipulatedMesh))
                            {
                                // Update collider mesh
                                rMeshCollider.sharedMesh = null;
                                rMeshCollider.sharedMesh = rRefManipulatedMesh.Reference as Mesh;

                                m_oPoseColliderMeshes[iColliderIndex] = rPoseMesh;
                            }
                        }

                        ++iColliderIndex;
                    }
                }
            }
        }

                #if AFTER_UNITY_4_3
        if (PolygonCollider2D != null)
        {
            PolygonCollider2D.points = Uni2DSkinningUtils.ApplySkinBlend(m_rSprite.SpriteData.mesh2D, m_oBones, transform, quality);
        }
                #endif
    }