示例#1
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;
	    }
示例#2
0
		//! duplicate this clip (deep copy)
		public Clip Duplicate() {
		
			Rig rig = m_rig.Duplicate();
			Clip clip = new Clip(rig);
			for (int i = 0; i < m_states.Count; i++) {
				clip.m_states.Add(m_states[i].Duplicate());
			}
			return clip;
		}
示例#3
0
		public void Reset() {
	
			m_clip = null;
			m_clip_path = "";
		}
示例#4
0
	    //! @brief Loads a faceshift clip
	    public void LoadFSB(string path) {
	    
			if (!File.Exists (path)) {
				#if UNITY_EDITOR
				EditorUtility.DisplayDialog("Clip loading failed", "File " + path + " does exist", "Ok");
				#endif
				return;
			}
			
	        Clip new_clip = FsbReader.Read(path);
			if (new_clip == null) {
				Debug.LogError("could not read clip from file " + path);
				#if UNITY_EDITOR
				EditorUtility.DisplayDialog("Load failed", "File " + path + " does not contain a clip", "Ok");
				#endif
				return;
			}
	
	        Rig clip_rig = new_clip.Rig();
	
			if (IsSourceRigDifferent(clip_rig)) {
				if ((cachedRigLoaded) && (!SourceRigChangedAskToContinue ())) {
					// The user wants to cancel
					return;
				}
	        }
	
			// always save new rig from the fsb file to have the same order
	
			// Apply new rig
			m_fs_Rig = clip_rig;
			
			// Cache new rig
			SaveSourceRig();
	
	        m_clip = new_clip;
			m_clip_path = path;
	    }