public void ApplyDNA(UMAData data, UMASkeleton skeleton)
        {
            if (morphSet == null)
            {
                Debug.LogError("Missing morph set asset for: " + this.name);
                return;
            }

            UMADnaBase activeDNA = data.GetDna(this.dnaTypeHash);

            if (activeDNA == null)
            {
                Debug.LogError("Could not get DNA values for: " + this.name);
                return;
            }

            if (morphSet.startingPose != null)
            {
                morphSet.startingPose.ApplyPose(skeleton, 1f);
            }
            if (!String.IsNullOrEmpty(morphSet.startingBlendShape))
            {
                data.SetBlendShape(morphSet.startingBlendShape, 1f);
            }

            if (activeDNA.Count == morphSet.dnaMorphs.Length)
            {
                float[] dnaValues = activeDNA.Values;
                for (int i = 0; i < dnaValues.Length; i++)
                {
                    float dnaValue = dnaValues[i];
                    MorphSetDnaAsset.DNAMorphSet morph = morphSet.dnaMorphs[i];

                    ApplyMorph(dnaValue, data, skeleton, morph);
                }
            }
            else
            {
                Debug.LogWarning("DNA length mismatch, trying names. This is SLOW!");
                string[] dnaNames = activeDNA.Names;
                for (int i = 0; i < morphSet.dnaMorphs.Length; i++)
                {
                    if (String.IsNullOrEmpty(morphSet.dnaMorphs[i].dnaEntryName))
                    {
                        continue;
                    }

                    int dnaIndex = System.Array.IndexOf(dnaNames, morphSet.dnaMorphs[i].dnaEntryName);
                    if (dnaIndex < 0)
                    {
                        continue;
                    }

                    float dnaValue = activeDNA.GetValue(dnaIndex);
                    MorphSetDnaAsset.DNAMorphSet morph = morphSet.dnaMorphs[i];

                    ApplyMorph(dnaValue, data, skeleton, morph);
                }
            }
        }
Example #2
0
 /// <summary>
 /// Finds the set dna name in the supplied dna list and applies the evaluator and multiplier to it.
 /// Tip: if you are already looping through the dna to find the name/value just use Evaluate(float dnaValue) instead for efficiency
 /// </summary>
 /// <param name="dna">The dna to search</param>
 /// <returns>The evaluated value</returns>
 public float Evaluate(UMADnaBase dna)
 {
     //using    lastIndex building dna takes apprx  00:00:00.0027695
     //Using    lastIndex modifying dna takes apprx 00:00:00.0004993
     //notusing lastIndex building dna takes apprx  00:00:00.0035695
     //notusing lastIndex modifying dna takes apprx 00:00:00.0008447
     //using lastIndex is about 1/3 faster at the cost of being less robust because the dnaNames could in theory be changed at runtime and lastIndex would then fail
     //could make the difference between being able to use things like color dna for wrinkle maps etc?
     if (_lastIndex != -1)
     {
         return(Evaluate(dna.GetValue(_lastIndex)));
     }
     else
     {
         _lastIndex = System.Array.IndexOf(dna.Names, _dnaName);
         if (_lastIndex > -1)
         {
             return(Evaluate(dna.GetValue(_lastIndex)));
         }
     }
     return(defaultDNAValue);
 }
        public void ApplyDNA(UMAData data, UMASkeleton skeleton)
        {
            UMADnaBase activeDNA = data.GetDna(this.dnaTypeHash);

            if (activeDNA == null)
            {
                Debug.LogError("Could not get DNA values for: " + this.name);
                return;
            }

            if (startingPose != null)
            {
                startingPose.ApplyPose(skeleton, 1f);
            }

            if (activeDNA.Count == dnaPoses.Length)
            {
                float[] dnaValues = activeDNA.Values;
                for (int i = 0; i < dnaValues.Length; i++)
                {
                    float dnaValue = dnaValues[i];
                    if ((dnaValue > 0.5f) && (dnaPoses[i].poseOne != null))
                    {
                        float poseWeight = (dnaValue - 0.5f) * 2f;
                        dnaPoses[i].poseOne.ApplyPose(skeleton, poseWeight);
                    }
                    else if ((dnaValue < 0.5f) && (dnaPoses[i].poseZero != null))
                    {
                        float poseWeight = (0.5f - dnaValue) * 2f;
                        dnaPoses[i].poseOne.ApplyPose(skeleton, poseWeight);
                    }
                }
            }
            else
            {
                Debug.LogWarning("DNA length mismatch, trying names. This is SLOW!");
                string[] dnaNames = activeDNA.Names;
                for (int i = 0; i < dnaPoses.Length; i++)
                {
                    if ((dnaPoses[i].dnaEntryName == null) || (dnaPoses[i].dnaEntryName.Length == 0))
                    {
                        continue;
                    }

                    int dnaIndex = System.Array.IndexOf(dnaNames, dnaPoses[i].dnaEntryName);
                    if (dnaIndex < 0)
                    {
                        continue;
                    }

                    float dnaValue = activeDNA.GetValue(dnaIndex);
                    if ((dnaValue > 0.5f) && (dnaPoses[i].poseOne != null))
                    {
                        float poseWeight = (dnaValue - 0.5f) * 2f;
                        dnaPoses[i].poseOne.ApplyPose(skeleton, poseWeight);
                    }
                    else if ((dnaValue < 0.5f) && (dnaPoses[i].poseZero != null))
                    {
                        float poseWeight = (0.5f - dnaValue) * 2f;
                        dnaPoses[i].poseOne.ApplyPose(skeleton, poseWeight);
                    }
                }
            }
        }