Exemplo n.º 1
0
    void UpdateFaceFeatures()
    {
        if (skinnedMeshRenderer == null || !skinnedMeshRenderer.enabled || skinnedMeshRenderer.sharedMesh == null)
        {
            return;
        }

        //XRFaceMesh xRFaceMesh = new XRFaceMesh();
        //m_ARKitFaceSubsystem.GetFaceMesh(m_Face.trackableId, Allocator.Temp, ref xRFaceMesh);

#if UNITY_IOS && !UNITY_EDITOR
        using (var blendShapes = m_ARKitFaceSubsystem.GetBlendShapeCoefficients(m_Face.trackableId, Allocator.Temp))
        {
            Dictionary <int, float> data = new Dictionary <int, float>();
            foreach (var featureCoefficient in blendShapes)
            {
                int mappedBlendShapeIndex;
                if (m_FaceArkitBlendShapeIndexMap.TryGetValue(featureCoefficient.blendShapeLocation, out mappedBlendShapeIndex))
                {
                    if (mappedBlendShapeIndex >= 0)
                    {
                        skinnedMeshRenderer.SetBlendShapeWeight(mappedBlendShapeIndex, featureCoefficient.coefficient * coefficientScale);
                        data.Add(mappedBlendShapeIndex, featureCoefficient.coefficient);
                    }
                }
            }

            string json = MiniJSON.Json.Serialize(data);
            udpSender.Send(json);
        }
#endif
    }
Exemplo n.º 2
0
 void UpdateFaceFeatures()
 {
     using (var blendShapes = m_ARKitFaceSubsystem.GetBlendShapeCoefficients(m_Face.trackableId, Unity.Collections.Allocator.Temp))
     {
         foreach (var featureCoefficient in blendShapes)
         {
             if (featureCoefficient.blendShapeLocation == ARKitBlendShapeLocation.BrowInnerUp)
             {
                 this.BrowCoefficient = featureCoefficient.coefficient * 100f;
             }
         }
     }
 }
Exemplo n.º 3
0
        static ARKitRemotePacket.FaceMesh ToMesh(ARFace face, ARKitFaceSubsystem subsystem)
        {
            var id = face.trackableId;

            return(new ARKitRemotePacket.FaceMesh()
            {
                id = id,
                vertices = face.vertices.ToRawBytes(),
                normals = face.normals.ToRawBytes(),
                indices = face.indices.ToRawBytes(),
                uvs = face.uvs.ToRawBytes(),
                coefficients = subsystem.GetBlendShapeCoefficients(id, Allocator.Temp).ToRawBytes(),
            });
        }
Exemplo n.º 4
0
        void OnUpdated(ARFaceUpdatedEventArgs eventArgs)
        {
            using (var blendShapes = arKitFaceSubsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp))
            {
                var list = blendShapes.Select(blendShapeCoefficient => (Enum.GetName(typeof(ARKitBlendShapeLocation), blendShapeCoefficient.blendShapeLocation), blendShapeCoefficient.coefficient)).ToList();
                udp.Send(transform, eventArgs.face, list);

                var t = "";
                foreach (var c in list)
                {
                    t += c.Item1 + c.Item2.ToString() + "\n";
                }
                text.text = t;
            }
        }
Exemplo n.º 5
0
 void UpdateFaceFeatures()
 {
     using (var blendShapes = faceSubsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp))
     {
         foreach (var featureCoefficient in blendShapes)
         {
             if (cacheBlendShape.TryGetValue(featureCoefficient.blendShapeLocation, out float coefficient))
             {
                 Coefficient = coefficient;
                 Logger.Instance.LogInfo(featureCoefficient.blendShapeLocation.ToString() + " " + Coefficient);
                 cacheBlendShape[featureCoefficient.blendShapeLocation] = featureCoefficient.coefficient;
             }
         }
     }
 }
Exemplo n.º 6
0
    void UpdateFaceFeatures()
    {
        blendShapesEnabled = true;
        using (var blendShapes = faceSubsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp))
        {
            foreach (var blendShape in blendShapes)
            {
                string blendShapeName = blendShape.blendShapeLocation.ToString();

                if (currentBlendShapes.TryGetValue(blendShapeName, out float coefficient))
                {
                    currentBlendShapes[blendShapeName] = blendShape.coefficient;
                }
            }
        }
    }
        //while recoring updating facial features and store them as blendshapedata as soon the subsystem update occurs
        void UpdateFaceFeatures()
        {
            if (recording)
            {
#if UNITY_IOS && !UNITY_EDITOR
                List <BlendShape> tmpBlendShapes = new List <BlendShape>();
                frame++;

                using (var m_blendShapes = m_ARKitFaceSubsystem.GetBlendShapeCoefficients(m_Face.trackableId, Allocator.Temp))
                {
                    foreach (var featureCoefficient in m_blendShapes)
                    {
                        BlendShape blendShape = new BlendShape()
                        {
                            shapeKey = featureCoefficient.blendShapeLocation.ToString(),
                            value    = featureCoefficient.coefficient
                        };

                        tmpBlendShapes.Add(blendShape);
                    }
                }

                //getting blend shape data
                BlendShapeData blendShapeData = new BlendShapeData()
                {
                    blendShapes = tmpBlendShapes,
                    frame       = frame
                };

                blendShapeDataList.Add(blendShapeData);

                string json = JsonUtility.ToJson(blendShapeData);

                if (lastFrame)
                {
                    string par = "]}";
                    json     += par;
                    recording = false;
                }
                JsonFileWriter.WriteDataToFile(path: filePath, text: json, title: "", lastFrame: lastFrame);
                if (lastFrame)
                {
                    filePath = null;
                }
#endif
            }
        }
Exemplo n.º 8
0
    void UpdateFaceFeatures()
    {
        if (skinnedMeshRenderer == null || !skinnedMeshRenderer.enabled || skinnedMeshRenderer.sharedMesh == null)
        {
            return;
        }

        using (var blendShapes = arKitFaceSubsystem.GetBlendShapeCoefficients(face.trackableId, Allocator.Temp))
        {
            foreach (var featureCoefficient in blendShapes)
            {
                int mappedBlendShapeIndex;
                if (faceArkitBlendShapeIndexMap.TryGetValue(featureCoefficient.blendShapeLocation, out mappedBlendShapeIndex))
                {
                    if (mappedBlendShapeIndex >= 0)
                    {
                        skinnedMeshRenderer.SetBlendShapeWeight(mappedBlendShapeIndex, featureCoefficient.coefficient * blendShapeMappings.CoefficientScale);
                    }
                }
            }
        }
    }
Exemplo n.º 9
0
 void Detect()
 {
     if (!activate)
     {
         return;
     }
 #if UNITY_IOS && !UNITY_EDITOR
     using (var blendShapes = m_ARKitFaceSubsystem.GetBlendShapeCoefficients(m_Face.trackableId, Allocator.Temp))
     {
         foreach (var featureCoefficient in blendShapes)
         {
             if (featureCoefficient.blendShapeLocation == ARKitBlendShapeLocation.EyeBlinkLeft || featureCoefficient.blendShapeLocation == ARKitBlendShapeLocation.EyeBlinkRight)
             {
                 Debug.Log(featureCoefficient.coefficient);
                 if (featureCoefficient.coefficient > 0.9)
                 {
                     blinkEvent.Raise();
                     break;
                 }
             }
         }
     }
 #endif
 }