public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        EditorGUILayout.HelpBox("Use the button below to create a snapshot of the expression. All changed vectors will be recorded", MessageType.Info);

        EditorGUI.BeginChangeCheck();
        if (GUILayout.Button("Create Snapshot"))
        {
            AssetDatabase.Refresh();
            List <Transform> changed = FindRecursiveChanged(facsStore.Root);
            facsStore.facsstore.AddFacialAction(facsStore.FacName, FacialAction.fromTransforms(changed));
            // Undo.RecordObject(facsStore.facsstore, "Added facial action");
            // AssetDatabase.SaveAssets();
            string jsondata = JsonUtility.ToJson(facsStore.facsstore);
            File.WriteAllText(Path.Combine(Application.persistentDataPath, facsStore.FACStoreJSONPath), jsondata);

            foreach (Transform change in changed)
            {
                change.localPosition = Vector3.zero;
            }
        }

        if (GUILayout.Button("Reset"))
        {
            List <Transform> changed = FindRecursiveChanged(facsStore.Root);
            foreach (Transform change in changed)
            {
                change.localPosition = Vector3.zero;
            }
        }

        EditorGUI.EndChangeCheck();
    }
Exemplo n.º 2
0
    public static FacialAction fromTransforms(List <Transform> transforms)
    {
        FacialAction fa = new FacialAction();

        fa.Transforms = transforms.Select(t => new NamedVector3(t.name, t.localPosition)).ToArray();
        return(fa);
    }
    private void ApplyFacialActionValues()
    {
        Dictionary <string, (Vector3, int)> facResults = new Dictionary <string, (Vector3, int)>();

        for (int i = 0; i < facsStore.facsstore.FacialActions.Length; i++)
        {
            FacialAction fac   = facsStore.facsstore.FacialActions[i].value;
            float        value = facialActionValues[i];

            foreach (NamedVector3 vec in fac.Transforms)
            {
                if (facResults.ContainsKey(vec.VectorName))
                {
                    (Vector3, int)currentValue = facResults[vec.VectorName];
                    facResults[vec.VectorName] = ((currentValue.Item1 * currentValue.Item2 + value * vec.value) / (float)currentValue.Item2, currentValue.Item2 + 1);
                }
                else
                {
                    facResults.Add(vec.VectorName, (value * vec.value, 1));
                }
            }
        }

        foreach (KeyValuePair <string, (Vector3, int)> kvp in facResults)
        {
            transforms[kvp.Key].localPosition = kvp.Value.Item1;
        }
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("LeftSB"))
        {
            selfieMode           = !selfieMode;
            thirdPerson.enabled  = !thirdPerson.enabled;
            selfieCamera.enabled = !selfieCamera.enabled;
            phoneCamera.enabled  = !phoneCamera.enabled;
        }
        if (!selfieMode)
        {
            FacialAction.ResetBlendShapes(ref EditableMeshes);
            return;
        }

        if (Input.GetButton("LeftB") && Input.GetButtonDown("Y"))
        {
            FacialAction.ResetBlendShapes(ref EditableMeshes);
        }


        phone.transform.position = phoneParent.transform.position;
        phone.transform.rotation = phoneParent.transform.rotation;
        handRotation.update();
        phoneRotation.update();
        lookRotation.update();
        leyeRotation.update();
        reyeRotation.update();
        foreach (SkinnedMeshRenderer renderer in EditableMeshes)
        {
            for (int i = 0; i < renderer.sharedMesh.blendShapeCount; i++)
            {
                if (renderer.GetBlendShapeWeight(i) > 0)
                {
                    renderer.SetBlendShapeWeight(i, renderer.GetBlendShapeWeight(i) - Time.deltaTime * DecayMultiplier);
                }
            }
        }
        foreach (FacialAction action in FacialActions)
        {
            if (Input.GetButton(action.ControlButtonCode))
            {
                action.ModifyBlendShapes(ref EditableMeshes, blendSpeed);
            }
        }
    }
 public void AddFacialAction(string name, FacialAction facialAction)
 {
     FacialActions = FacialActions.Where(fa => fa.ActionName != name).ToArray();
     FacialActions = FacialActions.Append(new NamedFacialAction(name, facialAction)).ToArray();
 }
Exemplo n.º 6
0
 public NamedFacialAction(string name, FacialAction value)
 {
     this.ActionName = name;
     this.value      = value;
 }