Esempio n. 1
0
 public void AdjustScale(UMASkeleton skeleton)
 {
     if (_adjustScale)
     {
         if (skeleton.HasBone(scaleBoneHash))
         {
             var   liveScaleResult   = _liveScale != -1f ? _liveScale : _scale;
             float finalOverallScale = skeleton.GetScale(_scaleBoneHash).x *liveScaleResult;                     //hmm why does this work- its supposed to be +
             skeleton.SetScale(_scaleBoneHash, new Vector3(finalOverallScale, finalOverallScale, finalOverallScale));
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Apply the modifiers using the given dna (determined by the typehash)
        /// </summary>
        /// <param name="umaData"></param>
        /// <param name="skeleton"></param>
        /// <param name="dnaTypeHash"></param>
        public override void ApplyDNA(UMAData umaData, UMASkeleton skeleton, int dnaTypeHash)
        {
            var umaDna           = umaData.GetDna(dnaTypeHash);
            var masterWeightCalc = masterWeight.GetWeight(umaDna);

            if (masterWeightCalc == 0f)
            {
                return;
            }
            for (int i = 0; i < _skeletonModifiers.Count; i++)
            {
                _skeletonModifiers[i].umaDNA = umaDna;

                var thisHash = (_skeletonModifiers[i].hash != 0) ? _skeletonModifiers[i].hash : UMAUtils.StringToHash(_skeletonModifiers[i].hashName);

                //check skeleton has the bone we want to change
                if (!skeleton.HasBone(thisHash))
                {
                    //Debug.LogWarning("You were trying to apply skeleton modifications to a bone that didn't exist (" + _skeletonModifiers[i].hashName + ") on " + umaData.gameObject.name);
                    continue;
                }

                //With these ValueX.x is the calculated value and ValueX.y is min and ValueX.z is max
                var thisValueX = _skeletonModifiers[i].CalculateValueX(umaDna);
                var thisValueY = _skeletonModifiers[i].CalculateValueY(umaDna);
                var thisValueZ = _skeletonModifiers[i].CalculateValueZ(umaDna);

                if (_skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Position)
                {
                    skeleton.SetPositionRelative(thisHash,
                                                 new Vector3(
                                                     Mathf.Clamp(thisValueX.x, thisValueX.y, thisValueX.z),
                                                     Mathf.Clamp(thisValueY.x, thisValueY.y, thisValueY.z),
                                                     Mathf.Clamp(thisValueZ.x, thisValueZ.y, thisValueZ.z)), masterWeightCalc);
                }
                else if (_skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Rotation)
                {
                    skeleton.SetRotationRelative(thisHash,
                                                 Quaternion.Euler(new Vector3(
                                                                      Mathf.Clamp(thisValueX.x, thisValueX.y, thisValueX.z),
                                                                      Mathf.Clamp(thisValueY.x, thisValueY.y, thisValueY.z),
                                                                      Mathf.Clamp(thisValueZ.x, thisValueZ.y, thisValueZ.z))), masterWeightCalc);
                }
                else if (_skeletonModifiers[i].property == SkeletonModifier.SkeletonPropType.Scale)
                {
                    //If there are two sets of skeletonModifiers and both are at 50% it needs to apply them both but the result should be cumulative
                    //so we need to work out the difference this one is making, weight that and add it to the current scale of the bone
                    var scale = new Vector3(
                        Mathf.Clamp(thisValueX.x, thisValueX.y, thisValueX.z),
                        Mathf.Clamp(thisValueY.x, thisValueY.y, thisValueY.z),
                        Mathf.Clamp(thisValueZ.x, thisValueZ.y, thisValueZ.z));
                    //we cant use val.value here because the initial values always need to be applied
                    var defaultVal = SkeletonModifier.skelAddDefaults[SkeletonModifier.SkeletonPropType.Scale].x;
                    var scaleDiff  = new Vector3(scale.x - defaultVal,
                                                 scale.y - defaultVal,
                                                 scale.z - defaultVal);
                    var weightedScaleDiff = scaleDiff * masterWeightCalc;
                    var fullScale         = skeleton.GetScale(_skeletonModifiers[i].hash) + weightedScaleDiff;
                    skeleton.SetScale(thisHash, fullScale);
                }
            }
        }