예제 #1
0
            // unity event handlers

            void Awake()
            {
                //Dbg.Log("MorphProc.Awake: {0}, {1}", name, GetInstanceID());

                if (m_Mesh == null)
                {
                    m_Mesh = EditableMesh.New(gameObject);
                }

                var m = m_Mesh.mesh;

                MeshUtil.MarkDynamic(m);

                if (m_Deforms == null)
                { //should be created by MeshManipulator
                    m_Deforms = new List <ShapeKeyMorphSO>();
                }
                else
                { //other circumstances, switch playMode, reload assembly, etc.
                    Dbg.Assert(m_Deforms.Count > 0, "MorphProc.Awake: the MorphProc is not null but empty?!");
                    m_OutData = ShapeKeyDataDiff.TempVarNew(m_Deforms[BASIS_MORPH_IDX]);
                }

                if (m_CmpWeights == null)
                {
                    m_CmpWeights = new float[MAX_SHAPEKEY_CNT];
                }
                if (m_MeshCache == null)
                {
                    //Dbg.Log("MorphProc.Awake: init MeshCache: {0}", name);
                    m_MeshCache = new MeshCacheRT();
                }

                // force apply weight on mesh, to fix the mesh deforming leftover when switch between playMode and editMode
                if (m_Deforms.Count > 0)
                {
                    ResetToBasisShape();
                    for (int i = 1; i < m_Deforms.Count; ++i) //don't check the first base shape
                    {
                        float animWeight = Mathf.Clamp(_GetAnimWeight(i), 0, 100f);
                        _ApplyWeightChange(i, animWeight);
                    }
                }
            }
예제 #2
0
            /// <summary>
            /// ApplyToMeshAsSubtract, with MeshCache version,
            /// </summary>
            public void ApplyToMeshAsSubtract(Mesh m, MeshCacheRT cache)
            {
                // vertices
                {
                    int       vcnt     = indV.Count;
                    Vector3[] newVerts = cache.GetVertices(m);
                    for (int i = 0; i < vcnt; ++i)
                    {
                        int vidx = indV[i];
                        newVerts[vidx] += vertices[i];
                    }
                    cache.SetVertices(m, newVerts);
                }

                //// normals
                //{
                //    int ncnt = indN.Count;
                //    Vector3[] newNormals = cache.GetNormals(m);
                //    for (int i = 0; i < ncnt; ++i)
                //    {
                //        int nidx = indN[i];
                //        newNormals[nidx] += normals[i];
                //    }
                //    cache.SetNormals(m, newNormals);
                //}

                //// tangents
                //{
                //    int tcnt = indT.Count;
                //    Vector4[] newTangents = cache.GetTangents(m);
                //    for (int i = 0; i < tcnt; ++i)
                //    {
                //        int tidx = indT[i];
                //        newTangents[tidx] += tangents[i];
                //    }
                //    cache.SetTangents(m, newTangents);
                //}

                if (evtShapeKeyModifyMesh != null)
                {
                    evtShapeKeyModifyMesh(basisSO);
                }
            }
예제 #3
0
            /// <summary>
            /// ApplyToMeshAsDiff, with MeshCache version,
            /// </summary>
            public void ApplyToMeshAsDiff(Mesh m, MeshCacheRT cache)
            {
                int vcnt = m.vertexCount;

                // vertices
                Vector3[] newVerts = cache.GetVertices(m);
                for (int i = 0; i < vcnt; ++i)
                {
                    newVerts[i] += vertices[i];
                }
                cache.SetVertices(m, newVerts);

                // normals
                Vector3[] cacheNormals = cache.GetNormals();
                if (cacheNormals != null && cacheNormals.Length == vcnt && HasNormals())
                {
                    Vector3[] newNormals = cache.GetNormals(m);
                    for (int i = 0; i < vcnt; ++i)
                    {
                        newNormals[i] += normals[i];
                    }
                    cache.SetNormals(m, newNormals);
                }

                // tangents
                Vector4[] cacheTangents = cache.GetTangents();
                if (cacheTangents != null && cacheTangents.Length == vcnt && HasTangents())
                {
                    Vector4[] newTangents = cache.GetTangents(m);
                    for (int i = 0; i < vcnt; ++i)
                    {
                        newTangents[i] += tangents[i];
                    }
                    cache.SetTangents(m, newTangents);
                }
            }