示例#1
0
        /**
         *	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 [] evaluate_target_blendshapes(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.get_number_of_blendshape_mappings(); mapping_nr++)
                {
                    string mapping_target = retargeting.get_blendshape_mapping_destination(mapping_nr);
                    if (!mapping_target.Equals(((BlendshapeInfo)target_blendshapes[index]).m_name))
                    {
                        continue;
                    }
                    string mapping_src = retargeting.get_blendshape_mapping_source(mapping_nr);
                    int    src_index   = rig.shape_index(mapping_src);
                    if (src_index >= 0)
                    {
                        double mapping_weight = retargeting.get_blendshape_mapping_weight(mapping_nr);
                        value += state.blendshape_coefficient(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);
        }
示例#2
0
		/**
		 *	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;
		}
		/// <summary>
		/// Applies the blendshapes given an influence factor
		/// </summary>
		/// <returns><c>true</c>, if blendshapes could be applied, <c>false</c> otherwise.</returns>
		/// <param name="transformationsToSet">The set of blendshapes to apply</param>
		/// <param name="influence">The factor to apply the blendshapes. 0.0 means that they are not used at all and the current
		/// animations are not changed. 1.0 means that they are fully used.</param>
		protected bool ApplyBlendshapes(BlendshapeValue [] blendshapesToSetToSet, float influence) {
			
			if (blendshapesToSetToSet.Length != m_GameObjectBlendshapes.Count) {
				return false;
			}
			
			for (int index = 0; index < m_GameObjectBlendshapes.Count; index++) {
				// Apply the value for this target
				if (blendshapesToSetToSet[index] != null) {
					BlendshapeInfo bs_info = m_GameObjectBlendshapes[index] as BlendshapeInfo;
					float originalValue = bs_info.m_mesh_renderer.GetBlendShapeWeight(bs_info.m_index);
					float newValue = (float)blendshapesToSetToSet[index].m_value;
					bs_info.m_mesh_renderer.SetBlendShapeWeight(bs_info.m_index, influence * newValue + (1.0f - influence) * originalValue);
				}
			}
			return true;
		}