// public method

            #endregion "public method"

            #region "private method"
            // private method

            private void _DrawShapeKeyData(ShapeKeyMorphSO morph, int keyIdx)
            {
                ShapeKeyDataDiff keyData = morph.GetShapeKeyDataDiff(keyIdx);

                EditorGUILayout.BeginHorizontal();
                {
                    EditorGUILayout.LabelField("Weight:", GUILayout.Width(50f));

                    float newWeight = keyData.weight;
                    if (EUtil.FloatField("weight" + keyIdx, ref newWeight)) //only true when use enter to confirm
                    {
                        morph.SetShapeKeyWeight(keyIdx, newWeight);         //this will ensure all keys are sorted
                    }

                    if (EUtil.Button(EditorRes.texSample, "Sample current mesh status as shape key", EditorRes.styleBtnMorphProc, GUILayout.Width(20f)))
                    {
                        morph.SetMeshCurrentDataToShapeKey(keyIdx);
                    }
                    if (EUtil.Button(EditorRes.texApplyToMesh, "Apply this shape key to mesh", EditorRes.styleBtnMorphProc, GUILayout.Width(20f)))
                    {
                        Undo.RecordObject(m_MorphProc, "MorphProc Inspector");
                        m_MorphProc.ResetToBasisShape();
                        m_MorphProc.ApplyOnlyMorphAt(m_MorphIdx, keyData.weight);
                    }
                    if (EUtil.Button(EditorRes.texDelete, "Delete this shape key from this morph", EditorRes.styleBtnMorphProc, GUILayout.Width(20f)))
                    {
                        if (morph.ShapeKeyCnt == 1)
                        {
                            EditorUtility.DisplayDialog("Only one shape key", "Cannot delete shape key when there's no others", "Got it");
                        }
                        else
                        {
                            morph.DelShapeKeyDataDiff(keyIdx);
                        }
                    }
                }
                EditorGUILayout.EndHorizontal();
            }
Esempio n. 2
0
 public bool IsBasis()
 {
     return(basisSO.GetShapeKeyDataDiff(0) == this);
 }
Esempio n. 3
0
            public void UpdateDiffDataWithCurrentMesh()
            {
                ShapeKeyDataDiff basisData = basisSO.GetShapeKeyDataDiff(0);
                Mesh             m         = basisSO.GetMesh();

                int nonMatchV = 0;
                //int nonMatchN = 0;
                //int nonMatchT = 0;

                // v
                {
                    List <Vector3> basisVertices = basisData.vertices;
                    Vector3[]      meshVertices  = m.vertices;
                    Dbg.Assert(basisVertices.Count == meshVertices.Length, "ShapeKeyDataDiff.UpdateDiffDataWithCurrentMesh: length non match: basisVertices != meshVertices: {0}", m.name);
                    vertices.Clear();
                    indV.Clear();
                    for (int i = 0; i < basisVertices.Count; ++i)
                    {
                        Vector3 basisPos = basisVertices[i];
                        Vector3 meshPos  = meshVertices[i];
                        if (!(basisPos == meshPos))
                        {
                            vertices.Add(meshPos);
                            indV.Add(i);
                            ++nonMatchV;
                        }
                    }
                }

                //// n
                //{
                //    List<Vector3> basisNormals = basisData.normals;
                //    Vector3[] meshNormals = m.normals;
                //    Dbg.Assert(basisNormals.Count == meshNormals.Length, "ShapeKeyDataDiff.UpdateDiffDataWithCurrentMesh: length non match: basisNormal != meshNormals: {0}", m.name);
                //    normals.Clear();
                //    indN.Clear();
                //    for(int i=0; i<basisNormals.Count; ++i)
                //    {
                //        Vector3 basisN = basisNormals[i];
                //        Vector3 meshN = meshNormals[i];
                //        if( ! (basisN == meshN) )
                //        {
                //            normals.Add(meshN);
                //            indN.Add(i);
                //            ++nonMatchN;
                //        }
                //    }
                //}

                //// t
                //{
                //    List<Vector4> basisTangents = basisData.tangents;
                //    Vector4[] meshTangents = m.tangents;
                //    Dbg.Assert(basisTangents.Count == meshTangents.Length, "ShapeKeyDataDiff.UpdateDiffDataWithCurrentMesh: length non match: basisTangents != meshTangents: {0}", m.name);
                //    tangents.Clear();
                //    indT.Clear();
                //    for (int i = 0; i < basisTangents.Count; ++i)
                //    {
                //        Vector4 basisT = basisTangents[i];
                //        Vector4 meshT = meshTangents[i];
                //        if (!(basisT == meshT))
                //        {
                //            tangents.Add(meshT);
                //            indT.Add(i);
                //            ++nonMatchT;
                //        }
                //    }
                //}

                //Dbg.Log("ShapeKeyDataDiff.UpdateDiffDataWithCurrentMesh: V: {0}, N: {1}, T:{2}", nonMatchV, nonMatchN, nonMatchT);
            }