/// <summary> /// Get the measurements used to determine the sphere position and radius /// </summary> /// <returns>Boolean if all measurements are valid</returns> internal bool MeasureSphere(ChaControl chaControl, Vector3 charScale, Vector3 nHeightScale, Vector3 totalScale) { //Measeurements need to be recalculated from saved values (Does not change waistWidth! or height) var newSphereRadius = GetSphereRadius(bellyInfo.WaistHeight, bellyInfo.WaistWidth, totalScale); var newSphereRadiusMult = newSphereRadius * (GetInflationMultiplier() + 1); //Store new values for later checks bellyInfo = new BellyInfo(bellyInfo.WaistWidth, bellyInfo.WaistHeight, newSphereRadiusMult, newSphereRadius, charScale, GetInflationMultiplier(), bellyInfo.WaistThick, nHeightScale, bellyInfo.BellyToBreastDist, chaControl.transform.localScale, bellyInfo.MeshRootDidMove); if (PregnancyPlusPlugin.DebugLog.Value) { PregnancyPlusPlugin.Logger.LogInfo($" MeasureSphere Recalc "); } return(bellyInfo.WaistWidth > 0 && newSphereRadius > 0 && bellyInfo.WaistThick > 0); }
/// <summary> /// Get the characters waist width and calculate the appropriate belly sphere radius from it /// Smaller characters have smaller bellies, wider characters have wider bellies etc... /// </summary> /// <param name="chaControl">The character to measure</param> /// <param name="forceRecalc">For debuggin, will recalculate from scratch each time when true</param> /// <returns>Boolean if all measurements are valid</returns> internal bool MeasureWaistAndSphere(ChaControl chaControl, bool forceRecalc = false) { var bodyTopScale = PregnancyPlusHelper.GetBodyTopScale(ChaControl); var nHeightScale = PregnancyPlusHelper.GetN_HeightScale(ChaControl); var charScale = ChaControl.transform.localScale; var totalScale = new Vector3(bodyTopScale.x * charScale.x, bodyTopScale.y * charScale.y, bodyTopScale.z * charScale.z); var needsWaistRecalc = bellyInfo != null?bellyInfo.NeedsBoneDistanceRecalc(bodyTopScale, nHeightScale, charScale) : true; var needsSphereRecalc = bellyInfo != null?bellyInfo.NeedsSphereRecalc(infConfig, GetInflationMultiplier()) : true; //We should reuse existing measurements when we can, because characters waise bone distance chan change with animation, which affects belly size. if (bellyInfo != null) { if (!forceRecalc && needsSphereRecalc && !needsWaistRecalc)//Sphere radius calc needed { var _valid = MeasureSphere(chaControl, bodyTopScale, nHeightScale, totalScale); if (PregnancyPlusPlugin.DebugLog.Value) { PregnancyPlusPlugin.Logger.LogInfo(bellyInfo.Log()); } return(_valid); } else if (!forceRecalc && needsWaistRecalc && !needsSphereRecalc)//Measurements needed which also requires sphere recalc { var _valid = MeasureWaist(chaControl, charScale, nHeightScale, out float _waistToRibDist, out float _waistToBackThickness, out float _waistWidth, out float _bellyToBreastDist); MeasureSphere(chaControl, bodyTopScale, nHeightScale, totalScale); //Store all these values for reuse later bellyInfo = new BellyInfo(_waistWidth, _waistToRibDist, bellyInfo.SphereRadius, bellyInfo.OriginalSphereRadius, bodyTopScale, GetInflationMultiplier(), _waistToBackThickness, nHeightScale, _bellyToBreastDist, charScale, bellyInfo.MeshRootDidMove); if (PregnancyPlusPlugin.DebugLog.Value) { PregnancyPlusPlugin.Logger.LogInfo(bellyInfo.Log()); } return(_valid); } else if (!forceRecalc && !needsSphereRecalc && !needsWaistRecalc)//No changed needed { //Just return the original measurements and sphere radius when no updates needed if (PregnancyPlusPlugin.DebugLog.Value) { PregnancyPlusPlugin.Logger.LogInfo(bellyInfo.Log()); } //Measeurements are fine and can be reused if above 0 return(bellyInfo.WaistWidth > 0 && bellyInfo.SphereRadius > 0 && bellyInfo.WaistThick > 0); } } //Measeurements need to be recalculated from scratch if (PregnancyPlusPlugin.DebugLog.Value) { PregnancyPlusPlugin.Logger.LogInfo($" MeasureWaistAndSphere init "); } //Get waist measurements from bone distances var valid = MeasureWaist(chaControl, charScale, nHeightScale, out float waistToRibDist, out float waistToBackThickness, out float waistWidth, out float bellyToBreastDist); //Check for bad values if (!valid) { return(false); } //Calculate sphere radius based on distance from waist to ribs (seems big, but lerping later will trim much of it), added Math.Min for skinny waists var sphereRadius = GetSphereRadius(waistToRibDist, waistWidth, totalScale); var sphereRadiusMultiplied = sphereRadius * (GetInflationMultiplier() + 1); //Store all these values for reuse later bellyInfo = new BellyInfo(waistWidth, waistToRibDist, sphereRadiusMultiplied, sphereRadius, bodyTopScale, GetInflationMultiplier(), waistToBackThickness, nHeightScale, bellyToBreastDist, charScale); if (PregnancyPlusPlugin.DebugLog.Value) { PregnancyPlusPlugin.Logger.LogInfo(bellyInfo.Log()); } return(waistWidth > 0 && sphereRadiusMultiplied > 0 && waistToBackThickness > 0 && bellyToBreastDist > 0); }