Exemplo n.º 1
0
 // Register FaceClip
 public void AddFace(FaceClip faceClip, bool asDefault = false)
 {
     faceClips[faceClip.Name] = faceClip;
     if (asDefault)
     {
         DefaultFace = new FaceRequest();
         DefaultFace.AddFace(faceClip.Name, 0.0f, "default face");
     }
 }
Exemplo n.º 2
0
        // Set face expressions
        public async Task SetFace(FaceRequest request)
        {
            foreach (var face in request.Faces)
            {
                History?.Add(face);
                if (faceClips.ContainsKey(face.Name))
                {
                    if (FaceFadeStep == 0)
                    {
                        // Change immediately when step is 0
                        foreach (var blendShapeValue in faceClips[face.Name].Values)
                        {
                            SkinnedMeshRenderer.SetBlendShapeWeight(blendShapeValue.Index, blendShapeValue.Weight);
                        }
                    }
                    else
                    {
                        // Calculate the weights to be added at each steps
                        var weightsForEachSteps = new Dictionary <int, List <float> >();
                        foreach (var blendShapeValue in faceClips[face.Name].Values)
                        {
                            var currentWeight = SkinnedMeshRenderer.GetBlendShapeWeight(blendShapeValue.Index);
                            weightsForEachSteps.Add(blendShapeValue.Index, new List <float>());
                            var weightToAdd = (blendShapeValue.Weight - currentWeight) / FaceFadeStep;
                            for (var i = 0; i < FaceFadeStep - 1; i++)
                            {
                                weightsForEachSteps[blendShapeValue.Index].Add(currentWeight + weightToAdd * (i + 1));
                            }
                            weightsForEachSteps[blendShapeValue.Index].Add(blendShapeValue.Weight);
                        }

                        // Apply weights
                        for (var i = 0; i < FaceFadeStep; i++)
                        {
                            foreach (var blendShapeValue in faceClips[face.Name].Values)
                            {
                                SkinnedMeshRenderer.SetBlendShapeWeight(blendShapeValue.Index, weightsForEachSteps[blendShapeValue.Index][i]);
                            }
                            await Task.Delay(10);
                        }
                    }
                    await Task.Delay((int)(face.Duration * 1000));
                }
                else
                {
                    Debug.LogWarning($"FaceClip not exists: {face.Name}");
                }
            }

            // Reset default face expression
            if (request.DefaultOnEnd && request.Faces.Last().Duration > 0)
            {
                _ = SetDefaultFace();
            }
        }
Exemplo n.º 3
0
        // Set face expressions
        public async Task SetFace(FaceRequest request)
        {
            foreach (var face in request.Faces)
            {
                for (var i = 0; i < skinnedMeshRenderer.sharedMesh.blendShapeCount; i++)
                {
                    // Apply weights
                    var weights = faces[face.Name];
                    var name    = skinnedMeshRenderer.sharedMesh.GetBlendShapeName(i);
                    var weight  = weights.Keys.Contains(name) ? weights[name] : 0f;
                    skinnedMeshRenderer.SetBlendShapeWeight(i, weight * 100);
                }
                await Task.Delay((int)(face.Duration * 1000));
            }

            // Reset default face expression
            if (request.DefaultOnEnd && request.Faces.Last().Duration > 0)
            {
                _ = SetDefaultFace();
            }
        }