Example #1
0
    public void SetBlendShapeValue(string name, float value)
    {
        if (BlendShapesMapping.TryGetValue(name, out int index))
        {
            SkinnedMeshRenderer skinnedMeshRenderer = CurrentModel.GetComponentInChildren <SkinnedMeshRenderer>();

            skinnedMeshRenderer.SetBlendShapeWeight(index, value * 100.0f);
        }
    }
Example #2
0
    public float GetBlendShapeValue(string name)
    {
        float value = -1.0f;

        if (BlendShapesMapping.TryGetValue(name, out int index))
        {
            SkinnedMeshRenderer skinnedMeshRenderer = CurrentModel.GetComponentInChildren <SkinnedMeshRenderer>();

            value = skinnedMeshRenderer.GetBlendShapeWeight(index) / 100.0f;
        }

        return(value);
    }
Example #3
0
        public override void OnInspectorGUI()
        {
            BlendShapesMapping blendshapesMapping = (BlendShapesMapping)target;

            Undo.RecordObject(blendshapesMapping, "Undo ActorCustomBoneMapping Changes");

            // Initialize Array
            if (blendshapesMapping.blendshapeNames.Count != BlendshapesArray.Length)
            {
                blendshapesMapping.blendshapeNames = new Dictionary <BlendShapes, string>(BlendshapesArray.Length);
                for (int i = 0; i < BlendshapesArray.Length; i++)
                {
                    blendshapesMapping.blendshapeNames.Add(BlendshapesArray[i], "");
                }

                // SerializedObject rereferce needs to be updated
                return;
            }

            GUILayout.Space(10);

            if (GUILayout.Button("Copy from ARKit"))
            {
                // Copy fiels from ARKit
                foreach (KeyValuePair <BlendShapes, string> pair in new Dictionary <BlendShapes, string>(blendshapesMapping.blendshapeNames))
                {
                    blendshapesMapping.blendshapeNames[pair.Key] = pair.Key.ToString();
                }
            }

            GUILayout.Space(10);

            // Draw a field for each Blendshape
            foreach (KeyValuePair <BlendShapes, string> pair in new Dictionary <BlendShapes, string>(blendshapesMapping.blendshapeNames))
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(pair.Key.ToString().ToUpperFirstChar());
                blendshapesMapping.blendshapeNames[pair.Key] = EditorGUILayout.TextField(pair.Value.ToString());
                EditorGUILayout.EndHorizontal();
            }

            serializedObject.ApplyModifiedProperties();

            // Draw standard fields
            //base.OnInspectorGUI();
        }
Example #4
0
    private void InitialiseMapping()
    {
        Debug.Assert(CurrentModel != null);

        BlendShapesMapping.Clear();

        SkinnedMeshRenderer skinnedMeshRenderer = CurrentModel.GetComponentInChildren <SkinnedMeshRenderer>();
        Mesh m = skinnedMeshRenderer.sharedMesh;

        for (int i = 0; i < m.blendShapeCount; i++)
        {
            string s       = m.GetBlendShapeName(i);
            int    index   = s.IndexOf('.') + 1;
            string trimmed = s.Remove(0, index);
            BlendShapesMapping.Add(trimmed, i);
        }
    }