コード例 #1
0
		public bool LoadRetargetingFromAsset(TextAsset asset) {
			
			if (asset == null) return false;
			
			ClipRetargeting retargeting = ClipRetargeting.Load(asset.bytes, /*fromAsset=*/true);
			if (retargeting == null || retargeting.IsEmpty()) {
				ResetRetargeting();
				return false;
			}
			
			m_Retargeting = retargeting;
			m_RetargetingAsset = asset;
			
			return true;
		}
コード例 #2
0
		public void ClearRetargeting() {
			m_Retargeting = new ClipRetargeting();
			m_RetargetingAsset = null;
			ClearCachedRig();
		}
コード例 #3
0
ファイル: Utils.cs プロジェクト: tommyfriday/ITP_Storytelling
		/**
		 *	Evaluates the target transformation based on the state of a rig and a retargeting configuration.
		 *  If a transform is not affected by the retargeting then the value of the transform is null.
		 */
		public static TransformationValue [] EvaluateTargetTransformations(ClipRetargeting retargeting,
		                                                       Rig rig,
		                                                       RigState state,
		                                                       ArrayList target_transformations) {
		                                                       
			if (retargeting == null || rig == null || state == null || target_transformations == null) {
				Debug.LogError("cannot evaluat target transformations as one or more object is null");
				return null;
			}
			
			int n_target_transformations = target_transformations.Count;
			TransformationValue [] values = new TransformationValue[n_target_transformations];
			// We iterate over the target transformations and accumulate all sources to them
			for (int target_nr = 0; target_nr < target_transformations.Count; target_nr++) {
				
				// get original rotation and translation from tpose
				TransformationInformation tpose_joint = target_transformations[target_nr] as TransformationInformation;
				if (tpose_joint == null) {
					Debug.LogError("joint " + target_nr + " is null");
					continue;
				}
				Vector3 tpose_translation               = tpose_joint.localPosition;
				Quaternion tpose_local_rotation         = tpose_joint.localRotation;
				Quaternion tpose_parent_global_rotation = tpose_joint.parentRotation;
				
				Quaternion fs_joint_rotation_local_from_t_pose = Quaternion.identity;
				Vector3 fs_joint_translation_local_from_t_pose = new Vector3(0, 0, 0);
				
				// Sum the translation to apply
				int value_count_trans = 0;
				for (int mapping_nr = 0; mapping_nr < retargeting.GetNumberOfTranslationMappings(); mapping_nr++) {
					string mapping_target = retargeting.GetTranslationMappingDestination (mapping_nr);
					if (!mapping_target.Equals(tpose_joint.transformName)) {
						continue;
					}
					string mapping_src = retargeting.GetTranslationMappingSource (mapping_nr);
					int src_index = rig.BoneIndex (mapping_src);
					if (src_index >= 0) {
						double mapping_weight = retargeting.GetTranslationMappingWeight (mapping_nr);
						fs_joint_translation_local_from_t_pose += state.BoneTranslation (src_index) * (float)mapping_weight;
						value_count_trans++;
					} else {
						Debug.Log ("Could not find source index for '" + mapping_src + "'");
					}
				} 
				
				// Convert translation to global translation
				//Vector3 unity_joint_translation_local = fs_joint_translation_local_from_t_pose + tpose_translation;
				Vector3 unity_joint_translation_local = 
					Quaternion.Inverse(tpose_parent_global_rotation) * fs_joint_translation_local_from_t_pose
					+ tpose_translation;
						
				// Sum the rotations to apply
				int value_count_rot = 0;
				for (int mapping_nr = 0; mapping_nr < retargeting.GetNumberOfRotationMappings(); mapping_nr++) {
					string mapping_target = retargeting.GetRotationMappingDestination (mapping_nr);
					if (!mapping_target.Equals (tpose_joint.transformName)) {
						continue;
					}
					string mapping_src = retargeting.GetRotationMappingSource (mapping_nr);
					int src_index = rig.BoneIndex (mapping_src);
					if (src_index >= 0) {
						double mapping_weight = retargeting.GetRotationMappingWeight (mapping_nr);
						
						// use slerp for weighting
						fs_joint_rotation_local_from_t_pose = Quaternion.Slerp (Quaternion.identity, state.BoneRotation (src_index), (float)mapping_weight);
						// TODO: here we should accumulate if there are more than one sources (like with blendshapes)
						value_count_rot++;
					} else {
						Debug.Log ("Could not find source rotation for '" + mapping_src);
					}
				} 
				
				// Convert to local unity rotation
				Quaternion unity_joint_rotation_local = 
						Quaternion.Inverse(tpose_parent_global_rotation) 
					 		* fs_joint_rotation_local_from_t_pose 
							* tpose_parent_global_rotation
							* tpose_local_rotation; // The initial local rotation;

				if (value_count_trans > 0 || value_count_rot > 0) {
					values[target_nr] = new TransformationValue(unity_joint_rotation_local, unity_joint_translation_local);
				}
			}
			
			return values;
		}
コード例 #4
0
ファイル: Utils.cs プロジェクト: tommyfriday/ITP_Storytelling
		/**
		 *	Evaluates the target blendshape values based on the state of a rig and a retargeting configuration.
		 *  If a blendshape is not affected by the retargeting then the value of this blendshape is null.
		 */
		public static BlendshapeValue [] EvaluateTargetBlendshapes(ClipRetargeting retargeting,
						                                             Rig rig,
						                                             RigState state,
						                                             ArrayList target_blendshapes) {
						                                             
			int n_target_blendshapes = target_blendshapes.Count;
			BlendshapeValue [] values = new BlendshapeValue[n_target_blendshapes];
			// We iterate over the targets and accumulate all sources to them
			for (int index = 0; index < n_target_blendshapes; index++) {
				double value = 0.0;
				int value_count = 0;
				for (int mapping_nr = 0; mapping_nr < retargeting.GetNumberOfBlendshapeMappings(); mapping_nr++) {
					string mapping_target = retargeting.GetBlendshapeMappingDestination(mapping_nr);
					if (!mapping_target.Equals(((BlendshapeInfo)target_blendshapes[index]).m_name)) {
						continue;
					}
					string mapping_src = retargeting.GetBlendshapeMappingSource(mapping_nr);
					int src_index = rig.ShapeIndex(mapping_src);
					if (src_index >= 0) {
						double mapping_weight = retargeting.GetBlendshapeMappingWeight(mapping_nr);
						value += state.BlendshapeCoefficient(src_index) * mapping_weight;
						value_count++;
					} else {
						Debug.Log("Could not find source blend shape '" + mapping_src);
					}
				} 
				// Apply the value for this target
				if (value_count > 0) {
					values[index] = new BlendshapeValue(value);
				}
			}
			return values;
		}
コード例 #5
0
		public void ResetRetargeting() {
			m_Retargeting = null;
			m_RetargetingAsset = null;
		}