示例#1
0
        void Update()
        {
            bool new_data = false;

            m_mutex.WaitOne();
            // check if there are new blendshape names, and if so update
            if (NewBlendShapeNamesArrived())
            {
                m_rig = 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.NumShapes();
                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.SetTimestamp(m_current_track.TimeStamp);
                    state.SetBoneTranslation(0, m_current_track.HeadTranslation());
                    state.SetBoneRotation(0, m_current_track.HeadRotation());
                    state.SetBoneRotation(1, m_current_track.LeftEyeRotation());
                    state.SetBoneRotation(2, m_current_track.RightEyeRotation());
                    for (int i = 0; i < m_rig.NumShapes(); i++)
                    {
                        state.SetBlendshapeCoefficient(i, m_current_track.Coefficient[i]);
                    }

                    base.UpdateAnimation(m_rig, state);
                }
            }
        }
		void Update () {
		
			bool new_data = false;
			m_mutex.WaitOne();
			// check if there are new blendshape names, and if so update
			if (NewBlendShapeNamesArrived()) {
				m_rig = 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.NumShapes();
				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.SetTimestamp(m_current_track.TimeStamp);
					state.SetBoneTranslation(0, m_current_track.HeadTranslation());
					state.SetBoneRotation(0, m_current_track.HeadRotation());
					state.SetBoneRotation(1, m_current_track.LeftEyeRotation());
					state.SetBoneRotation(2, m_current_track.RightEyeRotation());
					for (int i = 0; i < m_rig.NumShapes(); i++) {
						state.SetBlendshapeCoefficient(i, m_current_track.Coefficient[i]);
					}
					
					base.UpdateAnimation(m_rig, state);
				}
			}
		}
示例#3
0
        /**
         * @brief Reads an fsb file and returns a clip constructed from the the content of the fsb file.
         * @param[in] data  The binary data from the fsb file.
         * @return A clip with the track data imported from the fsb file, null if there was some error during loading.
         */
        public static Clip Read(byte[] data)
        {
            DataParser parser = new DataParser();

            parser.ExtractData(data, false, 0.0);

            if (parser.Valid())
            {
                Rig rig = new Rig();

                // add hardcoded bone names of fsb file
                rig.AddBone("Neck");
                rig.AddBone("EyeLeft");
                rig.AddBone("EyeRight");

                for (int i = 0; i < parser.fsBlendShapeNames.Length; i++)
                {
                    rig.AddShape(parser.fsBlendShapeNames[i]);
                }

                Clip clip = new Clip(rig);

                while (parser.CountAvailableTracks() > 0)
                {
                    TrackData track_data = parser.Dequeue();

                    if (!track_data.TrackSuccess)
                    {
                        // do not save the state if the tracking data is not valid
                        Debug.LogWarning("this frame doesn't contain valid tracking data");
                        continue;
                    }

                    RigState state = clip.NewState(track_data.TimeStamp);

                    state.SetTrackingSuccessful(track_data.TrackSuccess);

                    if (rig.NumShapes() != track_data.n_coefficients())
                    {
                        Debug.LogError("num blendshapes do not agree in file with " + rig.NumShapes() +
                                       " in rig and " + track_data.n_coefficients() + " in state");
                        return(null);
                    }

                    // Assume the head translation to be joint 0 (Neck)
                    state.SetBoneTranslation(0, track_data.HeadTranslation());

                    // bone indices same as the order when added to the rig
                    state.SetBoneRotation(0, track_data.HeadRotation());
                    state.SetBoneRotation(1, track_data.LeftEyeRotation());
                    state.SetBoneRotation(2, track_data.RightEyeRotation());

                    for (int i = 0; i < track_data.n_coefficients(); i++)
                    {
                        state.SetBlendshapeCoefficient(i, track_data.Coefficient[i]);
                    }
                }

                return(clip);
            }
            else
            {
                Debug.LogError("cannot parse fsb file");
            }

            return(null);
        }