Пример #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
		//! @returns a rig build from a set of blendshape names
		static public Rig GetRigFromBlendShapeNames(string [] blendshape_names) {
			Rig rig = new Rig();
			rig.AddBone("Neck");
			rig.AddBone("EyeLeft");
			rig.AddBone("EyeRight");
			for (int i = 0; i < blendshape_names.Length; i++) {
				rig.AddShape(blendshape_names[i]);
			}
			return rig;
		}
Пример #3
0
		//! duplicate this rig (deep copy)
		public Rig Duplicate() {
		
			Rig rig = new Rig ();
			for (int i = 0; i < NumShapes(); i++) rig.AddShape(ShapeName(i));
			for (int i = 0; i < NumBones() ; i++) rig.AddBone(BoneName(i));
			return rig;
		}