Esempio n. 1
0
    private void RefreshActionUnits()
    {
        // initialize action units
        if (ActionUnitCount == 0)
        {
            ActionUnitCount = VisageTrackerNative._getActionUnitCount();
            ActionUnits     = new ActionUnitData[ActionUnitCount];
            for (int actionUnitIndex = 0; actionUnitIndex < ActionUnitCount; actionUnitIndex++)
            {
                string         name           = Marshal.PtrToStringAnsi(VisageTrackerNative._getActionUnitName(actionUnitIndex));
                bool           used           = VisageTrackerNative._getActionUnitUsed(actionUnitIndex);
                ActionUnitData actionUnitData = new ActionUnitData(actionUnitIndex, name, used);
                ActionUnits [actionUnitIndex] = actionUnitData;
            }
        }

        // get action unit values
        if (ActionUnitCount > 0)
        {
            float[] values = new float[ActionUnitCount];
            VisageTrackerNative._getActionUnitValues(values);
            for (int actionUnitIndex = 0; actionUnitIndex < ActionUnitCount; actionUnitIndex++)
            {
                ActionUnits [actionUnitIndex].Value = values [actionUnitIndex];
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
                #if (UNITY_IPHONE || UNITY_ANDROID) && UNITY_EDITOR
        // no tracking on ios while in editor
        return;
                #endif

        if (masterTrackingController.CurrentTracker != 0)
        {
            return;
        }

        if (isTracking)
        {
            // find device orientation
            currentOrientation = GetDeviceOrientation();

            // check if orientation or camera device changed
            if (currentOrientation != Orientation || currentDevice != device)
            {
                OpenCamera(currentOrientation, currentDevice, defaultCameraWidth, defaultCameraHeight, isMirrored);
                Orientation = currentOrientation;
                device      = currentDevice;
                texture     = null;
            }

            // grab current frame and start face tracking
            VisageTrackerNative._grabFrame();

            TrackerStatus = VisageTrackerNative._track();

            // update tracker status and translation and rotation
            VisageTrackerNative._get3DData(out Translation.x, out Translation.y, out Translation.z, out Rotation.x, out Rotation.y, out Rotation.z);

            this.transform.position = Translation;
            this.transform.rotation = Quaternion.Euler(Rotation);

            VisageTrackerNative._getCameraInfo(out Focus, out ImageWidth, out ImageHeight);

            float aspect = ImageWidth / (float)ImageHeight;

            float yRange = (ImageWidth > ImageHeight) ? 1.0f : 1.0f / aspect;

            Camera.main.fieldOfView = Mathf.Rad2Deg * 2.0f * Mathf.Atan(yRange / Focus);

            VisageTrackerNative._getFaceModel(out VertexNumber, vertices, out TriangleNumber, triangles, texCoords);

            // vertices
            if (Vertices.Length != VertexNumber)
            {
                Vertices = new Vector3[VertexNumber];
            }

            for (int i = 0; i < VertexNumber; i++)
            {
                Vertices [i] = new Vector3(vertices [i * 3 + 0], vertices [i * 3 + 1], vertices [i * 3 + 2]);
            }

            // triangles
            if (Triangles.Length != TriangleNumber)
            {
                Triangles = new int[TriangleNumber * 3];
            }

            for (int i = 0; i < TriangleNumber * 3; i++)
            {
                Triangles [i] = triangles [i];
            }

            // tex coords
            if (TexCoords.Length != VertexNumber)
            {
                TexCoords = new Vector2[VertexNumber];
            }

            for (int i = 0; i < VertexNumber; i++)
            {
                TexCoords[i] = new Vector2(modelTexCoords[i].x, modelTexCoords[i].y);                 //new Vector2 (texCoords [i * 2 + 0], texCoords [i * 2 + 1]);
            }

            // action unit values
            VisageTrackerNative._getActionUnitValues(values);
            ActionUnitValues = values;
        }

        RefreshImage();

        meshFilter.mesh.Clear();
    }