示例#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);
        }