miijs 2.3.3 → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +71 -63
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -3230,78 +3230,82 @@ function generateInstructions(mii, full) {
|
|
|
3230
3230
|
}
|
|
3231
3231
|
}
|
|
3232
3232
|
|
|
3233
|
-
function
|
|
3234
|
-
|
|
3235
|
-
const
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
}
|
|
3244
|
-
else {
|
|
3245
|
-
// Upper half: 64–127 maps to 69–84
|
|
3246
|
-
totalInches = midInches + ((value - midPoint) / (127 - midPoint)) * (maxInches - midInches);
|
|
3247
|
-
}
|
|
3248
|
-
|
|
3249
|
-
const feet = Math.floor(totalInches / 12);
|
|
3250
|
-
const inches = Math.round(totalInches % 12);
|
|
3251
|
-
return { feet, inches, totalInches };
|
|
3233
|
+
function miiHeightToMeasurements(value) {
|
|
3234
|
+
// h in [0, 127]
|
|
3235
|
+
const totalInches = 36 + (48 / 127) * value; // 3' to 7'
|
|
3236
|
+
return {
|
|
3237
|
+
feet:Math.floor(totalInches / 12),
|
|
3238
|
+
inches:Math.round(totalInches % 12),
|
|
3239
|
+
totalInches,
|
|
3240
|
+
|
|
3241
|
+
centimeters:Math.round(totalInches*2.54)
|
|
3242
|
+
};
|
|
3252
3243
|
}
|
|
3253
3244
|
function inchesToMiiHeight(totalInches) {
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
let value;
|
|
3260
|
-
if (totalInches <= midInches) {
|
|
3261
|
-
// Below or equal to midpoint
|
|
3262
|
-
value = ((totalInches - minInches) / (midInches - minInches)) * midPoint;
|
|
3263
|
-
} else {
|
|
3264
|
-
// Above midpoint
|
|
3265
|
-
value = midPoint + ((totalInches - midInches) / (maxInches - midInches)) * (127 - midPoint);
|
|
3266
|
-
}
|
|
3267
|
-
|
|
3268
|
-
return Math.round(Math.max(0, Math.min(value, 127)));
|
|
3245
|
+
return ((totalInches - 36) * 127) / 48;
|
|
3246
|
+
}
|
|
3247
|
+
function centimetersToMiiHeight(totalCentimeters) {
|
|
3248
|
+
return ((Math.round(totalCentimeters/2.54) - 36) * 127) / 48;
|
|
3269
3249
|
}
|
|
3270
3250
|
|
|
3271
|
-
// Getting and setting Mii weights is HIGHLY EXPERIMENTAL and I am very unconfident in its output
|
|
3272
3251
|
// ---- Tunable anchors (BMI breakpoints) ----
|
|
3273
|
-
const BMI_MIN = 16;
|
|
3274
|
-
const BMI_MID =
|
|
3275
|
-
const BMI_MAX =
|
|
3276
|
-
function
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
let v;
|
|
3281
|
-
if (bmi <= BMI_MID) {
|
|
3282
|
-
const t = (clamp(bmi, BMI_MIN, BMI_MID) - BMI_MIN) / (BMI_MID - BMI_MIN);
|
|
3283
|
-
v = 0 + t * 64;
|
|
3252
|
+
const BMI_MIN = 16;
|
|
3253
|
+
const BMI_MID = 22;
|
|
3254
|
+
const BMI_MAX = 35;
|
|
3255
|
+
function bmiFromWeightSlider(w) {
|
|
3256
|
+
// w in [0, 127]
|
|
3257
|
+
if (w <= 64) {
|
|
3258
|
+
return BMI_MID - (64 - w) * (BMI_MID - BMI_MIN) / 64;
|
|
3284
3259
|
} else {
|
|
3285
|
-
|
|
3286
|
-
v = 64 + t * (127 - 64);
|
|
3260
|
+
return BMI_MID + (w - 64) * (BMI_MAX - BMI_MID) / 63;
|
|
3287
3261
|
}
|
|
3288
|
-
return Math.round(clamp(v, 0, 127));
|
|
3289
3262
|
}
|
|
3290
3263
|
function miiWeightToRealWeight(heightInches, miiWeight) {
|
|
3291
|
-
|
|
3292
|
-
|
|
3264
|
+
/*
|
|
3265
|
+
Take the height, map it to a reasonable height 0-127 === 3'-7'.
|
|
3266
|
+
Get the average weight for that height.
|
|
3267
|
+
Take the slider 0-127 for weight, assume 64 is the average midpoint.
|
|
3268
|
+
If less than 64, make the Mii's weight more underweight than the average.
|
|
3269
|
+
If higher, make the Mii's weight more overweight than the average.
|
|
3270
|
+
The shorter the height, the less drastic the weight changes.
|
|
3271
|
+
|
|
3272
|
+
This is approximate, not guaranteed accurate nor intended to be taken that way. This is for entertainment value only.
|
|
3273
|
+
*/
|
|
3274
|
+
if (!heightInches || heightInches < 0) throw new Error("heightInches must be >= 0");
|
|
3275
|
+
const H = miiHeightToMeasurements(heightInches).totalInches;
|
|
3276
|
+
const BMI = bmiFromWeightSlider(miiWeight);
|
|
3277
|
+
return {
|
|
3278
|
+
pounds:BMI * (H * H) / 703,
|
|
3279
|
+
kilograms:Math.round((BMI * (H * H) / 703)*0.4535924)
|
|
3280
|
+
};
|
|
3281
|
+
}
|
|
3282
|
+
function imperialHeightWeightToMiiWeight(heightInches, weightLbs) {
|
|
3283
|
+
if (!heightInches || heightInches < 0) throw new Error("heightInches must be >= 0");
|
|
3293
3284
|
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3285
|
+
const H = miiHeightToMeasurements(heightInches).totalInches;
|
|
3286
|
+
const BMI = weightLbs * 703 / (H * H);
|
|
3287
|
+
|
|
3288
|
+
if (BMI <= BMI_MID) {
|
|
3289
|
+
return 64 - 64 * (BMI_MID - BMI) / (BMI_MID - BMI_MIN);
|
|
3290
|
+
}
|
|
3291
|
+
else {
|
|
3292
|
+
return 64 + 63 * (BMI - BMI_MID) / (BMI_MAX - BMI_MID);
|
|
3301
3293
|
}
|
|
3294
|
+
}
|
|
3295
|
+
function metricHeightWeightToMiiWeight(heightCentimeters, weightKilograms) {
|
|
3296
|
+
const heightInches=Math.round(heightCentimeters/2.54);
|
|
3297
|
+
const weightLbs=Math.round(weightKilograms/0.4535924);
|
|
3298
|
+
if (!heightInches || heightInches < 0) throw new Error("heightCentimeters must be >= 0");
|
|
3302
3299
|
|
|
3303
|
-
const
|
|
3304
|
-
|
|
3300
|
+
const H = miiHeightToMeasurements(heightInches).totalInches;
|
|
3301
|
+
const BMI = weightLbs * 703 / (H * H);
|
|
3302
|
+
|
|
3303
|
+
if (BMI <= BMI_MID) {
|
|
3304
|
+
return 64 - 64 * (BMI_MID - BMI) / (BMI_MID - BMI_MIN);
|
|
3305
|
+
}
|
|
3306
|
+
else {
|
|
3307
|
+
return 64 + 63 * (BMI - BMI_MID) / (BMI_MAX - BMI_MID);
|
|
3308
|
+
}
|
|
3305
3309
|
}
|
|
3306
3310
|
|
|
3307
3311
|
|
|
@@ -3333,10 +3337,14 @@ module.exports = {
|
|
|
3333
3337
|
generateInstructions,
|
|
3334
3338
|
|
|
3335
3339
|
//Normalize Height and Weight 0-127 to human measurements
|
|
3336
|
-
|
|
3340
|
+
miiHeightToMeasurements,
|
|
3337
3341
|
inchesToMiiHeight,
|
|
3338
|
-
|
|
3339
|
-
|
|
3342
|
+
centimetersToMiiHeight,
|
|
3343
|
+
|
|
3344
|
+
//Highly Experimental
|
|
3345
|
+
miiWeightToRealWeight,
|
|
3346
|
+
imperialHeightWeightToMiiWeight,
|
|
3347
|
+
metricHeightWeightToMiiWeight,
|
|
3340
3348
|
|
|
3341
3349
|
/*
|
|
3342
3350
|
Handle Amiibo Functions
|