Example #1
0
        /**
         * @brief Creates a new state and adds it to this clip.
         * @param[in] timestamp    The timestamp for this new state.
         * @return The newly created state.
         */
        public RigState new_state(double timestamp)
        {
            RigState state = new RigState(m_rig);

            state.set_timestamp(timestamp);
            m_states.Add(state);
            return(state);
        }
Example #2
0
        void Update()
        {
            // ten kod kalkuluje bazowa pozycje glowy
            // trzeba jeszcze dorobic zeby przechwytywal trigerra
            // i wtedy zmieniał isBaseCalculated na false
            // i resetował timer i kalkulował jeszcze raz
            // pozniej trzeba jeszcze dodac zeby kazda metoda zwracała
            // to co zwraca minus base
            if (!isBaseCalculated)
            {
                timer += Time.deltaTime;
                if (timer < baseCalculationTime)
                {
                    if (getXHeadRotation() != -1)
                    {
                        baseX += getXHeadRotation();
                        ticksX++;
                    }

                    if (getYHeadRotation() != -1)
                    {
                        baseY += getYHeadRotation();
                        ticksY++;
                    }
                }
                else
                {
                    baseX           /= ticksX;
                    baseY           /= ticksY;
                    isBaseCalculated = true;
                }
            }


            new_data = false;
            m_mutex.WaitOne();
            // check if there are new blendshape names, and if so update
            if (newBlendShapeNamesArrived())
            {
                m_rig = getRigFromBlendShapeNames(getBlendShapeNames());
            }

            // get most recent tracking data
            while (m_data_parser.CountAvailableTracks() > 0)
            {
                m_current_track = m_data_parser.Dequeue();
                new_data        = true;
            }

            // check that we have a rig (set up from blendshape names) with the same number of blendshapes as what we receive
            if (m_rig != null && m_current_track != null)
            {
                int n_track_coefficients = m_current_track.n_coefficients();
                int n_rig_coefficients   = m_rig.num_shapes();
                if (n_track_coefficients != n_rig_coefficients)
                {
                    Debug.LogWarning("number of coefficients of rig and tracking state have changed: " + n_track_coefficients + " vs " + n_rig_coefficients);
                    // clear the current rig as it is not usable with the data coming from faceshift
                    m_rig           = null;
                    m_current_track = null;
                    // get again the blendshapes from fs studio
                    askForBlendshapeNames();
                }
            }
            m_mutex.ReleaseMutex();

            if (m_rig != null && m_current_track != null && m_retargeting != null)
            {
                if (new_data && m_current_track.TrackSuccess)
                {
                    // create a rig state
                    RigState state = new RigState(m_rig);
                    state.set_timestamp(m_current_track.TimeStamp);
                    state.set_bone_translation(0, m_current_track.HeadTranslation());
                    state.set_bone_rotation(0, m_current_track.HeadRotation());
                    state.set_bone_rotation(1, m_current_track.LeftEyeRotation());
                    state.set_bone_rotation(2, m_current_track.RightEyeRotation());

                    for (int i = 0; i < m_rig.num_shapes(); i++)
                    {
                        state.set_blendshape_coefficient(i, m_current_track.Coefficient [i]);
                    }

                    // evaluate joint transformations
                    TransformationValue [] transformation_values = null;
                    if (m_tpose != null && m_tpose.m_joints.Count == m_game_object_transformations.Count)
                    {
                        // evaluate using tpose
                        transformation_values = Utils.evaluate_target_transformations(m_retargeting, m_rig, state, m_tpose.m_joints);
                    }
                    else
                    {
                        // evaluate using state from start of application
                        transformation_values = Utils.evaluate_target_transformations(m_retargeting, m_rig, state, m_game_object_transformations);
                    }

                    if (transformation_values.Length == m_game_object_transformations.Count)
                    {
                        for (int index = 0; index < transformation_values.Length; index++)
                        {
                            // Apply the value for this target
                            if (transformation_values [index] != null)
                            {
                                TransformationInformation joint = m_game_object_transformations [index] as TransformationInformation;
                                joint.transform.localRotation = transformation_values [index].m_rotation;
                                joint.transform.localPosition = transformation_values [index].m_translation;
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Cannot create transformation as evaluated shape size is incorrect");
                    }

                    // evaluate blendshape valuesf
                    BlendshapeValue [] values = Utils.evaluate_target_blendshapes(m_retargeting, m_rig, state, m_game_object_blendshapes);

                    if (values.Length == m_game_object_blendshapes.Count)
                    {
                        for (int index = 0; index < m_game_object_blendshapes.Count; index++)
                        {
                            BlendshapeInfo bs_info = m_game_object_blendshapes [index] as BlendshapeInfo;
                            // Apply the value for this target
                            if (bs_info != null && values [index] != null)
                            {
                                bs_info.m_mesh_renderer.SetBlendShapeWeight(bs_info.m_index, (float)values [index].m_value);
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("Cannot create blendshapes as evaluated shape size is incorrect");
                    }
                }
            }
        }